1pub use env::*;
2pub use eval::*;
3pub use interpreter_input::*;
4pub use interpreter_result::*;
5pub use literal::*;
6pub use rib_function_invoke::*;
7pub use rib_interpreter::*;
8pub use rib_runtime_error::*;
9pub use stack::*;
10
11mod env;
12mod eval;
13mod instruction_cursor;
14mod interpreter_input;
15mod interpreter_result;
16mod interpreter_stack_value;
17mod literal;
18mod rib_function_invoke;
19mod rib_interpreter;
20mod rib_runtime_error;
21mod stack;
22
23use crate::{DefaultWorkerNameGenerator, GenerateInstanceName, RibByteCode};
24use std::sync::Arc;
25
26pub async fn interpret(
27 rib: RibByteCode,
28 rib_input: RibInput,
29 function_invoke: Arc<dyn RibComponentFunctionInvoke + Sync + Send>,
30 generate_worker_name: Option<Arc<dyn GenerateInstanceName + Sync + Send>>,
31) -> Result<RibResult, RibRuntimeError> {
32 let mut interpreter = Interpreter::new(
33 rib_input,
34 function_invoke,
35 generate_worker_name.unwrap_or_else(|| Arc::new(DefaultWorkerNameGenerator)),
36 );
37 interpreter.run(rib).await
38}
39
40pub async fn interpret_pure(
44 rib: RibByteCode,
45 rib_input: RibInput,
46 generate_worker_name: Option<Arc<dyn GenerateInstanceName + Sync + Send>>,
47) -> Result<RibResult, RibRuntimeError> {
48 let mut interpreter = Interpreter::pure(
49 rib_input,
50 generate_worker_name.unwrap_or_else(|| Arc::new(DefaultWorkerNameGenerator)),
51 );
52 interpreter.run(rib.clone()).await
53}
54
55#[macro_export]
56macro_rules! internal_corrupted_state {
57 ($fmt:expr) => {{
58 $crate::interpreter::rib_runtime_error::RibRuntimeError::InvariantViolation($crate::interpreter::rib_runtime_error::InvariantViolation::InternalCorruptedState($fmt.to_string()))
59 }};
60
61 ($fmt:expr, $($arg:tt)*) => {{
62 $crate::interpreter::rib_runtime_error::RibRuntimeError::InvariantViolation($crate::interpreter::rib_runtime_error::InvariantViolation::InternalCorruptedState(format!($fmt, $($arg)*)))
63 }};
64}
65
66#[macro_export]
67macro_rules! bail_corrupted_state {
68 ($fmt:expr) => {{
69 return Err($crate::interpreter::rib_runtime_error::RibRuntimeError::InvariantViolation($crate::interpreter::rib_runtime_error::InvariantViolation::InternalCorruptedState($fmt.to_string())));
70 }};
71
72 ($fmt:expr, $($arg:tt)*) => {{
73 return Err($crate::interpreter::rib_runtime_error::RibRuntimeError::InvariantViolation($crate::interpreter::rib_runtime_error::InvariantViolation::InternalCorruptedState(format!($fmt, $($arg)*))));
74 }};
75}