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"
|
||||
|
||||
@@ -60,7 +60,7 @@ static const struct row rows[] = {
|
||||
/* Singleton str field. Pre-fix p.s.len stayed 0; post-fix 5. */
|
||||
{ "alloc_str_singleton",
|
||||
"package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"type holder = struct { s: str };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *holder = alloc(holder { s = \"hello\" })!;\n"
|
||||
@@ -72,7 +72,7 @@ static const struct row rows[] = {
|
||||
* unaffected. Pre-fix: 100 + 0 = 100; post-fix: 100 + 2 = 102. */
|
||||
{ "alloc_i32_then_str",
|
||||
"package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"type holder = struct { n: i32, s: str };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *holder = alloc(holder { n = 100, s = \"hi\" })!;\n"
|
||||
@@ -84,7 +84,7 @@ static const struct row rows[] = {
|
||||
* post-fix: 5 + 7 = 12. */
|
||||
{ "alloc_str_then_i32",
|
||||
"package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"type holder = struct { s: str, n: i32 };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *holder = alloc(holder { s = \"world\", n = 7 })!;\n"
|
||||
@@ -95,7 +95,7 @@ static const struct row rows[] = {
|
||||
* Pins that `fi = nil` advances correctly between str fields. */
|
||||
{ "alloc_two_str",
|
||||
"package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"type holder = struct { a: str, b: str };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *holder = alloc(holder { a = \"foo\", b = \"barbaz\" })!;\n"
|
||||
@@ -108,7 +108,7 @@ static const struct row rows[] = {
|
||||
* without disrupting either. */
|
||||
{ "alloc_f64_str_i32",
|
||||
"package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"type holder = struct { f: f64, s: str, n: i32 };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *holder = alloc(holder { f = 1.5f64, s = \"abc\", n = 10 })!;\n"
|
||||
@@ -121,7 +121,7 @@ static const struct row rows[] = {
|
||||
* Indexes the string by hand to avoid pulling in stdlib. */
|
||||
{ "alloc_str_readback",
|
||||
"package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"type holder = struct { s: str };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let p: *holder = alloc(holder { s = \"hi\" })!;\n"
|
||||
|
||||
@@ -202,7 +202,7 @@ main(void)
|
||||
/* #45: alloc-slice `!` form, []T element ≠ u8. */
|
||||
{ "alloc_slice_rune_unw",
|
||||
"package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let s: []rune = alloc([], 8)!;\n"
|
||||
" return s.cap;\n"
|
||||
@@ -211,7 +211,7 @@ main(void)
|
||||
* enclosing fn's tagged return. */
|
||||
{ "alloc_slice_str_prop",
|
||||
"package main;\n"
|
||||
"import os;\n"
|
||||
"import rt;\n"
|
||||
"fn doit() (i32 | nomem) = {\n"
|
||||
" let s: []str = alloc([], 4)?;\n"
|
||||
" return s.cap: i32;\n"
|
||||
|
||||
Reference in New Issue
Block a user