ludic/selfhost/backend/emit_vis.ludic
Orkuncakilkaya ab0b84b87e feat(lang): 27.3 - a reducer on a table's row: reducer T in S.table on A, @Target, Row<T>, @RowVerb, @Column
An action names one row of a ludic.base Table<T> by its handle, in a field marked @Target, and
`reducer Deer in Herd.deer on Spook(r: mut Row<Deer>, n: Noise, a: Spook)` runs once, for that row
alone (the table may sit down a path, S.w.tab). The drain resolves the handle (tb_row) and hands the
reducer a Row<T> - new in ludic.base: tb, row, h, rec - that the queue keeps, one per row reducer,
filled in place, so a targeted action allocates nothing; a stale handle runs nothing, and
LUDIC_ACTIONS_LOG=1 prints a line for it (@alloc_ok). Row reducers order among an action's by their
state's name, then the table's path.

Checked at compile time (actions_rows.ludic): the row reaches r.rec and r.h only - r.tb / r.row
refused, the view never assigned, stored, copied or handed on except to a @RowVerb (a function of
the record's own module taking Row<T> first; any other function taking a row is refused); a field
marked @Column (a table column mirrors it) is not written through r.rec; only the module owning the
state declares a row reducer; one @Target, an int, per action; the states between the row and the
action are read. `mut` is allowed on a Row<T> parameter.

ludic schema's code section gains row_reducers (record, table, state, action, target, predicted,
net, module, at) and row_verbs (name, record, module, at), and every action its target; row
reducers are left out of `reducers`. ludic deps and ludic-lsp name a row reducer
`reducer Deer in Herd.deer on Spook`. vocab: @Target, @Column, @RowVerb; docs/language pages;
LANGUAGE.md "A reducer on a row"; examples actions/rows and ten rejects; test.ludic feat, reject and
schema cases (not run); changes/row-reducers.md. Reseeded; bootstrap-cfree fixpoint holds (307497
lines); Maroon Lake's `ludic build --check` is clean against this tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 16:14:59 +03:00

82 lines
3.5 KiB
Text

# emit_vis.ludic — L3: module scope. A file belongs to the module its own `module NAME` line or
# its importer's names (frontend/parse.ludic, module_of); a file in no module is public. A
# reference from one module to another module's function, global, record or event needs that
# declaration `export`ed, and - when the referring module says `uses` - that module (or, for a
# package with no module line, the package) named there (frontend/modules.ludic), unless the
# referring module is a friend of it (a test harness). The engine's runtime needs no naming.
# LUDIC_VIS_REPORT=1 prints every violation as `vis: <file>: <module>.<name>` (a private name) or
# `uses: <file>: ...` (a module not in the uses list) and goes on, so a tool can add the exports
# and the uses a codebase needs before the rule is switched on for it.
var g_vis_report: int = -1
var g_vis_off: bool = false # a port's binding: checked where it is written (ports.ludic)
function vis_reporting() -> bool {
if g_vis_report < 0 {
g_vis_report = 0
if getenv("LUDIC_VIS_REPORT") != null { g_vis_report = 1 }
}
return g_vis_report == 1
}
# `what` is the name as written at the reference
# a generic function's instance is named for its type arguments (grow$int); a message names grow
function vis_plain(what: pointer) -> pointer {
var i = 0
while i < len(what) {
if what[i] == '$' { return what[0 .. i] }
i += 1
}
return what
}
function vis_say(m: pointer) -> void {
file_write(file_stderr(), m, len(m))
}
# does s start with p - without making the slice a comparison of s[0 .. n] would (asked for every
# reference)
function str_prefix(s: pointer, p: pointer) -> bool {
if s == null { return false }
let n = len(p)
if len(s) < n { return false }
var i = 0
while i < n {
if s[i] != p[i] { return false }
i += 1
}
return true
}
function vis_check(d: Node, what0: pointer) -> void {
if d == null { return }
port_check_bound(d)
# 0.S/0.R: a state's instance, the action queue and a reducer are the runtime's to supply and to
# call - the code that names them depends on no module for it
if d.kind == N_VAR and d.uns == 1 and str_prefix(d.s, "state$") and is_state_ty(d.ty) { return }
if d.kind == N_FN and (str_prefix(d.s, "ludic_reduce__") or str_prefix(d.s, "ludic_rowred__") or is_action_builtin(d.s)) { return }
deps_edge(d, what0) # LUDIC_DEPS: the graph ludic deps reads (emit_deps.ludic)
if g_vis_off { return }
if d.file == null { return }
let what = vis_plain(what0)
var here = g_err_file
if here == null { return }
let from = module_of(here)
let uto = module_for_uses(d.file)
if not (uto == "") and not (from == uto) and not module_friend_of(from, uto) and not module_may_use(from, uto) {
if vis_reporting() {
vis_say(`uses: {d.file}:{itoa(d.line)}: {uto}.{what} used from {here} (module {from})\n`)
} else {
let um = `{from} uses {uto}.{what} ({d.file}:{itoa(d.line)}): add 'uses {uto}' to {from}'s module line, or take it through a port`
if g_diag_json { diag_add(here, g_err_line, 0, "error", um) } else { perr(um) }
}
}
let to = module_of(d.file)
if (to == "") or (from == to) { return }
if module_friend_of(from, to) { return }
if d.vis == 1 { return }
if vis_reporting() {
vis_say(`vis: {d.file}:{itoa(d.line)}: {to}.{what} used from {here}\n`)
return
}
let pm = `{what} is private to module {to}; mark it 'export' where it is declared ({d.file})`
if g_diag_json {
diag_add(here, g_err_line, 0, "error", pm)
return
}
perr(pm)
}