Expand description
Core runtime type definitions.
This module defines the primitive types used by LOGOS programs at runtime. These are type aliases that map LOGOS types to their Rust equivalents.
§Type Mappings
| LOGOS Type | Rust Type | Description |
|---|---|---|
Nat | u64 | Natural numbers (non-negative) |
Int | i64 | Signed integers |
Real | f64 | Floating-point numbers |
Text | String | UTF-8 strings |
Bool | bool | Boolean values |
Unit | () | The unit type |
Char | char | Unicode scalar values |
Byte | u8 | Raw bytes |
Seq<T> | LogosSeq<T> | Ordered sequences (reference semantics) |
Set<T> | HashSet<T> | Unordered unique elements |
Map<K,V> | LogosMap<K,V> | Key-value mappings (reference semantics) |
Structs§
- Logos
Complex - An exact complex number
re + im·i— the AOT mirror of the interpreter’sComplex.complex(0, 1)compiles toLogosComplex::new(..);+ − × ÷stay exact and closed (i·i = −1). NOT ordered.Displayshows3+4i/i/-2i, matching the interpreter. - Logos
Decimal - An exact base-10 fixed-point number — money’s runtime type on the compiled-to-Rust
path, the AOT mirror of the interpreter’s
Decimal.decimal("19.99")compiles toLogosDecimal::parse("19.99");+ − ×stay exactDecimal(scale preserved), and÷widens to the exactLogosRational(base-10 division need not terminate).Displayshows the scale faithfully (19.99,20.00), matching the interpreter. - Logos
Dense I64Map - Direct-addressed
i64 → i64map — the densest representation of aMap of Int to Int, emitted when the compiler PROVES every key ever inserted or queried lands in a statically bounded window[lo, lo + slots)whose width is ≤ the map’s ownwith capacityhint. Keys index a flat value array (data[key - lo]); a parallel presence bitset distinguishes a stored value from an absent slot, sogetreturnsNonefor an in-range key that was never inserted. No hashing, no probing, no sparse table — both build and scan phases are sequential array accesses, which the backend vectorizes and the prefetcher loves. This is perfect hashing for dense integer keys: it removes the random-access hash table that costsLogosI64Mapits cache locality. - Logos
Dense I64Map NoPresence - The presence-elided sibling of
LogosDenseI64Map, emitted ONLY when the compiler additionally proves the get/contains key domain is a subset of a CONTIGUOUSLY FULLY-COVERED insert range — i.e. every key the program reads was definitely written first. With that proof the presence bit is invariably set, so it is dropped:getis a bareSome(data[key - lo])load, byte-identical to a C array read, and no presence bitset is allocated. The gate forbids this type for any map with acontainsuse (there is no way to answer membership without presence), socontains_key/LogosContainsare intentionally absent — a generatedcontainson this type would fail to compile, surfacing a gate bug loudly rather than silently miscompiling. - Logos
Dense I64Set - Direct-addressed
i64SET — the keys-only, value-free sibling ofLogosDenseI64Map(the dense analogue ofLogosI64Set). Membership lives in a presence bitset over the proven window[lo, lo + slots);insertsets a bit,containstests one. No value array → 1 bit per key, the smallest footprint of any map/set representation. - Logos
DivU64 - Precomputed unsigned division by a loop-invariant runtime divisor — the
magic-multiply that replaces a hardware
div/idivonce the divisor is pinned. Codegen emitsLogosDivU64::new(n)in a loop’s preheader (computed ONCE) and rewrites each in-loopx % n/x / nto.rem(x)/.div(x), turning a ~20–40-cycle division into a multiply-high plus a shift. gcc and rustc both leave a runtime-invariant divisor as a realdiv(neither synthesizes this), so it is a strict win over the C baseline on division-hot loops (graph_bfs’s% nadjacency build). - Logos
I32Map - i32-narrowed open-addressing
i64 → i64map — the same probe-table shape asLogosI64Mapbut with 8-byte(i32, i32)slots, emitted when the compiler PROVES every key AND value stays ini32range. Halving the slot width halves the table’s memory traffic — the dominant cost of this random-access workload — for maps the dense gate cannot capture (no proven contiguous key window). The call surface isi64(keys/values widen at the boundary; the proof makes the narrowing cast lossless), so codegen emits it identically toLogosI64Map. - Logos
I32Set - i32-narrowed open-addressing set — the keys-only sibling of
LogosI32Map(the i32 analogue ofLogosI64Set). One flatVec<i32>: 4 bytes per slot, a quarter ofLogosI64Map’s footprint. Emitted for a set-usageInt → Intmap whose keys are all proven to fiti32. The empty-slot sentinel is0(the real key0tracked separately) sovec![0; slots]allocates viaalloc_zeroed— lazily-zeroed, no eager memset of the table. - Logos
I64Map - A specialized open-addressing
i64 → i64map with VALUE semantics and noRc<RefCell>indirection. - Logos
I64Set - Open-addressing
i64SET — the keys-only sibling ofLogosI64Map, emitted for aMap of Int to Intthe alias analysis proves is used ONLY as a set (insert + contains; the value is never read — two_sum’sseen). ONE flatVec<i64>with linear probing and a0empty-slot sentinel (the real key0tracked separately for full key-space correctness). With no value array it has HALF the store traffic and footprint of the map — 8 bytes/slot, smaller than C’sstruct Entry { long key; int occupied; }. - Logos
Map - Key-value mapping with reference semantics.
- Logos
Modular - An element of the ring ℤ/nℤ — the AOT mirror of the interpreter’s
Modular.modular(value, modulus)compiles toLogosModular::new(..);+ − ×wrap in the ring,powis fast modular exponentiation, and÷multiplies by the modular inverse. NOT ordered. - Logos
Money - Money for the compiled tier — an exact amount in a currency, mirroring
base::Money.+ −require the SAME currency (a runtime-panic backstop; the type checker rejects mismatches first),× ÷scale by an exact number, and a same-currency÷is the dimensionless ratio. - Logos
Quantity - A physical quantity on the compiled-to-Rust path — the AOT mirror of the interpreter’s
Quantityvalue. The magnitude rides the exact rational tower (no float drift) and the display unit travels with it soShowrenders faithfully (42/127 ft).+ −require the same dimension — the front-end’s type checker proves this, so a mismatch is a compile error, not a runtime one; the runtime check here is a defensive backstop.× ÷combine dimensions, and a quantity may be scaled by a dimensionless number (unit preserved). - Logos
Rational - Exact rational number for compiled LOGOS programs — the AOT counterpart of the
interpreter’s
RuntimeValue::Rational. - Logos
Seq - Ordered sequence with reference semantics.
- Logos
SeqIter - Logos
Uuid - A 128-bit UUID for the compiled tier (RFC 9562), mirroring
logicaffeine_base::Uuid. ACopynewtype over[u8; 16]— no allocation, byte-ordered comparison (so v6/v7 sort by time), canonical text form.
Enums§
- Logos
Int - The exact integer for GENERATED code:
i64on the fast path, spilling to a heap [logicaffeine_base::BigInt] the moment a value escapes 64 bits — the AOT’s mirror of the interpreter’s Int→BigInt promotion (and of the JIT’s overflow side-exit). Every operation NORMALIZES: a big result that fitsi64downsizes toSmall, so representation never leaks into==/Ord. - Value
- Dynamic value type for heterogeneous collections.
Traits§
- Fill
Clone - A FILL-SLOT copy: collections copy DEEP, so every slot of a fill
(
n copies of x,[x] * n) is an independent row — nevernaliases of one row (the classic[[0]] * 3footgun is designed out). Scalars copy plain. Mirrors the tree-walker’s recursiveRuntimeValue::deep_clone. - Into
Rate - An exchange rate accepted by
set_rate— a plain integer (1), an exactLogosDecimal(1.10), or aLogosRational. All widen losslessly onto the Rational tower so normalisation stays exact, matching the interpreter’sset_ratebuiltin. - Logos
Contains - Unified containment testing for all collection types.
Functions§
- set_
rate - Install (or replace) one exchange rate in the ambient rate context —
1 <code> = ratereference units. The compiled-tier mirror of theset_ratebuiltin; a fresh process starts with no rates, so a program installs them before any<money> in <currency>conversion. - set_
rates - Bulk-install a whole exchange-rate table from a
Map of Text to <number>(currency code → rate vs the reference) into the ambient rate context. The compiled-tier mirror of theset_ratesbuiltin and the bridge a literal, network-synced, or fetched table feeds. Order-independent. - text_
bytes - A Text’s UTF-8 bytes as a
Seq of Int(thetext_bytesbuiltin, AOT). - text_
from_ bytes - Rebuild a Text from a
Seq of Intof UTF-8 bytes (thetext_from_bytesbuiltin, AOT — the exact inverse oftext_bytes). Inputs originate fromtext_bytes, so the bytes are always valid UTF-8; the lossy fallback only guards against a hand-built malformed Seq. - to_
currency - Convert money to another currency via the ambient rate context — the
<money> in <currency>surface. Panics (the typed-error backstop, like a currency-mismatch+) when no rates are in scope or the currency lacks a rate; the front-end / interpreter surface these as clean errors. - value_
semantics_ enabled - Whether Mutable Value Semantics is enabled for compiled (AOT) programs. The
AOT binary is a separate process from the interpreter, so it reads the
LOGOS_VALUE_SEMANTICSenv var itself (inherited from the parent process), cached once. When on, collectionClonedeep-copies (value semantics); when off it shares theRc(the historical reference semantics — unchanged).
Type Aliases§
- Bool
- Boolean truth values.
- Byte
- Raw bytes (0-255).
- Char
- Unicode scalar values.
- FxIndex
Map - The insertion-ordered map behind every LOGOS
Map:IndexMapfor the order contract (iteration, display, and serialization follow insertion, like a Python dict), Fx hashing for speed on the small keys LOGOS programs use (no DoS-resistance requirement). - FxIndex
Set - Unordered collections of unique elements with FxHash.
The insertion-ordered set behind every LOGOS
Set: display and iteration follow first-insertion order, identical to the tree-walker’s Vec-backed sets and the direct-WASM linear sets. Fx hashing for speed. NOTE: removal must go throughshift_remove(order-preserving), neverswap_remove. - Int
- Signed integers.
- Map
- Key-value mappings with reference semantics.
- Nat
- Non-negative integers. Maps to Peano
Natin the kernel. - Real
- IEEE 754 floating-point numbers.
- Seq
- Ordered sequences with reference semantics.
- Set
- Text
- UTF-8 encoded text strings.
- Tuple
- Tuple type: Vec of heterogeneous Values (uses LogosIndex from indexing module)
- Unit
- The unit type (single value).