wip(0.S3): calls into the runtime get its states supplied; the emitter's own calls to runtime functions reach their thunks; the migration names the runtime's states per file
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a476ec7976
commit
d70b00f30d
15 changed files with 54328 additions and 53309 deletions
|
|
@ -958,6 +958,7 @@ function emit_call(e: Node) -> Val {
|
|||
}
|
||||
vis_check(fn2, name)
|
||||
state_inject_generated(e, fn2) # 0.S: a call the compiler wrote gets its states
|
||||
state_inject_runtime(e, fn2) # and a call into the runtime
|
||||
call_fill_defaults(e, fn2) # L11 - for code the checker does not walk
|
||||
reorder_named(e, param_labels(fn2))
|
||||
# evaluate args first (their IR is emitted before the call instruction), coercing
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ function emit_main(d: Node) -> void {
|
|||
# game that renders (drives tick_render, draws, uses the engine light pass) has
|
||||
# its framebuffer allocated. Headless it only allocates — no window, no output —
|
||||
# so a non-rendering entry game is unchanged.
|
||||
if (find_fn("rt_init") != null) { emit(" call void @fn_rt_init()\n") }
|
||||
if (find_fn("rt_init") != null) { emit(" call void " + fn_sym("rt_init") + "()\n") }
|
||||
emit(" call void @L_init_globals()\n")
|
||||
emit_block(d.a)
|
||||
if not g_term { emit(" br label %ret\n") }
|
||||
|
|
|
|||
|
|
@ -75,12 +75,12 @@ function emit_engine_systems_for_phase(phase: pointer) -> void {
|
|||
if (phase == "Update") {
|
||||
# Tween.* fluent handles (#48): advanced each Update tick when the game uses
|
||||
# them (gated on g_uses_tween_rt rather than a declared component).
|
||||
if g_uses_tween_rt and (find_fn("esys_tween") != null) { emit(" call void @fn_esys_tween()\n") }
|
||||
if g_uses_tween_rt and (find_fn("esys_tween") != null) { emit(" call void " + fn_sym("esys_tween") + "()\n") }
|
||||
if has_countdowns() { emit(" call void @L_countdowns()\n") } # `countdown` fields tick toward 0
|
||||
if g_uses_fx and (find_fn("fx_tick") != null) { emit(" call void @fn_fx_tick()\n") } # Fx.* age and move
|
||||
if g_uses_fx and (find_fn("fx_tick") != null) { emit(" call void " + fn_sym("fx_tick") + "()\n") } # Fx.* age and move
|
||||
}
|
||||
if (phase == "Render") {
|
||||
if g_uses_fx and (find_fn("fx_draw") != null) { emit(" call void @fn_fx_draw()\n") } # Fx.* draw after the sprites
|
||||
if g_uses_fx and (find_fn("fx_draw") != null) { emit(" call void " + fn_sym("fx_draw") + "()\n") } # Fx.* draw after the sprites
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -361,7 +361,7 @@ function emit_scene_menu_render() -> void {
|
|||
let ce = emit_bind(`icmp eq i32 {cs}, {itoa(sc.ival)}`)
|
||||
let run = lbl("mrun"); let skip = lbl("mskip")
|
||||
emit(" br i1 "); emit(ce); emit(", label %"); emit(run); emit(", label %"); emit(skip); emit("\n")
|
||||
emit(run); emit(":\n call void @fn_rt_ui_render()\n")
|
||||
emit(run); emit(":\n call void " + fn_sym("rt_ui_render") + "()\n")
|
||||
emit(" br label %"); emit(skip); emit("\n"); emit(skip); emit(":\n")
|
||||
}
|
||||
i += 1
|
||||
|
|
@ -380,10 +380,10 @@ function emit_scene_fn(name: pointer, kind: pointer, body: Node, menu: pointer)
|
|||
code = fbody
|
||||
# `scene X shows Menu`: a free cursor and the menu open on enter, closed on exit
|
||||
if (menu != null) and (kind == "enter") {
|
||||
if (find_fn("input_cursor_mode") != null) { emit(" call void @fn_input_cursor_mode(i32 0)\n") }
|
||||
emit(" call void @fn_rt_ui_open(i32 "); emit(itoa(ui_index_of("UI_" + menu))); emit(")\n")
|
||||
if (find_fn("input_cursor_mode") != null) { emit(" call void " + fn_sym("input_cursor_mode") + "(i32 0)\n") }
|
||||
emit(" call void " + fn_sym("rt_ui_open") + "(i32 "); emit(itoa(ui_index_of("UI_" + menu))); emit(")\n")
|
||||
}
|
||||
if (menu != null) and (kind == "exit") { emit(" call void @fn_rt_ui_close()\n") }
|
||||
if (menu != null) and (kind == "exit") { emit(" call void " + fn_sym("rt_ui_close") + "()\n") }
|
||||
if (body != null) { emit_block(body) }
|
||||
# EV1: a `public` scene fires scene_<S>_enter / scene_<S>_exit after its block
|
||||
let sev = `scene_{name}_{kind}`
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ function emit_machine(st: Node) -> void {
|
|||
if (addr != null) { s = emit_bind(`load i32, ptr {addr}`) }
|
||||
else {
|
||||
let regv = emit_expr(st.a)
|
||||
s = emit_bind(`call i32 @fn_rt_reg(i32 {regv.code})`)
|
||||
s = emit_bind(`call i32 {fn_sym("rt_reg")}(i32 {regv.code})`)
|
||||
}
|
||||
if nmach < len(mach_stk) { mach_stk[nmach] = st } else { push(mach_stk, st) }
|
||||
nmach += 1
|
||||
|
|
@ -96,7 +96,7 @@ function emit_become(st: Node) -> void {
|
|||
emit(` store i32 {sv}, ptr {addr}\n`)
|
||||
} else {
|
||||
let regv = emit_expr(m.a)
|
||||
emit(" call void @fn_rt_set_reg(i32 "); emit(regv.code); emit(", i32 "); emit(sv); emit(")\n")
|
||||
emit(" call void " + fn_sym("rt_set_reg") + "(i32 "); emit(regv.code); emit(", i32 "); emit(sv); emit(")\n")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ function emit_snapshot() -> void {
|
|||
emit(" %bad = icmp eq ptr %f, null\n")
|
||||
emit(" br i1 %bad, label %out, label %go\ngo:\n")
|
||||
emit_snapshot_blocks("fwrite")
|
||||
if has_save { emit(" call void @fn_rt_save_state(ptr %f)\n") }
|
||||
if has_save { emit(" call void " + fn_sym("rt_save_state") + "(ptr %f)\n") }
|
||||
emit(" %c = call i32 @fclose(ptr %f)\n br label %out\nout:\n ret void\n}\n\n")
|
||||
|
||||
emit("define i32 @L_load() {\nentry:\n")
|
||||
|
|
@ -94,7 +94,7 @@ function emit_snapshot() -> void {
|
|||
emit(" %bad = icmp eq ptr %f, null\n")
|
||||
emit(" br i1 %bad, label %miss, label %go\nmiss:\n ret i32 0\ngo:\n")
|
||||
emit_snapshot_blocks("fread")
|
||||
if has_load { emit(" call void @fn_rt_load_state(ptr %f)\n") }
|
||||
if has_load { emit(" call void " + fn_sym("rt_load_state") + "(ptr %f)\n") }
|
||||
emit(" %c = call i32 @fclose(ptr %f)\n ret i32 1\n}\n\n")
|
||||
|
||||
# world_save(buf) -> int / world_load(buf, len): the same whole-world snapshot,
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ function is_ui_ident(nm: pointer) -> bool {
|
|||
}
|
||||
|
||||
function ll_ui_set(idx: int, key: int, val: pointer) -> void {
|
||||
emit(" call void @fn_rt_ui_set(i32 "); emit(itoa(idx)); emit(", i32 "); emit(itoa(key)); emit(", i32 "); emit(val); emit(")\n")
|
||||
emit(" call void " + fn_sym("rt_ui_set") + "(i32 "); emit(itoa(idx)); emit(", i32 "); emit(itoa(key)); emit(", i32 "); emit(val); emit(")\n")
|
||||
}
|
||||
function ui_prop_key(k: pointer) -> int {
|
||||
if (k == "w") { return 2 }; if (k == "h") { return 3 }; if (k == "x") { return 4 }; if (k == "y") { return 5 }
|
||||
|
|
@ -102,7 +102,7 @@ function emit_ui_build() -> void {
|
|||
falloc = buf_new()
|
||||
let saved = code
|
||||
code = fbody
|
||||
emit(" call void @fn_rt_ui_reset(i32 "); emit(itoa(len(uiw))); emit(")\n")
|
||||
emit(" call void " + fn_sym("rt_ui_reset") + "(i32 "); emit(itoa(len(uiw))); emit(")\n")
|
||||
var i = 0
|
||||
while i < len(uiw) {
|
||||
let w = uiw[i]
|
||||
|
|
@ -119,10 +119,10 @@ function emit_ui_build() -> void {
|
|||
if (k == "id") or (k == "goto") { p += 1; continue }
|
||||
if (k == "text") {
|
||||
let sv = emit_expr(v)
|
||||
emit(" call void @fn_rt_ui_static_text(i32 "); emit(itoa(i)); emit(", ptr "); emit(sv.code); emit(")\n")
|
||||
emit(" call void " + fn_sym("rt_ui_static_text") + "(i32 "); emit(itoa(i)); emit(", ptr "); emit(sv.code); emit(")\n")
|
||||
} else { if (k == "skin") or (k == "image") {
|
||||
let sv = emit_expr(v)
|
||||
let r = emit_bind(`call i32 @fn_rt_image_load(ptr {sv.code})`)
|
||||
let r = emit_bind(`call i32 {fn_sym("rt_image_load")}(ptr {sv.code})`)
|
||||
if (k == "skin") { ll_ui_set(i, 20, r) } else { ll_ui_set(i, 19, r) }
|
||||
} else { if (k == "align") {
|
||||
if v.kind == E_ID {
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ function emit_game_main() -> void {
|
|||
emit("define i32 @main(i32 %argc, ptr %argv) {\nentry:\n")
|
||||
emit(" store i32 %argc, ptr @L_argc\n")
|
||||
emit(" store ptr %argv, ptr @L_argv\n")
|
||||
if (find_fn("rt_init") != null) { emit(" call void @fn_rt_init()\n") }
|
||||
if (find_fn("rt_init") != null) { emit(" call void " + fn_sym("rt_init") + "()\n") }
|
||||
emit(" call void @L_init_globals()\n")
|
||||
emit_calls_for_phase("Start")
|
||||
# enter the start scene once, after boot: store its id and run its on-enter.
|
||||
|
|
@ -463,7 +463,7 @@ function emit_game_main() -> void {
|
|||
let r = emit_bind("load i32, ptr @L_running")
|
||||
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 pr = emit_bind("call i32 " + fn_sym("rt_running") + "()")
|
||||
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")
|
||||
|
|
@ -478,11 +478,11 @@ function emit_game_main() -> void {
|
|||
# and the game no longer has to call Input.poll by hand. A game that uses no Input
|
||||
# runtime keeps the plain rt_poll path, byte-identical.
|
||||
if g_uses_input and (find_fn("input_drive") != null) {
|
||||
let k = emit_bind("call i32 @fn_input_drive()")
|
||||
let k = emit_bind("call i32 " + fn_sym("input_drive") + "()")
|
||||
emit(" store i32 "); emit(k); emit(", ptr @L_key\n")
|
||||
} else {
|
||||
if (find_fn("rt_poll") != null) {
|
||||
let k = emit_bind("call i32 @fn_rt_poll()")
|
||||
let k = emit_bind("call i32 " + fn_sym("rt_poll") + "()")
|
||||
emit(" store i32 "); emit(k); emit(", ptr @L_key\n")
|
||||
}
|
||||
}
|
||||
|
|
@ -490,7 +490,7 @@ function emit_game_main() -> void {
|
|||
# UiClicked on activation — so a scene never polls ui_tick by hand.
|
||||
if has_ui() and (find_fn("rt_ui_tick") != null) {
|
||||
let uk = emit_bind("load i32, ptr @L_key")
|
||||
emit(" call void @fn_rt_ui_tick(i32 "); emit(uk); emit(")\n")
|
||||
emit(" call void " + fn_sym("rt_ui_tick") + "(i32 "); emit(uk); emit(")\n")
|
||||
}
|
||||
emit_calls_for_phase("Input")
|
||||
emit_calls_for_phase("FixedUpdate")
|
||||
|
|
@ -503,14 +503,14 @@ function emit_game_main() -> void {
|
|||
# system owns the present).
|
||||
if g_has_clear_color and (find_fn("rt_clear") != null) {
|
||||
let colour = emit_expr(g_clear_color) # a literal, a const, or a Color.Name
|
||||
emit(" call void @fn_rt_clear(i32 "); emit(colour.code); emit(")\n")
|
||||
emit(" call void " + fn_sym("rt_clear") + "(i32 "); emit(colour.code); emit(")\n")
|
||||
}
|
||||
emit_calls_for_phase("Render")
|
||||
# Overlay: HUD / menus drawn after every engine Render system (sprites, lights), so
|
||||
# game UI is never painted under an actor. Presented together with the frame.
|
||||
emit_calls_for_phase("Overlay")
|
||||
if g_has_clear_color and (find_fn("rt_present") != null) {
|
||||
emit(" call void @fn_rt_present()\n")
|
||||
emit(" call void " + fn_sym("rt_present") + "()\n")
|
||||
}
|
||||
let fcur = emit_bind("load i32, ptr @L_frame") # Time.frame(): count completed frames
|
||||
let fnext = emit_bind(`add i32 {fcur}, 1`)
|
||||
|
|
@ -520,6 +520,6 @@ function emit_game_main() -> void {
|
|||
if len(g_ondespawn) > 0 { emit(" call void @L_despawn_all(i32 2)\n") } # LC1: every survivor's @OnDespawn fires with reason Quit
|
||||
emit_calls_for_phase("OnQuit") # @OnQuit shutdown hooks run once, before teardown
|
||||
if (find_event("program_quit") != null) { emit(" call void @ev_program_quit()\n") } # EV1: @Public @OnQuit
|
||||
if (find_fn("rt_shutdown") != null) { emit(" call void @fn_rt_shutdown()\n") }
|
||||
if (find_fn("rt_shutdown") != null) { emit(" call void " + fn_sym("rt_shutdown") + "()\n") }
|
||||
emit(" ret i32 0\n}\n")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ function emit_tween_ns(meth: pointer, e: Node) -> Val {
|
|||
# a call into tween.ludic; the 2-arg Tween.done(timer, dur) is the pure form.
|
||||
if (len(e.kids) == 1) {
|
||||
let h = emit_expr(e.kids[0])
|
||||
return val(emit_bind(`call i32 @fn_tween_done(i32 {h.code})`), "bool")
|
||||
return val(emit_bind(`call i32 {fn_sym("tween_done")}(i32 {h.code})`), "bool")
|
||||
}
|
||||
let timer = emit_expr(e.kids[0]); let dur = emit_expr(e.kids[1]) # timer >= duration -> bool
|
||||
let c = emit_bind(`icmp sge i32 {timer.code}, {dur.code}`)
|
||||
|
|
|
|||
|
|
@ -56,17 +56,17 @@ function emit_ivec_ns(meth: pointer, e: Node) -> Val {
|
|||
if (meth == "heading") { # degrees from a to b (0 = +x, 90 = +y)
|
||||
if find_fn("rt_ivec_heading") == null { perr("IVec2.heading needs the engine runtime") }
|
||||
let a = emit_expr(e.kids[0]); let b = emit_expr(e.kids[1])
|
||||
return val(emit_bind(`call i32 @fn_rt_ivec_heading(i64 {a.code}, i64 {b.code})`), "int")
|
||||
return val(emit_bind(`call i32 {fn_sym("rt_ivec_heading")}(i64 {a.code}, i64 {b.code})`), "int")
|
||||
}
|
||||
if (meth == "along") { # the point `distance` along `degrees` from origin
|
||||
if find_fn("rt_ivec_along") == null { perr("IVec2.along needs the engine runtime") }
|
||||
let o = emit_expr(e.kids[0]); let d = emit_expr(e.kids[1]); let n = emit_expr(e.kids[2])
|
||||
return val(emit_bind(`call i64 @fn_rt_ivec_along(i64 {o.code}, i32 {d.code}, i32 {n.code})`), "IVec2")
|
||||
return val(emit_bind(`call i64 {fn_sym("rt_ivec_along")}(i64 {o.code}, i32 {d.code}, i32 {n.code})`), "IVec2")
|
||||
}
|
||||
if (meth == "step") { # a -1/0/1 unit step along `degrees`
|
||||
if find_fn("rt_ivec_step") == null { perr("IVec2.step needs the engine runtime") }
|
||||
let d = emit_expr(e.kids[0])
|
||||
return val(emit_bind(`call i64 @fn_rt_ivec_step(i32 {d.code})`), "IVec2")
|
||||
return val(emit_bind(`call i64 {fn_sym("rt_ivec_step")}(i32 {d.code})`), "IVec2")
|
||||
}
|
||||
if (meth == "add") { # component-wise a + b
|
||||
let a = emit_expr(e.kids[0]); let b = emit_expr(e.kids[1])
|
||||
|
|
|
|||
|
|
@ -70,11 +70,11 @@ function emit_takeright(elt: pointer, mode: int, fnsym: pointer, keyll: pointer,
|
|||
return emit_bind(`icmp slt {elt} {bv}, {av}`) # right strictly less than left
|
||||
}
|
||||
if (mode == SORT_WITH) {
|
||||
let c = emit_bind(`call i32 @fn_{fnsym}({elt} {av}, {elt} {bv})`)
|
||||
let c = emit_bind(`call i32 {fn_sym(fnsym)}({elt} {av}, {elt} {bv})`)
|
||||
return emit_bind(`icmp sgt i32 {c}, 0`) # cmp(left, right) > 0 -> left comes after
|
||||
}
|
||||
let kl = emit_bind(`call {keyll} @fn_{fnsym}({elt} {av})`)
|
||||
let kr = emit_bind(`call {keyll} @fn_{fnsym}({elt} {bv})`)
|
||||
let kl = emit_bind(`call {keyll} {fn_sym(fnsym)}({elt} {av})`)
|
||||
let kr = emit_bind(`call {keyll} {fn_sym(fnsym)}({elt} {bv})`)
|
||||
if (mode == SORT_KEY_DESC) {
|
||||
return emit_bind(`icmp slt {keyll} {kl}, {kr}`) # desc: right first when its key is larger
|
||||
}
|
||||
|
|
@ -232,7 +232,7 @@ function emit_list_ns(meth: pointer, e: Node) -> Val {
|
|||
let pool = emit_expr(e.kids[0])
|
||||
let cnt = emit_expr(e.kids[1])
|
||||
if find_fn("rt_list_sample") == null { perr("List.sample needs the engine runtime (a game, or import ludic.core)") }
|
||||
return val(emit_bind(`call ptr @fn_rt_list_sample(ptr {pool.code}, i32 {cnt.code})`), "[]int")
|
||||
return val(emit_bind(`call ptr {fn_sym("rt_list_sample")}(ptr {pool.code}, i32 {cnt.code})`), "[]int")
|
||||
}
|
||||
let s = emit_expr(e.kids[0])
|
||||
if not is_slice_ty(s.ty) { perr(`List.{meth} needs a slice`) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue