edf4513b5a
refactor: complete MIR interpreter utility migration (Phase 2)
...
Migrate remaining argument validation and destination write patterns
to utility helpers introduced in Phase 1.
Changes:
- boxes_map.rs: 135 → 123 lines (-12)
* 6 arg validations → validate_args_exact()
* 7 destination writes → write_result()
- externals.rs: 219 → 206 lines (-13)
* 12 destination patterns unified
* Simplified env/future/modules handling
- boxes_string.rs: 209 → 197 lines (-12)
* 4 arg validations + 4 destinations unified
* Methods: replace, contains, lastIndexOf, concat, etc.
- boxes_array.rs: 64 lines (3 validations migrated)
* Methods: push, get, set
- boxes_object_fields.rs: 400 → 394 lines (-6)
* 2 arg validations (getField, setField)
Pattern Elimination:
- Argument validation: 15 → 0 (100% eliminated)
- Destination writes: 51 → 28 (45% eliminated)
Code Reduction:
- Phase 2: 43 lines removed (1.3%)
- Cumulative: 117-154 lines removed (3.5-4.6% of handlers/)
Test Results:
- Build: ✅ SUCCESS (no new warnings)
- MapBox: ✅ 37/37 passed
- StringBox: ✅ 30/30 passed
- ArrayBox: ⚠️ 13/14 (1 pre-existing failure)
Benefits:
- Unified error messages across all handlers
- Single source of truth for validation logic
- Easier maintenance and future refactoring
- Consistent behavior throughout codebase
Related: Phase 21.0 refactoring (DUPLICATION_ANALYSIS_REPORT.md)
Risk: Low (pure refactoring, behavior preserved)
2025-11-06 22:59:47 +09:00
8d179e9499
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