From 991e694b558691264f82d80a7aa1b86ef3d2c92c Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 27 Jun 2024 12:01:33 +0100 Subject: more tests --- vm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 023d2c3..500b4bf 100644 --- a/vm.c +++ b/vm.c @@ -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)) { -- cgit v1.2.3