lasm/
lib.rs

1#![doc = include_str!("../README.md")]
2use std::collections::HashMap;
3
4pub mod error;
5pub mod value;
6pub mod target;
7pub mod lasm_function;
8pub mod compiler;
9pub mod ast;
10pub mod lexer;
11pub mod parser;
12
13pub use error::{LasmError, Location};
14pub use value::Value;
15pub use target::Target;
16pub use lasm_function::LasmFunction;
17
18
19/// Compile LASM source code into a LasmFunction for JIT or AOT execution.
20///
21/// # Arguments
22/// * `lasm` - The LASM source code as a string
23/// * `target` - The target architecture and platform
24///
25/// # Returns
26/// A Result containing the compiled LasmFunction or an error
27pub fn compile(
28    lasm: &str,
29    target: Target
30) -> Result<LasmFunction, LasmError> {
31    compiler::compile(lasm, target)
32}
33
34/// Execute a compiled LasmFunction with the given variables.
35///
36/// # Arguments
37/// * `function` - The compiled LasmFunction
38/// * `variables` - Input variables as a HashMap
39///
40/// # Returns
41/// A Result containing the exit code and updated variables, or an error
42pub fn call(
43    function: &LasmFunction,
44    variables: &HashMap<String, Value>
45) -> Result<(i32, HashMap<String, Value>), LasmError> {
46    function.call(variables)
47}