//! noun โ€” the universal data type
//!
//! everything in nox is a noun: atom(F) | cell(noun, noun)
//! stored in a flat order with hash-consing (DAG, not tree)
//!
//! hash nouns (4 field elements) = cell(cell(h0,h1), cell(h2,h3))

pub mod tag;
pub mod inner;
pub mod hash;
pub mod order;

pub use tag::Tag;
pub use inner::Noun;
pub use hash::Digest;
pub use order::{Order, NounEntry};

/// order index โ€” all noun identifiers are u32 indices
pub type NounId = u32;

/// sentinel: no noun
pub const NIL: NounId = u32::MAX;

#[cfg(test)]
mod tests {
    use super::*;
    use nebu::Goldilocks;

    #[test]
    fn atom_allocation() {
        let mut order = Order::<1024>::new();
        let a = order.atom(Goldilocks::new(42), Tag::Field).unwrap();
        assert!(order.is_atom(a));
        let (val, tag) = order.atom_value(a).unwrap();
        assert_eq!(val, Goldilocks::new(42));
        assert_eq!(tag, Tag::Field);
    }

    #[test]
    fn cell_allocation() {
        let mut order = Order::<1024>::new();
        let a = order.atom(Goldilocks::new(1), Tag::Field).unwrap();
        let b = order.atom(Goldilocks::new(2), Tag::Field).unwrap();
        let c = order.cell(a, b).unwrap();
        assert!(order.is_cell(c));
        assert_eq!(order.head(c), Some(a));
        assert_eq!(order.tail(c), Some(b));
    }

    #[test]
    fn hash_consing_atoms() {
        let mut order = Order::<1024>::new();
        let a = order.atom(Goldilocks::new(42), Tag::Field).unwrap();
        let b = order.atom(Goldilocks::new(42), Tag::Field).unwrap();
        assert_eq!(a, b);
        assert_eq!(order.count(), 1);
    }

    #[test]
    fn hash_consing_cells() {
        let mut order = Order::<1024>::new();
        let x = order.atom(Goldilocks::new(1), Tag::Field).unwrap();
        let y = order.atom(Goldilocks::new(2), Tag::Field).unwrap();
        let c1 = order.cell(x, y).unwrap();
        let c2 = order.cell(x, y).unwrap();
        assert_eq!(c1, c2);
        assert_eq!(order.count(), 3);
    }

    #[test]
    fn different_tags_different_nouns() {
        let mut order = Order::<1024>::new();
        let a = order.atom(Goldilocks::new(42), Tag::Field).unwrap();
        let b = order.atom(Goldilocks::new(42), Tag::Word).unwrap();
        assert_ne!(a, b);
    }

    #[test]
    fn hash_noun_roundtrip() {
        let mut order = Order::<1024>::new();
        let d = [Goldilocks::new(11), Goldilocks::new(22), Goldilocks::new(33), Goldilocks::new(44)];
        let h = order.hash_noun(&d).unwrap();
        assert!(order.is_cell(h));
        assert_eq!(order.read_hash_noun(h).unwrap(), d);
    }

    #[test]
    fn hash_noun_is_hash_consed() {
        let mut order = Order::<1024>::new();
        let d = [Goldilocks::new(1), Goldilocks::new(2), Goldilocks::new(3), Goldilocks::new(4)];
        assert_eq!(order.hash_noun(&d).unwrap(), order.hash_noun(&d).unwrap());
    }
}

Dimensions

optica/src/output/mod.rs
trident/src/ir/mod.rs
trident/src/compile/mod.rs
nebu/rs/extension/mod.rs
optica/src/parser/mod.rs
trident/src/cli/mod.rs
optica/src/render/mod.rs
trident/src/runtime/mod.rs
trident/src/deploy/mod.rs
trident/src/neural/mod.rs
trident/src/api/mod.rs
trident/src/diagnostic/mod.rs
optica/src/server/mod.rs
nox/rs/patterns/mod.rs
optica/src/scanner/mod.rs
optica/src/graph/mod.rs
trident/src/syntax/mod.rs
trident/src/typecheck/mod.rs
trident/src/gpu/mod.rs
trident/src/verify/mod.rs
trident/src/package/mod.rs
trident/src/import/mod.rs
trident/src/ast/mod.rs
trident/src/cost/mod.rs
trident/src/config/mod.rs
trident/src/lsp/mod.rs
optica/src/query/mod.rs
trident/src/field/mod.rs
rs/core/src/bounded/mod.rs
trident/src/syntax/grammar/mod.rs
trident/src/syntax/lexer/mod.rs
trident/src/neural/training/mod.rs
trident/src/config/scaffold/mod.rs
trident/src/verify/equiv/mod.rs
trident/src/verify/sym/mod.rs
trident/src/verify/solve/mod.rs
trident/src/neural/data/mod.rs
rs/macros/src/registers/mod.rs
rs/macros/src/addressed/mod.rs
trident/src/verify/smt/mod.rs
trident/src/config/resolve/mod.rs
rs/core/src/fixed_point/mod.rs
trident/src/syntax/format/mod.rs
trident/src/lsp/semantic/mod.rs
trident/src/package/store/mod.rs
genies/wgsl/src/shaders/mod.rs
trident/src/ir/lir/mod.rs
trident/src/neural/model/mod.rs
trident/src/neural/inference/mod.rs
trident/src/package/hash/mod.rs
trident/src/package/registry/mod.rs
jali/wgsl/src/shaders/mod.rs
trident/src/lsp/util/mod.rs
trident/src/verify/synthesize/mod.rs
kuro/wgsl/src/shaders/mod.rs
trop/wgsl/src/shaders/mod.rs
rs/macros/src/cell/mod.rs
trident/src/cost/stack_verifier/mod.rs
trident/src/package/manifest/mod.rs
trident/src/api/tests/mod.rs
trident/src/cost/model/mod.rs
trident/src/verify/report/mod.rs
trident/src/ir/kir/mod.rs
trident/src/typecheck/tests/mod.rs
rs/rsc/src/lints/mod.rs
trident/src/syntax/parser/mod.rs
trident/src/ir/tree/mod.rs
trident/src/ir/tir/mod.rs
trident/src/ir/tir/optimize/mod.rs
trident/src/ir/lir/lower/mod.rs
trident/src/syntax/parser/tests/mod.rs
cw-cyber/packages/cyber-std/src/tokenfactory/mod.rs
trident/src/ir/tir/lower/mod.rs
trident/src/ir/kir/lower/mod.rs
trident/src/ir/tree/lower/mod.rs
trident/src/ir/tir/neural/mod.rs
trident/src/neural/data/tir_graph/mod.rs
trident/src/ir/tir/builder/mod.rs
cw-cyber/contracts/cybernet/src/tests/mod.rs
trident/src/ir/tir/stack/mod.rs

Local Graph