2025-09-26 14:34:42 +09:00
|
|
|
use super::*;
|
refactor: add MIR interpreter utility helpers (Phase 1)
- Add destination write helpers (write_box_result, write_void, write_result)
- Add argument validation helpers (validate_args_exact/range/min)
- Add receiver conversion helper (convert_to_box)
- Update handlers to use new helpers
Reduces code duplication:
- Destination patterns: 37 call sites converted
- Each replacement saves 2-3 lines (74-111 lines saved)
- Helper infrastructure: 178 lines added
- Net improvement: Reduced duplication + better maintainability
Impact:
- Build: ✓ SUCCESS (0 errors, 146 warnings)
- Tests: ✓ 8/9 smoke tests PASS
- Functionality: ✓ PRESERVED (no behavior changes)
Files created:
- src/backend/mir_interpreter/utils/mod.rs
- src/backend/mir_interpreter/utils/destination_helpers.rs
- src/backend/mir_interpreter/utils/arg_validation.rs
- src/backend/mir_interpreter/utils/receiver_helpers.rs
Files modified: 15 handler files
- arithmetic.rs, boxes.rs, boxes_array.rs, boxes_instance.rs
- boxes_map.rs, boxes_object_fields.rs, boxes_plugin.rs
- boxes_string.rs, calls.rs, extern_provider.rs, externals.rs
- memory.rs, misc.rs, mod.rs
Related: Phase 21.0 refactoring
Risk: Low (pure refactoring, no behavior change)
2025-11-06 22:50:46 +09:00
|
|
|
use super::super::utils::*;
|
2025-09-26 14:34:42 +09:00
|
|
|
use crate::box_trait::NyashBox;
|
|
|
|
|
|
|
|
|
|
pub(super) fn try_handle_array_box(
|
|
|
|
|
this: &mut MirInterpreter,
|
|
|
|
|
dst: Option<ValueId>,
|
|
|
|
|
box_val: ValueId,
|
|
|
|
|
method: &str,
|
|
|
|
|
args: &[ValueId],
|
|
|
|
|
) -> Result<bool, VMError> {
|
|
|
|
|
let recv = this.reg_load(box_val)?;
|
|
|
|
|
let recv_box_any: Box<dyn NyashBox> = match recv.clone() {
|
|
|
|
|
VMValue::BoxRef(b) => b.share_box(),
|
|
|
|
|
other => other.to_nyash_box(),
|
|
|
|
|
};
|
|
|
|
|
if let Some(ab) = recv_box_any
|
|
|
|
|
.as_any()
|
|
|
|
|
.downcast_ref::<crate::boxes::array::ArrayBox>()
|
|
|
|
|
{
|
|
|
|
|
match method {
|
|
|
|
|
"birth" => {
|
|
|
|
|
// No-op constructor init
|
refactor: add MIR interpreter utility helpers (Phase 1)
- Add destination write helpers (write_box_result, write_void, write_result)
- Add argument validation helpers (validate_args_exact/range/min)
- Add receiver conversion helper (convert_to_box)
- Update handlers to use new helpers
Reduces code duplication:
- Destination patterns: 37 call sites converted
- Each replacement saves 2-3 lines (74-111 lines saved)
- Helper infrastructure: 178 lines added
- Net improvement: Reduced duplication + better maintainability
Impact:
- Build: ✓ SUCCESS (0 errors, 146 warnings)
- Tests: ✓ 8/9 smoke tests PASS
- Functionality: ✓ PRESERVED (no behavior changes)
Files created:
- src/backend/mir_interpreter/utils/mod.rs
- src/backend/mir_interpreter/utils/destination_helpers.rs
- src/backend/mir_interpreter/utils/arg_validation.rs
- src/backend/mir_interpreter/utils/receiver_helpers.rs
Files modified: 15 handler files
- arithmetic.rs, boxes.rs, boxes_array.rs, boxes_instance.rs
- boxes_map.rs, boxes_object_fields.rs, boxes_plugin.rs
- boxes_string.rs, calls.rs, extern_provider.rs, externals.rs
- memory.rs, misc.rs, mod.rs
Related: Phase 21.0 refactoring
Risk: Low (pure refactoring, no behavior change)
2025-11-06 22:50:46 +09:00
|
|
|
this.write_void(dst);
|
2025-09-26 14:34:42 +09:00
|
|
|
return Ok(true);
|
|
|
|
|
}
|
|
|
|
|
"push" => {
|
2025-11-06 22:59:47 +09:00
|
|
|
this.validate_args_exact("push", args, 1)?;
|
2025-09-26 14:34:42 +09:00
|
|
|
let val = this.reg_load(args[0])?.to_nyash_box();
|
|
|
|
|
let _ = ab.push(val);
|
refactor: add MIR interpreter utility helpers (Phase 1)
- Add destination write helpers (write_box_result, write_void, write_result)
- Add argument validation helpers (validate_args_exact/range/min)
- Add receiver conversion helper (convert_to_box)
- Update handlers to use new helpers
Reduces code duplication:
- Destination patterns: 37 call sites converted
- Each replacement saves 2-3 lines (74-111 lines saved)
- Helper infrastructure: 178 lines added
- Net improvement: Reduced duplication + better maintainability
Impact:
- Build: ✓ SUCCESS (0 errors, 146 warnings)
- Tests: ✓ 8/9 smoke tests PASS
- Functionality: ✓ PRESERVED (no behavior changes)
Files created:
- src/backend/mir_interpreter/utils/mod.rs
- src/backend/mir_interpreter/utils/destination_helpers.rs
- src/backend/mir_interpreter/utils/arg_validation.rs
- src/backend/mir_interpreter/utils/receiver_helpers.rs
Files modified: 15 handler files
- arithmetic.rs, boxes.rs, boxes_array.rs, boxes_instance.rs
- boxes_map.rs, boxes_object_fields.rs, boxes_plugin.rs
- boxes_string.rs, calls.rs, extern_provider.rs, externals.rs
- memory.rs, misc.rs, mod.rs
Related: Phase 21.0 refactoring
Risk: Low (pure refactoring, no behavior change)
2025-11-06 22:50:46 +09:00
|
|
|
this.write_void(dst);
|
2025-09-26 14:34:42 +09:00
|
|
|
return Ok(true);
|
|
|
|
|
}
|
2025-11-02 11:47:58 +09:00
|
|
|
"pop" => {
|
|
|
|
|
if !args.is_empty() { return Err(VMError::InvalidInstruction("pop expects 0 args".into())); }
|
|
|
|
|
let ret = ab.pop();
|
refactor: add MIR interpreter utility helpers (Phase 1)
- Add destination write helpers (write_box_result, write_void, write_result)
- Add argument validation helpers (validate_args_exact/range/min)
- Add receiver conversion helper (convert_to_box)
- Update handlers to use new helpers
Reduces code duplication:
- Destination patterns: 37 call sites converted
- Each replacement saves 2-3 lines (74-111 lines saved)
- Helper infrastructure: 178 lines added
- Net improvement: Reduced duplication + better maintainability
Impact:
- Build: ✓ SUCCESS (0 errors, 146 warnings)
- Tests: ✓ 8/9 smoke tests PASS
- Functionality: ✓ PRESERVED (no behavior changes)
Files created:
- src/backend/mir_interpreter/utils/mod.rs
- src/backend/mir_interpreter/utils/destination_helpers.rs
- src/backend/mir_interpreter/utils/arg_validation.rs
- src/backend/mir_interpreter/utils/receiver_helpers.rs
Files modified: 15 handler files
- arithmetic.rs, boxes.rs, boxes_array.rs, boxes_instance.rs
- boxes_map.rs, boxes_object_fields.rs, boxes_plugin.rs
- boxes_string.rs, calls.rs, extern_provider.rs, externals.rs
- memory.rs, misc.rs, mod.rs
Related: Phase 21.0 refactoring
Risk: Low (pure refactoring, no behavior change)
2025-11-06 22:50:46 +09:00
|
|
|
this.write_result(dst, VMValue::from_nyash_box(ret));
|
2025-11-02 11:47:58 +09:00
|
|
|
return Ok(true);
|
|
|
|
|
}
|
2025-09-26 14:34:42 +09:00
|
|
|
"len" | "length" | "size" => {
|
|
|
|
|
let ret = ab.length();
|
refactor: add MIR interpreter utility helpers (Phase 1)
- Add destination write helpers (write_box_result, write_void, write_result)
- Add argument validation helpers (validate_args_exact/range/min)
- Add receiver conversion helper (convert_to_box)
- Update handlers to use new helpers
Reduces code duplication:
- Destination patterns: 37 call sites converted
- Each replacement saves 2-3 lines (74-111 lines saved)
- Helper infrastructure: 178 lines added
- Net improvement: Reduced duplication + better maintainability
Impact:
- Build: ✓ SUCCESS (0 errors, 146 warnings)
- Tests: ✓ 8/9 smoke tests PASS
- Functionality: ✓ PRESERVED (no behavior changes)
Files created:
- src/backend/mir_interpreter/utils/mod.rs
- src/backend/mir_interpreter/utils/destination_helpers.rs
- src/backend/mir_interpreter/utils/arg_validation.rs
- src/backend/mir_interpreter/utils/receiver_helpers.rs
Files modified: 15 handler files
- arithmetic.rs, boxes.rs, boxes_array.rs, boxes_instance.rs
- boxes_map.rs, boxes_object_fields.rs, boxes_plugin.rs
- boxes_string.rs, calls.rs, extern_provider.rs, externals.rs
- memory.rs, misc.rs, mod.rs
Related: Phase 21.0 refactoring
Risk: Low (pure refactoring, no behavior change)
2025-11-06 22:50:46 +09:00
|
|
|
this.write_result(dst, VMValue::from_nyash_box(ret));
|
2025-09-26 14:34:42 +09:00
|
|
|
return Ok(true);
|
|
|
|
|
}
|
|
|
|
|
"get" => {
|
2025-11-06 22:59:47 +09:00
|
|
|
this.validate_args_exact("get", args, 1)?;
|
2025-09-26 14:34:42 +09:00
|
|
|
let idx = this.reg_load(args[0])?.to_nyash_box();
|
|
|
|
|
let ret = ab.get(idx);
|
refactor: add MIR interpreter utility helpers (Phase 1)
- Add destination write helpers (write_box_result, write_void, write_result)
- Add argument validation helpers (validate_args_exact/range/min)
- Add receiver conversion helper (convert_to_box)
- Update handlers to use new helpers
Reduces code duplication:
- Destination patterns: 37 call sites converted
- Each replacement saves 2-3 lines (74-111 lines saved)
- Helper infrastructure: 178 lines added
- Net improvement: Reduced duplication + better maintainability
Impact:
- Build: ✓ SUCCESS (0 errors, 146 warnings)
- Tests: ✓ 8/9 smoke tests PASS
- Functionality: ✓ PRESERVED (no behavior changes)
Files created:
- src/backend/mir_interpreter/utils/mod.rs
- src/backend/mir_interpreter/utils/destination_helpers.rs
- src/backend/mir_interpreter/utils/arg_validation.rs
- src/backend/mir_interpreter/utils/receiver_helpers.rs
Files modified: 15 handler files
- arithmetic.rs, boxes.rs, boxes_array.rs, boxes_instance.rs
- boxes_map.rs, boxes_object_fields.rs, boxes_plugin.rs
- boxes_string.rs, calls.rs, extern_provider.rs, externals.rs
- memory.rs, misc.rs, mod.rs
Related: Phase 21.0 refactoring
Risk: Low (pure refactoring, no behavior change)
2025-11-06 22:50:46 +09:00
|
|
|
this.write_result(dst, VMValue::from_nyash_box(ret));
|
2025-09-26 14:34:42 +09:00
|
|
|
return Ok(true);
|
|
|
|
|
}
|
|
|
|
|
"set" => {
|
2025-11-06 22:59:47 +09:00
|
|
|
this.validate_args_exact("set", args, 2)?;
|
2025-09-26 14:34:42 +09:00
|
|
|
let idx = this.reg_load(args[0])?.to_nyash_box();
|
|
|
|
|
let val = this.reg_load(args[1])?.to_nyash_box();
|
|
|
|
|
let _ = ab.set(idx, val);
|
refactor: add MIR interpreter utility helpers (Phase 1)
- Add destination write helpers (write_box_result, write_void, write_result)
- Add argument validation helpers (validate_args_exact/range/min)
- Add receiver conversion helper (convert_to_box)
- Update handlers to use new helpers
Reduces code duplication:
- Destination patterns: 37 call sites converted
- Each replacement saves 2-3 lines (74-111 lines saved)
- Helper infrastructure: 178 lines added
- Net improvement: Reduced duplication + better maintainability
Impact:
- Build: ✓ SUCCESS (0 errors, 146 warnings)
- Tests: ✓ 8/9 smoke tests PASS
- Functionality: ✓ PRESERVED (no behavior changes)
Files created:
- src/backend/mir_interpreter/utils/mod.rs
- src/backend/mir_interpreter/utils/destination_helpers.rs
- src/backend/mir_interpreter/utils/arg_validation.rs
- src/backend/mir_interpreter/utils/receiver_helpers.rs
Files modified: 15 handler files
- arithmetic.rs, boxes.rs, boxes_array.rs, boxes_instance.rs
- boxes_map.rs, boxes_object_fields.rs, boxes_plugin.rs
- boxes_string.rs, calls.rs, extern_provider.rs, externals.rs
- memory.rs, misc.rs, mod.rs
Related: Phase 21.0 refactoring
Risk: Low (pure refactoring, no behavior change)
2025-11-06 22:50:46 +09:00
|
|
|
this.write_void(dst);
|
2025-09-26 14:34:42 +09:00
|
|
|
return Ok(true);
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(false)
|
|
|
|
|
}
|