Phase 7k: bytes(n) / words(n) allocators (retire mem_alloc)
Allocation reads as intent, not malloc: mem_alloc(64) -> bytes(64) (64 bytes -> a byte buffer) mem_alloc(w * h * 4) -> words(w * h) (w*h 32-bit words) bytes(n) mallocs n bytes and returns a plain pointer (byte-indexed); words(n) mallocs n*4 bytes and returns a `words` pointer (int-indexed). Since words(X) and mem_alloc(X*4) allocate the identical number of bytes, the migration cannot change any allocation size — the `* 4` factor just moves from the argument into the allocator name, pairing naturally with the Phase-7j `words` retyping (`var fb: words = words(w * h)`). Migrated 102 sites (mem_alloc(E*4) -> words(E), else bytes(E)); deleted the mem_alloc intrinsic. mem_realloc/free/copy/set stay as the low-level reallocation/free family. Reseeded (22565 lines); C-free fixpoint holds; goldens byte-identical; 18/18; vocab + doc-fences clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
5cab68ea2e
commit
86948d2b19
22 changed files with 3118 additions and 3069 deletions
|
|
@ -14,16 +14,16 @@ fn char_is_alnum(c: int) -> bool { return char_is_alpha(c) or char_is_digit(c) }
|
|||
|
||||
# integer -> fresh decimal string
|
||||
fn itoa(v: int) -> ptr {
|
||||
if v == 0 { let z = mem_alloc(2); z[0] = 48; z[1] = 0; return z }
|
||||
if v == 0 { let z = bytes(2); z[0] = 48; z[1] = 0; return z }
|
||||
var neg = false
|
||||
var x = v
|
||||
if x < 0 { neg = true; x = 0 - x }
|
||||
let tmp = mem_alloc(16)
|
||||
let tmp = bytes(16)
|
||||
var n = 0
|
||||
while x > 0 { tmp[n] = 48 + x % 10; x = x / 10; n = n + 1 }
|
||||
var total = n
|
||||
if neg { total = total + 1 }
|
||||
let out = mem_alloc(total + 1)
|
||||
let out = bytes(total + 1)
|
||||
var k = 0
|
||||
if neg { out[0] = 45; k = 1 }
|
||||
var i = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue