Fixed issue with resuming from incremental compilation
This commit is contained in:
parent
dc195409c9
commit
de9b51152e
|
@ -220,7 +220,7 @@ proc markRoots(self: var PeonVM): HashSet[ptr HeapObject] =
|
||||||
result.incl(obj)
|
result.incl(obj)
|
||||||
for obj in self.operands:
|
for obj in self.operands:
|
||||||
if obj in self.gc.pointers:
|
if obj in self.gc.pointers:
|
||||||
result.incl(obj)
|
result.incl(obj)
|
||||||
var obj: ptr HeapObject
|
var obj: ptr HeapObject
|
||||||
for p in result:
|
for p in result:
|
||||||
obj = cast[ptr HeapObject](p)
|
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) =
|
proc resume*(self: var PeonVM, chunk: Chunk) =
|
||||||
## Resumes execution of the given chunk (which
|
## Resumes execution of the given chunk (which
|
||||||
## may have changed since the last call to run()).
|
## 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
|
## 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:
|
try:
|
||||||
self.ip = 12
|
|
||||||
self.chunk = chunk
|
|
||||||
self.dispatch()
|
self.dispatch()
|
||||||
except NilAccessDefect:
|
except NilAccessDefect:
|
||||||
stderr.writeLine("Memory Access Violation: SIGSEGV")
|
stderr.writeLine("Memory Access Violation: SIGSEGV")
|
||||||
|
|
|
@ -1981,12 +1981,12 @@ proc funDecl(self: BytecodeCompiler, node: FunDecl, name: Name) =
|
||||||
self.patchJump(jump)
|
self.patchJump(jump)
|
||||||
self.endScope()
|
self.endScope()
|
||||||
# Terminates the function's context
|
# Terminates the function's context
|
||||||
|
let stop = self.chunk.code.len().toTriple()
|
||||||
self.emitByte(OpCode.Return, self.peek().token.line)
|
self.emitByte(OpCode.Return, self.peek().token.line)
|
||||||
if hasVal:
|
if hasVal:
|
||||||
self.emitByte(1, self.peek().token.line)
|
self.emitByte(1, self.peek().token.line)
|
||||||
else:
|
else:
|
||||||
self.emitByte(0, self.peek().token.line)
|
self.emitByte(0, self.peek().token.line)
|
||||||
let stop = self.chunk.code.len().toTriple()
|
|
||||||
self.chunk.functions[idx] = stop[0]
|
self.chunk.functions[idx] = stop[0]
|
||||||
self.chunk.functions[idx + 1] = stop[1]
|
self.chunk.functions[idx + 1] = stop[1]
|
||||||
self.chunk.functions[idx + 2] = stop[2]
|
self.chunk.functions[idx + 2] = stop[2]
|
||||||
|
|
|
@ -58,7 +58,7 @@ proc repl(warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: Comp
|
||||||
tokens: seq[Token] = @[]
|
tokens: seq[Token] = @[]
|
||||||
tree: seq[Declaration] = @[]
|
tree: seq[Declaration] = @[]
|
||||||
compiler = newBytecodeCompiler(replMode=true)
|
compiler = newBytecodeCompiler(replMode=true)
|
||||||
compiled: Chunk
|
compiled: Chunk = newChunk()
|
||||||
serialized: Serialized
|
serialized: Serialized
|
||||||
tokenizer = newLexer()
|
tokenizer = newLexer()
|
||||||
vm = newPeonVM()
|
vm = newPeonVM()
|
||||||
|
@ -104,7 +104,7 @@ proc repl(warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: Comp
|
||||||
for node in tree:
|
for node in tree:
|
||||||
styledEcho fgGreen, "\t", $node
|
styledEcho fgGreen, "\t", $node
|
||||||
echo ""
|
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:
|
when debugCompiler:
|
||||||
styledEcho fgCyan, "Compilation step:\n"
|
styledEcho fgCyan, "Compilation step:\n"
|
||||||
debugger.disassembleChunk(compiled, "stdin")
|
debugger.disassembleChunk(compiled, "stdin")
|
||||||
|
|
|
@ -16,4 +16,9 @@ export comparisons;
|
||||||
|
|
||||||
var version* = 1;
|
var version* = 1;
|
||||||
var _private = 5; # Invisible outside the module (underscore is to silence warning)
|
var _private = 5; # Invisible outside the module (underscore is to silence warning)
|
||||||
var test* = 0x60;
|
var test* = 0x60;
|
||||||
|
|
||||||
|
|
||||||
|
fn testGlobals*: bool {
|
||||||
|
return version == 1 and _private == 5 and test == 0x60;
|
||||||
|
}
|
Loading…
Reference in New Issue