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
|
|
@ -13,7 +13,7 @@ const IMG_MAX: int = 32
|
|||
const SPR_MAX: int = 160
|
||||
const SPR_SZ: int = 16
|
||||
|
||||
var img_px: ptr = null # IMG_MAX pointers to RGBA buffers
|
||||
var img_px: ptrs = null # IMG_MAX pointers to RGBA buffers
|
||||
var img_w: words = null
|
||||
var img_h: words = null
|
||||
var img_n: int = 0
|
||||
|
|
@ -232,7 +232,7 @@ fn rt_image_load(path: str) -> int {
|
|||
if rt_decode_png(path) == false { return 0 - 1 }
|
||||
let id = img_n
|
||||
img_n = img_n + 1
|
||||
pokep(img_px, id, png_px)
|
||||
img_px[id] = png_px
|
||||
img_w[id] = png_w
|
||||
img_h[id] = png_h
|
||||
return id
|
||||
|
|
@ -265,7 +265,7 @@ fn rt_draw_image(id: int, dx: int, dy: int) -> void {
|
|||
if id >= img_n { return }
|
||||
let w = img_w[id]
|
||||
let h = img_h[id]
|
||||
let s: words = peekp(img_px, id)
|
||||
let s: words = img_px[id]
|
||||
for y in 0 .. h {
|
||||
for x in 0 .. w {
|
||||
rt_blend_px(dx + x, dy + y, s[y * w + x])
|
||||
|
|
@ -280,7 +280,7 @@ fn rt_draw_image_scaled(id: int, dx: int, dy: int, dw: int, dh: int) -> void {
|
|||
if dh <= 0 { return }
|
||||
let w = img_w[id]
|
||||
let h = img_h[id]
|
||||
let s: words = peekp(img_px, id)
|
||||
let s: words = img_px[id]
|
||||
for y in 0 .. dh {
|
||||
for x in 0 .. dw {
|
||||
rt_blend_px(dx + x, dy + y, s[(y * h / dh) * w + x * w / dw])
|
||||
|
|
@ -305,7 +305,7 @@ fn rt_draw_9slice(id: int, dx: int, dy: int, dw: int, dh: int, inset: int) -> vo
|
|||
if dh <= 0 { return }
|
||||
let w = img_w[id]
|
||||
let h = img_h[id]
|
||||
let s: words = peekp(img_px, id)
|
||||
let s: words = img_px[id]
|
||||
for y in 0 .. dh {
|
||||
let sy = rt_9map(y, dh, h, inset)
|
||||
for x in 0 .. dw {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const TT_EDGES: int = 16384 # line segments in one glyph
|
|||
const TT_GC: int = 512 # glyph cache entries
|
||||
|
||||
# ---- per-font tables (parallel arrays; index = font id) -------------------
|
||||
var tt_data: ptr = null
|
||||
var tt_data: ptrs = null
|
||||
var tt_size: words = null
|
||||
var tt_upem: words = null
|
||||
var tt_nglyf: words = null
|
||||
|
|
@ -35,20 +35,20 @@ var tt_cfmt: words = null
|
|||
var tt_n: int = 0
|
||||
|
||||
# ---- outline + edge scratch (reused for every glyph) ----------------------
|
||||
var ol_x: ptr = null
|
||||
var ol_y: ptr = null
|
||||
var ol_x: fixeds = null
|
||||
var ol_y: fixeds = null
|
||||
var ol_on: words = null
|
||||
var ol_ends: words = null
|
||||
var ol_n: int = 0
|
||||
var ol_ne: int = 0
|
||||
|
||||
var ed_x0: ptr = null
|
||||
var ed_y0: ptr = null
|
||||
var ed_x1: ptr = null
|
||||
var ed_y1: ptr = null
|
||||
var ed_x0: fixeds = null
|
||||
var ed_y0: fixeds = null
|
||||
var ed_x1: fixeds = null
|
||||
var ed_y1: fixeds = null
|
||||
var ed_n: int = 0
|
||||
|
||||
var sc_x: ptr = null # scanline crossings
|
||||
var sc_x: fixeds = null # scanline crossings
|
||||
var sc_d: words = null
|
||||
|
||||
# ---- glyph cache ----------------------------------------------------------
|
||||
|
|
@ -61,7 +61,7 @@ var gc_h: words = null
|
|||
var gc_ox: words = null
|
||||
var gc_oy: words = null
|
||||
var gc_adv: words = null
|
||||
var gc_bmp: ptr = null
|
||||
var gc_bmp: ptrs = null
|
||||
|
||||
fn rt_tt_init() -> void {
|
||||
tt_data = bytes(TT_MAX * 8)
|
||||
|
|
@ -193,7 +193,7 @@ fn rt_font_load(path: str) -> int {
|
|||
|
||||
let id = tt_n
|
||||
tt_n = tt_n + 1
|
||||
pokep(tt_data, id, d)
|
||||
tt_data[id] = d
|
||||
tt_size[id] = size
|
||||
var upem = tt_u16(d, head + 18)
|
||||
if upem <= 0 { upem = 1000 }
|
||||
|
|
@ -213,7 +213,7 @@ fn rt_font_load(path: str) -> int {
|
|||
|
||||
# ---- codepoint -> glyph id ------------------------------------------------
|
||||
fn tt_glyph_index(id: int, cp: int) -> int {
|
||||
let d = peekp(tt_data, id)
|
||||
let d = tt_data[id]
|
||||
let s = tt_cmap[id]
|
||||
if s < 0 { return 0 }
|
||||
let fmt = tt_cfmt[id]
|
||||
|
|
@ -262,7 +262,7 @@ fn tt_glyph_index(id: int, cp: int) -> int {
|
|||
}
|
||||
|
||||
fn tt_advance(id: int, gid: int) -> int {
|
||||
let d = peekp(tt_data, id)
|
||||
let d = tt_data[id]
|
||||
let hmtx = tt_hmtx[id]
|
||||
let n = tt_nhm[id]
|
||||
if gid < n { return tt_u16(d, hmtx + gid * 4) }
|
||||
|
|
@ -272,20 +272,20 @@ fn tt_advance(id: int, gid: int) -> int {
|
|||
# ---- outline extraction ---------------------------------------------------
|
||||
fn ol_pt(x: fixed, y: fixed, on: int) -> void {
|
||||
if ol_n >= TT_PTS { return }
|
||||
pokef(ol_x, ol_n, x)
|
||||
pokef(ol_y, ol_n, y)
|
||||
ol_x[ol_n] = x
|
||||
ol_y[ol_n] = y
|
||||
ol_on[ol_n] = on
|
||||
ol_n = ol_n + 1
|
||||
}
|
||||
|
||||
fn tt_glyph_start(id: int, gid: int) -> int {
|
||||
let d = peekp(tt_data, id)
|
||||
let d = tt_data[id]
|
||||
let loca = tt_loca[id]
|
||||
if tt_locfm[id] == 0 { return tt_u16(d, loca + gid * 2) * 2 }
|
||||
return tt_u32(d, loca + gid * 4)
|
||||
}
|
||||
fn tt_glyph_end(id: int, gid: int) -> int {
|
||||
let d = peekp(tt_data, id)
|
||||
let d = tt_data[id]
|
||||
let loca = tt_loca[id]
|
||||
if tt_locfm[id] == 0 { return tt_u16(d, loca + (gid + 1) * 2) * 2 }
|
||||
return tt_u32(d, loca + (gid + 1) * 4)
|
||||
|
|
@ -299,7 +299,7 @@ fn tt_load_outline(id: int, gid: int, a: fixed, b: fixed, c: fixed, e: fixed, dx
|
|||
let goff = tt_glyph_start(id, gid)
|
||||
let gend = tt_glyph_end(id, gid)
|
||||
if goff >= gend { return }
|
||||
let d = peekp(tt_data, id)
|
||||
let d = tt_data[id]
|
||||
let g = tt_glyf[id] + goff
|
||||
let nc = tt_i16(d, g)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
# ---- rasterization --------------------------------------------------------
|
||||
fn ed_add(x0: fixed, y0: fixed, x1: fixed, y1: fixed) -> void {
|
||||
if ed_n >= TT_EDGES { return }
|
||||
pokef(ed_x0, ed_n, x0)
|
||||
pokef(ed_y0, ed_n, y0)
|
||||
pokef(ed_x1, ed_n, x1)
|
||||
pokef(ed_y1, ed_n, y1)
|
||||
ed_x0[ed_n] = x0
|
||||
ed_y0[ed_n] = y0
|
||||
ed_x1[ed_n] = x1
|
||||
ed_y1[ed_n] = y1
|
||||
ed_n = ed_n + 1
|
||||
}
|
||||
|
||||
|
|
@ -68,8 +68,8 @@ fn tt_raster(id: int, gid: int, px: int) -> ptr {
|
|||
var maxx = 0.0 - 999999.0
|
||||
var maxy = 0.0 - 999999.0
|
||||
for i in 0 .. ol_n {
|
||||
let X = peekf(ol_x, i) * scale
|
||||
let Y = peekf(ol_y, i) * scale
|
||||
let X = ol_x[i] * scale
|
||||
let Y = ol_y[i] * scale
|
||||
if X < minx { minx = X }
|
||||
if X > maxx { maxx = X }
|
||||
if Y < miny { miny = Y }
|
||||
|
|
@ -106,30 +106,30 @@ fn tt_raster(id: int, gid: int, px: int) -> ptr {
|
|||
var sy = 0.0
|
||||
if first_on < 0 {
|
||||
# all off-curve: start at the midpoint of the first and last point
|
||||
let mx = (peekf(ol_x, start) + peekf(ol_x, start + cnt - 1)) / 2
|
||||
let my = (peekf(ol_y, start) + peekf(ol_y, start + cnt - 1)) / 2
|
||||
let mx = (ol_x[start] + ol_x[start + cnt - 1]) / 2
|
||||
let my = (ol_y[start] + ol_y[start + cnt - 1]) / 2
|
||||
sx = (mx * scale - fx(x0)) * TT_SS
|
||||
sy = (fx(y1) - my * scale) * TT_SS
|
||||
first_on = 0
|
||||
} else {
|
||||
sx = (peekf(ol_x, start + first_on) * scale - fx(x0)) * TT_SS
|
||||
sy = (fx(y1) - peekf(ol_y, start + first_on) * scale) * TT_SS
|
||||
sx = (ol_x[start + first_on] * scale - fx(x0)) * TT_SS
|
||||
sy = (fx(y1) - ol_y[start + first_on] * scale) * TT_SS
|
||||
}
|
||||
var curx = sx
|
||||
var cury = sy
|
||||
var step = 0
|
||||
while step < cnt {
|
||||
let i = (first_on + 1 + step) % cnt
|
||||
let ix = (peekf(ol_x, start + i) * scale - fx(x0)) * TT_SS
|
||||
let iy = (fx(y1) - peekf(ol_y, start + i) * scale) * TT_SS
|
||||
let ix = (ol_x[start + i] * scale - fx(x0)) * TT_SS
|
||||
let iy = (fx(y1) - ol_y[start + i] * scale) * TT_SS
|
||||
if ol_on[start + i] == 1 {
|
||||
ed_add(curx, cury, ix, iy)
|
||||
curx = ix
|
||||
cury = iy
|
||||
} else {
|
||||
var j = (i + 1) % cnt
|
||||
let jx = (peekf(ol_x, start + j) * scale - fx(x0)) * TT_SS
|
||||
let jy = (fx(y1) - peekf(ol_y, start + j) * scale) * TT_SS
|
||||
let jx = (ol_x[start + j] * scale - fx(x0)) * TT_SS
|
||||
let jy = (fx(y1) - ol_y[start + j] * scale) * TT_SS
|
||||
var ex = jx
|
||||
var ey = jy
|
||||
if ol_on[start + j] == 1 {
|
||||
|
|
@ -159,38 +159,38 @@ fn tt_raster(id: int, gid: int, px: int) -> ptr {
|
|||
let yc = fx(sy) + 0.5
|
||||
var m = 0
|
||||
for i in 0 .. ed_n {
|
||||
let ya = peekf(ed_y0, i)
|
||||
let yb = peekf(ed_y1, i)
|
||||
let ya = ed_y0[i]
|
||||
let yb = ed_y1[i]
|
||||
var hit = 0
|
||||
if ya <= yc { if yb > yc { hit = 1 } }
|
||||
if yb <= yc { if ya > yc { hit = 1 } }
|
||||
if hit == 1 {
|
||||
let t = (yc - ya) / (yb - ya)
|
||||
pokef(sc_x, m, peekf(ed_x0, i) + t * (peekf(ed_x1, i) - peekf(ed_x0, i)))
|
||||
sc_x[m] = ed_x0[i] + t * (ed_x1[i] - ed_x0[i])
|
||||
if yb > ya { sc_d[m] = 1 } else { sc_d[m] = 0 - 1 }
|
||||
m = m + 1
|
||||
}
|
||||
}
|
||||
# insertion sort the crossings by x
|
||||
for i in 1 .. m {
|
||||
let kx = peekf(sc_x, i)
|
||||
let kx = sc_x[i]
|
||||
let kd = sc_d[i]
|
||||
var j = i - 1
|
||||
var placed = 0
|
||||
while j >= 0 {
|
||||
if peekf(sc_x, j) > kx {
|
||||
pokef(sc_x, j + 1, peekf(sc_x, j))
|
||||
if sc_x[j] > kx {
|
||||
sc_x[j + 1] = sc_x[j]
|
||||
sc_d[j + 1] = sc_d[j]
|
||||
j = j - 1
|
||||
} else {
|
||||
pokef(sc_x, j + 1, kx)
|
||||
sc_x[j + 1] = kx
|
||||
sc_d[j + 1] = kd
|
||||
placed = 1
|
||||
j = 0 - 1
|
||||
}
|
||||
}
|
||||
if placed == 0 {
|
||||
pokef(sc_x, 0, kx)
|
||||
sc_x[0] = kx
|
||||
sc_d[0] = kd
|
||||
}
|
||||
}
|
||||
|
|
@ -199,8 +199,8 @@ fn tt_raster(id: int, gid: int, px: int) -> ptr {
|
|||
for i in 0 .. m - 1 {
|
||||
wind = wind + sc_d[i]
|
||||
if wind != 0 {
|
||||
var xa = peekf(sc_x, i)
|
||||
var xb = peekf(sc_x, i + 1)
|
||||
var xa = sc_x[i]
|
||||
var xb = sc_x[i + 1]
|
||||
if xa < 0.0 { xa = 0.0 }
|
||||
if xb > fx(SW) { xb = fx(SW) }
|
||||
if xb > xa {
|
||||
|
|
@ -249,11 +249,11 @@ fn tt_glyph_get(font: int, cp: int, px: int) -> int {
|
|||
}
|
||||
let s = h
|
||||
if gc_used[s] == 1 {
|
||||
let old = peekp(gc_bmp, s)
|
||||
let old = gc_bmp[s]
|
||||
if (old == null) == false { mem_free(old) }
|
||||
}
|
||||
let bmp = tt_raster(font, tt_glyph_index(font, cp), px)
|
||||
pokep(gc_bmp, s, bmp)
|
||||
gc_bmp[s] = bmp
|
||||
gc_used[s] = 1
|
||||
gc_font[s] = font
|
||||
gc_cp[s] = cp
|
||||
|
|
@ -345,7 +345,7 @@ fn rt_text_ttf(font: int, x: int, y: int, s: str, colour: int, px: int) -> void
|
|||
baseline = baseline + lineh
|
||||
} else {
|
||||
let g = tt_glyph_get(font, cp, px)
|
||||
tt_blit(peekp(gc_bmp, g), gc_w[g], gc_h[g], penx + gc_ox[g], baseline - gc_oy[g], colour)
|
||||
tt_blit(gc_bmp[g], gc_w[g], gc_h[g], penx + gc_ox[g], baseline - gc_oy[g], colour)
|
||||
penx = penx + gc_adv[g]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ var ui_visible: words = null
|
|||
var ui_fired: words = null
|
||||
var ui_hasdyn: words = null
|
||||
var ui_dyn: ptr = null # UI_MAX * 96 bytes
|
||||
var ui_text: ptr = null # UI_MAX static string pointers
|
||||
var ui_text: ptrs = null # UI_MAX static string pointers
|
||||
|
||||
var ui_n: int = 0
|
||||
var ui_active: int = -1
|
||||
|
|
@ -138,7 +138,7 @@ fn rt_ui_reset(n: int) -> void {
|
|||
ui_visible[i] = 1
|
||||
ui_fired[i] = 0
|
||||
ui_hasdyn[i] = 0
|
||||
pokep(ui_text, i, null)
|
||||
ui_text[i] = null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,13 +171,13 @@ fn rt_ui_set(i: int, k: int, v: int) -> void {
|
|||
fn rt_ui_static_text(i: int, s: str) -> void {
|
||||
if i < 0 { return }
|
||||
if i >= UI_MAX { return }
|
||||
pokep(ui_text, i, s)
|
||||
ui_text[i] = s
|
||||
}
|
||||
|
||||
# ---- text helpers: TrueType when a font is loaded, bitmap otherwise -------
|
||||
fn ui_str(i: int) -> ptr {
|
||||
if ui_hasdyn[i] == 1 { return ptr_add(ui_dyn, i * 96) }
|
||||
let t = peekp(ui_text, i)
|
||||
let t = ui_text[i]
|
||||
if (t == null) { return ptr_add(ui_dyn, i * 96) }
|
||||
return t
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue