From 4515d21211263a2c7367ec20ec01ce9efaae1d18 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 27 Oct 2021 17:15:48 +0200 Subject: Fix depth resolution on recursive calls --- src/bytecode/vm.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/bytecode/vm.h') diff --git a/src/bytecode/vm.h b/src/bytecode/vm.h index 3c99131..3fba3d7 100755 --- a/src/bytecode/vm.h +++ b/src/bytecode/vm.h @@ -177,9 +177,9 @@ vm_interpret(VM *vm) { case OP_LOCAL: { ssize_t idx = AS_FIXNUM(array_pop(vm->stack)); ssize_t depth = AS_FIXNUM(array_pop(vm->stack)); + depth = array_size(vm->frames) - depth; CallFrame frame = vm->frames[depth]; array_push(vm->stack, vm->stack[frame.stack_offset + idx]); - } break; case OP_CONSTANT: { u8 constant = *vm->pc++; @@ -300,8 +300,9 @@ vm_interpret(VM *vm) { #ifdef DEBUG disassemble_chunk(proc.chunk); + printf("n_locals: %ld\n", n_locals); + printf("n_params: %ld\n", n_params); #endif - // Tail-call optimization. if (proc.chunk != frame->chunk || *vm->pc != OP_RETURN) { // Prepare new call frame. -- cgit v1.2.1