rib-lang 0.0.5

Rib language: parser, typechecker, compiler, and interpreter for WebAssembly component (WIT) workflows
Documentation
pub use env::*;
pub use eval::*;
pub use interpreter_input::*;
pub use interpreter_result::*;
pub use literal::*;
pub use rib_function_invoke::*;
pub use rib_interpreter::*;
pub use rib_runtime_error::*;
pub use stack::*;

mod env;
mod eval;
mod instruction_cursor;
mod interpreter_input;
mod interpreter_result;
mod interpreter_stack_value;
mod literal;
mod rib_function_invoke;
mod rib_interpreter;
mod rib_runtime_error;
mod stack;

use crate::{DefaultWorkerNameGenerator, GenerateInstanceName, RibByteCode};
use std::sync::Arc;

pub async fn interpret(
    rib: RibByteCode,
    rib_input: RibInput,
    function_invoke: Arc<dyn RibComponentFunctionInvoke + Sync + Send>,
    generate_worker_name: Option<Arc<dyn GenerateInstanceName + Sync + Send>>,
) -> Result<RibResult, RibRuntimeError> {
    let mut interpreter = Interpreter::new(
        rib_input,
        function_invoke,
        generate_worker_name.unwrap_or_else(|| Arc::new(DefaultWorkerNameGenerator)),
    );
    interpreter.run(rib).await
}

// This function can be used for those the Rib Scripts
// where there are no side effecting function calls.
// It is recommended to use `interpret` over `interpret_pure` if you are unsure.
pub async fn interpret_pure(
    rib: RibByteCode,
    rib_input: RibInput,
    generate_worker_name: Option<Arc<dyn GenerateInstanceName + Sync + Send>>,
) -> Result<RibResult, RibRuntimeError> {
    let mut interpreter = Interpreter::pure(
        rib_input,
        generate_worker_name.unwrap_or_else(|| Arc::new(DefaultWorkerNameGenerator)),
    );
    interpreter.run(rib.clone()).await
}

#[macro_export]
macro_rules! internal_corrupted_state {
    ($fmt:expr) => {{
        $crate::interpreter::rib_runtime_error::RibRuntimeError::InvariantViolation($crate::interpreter::rib_runtime_error::InvariantViolation::InternalCorruptedState($fmt.to_string()))
    }};

    ($fmt:expr, $($arg:tt)*) => {{
        $crate::interpreter::rib_runtime_error::RibRuntimeError::InvariantViolation($crate::interpreter::rib_runtime_error::InvariantViolation::InternalCorruptedState(format!($fmt, $($arg)*)))
    }};
}

#[macro_export]
macro_rules! bail_corrupted_state {
    ($fmt:expr) => {{
        return Err($crate::interpreter::rib_runtime_error::RibRuntimeError::InvariantViolation($crate::interpreter::rib_runtime_error::InvariantViolation::InternalCorruptedState($fmt.to_string())));
    }};

    ($fmt:expr, $($arg:tt)*) => {{
        return Err($crate::interpreter::rib_runtime_error::RibRuntimeError::InvariantViolation($crate::interpreter::rib_runtime_error::InvariantViolation::InternalCorruptedState(format!($fmt, $($arg)*))));
    }};
}