Phase 7f: len(x) works on strings too (retire slen)

`len` is now polymorphic — a slice's element count OR a string's byte length —
so the C-style `slen` (strlen) is gone: `slen(name)` -> `len(name)`. emit_len
branches on the operand type (slice header vs @strlen). Two reseeds: add the
string branch, then migrate the 19 slen calls and delete slen.

Reseeded (22565 lines); C-free fixpoint holds; goldens identical; 18/18; vocab +
doc-fences clean. (String slicing s[a..b] to replace substr is deferred to its
own phase.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-08-28 01:25:57 +03:00
parent 058cac88ec
commit 839a6bf0c0
11 changed files with 3555 additions and 3542 deletions

View file

@ -50,8 +50,12 @@ fn slice_field(h: ptr, i: int) -> ptr {
fn emit_len(e: Node) -> Val {
let s = emit_expr(e.kids[0])
let lp = slice_field(s.code, 1)
return val(emit_bind(("load i32, ptr " + lp)), "int")
if is_slice_ty(s.ty) { # a slice: read its header length
let lp = slice_field(s.code, 1)
return val(emit_bind(("load i32, ptr " + lp)), "int")
}
let r = emit_bind(("call i64 @strlen(ptr " + (s.code + ")"))) # a string: byte length
return val(emit_bind(("trunc i64 " + (r + " to i32"))), "int")
}
fn emit_push(e: Node) -> Val {