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:
@@ -201,18 +201,22 @@ fn now_ns() u64 = {
|
|||||||
// ---- cmat allocate / free ---------------------------------------------
|
// ---- cmat allocate / free ---------------------------------------------
|
||||||
|
|
||||||
fn cmat_alloc(w: i32, h: i32, r: *rng) *cmat = {
|
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.w = w;
|
||||||
m.h = h;
|
m.h = h;
|
||||||
m.gspeed = -1;
|
m.gspeed = -1;
|
||||||
m.gtheme = theme.GREEN: i32;
|
m.gtheme = theme.GREEN: i32;
|
||||||
m.flash = 0;
|
m.flash = 0;
|
||||||
let n4 = (w: u64) * 4u64;
|
let head_sl: []i32 = alloc([], w: u64)!;
|
||||||
m.head = rt.malloc(n4): *i32;
|
m.head = head_sl.ptr;
|
||||||
m.length = rt.malloc(n4): *i32;
|
let length_sl: []i32 = alloc([], w: u64)!;
|
||||||
m.speed = rt.malloc(n4): *i32;
|
m.length = length_sl.ptr;
|
||||||
m.counter = rt.malloc(n4): *i32;
|
let speed_sl: []i32 = alloc([], w: u64)!;
|
||||||
m.glyphs = rt.malloc((w: u64) * (MAX_TRAIL: u64)): *u8;
|
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;
|
let c = 0;
|
||||||
for (c < w) {
|
for (c < w) {
|
||||||
m.head[c] = -rng_range(r, 0, h);
|
m.head[c] = -rng_range(r, 0, h);
|
||||||
|
|||||||
@@ -159,8 +159,8 @@ let perm_arena: arena;
|
|||||||
let trans_arena: arena;
|
let trans_arena: arena;
|
||||||
|
|
||||||
fn arena_new_chunk(prev: *chunk) *chunk = {
|
fn arena_new_chunk(prev: *chunk) *chunk = {
|
||||||
let raw: *u8 = rt.malloc(ARENA_CHUNK): *u8;
|
let raw: []u8 = alloc([], ARENA_CHUNK)!;
|
||||||
let c: *chunk = raw: *chunk;
|
let c: *chunk = raw.ptr: *chunk;
|
||||||
c.next = prev;
|
c.next = prev;
|
||||||
c.cur = 0u64;
|
c.cur = 0u64;
|
||||||
return c;
|
return c;
|
||||||
@@ -1566,10 +1566,14 @@ fn bind_one(e: **env, name: str, id: i32) void = {
|
|||||||
|
|
||||||
export fn initsyms() void = {
|
export fn initsyms() void = {
|
||||||
arena_init();
|
arena_init();
|
||||||
sym_off = rt.malloc((SYM_CAP: u64) * 4u64): *i32;
|
let sym_off_sl: []i32 = alloc([], SYM_CAP: u64)!;
|
||||||
sym_len = rt.malloc((SYM_CAP: u64) * 4u64): *i32;
|
sym_off = sym_off_sl.ptr;
|
||||||
sym_blob = rt.malloc(SYM_BLOBSZ: u64): *u8;
|
let sym_len_sl: []i32 = alloc([], SYM_CAP: u64)!;
|
||||||
obuf = rt.malloc(OBUF_SZ: u64): *u8;
|
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.
|
// Stash the special-form ids so classify_sform sees them.
|
||||||
SID_QUOTE = intern("quote");
|
SID_QUOTE = intern("quote");
|
||||||
|
|||||||
Reference in New Issue
Block a user