diff --git a/Cargo.toml b/Cargo.toml index fac93b2a..bfde35b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ gui = ["dep:egui", "dep:eframe", "dep:egui_extras", "dep:image"] gui-examples = ["gui"] all-examples = ["gui-examples"] dynamic-file = [] +wasm-backend = ["dep:wasmtime", "dep:wabt"] # Note: LLVM feature requires inkwell dependency and LLVM development libraries # llvm = ["dep:inkwell"] @@ -120,9 +121,9 @@ wasm-bindgen = "0.2" console_error_panic_hook = "0.1" js-sys = "0.3" -# WASM backend dependencies (Phase 8) -wabt = "0.10" -wasmtime = "35.0.0" +# WASM backend dependencies (Phase 8) - optional for faster builds +wabt = { version = "0.10", optional = true } +wasmtime = { version = "35.0.0", optional = true } # GUI フレームワーク - only when gui feature is enabled egui = { version = "0.29", optional = true } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index e6990315..ddd60e95 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -4,14 +4,20 @@ pub mod vm; pub mod vm_phi; + +#[cfg(feature = "wasm-backend")] pub mod wasm; +#[cfg(feature = "wasm-backend")] pub mod aot; #[cfg(feature = "llvm")] pub mod llvm; pub use vm::{VM, VMError, VMValue}; + +#[cfg(feature = "wasm-backend")] pub use wasm::{WasmBackend, WasmError}; +#[cfg(feature = "wasm-backend")] pub use aot::{AotBackend, AotError, AotConfig, AotStats}; #[cfg(feature = "llvm")] diff --git a/src/benchmarks.rs b/src/benchmarks.rs index ddab2be6..dc1c1ca9 100644 --- a/src/benchmarks.rs +++ b/src/benchmarks.rs @@ -12,7 +12,9 @@ use std::fs; use crate::parser::NyashParser; use crate::interpreter::NyashInterpreter; use crate::mir::MirCompiler; -use crate::backend::{VM, WasmBackend}; +use crate::backend::VM; +#[cfg(feature = "wasm-backend")] +use crate::backend::WasmBackend; #[derive(Debug)] pub struct BenchmarkResult { @@ -56,6 +58,7 @@ impl BenchmarkSuite { results.push(vm_result); } + #[cfg(feature = "wasm-backend")] if let Ok(wasm_result) = self.run_wasm_benchmark(name, &source) { results.push(wasm_result); } @@ -128,6 +131,7 @@ impl BenchmarkSuite { } /// Run benchmark on WASM backend + #[cfg(feature = "wasm-backend")] fn run_wasm_benchmark(&self, name: &str, source: &str) -> Result> { let mut total_duration = 0.0; diff --git a/src/box_factory/builtin.rs b/src/box_factory/builtin.rs index ab74a1f1..b48336b7 100644 --- a/src/box_factory/builtin.rs +++ b/src/box_factory/builtin.rs @@ -7,7 +7,7 @@ use super::BoxFactory; use crate::box_trait::NyashBox; -use crate::RuntimeError; +use crate::interpreter::RuntimeError; use crate::boxes::*; use std::collections::HashMap; diff --git a/src/box_factory/mod.rs b/src/box_factory/mod.rs index 03ecbf4c..9d832205 100644 --- a/src/box_factory/mod.rs +++ b/src/box_factory/mod.rs @@ -11,7 +11,7 @@ */ use crate::box_trait::NyashBox; -use crate::RuntimeError; +use crate::interpreter::RuntimeError; use std::collections::HashMap; use std::sync::{Arc, RwLock}; diff --git a/src/box_factory/plugin.rs b/src/box_factory/plugin.rs index b8b6cde1..d2e92156 100644 --- a/src/box_factory/plugin.rs +++ b/src/box_factory/plugin.rs @@ -7,7 +7,7 @@ use super::BoxFactory; use crate::box_trait::NyashBox; -use crate::RuntimeError; +use crate::interpreter::RuntimeError; use crate::runtime::get_global_registry; /// Factory for plugin-based Box types diff --git a/src/box_factory/user_defined.rs b/src/box_factory/user_defined.rs index 7a083615..46f483af 100644 --- a/src/box_factory/user_defined.rs +++ b/src/box_factory/user_defined.rs @@ -7,7 +7,7 @@ use super::BoxFactory; use crate::box_trait::NyashBox; -use crate::RuntimeError; +use crate::interpreter::RuntimeError; /// Factory for user-defined Box types pub struct UserDefinedBoxFactory { diff --git a/src/interpreter/objects.rs b/src/interpreter/objects.rs index 0f9ff8ac..2c74000c 100644 --- a/src/interpreter/objects.rs +++ b/src/interpreter/objects.rs @@ -29,7 +29,7 @@ impl NyashInterpreter { match nyash_args { Ok(args) => { // Try unified registry - use crate::runtime::get_global_unified_registry; + use super::super::runtime::get_global_unified_registry; let registry = get_global_unified_registry(); let registry_lock = registry.lock().unwrap(); diff --git a/src/main.rs b/src/main.rs index 85243f30..867876fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ // Core modules pub mod box_trait; pub mod boxes; +pub mod box_factory; // 🏭 Unified Box Factory Architecture (Phase 9.78) pub mod stdlib; pub mod environment; pub mod tokenizer; diff --git a/src/runner.rs b/src/runner.rs index 0ecbbb2b..8d1eec7b 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -25,6 +25,7 @@ use std::{fs, process}; // v2 plugin system imports use nyash_rust::runtime::{init_global_loader_v2, get_global_registry, get_global_loader_v2, PluginConfig}; +use crate::runtime; /// Main execution coordinator pub struct NyashRunner { @@ -40,7 +41,7 @@ impl NyashRunner { /// Run Nyash based on the configuration pub fn run(&self) { // 🏭 Phase 9.78b: Initialize unified registry - nyash_rust::runtime::init_global_unified_registry(); + runtime::init_global_unified_registry(); // Try to initialize BID plugins from nyash.toml (best-effort) self.init_bid_plugins(); diff --git a/src/runtime/unified_registry.rs b/src/runtime/unified_registry.rs index ca4ca68d..e44e5403 100644 --- a/src/runtime/unified_registry.rs +++ b/src/runtime/unified_registry.rs @@ -5,7 +5,7 @@ * Integrates all Box creation sources (builtin, user-defined, plugin) */ -use super::super::box_factory::{UnifiedBoxRegistry, builtin::BuiltinBoxFactory, plugin::PluginBoxFactory}; +use crate::box_factory::{UnifiedBoxRegistry, builtin::BuiltinBoxFactory, plugin::PluginBoxFactory}; use std::sync::{Arc, Mutex, OnceLock}; /// Global registry instance @@ -35,7 +35,7 @@ pub fn get_global_unified_registry() -> Arc> { } /// Register a user-defined Box factory (called by interpreter) -pub fn register_user_defined_factory(factory: Arc) { +pub fn register_user_defined_factory(factory: Arc) { let registry = get_global_unified_registry(); let mut registry_lock = registry.lock().unwrap();