fix: MIR builder me resolution for static box methods
- Fixed me ValueId inconsistency in static box methods - Previously, each me reference generated a new const __me__ ValueId - Now caches the first me ValueId in variable_map for reuse - This ensures RefSet and RefGet operate on the same object - ArrayBox get/set/push now working correctly in VM mode - Test results: 1, 42, 3 (as expected) 🔧 Technical Details: - build_me_expression() now stores fallback ValueId in variable_map - Subsequent me references reuse the same ValueId - VM BoxCall debug logs confirm ArrayBox methods dispatch correctly Co-Authored-By: ChatGPT5 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -243,24 +243,44 @@ impl NyashInterpreter {
|
||||
// ビルトインBoxのインスタンスを作成または取得
|
||||
match parent {
|
||||
"StringBox" => {
|
||||
let string_box = StringBox::new("");
|
||||
self.execute_string_method(&string_box, method, arguments)
|
||||
if let Some(sb) = current_instance.as_any().downcast_ref::<StringBox>() {
|
||||
self.execute_string_method(sb, method, arguments)
|
||||
} else {
|
||||
let string_box = StringBox::new("");
|
||||
self.execute_string_method(&string_box, method, arguments)
|
||||
}
|
||||
}
|
||||
"IntegerBox" => {
|
||||
let integer_box = IntegerBox::new(0);
|
||||
self.execute_integer_method(&integer_box, method, arguments)
|
||||
if let Some(ib) = current_instance.as_any().downcast_ref::<IntegerBox>() {
|
||||
self.execute_integer_method(ib, method, arguments)
|
||||
} else {
|
||||
let integer_box = IntegerBox::new(0);
|
||||
self.execute_integer_method(&integer_box, method, arguments)
|
||||
}
|
||||
}
|
||||
"ArrayBox" => {
|
||||
let array_box = ArrayBox::new();
|
||||
self.execute_array_method(&array_box, method, arguments)
|
||||
if let Some(ab) = current_instance.as_any().downcast_ref::<ArrayBox>() {
|
||||
self.execute_array_method(ab, method, arguments)
|
||||
} else {
|
||||
let array_box = ArrayBox::new();
|
||||
self.execute_array_method(&array_box, method, arguments)
|
||||
}
|
||||
}
|
||||
"MapBox" => {
|
||||
let map_box = MapBox::new();
|
||||
self.execute_map_method(&map_box, method, arguments)
|
||||
if let Some(mb) = current_instance.as_any().downcast_ref::<MapBox>() {
|
||||
self.execute_map_method(mb, method, arguments)
|
||||
} else {
|
||||
let map_box = MapBox::new();
|
||||
self.execute_map_method(&map_box, method, arguments)
|
||||
}
|
||||
}
|
||||
"MathBox" => {
|
||||
let math_box = MathBox::new();
|
||||
self.execute_math_method(&math_box, method, arguments)
|
||||
if let Some(math) = current_instance.as_any().downcast_ref::<MathBox>() {
|
||||
self.execute_math_method(math, method, arguments)
|
||||
} else {
|
||||
let math_box = MathBox::new();
|
||||
self.execute_math_method(&math_box, method, arguments)
|
||||
}
|
||||
}
|
||||
// 他のビルトインBoxは必要に応じて追加
|
||||
_ => {
|
||||
|
||||
@ -47,6 +47,15 @@ impl NyashInterpreter {
|
||||
|
||||
Ok(socket_box.accept())
|
||||
}
|
||||
"acceptTimeout" | "accept_timeout" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("acceptTimeout(ms) expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let ms = self.execute_expression(&arguments[0])?;
|
||||
Ok(socket_box.accept_timeout(ms))
|
||||
}
|
||||
"connect" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
@ -67,6 +76,15 @@ impl NyashInterpreter {
|
||||
|
||||
Ok(socket_box.read())
|
||||
}
|
||||
"recvTimeout" | "recv_timeout" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("recvTimeout(ms) expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let ms = self.execute_expression(&arguments[0])?;
|
||||
Ok(socket_box.recv_timeout(ms))
|
||||
}
|
||||
"readHttpRequest" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
@ -284,4 +302,4 @@ impl NyashInterpreter {
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user