Trait budvm::Environment

source ·
pub trait Environment: 'static {
    type String: DynamicValue + for<'a> From<&'a str> + From<String>;
    type Intrinsic: Clone + PartialEq + Display + Debug + FromStr;

    // Required methods
    fn intrinsic(
        &mut self,
        intrinsic: &Self::Intrinsic,
        args: PoppedValues<'_>
    ) -> Result<Value, FaultKind>;
    fn step(&mut self) -> ExecutionBehavior;

    // Provided methods
    fn convert(&self, value: &Value, kind: &Symbol) -> Result<Value, FaultKind> { ... }
    fn convert_string(&self, value: &Value) -> Result<Value, FaultKind> { ... }
}
Expand description

Customizes the behavior of a virtual machine instance.

Required Associated Types§

source

type String: DynamicValue + for<'a> From<&'a str> + From<String>

The string type for this environment.

source

type Intrinsic: Clone + PartialEq + Display + Debug + FromStr

The intrinsics offered by this environment.

Required Methods§

source

fn intrinsic( &mut self, intrinsic: &Self::Intrinsic, args: PoppedValues<'_> ) -> Result<Value, FaultKind>

Evalutes the intrinsic operation with the provided arguments.

This is invoked when the virtual machine executes an Instruction::CallIntrinsic.

source

fn step(&mut self) -> ExecutionBehavior

Called once before each instruction is executed.

If ExecutionBehavior::Continue is returned, the next instruction will be exected.

If ExecutionBehavior::Pause is returned, the virtual machine is paused and a FaultOrPause::Pause is raised. If the execution is resumed, the first function call will be before executing the same instruction as the one when ExecutionBehavior::Pause was called.

Provided Methods§

source

fn convert(&self, value: &Value, kind: &Symbol) -> Result<Value, FaultKind>

Converts value to a custom type supported by the runtime.

The provided implementation supports the String type.

source

fn convert_string(&self, value: &Value) -> Result<Value, FaultKind>

Converts value to a Value containing an instance of Self::String.

The provided implementation supports the String type.

Implementations on Foreign Types§

source§

impl Environment for ()

§

type String = String

§

type Intrinsic = Noop

source§

fn intrinsic( &mut self, _intrinsic: &Self::Intrinsic, _args: PoppedValues<'_> ) -> Result<Value, FaultKind>

source§

fn step(&mut self) -> ExecutionBehavior

Implementors§

source§

impl<Env> Environment for Budgeted<Env>where Env: Environment,

§

type String = <Env as Environment>::String

§

type Intrinsic = <Env as Environment>::Intrinsic