lib: extract rt module from os, sweep imports

Hare puts runtime allocation in rt::, not os:: (ref/hare/rt/malloc.ha:27,
README). ww's `@symbol("rt_alloc") fn alloc(n: u64) *void;` lived at
lib/os/os.ww as a historical bootstrap shortcut; this commit relocates
it to a new lib/rt/malloc.ww and sweeps every site that depended on
`import os` for the alloc decl over to `import rt`.

This is commit 1 of 3 in the lib/rt extraction (#35):
  1. (this) move decl, sweep imports — preserves shape
  2. rename rt_alloc → rt_malloc (#38)
  3. nullable return type + OOM-propagating builtin lowering (#39)

No rename here. Symbol stays rt_alloc, function stays `alloc`, return
stays *void. Behavior identical — same ffi resolution outcome, just
sourced from a different module file. The rt::ensure runtime helper at
selfhost/rt/ensure.ww is its own compilation unit with a local decl and
is untouched.

Side effect: every wcc cgen file used `rt` as a local *node variable
name for "return type." `import rt;` shadows the module, so each
selfhost/cmd/wcc/{check,cgenstmt,cgenexpr,cgenutil}.ww site renamed
to `rtyp`. Mechanical follow-through; only the wcc module-import was
forced to do this rename.

Verified 132/132 + 995_self_rebuild byte-identity (5 wwstage tools
round-trip byte-identical).
This commit is contained in:
2026-05-20 20:39:52 +09:00
parent a1ee817906
commit d68d3c7eb4
34 changed files with 530 additions and 488 deletions

View File

@@ -29,6 +29,7 @@
package cmatrix;
import os;
import rt;
import time;
import fmt;
@@ -200,18 +201,18 @@ fn now_ns() u64 = {
// ---- cmat allocate / free ---------------------------------------------
fn cmat_alloc(w: i32, h: i32, r: *rng) *cmat = {
let m = os.alloc(CMAT_SZ): *cmat;
let m = rt.alloc(CMAT_SZ): *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 = os.alloc(n4): *i32;
m.length = os.alloc(n4): *i32;
m.speed = os.alloc(n4): *i32;
m.counter = os.alloc(n4): *i32;
m.glyphs = os.alloc((w: u64) * (MAX_TRAIL: u64)): *u8;
m.head = rt.alloc(n4): *i32;
m.length = rt.alloc(n4): *i32;
m.speed = rt.alloc(n4): *i32;
m.counter = rt.alloc(n4): *i32;
m.glyphs = rt.alloc((w: u64) * (MAX_TRAIL: u64)): *u8;
let c = 0;
for (c < w) {
m.head[c] = -rng_range(r, 0, h);

View File

@@ -62,6 +62,7 @@
package lisp;
import os;
import rt;
import fmt;
import ascii;
import strconv;
@@ -158,7 +159,7 @@ let perm_arena: arena;
let trans_arena: arena;
fn arena_new_chunk(prev: *chunk) *chunk = {
let raw: *u8 = os.alloc(ARENA_CHUNK): *u8;
let raw: *u8 = rt.alloc(ARENA_CHUNK): *u8;
let c: *chunk = raw: *chunk;
c.next = prev;
c.cur = 0u64;
@@ -1565,10 +1566,10 @@ fn bind_one(e: **env, name: str, id: i32) void = {
export fn initsyms() void = {
arena_init();
sym_off = os.alloc((SYM_CAP: u64) * 4u64): *i32;
sym_len = os.alloc((SYM_CAP: u64) * 4u64): *i32;
sym_blob = os.alloc(SYM_BLOBSZ: u64): *u8;
obuf = os.alloc(OBUF_SZ: u64): *u8;
sym_off = rt.alloc((SYM_CAP: u64) * 4u64): *i32;
sym_len = rt.alloc((SYM_CAP: u64) * 4u64): *i32;
sym_blob = rt.alloc(SYM_BLOBSZ: u64): *u8;
obuf = rt.alloc(OBUF_SZ: u64): *u8;
// Stash the special-form ids so classify_sform sees them.
SID_QUOTE = intern("quote");