diff --git a/src/backend/vm.nim b/src/backend/vm.nim index f7c09dc..e8de298 100644 --- a/src/backend/vm.nim +++ b/src/backend/vm.nim @@ -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.. 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 diff --git a/src/main.nim b/src/main.nim index 4ab11fc..33e264b 100644 --- a/src/main.nim +++ b/src/main.nim @@ -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)