rib/interpreter/
mod.rs

1// Copyright 2024-2025 Golem Cloud
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15pub use crate::interpreter::env::*;
16pub use crate::interpreter::rib_interpreter::*;
17pub use crate::interpreter::stack::*;
18pub use interpreter_input::*;
19pub use interpreter_result::*;
20pub use literal::*;
21pub use rib_function_invoke::*;
22
23use std::sync::Arc;
24
25use crate::RibByteCode;
26
27mod env;
28mod instruction_cursor;
29mod interpreter_input;
30mod interpreter_result;
31mod interpreter_stack_value;
32mod literal;
33mod rib_function_invoke;
34mod rib_interpreter;
35mod stack;
36mod tests;
37
38pub async fn interpret(
39    rib: &RibByteCode,
40    rib_input: &RibInput,
41    function_invoke: Arc<dyn RibFunctionInvoke + Sync + Send>,
42) -> Result<RibResult, String> {
43    let mut interpreter = Interpreter::new(rib_input, function_invoke, None, None);
44    interpreter.run(rib.clone()).await
45}
46
47// This function can be used for those the Rib Scripts
48// where there are no side effecting function calls.
49// It is recommended to use `interpret` over `interpret_pure` if you are unsure.
50pub async fn interpret_pure(rib: &RibByteCode, rib_input: &RibInput) -> Result<RibResult, String> {
51    let mut interpreter = Interpreter::pure(rib_input, None, None);
52    interpreter.run(rib.clone()).await
53}