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:
@@ -9,6 +9,7 @@
|
||||
package main;
|
||||
|
||||
import os;
|
||||
import rt;
|
||||
import mem;
|
||||
import sym;
|
||||
import obj;
|
||||
@@ -63,7 +64,7 @@ fn appenddec(dst: *u8, i: u64, n: u64) u64 = {
|
||||
dst[i] = 48u8;
|
||||
return i + 1u64;
|
||||
};
|
||||
let buf: *u8 = os.alloc(16u64): *u8;
|
||||
let buf: *u8 = rt.alloc(16u64): *u8;
|
||||
let k: u64 = 0u64;
|
||||
let v: u64 = n;
|
||||
for (v > 0u64) {
|
||||
@@ -102,7 +103,7 @@ fn buildpathv(dst: *u8, dir: *u8, name: *u8, v: u64) u64 = {
|
||||
fn islinkable(path: *u8) bool = {
|
||||
let fd: i32 = os.open(pathstr(path), os.flag.RDONLY, 0i32);
|
||||
if (fd < 0) { return false; };
|
||||
let mp: *u8 = os.alloc(8u64): *u8;
|
||||
let mp: *u8 = rt.alloc(8u64): *u8;
|
||||
let n: i64 = os.read(fd, mp, 8u64);
|
||||
os.close(fd);
|
||||
if (n < 4i64) { return false; };
|
||||
@@ -130,7 +131,7 @@ fn islinkable(path: *u8) bool = {
|
||||
// then lib<name>.a. Return arena-owned NUL-terminated path on success,
|
||||
// nil on miss.
|
||||
fn resolvelib(a: *arena, name: *u8, libdirs: **u8, nlibdirs: i32) *u8 = {
|
||||
let bufp: *u8 = os.alloc(1024u64): *u8;
|
||||
let bufp: *u8 = rt.alloc(1024u64): *u8;
|
||||
let i: i32 = 0;
|
||||
for (i < nlibdirs) {
|
||||
let dir: *u8 = libdirs[i];
|
||||
@@ -171,7 +172,7 @@ fn resolvelib(a: *arena, name: *u8, libdirs: **u8, nlibdirs: i32) *u8 = {
|
||||
fn isso(path: *u8) i32 = {
|
||||
let fd: i32 = os.open(pathstr(path), os.flag.RDONLY, 0i32);
|
||||
if (fd < 0) { return 0; };
|
||||
let mp: *u8 = os.alloc(20u64): *u8;
|
||||
let mp: *u8 = rt.alloc(20u64): *u8;
|
||||
let n: i64 = os.read(fd, mp, 20u64);
|
||||
os.close(fd);
|
||||
if (n < 20i64) { return 0; };
|
||||
@@ -188,11 +189,11 @@ fn isso(path: *u8) i32 = {
|
||||
export fn main(argc: i32, argv: **u8) i32 = {
|
||||
let outpath: *u8 = nil;
|
||||
let maxinputs: i32 = 64;
|
||||
let inputs: **u8 = os.alloc((maxinputs: u64) * 8u64): **u8;
|
||||
let inputs: **u8 = rt.alloc((maxinputs: u64) * 8u64): **u8;
|
||||
let ninputs: i32 = 0;
|
||||
let libdirs: **u8 = os.alloc((maxinputs: u64) * 8u64): **u8;
|
||||
let libdirs: **u8 = rt.alloc((maxinputs: u64) * 8u64): **u8;
|
||||
let nlibdirs: i32 = 0;
|
||||
let lflags: **u8 = os.alloc((maxinputs: u64) * 8u64): **u8;
|
||||
let lflags: **u8 = rt.alloc((maxinputs: u64) * 8u64): **u8;
|
||||
let nlflags: i32 = 0;
|
||||
|
||||
let i: i32 = 1;
|
||||
|
||||
Reference in New Issue
Block a user