Commit Graph

3 Commits

Author SHA1 Message Date
8488df58a8 Phase 6 WIP: Type conversion helpers (11 sites, 23 lines)
Added conversion_helpers.rs with unified type conversion:
- load_as_box() for reg_load().to_nyash_box()
- load_as_string() for reg_load().to_string()
- load_as_int/bool() for type-checked loads
- load_args_as_boxes/values() for bulk conversion

Files updated (partial):
- boxes.rs: 2 sites (-6 lines)
- calls.rs: 5 sites (-10 lines)
- boxes_plugin.rs: 1 site (-3 lines)
- externals.rs: 3 sites (-4 lines)

Next: boxes_array, boxes_map, boxes_object_fields, boxes_instance

Tests: Phase 21.0 PASS (2/2, 100%)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 00:21:42 +09:00
0287020a5b refactor: unify error message generation (Phase 3)
Add ErrorBuilder utility and migrate 35 error generation sites

Phase 3: Error Message Generation Unification
============================================

Infrastructure:
- Add src/backend/mir_interpreter/utils/error_helpers.rs (255 lines)
- Implement ErrorBuilder with 7 standardized error patterns
- Add MirInterpreter convenience methods (err_invalid, err_type_mismatch, etc.)

Migration Results:
- Total patterns migrated: 35 instances (80 → 45, 44% reduction)
- calls.rs: 37 → 13 patterns (65% reduction)
- extern_provider.rs: 20 → 9 patterns (55% reduction)
- Lines saved: 33 lines (1.0% of handlers)

Error Patterns Unified:
1. Invalid instruction errors → ErrorBuilder::invalid_instruction()
2. Type mismatch errors → ErrorBuilder::type_mismatch()
3. Argument count errors → ErrorBuilder::arg_count_mismatch()
4. Method not found → ErrorBuilder::method_not_found()
5. Unsupported operations → ErrorBuilder::unsupported_operation()
6. Context errors → ErrorBuilder::with_context()
7. Bounds errors → ErrorBuilder::out_of_bounds()

Benefits:
- Consistent error message formatting across all handlers
- Single point of change for error improvements
- Better IDE autocomplete support
- Easier future i18n integration
- Reduced code duplication

Cumulative Impact (Phase 1+2+3):
- Total lines saved: 150-187 lines (4.5-5.7% of handlers)
- Total patterns unified: 124 instances
  * Phase 1: 37 destination patterns
  * Phase 2: 52 argument validation patterns
  * Phase 3: 35 error generation patterns

Remaining Work:
- 45 error patterns still to migrate (estimated 50-80 lines)
- Complex cases requiring manual review

Testing:
- Build:  0 errors, 0 new warnings
- Smoke tests: ⚠️ 8/9 passed (1 timeout unrelated)
- Core functionality:  Verified

Related: Phase 21.0 MIR Interpreter refactoring
Risk: Low (error messages only, behavior preserved)
Impact: High (maintainability, consistency, i18n-ready)

Co-authored-by: Claude Code <claude@anthropic.com>
2025-11-06 23:18:10 +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