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<'a> uor_foundation::pipeline::IntoBindingValue<'a> for W8Byte {
30    fn as_binding_value<const INLINE_BYTES: usize>(
31        &self,
32    ) -> uor_foundation::pipeline::TermValue<'a, INLINE_BYTES> {
33        uor_foundation::pipeline::TermValue::empty()
34    }
35}
36
37partition_product!(BytePair, W8Byte, W8Byte);
38
39// Substrate-Term `add_bytes(a, b)` — single-byte ring add at W8.
40// Architectural witness that verb body composition over W8 leaves
41// works through depth-1 partition-product field access.
42verb! {
43    pub fn add_bytes(input: BytePair) -> W8Byte {
44        add(input.0, input.1)
45    }
46}
47
48// Substrate-Term concat — admissible per ADR-056 (verb bodies have
49// no ψ-residual discipline). Realizes the byte-packing primitive
50// the canonical SHA pad-and-finalize composition uses.
51verb! {
52    pub fn concat_bytes(input: BytePair) -> W8Byte {
53        concat(input.0, input.1)
54    }
55}
56
57// `saturating_xor_bytes(a, b)` — the GF(2) overflow-free byte sum
58// xor(a, b), shipped as the architectural witness for tensor
59// saturation per ADR-054 § Substrate-Term realization examples.
60// Per ADR-056 the broader Wn saturation path uses `match` over
61// `ge(acc, sat_max)` comparisons (now admissible in verb bodies);
62// the witness here demonstrates the no-overflow byte-add primitive
63// the saturation composition reduces to for unsigned operands.
64verb! {
65    pub fn saturating_xor_bytes(input: BytePair) -> W8Byte {
66        xor(input.0, input.1)
67    }
68}