Reformatted help menu, added -w option. All code can now be disassembled
This commit is contained in:
parent
ae819daac4
commit
81e10ae1ea
|
@ -53,22 +53,21 @@ $ peon file.pbc Run the given Peon bytecode file
|
||||||
Options
|
Options
|
||||||
-------
|
-------
|
||||||
|
|
||||||
-h, --help Show this help text and exits
|
-h, --help Show this help text and exit
|
||||||
-v, --version Print the current peon version and exits
|
-v, --version Print the current peon version and exit
|
||||||
-s, --string Execute the passed string as if it was a file
|
-s, --string Execute the passed string as if it was a file
|
||||||
-n, --noDump Don't dump the result of compilation to a file.
|
-n, --noDump Don't dump the result of compilation to a file.
|
||||||
Note that no dump is created when using -s/--string
|
Note that no dump is created when using -s/--string
|
||||||
-b, --breakpoints Run the debugger at specific bytecode offsets (comma-separated).
|
-b, --breakpoints Run the debugger at specific bytecode offsets (comma-separated).
|
||||||
Only available with --backend:bytecode and when compiled with VM
|
Only available with --backend:bytecode and when compiled with VM
|
||||||
debugging on
|
debugging on
|
||||||
-d, --disassemble Disassemble the given bytecode file instead of executing it
|
-d, --disassemble Disassemble the output of compilation (only makes sense with --backend:bytecode)
|
||||||
(only makes sense with --backend:bytecode)
|
|
||||||
-m, --mode Set the compilation mode. Acceptable values are 'debug' and
|
-m, --mode Set the compilation mode. Acceptable values are 'debug' and
|
||||||
'release'. Defaults to 'debug'
|
'release'. Defaults to 'debug'
|
||||||
-c, --compile Compile the code, but do not execute it
|
-c, --compile Compile the code, but do not execute it. Useful along with -d
|
||||||
--warnings Turn warnings on or off (default: on). Acceptable values are
|
-w, --warnings Turn warnings on or off (default: on). Acceptable values are
|
||||||
yes/on and no/off
|
yes/on and no/off
|
||||||
--noWarn Disable a specific warning (for example, --noWarn unusedVariable)
|
--noWarn Disable a specific warning (for example, --noWarn:unusedVariable)
|
||||||
--showMismatches Show all mismatches when function dispatching fails (output is really verbose)
|
--showMismatches Show all mismatches when function dispatching fails (output is really verbose)
|
||||||
--backend Select the compilation backend (valid values are: 'c', 'cpp' and 'bytecode'). Note
|
--backend Select the compilation backend (valid values are: 'c', 'cpp' and 'bytecode'). Note
|
||||||
that the REPL always uses the bytecode target. Defaults to 'bytecode'
|
that the REPL always uses the bytecode target. Defaults to 'bytecode'
|
||||||
|
|
|
@ -274,23 +274,6 @@ proc setJump(self: BytecodeCompiler, offset: int, jmp: seq[uint8]) =
|
||||||
self.chunk.code[offset + 1] = jmp[0]
|
self.chunk.code[offset + 1] = jmp[0]
|
||||||
self.chunk.code[offset + 2] = jmp[1]
|
self.chunk.code[offset + 2] = jmp[1]
|
||||||
self.chunk.code[offset + 3] = jmp[2]
|
self.chunk.code[offset + 3] = jmp[2]
|
||||||
|
|
||||||
|
|
||||||
proc patchJump(self: BytecodeCompiler, offset: int) =
|
|
||||||
## Patches a previously emitted relative
|
|
||||||
## jump using emitJump
|
|
||||||
var jump: int = self.chunk.code.len() - self.jumps[offset].offset
|
|
||||||
if jump < 0:
|
|
||||||
self.error("jump size cannot be negative (This is an internal error and most likely a bug)")
|
|
||||||
if jump > 16777215:
|
|
||||||
# TODO: Emit consecutive jumps using insertAt
|
|
||||||
self.error("cannot jump more than 16777215 instructions")
|
|
||||||
if jump > 0:
|
|
||||||
self.setJump(self.jumps[offset].offset, (jump - 4).toTriple())
|
|
||||||
self.jumps[offset].patched = true
|
|
||||||
else:
|
|
||||||
# TODO: Discard jump of size 0
|
|
||||||
discard
|
|
||||||
|
|
||||||
|
|
||||||
proc emitJump(self: BytecodeCompiler, opcode: OpCode, line: int): int =
|
proc emitJump(self: BytecodeCompiler, opcode: OpCode, line: int): int =
|
||||||
|
@ -401,6 +384,21 @@ proc insertAt(self: BytecodeCompiler, where: int, opcode: OpCode, data: openarra
|
||||||
self.fixFunctionOffsets(oldLen, where)
|
self.fixFunctionOffsets(oldLen, where)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
proc patchJump(self: BytecodeCompiler, offset: int) =
|
||||||
|
## Patches a previously emitted relative
|
||||||
|
## jump using emitJump
|
||||||
|
var jump: int = self.chunk.code.len() - self.jumps[offset].offset
|
||||||
|
if jump < 0:
|
||||||
|
self.error("jump size cannot be negative (This is an internal error and most likely a bug)")
|
||||||
|
if jump > 16777215:
|
||||||
|
# TODO: Emit consecutive jumps using insertAt
|
||||||
|
self.error("cannot jump more than 16777215 instructions")
|
||||||
|
if jump > 0:
|
||||||
|
self.setJump(self.jumps[offset].offset, (jump - 4).toTriple())
|
||||||
|
self.jumps[offset].patched = true
|
||||||
|
|
||||||
|
|
||||||
proc handleBuiltinFunction(self: BytecodeCompiler, fn: Type, args: seq[Expression], line: int) =
|
proc handleBuiltinFunction(self: BytecodeCompiler, fn: Type, args: seq[Expression], line: int) =
|
||||||
## Emits instructions for builtin functions
|
## Emits instructions for builtin functions
|
||||||
## such as addition or subtraction
|
## such as addition or subtraction
|
||||||
|
|
15
src/main.nim
15
src/main.nim
|
@ -179,9 +179,6 @@ proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints
|
||||||
if not fromString:
|
if not fromString:
|
||||||
if not f.endsWith(".pn") and not f.endsWith(".pbc"):
|
if not f.endsWith(".pn") and not f.endsWith(".pbc"):
|
||||||
f &= ".pn"
|
f &= ".pn"
|
||||||
if backend == PeonBackend.Bytecode and dis:
|
|
||||||
debugger.disassembleChunk(serializer.loadFile(f).chunk, f)
|
|
||||||
return
|
|
||||||
input = readFile(f)
|
input = readFile(f)
|
||||||
else:
|
else:
|
||||||
input = f
|
input = f
|
||||||
|
@ -212,7 +209,8 @@ proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints
|
||||||
when debugCompiler:
|
when debugCompiler:
|
||||||
styledEcho fgCyan, "Compilation step:\n"
|
styledEcho fgCyan, "Compilation step:\n"
|
||||||
debugger.disassembleChunk(compiled, f)
|
debugger.disassembleChunk(compiled, f)
|
||||||
echo ""
|
if dis:
|
||||||
|
debugger.disassembleChunk(compiled, f)
|
||||||
var path = splitFile(if output.len() > 0: output else: f).dir
|
var path = splitFile(if output.len() > 0: output else: f).dir
|
||||||
if path.len() > 0:
|
if path.len() > 0:
|
||||||
path &= "/"
|
path &= "/"
|
||||||
|
@ -384,6 +382,15 @@ when isMainModule:
|
||||||
fromString = true
|
fromString = true
|
||||||
of "n":
|
of "n":
|
||||||
dump = false
|
dump = false
|
||||||
|
of "w":
|
||||||
|
if value.toLowerAscii() in ["yes", "on"]:
|
||||||
|
warnings = @[]
|
||||||
|
elif value.toLowerAscii() in ["no", "off"]:
|
||||||
|
for warning in WarningKind:
|
||||||
|
warnings.add(warning)
|
||||||
|
else:
|
||||||
|
stderr.styledWriteLine(fgRed, styleBright, "Error: ", fgDefault, "invalid value for option 'w' (valid options are: yes, on, no, off)")
|
||||||
|
quit()
|
||||||
of "b":
|
of "b":
|
||||||
when not debugVM:
|
when not debugVM:
|
||||||
stderr.styledWriteLine(fgRed, styleBright, "Error: ", fgDefault, "cannot set breakpoints in release mode")
|
stderr.styledWriteLine(fgRed, styleBright, "Error: ", fgDefault, "cannot set breakpoints in release mode")
|
||||||
|
|
Loading…
Reference in New Issue