Added -o/--output option
This commit is contained in:
parent
cf6d20e757
commit
382244f7a7
16
src/main.nim
16
src/main.nim
|
@ -160,7 +160,7 @@ proc repl(warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: Comp
|
||||||
|
|
||||||
proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints: seq[uint64] = @[], dis: bool = false,
|
proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints: seq[uint64] = @[], dis: bool = false,
|
||||||
warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: CompileMode = Debug, run: bool = true,
|
warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: CompileMode = Debug, run: bool = true,
|
||||||
backend: PeonBackend = PeonBackend.Bytecode) =
|
backend: PeonBackend = PeonBackend.Bytecode, output: string) =
|
||||||
var
|
var
|
||||||
tokens: seq[Token] = @[]
|
tokens: seq[Token] = @[]
|
||||||
tree: seq[Declaration] = @[]
|
tree: seq[Declaration] = @[]
|
||||||
|
@ -213,12 +213,13 @@ proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints
|
||||||
styledEcho fgCyan, "Compilation step:\n"
|
styledEcho fgCyan, "Compilation step:\n"
|
||||||
debugger.disassembleChunk(compiled, f)
|
debugger.disassembleChunk(compiled, f)
|
||||||
echo ""
|
echo ""
|
||||||
var path = splitFile(f).dir
|
var path = splitFile(if output.len() > 0: output else: f).dir
|
||||||
if path.len() > 0:
|
if path.len() > 0:
|
||||||
path &= "/"
|
path &= "/"
|
||||||
path &= splitFile(f).name & ".pbc"
|
if not path.endsWith(".pbc"):
|
||||||
|
path &= splitFile(if output.len() > 0: output else: f).name & ".pbc"
|
||||||
if dump and not fromString:
|
if dump and not fromString:
|
||||||
serializer.dumpFile(compiled, f, path)
|
serializer.dumpFile(compiled, f , path)
|
||||||
serialized = serializer.loadFile(path)
|
serialized = serializer.loadFile(path)
|
||||||
else:
|
else:
|
||||||
serialized = serializer.loadBytes(serializer.dumpBytes(compiled, f))
|
serialized = serializer.loadBytes(serializer.dumpBytes(compiled, f))
|
||||||
|
@ -291,6 +292,7 @@ when isMainModule:
|
||||||
var mode: CompileMode = CompileMode.Debug
|
var mode: CompileMode = CompileMode.Debug
|
||||||
var run: bool = true
|
var run: bool = true
|
||||||
var backend: PeonBackend
|
var backend: PeonBackend
|
||||||
|
var output: string = ""
|
||||||
for kind, key, value in optParser.getopt():
|
for kind, key, value in optParser.getopt():
|
||||||
case kind:
|
case kind:
|
||||||
of cmdArgument:
|
of cmdArgument:
|
||||||
|
@ -354,6 +356,8 @@ when isMainModule:
|
||||||
dis = true
|
dis = true
|
||||||
of "compile":
|
of "compile":
|
||||||
run = false
|
run = false
|
||||||
|
of "output":
|
||||||
|
output = value
|
||||||
of "backend":
|
of "backend":
|
||||||
case value:
|
case value:
|
||||||
of "bytecode":
|
of "bytecode":
|
||||||
|
@ -367,6 +371,8 @@ when isMainModule:
|
||||||
quit()
|
quit()
|
||||||
of cmdShortOption:
|
of cmdShortOption:
|
||||||
case key:
|
case key:
|
||||||
|
of "o":
|
||||||
|
output = value
|
||||||
of "h":
|
of "h":
|
||||||
echo HELP_MESSAGE
|
echo HELP_MESSAGE
|
||||||
quit()
|
quit()
|
||||||
|
@ -401,4 +407,4 @@ when isMainModule:
|
||||||
if file == "":
|
if file == "":
|
||||||
repl(warnings, mismatches, mode)
|
repl(warnings, mismatches, mode)
|
||||||
else:
|
else:
|
||||||
runFile(file, fromString, dump, breaks, dis, warnings, mismatches, mode, run, backend)
|
runFile(file, fromString, dump, breaks, dis, warnings, mismatches, mode, run, backend, output)
|
||||||
|
|
Loading…
Reference in New Issue