Skip to main content

hara_compiler/
lib.rs

1//! Full Hara compilation surface, kept outside VM-only deployments.
2
3pub use hara_vm::{Program, Value};
4pub use hara_wasm::vm::{compile_halc_module, compile_source, compile_source_with, CompileError};
5
6pub fn compile_bytecode(source: &str) -> Result<Vec<u8>, String> {
7    let program = compile_source(source).map_err(|error| error.to_string())?;
8    hara_wasm::vm::encode_program(&program)
9}
10
11#[cfg(feature = "full-wasm")]
12pub fn compile_wasm(source: &str) -> Result<Vec<u8>, String> {
13    let program = compile_source(source).map_err(|error| error.to_string())?;
14    hara_wasm::whole_wasm::compile_artifact(&program)
15}
16
17#[cfg(test)]
18mod tests {
19    #[test]
20    fn compiler_output_executes_in_vm_only_crate() {
21        let artifact = super::compile_bytecode("(+ 19 23)").unwrap();
22        assert_eq!(hara_vm::execute(&artifact).unwrap().display(), "42");
23    }
24}