Skip to main content

execute_value

Function execute_value 

Source
pub fn execute_value<P: Program>(
    program: P,
    context: &Context,
    options: &Options<'_>,
) -> Result<Execution, Stopped>
Expand description

Runs program over context as execute does, and also answers the value of its last expression statement: what its last pop discarded, or undefined when it popped nothing (Execution::value).

A run that stops answers a Stopped, exactly as execute’s does, with no value.

use predicator_rs::{Context, Instructions, Options, Value, execute_value};

// x = 2; x * 10
let program = Instructions::from_json(
    r#"[["lit","x"],["lit",2],["store",1],["load","x"],["lit",10],["multiply"],["pop"]]"#,
)?;
let execution = execute_value(&program, &Context::new(), &Options::new())?;
assert_eq!(execution.value(), Some(&Value::from(20)));