feat(lang): L6 namespaces declared in Ludic - alias

`alias meth(labels) = target` in a namespace block makes Ns.meth a call to
target with those labels (the target's own parameter names without a list). The
engine's 41 table-driven namespaces - 438 methods: Http, Udp, Process, Json,
Value, Screen, Input, Audio, World, Tiled, ... - leave emit_ns_call for
runtime/native/namespaces.ludic, spliced into every program; 532 lines of
compiler go and the seed shrinks by 23k lines of IR. The game's IR is byte
identical. The checker checks an alias call's arguments against its target.
Still built in: the inline namespaces (Math, Text, List, Vector, Color, Time,
Date, ...) and the methods that pick a target by argument type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-24 02:40:57 +03:00
parent 9662680bb0
commit 9259808f80
16 changed files with 49226 additions and 95736 deletions

View file

@ -0,0 +1,19 @@
# aliases.ludic — L6: a namespace method that is a name for a function. `alias` gives the method,
# the labels a call may use (in the target's parameter order) and the function it calls; without a
# label list the target's own parameter names are the labels. This is how the engine declares
# Http, Screen, Json and the rest (runtime/native/namespaces.ludic), and how a package owns an API.
#
# Running it prints: 10 5 3
program Aliases {
namespace Trail {
export alias length(from, to) = trail_distance
alias km = trail_km
alias stops() = trail_stops
}
function trail_distance(a: int, b: int) -> int { return b - a }
function trail_km(metres: int) -> int { return metres / 1000 }
function trail_stops() -> int { return 3 }
entry {
print(`{Trail.length(to: 12, from: 2)} {Trail.km(metres: 5000)} {Trail.stops()}`)
}
}

View file

@ -0,0 +1,8 @@
# L6: an alias is its target, so a call gives it the target's arguments
program AliasArity {
namespace Trail {
alias length(from, to) = trail_distance
}
function trail_distance(a: int, b: int) -> int { return b - a }
entry { print(Trail.length(4)) }
}

View file

@ -0,0 +1,9 @@
# L6: a namespace method is declared once
program AliasTwice {
namespace Trail {
alias length(from, to) = trail_distance
alias length(a, b) = trail_distance
}
function trail_distance(a: int, b: int) -> int { return b - a }
entry { print(Trail.length(1, 2)) }
}