Phase 8a: finish typed indexing — fixeds/ptrs buffers (retire peekf/pokef/peekp/pokep/str_len)
The last peek/poke pairs were the same "typed buffer access wearing a C name" as peek8/peek32, so they become indexing too: peekf(sc_x, i) -> sc_x[i] (a `fixeds` buffer -> a fixed) pokep(gc_bmp, s,b) -> gc_bmp[s] = b (a `ptrs` buffer -> a pointer) str_len(s) -> len(s) (len is polymorphic since 7f; str_len was dead) Two new element-typed buffers join words: `fixeds` (32-bit fixed) and `ptrs` (pointer, 8-byte stride). emit_index_addr dispatches on the base type; IR is byte-identical to the old intrinsics. The peekf/peekp buffers (ed_x0/ed_x1/ol_x/sc_x fixed coords; gc_bmp/img_px/ tt_data/ui_text pointer arrays) were retyped scope-aware, then the 33 sites migrated to indexing. Two bugs found via a menu golden diff / a link-time type error and fixed: the buffer-name regex truncated digit suffixes (ed_x0 -> ed_x), and the char-literal brace-miscount skipped a few module declarations (same class as 7j). Reseeded (22371 lines); C-free fixpoint holds; goldens byte-identical; 18/18; vocab (fixeds/ptrs types in, 5 intrinsics out) + doc-fences clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
ae65acde33
commit
5a9e8cb2da
13 changed files with 2992 additions and 3206 deletions
|
|
@ -23,11 +23,21 @@ fn emit_index_addr(e: Node) -> ptr {
|
|||
let base = emit_expr(e.a)
|
||||
if not is_slice_ty(base.ty) { # a raw pointer: address of element i
|
||||
let bi = emit_expr(e.b) # (evaluate index first — it may set g_addr_ty)
|
||||
if (base.ty == "words") { # a `words` buffer: 32-bit elements
|
||||
if (base.ty == "words") { # a `words` buffer: 32-bit int elements
|
||||
let rw = emit_bind(`getelementptr inbounds i32, ptr {base.code}, i32 {bi.code}`)
|
||||
g_addr_ty = "int"
|
||||
return rw
|
||||
}
|
||||
if (base.ty == "fixeds") { # a `fixeds` buffer: 32-bit fixed elements
|
||||
let rf = emit_bind(`getelementptr inbounds i32, ptr {base.code}, i32 {bi.code}`)
|
||||
g_addr_ty = "fixed"
|
||||
return rf
|
||||
}
|
||||
if (base.ty == "ptrs") { # a `ptrs` buffer: pointer elements
|
||||
let rp = emit_bind(`getelementptr inbounds ptr, ptr {base.code}, i32 {bi.code}`)
|
||||
g_addr_ty = "ptr"
|
||||
return rp
|
||||
}
|
||||
let r = emit_bind(`getelementptr inbounds i8, ptr {base.code}, i32 {bi.code}`) # a ptr/str: bytes
|
||||
g_addr_ty = "byte" # set last so the caller sees it
|
||||
return r
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ fn lbl(pfx: ptr) -> ptr { let r = (pfx + itoa(ll_lbl)); ll_lbl = ll_lbl + 1; r
|
|||
fn llty(t: ptr) -> ptr {
|
||||
if (t == "int") or (t == "bool") or (t == "fixed") { return "i32" }
|
||||
if (t == "byte") { return "i8" } # a single byte (p[i] on a raw ptr)
|
||||
if (t == "words") { return "ptr" } # a 32-bit-word buffer (w[i] is i32)
|
||||
if (t == "words") or (t == "fixeds") or (t == "ptrs") { return "ptr" } # typed buffers
|
||||
if (t == "void") { return "void" }
|
||||
return "ptr"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,8 @@ var g_windowed: bool = false # headless by default (games read stdin / dump
|
|||
fn is_intrinsic2(name: ptr) -> bool {
|
||||
if (name == "mem_free") or (name == "mem_copy") or (name == "mem_set") { return true }
|
||||
if (name == "ptr_add") or (name == "read_byte") or (name == "write_byte") { return true }
|
||||
if (name == "str_len") or (name == "os_time") { return true }
|
||||
if (name == "peekf") or (name == "pokef") or (name == "as_fixed") or (name == "as_int") { return true }
|
||||
if (name == "peekp") or (name == "pokep") { return true }
|
||||
if (name == "os_time") { return true }
|
||||
if (name == "as_fixed") or (name == "as_int") { return true }
|
||||
if (name == "is_windowed") or (name == "game_title") { return true }
|
||||
if (name == "win_open") or (name == "win_poll") or (name == "win_present") { return true }
|
||||
if (name == "win_running") or (name == "win_close") { return true }
|
||||
|
|
@ -42,37 +41,10 @@ fn emit_intrinsic2(name: ptr, e: Node) -> Val {
|
|||
if (name == "write_byte") {
|
||||
let v = arg_code(e, 0); emit(" call i32 @putchar(i32 "); emit(v); emit(")\n"); return val("0", "void")
|
||||
}
|
||||
if (name == "str_len") {
|
||||
let s = arg_code(e, 0)
|
||||
let r = emit_bind(`call i64 @strlen(ptr {s})`)
|
||||
return val(emit_bind(`trunc i64 {r} to i32`), "int")
|
||||
}
|
||||
if (name == "os_time") {
|
||||
let r = emit_bind("call i64 @time(ptr null)")
|
||||
return val(emit_bind(`trunc i64 {r} to i32`), "int")
|
||||
}
|
||||
if (name == "peekf") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1)
|
||||
let g = nreg(); emit(" "); emit(g); emit(" = getelementptr inbounds i32, ptr "); emit(p); emit(", i32 "); emit(i); emit("\n")
|
||||
return val(emit_bind(`load i32, ptr {g}`), "fixed")
|
||||
}
|
||||
if (name == "pokef") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1); let v = arg_code(e, 2)
|
||||
let g = nreg(); emit(" "); emit(g); emit(" = getelementptr inbounds i32, ptr "); emit(p); emit(", i32 "); emit(i); emit("\n")
|
||||
emit(" store i32 "); emit(v); emit(", ptr "); emit(g); emit("\n")
|
||||
return val("0", "void")
|
||||
}
|
||||
if (name == "peekp") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1)
|
||||
let g = nreg(); emit(" "); emit(g); emit(" = getelementptr inbounds ptr, ptr "); emit(p); emit(", i32 "); emit(i); emit("\n")
|
||||
return val(emit_bind(`load ptr, ptr {g}`), "ptr")
|
||||
}
|
||||
if (name == "pokep") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1); let v = arg_code(e, 2)
|
||||
let g = nreg(); emit(" "); emit(g); emit(" = getelementptr inbounds ptr, ptr "); emit(p); emit(", i32 "); emit(i); emit("\n")
|
||||
emit(" store ptr "); emit(v); emit(", ptr "); emit(g); emit("\n")
|
||||
return val("0", "void")
|
||||
}
|
||||
if (name == "as_fixed") { let a = emit_expr(e.kids[0]); return val(a.code, "fixed") }
|
||||
if (name == "as_int") { let a = emit_expr(e.kids[0]); return val(a.code, "int") }
|
||||
if (name == "is_windowed") { if g_windowed { return val("1", "bool") }; return val("0", "bool") }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue