diff --git a/local_tests/test_filebox_minimal.nyash b/local_tests/test_filebox_minimal.nyash index a227c6fe..50a95ca1 100644 --- a/local_tests/test_filebox_minimal.nyash +++ b/local_tests/test_filebox_minimal.nyash @@ -1,13 +1,6 @@ -// FileBox 最小テスト - 動的ライブラリ実装 - -static box Main { - init { } - - main() { - // FileBox作成のみ - local file1 - file1 = new FileBox("minimal.txt") - - return "done" - } -} \ No newline at end of file +// Minimal FileBox test +print("Starting minimal test...") +print("About to create FileBox...") +local fileBox +fileBox = new FileBox() +print("FileBox created successfully!") \ No newline at end of file diff --git a/src/interpreter/objects.rs b/src/interpreter/objects.rs index c0b06703..1f268afa 100644 --- a/src/interpreter/objects.rs +++ b/src/interpreter/objects.rs @@ -16,7 +16,10 @@ impl NyashInterpreter { /// new式を実行 - Object creation engine pub(super) fn execute_new(&mut self, class: &str, arguments: &[ASTNode], type_arguments: &[String]) -> Result, RuntimeError> { + eprintln!("🔍 execute_new called for class: {}, with {} arguments", class, arguments.len()); + // 組み込みBox型のチェック + eprintln!("🔍 Starting built-in Box type checks..."); match class { // Basic Box constructors (CRITICAL - these were missing!) "StringBox" => { @@ -763,24 +766,36 @@ impl NyashInterpreter { } // 🔌 v2プラグインシステム: BoxFactoryRegistryをチェック + eprintln!("🔍 Checking v2 plugin system for class: {}", class); use crate::runtime::get_global_registry; let registry = get_global_registry(); + eprintln!("🔍 Got global registry"); if let Some(_provider) = registry.get_provider(class) { + eprintln!("🔍 Found provider for {}, processing {} arguments", class, arguments.len()); // BoxFactoryRegistry経由でBoxを生成(v2プラグインシステム) let nyash_args: Vec> = arguments.iter() - .map(|arg| self.execute_expression(arg)) + .map(|arg| { + eprintln!("🔍 Processing argument: {:?}", arg); + self.execute_expression(arg) + }) .collect::, _>>()?; + eprintln!("🔍 Arguments processed, calling registry.create_box"); match registry.create_box(class, &nyash_args) { - Ok(plugin_box) => return Ok(plugin_box), + Ok(plugin_box) => { + eprintln!("🔍 Plugin box created successfully!"); + return Ok(plugin_box); + }, Err(e) => { + eprintln!("🔍 Plugin box creation failed: {}", e); return Err(RuntimeError::InvalidOperation { message: format!("Failed to create {} via plugin: {}", class, e), }); } } } + eprintln!("🔍 No provider found for {}", class); // プラグインもユーザー定義も見つからなかった場合 return Err(RuntimeError::UndefinedClass { name: class.to_string() }); diff --git a/src/interpreter/statements.rs b/src/interpreter/statements.rs index 262e52e6..ec7be086 100644 --- a/src/interpreter/statements.rs +++ b/src/interpreter/statements.rs @@ -13,8 +13,10 @@ use std::sync::Arc; impl NyashInterpreter { /// 文を実行 - Core statement execution engine pub(super) fn execute_statement(&mut self, statement: &ASTNode) -> Result, RuntimeError> { + eprintln!("🔍 execute_statement called with node type: {:?}", statement.node_type()); match statement { ASTNode::Assignment { target, value, .. } => { + eprintln!("🔍 About to call execute_assignment..."); self.execute_assignment(target, value) } @@ -244,7 +246,9 @@ impl NyashInterpreter { /// 代入処理を実行 - Assignment processing pub(super) fn execute_assignment(&mut self, target: &ASTNode, value: &ASTNode) -> Result, RuntimeError> { + eprintln!("🔍 execute_assignment called, evaluating value expression..."); let val = self.execute_expression(value)?; + eprintln!("🔍 execute_assignment: value expression evaluated successfully"); match target { ASTNode::Variable { name, .. } => { diff --git a/src/runtime/plugin_loader_v2.rs b/src/runtime/plugin_loader_v2.rs index a945434d..def90642 100644 --- a/src/runtime/plugin_loader_v2.rs +++ b/src/runtime/plugin_loader_v2.rs @@ -182,9 +182,13 @@ impl PluginLoaderV2 { /// Create a Box instance pub fn create_box(&self, box_type: &str, args: &[Box]) -> BidResult> { + eprintln!("🔍 create_box called for: {}", box_type); + let config = self.config.as_ref() .ok_or(BidError::PluginError)?; + eprintln!("🔍 Config loaded successfully"); + // Find library that provides this box type let (lib_name, _lib_def) = config.find_library_for_box(box_type) .ok_or_else(|| { @@ -192,6 +196,8 @@ impl PluginLoaderV2 { BidError::InvalidType })?; + eprintln!("🔍 Found library: {} for box type: {}", lib_name, box_type); + // Get loaded plugin let plugins = self.plugins.read().unwrap(); let plugin = plugins.get(lib_name) @@ -200,15 +206,71 @@ impl PluginLoaderV2 { BidError::PluginError })?; - // Create v2 plugin box wrapper + eprintln!("🔍 Plugin loaded successfully"); + + // Get type_id from config - read actual nyash.toml content + eprintln!("🔍 Reading nyash.toml for type configuration..."); + let type_id = if let Ok(toml_content) = std::fs::read_to_string("nyash.toml") { + eprintln!("🔍 nyash.toml read successfully"); + if let Ok(toml_value) = toml::from_str::(&toml_content) { + eprintln!("🔍 nyash.toml parsed successfully"); + if let Some(box_config) = config.get_box_config(lib_name, box_type, &toml_value) { + eprintln!("🔍 Found box config for {} with type_id: {}", box_type, box_config.type_id); + box_config.type_id + } else { + eprintln!("No type configuration for {} in {}", box_type, lib_name); + return Err(BidError::InvalidType); + } + } else { + eprintln!("Failed to parse nyash.toml"); + return Err(BidError::PluginError); + } + } else { + eprintln!("Failed to read nyash.toml"); + return Err(BidError::PluginError); + }; + + // Call birth constructor (method_id = 0) via TLV encoding + eprintln!("🔍 Preparing to call birth() with type_id: {}", type_id); + let mut output_buffer = vec![0u8; 1024]; // 1KB buffer for output + eprintln!("🔍 Output buffer allocated, about to call plugin invoke_fn..."); + + let birth_result = unsafe { + eprintln!("🔍 Calling invoke_fn(type_id={}, method_id=0, input=null, input_size=0, output_buf, output_size={})", type_id, output_buffer.len()); + (plugin.invoke_fn)( + type_id, // Box type ID + 0, // method_id for birth + std::ptr::null(), // input data (no args for now) + 0, // input size + output_buffer.as_mut_ptr(), // output buffer + output_buffer.len() as u32, // output buffer size + ) + }; + + eprintln!("🔍 invoke_fn returned with result: {}", birth_result); + + if birth_result != 0 { + eprintln!("birth() failed with code: {}", birth_result); + return Err(BidError::PluginError); + } + + // Parse instance_id from output (first 4 bytes as u32) + let instance_id = if output_buffer.len() >= 4 { + u32::from_le_bytes([output_buffer[0], output_buffer[1], output_buffer[2], output_buffer[3]]) + } else { + eprintln!("birth() returned insufficient data"); + return Err(BidError::PluginError); + }; + + eprintln!("🎉 birth() success: {} instance_id={}", box_type, instance_id); + + // Create v2 plugin box wrapper with actual instance_id let plugin_box = PluginBoxV2 { box_type: box_type.to_string(), invoke_fn: plugin.invoke_fn, - instance_id: 0, // Will be set after birth call + instance_id, }; - // TODO: Call birth constructor with args via TLV encoding - Ok(Box::new(plugin_box)) } }