feat: CLI 可执行 JS 语句输出值

This commit is contained in:
2026-06-05 03:31:48 +08:00
parent 3fa3d0b5b0
commit 9e6cb0f02b
5 changed files with 132 additions and 3 deletions
+1
View File
@@ -13,6 +13,7 @@ path = "src/main.rs"
[dependencies]
oxide_parser = { path = "../oxide_parser" }
oxide_compiler = { path = "../oxide_compiler" }
oxide_vm = { path = "../oxide_vm" }
oxide_api = { path = "../oxide_api" }
clap.workspace = true
rustyline.workspace = true
+13 -3
View File
@@ -5,6 +5,7 @@ use ansi_term::Colour::Red;
use clap::{Parser, Subcommand};
use oxide_compiler::compiler::Compiler;
use oxide_parser::Allocator;
use oxide_vm::vm::Vm;
#[derive(Parser)]
#[command(name = "oxide", version, about = "OxideJS - Rust JavaScript engine")]
@@ -66,9 +67,18 @@ fn eval(code: &str) -> ExitCode {
};
let compiler = Compiler::new();
match compiler.compile(&program) {
Ok(module) => {
print!("{module}");
let module = match compiler.compile(&program) {
Ok(m) => m,
Err(err) => {
eprintln!("{}", Red.paint(err));
return ExitCode::FAILURE;
}
};
let mut vm = Vm::new();
match vm.run(&module) {
Ok(result) => {
println!("{result}");
ExitCode::SUCCESS
}
Err(err) => {