diff --git a/src/backend/vm.nim b/src/backend/vm.nim index 8409ad0..b43a733 100644 --- a/src/backend/vm.nim +++ b/src/backend/vm.nim @@ -404,7 +404,7 @@ proc dispatch*(self: PeonVM) = of StoreVar: # Stores the value at the top of the operand stack # into the given call stack index - let idx = int(self.readLong()) + let idx = int(self.readLong()) + self.frames[^1] if idx <= self.calls.high(): self.setc(idx, self.pop()) else: diff --git a/src/config.nim b/src/config.nim index 1fda235..6014eb9 100644 --- a/src/config.nim +++ b/src/config.nim @@ -27,7 +27,7 @@ when len(PEON_COMMIT_HASH) != 40: const PEON_BRANCH* = "master" when len(PEON_BRANCH) > 255: {.fatal: "The git branch name's length must be less than or equal to 255 characters".} -const DEBUG_TRACE_VM* = false # Traces VM execution +const DEBUG_TRACE_VM* = true # Traces VM execution const DEBUG_TRACE_GC* = false # Traces the garbage collector (TODO) const DEBUG_TRACE_ALLOCATION* = false # Traces memory allocation/deallocation const DEBUG_TRACE_COMPILER* = false # Traces the compiler diff --git a/src/frontend/compiler.nim b/src/frontend/compiler.nim index 643fac1..fcec330 100644 --- a/src/frontend/compiler.nim +++ b/src/frontend/compiler.nim @@ -1473,9 +1473,9 @@ proc funDecl(self: Compiler, node: FunDecl) = self.error("non-empty return statement is not allowed in void functions") elif not hasVal and self.currentFunction.returnType != nil: self.error("function has an explicit return type, but no return statement was found") - # self.endFunctionBeforeReturn() + self.endFunctionBeforeReturn() hasVal = hasVal and typ.returnType != nil - self.endScope(deleteNames=true, fromFunc=false) + self.endScope(deleteNames=true, fromFunc=true) self.emitByte(OpCode.Return) if hasVal: self.emitByte(1)