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:
@@ -152,8 +152,9 @@ static const struct row rows[] = {
|
||||
/* alloc + free via mmap-backed runtime — write through allocated
|
||||
* memory and free it. exit = 0 if the allocation succeeded. */
|
||||
{ "import os;\n"
|
||||
"import rt;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *void = os.alloc(4096u64);\n"
|
||||
" let p: *void = rt.alloc(4096u64);\n"
|
||||
" if (p == nil) { return 1; };\n"
|
||||
" let bp: *u8 = p: *u8;\n"
|
||||
" bp[0] = 65u8;\n"
|
||||
@@ -280,7 +281,7 @@ static const struct row rows[] = {
|
||||
* builtin via the inherited os.alloc decl. Task #30 graduated
|
||||
* the builtin to `(*T | nomem)`; the `!` aborts on OOM. */
|
||||
{ "package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"type point = struct { x: i32, y: i32 };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *point = alloc(point { x = 3, y = 4 })!;\n"
|
||||
@@ -301,7 +302,7 @@ static const struct row rows[] = {
|
||||
* Task #30 graduated the slice form to `([]T | nomem)`; the `!`
|
||||
* aborts on OOM. */
|
||||
{ "package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let s: []u8 = alloc([], 16)!;\n"
|
||||
" append(s, 72u8, 105u8);\n"
|
||||
@@ -311,14 +312,14 @@ static const struct row rows[] = {
|
||||
* `[]rune` is 4B-per-element; the cgen shortcut scales count by
|
||||
* size(T). Returns s.cap = 8. */
|
||||
{ "package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let s: []rune = alloc([], 8)!;\n"
|
||||
" return s.cap;\n"
|
||||
"};", 8 },
|
||||
/* #45: same as above for `[]str` (16B-per-element). */
|
||||
{ "package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let s: []str = alloc([], 4)!;\n"
|
||||
" return s.cap;\n"
|
||||
@@ -327,7 +328,7 @@ static const struct row rows[] = {
|
||||
* return; the alloc-slice shortcut emits MOVQ $nomem_tag, AX +
|
||||
* propret on null. doit returns 12 on success; main unwraps. */
|
||||
{ "package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"fn doit() (i32 | nomem) = {\n"
|
||||
" let s: []str = alloc([], 12)?;\n"
|
||||
" return s.cap: i32;\n"
|
||||
@@ -393,6 +394,7 @@ static const struct row rows[] = {
|
||||
* builtin to a fallible signature; the `!` aborts on OOM. */
|
||||
{ "package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"type point = struct { x: i64, y: i64 };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *point = alloc(point { x = 7, y = 35 })!;\n"
|
||||
|
||||
Reference in New Issue
Block a user