Phase 7i: byte indexing p[i] / p[i] = v (retire peek8/poke8)
Raw byte access is now indexing, not C-style peek/poke: peek8(src, i) -> src[i] (reads a byte, widened to int) poke8(out, j, r) -> out[j] = r (narrows the int to a byte) E_INDEX on a non-slice pointer/string lowers to a `getelementptr i8` + load/zext (read) or trunc/store (write) — byte-identical to the old peek8/poke8, so the migration reproduces the compiler exactly. A "byte" element type (llty i8) drives the widen/narrow. The compiler's own byte work now reads naturally, e.g. `is_slice_ty` is `t[0] == 91 and t[1] == 93`. Subtlety fixed on the way: g_addr_ty (the out-param carrying the indexed element type) must be set AFTER evaluating the index expression, since a member/index in the index would otherwise clobber it — doing it early made a byte read load a full pointer from a byte address and crash the self-compile. Two reseeds: add byte-index support keeping peek8/poke8, then migrate 148 call sites and delete the intrinsics (+ the now-dead emit_gep_i8). Vocabulary drops peek8/poke8. Reseeded (22604 lines); C-free fixpoint holds; goldens identical; 18/18; vocab clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
3aaf983cf5
commit
feb3a71e56
25 changed files with 3309 additions and 3388 deletions
|
|
@ -14,20 +14,20 @@ fn char_is_alnum(c: int) -> bool { return char_is_alpha(c) or char_is_digit(c) }
|
|||
|
||||
# integer -> fresh decimal string
|
||||
fn itoa(v: int) -> ptr {
|
||||
if v == 0 { let z = mem_alloc(2); poke8(z, 0, 48); poke8(z, 1, 0); return z }
|
||||
if v == 0 { let z = mem_alloc(2); z[0] = 48; z[1] = 0; return z }
|
||||
var neg = false
|
||||
var x = v
|
||||
if x < 0 { neg = true; x = 0 - x }
|
||||
let tmp = mem_alloc(16)
|
||||
var n = 0
|
||||
while x > 0 { poke8(tmp, n, 48 + x % 10); x = x / 10; n = n + 1 }
|
||||
while x > 0 { tmp[n] = 48 + x % 10; x = x / 10; n = n + 1 }
|
||||
var total = n
|
||||
if neg { total = total + 1 }
|
||||
let out = mem_alloc(total + 1)
|
||||
var k = 0
|
||||
if neg { poke8(out, 0, 45); k = 1 }
|
||||
if neg { out[0] = 45; k = 1 }
|
||||
var i = 0
|
||||
while i < n { poke8(out, k + i, peek8(tmp, n - 1 - i)); i = i + 1 }
|
||||
poke8(out, total, 0)
|
||||
while i < n { out[k + i] = tmp[n - 1 - i]; i = i + 1 }
|
||||
out[total] = 0
|
||||
return out
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue