Fixed issue with resuming from incremental compilation
This commit is contained in:
parent
dc195409c9
commit
de9b51152e
|
@ -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
|
||||
try:
|
||||
self.ip = 12
|
||||
## 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.dispatch()
|
||||
except NilAccessDefect:
|
||||
stderr.writeLine("Memory Access Violation: SIGSEGV")
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -17,3 +17,8 @@ export comparisons;
|
|||
var version* = 1;
|
||||
var _private = 5; # Invisible outside the module (underscore is to silence warning)
|
||||
var test* = 0x60;
|
||||
|
||||
|
||||
fn testGlobals*: bool {
|
||||
return version == 1 and _private == 5 and test == 0x60;
|
||||
}
|
Loading…
Reference in New Issue