diff --git a/lang/bytecode.c b/lang/bytecode.c index f7054bf..e9c6eaf 100644 --- a/lang/bytecode.c +++ b/lang/bytecode.c @@ -32,11 +32,11 @@ }; // clang-format on -void bytecode_run(struct object **stack) { +void bytecode_run(struct object **stack, int arg_count) { abort_if(!stack, "bytecode_run has no stack"); const unsigned char *pos_code = &bytecode[0]; // We assume one argument: A return value - struct object **pos_stack = stack + 1; + struct object **pos_stack = stack + arg_count; unsigned char op = OP_RET; while ((op = *pos_code++) != OP_RET) { // Skip over NOP, ASCII and unknown OPs @@ -76,7 +76,7 @@ } } // Clean up the stack - struct object **pos_cleanup = pos_stack - 1; + struct object **pos_cleanup = pos_stack - arg_count; while (pos_cleanup != stack) { object_drop(pos_cleanup--); } diff --git a/lang/bytecode.h b/lang/bytecode.h index d39bdae..4c73036 100644 --- a/lang/bytecode.h +++ b/lang/bytecode.h @@ -7,6 +7,6 @@ #include "object.h" // Runs bytecode on a stack -void bytecode_run(struct object **stack); +void bytecode_run(struct object **stack, int arg_count); #endif diff --git a/lang/func.c b/lang/func.c index b331fa7..13472cc 100644 --- a/lang/func.c +++ b/lang/func.c @@ -30,7 +30,7 @@ static void func_call(struct object *obj, int arg_count, struct object **args) { abort_if(arg_count != 1, "func_add called with more than 1 argument"); abort_if(obj->class_data != &func_class, "func_call obj is not a func"); - bytecode_run(args); + bytecode_run(args, arg_count); } static struct object_call calls[] = {