From 1a235f748b54cbb8daea5cfed73be27a995a260e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=89=B9=E6=AF=8F=E7=BE=8A=E9=98=9F?= Date: Thu, 6 Aug 2026 11:48:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(cli):=20compile=20=E5=AD=90=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=96=B0=E5=A2=9E=20--no-dce=20flag=20=E9=80=8F?= =?UTF-8?q?=E4=BC=A0=20Compiler=EF=BC=88D-10=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Commands::Compile 追加 #[arg(long)] no_dce 字段 - compile(expr, file, no_dce) 按 flag 选择 Compiler::new().with_dce(false) - eval/run/repl 走默认 enable_dce=true 不变 --- crates/oxide_cli/src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/oxide_cli/src/main.rs b/crates/oxide_cli/src/main.rs index 8fed07b..64b90aa 100644 --- a/crates/oxide_cli/src/main.rs +++ b/crates/oxide_cli/src/main.rs @@ -49,6 +49,8 @@ enum Commands { #[arg(short = 'e')] expr: Option, file: Option, + #[arg(long)] + no_dce: bool, }, Bench { #[arg(default_value = "js")] @@ -94,7 +96,7 @@ fn main() -> ExitCode { } ExitCode::SUCCESS } - Some(Commands::Compile { expr, file }) => compile(expr, file), + Some(Commands::Compile { expr, file, no_dce }) => compile(expr, file, no_dce), Some(Commands::Bench { mode, filter, @@ -259,7 +261,7 @@ fn run(file: &str, kernel: &Arc, pool: &Arc) -> ExitCode { } } -fn compile(expr: Option, file: Option) -> ExitCode { +fn compile(expr: Option, file: Option, no_dce: bool) -> ExitCode { let source = if let Some(code) = expr { code } else if let Some(path) = file { @@ -289,7 +291,7 @@ fn compile(expr: Option, file: Option) -> ExitCode { } }; - let compiler = Compiler::new(); + let compiler = if no_dce { Compiler::new().with_dce(false) } else { Compiler::new() }; match compiler.compile(&program) { Ok(module) => { print!("{module}");