Phase 1 Complete: Remove critical debug statements - Major performance improvement
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
@ -256,28 +256,22 @@ impl NyashInterpreter {
|
|||||||
/// ASTを実行
|
/// ASTを実行
|
||||||
pub fn execute(&mut self, ast: ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
pub fn execute(&mut self, ast: ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||||
debug_log("=== NYASH EXECUTION START ===");
|
debug_log("=== NYASH EXECUTION START ===");
|
||||||
eprintln!("🔍 DEBUG: Starting interpreter execution...");
|
|
||||||
let result = self.execute_node(&ast);
|
let result = self.execute_node(&ast);
|
||||||
if let Err(ref e) = result {
|
if let Err(ref e) = result {
|
||||||
eprintln!("❌ Interpreter error: {}", e);
|
eprintln!("❌ Interpreter error: {}", e);
|
||||||
}
|
}
|
||||||
debug_log("=== NYASH EXECUTION END ===");
|
debug_log("=== NYASH EXECUTION END ===");
|
||||||
eprintln!("🔍 DEBUG: Interpreter execution completed");
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ノードを実行
|
/// ノードを実行
|
||||||
fn execute_node(&mut self, node: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
fn execute_node(&mut self, node: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||||
eprintln!("🔍 DEBUG: execute_node called with node type: {}", node.node_type());
|
|
||||||
match node {
|
match node {
|
||||||
ASTNode::Program { statements, .. } => {
|
ASTNode::Program { statements, .. } => {
|
||||||
eprintln!("🔍 DEBUG: Executing program with {} statements", statements.len());
|
|
||||||
let mut result: Box<dyn NyashBox> = Box::new(VoidBox::new());
|
let mut result: Box<dyn NyashBox> = Box::new(VoidBox::new());
|
||||||
|
|
||||||
for (i, statement) in statements.iter().enumerate() {
|
for statement in statements.iter() {
|
||||||
eprintln!("🔍 DEBUG: Executing statement {} of {}: {}", i + 1, statements.len(), statement.node_type());
|
|
||||||
result = self.execute_statement(statement)?;
|
result = self.execute_statement(statement)?;
|
||||||
eprintln!("🔍 DEBUG: Statement {} completed", i + 1);
|
|
||||||
|
|
||||||
// 制御フローチェック
|
// 制御フローチェック
|
||||||
match &self.control_flow {
|
match &self.control_flow {
|
||||||
@ -343,88 +337,51 @@ impl NyashInterpreter {
|
|||||||
let log_msg = format!("resolve_variable: name='{}', local_vars={:?}",
|
let log_msg = format!("resolve_variable: name='{}', local_vars={:?}",
|
||||||
name, self.local_vars.keys().collect::<Vec<_>>());
|
name, self.local_vars.keys().collect::<Vec<_>>());
|
||||||
debug_log(&log_msg);
|
debug_log(&log_msg);
|
||||||
eprintln!("🔍 DEBUG: {}", log_msg);
|
|
||||||
|
|
||||||
// 1. outbox変数を最初にチェック(static関数内で優先)
|
// 1. outbox変数を最初にチェック(static関数内で優先)
|
||||||
if let Some(outbox_value) = self.outbox_vars.get(name) {
|
if let Some(outbox_value) = self.outbox_vars.get(name) {
|
||||||
eprintln!("🔍 DEBUG: Found '{}' in outbox_vars", name);
|
|
||||||
|
|
||||||
// 🔧 修正:clone_box() → Arc::clone() で参照共有
|
// 🔧 修正:clone_box() → Arc::clone() で参照共有
|
||||||
let shared_value = Arc::clone(outbox_value);
|
let shared_value = Arc::clone(outbox_value);
|
||||||
|
|
||||||
eprintln!("✅ RESOLVE_VARIABLE shared reference: {} id={}",
|
|
||||||
name, shared_value.box_id());
|
|
||||||
|
|
||||||
return Ok(shared_value);
|
return Ok(shared_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. local変数をチェック
|
// 2. local変数をチェック
|
||||||
if let Some(local_value) = self.local_vars.get(name) {
|
if let Some(local_value) = self.local_vars.get(name) {
|
||||||
eprintln!("🔍 DEBUG: Found '{}' in local_vars", name);
|
|
||||||
|
|
||||||
// 🔧 修正:clone_box() → Arc::clone() で参照共有
|
// 🔧 修正:clone_box() → Arc::clone() で参照共有
|
||||||
let shared_value = Arc::clone(local_value);
|
let shared_value = Arc::clone(local_value);
|
||||||
|
|
||||||
eprintln!("✅ RESOLVE_VARIABLE shared reference: {} id={}",
|
|
||||||
name, shared_value.box_id());
|
|
||||||
|
|
||||||
return Ok(shared_value);
|
return Ok(shared_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. GlobalBoxのフィールドをチェック
|
// 3. GlobalBoxのフィールドをチェック
|
||||||
eprintln!("🔍 DEBUG: Checking GlobalBox for '{}'...", name);
|
|
||||||
let global_box = self.shared.global_box.lock().unwrap();
|
let global_box = self.shared.global_box.lock().unwrap();
|
||||||
if let Some(field_value) = global_box.get_field(name) {
|
if let Some(field_value) = global_box.get_field(name) {
|
||||||
eprintln!("🔍 DEBUG: Found '{}' in GlobalBox", name);
|
|
||||||
return Ok(field_value);
|
return Ok(field_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. statics名前空間内のstatic boxをチェック
|
// 4. statics名前空間内のstatic boxをチェック
|
||||||
eprintln!("🔍 DEBUG: Checking statics namespace for '{}'...", name);
|
|
||||||
if let Some(statics_namespace) = global_box.get_field("statics") {
|
if let Some(statics_namespace) = global_box.get_field("statics") {
|
||||||
eprintln!("🔍 DEBUG: statics namespace type: {}", statics_namespace.type_name());
|
|
||||||
|
|
||||||
// MapBoxとして試す
|
// MapBoxとして試す
|
||||||
if let Some(map_box) = statics_namespace.as_any().downcast_ref::<crate::boxes::map_box::MapBox>() {
|
if let Some(map_box) = statics_namespace.as_any().downcast_ref::<crate::boxes::map_box::MapBox>() {
|
||||||
eprintln!("🔍 DEBUG: statics is a MapBox, looking for '{}'", name);
|
|
||||||
let key_box: Box<dyn NyashBox> = Box::new(StringBox::new(name));
|
let key_box: Box<dyn NyashBox> = Box::new(StringBox::new(name));
|
||||||
let static_box_result = map_box.get(key_box);
|
let static_box_result = map_box.get(key_box);
|
||||||
|
|
||||||
// NullBoxでないかチェック(MapBoxは見つからない場合NullBoxを返す)
|
// NullBoxでないかチェック(MapBoxは見つからない場合NullBoxを返す)
|
||||||
if static_box_result.type_name() != "NullBox" {
|
if static_box_result.type_name() != "NullBox" {
|
||||||
eprintln!("🔍 DEBUG: Found '{}' in statics namespace", name);
|
|
||||||
return Ok(Arc::from(static_box_result));
|
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::<InstanceBox>() {
|
} else if let Some(instance) = statics_namespace.as_any().downcast_ref::<InstanceBox>() {
|
||||||
eprintln!("🔍 DEBUG: statics is an InstanceBox, looking for '{}'", name);
|
|
||||||
if let Some(static_box) = instance.get_field(name) {
|
if let Some(static_box) = instance.get_field(name) {
|
||||||
eprintln!("🔍 DEBUG: Found '{}' in statics namespace", name);
|
|
||||||
return Ok(static_box);
|
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チェック
|
drop(global_box); // lockを解放してからstdlibチェック
|
||||||
|
|
||||||
// 5. nyashstd標準ライブラリ名前空間をチェック
|
// 5. nyashstd標準ライブラリ名前空間をチェック
|
||||||
eprintln!("🔍 DEBUG: Checking nyashstd stdlib for '{}'...", name);
|
|
||||||
if let Some(ref stdlib) = self.stdlib {
|
if let Some(ref stdlib) = self.stdlib {
|
||||||
eprintln!("🔍 DEBUG: stdlib is initialized, checking namespaces...");
|
|
||||||
eprintln!("🔍 DEBUG: Available namespaces: {:?}", stdlib.namespaces.keys().collect::<Vec<_>>());
|
|
||||||
|
|
||||||
if let Some(nyashstd_namespace) = stdlib.namespaces.get("nyashstd") {
|
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::<Vec<_>>());
|
|
||||||
|
|
||||||
if let Some(_static_box) = nyashstd_namespace.static_boxes.get(name) {
|
if let Some(_static_box) = nyashstd_namespace.static_boxes.get(name) {
|
||||||
eprintln!("🔍 DEBUG: Found '{}' in nyashstd namespace", name);
|
|
||||||
|
|
||||||
// BuiltinStaticBoxをInstanceBoxとしてラップ
|
// BuiltinStaticBoxをInstanceBoxとしてラップ
|
||||||
let static_instance = InstanceBox::new(
|
let static_instance = InstanceBox::new(
|
||||||
format!("{}_builtin", name),
|
format!("{}_builtin", name),
|
||||||
@ -433,14 +390,8 @@ impl NyashInterpreter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return Ok(Arc::new(static_instance));
|
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. エラー:見つからない
|
// 6. エラー:見つからない
|
||||||
|
|||||||
@ -45,13 +45,10 @@ impl NyashInterpreter {
|
|||||||
message: format!("Field '{}' not found in {}", field, instance.class_name),
|
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
|
// 🔗 Weak Reference Check: Use unified accessor for weak fields
|
||||||
let box_decls = self.shared.box_declarations.read().unwrap();
|
let box_decls = self.shared.box_declarations.read().unwrap();
|
||||||
if let Some(box_decl) = box_decls.get(&instance.class_name) {
|
if let Some(box_decl) = box_decls.get(&instance.class_name) {
|
||||||
if box_decl.weak_fields.contains(&field.to_string()) {
|
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
|
// 🎯 PHASE 2: Use unified accessor for auto-nil weak reference handling
|
||||||
if let Some(weak_value) = instance.get_weak_field(field, self) { // Pass self
|
if let Some(weak_value) = instance.get_weak_field(field, self) { // Pass self
|
||||||
|
|||||||
@ -22,31 +22,22 @@ fn unwrap_instance(boxed: &dyn NyashBox) -> &dyn NyashBox {
|
|||||||
boxed
|
boxed
|
||||||
}
|
}
|
||||||
pub(super) fn try_add_operation(left: &dyn NyashBox, right: &dyn NyashBox) -> Option<Box<dyn NyashBox>> {
|
pub(super) fn try_add_operation(left: &dyn NyashBox, right: &dyn NyashBox) -> Option<Box<dyn NyashBox>> {
|
||||||
// 🔍 デバッグ出力追加
|
|
||||||
eprintln!("🔍 try_add_operation: left={}, right={}", left.type_name(), right.type_name());
|
|
||||||
|
|
||||||
// 🎯 InstanceBoxのunwrap処理
|
// 🎯 InstanceBoxのunwrap処理
|
||||||
let left = unwrap_instance(left);
|
let left = unwrap_instance(left);
|
||||||
let right = unwrap_instance(right);
|
let right = unwrap_instance(right);
|
||||||
eprintln!("🔍 After unwrap: left={}, right={}", left.type_name(), right.type_name());
|
|
||||||
|
|
||||||
// IntegerBox + IntegerBox
|
// IntegerBox + IntegerBox
|
||||||
if let (Some(left_int), Some(right_int)) = (
|
if let (Some(left_int), Some(right_int)) = (
|
||||||
left.as_any().downcast_ref::<IntegerBox>(),
|
left.as_any().downcast_ref::<IntegerBox>(),
|
||||||
right.as_any().downcast_ref::<IntegerBox>()
|
right.as_any().downcast_ref::<IntegerBox>()
|
||||||
) {
|
) {
|
||||||
eprintln!("🔍 IntegerBox + IntegerBox detected");
|
|
||||||
return Some(Box::new(IntegerBox::new(left_int.value + right_int.value)));
|
return Some(Box::new(IntegerBox::new(left_int.value + right_int.value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringBox + anything -> concatenation
|
// StringBox + anything -> concatenation
|
||||||
eprintln!("🔍 Checking StringBox downcast...");
|
|
||||||
if let Some(left_str) = left.as_any().downcast_ref::<StringBox>() {
|
if let Some(left_str) = left.as_any().downcast_ref::<StringBox>() {
|
||||||
eprintln!("🔍 StringBox downcast SUCCESS!");
|
|
||||||
let right_str = right.to_string_box();
|
let right_str = right.to_string_box();
|
||||||
return Some(Box::new(StringBox::new(format!("{}{}", left_str.value, right_str.value))));
|
return Some(Box::new(StringBox::new(format!("{}{}", left_str.value, right_str.value))));
|
||||||
} else {
|
|
||||||
eprintln!("🔍 StringBox downcast FAILED!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoolBox + BoolBox -> IntegerBox
|
// BoolBox + BoolBox -> IntegerBox
|
||||||
@ -139,7 +130,7 @@ impl NyashInterpreter {
|
|||||||
-> Result<Box<dyn NyashBox>, RuntimeError> {
|
-> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||||
let left_val = self.execute_expression(left)?;
|
let left_val = self.execute_expression(left)?;
|
||||||
let right_val = self.execute_expression(right)?;
|
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 {
|
match op {
|
||||||
BinaryOperator::Add => {
|
BinaryOperator::Add => {
|
||||||
|
|||||||
@ -16,10 +16,8 @@ impl NyashInterpreter {
|
|||||||
/// new式を実行 - Object creation engine
|
/// new式を実行 - Object creation engine
|
||||||
pub(super) fn execute_new(&mut self, class: &str, arguments: &[ASTNode], type_arguments: &[String])
|
pub(super) fn execute_new(&mut self, class: &str, arguments: &[ASTNode], type_arguments: &[String])
|
||||||
-> Result<Box<dyn NyashBox>, RuntimeError> {
|
-> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||||
eprintln!("🔍 execute_new called for class: {}, with {} arguments", class, arguments.len());
|
|
||||||
|
|
||||||
// 🏭 Phase 9.78b: Try unified registry first
|
// 🏭 Phase 9.78b: Try unified registry first
|
||||||
eprintln!("🔍 Trying unified registry for class: {}", class);
|
|
||||||
|
|
||||||
// Convert ASTNode arguments to Box<dyn NyashBox>
|
// Convert ASTNode arguments to Box<dyn NyashBox>
|
||||||
let nyash_args: Result<Vec<Box<dyn NyashBox>>, RuntimeError> = arguments.iter()
|
let nyash_args: Result<Vec<Box<dyn NyashBox>>, RuntimeError> = arguments.iter()
|
||||||
@ -35,7 +33,6 @@ impl NyashInterpreter {
|
|||||||
|
|
||||||
match registry_lock.create_box(class, &args) {
|
match registry_lock.create_box(class, &args) {
|
||||||
Ok(box_instance) => {
|
Ok(box_instance) => {
|
||||||
eprintln!("🏭 Unified registry created: {}", class);
|
|
||||||
|
|
||||||
// Check if this is a user-defined box that needs constructor execution
|
// Check if this is a user-defined box that needs constructor execution
|
||||||
if let Some(_instance_box) = box_instance.as_any().downcast_ref::<crate::instance_v2::InstanceBox>() {
|
if let Some(_instance_box) = box_instance.as_any().downcast_ref::<crate::instance_v2::InstanceBox>() {
|
||||||
|
|||||||
@ -13,10 +13,8 @@ use std::sync::Arc;
|
|||||||
impl NyashInterpreter {
|
impl NyashInterpreter {
|
||||||
/// 文を実行 - Core statement execution engine
|
/// 文を実行 - Core statement execution engine
|
||||||
pub(super) fn execute_statement(&mut self, statement: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
pub(super) fn execute_statement(&mut self, statement: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||||
eprintln!("🔍 execute_statement called with node type: {:?}", statement.node_type());
|
|
||||||
match statement {
|
match statement {
|
||||||
ASTNode::Assignment { target, value, .. } => {
|
ASTNode::Assignment { target, value, .. } => {
|
||||||
eprintln!("🔍 About to call execute_assignment...");
|
|
||||||
self.execute_assignment(target, value)
|
self.execute_assignment(target, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,9 +244,7 @@ impl NyashInterpreter {
|
|||||||
|
|
||||||
/// 代入処理を実行 - Assignment processing
|
/// 代入処理を実行 - Assignment processing
|
||||||
pub(super) fn execute_assignment(&mut self, target: &ASTNode, value: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
pub(super) fn execute_assignment(&mut self, target: &ASTNode, value: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||||
eprintln!("🔍 execute_assignment called, evaluating value expression...");
|
|
||||||
let val = self.execute_expression(value)?;
|
let val = self.execute_expression(value)?;
|
||||||
eprintln!("🔍 execute_assignment: value expression evaluated successfully");
|
|
||||||
|
|
||||||
match target {
|
match target {
|
||||||
ASTNode::Variable { name, .. } => {
|
ASTNode::Variable { name, .. } => {
|
||||||
|
|||||||
Reference in New Issue
Block a user