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

@@ -5,7 +5,7 @@
package path;
import os;
import rt;
def SEP: u8 = 47u8; // '/'
@@ -95,7 +95,7 @@ export fn extension(p: str) str = {
// two-arg join (no variadic).
export fn join(a: str, b: str) str = {
if (abs(b)) {
let buf: *u8 = os.alloc(b.len: u64): *u8;
let buf: *u8 = rt.alloc(b.len: u64): *u8;
let i: i32 = 0;
for (i < b.len) { buf[i] = b[i]; i += 1; };
let r: str;
@@ -104,7 +104,7 @@ export fn join(a: str, b: str) str = {
return r;
};
if (a.len == 0) {
let buf: *u8 = os.alloc(b.len: u64): *u8;
let buf: *u8 = rt.alloc(b.len: u64): *u8;
let i: i32 = 0;
for (i < b.len) { buf[i] = b[i]; i += 1; };
let r: str;
@@ -113,7 +113,7 @@ export fn join(a: str, b: str) str = {
return r;
};
if (b.len == 0) {
let buf: *u8 = os.alloc(a.len: u64): *u8;
let buf: *u8 = rt.alloc(a.len: u64): *u8;
let i: i32 = 0;
for (i < a.len) { buf[i] = a[i]; i += 1; };
let r: str;
@@ -129,7 +129,7 @@ export fn join(a: str, b: str) str = {
an -= 1;
};
let total: i32 = an + 1 + b.len;
let buf: *u8 = os.alloc(total: u64): *u8;
let buf: *u8 = rt.alloc(total: u64): *u8;
let i: i32 = 0;
for (i < an) { buf[i] = a[i]; i += 1; };
buf[an] = SEP;