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(
15                all(feature="llvm", not(feature="cranelift")),
16                all(feature="cranelift", not(feature="llvm"))
17            ))]
18            #[cfg(any(feature="llvm", feature="cranelift", doc))]
19            $item
20        )*
21    };
22}
23
24feature_item!(
25    use std::collections::HashMap;
26
27    mod error;
28    mod value;
29    mod target;
30    mod lasm_function;
31    mod compiler;
32    mod ast;
33    mod lexer;
34    mod parser;
35
36    pub use error::{LasmError, Location};
37    pub use value::Value;
38    pub use target::Target;
39    pub use lasm_function::LasmFunction;
40
41    /// Compile LASM source code into a LasmFunction for JIT or AOT execution.
42    ///
43    /// # Arguments
44    /// * `lasm` - The LASM source code as a string
45    /// * `target` - The target architecture and platform
46    ///
47    /// # Returns
48    /// A Result containing the compiled LasmFunction or an error
49    pub fn compile(lasm: &str, target: Target) -> Result<LasmFunction, LasmError> {
50        compiler::compile(lasm, target)
51    }
52
53    /// Execute a compiled LasmFunction with the given variables.
54    ///
55    /// # Arguments
56    /// * `function` - The compiled LasmFunction
57    /// * `variables` - Mutable reference to a `HashMap` of input variables;
58    ///                 updated in place with the output variables after execution
59    ///
60    /// # Returns
61    /// A Result containing the exit code, or an error
62    pub fn call(
63        function: &LasmFunction,
64        variables: &mut HashMap<String, Value>,
65    ) -> Result<i32, LasmError> {
66        function.call(variables)
67    }
68
69    /// Constant for the current version of 'lucia-lasm'
70    pub const VERSION: &str = env!("CARGO_PKG_VERSION");
71    /// Constant to indicate if 'lucia-lasm' was compiled with LLVM support
72    pub const USES_LLVM: bool = cfg!(feature = "llvm");
73    /// Constant to indicate if 'lucia-lasm' was compiled with Cranelift support
74    pub const USES_CRANELIFT: bool = cfg!(feature = "cranelift");
75    /// Constant to indicate if 'lucia-lasm' was compiled with debug features enabled
76    pub const USES_DEBUG: bool = cfg!(feature = "dbg");
77);