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:
parent
4faf91abdc
commit
df6955e609
20 changed files with 566 additions and 566 deletions
|
|
@ -22,13 +22,13 @@ fn emit_intrinsic2(name: ptr, e: Node) -> Val {
|
|||
}
|
||||
if (name == "mem_copy") {
|
||||
let d = arg_code(e, 0); let s = arg_code(e, 1); let n = arg_code(e, 2)
|
||||
let w = emit_bind(("zext i32 " + (n + " to i64")))
|
||||
let w = emit_bind(`zext i32 {n} to i64`)
|
||||
emit(" call ptr @memcpy(ptr "); emit(d); emit(", ptr "); emit(s); emit(", i64 "); emit(w); emit(")\n")
|
||||
return val("0", "void")
|
||||
}
|
||||
if (name == "mem_set") {
|
||||
let p = arg_code(e, 0); let v = arg_code(e, 1); let n = arg_code(e, 2)
|
||||
let w = emit_bind(("zext i32 " + (n + " to i64")))
|
||||
let w = emit_bind(`zext i32 {n} to i64`)
|
||||
emit(" call ptr @memset(ptr "); emit(p); emit(", i32 "); emit(v); emit(", i64 "); emit(w); emit(")\n")
|
||||
return val("0", "void")
|
||||
}
|
||||
|
|
@ -44,17 +44,17 @@ fn emit_intrinsic2(name: ptr, e: Node) -> Val {
|
|||
}
|
||||
if (name == "str_len") {
|
||||
let s = arg_code(e, 0)
|
||||
let r = emit_bind(("call i64 @strlen(ptr " + (s + ")")))
|
||||
return val(emit_bind(("trunc i64 " + (r + " to i32"))), "int")
|
||||
let r = emit_bind(`call i64 @strlen(ptr {s})`)
|
||||
return val(emit_bind(`trunc i64 {r} to i32`), "int")
|
||||
}
|
||||
if (name == "os_time") {
|
||||
let r = emit_bind("call i64 @time(ptr null)")
|
||||
return val(emit_bind(("trunc i64 " + (r + " to i32"))), "int")
|
||||
return val(emit_bind(`trunc i64 {r} to i32`), "int")
|
||||
}
|
||||
if (name == "peekf") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1)
|
||||
let g = nreg(); emit(" "); emit(g); emit(" = getelementptr inbounds i32, ptr "); emit(p); emit(", i32 "); emit(i); emit("\n")
|
||||
return val(emit_bind(("load i32, ptr " + g)), "fixed")
|
||||
return val(emit_bind(`load i32, ptr {g}`), "fixed")
|
||||
}
|
||||
if (name == "pokef") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1); let v = arg_code(e, 2)
|
||||
|
|
@ -65,7 +65,7 @@ fn emit_intrinsic2(name: ptr, e: Node) -> Val {
|
|||
if (name == "peekp") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1)
|
||||
let g = nreg(); emit(" "); emit(g); emit(" = getelementptr inbounds ptr, ptr "); emit(p); emit(", i32 "); emit(i); emit("\n")
|
||||
return val(emit_bind(("load ptr, ptr " + g)), "ptr")
|
||||
return val(emit_bind(`load ptr, ptr {g}`), "ptr")
|
||||
}
|
||||
if (name == "pokep") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1); let v = arg_code(e, 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue