Skip to main content

Module compiler

Module compiler 

Source
Expand description

AST → bytecode compiler.

Layout: Main’s bytecode is emitted first (entry pc 0) and ends with Halt; each function body is appended after it and reached via Call (an absolute jump to its entry_pc). Function names are registered in a first pass so forward references and (mutual) recursion resolve.

Locals are assigned registers as they are first bound; expression temporaries get fresh registers above them, so a call’s argument block never overlaps a live caller local.

Structs§

Compiler

Functions§

magic_div_enabled
Whether the W24 constant-divisor magic-reciprocal lowering is enabled. Default ON (it is bit-identical to Op::Div/Op::Mod for the proven non-negative dividend it gates on, validated by the corpus differential). LOGOS_MAGIC_DIV=0 is the kill-switch — also the A/B handle for measuring the lever’s effect on a quiet box. Read once.
magic_eval
Evaluate the magic reciprocal: x / c when mul_back == 0, else x % c (mul_back == c). x is the dividend reinterpreted as u64 — sound because the op is emitted ONLY for a proven non-negative x, where the i64 bit pattern equals the mathematical value and the unsigned quotient/remainder equal the signed truncating ones. The remainder is x - q*c computed in wrapping i64 (the low 64 bits agree with the u64 difference), bit-exact with the kernel’s wrapping_rem for non-negative x.
magic_u64_gen
Precompute the unsigned magic-reciprocal constants (magic, more) for a constant divisor c (c != 0), reusing the single canonical logicaffeine_data::LogosDivU64 generator — the same algorithm the AOT compile_to_rust path emits, exhaustively proven against hardware //%. The more byte encoding (low 6 bits = shift, 0x40 = the 65-bit add-marker path, 0x80 = the pure-shift power-of-two path) is exactly what magic_eval consumes.
narrow_vm_enabled
Narrow a new Seq of Int whose elements provably fit i32 into half-width (Vec<i32>) VM storage — the interpreter analogue of the AOT Vec<i64>Vec<i32> narrowing, halving the array footprint and cache pressure. The JIT region path is i32-array aware (the hot region still tiers — 0 bails). PROMOTED 2026-06-21: default ON (kill-switch LOGOS_NARROW_VM=0) — graph_bfs -27.6% and array_fill -16.7% on the faithful interleaved A/B, all 33 benchmarks bit-identical, full suite 10341/10341 green, no regression.