diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 37a395a8..e0978bb6 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -66,12 +66,11 @@ void gc_init_heap(long heap_size); * */ /**@{*/ -#define Cyc_check_num_args(data, fnc_name, num_args, args) { \ - object l = Cyc_length(data, args); \ - if (num_args > obj_obj2int(l)) { \ +#define Cyc_check_num_args(data, fnc_name, num_expected_args, args, args_len) { \ + if (num_expected_args > args_len) { \ char buf[128]; \ - snprintf(buf, 127, "Expected %d arguments to %s but received %ld", \ - num_args, fnc_name, obj_obj2int(l)); \ + snprintf(buf, 127, "Expected %d arguments to %s but received %d", \ + num_expected_args, fnc_name, args_len); \ Cyc_rt_raise_msg(data, buf); \ } \ } diff --git a/runtime.c b/runtime.c index c66241f9..aea47931 100644 --- a/runtime.c +++ b/runtime.c @@ -5781,16 +5781,11 @@ object apply_va(void *data, object cont, int argc, object func, ...) */ object apply(void *data, object cont, object func, object args) { - object count; + int count; -//printf("DEBUG apply: "); -//Cyc_display(data, args); -//printf("\n"); if (!is_object_type(func)) { Cyc_rt_raise2(data, "Call of non-procedure: ", func); } - // Causes problems... - //Cyc_check_pair_or_null(args); switch (type_of(func)) { case primitive_tag: @@ -5798,18 +5793,14 @@ object apply(void *data, object cont, object func, object args) case closure0_tag: case closure1_tag: case closureN_tag: - count = Cyc_length(data, args); + count = obj_obj2int(Cyc_length(data, args)); if (func == Cyc_glo_call_cc) { -// make_pair(c, cont, args); -//Cyc_display(data, args, stderr); -// args = &c; -//Cyc_display(data, &c, stderr); - Cyc_check_num_args(data, "", 1, args); - dispatch(data, obj_obj2int(count), ((closure) func)->fn, func, cont, + Cyc_check_num_args(data, "", 1, args, count); + dispatch(data, count, ((closure) func)->fn, func, cont, args); } else { - Cyc_check_num_args(data, "", ((closure) func)->num_args, args); // TODO: could be more efficient, eg: cyc_length(args) is called twice. - dispatch(data, obj_obj2int(count), ((closure) func)->fn, func, cont, args); + Cyc_check_num_args(data, "", ((closure) func)->num_args, args, count); + dispatch(data, count, ((closure) func)->fn, func, cont, args); } break;