feat(cli): compile 子命令新增 --no-dce flag 透传 Compiler(D-10)

- Commands::Compile 追加 #[arg(long)] no_dce 字段
- compile(expr, file, no_dce) 按 flag 选择 Compiler::new().with_dce(false)
- eval/run/repl 走默认 enable_dce=true 不变
This commit is contained in:
爱特每羊队
2026-08-06 11:48:30 +08:00
parent bbba23b93a
commit 1a235f748b
+5 -3
View File
@@ -49,6 +49,8 @@ enum Commands {
#[arg(short = 'e')]
expr: Option<String>,
file: Option<String>,
#[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<KernelCore>, pool: &Arc<VmPool>) -> ExitCode {
}
}
fn compile(expr: Option<String>, file: Option<String>) -> ExitCode {
fn compile(expr: Option<String>, file: Option<String>, 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<String>, file: Option<String>) -> 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}");