import vm import compiler import os import config type Result = enum rsOK, rsCompileError, rsRuntimeError proc interpret(name: string, source: string): Result = let compiler = newCompiler(name, source) compiler.compile() if compiler.hadError: return rsCompileError case compiler.chunk.run(): of irOK: rsOK of irRuntimeError: rsRuntimeError proc repl = while true: try: let line = konLineEditor() if line.len > 0: discard interpret("repl", line) except ReadlineInterruptedException: break proc runFile(path: string) = case interpret(path, readFile(path)): of rsCompileError: quit 65 of rsRuntimeError: quit 70 of rsOK: quit 0 const hardcodedPath* = "" if paramCount() == 0: if hardcodedPath == "": repl() else: runFile(hardcodedPath) elif paramCount() == 1: runFile(paramStr(1)) else: echo "Maximum param count is 1" quit 1