`null` is now a real pointer literal and null-tests are comparisons, instead of `ptr_null()` and `ptr_is_null(x)`: ptr_null() -> null ptr_is_null(x) -> (x == null) not ptr_is_null(x) -> (x != null) Mechanics: a new E_NULL primary (`null`, like true/false) lowers to the `null` pointer; emit_bin's comparison path now picks `ptr` vs `i32` from operand type (via llty), so `==`/`!=` work on any pointer/record/slice. The two intrinsics are deleted. Two reseeds: (A) add the literal + ptr comparison keeping the intrinsics; (B) migrate all 182 call sites (compiler + runtime, via a balanced-paren script that skips string-literal args and rewrites `not ptr_is_null` to `!= null`) and delete the intrinsics. Node/Val/Buf/Tok field defaults now read `ptr = null`. Vocabulary drops the two from LUDIC_INTRINSICS; `null` joins true/false as a language constant (grammar + ludic_syntax.h). LANGUAGE.md notes the literal. Reseeded (21664 lines); C-free fixpoint holds; goldens identical; 17/17; vocab + doc-fences clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
924 B
Text
29 lines
924 B
Text
# buf.ludic — a growable byte buffer for building IR text. The emitter writes
|
|
# module-level material (types, globals, string constants) into one buffer and
|
|
# function bodies into another, then prints them in order.
|
|
|
|
property Buf { data: ptr = null, len: int = 0, cap: int = 0 }
|
|
|
|
fn buf_new() -> Buf {
|
|
let b = new Buf
|
|
b.cap = 256
|
|
b.data = mem_alloc(b.cap)
|
|
b.len = 0
|
|
return b
|
|
}
|
|
fn buf_ensure(b: Buf, extra: int) -> void {
|
|
if b.len + extra + 1 <= b.cap { return }
|
|
while b.len + extra + 1 > b.cap { b.cap = b.cap * 2 }
|
|
b.data = mem_realloc(b.data, b.cap)
|
|
}
|
|
fn buf_putc(b: Buf, c: int) -> void {
|
|
buf_ensure(b, 1)
|
|
poke8(b.data, b.len, c)
|
|
b.len = b.len + 1
|
|
}
|
|
fn buf_puts(b: Buf, s: ptr) -> void {
|
|
var i = 0
|
|
while peek8(s, i) != 0 { buf_putc(b, peek8(s, i)); i = i + 1 }
|
|
}
|
|
fn buf_puti(b: Buf, n: int) -> void { buf_puts(b, itoa(n)) }
|
|
fn buf_str(b: Buf) -> ptr { poke8(b.data, b.len, 0); return b.data }
|