Skip to main content

Interpreter

Struct Interpreter 

Source
pub struct Interpreter {
    pub max_depth: usize,
    pub max_terminals: usize,
    pub seed: u64,
    /* private fields */
}

Fields§

§max_depth: usize

Hard cap on rule-derivation recursion depth. Defaults to MAX_DEPTH (64). Exceeding it returns ShapeError::DepthLimitExceeded.

§max_terminals: usize

Hard cap on the number of terminals a single derivation may emit. Defaults to MAX_TERMINALS (100 000). Exceeding it returns ShapeError::CapacityOverflow.

§seed: u64

Seed for stochastic rule selection. Each call to Interpreter::derive constructs a fresh Pcg64 from this seed, so re-running with the same seed produces a bit-identical ShapeModel. Default 0.

Implementations§

Source§

impl Interpreter

Source

pub fn new() -> Self

Source

pub fn add_statement(&mut self, stmt: Statement) -> Result<(), ShapeError>

Registers one parsed grammar statement — rule, attr, const, or style. The one-stop text loading path:

use symbios_shape::Interpreter;
use symbios_shape::grammar::parse_statement;
let mut interp = Interpreter::new();
for line in ["attr Floors = 3", r#"Lot --> Extrude(Floors * 3.2) I("Mass")"#] {
    interp.add_statement(parse_statement(line).unwrap()).unwrap();
}
Source

pub fn set_style(&mut self, name: impl Into<String>) -> Result<(), ShapeError>

Selects a declared style; its attr overrides apply at derivation (below host set_attr overrides, above attr defaults).

Source

pub fn clear_style(&mut self)

Clears any active style.

Source

pub fn rules(&self) -> &HashMap<String, RuleDef>

Returns a reference to the full rule table (rule name → definition).

Source

pub fn set_attr(&mut self, name: impl Into<String>, value: f64)

Sets a named attribute readable from grammar expressions. The host’s override channel: call before derive to parameterize a grammar from outside (per-lot floor counts, prosperity knobs, …).

Source

pub fn attrs(&self) -> &HashMap<String, f64>

Returns the attribute table (host overrides + grammar declarations).

Source

pub fn set_variants( &mut self, name: impl Into<String>, variants: Vec<RuleVariant>, )

Directly inserts a pre-built variant list for name, bypassing weight validation. The rule’s declared parameters are preserved when it already exists.

Intended for restoring snapshots produced by crate::genetics::ShapeGenotype::to_interpreter.

Source

pub fn add_rule(&mut self, name: impl Into<String>, ops: Vec<ShapeOp>)

Registers a deterministic production rule.

Source

pub fn add_grammar_rule(&mut self, rule: GrammarRule) -> Result<(), ShapeError>

Registers a rule parsed from grammar text — parameters, weighted or guarded variants and all. The one-stop registration path for text-driven hosts.

Source

pub fn add_rule_variants( &mut self, name: impl Into<String>, params: Vec<String>, variants: Vec<RuleVariant>, ) -> Result<(), ShapeError>

Registers a rule from pre-built variants, validating selector shape: all-weighted, or when(..) guards with at most one trailing else.

Source

pub fn add_rule_def( &mut self, name: impl Into<String>, params: Vec<String>, variants: Vec<(f64, Vec<ShapeOp>)>, ) -> Result<(), ShapeError>

Registers a rule with declared parameter names and weighted variants — the full-fidelity registration path for parameterized rules.

Returns Err(InvalidNumericValue) for bad weights and Err(ParseError) for duplicate or over-long parameter lists.

Source

pub fn add_weighted_rules( &mut self, name: impl Into<String>, variants: Vec<(f64, Vec<ShapeOp>)>, ) -> Result<(), ShapeError>

Registers a stochastic rule with multiple weighted alternatives.

variants is a list of (relative_weight, ops) pairs. Weights need not sum to 1.0 — they are normalised internally during selection.

Returns Err(InvalidNumericValue) if any weight is non-finite or negative.

Source

pub fn has_rule(&self, name: &str) -> bool

Returns true if a rule with name is registered.

Source

pub fn derive( &self, root_scope: Scope, root_rule: impl Into<String>, ) -> Result<ShapeModel, ShapeError>

Derives the shape model starting from root_scope and root_rule.

Uses a breadth-first work queue to expand rules until all branches terminate via I(mesh_id) or an unknown rule name (implicit terminal). A fresh RNG seeded from self.seed is created for each call, making derivations reproducible for the same seed value.

Trait Implementations§

Source§

impl Default for Interpreter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V