Fixed local variables

This commit is contained in:
Mattia Giambirtone 2022-06-02 11:45:27 +02:00
parent 6b314f2882
commit e9cb3fca89
3 changed files with 4 additions and 4 deletions

View File

@ -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:

View File

@ -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

View File

@ -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)