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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user