diff --git a/src/interpreter/core.rs b/src/interpreter/core.rs index f13aad2f..843e39c1 100644 --- a/src/interpreter/core.rs +++ b/src/interpreter/core.rs @@ -256,28 +256,22 @@ impl NyashInterpreter { /// ASTを実行 pub fn execute(&mut self, ast: ASTNode) -> Result, RuntimeError> { debug_log("=== NYASH EXECUTION START ==="); - eprintln!("🔍 DEBUG: Starting interpreter execution..."); let result = self.execute_node(&ast); if let Err(ref e) = result { eprintln!("❌ Interpreter error: {}", e); } debug_log("=== NYASH EXECUTION END ==="); - eprintln!("🔍 DEBUG: Interpreter execution completed"); result } /// ノードを実行 fn execute_node(&mut self, node: &ASTNode) -> Result, RuntimeError> { - eprintln!("🔍 DEBUG: execute_node called with node type: {}", node.node_type()); match node { ASTNode::Program { statements, .. } => { - eprintln!("🔍 DEBUG: Executing program with {} statements", statements.len()); let mut result: Box = Box::new(VoidBox::new()); - for (i, statement) in statements.iter().enumerate() { - eprintln!("🔍 DEBUG: Executing statement {} of {}: {}", i + 1, statements.len(), statement.node_type()); + for statement in statements.iter() { result = self.execute_statement(statement)?; - eprintln!("🔍 DEBUG: Statement {} completed", i + 1); // 制御フローチェック match &self.control_flow { @@ -343,88 +337,51 @@ impl NyashInterpreter { let log_msg = format!("resolve_variable: name='{}', local_vars={:?}", name, self.local_vars.keys().collect::>()); debug_log(&log_msg); - eprintln!("🔍 DEBUG: {}", log_msg); - // 1. outbox変数を最初にチェック(static関数内で優先) if let Some(outbox_value) = self.outbox_vars.get(name) { - eprintln!("🔍 DEBUG: Found '{}' in outbox_vars", name); - // 🔧 修正:clone_box() → Arc::clone() で参照共有 let shared_value = Arc::clone(outbox_value); - - eprintln!("✅ RESOLVE_VARIABLE shared reference: {} id={}", - name, shared_value.box_id()); - return Ok(shared_value); } // 2. local変数をチェック if let Some(local_value) = self.local_vars.get(name) { - eprintln!("🔍 DEBUG: Found '{}' in local_vars", name); - // 🔧 修正:clone_box() → Arc::clone() で参照共有 let shared_value = Arc::clone(local_value); - - eprintln!("✅ RESOLVE_VARIABLE shared reference: {} id={}", - name, shared_value.box_id()); - return Ok(shared_value); } // 3. GlobalBoxのフィールドをチェック - eprintln!("🔍 DEBUG: Checking GlobalBox for '{}'...", name); let global_box = self.shared.global_box.lock().unwrap(); if let Some(field_value) = global_box.get_field(name) { - eprintln!("🔍 DEBUG: Found '{}' in GlobalBox", name); return Ok(field_value); } // 4. statics名前空間内のstatic boxをチェック - eprintln!("🔍 DEBUG: Checking statics namespace for '{}'...", name); if let Some(statics_namespace) = global_box.get_field("statics") { - eprintln!("🔍 DEBUG: statics namespace type: {}", statics_namespace.type_name()); // MapBoxとして試す if let Some(map_box) = statics_namespace.as_any().downcast_ref::() { - eprintln!("🔍 DEBUG: statics is a MapBox, looking for '{}'", name); let key_box: Box = Box::new(StringBox::new(name)); let static_box_result = map_box.get(key_box); // NullBoxでないかチェック(MapBoxは見つからない場合NullBoxを返す) if static_box_result.type_name() != "NullBox" { - eprintln!("🔍 DEBUG: Found '{}' in statics namespace", name); return Ok(Arc::from(static_box_result)); - } else { - eprintln!("🔍 DEBUG: '{}' not found in statics MapBox", name); } } else if let Some(instance) = statics_namespace.as_any().downcast_ref::() { - eprintln!("🔍 DEBUG: statics is an InstanceBox, looking for '{}'", name); if let Some(static_box) = instance.get_field(name) { - eprintln!("🔍 DEBUG: Found '{}' in statics namespace", name); return Ok(static_box); - } else { - eprintln!("🔍 DEBUG: '{}' not found in statics InstanceBox", name); } - } else { - eprintln!("🔍 DEBUG: statics namespace is neither MapBox nor InstanceBox"); } } drop(global_box); // lockを解放してからstdlibチェック // 5. nyashstd標準ライブラリ名前空間をチェック - eprintln!("🔍 DEBUG: Checking nyashstd stdlib for '{}'...", name); if let Some(ref stdlib) = self.stdlib { - eprintln!("🔍 DEBUG: stdlib is initialized, checking namespaces..."); - eprintln!("🔍 DEBUG: Available namespaces: {:?}", stdlib.namespaces.keys().collect::>()); - if let Some(nyashstd_namespace) = stdlib.namespaces.get("nyashstd") { - eprintln!("🔍 DEBUG: nyashstd namespace found, checking static boxes..."); - eprintln!("🔍 DEBUG: Available static boxes: {:?}", nyashstd_namespace.static_boxes.keys().collect::>()); - if let Some(_static_box) = nyashstd_namespace.static_boxes.get(name) { - eprintln!("🔍 DEBUG: Found '{}' in nyashstd namespace", name); - // BuiltinStaticBoxをInstanceBoxとしてラップ let static_instance = InstanceBox::new( format!("{}_builtin", name), @@ -433,14 +390,8 @@ impl NyashInterpreter { ); return Ok(Arc::new(static_instance)); - } else { - eprintln!("🔍 DEBUG: '{}' not found in nyashstd namespace", name); } - } else { - eprintln!("🔍 DEBUG: nyashstd namespace not found in stdlib"); } - } else { - eprintln!("🔍 DEBUG: stdlib not initialized"); } // 6. エラー:見つからない diff --git a/src/interpreter/expressions/access.rs b/src/interpreter/expressions/access.rs index df4a07da..13885afd 100644 --- a/src/interpreter/expressions/access.rs +++ b/src/interpreter/expressions/access.rs @@ -45,13 +45,10 @@ impl NyashInterpreter { message: format!("Field '{}' not found in {}", field, instance.class_name), })?; - eprintln!("✅ FIELD ACCESS: Returning shared reference id={}", field_value.box_id()); - // 🔗 Weak Reference Check: Use unified accessor for weak fields let box_decls = self.shared.box_declarations.read().unwrap(); if let Some(box_decl) = box_decls.get(&instance.class_name) { if box_decl.weak_fields.contains(&field.to_string()) { - eprintln!("🔗 DEBUG: Accessing weak field '{}' in class '{}'", field, instance.class_name); // 🎯 PHASE 2: Use unified accessor for auto-nil weak reference handling if let Some(weak_value) = instance.get_weak_field(field, self) { // Pass self diff --git a/src/interpreter/expressions/operators.rs b/src/interpreter/expressions/operators.rs index 78001b33..5b96fece 100644 --- a/src/interpreter/expressions/operators.rs +++ b/src/interpreter/expressions/operators.rs @@ -22,31 +22,22 @@ fn unwrap_instance(boxed: &dyn NyashBox) -> &dyn NyashBox { boxed } pub(super) fn try_add_operation(left: &dyn NyashBox, right: &dyn NyashBox) -> Option> { - // 🔍 デバッグ出力追加 - eprintln!("🔍 try_add_operation: left={}, right={}", left.type_name(), right.type_name()); - // 🎯 InstanceBoxのunwrap処理 let left = unwrap_instance(left); let right = unwrap_instance(right); - eprintln!("🔍 After unwrap: left={}, right={}", left.type_name(), right.type_name()); // IntegerBox + IntegerBox if let (Some(left_int), Some(right_int)) = ( left.as_any().downcast_ref::(), right.as_any().downcast_ref::() ) { - eprintln!("🔍 IntegerBox + IntegerBox detected"); return Some(Box::new(IntegerBox::new(left_int.value + right_int.value))); } // StringBox + anything -> concatenation - eprintln!("🔍 Checking StringBox downcast..."); if let Some(left_str) = left.as_any().downcast_ref::() { - eprintln!("🔍 StringBox downcast SUCCESS!"); let right_str = right.to_string_box(); return Some(Box::new(StringBox::new(format!("{}{}", left_str.value, right_str.value)))); - } else { - eprintln!("🔍 StringBox downcast FAILED!"); } // BoolBox + BoolBox -> IntegerBox @@ -139,7 +130,7 @@ impl NyashInterpreter { -> Result, RuntimeError> { let left_val = self.execute_expression(left)?; let right_val = self.execute_expression(right)?; - eprintln!("🔧 execute_binary_op: op={:?}, left={}, right={}", op, left_val.type_name(), right_val.type_name()); + // Binary operation execution match op { BinaryOperator::Add => { diff --git a/src/interpreter/objects.rs b/src/interpreter/objects.rs index f0eb740b..f4e5c058 100644 --- a/src/interpreter/objects.rs +++ b/src/interpreter/objects.rs @@ -16,10 +16,8 @@ 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()); // 🏭 Phase 9.78b: Try unified registry first - eprintln!("🔍 Trying unified registry for class: {}", class); // Convert ASTNode arguments to Box let nyash_args: Result>, RuntimeError> = arguments.iter() @@ -35,7 +33,6 @@ impl NyashInterpreter { match registry_lock.create_box(class, &args) { Ok(box_instance) => { - eprintln!("🏭 Unified registry created: {}", class); // Check if this is a user-defined box that needs constructor execution if let Some(_instance_box) = box_instance.as_any().downcast_ref::() { diff --git a/src/interpreter/statements.rs b/src/interpreter/statements.rs index 0a65349b..7379744c 100644 --- a/src/interpreter/statements.rs +++ b/src/interpreter/statements.rs @@ -13,10 +13,8 @@ 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) } @@ -246,9 +244,7 @@ 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, .. } => {