Phase 7c: string operators + and ==/!= (retire streq/sconcat)
Strings are values now: `a + b` concatenates and `a == b` / `a != b` compare by
content, replacing the 605 `sconcat(...)` / `streq(...)` calls that made the
compiler read like C.
streq(name, "let") -> name == "let"
sconcat("load ", reg) -> "load " + reg
sconcat(a, sconcat(b, c)) -> a + b + c
Implementation: emit_bin gains a string path. Strings are pointer-typed, so any
`+` with a pointer operand concatenates and `==`/`!=` between pointers compares
content — except when one side is the `null` literal, which stays a pointer
identity test (the only two kinds of pointer `==` in the codebase). Both call a
small hand-written IR prelude, @fn_str_eq / @fn_str_concat, emitted once into any
program that uses string ops (so it works for tools, games and the compiler with
no runtime-splice dependency and no duplicate symbols).
Delivered as two reseeds: (A) add the operators + prelude with the full
pointer-aware dispatch, keeping streq/sconcat; (B) migrate every call site
(354 lines, via a string-literal-safe balanced-paren script that leaves the
function definitions alone) and delete streq/sconcat. examples/strings.ludic +
a test.sh smoke (prints 1 2 3 4 5) guard it.
Reseeded (21890 lines); C-free fixpoint holds; goldens byte-identical; 18/18;
vocab + doc-fences clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
56024f2cba
commit
a021362cdb
25 changed files with 3553 additions and 3248 deletions
|
|
@ -24,9 +24,9 @@ fn emit_calls_for_phase(phase: ptr) -> void {
|
|||
var i = 0
|
||||
while i < len(prog) {
|
||||
let d = prog[i]
|
||||
if d.kind == N_SYS and streq(d.ty, phase) { # skip a disabled handler
|
||||
let he = emit_bind(sconcat("load i32, ptr @HE_", d.s))
|
||||
let hc = emit_bind(sconcat("icmp ne i32 ", sconcat(he, ", 0")))
|
||||
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 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(sconcat("icmp ne i32 ", sconcat(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(sconcat("icmp ne i32 ", sconcat(pr, ", 0")))
|
||||
let go = emit_bind(sconcat("and i1 ", sconcat(rc, sconcat(", ", 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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue