diff --git a/src/backend/vm.nim b/src/backend/vm.nim index 646c3db..daf3af9 100644 --- a/src/backend/vm.nim +++ b/src/backend/vm.nim @@ -220,7 +220,7 @@ proc markRoots(self: var PeonVM): HashSet[ptr HeapObject] = result.incl(obj) for obj in self.operands: if obj in self.gc.pointers: - result.incl(obj) + result.incl(obj) var obj: ptr HeapObject for p in result: obj = cast[ptr HeapObject](p) @@ -1063,14 +1063,13 @@ proc run*(self: var PeonVM, chunk: Chunk, breakpoints: seq[uint64] = @[], repl: proc resume*(self: var PeonVM, chunk: Chunk) = ## Resumes execution of the given chunk (which ## may have changed since the last call to run()). - ## The instruction pointer is set to address 12, - ## as it is assumed that the compiler has produced - ## new code in the chunk, replacing the previous one. ## No other state mutation occurs and all stacks as - ## well as other metadata are left intact + ## well as other metadata are left intact. This should + ## not be used directly unless you know what you're + ## doing, as incremental compilation support is very + ## experimental and highly unstable + self.chunk = chunk try: - self.ip = 12 - self.chunk = chunk self.dispatch() except NilAccessDefect: stderr.writeLine("Memory Access Violation: SIGSEGV") diff --git a/src/frontend/compiler/targets/bytecode/target.nim b/src/frontend/compiler/targets/bytecode/target.nim index b984658..3ecc077 100644 --- a/src/frontend/compiler/targets/bytecode/target.nim +++ b/src/frontend/compiler/targets/bytecode/target.nim @@ -1981,12 +1981,12 @@ proc funDecl(self: BytecodeCompiler, node: FunDecl, name: Name) = self.patchJump(jump) self.endScope() # Terminates the function's context + let stop = self.chunk.code.len().toTriple() self.emitByte(OpCode.Return, self.peek().token.line) if hasVal: self.emitByte(1, self.peek().token.line) else: self.emitByte(0, self.peek().token.line) - let stop = self.chunk.code.len().toTriple() self.chunk.functions[idx] = stop[0] self.chunk.functions[idx + 1] = stop[1] self.chunk.functions[idx + 2] = stop[2] diff --git a/src/main.nim b/src/main.nim index e15f2a7..55af6ef 100644 --- a/src/main.nim +++ b/src/main.nim @@ -58,7 +58,7 @@ proc repl(warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: Comp tokens: seq[Token] = @[] tree: seq[Declaration] = @[] compiler = newBytecodeCompiler(replMode=true) - compiled: Chunk + compiled: Chunk = newChunk() serialized: Serialized tokenizer = newLexer() vm = newPeonVM() @@ -104,7 +104,7 @@ proc repl(warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: Comp for node in tree: styledEcho fgGreen, "\t", $node echo "" - compiled = compiler.compile(tree, "stdin", tokenizer.getLines(), input, showMismatches=mismatches, disabledWarnings=warnings, mode=mode) + compiled = compiler.compile(tree, "stdin", tokenizer.getLines(), input, chunk=compiled, showMismatches=mismatches, disabledWarnings=warnings, mode=mode, incremental=true) when debugCompiler: styledEcho fgCyan, "Compilation step:\n" debugger.disassembleChunk(compiled, "stdin") diff --git a/src/peon/stdlib/std.pn b/src/peon/stdlib/std.pn index c5bd37f..8d98299 100644 --- a/src/peon/stdlib/std.pn +++ b/src/peon/stdlib/std.pn @@ -16,4 +16,9 @@ export comparisons; var version* = 1; var _private = 5; # Invisible outside the module (underscore is to silence warning) -var test* = 0x60; \ No newline at end of file +var test* = 0x60; + + +fn testGlobals*: bool { + return version == 1 and _private == 5 and test == 0x60; +} \ No newline at end of file