Require num_args for primitive_type

This will allow us to use the same validation code as for closures.
This commit is contained in:
Justin Ethier 2021-05-24 12:35:50 -04:00
parent a05959cb90
commit 8526a0676f
2 changed files with 5 additions and 8 deletions

View file

@ -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;

View file

@ -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, "<procedure>", 1, args);
dispatch(data, obj_obj2int(count), ((closure) func)->fn, func, cont,
args);
} else {
Cyc_check_num_args(data, "<procedure>", ((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, "<procedure>", ((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: