Commit e23f48b
compiler: lower polymorphic len() to wasm (string + array length) (#583)
## Lower polymorphic `len()` to wasm (string + array length)
A string-wall residual found while verifying the migration corpus is
actually unblocked: **`len()` did not lower to wasm**
(`Codegen.UnboundVariable "len"`) — only `string_length` did.
AffineScript arrays and strings share the same `[len: i32][payload…]`
header (the list-concat handler already relies on this), so `len()` is
the **same single `i32.load` at offset 0** whether its argument is a
`String` or an array. Merged into the existing `string_length` arm.
This unblocks the **stdlib string layer** on the wasm backend
(`starts_with`/`ends_with`/`substring`/`split`/`join`/`pad_*` all call
`len()` on strings; `join` also on arrays), which the corpus's
`String.length` pattern (30 files) needs.
**Verified:** `len("abcd")`=4 and `len([10,20,30])`=3 lower and run;
full `run_codegen_wasm_tests.sh` green (no regressions).
**Separately noted (not fixed here):** string `==`/`!=` still lower to
*pointer* comparison, not value comparison (`string_sub(...) == "ab"` is
wrongly `0`) — a #555-class interp-vs-wasm divergence, tracked for a
follow-up slice. It only affects string-logic kernels; integer-brain
extraction (strings kept host-side) is unaffected.
https://claude.ai/code/session_01WoKhFQePiRsAj7aqnxbG8s
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WoKhFQePiRsAj7aqnxbG8s)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent f8230ce commit e23f48b
1 file changed
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1002 | 1002 | | |
1003 | 1003 | | |
1004 | 1004 | | |
1005 | | - | |
| 1005 | + | |
| 1006 | + | |
1006 | 1007 | | |
1007 | 1008 | | |
1008 | 1009 | | |
1009 | 1010 | | |
1010 | 1011 | | |
1011 | 1012 | | |
1012 | | - | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
1013 | 1023 | | |
1014 | 1024 | | |
1015 | 1025 | | |
| |||
0 commit comments