From 775b271dc76bd74045d9e4e686729307793d67bb Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Thu, 21 May 2026 02:41:37 +0900 Subject: [PATCH] =?UTF-8?q?examples:=20=CE=B1/=CE=B3=20rt.malloc=20?= =?UTF-8?q?=E2=86=92=20alloc([],=20N)!=20(cmatrix=20+=20lispcore)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- examples/cmatrix/cmatrix.ww | 18 +++++++++++------- examples/lisp/lispcore.ww | 16 ++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/examples/cmatrix/cmatrix.ww b/examples/cmatrix/cmatrix.ww index 49051c66..6bb42981 100644 --- a/examples/cmatrix/cmatrix.ww +++ b/examples/cmatrix/cmatrix.ww @@ -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); diff --git a/examples/lisp/lispcore.ww b/examples/lisp/lispcore.ww index c97b9763..67523ed1 100644 --- a/examples/lisp/lispcore.ww +++ b/examples/lisp/lispcore.ww @@ -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");