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
|
|
@ -36,10 +36,10 @@ fn ptype() -> ptr {
|
|||
eat_op("]")
|
||||
let el = ptype()
|
||||
let out = mem_alloc(len(el) + 3)
|
||||
poke8(out, 0, 91); poke8(out, 1, 93) # "[]"
|
||||
out[0] = 91; out[1] = 93 # "[]"
|
||||
var i = 0
|
||||
while peek8(el, i) != 0 { poke8(out, 2 + i, peek8(el, i)); i = i + 1 }
|
||||
poke8(out, 2 + i, 0)
|
||||
while el[i] != 0 { out[2 + i] = el[i]; i = i + 1 }
|
||||
out[2 + i] = 0
|
||||
return out
|
||||
}
|
||||
return eat_id()
|
||||
|
|
@ -79,15 +79,15 @@ fn parse_interp(raw: ptr) -> Node {
|
|||
var lj = 0
|
||||
var i = 0
|
||||
while i < n {
|
||||
let c = peek8(raw, i)
|
||||
let c = raw[i]
|
||||
if c == 123 { # '{'
|
||||
if peek8(raw, i + 1) == 123 { poke8(lit, lj, 123); lj = lj + 1; i = i + 2; continue } # {{ -> {
|
||||
if raw[i + 1] == 123 { lit[lj] = 123; lj = lj + 1; i = i + 2; continue } # {{ -> {
|
||||
if lj > 0 { acc = interp_add(acc, interp_lit(lit, lj)); lj = 0 }
|
||||
i = i + 1
|
||||
let hs = i
|
||||
var depth = 1
|
||||
while i < n and depth > 0 {
|
||||
let d = peek8(raw, i)
|
||||
let d = raw[i]
|
||||
if d == 123 { depth = depth + 1 }
|
||||
else { if d == 125 { depth = depth - 1; if depth == 0 { break } } }
|
||||
i = i + 1
|
||||
|
|
@ -95,14 +95,14 @@ fn parse_interp(raw: ptr) -> Node {
|
|||
acc = interp_add(acc, interp_str(parse_hole(raw[hs..i])))
|
||||
i = i + 1 # skip the closing '}'
|
||||
} else {
|
||||
if c == 125 and peek8(raw, i + 1) == 125 { poke8(lit, lj, 125); lj = lj + 1; i = i + 2; continue } # }} -> }
|
||||
if c == 125 and raw[i + 1] == 125 { lit[lj] = 125; lj = lj + 1; i = i + 2; continue } # }} -> }
|
||||
if c == 92 { # backslash escape in literal text
|
||||
let e = peek8(raw, i + 1); var r = e
|
||||
let e = raw[i + 1]; var r = e
|
||||
if e == 110 { r = 10 }
|
||||
if e == 116 { r = 9 }
|
||||
poke8(lit, lj, r); lj = lj + 1; i = i + 2; continue
|
||||
lit[lj] = r; lj = lj + 1; i = i + 2; continue
|
||||
}
|
||||
poke8(lit, lj, c); lj = lj + 1; i = i + 1
|
||||
lit[lj] = c; lj = lj + 1; i = i + 1
|
||||
}
|
||||
}
|
||||
if lj > 0 or (acc == null) { acc = interp_add(acc, interp_lit(lit, lj)) }
|
||||
|
|
@ -311,12 +311,12 @@ fn parse_main() -> Node { pi = pi + 1; let n = node(N_MAIN); n.a = block(); retu
|
|||
fn dir_of(path: ptr) -> ptr {
|
||||
var last = 0 - 1
|
||||
var i = 0
|
||||
while peek8(path, i) != 0 { if peek8(path, i) == 47 { last = i }; i = i + 1 }
|
||||
while path[i] != 0 { if path[i] == 47 { last = i }; i = i + 1 }
|
||||
if last < 0 { return "" }
|
||||
return path[0..0 + (last + 1)]
|
||||
}
|
||||
fn path_join(dir: ptr, rel: ptr) -> ptr {
|
||||
if peek8(rel, 0) == 47 { return rel } # absolute
|
||||
if rel[0] == 47 { return rel } # absolute
|
||||
return (dir + rel)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue