diff --git a/src/backend/llvm_legacy/box_types.rs b/archive/llvm_legacy/box_types.rs similarity index 100% rename from src/backend/llvm_legacy/box_types.rs rename to archive/llvm_legacy/box_types.rs diff --git a/src/backend/llvm_legacy/compiler/mod.rs b/archive/llvm_legacy/compiler/mod.rs similarity index 100% rename from src/backend/llvm_legacy/compiler/mod.rs rename to archive/llvm_legacy/compiler/mod.rs diff --git a/src/backend/llvm_legacy/context.rs b/archive/llvm_legacy/context.rs similarity index 100% rename from src/backend/llvm_legacy/context.rs rename to archive/llvm_legacy/context.rs diff --git a/src/backend/llvm_legacy/mod.rs b/archive/llvm_legacy/mod.rs similarity index 100% rename from src/backend/llvm_legacy/mod.rs rename to archive/llvm_legacy/mod.rs diff --git a/src/benchmarks.rs b/src/benchmarks.rs index 6a2d6900..e1d0b48b 100644 --- a/src/benchmarks.rs +++ b/src/benchmarks.rs @@ -9,13 +9,9 @@ #[cfg(feature = "wasm-backend")] use crate::backend::WasmBackend; -#[cfg(feature = "vm-legacy")] -use crate::backend::VM; -// use crate::interpreter::NyashInterpreter; // Legacy interpreter removed -// use crate::mir::MirCompiler; // not used in Phase-15 (PyVM primary) -use crate::parser::NyashParser; +// VM import removed with vm-legacy +// Interpreter and MirCompiler removed use std::fs; -use std::time::Instant; #[derive(Debug)] pub struct BenchmarkResult { @@ -51,15 +47,9 @@ impl BenchmarkSuite { // Test if file exists and is readable if let Ok(source) = fs::read_to_string(file_path) { // Run on all backends - // Interpreter benchmark disabled - legacy interpreter removed - // if let Ok(interpreter_result) = self.run_interpreter_benchmark(name, &source) { - // results.push(interpreter_result); - // } + // Interpreter benchmark removed with legacy interpreter - #[cfg(feature = "vm-legacy")] - if let Ok(vm_result) = self.run_vm_benchmark(name, &source) { - results.push(vm_result); - } + // VM benchmark removed with vm-legacy #[cfg(feature = "wasm-backend")] if let Ok(wasm_result) = self.run_wasm_benchmark(name, &source) { @@ -73,78 +63,16 @@ impl BenchmarkSuite { results } - /// Run benchmark on interpreter backend (DISABLED - legacy interpreter removed) + // Interpreter benchmark removed with legacy interpreter + + // VM benchmark removed with vm-legacy #[allow(dead_code)] - fn run_interpreter_benchmark( + fn run_vm_benchmark( &self, _name: &str, _source: &str, ) -> Result> { - Err("Interpreter benchmark disabled - legacy interpreter removed".into()) - - /* - let mut total_duration = 0.0; - - for i in 0..self.iterations { - let start = Instant::now(); - - // Parse and execute - let ast = NyashParser::parse_from_string(source)?; - let mut interpreter = NyashInterpreter::new(); - let _result = interpreter.execute(ast)?; - - let duration = start.elapsed(); - total_duration += duration.as_secs_f64() * 1000.0; // Convert to ms - - if i == 0 { - println!(" ๐Ÿ“Š Interpreter: First run completed"); - } - } - - Ok(BenchmarkResult { - name: name.to_string(), - backend: "Interpreter".to_string(), - duration_ms: total_duration, - iterations: self.iterations, - avg_duration_ms: total_duration / (self.iterations as f64), - }) - */ - } - - /// Run benchmark on VM backend - #[cfg(feature = "vm-legacy")] - fn run_vm_benchmark( - &self, - name: &str, - source: &str, - ) -> Result> { - let mut total_duration = 0.0; - - for i in 0..self.iterations { - let start = Instant::now(); - - // Parse -> MIR -> VM - let ast = NyashParser::parse_from_string(source)?; - let mut compiler = MirCompiler::new(); - let compile_result = compiler.compile(ast)?; - let mut vm = VM::new(); - let _result = vm.execute_module(&compile_result.module)?; - - let duration = start.elapsed(); - total_duration += duration.as_secs_f64() * 1000.0; // Convert to ms - - if i == 0 { - println!(" ๐ŸŽ๏ธ VM: First run completed"); - } - } - - Ok(BenchmarkResult { - name: name.to_string(), - backend: "VM".to_string(), - duration_ms: total_duration, - iterations: self.iterations, - avg_duration_ms: total_duration / (self.iterations as f64), - }) + Err("VM benchmark removed with vm-legacy".into()) } /// Run benchmark on WASM backend diff --git a/src/instance_v2.rs b/src/instance_v2.rs index 2e809e94..5f6f1911 100644 --- a/src/instance_v2.rs +++ b/src/instance_v2.rs @@ -12,7 +12,6 @@ use crate::ast::ASTNode; use crate::box_trait::{BoolBox, BoxBase, BoxCore, NyashBox, SharedNyashBox, StringBox}; -// use crate::interpreter::NyashInterpreter; // ใƒฌใ‚ฌใ‚ทใƒผไบ’ๆ›็”จ - removed use crate::value::NyashValue; use std::any::Any; use std::collections::HashMap; diff --git a/src/jit_stub.rs b/src/jit_stub.rs deleted file mode 100644 index 6ad8640b..00000000 --- a/src/jit_stub.rs +++ /dev/null @@ -1,134 +0,0 @@ -//! JIT stub module for Phase 15 compilation compatibility -//! -//! This is a temporary stub to maintain compilation compatibility while -//! JIT/Cranelift is archived. All functions return safe defaults or no-op. - -pub mod config { - #[derive(Debug, Clone, Default)] - pub struct JitConfig { - pub exec: bool, - pub stats: bool, - pub stats_json: bool, - pub dump: bool, - pub threshold: Option, - pub phi_min: bool, - pub hostcall: bool, - pub handle_debug: bool, - pub native_f64: bool, - pub native_bool: bool, - pub native_bool_abi: bool, - } - - impl JitConfig { - pub fn from_env() -> Self { - Self::default() - } - - pub fn apply_env(&self) { - // No-op - } - } - - #[derive(Debug, Clone, Default)] - pub struct Capabilities { - pub supports_b1_sig: bool, - } - - pub fn probe_capabilities() -> Capabilities { - Capabilities::default() - } - - pub fn apply_runtime_caps(config: JitConfig, _caps: Capabilities) -> JitConfig { - config - } - - pub fn set_current(_config: JitConfig) { - // No-op - } - - pub fn current() -> JitConfig { - JitConfig::default() - } -} - -pub mod policy { - pub fn current() -> () { - // Return empty policy - } -} - -pub mod engine { - pub struct JitEngine; - - impl JitEngine { - pub fn new() -> Self { - Self - } - - pub fn last_lower_stats(&self) -> (u64, u64, u64) { - (0, 0, 0) // Return default stats: phi_t, phi_b1, ret_b - } - } -} - -pub mod events { - pub fn emit(_category: &str, _name: &str, _h: Option, _none: Option<()>, _data: serde_json::Value) { - // No-op - JIT events disabled for Phase 15 - } - - pub fn emit_lower(_data: serde_json::Value, _category: &str, _source: &str) { - // No-op - JIT events disabled for Phase 15 - } -} - -pub mod abi { - #[derive(Debug, Clone)] - pub enum JitValue { - I64(i64), - F64(f64), - Bool(bool), - Handle(i64), - } - - pub mod adapter { - use crate::NyashValue; - use super::JitValue; - - pub fn from_jit_value(_value: &JitValue) -> NyashValue { - NyashValue::Void - } - } -} - -pub mod rt { - use super::abi::JitValue; - - pub fn set_current_jit_args(_args: &[JitValue]) { - // No-op - } - - pub fn b1_norm_get() -> u64 { - 0 - } - - pub fn ret_bool_hint_get() -> u64 { - 0 - } - - pub mod handles { - use std::sync::Arc; - use crate::box_trait::NyashBox; - - pub fn to_handle(_boxref: Arc) -> i64 { - 0 - } - - pub fn get(_handle: i64) -> Option> { - None - } - - pub fn snapshot_arcs() -> Vec> { - Vec::new() - } - } -} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index e3495ed6..115ad53c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,8 +10,6 @@ extern crate self as nyash_rust; #[cfg(target_arch = "wasm32")] use wasm_bindgen::prelude::*; -// Legacy interpreter removed - pub mod ast; // using historical ast.rs pub mod box_arithmetic; pub mod box_factory; // unified Box Factory @@ -24,7 +22,6 @@ pub mod environment; pub mod exception_box; pub mod finalization; pub mod instance_v2; // simplified InstanceBox implementation -// pub mod interpreter removed - legacy interpreter deleted pub mod method_box; pub mod operator_traits; // trait-based operator overloading pub mod parser; // using historical parser.rs @@ -47,9 +44,7 @@ pub mod mir_aot_plan_import { // Backends pub mod backend; -// pub mod jit; // ARCHIVED: Cranelift JIT subsystem moved to archive/jit-cranelift/ -pub mod jit_stub; // Temporary JIT stub for Phase 15 compilation compatibility -pub use jit_stub as jit; // Alias for compatibility +// JIT functionality archived to archive/jit-cranelift/ pub mod semantics; // Unified semantics trait for MIR evaluation/lowering pub mod benchmarks; @@ -93,7 +88,6 @@ pub use box_factory::RuntimeError; pub use parser::{NyashParser, ParseError}; pub use tokenizer::{NyashTokenizer, Token, TokenType}; pub use type_box::{MethodSignature, TypeBox, TypeRegistry}; // ๐ŸŒŸ TypeBox exports - // pub use instance::InstanceBox; // ๆ—งๅฎŸ่ฃ… pub use boxes::console_box::ConsoleBox; pub use boxes::debug_box::DebugBox; pub use boxes::map_box::MapBox; @@ -108,5 +102,4 @@ pub use method_box::{BoxType, EphemeralInstance, FunctionDefinition, MethodBox}; pub use value::NyashValue; -// WASM support temporarily disabled - legacy interpreter removed -// TODO: Implement WASM support using VM or LLVM backends +// WASM support to be reimplemented with VM/LLVM backends diff --git a/src/runner/mod.rs b/src/runner/mod.rs index 35cfa4c0..bb280a0d 100644 --- a/src/runner/mod.rs +++ b/src/runner/mod.rs @@ -217,53 +217,17 @@ impl NyashRunner { // init_runtime_and_plugins moved to runner/plugins.rs - /// Configure backend knobs (VM/JIT) from CLI flags and env, merging with runtime capabilities. - /// Side effects: writes environment variables for flags and applies JIT config via nyash_rust::jit::config. + /// Configure backend knobs (VM) from CLI flags and env. + /// JIT configuration removed with JIT/Cranelift archival. fn configure_backend(&self, groups: &crate::cli::CliGroups) { if groups.backend.vm_stats { std::env::set_var("NYASH_VM_STATS", "1"); } if groups.backend.vm_stats_json { std::env::set_var("NYASH_VM_STATS_JSON", "1"); } - { - if groups.backend.jit.events { std::env::set_var("NYASH_JIT_EVENTS", "1"); } - if groups.backend.jit.events_compile { std::env::set_var("NYASH_JIT_EVENTS_COMPILE", "1"); } - if groups.backend.jit.events_runtime { std::env::set_var("NYASH_JIT_EVENTS_RUNTIME", "1"); } - if let Some(ref p) = groups.backend.jit.events_path { std::env::set_var("NYASH_JIT_EVENTS_PATH", p); } - let mut jc = nyash_rust::jit::config::JitConfig::from_env(); - jc.exec |= groups.backend.jit.exec; - jc.stats |= groups.backend.jit.stats; - jc.stats_json |= groups.backend.jit.stats_json; - jc.dump |= groups.backend.jit.dump; - if groups.backend.jit.threshold.is_some() { jc.threshold = groups.backend.jit.threshold; } - jc.phi_min |= groups.backend.jit.phi_min; - jc.hostcall |= groups.backend.jit.hostcall; - jc.handle_debug |= groups.backend.jit.handle_debug; - jc.native_f64 |= groups.backend.jit.native_f64; - jc.native_bool |= groups.backend.jit.native_bool; - let events_on = std::env::var("NYASH_JIT_EVENTS").ok().as_deref() == Some("1") - || std::env::var("NYASH_JIT_EVENTS_COMPILE").ok().as_deref() == Some("1") - || std::env::var("NYASH_JIT_EVENTS_RUNTIME").ok().as_deref() == Some("1"); - if events_on && jc.threshold.is_none() { jc.threshold = Some(1); } - if groups.backend.jit.only { std::env::set_var("NYASH_JIT_ONLY", "1"); } - let caps = nyash_rust::jit::config::probe_capabilities(); - jc = nyash_rust::jit::config::apply_runtime_caps(jc, caps); - if let Some(path) = &groups.emit.emit_cfg { std::env::set_var("NYASH_JIT_DOT", path); jc.dump = true; } - jc.apply_env(); - nyash_rust::jit::config::set_current(jc.clone()); - } - if std::env::var("NYASH_JIT_STRICT").ok().as_deref() == Some("1") { - if std::env::var("NYASH_JIT_ARGS_HANDLE_ONLY").ok().is_none() { std::env::set_var("NYASH_JIT_ARGS_HANDLE_ONLY", "1"); } - if std::env::var("NYASH_JIT_ONLY").ok().is_none() { std::env::set_var("NYASH_JIT_ONLY", "1"); } - } + // JIT configuration removed - archived to archive/jit-cranelift/ } - /// Enforce runtime policy for JIT execution when AOT object output is absent. - /// Side effects: may set `NYASH_JIT_EXEC=0` when policy requires. - fn enforce_runtime_jit_policy(&self, groups: &crate::cli::CliGroups) { - if !groups.compile_native && !groups.backend.jit.direct { - let aot_obj = std::env::var("NYASH_AOT_OBJECT_OUT").ok(); - if aot_obj.is_none() || aot_obj.as_deref() == Some("") { - std::env::set_var("NYASH_JIT_EXEC", "0"); - } - } + /// JIT runtime policy enforcement removed with JIT/Cranelift archival. + fn enforce_runtime_jit_policy(&self, _groups: &crate::cli::CliGroups) { + // JIT policy enforcement removed - archived to archive/jit-cranelift/ } /// Optionally run the benchmark suite and exit, depending on CLI flags. @@ -274,10 +238,9 @@ impl NyashRunner { println!("===================================="); println!("Running {} iterations per test...", groups.iterations); println!(); - #[cfg(feature = "vm-legacy")] - { self.execute_benchmark_mode(); return true; } - #[cfg(not(feature = "vm-legacy"))] - { eprintln!("โŒ Benchmark mode requires VM backend. Rebuild with --features vm-legacy."); std::process::exit(1); } + // VM-legacy removed - benchmark mode no longer available + eprintln!("โŒ Benchmark mode removed with vm-legacy. Use regular execution modes instead."); + std::process::exit(1); } false } @@ -299,373 +262,8 @@ impl NyashRunner { eprintln!(" Use VM backend instead: nyash {}", filename); eprintln!(" Or use LLVM backend: nyash --backend llvm {}", filename); std::process::exit(1); - - // Original JIT implementation archived - commented out for Phase 15 - /* - use nyash_rust::{mir::MirCompiler, parser::NyashParser}; - use std::fs; - // Small helper for unified error output (text or JSON) - let emit_err = |phase: &str, code: &str, msg: &str| { - if std::env::var("NYASH_JIT_STATS_JSON").ok().as_deref() == Some("1") - || std::env::var("NYASH_JIT_ERROR_JSON").ok().as_deref() == Some("1") - { - let payload = serde_json::json!({ - "kind": "jit_direct_error", - "phase": phase, - "code": code, - "message": msg, - "file": filename, - }); - println!("{}", payload.to_string()); - } else { - eprintln!("[JIT-direct][{}][{}] {}", phase, code, msg); - } - }; - // Require cranelift feature at runtime by attempting compile; if unavailable compile_function returns None - let code = match fs::read_to_string(filename) { - Ok(s) => s, - Err(e) => { - emit_err("read_file", "IO", &format!("{}", e)); - std::process::exit(1); - } - }; - let ast = match NyashParser::parse_from_string(&code) { - Ok(a) => a, - Err(e) => { - emit_err("parse", "SYNTAX", &format!("{}", e)); - std::process::exit(1); - } - }; - let mut mc = MirCompiler::new(); - let cr = match mc.compile(ast) { - Ok(m) => m, - Err(e) => { - emit_err("mir", "MIR_COMPILE", &format!("{}", e)); - std::process::exit(1); - } - }; - let func = match cr.module.functions.get("main") { - Some(f) => f, - None => { - emit_err("mir", "NO_MAIN", "No main function found"); - std::process::exit(1); - } - }; - - // Guard: refuse write-effects in jit-direct when policy.read_only - { - use nyash_rust::mir::effect::Effect; - let policy = nyash_rust::jit::policy::current(); - let mut writes = 0usize; - for (_bbid, bb) in func.blocks.iter() { - for inst in bb.instructions.iter() { - let mask = inst.effects(); - if mask.contains(Effect::WriteHeap) { - writes += 1; - } - } - if let Some(term) = &bb.terminator { - if term.effects().contains(Effect::WriteHeap) { - writes += 1; - } - } - } - if policy.read_only && writes > 0 { - emit_err( - "policy", - "WRITE_EFFECTS", - &format!( - "write-effects detected ({} ops). jit-direct is read-only at this stage.", - writes - ), - ); - std::process::exit(1); - } - } - - // jit-direct ๅฎ‰ๅฎšๅŒ–: ๅˆ†ๅฒๅˆๆต(PHI)ใฏๆ˜Ž็คบใƒ–ใƒญใƒƒใ‚ฏๅผ•ๆ•ฐใง้…็ทš - { - let mut cfg = nyash_rust::jit::config::current(); - cfg.phi_min = true; // enable multi-PHI arg passing/join - nyash_rust::jit::config::set_current(cfg); - } - // Prepare minimal runtime hooks so JIT externs (checkpoint/await) can reach GC/scheduler - { - let rt = nyash_rust::runtime::NyashRuntime::new(); - nyash_rust::runtime::global_hooks::set_from_runtime(&rt); - } - let mut engine = nyash_rust::jit::engine::JitEngine::new(); - match engine.compile_function("main", func) { - Some(h) => { - // Optional event: compile - nyash_rust::jit::events::emit( - "compile", - &func.signature.name, - Some(h), - None, - serde_json::json!({}), - ); - // Parse JIT args from env: NYASH_JIT_ARGS (comma-separated), with optional type prefixes - // Formats per arg: i:123, f:3.14, b:true/false, h:42 (handle), or bare numbers (int), true/false (bool) - let mut jit_args: Vec = Vec::new(); - if let Ok(s) = std::env::var("NYASH_JIT_ARGS") { - for raw in s.split(',') { - let t = raw.trim(); - if t.is_empty() { - continue; - } - let v = if let Some(rest) = t.strip_prefix("i:") { - rest.parse::() - .ok() - .map(nyash_rust::jit::abi::JitValue::I64) - } else if let Some(rest) = t.strip_prefix("f:") { - rest.parse::() - .ok() - .map(nyash_rust::jit::abi::JitValue::F64) - } else if let Some(rest) = t.strip_prefix("b:") { - let b = matches!(rest, "1" | "true" | "True" | "TRUE"); - Some(nyash_rust::jit::abi::JitValue::Bool(b)) - } else if let Some(rest) = t.strip_prefix("h:") { - rest.parse::() - .ok() - .map(nyash_rust::jit::abi::JitValue::Handle) - } else if t.eq_ignore_ascii_case("true") || t == "1" { - Some(nyash_rust::jit::abi::JitValue::Bool(true)) - } else if t.eq_ignore_ascii_case("false") || t == "0" { - Some(nyash_rust::jit::abi::JitValue::Bool(false)) - } else if let Ok(iv) = t.parse::() { - Some(nyash_rust::jit::abi::JitValue::I64(iv)) - } else if let Ok(fv) = t.parse::() { - Some(nyash_rust::jit::abi::JitValue::F64(fv)) - } else { - None - }; - if let Some(jv) = v { - jit_args.push(jv); - } - } - } - // Coerce args to expected MIR types - use nyash_rust::mir::MirType; - let expected = &func.signature.params; - if expected.len() != jit_args.len() { - emit_err( - "args", - "COUNT_MISMATCH", - &format!("expected={}, passed={}", expected.len(), jit_args.len()), - ); - eprintln!("Hint: set NYASH_JIT_ARGS as comma-separated values, e.g., i:42,f:3.14,b:true"); - std::process::exit(1); - } - let mut coerced: Vec = - Vec::with_capacity(jit_args.len()); - for (i, (exp, got)) in expected.iter().zip(jit_args.iter()).enumerate() { - let cv = match exp { - MirType::Integer => match got { - nyash_rust::jit::abi::JitValue::I64(v) => { - nyash_rust::jit::abi::JitValue::I64(*v) - } - nyash_rust::jit::abi::JitValue::F64(f) => { - nyash_rust::jit::abi::JitValue::I64(*f as i64) - } - nyash_rust::jit::abi::JitValue::Bool(b) => { - nyash_rust::jit::abi::JitValue::I64(if *b { 1 } else { 0 }) - } - _ => { - emit_err( - "args", - "TYPE_MISMATCH", - &format!("param#{} expects Integer", i), - ); - std::process::exit(1); - } - }, - MirType::Float => match got { - nyash_rust::jit::abi::JitValue::F64(f) => { - nyash_rust::jit::abi::JitValue::F64(*f) - } - nyash_rust::jit::abi::JitValue::I64(v) => { - nyash_rust::jit::abi::JitValue::F64(*v as f64) - } - nyash_rust::jit::abi::JitValue::Bool(b) => { - nyash_rust::jit::abi::JitValue::F64(if *b { 1.0 } else { 0.0 }) - } - _ => { - emit_err( - "args", - "TYPE_MISMATCH", - &format!("param#{} expects Float", i), - ); - std::process::exit(1); - } - }, - MirType::Bool => match got { - nyash_rust::jit::abi::JitValue::Bool(b) => { - nyash_rust::jit::abi::JitValue::Bool(*b) - } - nyash_rust::jit::abi::JitValue::I64(v) => { - nyash_rust::jit::abi::JitValue::Bool(*v != 0) - } - nyash_rust::jit::abi::JitValue::F64(f) => { - nyash_rust::jit::abi::JitValue::Bool(*f != 0.0) - } - _ => { - emit_err( - "args", - "TYPE_MISMATCH", - &format!("param#{} expects Bool", i), - ); - std::process::exit(1); - } - }, - MirType::String - | MirType::Box(_) - | MirType::Array(_) - | MirType::Future(_) => match got { - nyash_rust::jit::abi::JitValue::Handle(h) => { - nyash_rust::jit::abi::JitValue::Handle(*h) - } - _ => { - emit_err( - "args", - "TYPE_MISMATCH", - &format!("param#{} expects handle (h:)", i), - ); - std::process::exit(1); - } - }, - MirType::Void | MirType::Unknown => { - // Keep as-is - *got - } - }; - coerced.push(cv); - } - nyash_rust::jit::rt::set_current_jit_args(&coerced); - let t0 = std::time::Instant::now(); - let out = engine.execute_handle(h, &coerced); - match out { - Some(v) => { - let ms = t0.elapsed().as_millis(); - nyash_rust::jit::events::emit( - "execute", - &func.signature.name, - Some(h), - Some(ms), - serde_json::json!({}), - ); - // Normalize result according to MIR return type for friendly output - use nyash_rust::mir::MirType; - let ret_ty = &func.signature.return_type; - let vmv = match (ret_ty, v) { - (MirType::Bool, nyash_rust::jit::abi::JitValue::I64(i)) => { - nyash_rust::backend::vm::VMValue::Bool(i != 0) - } - (MirType::Bool, nyash_rust::jit::abi::JitValue::Bool(b)) => { - nyash_rust::backend::vm::VMValue::Bool(b) - } - (MirType::Float, nyash_rust::jit::abi::JitValue::F64(f)) => { - nyash_rust::backend::vm::VMValue::Float(f) - } - (MirType::Float, nyash_rust::jit::abi::JitValue::I64(i)) => { - nyash_rust::backend::vm::VMValue::Float(i as f64) - } - // Default adapter for other combos - _ => nyash_rust::jit::abi::adapter::from_jit_value(v), - }; - println!("โœ… JIT-direct execution completed successfully!"); - // Pretty print with expected type tag - let (ety, sval) = match (ret_ty, &vmv) { - (MirType::Bool, nyash_rust::backend::vm::VMValue::Bool(b)) => { - ("Bool", b.to_string()) - } - (MirType::Float, nyash_rust::backend::vm::VMValue::Float(f)) => { - ("Float", format!("{}", f)) - } - (MirType::Integer, nyash_rust::backend::vm::VMValue::Integer(i)) => { - ("Integer", i.to_string()) - } - // Fallbacks - (_, nyash_rust::backend::vm::VMValue::Integer(i)) => { - ("Integer", i.to_string()) - } - (_, nyash_rust::backend::vm::VMValue::Float(f)) => { - ("Float", format!("{}", f)) - } - (_, nyash_rust::backend::vm::VMValue::Bool(b)) => { - ("Bool", b.to_string()) - } - (_, nyash_rust::backend::vm::VMValue::String(s)) => { - ("String", s.clone()) - } - (_, nyash_rust::backend::vm::VMValue::BoxRef(arc)) => { - ("BoxRef", arc.type_name().to_string()) - } - (_, nyash_rust::backend::vm::VMValue::Future(_)) => { - ("Future", "".to_string()) - } - (_, nyash_rust::backend::vm::VMValue::Void) => { - ("Void", "void".to_string()) - } - }; - println!("ResultType(MIR): {}", ety); - println!("Result: {}", sval); - // Optional JSON stats - if std::env::var("NYASH_JIT_STATS_JSON").ok().as_deref() == Some("1") { - let cfg = nyash_rust::jit::config::current(); - let caps = nyash_rust::jit::config::probe_capabilities(); - let (phi_t, phi_b1, ret_b) = engine.last_lower_stats(); - let abi_mode = if cfg.native_bool_abi && caps.supports_b1_sig { - "b1_bool" - } else { - "i64_bool" - }; - let payload = serde_json::json!({ - "version": 1, - "function": func.signature.name, - "abi_mode": abi_mode, - "abi_b1_enabled": cfg.native_bool_abi, - "abi_b1_supported": caps.supports_b1_sig, - "b1_norm_count": nyash_rust::jit::rt::b1_norm_get(), - "ret_bool_hint_count": nyash_rust::jit::rt::ret_bool_hint_get(), - "phi_total_slots": phi_t, - "phi_b1_slots": phi_b1, - "ret_bool_hint_used": ret_b, - }); - println!("{}", payload.to_string()); - } - } - None => { - nyash_rust::jit::events::emit( - "fallback", - &func.signature.name, - Some(h), - None, - serde_json::json!({"reason":"trap_or_missing"}), - ); - emit_err( - "execute", - "TRAP_OR_MISSING", - "execution failed (trap or missing handle)", - ); - std::process::exit(1); - } - } - } - None => { - emit_err( - "compile", - "UNAVAILABLE", - "Build with --features cranelift-jit", - ); - std::process::exit(1); - } - } - */ // End of archived JIT implementation } } - -// Demo functions (moved from main.rs) // moved to demos.rs // moved to demos.rs diff --git a/src/runner/modes/mod.rs b/src/runner/modes/mod.rs index 27c170b8..abf70fb9 100644 --- a/src/runner/modes/mod.rs +++ b/src/runner/modes/mod.rs @@ -1,10 +1,8 @@ -#[cfg(feature = "vm-legacy")] -pub mod bench; +// bench module removed with vm-legacy pub mod llvm; pub mod mir; pub mod vm_fallback; -#[cfg(feature = "vm-legacy")] -pub mod vm; +// vm module removed with vm-legacy pub mod pyvm; pub mod macro_child; diff --git a/src/runtime/host_api.rs b/src/runtime/host_api.rs index 3ee26c9a..17dc158b 100644 --- a/src/runtime/host_api.rs +++ b/src/runtime/host_api.rs @@ -10,48 +10,9 @@ use crate::box_trait::NyashBox; // ===== TLS: current VM pointer during plugin invoke ===== -// When legacy VM is enabled, keep a real pointer for write barriers. -#[cfg(feature = "vm-legacy")] -thread_local! { - static CURRENT_VM: std::cell::Cell<*mut crate::backend::vm::VM> = std::cell::Cell::new(std::ptr::null_mut()); -} -#[cfg(feature = "vm-legacy")] -pub fn set_current_vm(ptr: *mut crate::backend::vm::VM) { - CURRENT_VM.with(|c| c.set(ptr)); -} -#[cfg(feature = "vm-legacy")] -pub fn clear_current_vm() { - CURRENT_VM.with(|c| c.set(std::ptr::null_mut())); -} -#[cfg(feature = "vm-legacy")] -#[allow(dead_code)] -fn with_current_vm_mut(f: F) -> Option -where - F: FnOnce(&mut crate::backend::vm::VM) -> R, -{ - CURRENT_VM.with(|c| { - let p = c.get(); - if p.is_null() { - None - } else { - Some(unsafe { f(&mut *p) }) - } - }) -} - -// When legacy VM is disabled, provide stubs (no GC barriers). -#[cfg(not(feature = "vm-legacy"))] +// VM-legacy feature removed - provide stubs only pub fn set_current_vm(_ptr: *mut ()) {} -#[cfg(not(feature = "vm-legacy"))] pub fn clear_current_vm() {} -#[cfg(not(feature = "vm-legacy"))] -#[allow(dead_code)] -fn with_current_vm_mut(_f: F) -> Option -where - F: FnOnce(&mut ()) -> R, -{ - None -} // ===== Utilities: TLV encode helpers (single-value) ===== fn tlv_encode_one(val: &crate::backend::vm::VMValue) -> Vec { @@ -220,16 +181,7 @@ pub extern "C" fn nyrt_host_call_name( crate::backend::vm::VMValue::String(s) => s.clone(), v => v.to_string(), }; - // Barrier: use current VM runtime if available - #[cfg(feature = "vm-legacy")] - { - let _ = with_current_vm_mut(|vm| { - crate::backend::gc_helpers::gc_write_barrier_site( - vm.runtime_ref(), - "HostAPI.setField", - ); - }); - } + // VM-legacy removed - no GC barrier needed // Accept primitives only for now let nv_opt = match argv[1].clone() { crate::backend::vm::VMValue::Integer(i) => { @@ -291,15 +243,7 @@ pub extern "C" fn nyrt_host_call_name( crate::backend::vm::VMValue::BoxRef(b) => b.share_box(), _ => Box::new(crate::box_trait::VoidBox::new()), }; - #[cfg(feature = "vm-legacy")] - { - let _ = with_current_vm_mut(|vm| { - crate::backend::gc_helpers::gc_write_barrier_site( - vm.runtime_ref(), - "HostAPI.Array.set", - ); - }); - } + // VM-legacy removed - no GC barrier needed let out = arr.set(Box::new(crate::box_trait::IntegerBox::new(idx)), vb); let vmv = crate::backend::vm::VMValue::from_nyash_box(out); let buf = tlv_encode_one(&vmv); @@ -428,15 +372,7 @@ pub extern "C" fn nyrt_host_call_slot( crate::backend::vm::VMValue::String(s) => s.clone(), v => v.to_string(), }; - #[cfg(feature = "vm-legacy")] - { - let _ = with_current_vm_mut(|vm| { - crate::backend::gc_helpers::gc_write_barrier_site( - vm.runtime_ref(), - "HostAPI.setField", - ); - }); - } + // VM-legacy removed - no GC barrier needed let nv_opt = match argv[1].clone() { crate::backend::vm::VMValue::Integer(i) => { Some(crate::value::NyashValue::Integer(i)) @@ -521,15 +457,7 @@ pub extern "C" fn nyrt_host_call_slot( crate::backend::vm::VMValue::BoxRef(b) => b.share_box(), _ => Box::new(crate::box_trait::VoidBox::new()), }; - #[cfg(feature = "vm-legacy")] - { - let _ = with_current_vm_mut(|vm| { - crate::backend::gc_helpers::gc_write_barrier_site( - vm.runtime_ref(), - "HostAPI.Array.set", - ); - }); - } + // VM-legacy removed - no GC barrier needed let out = arr.set(Box::new(crate::box_trait::IntegerBox::new(idx)), vb); let vmv = crate::backend::vm::VMValue::from_nyash_box(out); let buf = tlv_encode_one(&vmv);