The parser now requires a newline or ';' between statements (block() in selfhost/parse.ludic); two statements may no longer sit adjacent with only spaces. Also fixed if-without-else swallowing its trailing separator. Migration: tools/ludic-tools/migrate_separators.c inserts ';' at statement boundaries corpus-wide (examples, runtime, 25 self-host fragments, ~1100 boundaries). Verified semantically identical — the migrated compiler compiles itself to IR byte-identical to the pre-migration seed, and every golden game renders identically. Reseeded to the strict compiler; C-free fixpoint holds; test.sh 14/14. Docs: Rule B documented in LANGUAGE.md; BOOTSTRAP.md R1 + stale fences updated; check-docs green across all docs. Fixed a multi-line string literal in emit_expr.ludic (byte-identical \n escape) that the C toolchain lexer mis-lexes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
928 B
Text
29 lines
928 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.
|
|
|
|
struct Buf { data: ptr = 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 {
|
|
let 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 }
|