From 7735863cab76a77e19b96dcc82a2f714c2a160cc Mon Sep 17 00:00:00 2001 From: DualFroz Date: Wed, 26 Aug 2026 19:15:00 +0200 Subject: [PATCH] feat(cli): add command-line entry point --- src/main/kotlin/lumen/cli/Main.kt | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/kotlin/lumen/cli/Main.kt diff --git a/src/main/kotlin/lumen/cli/Main.kt b/src/main/kotlin/lumen/cli/Main.kt new file mode 100644 index 0000000..e8a5be9 --- /dev/null +++ b/src/main/kotlin/lumen/cli/Main.kt @@ -0,0 +1,35 @@ +package lumen.cli + +import lumen.Lumen +import lumen.LumenError +import lumen.bytecode.Disassembler +import lumen.formatError +import lumen.module.ModuleError +import java.io.File +import kotlin.system.exitProcess + +fun main(args: Array) { + if (args.isEmpty()) { + Repl().start() + return + } + if (args[0] == "--dump" && args.size > 1) { + Disassembler.dump(Lumen.compile(File(args[1]).readText())) + return + } + val path = args[0] + val file = File(path) + if (!file.exists()) { + System.err.println("error: file not found: $path") + exitProcess(1) + } + try { + Lumen.runFile(file) + } catch (error: ModuleError) { + System.err.println(formatError(error.source, error.error)) + exitProcess(1) + } catch (error: LumenError) { + System.err.println(formatError(file.readText(), error)) + exitProcess(1) + } +}