improve error message for arith op

This commit is contained in:
Sunrin SHIMURA (keen) 2015-01-19 18:03:48 +00:00
parent e67996f8af
commit f783640240
1 changed files with 13 additions and 8 deletions

View File

@ -558,9 +558,13 @@ analyze_quote(analyze_state *state, pic_value obj)
return pic_list2(pic, pic_obj_value(pic->sQUOTE), pic_list_ref(pic, obj, 1));
}
#define ARGC_ASSERT_GE(n) do { \
#define ARGC_ASSERT_GE(n, name) do { \
if (pic_length(pic, obj) < (n) + 1) { \
pic_errorf(pic, "wrong number of arguments"); \
pic_errorf(pic, \
#name ": wrong number of arguments (%d for equal to or more than %d)", \
pic_length(pic, obj) - 1, \
n); \
} \
} while (0)
@ -572,13 +576,14 @@ analyze_quote(analyze_state *state, pic_value obj)
} \
} while (0)
static pic_value
analyze_add(analyze_state *state, pic_value obj, bool tailpos)
{
pic_state *pic = state->pic;
pic_value args, arg;
ARGC_ASSERT_GE(0);
ARGC_ASSERT_GE(0, "+");
switch (pic_length(pic, obj)) {
case 1:
return pic_list2(pic, pic_obj_value(pic->sQUOTE), pic_int_value(0));
@ -597,7 +602,7 @@ analyze_sub(analyze_state *state, pic_value obj)
pic_state *pic = state->pic;
pic_value args, arg;
ARGC_ASSERT_GE(1);
ARGC_ASSERT_GE(1, "-");
switch (pic_length(pic, obj)) {
case 2:
return pic_list2(pic, pic_obj_value(pic->sMINUS),
@ -615,7 +620,7 @@ analyze_mul(analyze_state *state, pic_value obj, bool tailpos)
pic_state *pic = state->pic;
pic_value args, arg;
ARGC_ASSERT_GE(0);
ARGC_ASSERT_GE(0, "*");
switch (pic_length(pic, obj)) {
case 1:
return pic_list2(pic, pic_obj_value(pic->sQUOTE), pic_int_value(1));
@ -634,7 +639,7 @@ analyze_div(analyze_state *state, pic_value obj)
pic_state *pic = state->pic;
pic_value args, arg;
ARGC_ASSERT_GE(1);
ARGC_ASSERT_GE(1, "/");
switch (pic_length(pic, obj)) {
case 2:
args = pic_cdr(pic, obj);