aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/vm.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-27 17:15:48 +0200
committerBad Diode <bd@badd10de.dev>2021-10-27 17:15:48 +0200
commit4515d21211263a2c7367ec20ec01ce9efaae1d18 (patch)
tree9458dd1d5b7f066631c939f6039d95ed44b5de81 /src/bytecode/vm.h
parent67f0debc923dc97fd79554678435f113c9f761d1 (diff)
downloadbdl-4515d21211263a2c7367ec20ec01ce9efaae1d18.tar.gz
bdl-4515d21211263a2c7367ec20ec01ce9efaae1d18.zip
Fix depth resolution on recursive calls
Diffstat (limited to 'src/bytecode/vm.h')
-rwxr-xr-xsrc/bytecode/vm.h5
1 files changed, 3 insertions, 2 deletions
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) {
177 case OP_LOCAL: { 177 case OP_LOCAL: {
178 ssize_t idx = AS_FIXNUM(array_pop(vm->stack)); 178 ssize_t idx = AS_FIXNUM(array_pop(vm->stack));
179 ssize_t depth = AS_FIXNUM(array_pop(vm->stack)); 179 ssize_t depth = AS_FIXNUM(array_pop(vm->stack));
180 depth = array_size(vm->frames) - depth;
180 CallFrame frame = vm->frames[depth]; 181 CallFrame frame = vm->frames[depth];
181 array_push(vm->stack, vm->stack[frame.stack_offset + idx]); 182 array_push(vm->stack, vm->stack[frame.stack_offset + idx]);
182
183 } break; 183 } break;
184 case OP_CONSTANT: { 184 case OP_CONSTANT: {
185 u8 constant = *vm->pc++; 185 u8 constant = *vm->pc++;
@@ -300,8 +300,9 @@ vm_interpret(VM *vm) {
300 300
301#ifdef DEBUG 301#ifdef DEBUG
302 disassemble_chunk(proc.chunk); 302 disassemble_chunk(proc.chunk);
303 printf("n_locals: %ld\n", n_locals);
304 printf("n_params: %ld\n", n_params);
303#endif 305#endif
304
305 // Tail-call optimization. 306 // Tail-call optimization.
306 if (proc.chunk != frame->chunk || *vm->pc != OP_RETURN) { 307 if (proc.chunk != frame->chunk || *vm->pc != OP_RETURN) {
307 // Prepare new call frame. 308 // Prepare new call frame.