2025-09-17 16:11:01 +09:00
|
|
|
use super::super::NyashRunner;
|
|
|
|
|
use nyash_rust::{mir::MirCompiler, parser::NyashParser};
|
|
|
|
|
use std::{fs, process};
|
|
|
|
|
|
|
|
|
|
/// Execute using PyVM only (no Rust VM runtime). Emits MIR(JSON) and invokes tools/pyvm_runner.py.
|
2025-09-21 08:53:00 +09:00
|
|
|
pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
|
2025-09-17 16:11:01 +09:00
|
|
|
// Read the file
|
|
|
|
|
let code = match fs::read_to_string(filename) {
|
|
|
|
|
Ok(content) => content,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
eprintln!("❌ Error reading file {}: {}", filename, e);
|
|
|
|
|
process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-21 08:53:00 +09:00
|
|
|
// Optional using pre-processing (strip lines and register modules)
|
|
|
|
|
let code = if crate::config::env::enable_using() {
|
|
|
|
|
match crate::runner::modes::common_util::resolve::strip_using_and_register(runner, &code, filename) {
|
|
|
|
|
Ok(s) => s,
|
|
|
|
|
Err(e) => { eprintln!("❌ {}", e); process::exit(1); }
|
|
|
|
|
}
|
|
|
|
|
} else { code };
|
|
|
|
|
|
2025-09-17 16:11:01 +09:00
|
|
|
// Parse to AST
|
|
|
|
|
let ast = match NyashParser::parse_from_string(&code) {
|
|
|
|
|
Ok(ast) => ast,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
eprintln!("❌ Parse error: {}", e);
|
|
|
|
|
process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-09-19 22:27:59 +09:00
|
|
|
let ast = crate::r#macro::maybe_expand_and_dump(&ast, false);
|
2025-09-20 08:39:40 +09:00
|
|
|
let ast = crate::runner::modes::macro_child::normalize_core_pass(&ast);
|
2025-09-17 16:11:01 +09:00
|
|
|
|
|
|
|
|
// Compile to MIR (respect default optimizer setting)
|
|
|
|
|
let mut mir_compiler = MirCompiler::with_options(true);
|
|
|
|
|
let mut compile_result = match mir_compiler.compile(ast) {
|
|
|
|
|
Ok(result) => result,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
eprintln!("❌ MIR compilation error: {}", e);
|
|
|
|
|
process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Optional: VM-only escape analysis elision pass retained for parity with VM path
|
|
|
|
|
if std::env::var("NYASH_VM_ESCAPE_ANALYSIS").ok().as_deref() == Some("1") {
|
|
|
|
|
let removed = nyash_rust::mir::passes::escape::escape_elide_barriers_vm(&mut compile_result.module);
|
2025-09-19 02:07:38 +09:00
|
|
|
if removed > 0 { crate::cli_v!("[PyVM] escape_elide_barriers: removed {} barriers", removed); }
|
2025-09-17 16:11:01 +09:00
|
|
|
}
|
|
|
|
|
|
2025-09-19 02:07:38 +09:00
|
|
|
// Delegate to common PyVM harness
|
|
|
|
|
match crate::runner::modes::common_util::pyvm::run_pyvm_harness_lib(&compile_result.module, "pyvm") {
|
|
|
|
|
Ok(code) => { process::exit(code); }
|
|
|
|
|
Err(e) => { eprintln!("❌ PyVM error: {}", e); process::exit(1); }
|
2025-09-17 16:11:01 +09:00
|
|
|
}
|
|
|
|
|
}
|