Fixed logic bug within if/else construct

This commit is contained in:
Mattia Giambirtone 2022-06-02 12:19:18 +02:00
parent dfa42d994b
commit 1d228c6310
3 changed files with 5 additions and 5 deletions

View File

@ -484,7 +484,7 @@ proc dispatch*(self: PeonVM) =
of JumpIfFalsePop: of JumpIfFalsePop:
let ip = self.readLong() let ip = self.readLong()
if not self.peek().boolean: if not self.peek().boolean:
self.ip = ip self.ip += ip
discard self.pop() discard self.pop()
of JumpIfFalseOrPop: of JumpIfFalseOrPop:
if not self.peek().boolean: if not self.peek().boolean:

View File

@ -27,7 +27,7 @@ when len(PEON_COMMIT_HASH) != 40:
const PEON_BRANCH* = "master" const PEON_BRANCH* = "master"
when len(PEON_BRANCH) > 255: when len(PEON_BRANCH) > 255:
{.fatal: "The git branch name's length must be less than or equal to 255 characters".} {.fatal: "The git branch name's length must be less than or equal to 255 characters".}
const DEBUG_TRACE_VM* = true # Traces VM execution const DEBUG_TRACE_VM* = false # Traces VM execution
const DEBUG_TRACE_GC* = false # Traces the garbage collector (TODO) const DEBUG_TRACE_GC* = false # Traces the garbage collector (TODO)
const DEBUG_TRACE_ALLOCATION* = false # Traces memory allocation/deallocation const DEBUG_TRACE_ALLOCATION* = false # Traces memory allocation/deallocation
const DEBUG_TRACE_COMPILER* = false # Traces the compiler const DEBUG_TRACE_COMPILER* = false # Traces the compiler

View File

@ -1119,11 +1119,11 @@ proc ifStmt(self: Compiler, node: IfStmt) =
if not self.enableOptimizations: if not self.enableOptimizations:
self.emitByte(Pop) self.emitByte(Pop)
self.statement(node.thenBranch) self.statement(node.thenBranch)
let jump2 = self.emitJump(JumpForwards)
self.patchJump(jump) self.patchJump(jump)
if node.elseBranch != nil: if node.elseBranch != nil:
let jump = self.emitJump(JumpForwards)
self.statement(node.elseBranch) self.statement(node.elseBranch)
self.patchJump(jump) self.patchJump(jump2)
proc emitLoop(self: Compiler, begin: int) = proc emitLoop(self: Compiler, begin: int) =
@ -1555,7 +1555,7 @@ proc compile*(self: Compiler, ast: seq[Declaration], file: string): Chunk =
name: "", name: "",
returnType: nil, returnType: nil,
args: @[]), args: @[]),
codePos: 13, codePos: 13, # Jump address is hardcoded
name: newIdentExpr(Token(lexeme: "", kind: Identifier)), name: newIdentExpr(Token(lexeme: "", kind: Identifier)),
line: -1) line: -1)
self.names.add(main) self.names.add(main)