examples: α/γ rt.malloc → alloc([], N)! (cmatrix + lispcore)

Phase 0 #8 seventh α-batch. 11 sites across two examples:
 - cmatrix.ww: cmat struct (alloc(cmat{})!) + 4 γ i32 arrays
   (head/length/speed/counter) + 1 α u8 (glyphs)
 - lispcore.ww: 1 α arena chunk u8 + 2 γ i32 (sym_off/sym_len)
   + 2 α u8 (sym_blob, obuf)

γ pattern uses element count (was bytes/4). Struct fields stay
`*T` (legacy) so callers extract via intermediate `*_sl` local
slice + `.ptr` assign — verbose but mechanical until struct-field
slice types are part of a separate refactor.

Verified 132/132 + 995_self_rebuild byte-identity.
This commit is contained in:
2026-05-21 02:41:37 +09:00
parent 0f011661b6
commit 775b271dc7
2 changed files with 21 additions and 13 deletions

View File

@@ -201,18 +201,22 @@ fn now_ns() u64 = {
// ---- cmat allocate / free ---------------------------------------------
fn cmat_alloc(w: i32, h: i32, r: *rng) *cmat = {
let m = rt.malloc(CMAT_SZ): *cmat;
let m = alloc(cmat{})!;
m.w = w;
m.h = h;
m.gspeed = -1;
m.gtheme = theme.GREEN: i32;
m.flash = 0;
let n4 = (w: u64) * 4u64;
m.head = rt.malloc(n4): *i32;
m.length = rt.malloc(n4): *i32;
m.speed = rt.malloc(n4): *i32;
m.counter = rt.malloc(n4): *i32;
m.glyphs = rt.malloc((w: u64) * (MAX_TRAIL: u64)): *u8;
let head_sl: []i32 = alloc([], w: u64)!;
m.head = head_sl.ptr;
let length_sl: []i32 = alloc([], w: u64)!;
m.length = length_sl.ptr;
let speed_sl: []i32 = alloc([], w: u64)!;
m.speed = speed_sl.ptr;
let counter_sl: []i32 = alloc([], w: u64)!;
m.counter = counter_sl.ptr;
let glyphs_sl: []u8 = alloc([], (w: u64) * (MAX_TRAIL: u64))!;
m.glyphs = glyphs_sl.ptr;
let c = 0;
for (c < w) {
m.head[c] = -rng_range(r, 0, h);

View File

@@ -159,8 +159,8 @@ let perm_arena: arena;
let trans_arena: arena;
fn arena_new_chunk(prev: *chunk) *chunk = {
let raw: *u8 = rt.malloc(ARENA_CHUNK): *u8;
let c: *chunk = raw: *chunk;
let raw: []u8 = alloc([], ARENA_CHUNK)!;
let c: *chunk = raw.ptr: *chunk;
c.next = prev;
c.cur = 0u64;
return c;
@@ -1566,10 +1566,14 @@ fn bind_one(e: **env, name: str, id: i32) void = {
export fn initsyms() void = {
arena_init();
sym_off = rt.malloc((SYM_CAP: u64) * 4u64): *i32;
sym_len = rt.malloc((SYM_CAP: u64) * 4u64): *i32;
sym_blob = rt.malloc(SYM_BLOBSZ: u64): *u8;
obuf = rt.malloc(OBUF_SZ: u64): *u8;
let sym_off_sl: []i32 = alloc([], SYM_CAP: u64)!;
sym_off = sym_off_sl.ptr;
let sym_len_sl: []i32 = alloc([], SYM_CAP: u64)!;
sym_len = sym_len_sl.ptr;
let sym_blob_sl: []u8 = alloc([], SYM_BLOBSZ: u64)!;
sym_blob = sym_blob_sl.ptr;
let obuf_sl: []u8 = alloc([], OBUF_SZ: u64)!;
obuf = obuf_sl.ptr;
// Stash the special-form ids so classify_sform sees them.
SID_QUOTE = intern("quote");