diff --git a/src/main.nim b/src/main.nim index 1257020..2f11e1b 100644 --- a/src/main.nim +++ b/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, warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: CompileMode = Debug, run: bool = true, - backend: PeonBackend = PeonBackend.Bytecode) = + backend: PeonBackend = PeonBackend.Bytecode, output: string) = var tokens: seq[Token] = @[] tree: seq[Declaration] = @[] @@ -213,12 +213,13 @@ proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints styledEcho fgCyan, "Compilation step:\n" debugger.disassembleChunk(compiled, f) echo "" - var path = splitFile(f).dir + var path = splitFile(if output.len() > 0: output else: f).dir if path.len() > 0: 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: - serializer.dumpFile(compiled, f, path) + serializer.dumpFile(compiled, f , path) serialized = serializer.loadFile(path) else: serialized = serializer.loadBytes(serializer.dumpBytes(compiled, f)) @@ -291,6 +292,7 @@ when isMainModule: var mode: CompileMode = CompileMode.Debug var run: bool = true var backend: PeonBackend + var output: string = "" for kind, key, value in optParser.getopt(): case kind: of cmdArgument: @@ -354,6 +356,8 @@ when isMainModule: dis = true of "compile": run = false + of "output": + output = value of "backend": case value: of "bytecode": @@ -367,6 +371,8 @@ when isMainModule: quit() of cmdShortOption: case key: + of "o": + output = value of "h": echo HELP_MESSAGE quit() @@ -401,4 +407,4 @@ when isMainModule: if file == "": repl(warnings, mismatches, mode) else: - runFile(file, fromString, dump, breaks, dis, warnings, mismatches, mode, run, backend) + runFile(file, fromString, dump, breaks, dis, warnings, mismatches, mode, run, backend, output)