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, producing the message bytes for the two failure classes. The envelope shape and its plural encodings live in crate::wire — this module is the solve side plus the shared exhausted rule, with no commitment to where output bytes go or how they’re encoded. Both the CLI shell (entry.rs) and the Tier-2 reactor (reactor.rs) call run_query here, then build a crate::wire::Envelope and hand it to a chosen crate::wire::EncoderDesc — so the shape has one source and can’t drift between transports.
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 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 readable text form (term_to_string) plus the raw term word the bson encoder walks. (No JSON rendering — the engine speaks text + bson; JSON, if a host wants it, is derived from bson at the host boundary. docs/design/IO.md.)
solve
The solve driver: dispatches a parsed goal into compiled predicates and runs the backtracking loop.
unify
Generic unification over tagged heap words.
wire
The wire layer: the fixed envelope shape as a typed value, plus plural encodings exposed as descriptors (vtables of function pointers). Splits what was collapsed in core.rs — where byte-emitters implicitly defined the shape — so the shape is owned once (here) and the encodings vary independently. See docs/design/IO.md.