clm-kernel 0.0.12

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
//! Layer 1: declarative Fractal Petri Net harness (Sprint 533, option A).
//!
//! The namespace-firing nets rebuilt the same place table and registered it by
//! hand. `PlaceSpec` plus `register_place_specs` turns that into one declaration.
//!
//! Scope is deliberate. The harness serves the nets that fire through
//! `MCardTokenNamespace`. `petri_process` builds markings locally and never fires
//! through the namespace, so it is excluded until Sprint 535 decides its fate.

use crate::cpn::mcard_token::PlaceMCard;
use crate::cpn::place_type_lattice::{PlaceRole, PlaceTypeBinding};
use crate::cpn::token_namespace::MCardTokenNamespace;

/// One place and its lattice role.
#[derive(Debug, Clone)]
pub struct PlaceSpec<'a> {
    pub place_id: &'a str,
    pub type_expr: &'a str,
    pub role: PlaceRole,
    /// Binding-level type URI. `None` falls back to the place's own expression.
    pub binding_type_uri: Option<&'a str>,
}

impl<'a> PlaceSpec<'a> {
    pub fn new(place_id: &'a str, type_expr: &'a str, role: PlaceRole) -> Self {
        Self { place_id, type_expr, role, binding_type_uri: None }
    }

    /// Binds the place under an explicit type URI rather than its own expression.
    pub fn with_binding_type_uri(mut self, type_uri: &'a str) -> Self {
        self.binding_type_uri = Some(type_uri);
        self
    }
}

/// Builds one place from a spec. Use this for dynamic places too.
pub fn build_place(spec: &PlaceSpec<'_>) -> Result<PlaceMCard, String> {
    PlaceMCard::create(spec.place_id, spec.type_expr, None, spec.role.as_str(), Some("blake3"), None)
}

/// Builds and registers every place in a table, returning them in declaration order.
pub fn register_place_specs(
    namespace: &mut MCardTokenNamespace,
    specs: &[PlaceSpec<'_>],
) -> Result<Vec<PlaceMCard>, String> {
    let mut places = Vec::with_capacity(specs.len());
    for spec in specs {
        let place = build_place(spec)?;
        let binding = PlaceTypeBinding::new(
            place.clone(),
            spec.role,
            spec.binding_type_uri.map(|uri| uri.to_string()),
            None,
        );
        namespace.register_place(place.clone(), Some(binding));
        places.push(place);
    }
    Ok(places)
}