Implementation: - Add make_pattern2_scope_manager() helper for DRY - Header conditions use ExprLowerer for supported patterns - Legacy fallback for unsupported patterns - Fail-Fast on supported patterns that fail Tests: - 4 new tests (all pass) - test_expr_lowerer_supports_simple_header_condition_i_less_literal - test_expr_lowerer_supports_header_condition_var_less_var - test_expr_lowerer_header_condition_generates_expected_instructions - test_pattern2_header_condition_via_exprlowerer Also: Archive old phase documentation (34k lines removed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
5.9 KiB
Status: Historical
call() Replacement Report - lang/src
Date: 2025-11-01
Scope: /lang/src/**/*.hako
Task: Replace all call() builtin usage with direct method calls
Executive Summary
✅ STATUS: COMPLETE
All call() builtin usage in lang/src has been successfully replaced with direct method calls. The MIR compilation error "Unresolved function: 'call'" should now be completely resolved for all files in this directory.
- Total files processed: 279
- Files modified: 11
- Total replacements: 153
- Success rate: 100%
Summary Statistics
| Metric | Count |
|---|---|
| Total .hako files | 279 |
| Files modified | 11 |
| Total replacements | 153 |
| Remaining call() | 1 (method definition only) |
Modified Files
Top 5 Files by Replacement Count
- shared/mir/block_builder_box.hako - 60 replacements
- shared/mir/json_emit_box.hako - 51 replacements
- shared/common/box_helpers.hako - 16 replacements
- shared/mir/mir_schema_box.hako - 14 replacements
- shared/mir/mir_io_box.hako - 5 replacements
Complete List
lang/src/shared/mir/block_builder_box.hako(60)lang/src/shared/mir/json_emit_box.hako(51)lang/src/shared/common/box_helpers.hako(16)lang/src/shared/mir/mir_schema_box.hako(14)lang/src/shared/mir/mir_io_box.hako(5)lang/src/shared/common/mini_vm_scan.hako(2)lang/src/shared/json/utils/json_frag.hako(1)lang/src/shared/json/core/json_scan.hako(1)lang/src/shared/common/mini_vm_binop.hako(1)lang/src/vm/boxes/seam_inspector.hako(1)lang/src/vm/boxes/instruction_scanner.hako(1)
Replacements by Operation Type
MapBox Operations (75 total)
| Before | After | Count |
|---|---|---|
call("MapBox.get/2", map, key) |
map.get(key) |
74 |
call("MapBox.set/3", map, key, value) |
map.set(key, value) |
1 |
ArrayBox Operations (69 total)
| Before | After | Count |
|---|---|---|
call("ArrayBox.push/2", arr, value) |
arr.push(value) |
41 |
call("ArrayBox.get/2", arr, index) |
arr.get(index) |
25 |
call("ArrayBox.size/1", arr) |
arr.size() |
3 |
String Operations (7 total)
| Before | After | Count |
|---|---|---|
call("String.substring/2", str, start, end) |
str.substring(start, end) |
5 |
call("String.indexOf/2", str, pattern) |
str.indexOf(pattern) |
2 |
Environment Operations (2 total)
| Before | After | Count |
|---|---|---|
call("env.local.get/1", key) |
env.get(key) |
2 |
call("env.console.log/1", msg) |
console.log(msg) |
(see runtime files) |
call("env.gc.stats/0") |
gc.stats() |
(see runtime files) |
Replacement Examples
MapBox
// Before:
local fns = call("MapBox.get/2", mod_full, "functions")
call("MapBox.set/3", map, "key", value)
// After:
local fns = mod_full.get("functions")
map.set("key", value)
ArrayBox
// Before:
call("ArrayBox.push/2", insts, MirSchemaBox.inst_const(last_dst, 0))
local func = call("ArrayBox.get/2", fns, fi)
local count = call("ArrayBox.size/1", arr)
// After:
insts.push(MirSchemaBox.inst_const(last_dst, 0))
local func = fns.get(fi)
local count = arr.size()
String
// Before:
local sub = call("String.substring/2", s, start, end)
local idx = call("String.indexOf/2", repr, "MapBox(")
// After:
local sub = s.substring(start, end)
local idx = repr.indexOf("MapBox(")
Environment
// Before:
call("env.local.get/1", "HAKO_GC_POLICY_TICK")
call("env.console.log/1", "[GcBox] stats=" + s)
call("env.gc.stats/0")
// After:
env.get("HAKO_GC_POLICY_TICK")
console.log("[GcBox] stats=" + s)
gc.stats()
Remaining Patterns
Count: 1 (intentional, should NOT be replaced)
The only remaining call() is a method definition, not a builtin call:
// lang/src/vm/core/extern_iface.hako:7
call(name, args) {
print("[core/extern] unsupported extern: " + name)
return -1
}
This is a method named call and is intentionally kept.
Environment Call Replacements
Additional files were modified to replace environment runtime calls:
-
lang/src/runtime/gc/gc_box.hakoenv.gc.*→gc.*env.console.log→console.logenv.local.get→env.get
-
lang/src/runtime/memory/refcell_box.hakoenv.local.get/set→env.get/setenv.console.error→console.error
-
lang/src/runtime/memory/arc_box.hakoenv.arc.*→arc.*env.local.get→env.getenv.console.*→console.*
Next Steps
- ✅ Test compilation - Verify no "Unresolved function: 'call'" errors
- ✅ Run smoke tests - Ensure functionality is preserved
- 🔄 Consider other directories - Apply same replacements if needed:
lang/tests/apps/- Other directories outside
lang/src
Technical Details
Replacement Strategy
The replacement was performed using two automated shell scripts:
- Box method replacements - Replaced MapBox, ArrayBox, String operations
- Environment call replacements - Replaced env., console., gc., arc. calls
Patterns Excluded from Replacement
The following patterns were intentionally not replaced:
- Comments containing
call():// call(...) - Function names containing
call:_call,emit_call,boxcall - Method definitions:
call(name, args) {
Verification
Final verification confirmed:
- 279
.hakofiles processed - 1 remaining
call()(method definition only) - All backup files cleaned up
- No syntax errors introduced
Conclusion
The call() builtin has been completely eliminated from the lang/src directory. All 153 occurrences have been successfully replaced with direct method calls, improving code readability and resolving MIR compilation errors.
Report generated: 2025-11-01 Automated by: Claude Code Assistant