wip(0.S3): ui blocks, scene on enter/exit, hooks, machines over a state's field, namespace and engine-system injection; a reference out of a read-only state or a module let is read-only; deps counts writes into another module's state; the rejected examples hold states

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 14:49:03 +03:00
parent 4919c9c2fc
commit e7f8ee6b91
31 changed files with 100137 additions and 72476 deletions

View file

@ -1,6 +1,8 @@
# fn_type_mismatch.ludic - a function of one type where another is wanted is refused, by name
program FnTypeMismatch {
function half(x: float) -> float { return x / 2.0 }
var op: fn(int) -> int = null
entry { op = fn half }
state Ops {
op: fn(int) -> int = null
}
entry (ops: mut Ops) { ops.op = fn half }
}

View file

@ -3,8 +3,8 @@ import "private_bank"
import "private_kit"
program FriendScope {
friend module lab of kit
entry {
add(5)
print(total())
entry (bank_st: mut BankState) {
add(bank_st, 5)
print(total(bank_st))
}
}

View file

@ -1,8 +1,8 @@
# L3: a variable answers a member that takes nothing; price takes an int, so it binds a function
# L3: a state's field answers a member that takes nothing; price takes an int, so it binds a function
program PortVarArgs {
port Purse { price: fn(int) -> int }
var g_rate: int = 3
bind Purse { price: g_rate }
state Rates { rate: int = 3 }
bind Purse { price: Rates.rate }
entry {
print(Purse.price(2))
}

View file

@ -1,13 +1,15 @@
# bank/ledger.ludic - inherits `module bank` from the barrel that imports it
var balance: int = 0
export event Deposited { amount: int }
function add(n: int) -> void {
balance += n
export state BankState {
balance: int = 0
}
export function deposit(n: int) -> void {
add(n)
export event Deposited { amount: int }
function add(bank_st: mut BankState, n: int) -> void {
bank_st.balance += n
}
export function deposit(bank_st: mut BankState, n: int) -> void {
add(bank_st, n)
emit Deposited(amount: n)
}
export function total() -> int {
return balance
export function total(bank_st: BankState) -> int {
return bank_st.balance
}

View file

@ -1,8 +1,8 @@
# L3: `add` is private to module bank; calling it from outside the module is refused
import "private_bank"
program Private {
entry {
add(5)
print(total())
entry (bank_st: mut BankState) {
add(bank_st, 5)
print(total(bank_st))
}
}

View file

@ -4,5 +4,5 @@ module mech uses ludic_base
import "ludic.base"
import "ludic.inventory"
export function stock() -> int {
return inv_count(0)
return inv_limit(0)
}

View file

@ -1,9 +1,9 @@
# a view field that is not a bare global has to say its type
# a view field that is not a bare field of its state has to say its type
import "ludic.ui"
program ViewUntyped {
var a: int = 1
view Sums {
total = a + 2
state Nums { a: int = 1 }
view Sums (n: Nums) {
total = n.a + 2
}
entry { print(view_sums().name) }
entry { print(1) }
}

View file

@ -1,8 +1,8 @@
# a view is for templates, which ludic.ui shows
program ViewWithoutUi {
var a: int = 1
view Sums {
a = a
state Nums { a: int = 1 }
view Sums (n: Nums) {
a: int = n.a
}
entry { print(a) }
entry { print(1) }
}