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:
Orkun ÇAKILKAYA 2026-09-25 15:44:50 +03:00
parent a476ec7976
commit d70b00f30d
15 changed files with 54328 additions and 53309 deletions

View file

@ -81,6 +81,16 @@ var g_mg_entry: pointer = "" # the program's own file: its vars are t
# the state a var's file moves into: its module's, or - a file in no module - the program's for the
# program's own file, else one named for the file's directory (a test's shared fakes)
function mg_state_of_file(f: pointer) -> int {
if is_runtime_file(f) { # the runtime: a state per file (rt_input: RtInputState)
var b = f
var i = 0
while i < len(f) {
if f[i] == '/' { b = f[i + 1 .. len(f)] }
i += 1
}
if len(b) > 6 and (b[len(b) - 6 .. len(b)] == ".ludic") { b = b[0 .. len(b) - 6] }
return mg_state_of_mod(`@{f}`, `rt_{b}`)
}
let m = module_for_uses(f)
if not (m == "") { return mg_state_of_mod(m, mg_short(m)) }
if (f == g_mg_entry) { # the program's own: SceneDemo is SceneDemoState, scene_demo_st
@ -301,6 +311,7 @@ var g_mc_passed: []int = new []int # 1: the call already hands the callee a sta
function mg_call(e: Node, f: Node) -> void {
if not g_migrate or f == null or g_mg_cur < 0 { return }
if e.pos < 0 { return } # a generated call gets its states when compiled
if is_runtime_file(f.file) and not is_runtime_file(e.file) { return } # the runtime's are supplied
push(g_mc_call, e)
push(g_mc_unit, g_mg_cur)
push(g_mc_callee, mg_unit(f, 0))

View file

@ -18,6 +18,11 @@ var g_state_names: []pointer = new []pointer
var g_allow_globals: bool = false
var g_gen_nodes: bool = false # the finishing passes are writing code: its nodes are generated
# a runtime function called from outside the runtime: a built-in, whose states are the runtime's
function is_runtime_file(f: pointer) -> bool { return f != null and has_sub(f, "runtime/native/") }
function state_inject_runtime(e: Node, f: Node) -> void {
if e != null and f != null and is_runtime_file(f.file) and not is_runtime_file(e.file) { state_inject(e, f) }
}
# a call the compiler wrote itself (a view's model, a component's glue): its callee's states are
# supplied - the runtime's side of an entry point
function state_inject_generated(e: Node, f: Node) -> void {
@ -117,6 +122,12 @@ function state_inject(e: Node, f: Node) -> void {
i += 1
}
if k == 0 or len(e.kids) + k > total { return }
var named = false # `f(x: 1)`: the states go in by name too
i = 0
while i < len(e.kids) {
if e.kids[i].kind == E_FINIT { named = true }
i += 1
}
let args = new []Node
i = 0
while i < k {
@ -124,7 +135,12 @@ function state_inject(e: Node, f: Node) -> void {
id.s = state_global(f.kids[i].ty)
id.file = e.file
id.line = e.line
push(args, id)
if named {
let fi = node(E_FINIT)
fi.s = f.kids[i].s
fi.a = id
push(args, fi)
} else { push(args, id) }
i += 1
}
i = 0