From 8526a0676f0ae29c9fc7b4e01e3ad0b2004edba0 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 24 May 2021 12:35:50 -0400 Subject: [PATCH] Require num_args for primitive_type This will allow us to use the same validation code as for closures. --- include/cyclone/types.h | 1 + runtime.c | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index b8674353..e3e3e949 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -1471,6 +1471,7 @@ typedef struct { gc_header_type hdr; tag_type tag; function_type fn; + int num_args; const char *desc; } primitive_type; typedef primitive_type *primitive; diff --git a/runtime.c b/runtime.c index 899e8e5c..c66241f9 100644 --- a/runtime.c +++ b/runtime.c @@ -5794,27 +5794,23 @@ object apply(void *data, object cont, object func, object args) switch (type_of(func)) { case primitive_tag: - TODO: fn function signature changed, need to convert from list to array - ((primitive_type *) func)->fn(data, cont, args); - break; case macro_tag: case closure0_tag: case closure1_tag: case closureN_tag: + count = 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); - count = Cyc_length(data, args); Cyc_check_num_args(data, "", 1, args); dispatch(data, obj_obj2int(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); } - count = Cyc_length(data, args); - // TODO: validate number of args provided: - 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); break; case pair_tag: