Skip to main content

Crate plg_runtime

Crate plg_runtime 

Source
Expand description

plg-runtime: the support library linked into every compiled Prolog binary (libplg_runtime.a).

It provides the machine substrate compiled predicates call into — term heap, trail, choice-point stack, generic unification, the goal-only --query parser, solution output, and the process entry point. It contains NO clause interpreter: clause control flow lives in the LLVM IR that plgc generates (see docs/design/COMPILATION_MODEL.md and docs/design/LESSONS_FROM_V1.md).

Modules§

abi
The C-ABI surface generated code calls into (plg_rt_*).
builtins
The builtin layer: arithmetic evaluation (arith), standard term order (order), and the C-ABI predicate surface (pred) that compiled code calls into for is/2, arithmetic/term comparison, \=/2, compare/3, cut, and codegen helpers.
cell
Tagged 64-bit term words.
control
Query-level control constructs and deterministic builtins.
copyterm
Relocatable off-heap term copies.
core
I/O-free query core: parse + solve + the v1 JSON wire shape, with no commitment to where the bytes go. Both the WASI/CLI shell (entry.rs, sink = stdout) and the Tier-2 reactor (reactor.rs, sink = a linear-memory buffer) call into here, so the JSON shape and the exhausted rule have a single source and can’t drift between the two transports (docs/design/done/WASM_TIER2_PLAN.md A1 / WASM.md finding #6). The shared core INVOCATION.md’s resident mode also wants is the same one.
entry
Process entry: plg_rt_init + plg_rt_main, called from the thin generated main. Owns argv parsing (hand-rolled — no clap inside compiled binaries), output, and the v1 exit-code contract:
errors
Structured runtime errors (ISO error terms).
machine
The Machine: the single runtime context every compiled predicate receives (%M in generated IR). Owns the term heap, trail, choice-point stack, argument registers, the current success continuation, step accounting, and the runtime atom table.
query
Minimal goal-only parser for runtime --query strings.
reactor
Tier-2 reactor ABI for wasm32-unknown-unknown (Cloudflare Workers / V8 isolates). No WASI, no stdio/argv — the module exports functions a JS host calls over linear memory (docs/design/done/WASM_TIER2_PLAN.md A3):
render
Solution rendering: the v1 wire contract, byte-compatible.
solve
The solve driver: dispatches a parsed goal into compiled predicates and runs the backtracking loop.
unify
Generic unification over tagged heap words.