Skip to main content

Module n3_compiler

Module n3_compiler 

Source
Expand description

N3Logic → SHACL → Sentinel Bytecode compiler (CogAI symbolic layer).

The LLM emits N3 assertions on the cold path; this module validates them against compiled SHACL shapes from crate::modalities::logic::shacl and lowers surviving rules to SlgOpcode sequences for the Core-1 Webizen VM. Hot-path execution uses only fixed caller-supplied buffers.

Structs§

AgentIntentFrame
CompiledFormula
CompiledRule
CompiledTriple
N3CompiledProgram

Enums§

CompiledTerm
N3CompileError
N3OutputMode
SentinelError

Constants§

MAX_COMPILED_OPCODES
MAX_COMPILED_QUINS
MAX_CONTEXT_NAMESPACE_SLOTS
MAX_INTENT_SCOPE_SLOTS

Functions§

compile_formula
Compile a formula into the fixed 8-triple CompiledFormula buffer; triples beyond the cap are silently truncated.
compile_rule_to_opcodes
Lower one N3 rule into Sentinel opcodes (reuses SHACL terminal semantics).
compile_rule_to_quin
Emit a compiled rule as NQuin(s): deontic-lowerable rules produce a single norm quin via compile_n3_rule_to_norm; other rules fall back to one fact quin per formula head triple. QuinBufferFull when out can’t hold the result.
compile_rule_to_zero_heap
Compile an entire parsed N3 rule (id, arrow type, weight, premise, conclusion) into the zero-heap CompiledRule form.
compile_rules_with_shacl_gate
SHACL-gated batch compile: validate each rule, then emit opcodes into a fixed buffer.
compile_term
Hash-lower a parsed N3 Term to a CompiledTerm, preserving the variable/literal/URI distinction. Variables hash their name; an unhashable non-variable falls back to q_hash("?").
compile_triple
Compile a parsed triple — each of subject/predicate/object lowered via compile_term.
default_observation_shape
Build a default health-observation SHACL gate for LLM-emitted N3 (cold path helper).
execute_compiled_program
Execute compiled opcodes inside the 42 MB SlgArena without heap growth in the eval loop.
triple_to_quin
Pack a compiled triple into an NQuin under context, computing the XOR-fold parity. Never fails at present — the Result preserves the signature for future checks.
validate_rule_against_shapes
Returns true when every conclusion triple property path matches a compiled SHACL shape.