diff options
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -177,12 +177,14 @@ int runvm(State *S) { case OP_CALL: { // nargs + 1 = function and args uint8_t len = RBYTE(); - + uint8_t nargs = len - 1; Val callee = PEEKN(len); if (IS_FUNC(callee)) { ObjFunc *func = AS_FUNC(callee); + CHECK(nargs == func->arity, "func needs exactly %d args, but got %d",func->arity,nargs); + CHECK(th->rsp < MAXDEPTH, "rstack overflow"); StackFrame *sf = &th->rstack[th->rsp++]; sf->ip = th->ip; sf->ch = th->ch; @@ -192,9 +194,8 @@ int runvm(State *S) { th->ch = &func->ch; th->fp = th->sp - len; } else if (IS_CFUNC(callee)) { - int nargs = len - 1; Val *firstarg = &th->stack[th->sp - nargs]; - Val res = AS_CFUNC(callee)(S, len - 1, firstarg); + Val res = AS_CFUNC(callee)(S, nargs, firstarg); th->sp -= len; PUSH(res); } else if (IS_ARR(callee)) { |