diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-27 12:01:33 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-27 12:05:27 +0100 |
commit | 991e694b558691264f82d80a7aa1b86ef3d2c92c (patch) | |
tree | 881946b076bdcc6545aa167ef7d544b6e16f9abb /vm.c | |
parent | a559125a2d7af771784614b7a2092cc7fb707345 (diff) |
more tests
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)) { |