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>
38 lines
1.5 KiB
Text
38 lines
1.5 KiB
Text
# emit_addr.ludic — addresses of lvalues (struct fields and slice elements),
|
|
# shared by expression loads and assignment stores. Each returns the address
|
|
# register; the element/field type is written into g_addr_ty.
|
|
|
|
var g_addr_ty: ptr # out-param: the type at the computed address
|
|
|
|
# address of `base.field`
|
|
fn emit_member_addr(e: Node) -> ptr {
|
|
let base = emit_expr(e.a)
|
|
let s = layout_node(base.ty)
|
|
if ptr_is_null(s) { perr(sconcat("member access on non-aggregate ", base.ty)) }
|
|
let fidx = field_index(s, e.s)
|
|
if fidx < 0 { perr(sconcat("no such field ", e.s)) }
|
|
g_addr_ty = field_type(s, e.s)
|
|
let r = nreg()
|
|
emit(" "); emit(r); emit(" = getelementptr inbounds "); emit(layout_ty(base.ty))
|
|
emit(", ptr "); emit(base.code); emit(", i32 0, i32 "); emit(itoa(fidx)); emit("\n")
|
|
return r
|
|
}
|
|
|
|
# address of `base[index]` (slices only in this subset)
|
|
fn emit_index_addr(e: Node) -> ptr {
|
|
let base = emit_expr(e.a)
|
|
if not is_slice_ty(base.ty) { perr("indexing a non-slice") }
|
|
let el = slice_elem(base.ty)
|
|
g_addr_ty = el
|
|
# load the data pointer from the slice header (field 0)
|
|
let dp = nreg()
|
|
emit(" "); emit(dp); emit(" = getelementptr inbounds %LSlice, ptr ")
|
|
emit(base.code); emit(", i32 0, i32 0\n")
|
|
let data = nreg()
|
|
emit(" "); emit(data); emit(" = load ptr, ptr "); emit(dp); emit("\n")
|
|
let ix = emit_expr(e.b)
|
|
let r = nreg()
|
|
emit(" "); emit(r); emit(" = getelementptr inbounds "); emit(llty(el))
|
|
emit(", ptr "); emit(data); emit(", i32 "); emit(ix.code); emit("\n")
|
|
return r
|
|
}
|