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
impl SpaceInstance
Sourcepub fn new(program: &Program) -> EvalResult<Self>
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.
Sourcepub fn with_gas_limit(program: &Program, gas_limit: u64) -> EvalResult<Self>
pub fn with_gas_limit(program: &Program, gas_limit: u64) -> EvalResult<Self>
Create with a custom gas limit.
Sourcepub fn state_snapshot(&self) -> BTreeMap<String, Value>
pub fn state_snapshot(&self) -> BTreeMap<String, Value>
Get all state as a snapshot.
Sourcepub fn log_output(&self) -> &[String]
pub fn log_output(&self) -> &[String]
Get captured log output.
Sourcepub fn set_credential(&mut self, name: &str, value: Value)
pub fn set_credential(&mut self, name: &str, value: Value)
Set a credential value (called by host before actions).
Sourcepub fn dispatch(
&mut self,
action_name: &str,
args: Vec<Value>,
) -> EvalResult<ActionResult>
pub fn dispatch( &mut self, action_name: &str, args: Vec<Value>, ) -> EvalResult<ActionResult>
Dispatch an action by name with arguments.
Implements atomic transactions:
- Snapshot pre-action state
- Execute action body
- Check invariants
- Commit or rollback
Sourcepub fn render_view(&mut self, view_name: &str) -> EvalResult<Vec<SurfaceNode>>
pub fn render_view(&mut self, view_name: &str) -> EvalResult<Vec<SurfaceNode>>
Render the main view (or a named view) to a Surface tree.
Sourcepub fn render(&mut self) -> EvalResult<Vec<SurfaceNode>>
pub fn render(&mut self) -> EvalResult<Vec<SurfaceNode>>
Render the default “main” view.
Sourcepub fn set_mock_responses(&mut self, mocks: Vec<MockResponse>)
pub fn set_mock_responses(&mut self, mocks: Vec<MockResponse>)
Install mock capability responses (used by test runner).
Sourcepub fn eval_expr_public(&mut self, expr: &Expr) -> EvalResult<Value>
pub fn eval_expr_public(&mut self, expr: &Expr) -> EvalResult<Value>
Evaluate an expression via the internal evaluator (public for test runner).
Sourcepub fn eval_stmt_public(&mut self, stmt: &Stmt) -> EvalResult<Value>
pub fn eval_stmt_public(&mut self, stmt: &Stmt) -> EvalResult<Value>
Execute a statement via the internal evaluator (public for test runner).
Sourcepub fn define_in_env(&mut self, name: &str, value: Value)
pub fn define_in_env(&mut self, name: &str, value: Value)
Define a variable in the current environment scope (public for test runner).
Sourcepub fn push_scope(&mut self)
pub fn push_scope(&mut self)
Push a new scope in the environment (public for test runner).
Sourcepub fn call_update(&mut self, dt: f64) -> EvalResult<ActionResult>
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.
Sourcepub fn call_handle_event(&mut self, event: Value) -> EvalResult<ActionResult>
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.
Sourcepub fn surface_to_json(nodes: &[SurfaceNode]) -> Value
pub fn surface_to_json(nodes: &[SurfaceNode]) -> Value
Serialize a surface tree to JSON.
Sourcepub fn value_to_json_public(val: &Value) -> Value
pub fn value_to_json_public(val: &Value) -> Value
Convert a Value to JSON (public for golden reference generation).