Phase 7g: the compiler builds its IR with interpolation, not +

Answering your readability point directly: the compiler's own string-building —
left uglier by the 7c `+` migration, e.g. `emit_bind(("load i32, ptr " + ip))` —
now reads as interpolation:

  emit_bind(("load i32, ptr " + ip))            -> emit_bind(`load i32, ptr {ip}`)
  emit_bind(("icmp eq i32 " + (kv + (", " + itoa(ak)))))
                                                -> emit_bind(`icmp eq i32 {kv}, {itoa(ak)}`)
  perr(("assign to unknown " + t.s))            -> perr(`assign to unknown {t.s}`)

164 concat chains across selfhost converted by a tool that flattens the `+` tree,
keeps call/index parens (only grouping parens are rewritten), and converts only
**brace-free** literals — LLVM IR structure strings full of `{`/`}` stay as `+`
rather than becoming awkward `{{`/`}}`. No new language surface; interpolation
already desugars to the same concat.

Reseeded (22565 lines); C-free fixpoint holds byte-for-byte (the strongest proof
the reconstruction is exact); goldens identical; 18/18.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-08-28 01:30:37 +03:00
parent 4faf91abdc
commit df6955e609
20 changed files with 566 additions and 566 deletions

View file

@ -25,8 +25,8 @@ fn emit_calls_for_phase(phase: ptr) -> void {
while i < len(prog) {
let d = prog[i]
if d.kind == N_SYS and (d.ty == phase) { # skip a disabled handler
let he = emit_bind(("load i32, ptr @HE_" + d.s))
let hc = emit_bind(("icmp ne i32 " + (he + ", 0")))
let he = emit_bind(`load i32, ptr @HE_{d.s}`)
let hc = emit_bind(`icmp ne i32 {he}, 0`)
let run = lbl("hrun"); let skip = lbl("hskip")
emit(" br i1 "); emit(hc); emit(", label %"); emit(run); emit(", label %"); emit(skip); emit("\n")
emit(run); emit(":\n call void @sys_"); emit(d.s); emit("()\n")
@ -76,11 +76,11 @@ fn emit_game_main() -> void {
emit(" br label %loop\n")
emit("loop:\n")
let r = emit_bind("load i32, ptr @L_running")
let rc = emit_bind(("icmp ne i32 " + (r + ", 0")))
let rc = emit_bind(`icmp ne i32 {r}, 0`)
if (find_fn("rt_running") != null) {
let pr = emit_bind("call i32 @fn_rt_running()")
let pc = emit_bind(("icmp ne i32 " + (pr + ", 0")))
let go = emit_bind(("and i1 " + (rc + (", " + pc))))
let pc = emit_bind(`icmp ne i32 {pr}, 0`)
let go = emit_bind(`and i1 {rc}, {pc}`)
emit(" br i1 "); emit(go); emit(", label %body, label %done\n")
} else {
emit(" br i1 "); emit(rc); emit(", label %body, label %done\n")