feat(lang): L11 views and templates - the UI is markup, not code

A `view Name { field = x; function q(..); on e(..) }` declaration is the one bridge between a
program and its UI: it writes view_<name>() -> UiView, whose model is a Value of every field and
whose call runs a query or an event by name.

ludic.ui is a template runtime:
- HTML-shaped XML screens and components, loaded at run time;
- {expression} bindings, if/else/each, props, slots, per-instance state;
- on-press / onclick actions (event, set, emit);
- component libraries (export="true", <import src as>).

Styling:
- stylesheets in <style> or importable .lss files (@import);
- CSS selectors (#id, .class, [attr=v], descendant and > combinators, :hover, :disabled,
  :first-child, :last-child, :nth-child, :not) weighed by specificity;
- the box model and flex under CSS's property names.

Also:
- default parameters, and positional-then-named calls;
- Value gains a float kind;
- a function shadowing a runtime one is refused;
- an index is evaluated before the slice is read;
- runtime errors name the right file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-24 15:58:47 +03:00
parent 334469ef61
commit 66a2bc2214
64 changed files with 74806 additions and 63975 deletions

View file

@ -50,13 +50,16 @@ function emit_index_addr(e: Node) -> pointer {
return r
}
let el = slice_elem(base.ty)
# the index is evaluated BEFORE the elements' address is read: evaluating it may grow this
# very slice (xs[slot_of(k)] where slot_of pushes), and a push can move the elements
let ix = emit_expr(e.b)
# load the data pointer from the slice header (field 0)
let dp = nreg()
emit(" "); emit(dp); emit(" = getelementptr inbounds %LSlice, ptr ")
emit(base.code); emit(", i32 0, i32 0\n")
let data = nreg()
emit(" "); emit(data); emit(" = load ptr, ptr "); emit(dp); emit("\n")
let ix = emit_expr(e.b) # (evaluate index BEFORE setting
# (the index was evaluated first, above, and before g_addr_ty is set
# THE INDEX IS CHECKED AGAINST THE LENGTH. A slice has carried { ptr, len, cap } since it
# existed, and nothing ever read the len: every index was a bare getelementptr, so running
# off the end of one wrote into whatever the allocator had put next and the program died
@ -73,7 +76,7 @@ function emit_index_addr(e: Node) -> pointer {
let lbad = lbl("ixbad")
emit(` br i1 {okc}, label %{lok}, label %{lbad}\n`)
emit(`{lbad}:\n`)
let bmsg = emit_str_const(`{g_src_name}:{itoa(e.line)}: index out of range: `)
let bmsg = emit_str_const(`{src_name_of(e)}:{itoa(e.line)}: index out of range: `)
let bse = emit_bind(stdstream_rhs(2))
emit(` call i32 (ptr, ptr, ...) @fprintf(ptr {bse}, ptr @.fmt_bounds, ptr {bmsg}, i32 {ix.code}, i32 {lnv})\n`)
emit(" call void @exit(i32 1)\n unreachable\n")

View file

@ -523,7 +523,7 @@ function emit_call(e: Node) -> Val {
if (name == "self") { if nself == 0 { return val("0", "entity") }; return val(emit_bind(`load i32, ptr {self_stk[nself - 1]}`), "entity") }
if (name == "key") { return val(emit_bind("load i32, ptr @L_key"), "int") }
if (name == "save") { emit(" call void @L_save()\n"); return val("0", "void") }
if (name == "ui_build") { emit(" call void @ui_build()\n"); return val("0", "void") }
if (name == "ui_build") and (find_fn(name) == null) { emit(" call void @ui_build()\n"); return val("0", "void") }
if (name == "load") { return val(emit_bind("call i32 @L_load()"), "bool") }
if (name == "world_size") { return val(emit_bind("call i32 @L_world_size()"), "int") }
if (name == "world_save") { # world_save(buf) -> bytes written
@ -906,6 +906,7 @@ function emit_call(e: Node) -> Val {
cname = rtname
}
vis_check(fn2, name)
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
# each to the parameter's declared type so an int passed for a `long` widens.

View file

@ -70,6 +70,11 @@ function emit_sized_slice(el: pointer, n: Val) -> Val {
emit(` store i32 {n.code}, ptr {slice_field(h.code, 2)}\n`)
return h
}
# the file a runtime error names: the one the expression is written in, not the program's own
function src_name_of(e: Node) -> pointer {
if e == null or e.file == null { return g_src_name }
return e.file
}
function emit_view(e: Node) -> Val {
let xs = emit_expr(e.kids[0])
if not is_slice_ty(xs.ty) { perr(`view takes a slice, and this is {xs.ty}`) }
@ -88,7 +93,7 @@ function emit_view(e: Node) -> Val {
emit(` br i1 {ok}, label %{lok}, label %{lbad}\n`)
emit(`{lbad}:\n`)
g_uses_bounds = true
let bmsg = emit_str_const(`{g_src_name}:{itoa(e.line)}: view past the end: from `)
let bmsg = emit_str_const(`{src_name_of(e)}:{itoa(e.line)}: view past the end: from `)
let bse = emit_bind(stdstream_rhs(2))
emit(` call i32 (ptr, ptr, ...) @fprintf(ptr {bse}, ptr @.fmt_bounds, ptr {bmsg}, i32 {endv}, i32 {ln})\n`)
emit(" call void @exit(i32 1)\n unreachable\n")