mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
feat: CLI 可执行 JS 语句输出值
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user