Skip to main content

lasm/
lib.rs

1// #![doc = include_str!("../README.md")]
2#![doc = include_str!("../DOC.md")]
3
4#[cfg(all(feature = "llvm", feature = "cranelift"))]
5compile_error!("Features `llvm` and `cranelift` cannot be enabled at the same time");
6
7#[cfg(not(any(feature = "llvm", feature = "cranelift")))]
8compile_error!("You must enable exactly one of `llvm` or `cranelift` features");
9
10/// Internal macro to conditionally include items based on features
11macro_rules! feature_item {
12    ($($item:item)*) => {
13        $(
14            #[cfg(any(feature = "llvm", feature = "cranelift"))]
15            #[cfg(not(all(feature = "llvm", feature = "cranelift")))]
16            #[cfg_attr(doc, allow(dead_code))]
17            $item
18        )*
19    };
20}
21
22feature_item!(
23    use std::collections::HashMap;
24
25    mod error;
26    mod value;
27    mod target;
28    mod lasm_function;
29    mod compiler;
30    mod ast;
31    mod lexer;
32    mod parser;
33
34    pub use error::{LasmError, Location};
35    pub use value::Value;
36    pub use target::Target;
37    pub use lasm_function::LasmFunction;
38
39    /// Compile LASM source code into a LasmFunction for JIT or AOT execution.
40    ///
41    /// # Arguments
42    /// * `lasm` - The LASM source code as a string
43    /// * `target` - The target architecture and platform
44    ///
45    /// # Returns
46    /// A Result containing the compiled LasmFunction or an error
47    pub fn compile(lasm: &str, target: Target) -> Result<LasmFunction, LasmError> {
48        compiler::compile(lasm, target)
49    }
50
51    /// Execute a compiled LasmFunction with the given variables.
52    ///
53    /// # Arguments
54    /// * `function` - The compiled LasmFunction
55    /// * `variables` - Input variables as a HashMap
56    ///
57    /// # Returns
58    /// A Result containing the exit code and updated variables, or an error
59    pub fn call(
60        function: &LasmFunction,
61        variables: &HashMap<String, Value>,
62    ) -> Result<(i32, HashMap<String, Value>), LasmError> {
63        function.call(variables)
64    }
65
66    /// Constant to indicate if 'lucia-lasm' was compiled with LLVM support
67    pub const USES_LLVM: bool = cfg!(feature = "llvm");
68    /// Constant to indicate if 'lucia-lasm' was compiled with Cranelift support
69    pub const USES_CRANELIFT: bool = cfg!(feature = "cranelift");
70    /// Constant to indicate if 'lucia-lasm' was compiled with debug features enabled
71    pub const USES_DEBUG: bool = cfg!(feature = "dbg");
72);