mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
Testing out basic arg count validation
This commit is contained in:
parent
2d8c6ed5f3
commit
72c32de774
1 changed files with 11 additions and 0 deletions
11
runtime.c
11
runtime.c
|
@ -9,6 +9,16 @@
|
||||||
#include "cyclone.h"
|
#include "cyclone.h"
|
||||||
#include "runtime.h"
|
#include "runtime.h"
|
||||||
|
|
||||||
|
/* TODO: working on validation for applying functions */
|
||||||
|
#define Cyc_check_num_args(fnc_name, num_args, args) { \
|
||||||
|
integer_type l = Cyc_length(args); \
|
||||||
|
if (num_args > l.value) { \
|
||||||
|
char buf[256]; \
|
||||||
|
snprintf(buf, 255, "Expected %d arguments but received %d.", num_args, l.value); \
|
||||||
|
Cyc_rt_raise_msg(buf); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
/* Funcall section, these are hardcoded here to support
|
/* Funcall section, these are hardcoded here to support
|
||||||
functions in this module. */
|
functions in this module. */
|
||||||
#define funcall1(cfn,a1) if (type_of(cfn) == cons_tag || prim(cfn)) { Cyc_apply(0, (closure)a1, cfn); } else { ((cfn)->fn)(1,cfn,a1);}
|
#define funcall1(cfn,a1) if (type_of(cfn) == cons_tag || prim(cfn)) { Cyc_apply(0, (closure)a1, cfn); } else { ((cfn)->fn)(1,cfn,a1);}
|
||||||
|
@ -1186,6 +1196,7 @@ cvar_type *mcvar(object *var) {
|
||||||
void _Cyc_91global_91vars(object cont, object args){
|
void _Cyc_91global_91vars(object cont, object args){
|
||||||
return_funcall1(cont, Cyc_global_variables); }
|
return_funcall1(cont, Cyc_global_variables); }
|
||||||
void _car(object cont, object args) {
|
void _car(object cont, object args) {
|
||||||
|
Cyc_check_num_args("car", 1, args);
|
||||||
return_funcall1(cont, car(car(args))); }
|
return_funcall1(cont, car(car(args))); }
|
||||||
void _cdr(object cont, object args) {
|
void _cdr(object cont, object args) {
|
||||||
return_funcall1(cont, cdr(car(args))); }
|
return_funcall1(cont, cdr(car(args))); }
|
||||||
|
|
Loading…
Add table
Reference in a new issue