Added lastPop field to VM

This commit is contained in:
Mattia Giambirtone 2022-05-30 09:32:00 +02:00
parent 9f126845fc
commit 0887dab246
3 changed files with 4 additions and 2 deletions

View File

@ -30,6 +30,7 @@ type
chunk: Chunk # Piece of bytecode to execute
frames: seq[int] # Stores the initial index of stack frames
heapVars: seq[PeonObject] # Stores variables that do not have stack semantics (i.e. "static")
lastPop*: PeonObject # Used in the REPL
proc initCache*(self: PeonVM) =
@ -265,7 +266,7 @@ proc dispatch*(self: PeonVM) =
of NoOp:
continue
of Pop:
discard self.pop()
self.lastPop = self.pop()
of PopN:
for _ in 0..<int(self.readLong()):
discard self.pop()

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* = 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_ALLOCATION* = false # Traces memory allocation/deallocation
const DEBUG_TRACE_COMPILER* = false # Traces the compiler

View File

@ -123,6 +123,7 @@ proc repl =
when debugRuntime:
styledEcho fgCyan, "\n\nExecution step: "
vm.run(serialized.chunk)
echo vm.lastPop
except LexingError:
let exc = LexingError(getCurrentException())
let relPos = tokenizer.getRelPos(exc.line)