LASM - Lucia Assembly Language
LASM (Lucia Assembly) is a Rust crate that provides JIT (Just-In-Time) compilation of a custom register-based assembly language into native machine code.
It is primarily designed to serve as a high-performance execution backend for interpreted or scripting programming languages, allowing them to JIT-compile performance-critical parts of the code at runtime.
Key Features
- JIT using either Cranelift or LLVM backends
- Seamless variable bridge - easily read/write variables between the host language and LASM code
- Modern, clean assembly syntax with high-level syscalls
- 64-bit register-based architecture (x86_64 + AArch64 support)
- Meant to be embedded into interpreters / VMs / scripting runtimes
Why LASM?
Many interpreted languages suffer from performance bottlenecks in hot loops, math-heavy code, or data processing.
LASM is intended that the language designer exposes LASM compiling and calling to the language and then the users of the language can:
- Compile LASM code into abstracted out identifiers
- Call these abstracted out identifiers and get the output
- Interact between language variables and values from lasm
- Run heavy loops or calculations from native JIT code for faster execution
If you want to see an example of how LASM is integrated into a scripting language, see Lucia and it's LASM library
Backend Selection (Cargo Features)
LASM requires exactly one code-generation backend to be enabled:
[]
= { = "2", = false, = ["cranelift"], = "lucia-lasm" }
# or
= { = "2", = false, = ["llvm"], = "lucia-lasm" }
Available features:
cranelift- uses Cranelift (fast compilation, good runtime performance, smaller dependency footprint)
(this is the default when no features are specified)llvm- uses LLVM via theinkwellcrate (potentially better optimizations, larger & slower compilation, requiresllvm-17installed)dbg- enables extra debug checks, instruction tracing, and validation (makes execution significantly slower - only for development)
Important:
If neither cranelift nor llvm is enabled -> compile-time error
If both are enabled -> compile-time error
Installation
[]
= { = "2", = "lucia-lasm" }
As an executable:
Basic Embedding Example
use ;
use HashMap;
Architecture & Highlights
- Registers: r0–r15 (64-bit), rsp, rbp
- Variable bridge:
load "name", reg- read from hostpush reg, "name"- write to host
- Float operations:
fadd,fsub,fmul, ... - High-level syscalls:
print_int,malloc,strcmp,time,rand,sleep, ... - Control flow:
beq,bne,blt,call/ret, labels - Supported types (via
Valueenum):Int,Float,String,Ptr,Null
Current Status
- Compiling for not Native target is not supported yet.
- Cranelift backend is more lightweight and faster to compile lasm functions, slower to compile crate.
- LLVM backend may give better peak performance on complex code (but slower compilation of lasm functions)
dbgfeature is useful during language development but hurts performance
License
See LICENSE