summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-27 12:01:33 +0100
committerubq323 <ubq323@ubq323.website>2024-06-27 12:05:27 +0100
commit991e694b558691264f82d80a7aa1b86ef3d2c92c (patch)
tree881946b076bdcc6545aa167ef7d544b6e16f9abb /vm.c
parenta559125a2d7af771784614b7a2092cc7fb707345 (diff)
more tests
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c7
1 files changed, 4 insertions, 3 deletions
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)) {