From bba646bc3b6c77ed87ba09b844618852b7e1a7e2 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Tue, 16 Jun 2026 18:46:47 +0200 Subject: [PATCH] add cli mod --- crates/jam-llvm/Cargo.toml | 8 +++++ crates/jam-llvm/lib.rs | 0 crates/jam/src/cli/mod.rs | 52 +++++++++++++++++++++++++++++ crates/jam/src/cli/progress.rs | 61 ++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 crates/jam-llvm/Cargo.toml create mode 100644 crates/jam-llvm/lib.rs create mode 100644 crates/jam/src/cli/mod.rs create mode 100644 crates/jam/src/cli/progress.rs diff --git a/crates/jam-llvm/Cargo.toml b/crates/jam-llvm/Cargo.toml new file mode 100644 index 0000000..bb66baa --- /dev/null +++ b/crates/jam-llvm/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "jam_llvm" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +rust-version.workspace = true +description = "Jam programming language compiler llvm bindings" diff --git a/crates/jam-llvm/lib.rs b/crates/jam-llvm/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/jam/src/cli/mod.rs b/crates/jam/src/cli/mod.rs new file mode 100644 index 0000000..6112f4b --- /dev/null +++ b/crates/jam/src/cli/mod.rs @@ -0,0 +1,52 @@ +pub mod progress; + +pub fn display_help() { + println!(r#"Jam programming language compiler + +Usage: jam [OPTIONS] + jam run [LINKER-FLAGS] + jam test [] + +Subcommands: + run Compile, run, and clean up the executable. + Only linker flags (-l) may accompany it. + test Compile test functions and run them. + version Print version and exit. + help Print help and exit. + +Options: + -o Output binary name (default: 'output') + -C opt-level=N Optimization level, Default is '0' + 0 no optimizations + 1 basic optimizations + 2 LLVM default (-O2) + 3 aggressive (-O3) + s optimize for size (-Os) + z aggressively optimize for size (-Oz) + -C lto=MODE Link-time optimization. Default is 'off' + off regular object file (no LTO) + thin ThinLTO bitcode — fast, parallel link + fat full LTO bitcode — slowest link, most opt + -C strip=MODE Symbol / debug-info stripping. Default is 'none' + none keep all symbols & debug info + debuginfo strip DWARF / debug sections only + symbols strip debug + local symbols + --emit-ir Print LLVM IR to stdout + --target-info Show host target info (arch, triple, ...) + --std-path + Override the standard-library root used to + takes precedence over the JAM_STD_PATH env var + -l, --library + Link against system library + +Examples: + +jam hello.jam # compile to './output' +jam run hello.jam # compile and run +jam run -lncurses tetris.jam # compile, link with ncurses, run +jam help # show help +jam version # show version +jam test # run tests in current working directory +jam test tests/unit # run tests under tests/unit +jam test tests/unit/foo.jam # run tests in a single file"#); +} diff --git a/crates/jam/src/cli/progress.rs b/crates/jam/src/cli/progress.rs new file mode 100644 index 0000000..18ea94c --- /dev/null +++ b/crates/jam/src/cli/progress.rs @@ -0,0 +1,61 @@ +// Terminal progress reporting via OSC 9;4. Supported by ConEmu, +// Rio Terminal, Windows Terminal, iTerm2, WezTerm, Ghostty, etc. + +// 0=remove, 1=normal+percent, 2=error, 3=indeterminate, +// 4=warning. + +// in jam we use 3 during compile, 2 on error, 0 on success. +pub struct ProgressGuard { + active: bool +} + +impl Drop for ProgressGuard { + fn drop(&mut self) { + self.stop(); + } +} + +impl ProgressGuard { + pub fn error(&mut self) { + if self.active { + println!("\033]9;4;2;\033\\"); + self.active = false; + } + } + + pub fn stop(&mut self) { + if self.active { + println!("\033]9;4;0;\033\\"); + self.active = false; + } + + } +} + +// Pr +// public: +// ProgressGuard(bool enabled) { +// if (!enabled) return; +// if (!isatty(STDERR_FILENO)) return; +// active = true; +// std::cerr << "\033]9;4;3;\033\\" << std::flush; +// } +// ~ProgressGuard() { clear(); } + +// void error() { +// if (active) { +// std::cerr << "\033]9;4;2;\033\\" << std::flush; +// active = false; +// } +// } +// // Stop without flagging error — same exit as success. +// void stop() { clear(); } + +// private: +// void clear() { +// if (active) { +// std::cerr << "\033]9;4;0;\033\\" << std::flush; +// active = false; +// } +// } +// }; \ No newline at end of file -- 2.51.2