Skip to main content

prism_tensor/
verbs.rs

1//! Layer-3 substrate-Term verbs per [Wiki ADR-024][09-adr-024] +
2//! [Wiki ADR-055][09-adr-055] + [Wiki ADR-056][09-adr-056] (ψ-residuals
3//! discipline scope refined to route bodies only — verb bodies admit
4//! comparison + concat + hash composition).
5//!
6//! [09-adr-024]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
7//! [09-adr-055]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
8//! [09-adr-056]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
9
10#![allow(missing_docs)]
11
12use uor_foundation_sdk::{partition_product, verb};
13
14// A single-byte W8 wrapper shape for compositional verbs over
15// signed 8-bit values. Per ADR-056 verb bodies admit the full
16// substrate vocabulary (concat for byte-packing, comparisons for
17// saturation matches); the leaf-shape pattern follows the
18// smoke-test convention (no PartitionProductFields impl on leaves).
19
20pub struct W8Byte;
21impl uor_foundation::pipeline::ConstrainedTypeShape for W8Byte {
22    const IRI: &'static str = "https://uor.foundation/type/ConstrainedType";
23    const SITE_COUNT: usize = 1;
24    const CONSTRAINTS: &'static [uor_foundation::pipeline::ConstraintRef] = &[];
25    const CYCLE_SIZE: u64 = 256;
26}
27impl uor_foundation::pipeline::__sdk_seal::Sealed for W8Byte {}
28impl uor_foundation::enforcement::GroundedShape for W8Byte {}
29impl uor_foundation::pipeline::IntoBindingValue for W8Byte {
30    const MAX_BYTES: usize = 1;
31    fn into_binding_bytes(
32        &self,
33        _out: &mut [u8],
34    ) -> Result<usize, uor_foundation::enforcement::ShapeViolation> {
35        Ok(0)
36    }
37}
38
39partition_product!(BytePair, W8Byte, W8Byte);
40
41// Substrate-Term `add_bytes(a, b)` — single-byte ring add at W8.
42// Architectural witness that verb body composition over W8 leaves
43// works through depth-1 partition-product field access.
44verb! {
45    pub fn add_bytes(input: BytePair) -> W8Byte {
46        add(input.0, input.1)
47    }
48}
49
50// Substrate-Term concat — admissible per ADR-056 (verb bodies have
51// no ψ-residual discipline). Realizes the byte-packing primitive
52// the canonical SHA pad-and-finalize composition uses.
53verb! {
54    pub fn concat_bytes(input: BytePair) -> W8Byte {
55        concat(input.0, input.1)
56    }
57}
58
59// `saturating_xor_bytes(a, b)` — the GF(2) overflow-free byte sum
60// xor(a, b), shipped as the architectural witness for tensor
61// saturation per ADR-054 § Substrate-Term realization examples.
62// Per ADR-056 the broader Wn saturation path uses `match` over
63// `ge(acc, sat_max)` comparisons (now admissible in verb bodies);
64// the witness here demonstrates the no-overflow byte-add primitive
65// the saturation composition reduces to for unsigned operands.
66verb! {
67    pub fn saturating_xor_bytes(input: BytePair) -> W8Byte {
68        xor(input.0, input.1)
69    }
70}