Skip to main content

SpaceInstance

Struct SpaceInstance 

Source
pub struct SpaceInstance { /* private fields */ }
Expand description

Runtime instance of a PEPL space.

Holds the current state, derived fields, and references to the AST for actions, views, and invariants. Supports atomic action dispatch with invariant checking and rollback.

Implementations§

Source§

impl SpaceInstance

Source

pub fn new(program: &Program) -> EvalResult<Self>

Create a new SpaceInstance from a parsed+validated Program.

Initializes state fields with their default values, computes derived fields, and registers actions/views.

Source

pub fn with_gas_limit(program: &Program, gas_limit: u64) -> EvalResult<Self>

Create with a custom gas limit.

Source

pub fn get_state(&self, name: &str) -> Option<&Value>

Get the current value of a state field.

Source

pub fn state_snapshot(&self) -> BTreeMap<String, Value>

Get all state as a snapshot.

Source

pub fn log_output(&self) -> &[String]

Get captured log output.

Source

pub fn clear_log(&mut self)

Clear log output.

Source

pub fn set_credential(&mut self, name: &str, value: Value)

Set a credential value (called by host before actions).

Source

pub fn dispatch( &mut self, action_name: &str, args: Vec<Value>, ) -> EvalResult<ActionResult>

Dispatch an action by name with arguments.

Implements atomic transactions:

  1. Snapshot pre-action state
  2. Execute action body
  3. Check invariants
  4. Commit or rollback
Source

pub fn render_view(&mut self, view_name: &str) -> EvalResult<Vec<SurfaceNode>>

Render the main view (or a named view) to a Surface tree.

Source

pub fn render(&mut self) -> EvalResult<Vec<SurfaceNode>>

Render the default “main” view.

Source

pub fn set_mock_responses(&mut self, mocks: Vec<MockResponse>)

Install mock capability responses (used by test runner).

Source

pub fn eval_expr_public(&mut self, expr: &Expr) -> EvalResult<Value>

Evaluate an expression via the internal evaluator (public for test runner).

Source

pub fn eval_stmt_public(&mut self, stmt: &Stmt) -> EvalResult<Value>

Execute a statement via the internal evaluator (public for test runner).

Source

pub fn define_in_env(&mut self, name: &str, value: Value)

Define a variable in the current environment scope (public for test runner).

Source

pub fn push_scope(&mut self)

Push a new scope in the environment (public for test runner).

Source

pub fn pop_scope(&mut self)

Pop the innermost scope (public for test runner).

Source

pub fn call_update(&mut self, dt: f64) -> EvalResult<ActionResult>

Call update(dt) — game loop tick.

Like an action dispatch: atomic, with invariant checking and rollback.

Source

pub fn call_handle_event(&mut self, event: Value) -> EvalResult<ActionResult>

Call handleEvent(event) — game loop event handler.

Like an action dispatch: atomic, with invariant checking and rollback.

Source

pub fn surface_to_json(nodes: &[SurfaceNode]) -> Value

Serialize a surface tree to JSON.

Source

pub fn value_to_json_public(val: &Value) -> Value

Convert a Value to JSON (public for golden reference generation).

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<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, 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.