Skip to main content

Crate lehit

Crate lehit 

Source
Expand description

Experimental Lehit language frontend and embeddable Cranelift JIT runtime.

§Quick start

Checked execution is the recommended host-facing mode because instrumented runtime failures are returned as structured errors instead of backend traps.

use lehit::runtime::{ExecutionMode, RuntimeBuilder};

let mut runtime = RuntimeBuilder::new()
    .with_execution_mode(ExecutionMode::Checked)
    .build()?;

runtime.load_script(
    "app://entry.lt",
    "as fn(argument: usize) -> i32
     let values: [i32; 2] = [11, 22] return values[argument]",
)?;
let function = runtime.function("app://entry.lt", "")?.abi_function()?;
let mut call = function.abi_call_builder();
call.push_rust_value_argument(1usize)?;
assert_eq!(call.call()?.into_rust_value::<i32>()?, 22);

let mut call = function.abi_call_builder();
call.push_rust_value_argument(3usize)?;
assert!(matches!(
    call.call(),
    Err(lehit::runtime::AbiCallError::Execution(status))
        if status == lehit::runtime::AbiCallStatus::BOUNDS_VIOLATION
));

§Choosing an API

  • runtime is the supported embedding and execution facade.
  • rust_lib and LehitRegistration register trusted native Rust code.
  • parsing::parse_file is the source-level frontend entry point.
  • semantic exposes the experimental compiler passes and typed IR.
  • core_lib exposes the embedded core:// source modules.
  • guides contains the long-form documentation rendered on docs.rs.

§Status and trust model

The project is pre-release and is not a sandbox. Checked execution only covers failures explicitly instrumented by codegen; native pointers, custom layouts, allocator callbacks, and aggregate byte validity remain trusted-host responsibilities. Read guides::safety before using native integration.

Modules§

core_lib
Embedded core:// source modules.
guides
Long-form guides rendered directly in docs.rs navigation. Long-form documentation rendered as part of the docs.rs navigation.
parsing
Source-level frontend: lexer, grammar, AST, spans, and parse diagnostics.
prelude
Common imports for host applications using the high-level runtime API.
runtime
High-level runtime facade for loading, executing, reloading, and diagnosing Lehit modules.
rust_lib
Declarative integration model for modules, types, and functions supplied by a Rust host.
semantic
Semantic frontend: declarations, modules, types, methods, body analysis, and typed IR.

Macros§

core_namespace

Derive Macros§

LehitRegistration
Derives native registration metadata for a concrete struct or enum.