commit c092e54b8207e271e7bf6ae98b83226a6c3cfe2c from: Omar Polo date: Wed Aug 04 14:59:13 2021 UTC checks on global vars and on arity commit - f9cd3e06af84c7a1ce4408cda517310d99e5a23e commit + c092e54b8207e271e7bf6ae98b83226a6c3cfe2c blob - bf9bce72ab5ffef4c88153d884ccbe76a81deb17 blob + a90c9dd22fc45b80a73c7b24009f7abf1d534217 --- np.y +++ np.y @@ -133,7 +133,14 @@ include : INCLUDE STRING { } ; -const : CONST SYMBOL '=' literal { global_set($2, $4); }; +const : CONST SYMBOL '=' literal { + if (!global_set($2, $4)) { + yyerror("constant expression is not a literal"); + free($2); + free_op($4); + YYERROR; + } +}; var : SYMBOL '=' expr { $$ = op_assign($1, $3); } ; varref : SYMBOL { $$ = op_var($1); } ; @@ -169,6 +176,12 @@ funcall : procname { prepare_funcall(); } '(' args optcomma ')' { $$ = op_funcall($1); + if ($$->v.funcall.argc != $$->v.funcall.proc->minargs) { + yyerror("invalid arity for `%s'", + $1->name); + /* TODO: recursively free $$ */ + YYERROR; + } } ;