amvm 0.1.0

Apika's My Virtual Machine. A virtual machine with Intermediate Lenguage
Documentation
use crate::runtime::{expr, scope, AmvmResult};
use crate::{AmvmScope, Command, CommandExpression, Value};

pub fn eval(
    scope: &mut AmvmScope,
    condition: &CommandExpression,
    body: &Vec<Command>,
    otherwise: &Option<Vec<Command>>,
) -> AmvmResult {
    let condition = expr::eval(scope, condition)?;
    let Value::Bool(condition) = condition else {
        return Ok(Value::Null);
    };

    if condition {
        scope::eval(scope, body)
    } else if let Some(otherwise) = otherwise {
        scope::eval(scope, otherwise)
    } else {
        Ok(Value::Null)
    }
}