Phase 5: Complete destination pattern unification (28 sites, 53 lines)
Unified remaining destination write patterns with new helpers: - write_string() for VMValue::String writes - write_from_box() for VMValue::from_nyash_box() patterns Files updated: - boxes.rs: 8 sites unified (-14 lines) - boxes_plugin.rs: 9 sites unified (-17 lines) - boxes_object_fields.rs: 7 sites unified (-14 lines) - boxes_instance.rs: 2 sites unified (-4 lines) - calls.rs: 2 sites unified (-4 lines) - destination_helpers.rs: +28 lines (new helpers) Impact: 28 sites unified, net -25 lines, improved maintainability Tests: Phase 21.0 PASS (2/2, 100%) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -62,14 +62,10 @@ impl MirInterpreter {
|
||||
}
|
||||
match host.invoke_instance_method(&p.box_type, method, p.inner.instance_id, &argv) {
|
||||
Ok(Some(ret)) => {
|
||||
if let Some(d) = dst {
|
||||
self.regs.insert(d, VMValue::from_nyash_box(ret));
|
||||
}
|
||||
self.write_from_box(dst, ret);
|
||||
}
|
||||
Ok(None) => {
|
||||
if let Some(d) = dst {
|
||||
self.regs.insert(d, VMValue::Void);
|
||||
}
|
||||
self.write_void(dst);
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(self.err_with_context(
|
||||
@ -80,10 +76,7 @@ impl MirInterpreter {
|
||||
}
|
||||
Ok(())
|
||||
} else if method == "toString" {
|
||||
if let Some(d) = dst {
|
||||
self.regs
|
||||
.insert(d, VMValue::String(recv_box.to_string_box().value));
|
||||
}
|
||||
self.write_string(dst, recv_box.to_string_box().value);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(self.err_method_not_found(&recv_box.type_name(), method))
|
||||
@ -100,12 +93,12 @@ impl MirInterpreter {
|
||||
// Dev-safe: stringify(Void) → "null" (最小安全弁)
|
||||
if method == "stringify" {
|
||||
if let VMValue::Void = self.reg_load(box_val)? {
|
||||
if let Some(d) = dst { self.regs.insert(d, VMValue::String("null".to_string())); }
|
||||
self.write_string(dst, "null".to_string());
|
||||
return Ok(());
|
||||
}
|
||||
if let VMValue::BoxRef(b) = self.reg_load(box_val)? {
|
||||
if b.as_any().downcast_ref::<crate::box_trait::VoidBox>().is_some() {
|
||||
if let Some(d) = dst { self.regs.insert(d, VMValue::String("null".to_string())); }
|
||||
self.write_string(dst, "null".to_string());
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@ -151,14 +144,14 @@ impl MirInterpreter {
|
||||
match self.reg_load(box_val)? {
|
||||
VMValue::Void => {
|
||||
if let Some(val) = super::boxes_void_guards::handle_void_method(method) {
|
||||
if let Some(d) = dst { self.regs.insert(d, val); }
|
||||
self.write_result(dst, val);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
VMValue::BoxRef(ref b) => {
|
||||
if b.as_any().downcast_ref::<crate::box_trait::VoidBox>().is_some() {
|
||||
if let Some(val) = super::boxes_void_guards::handle_void_method(method) {
|
||||
if let Some(d) = dst { self.regs.insert(d, val); }
|
||||
self.write_result(dst, val);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@ -259,7 +252,7 @@ impl MirInterpreter {
|
||||
argv.push(recv_vm);
|
||||
for a in args { argv.push(self.reg_load(*a)?); }
|
||||
let ret = self.exec_function_inner(&func, Some(&argv))?;
|
||||
if let Some(d) = dst { self.regs.insert(d, ret); }
|
||||
self.write_result(dst, ret);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user