Skip to main content

Crate luna_aot

Crate luna_aot 

Source
Expand description

luna-aot — ahead-of-time compiler from Lua source to a self-contained native binary.

§Scaffold pipeline (bytecode embed)

  1. CLI cli::run / library embed::embed_bytecode take a .lua source file.
  2. luna-core’s frontend parses + compiles it to bytecode (a luna_core::runtime::Proto tree).
  3. The bytecode is dumped via luna_core::vm::dump (luna’s own body format — "\x1bLua" + version-byte header + the "\x00LunaV1\x00" sentinel + luna body).
  4. The dump bytes are written into a .luna.bytecode section of an ELF / Mach-O / PE object file via object::write::Object, bracketed by two public symbols __luna_bytecode_start and __luna_bytecode_end that the runtime stub (or a custom host binary) extern "C"s.
  5. The CLI invokes system cc to link the bytecode object + a minimal C entry point into a final executable. The default scaffold entry just prints the embedded bytecode length to stderr and exits — proving the section is reachable end-to-end.

§Why a separate crate

This crate pulls object + clap and all of cranelift; embedders who only want the runtime JIT keep using luna-jit, and embedders who only want pure interp keep using luna-core — both stay free of luna-aot’s build-time dep tree.

luna-core 0-third-party-dep contract is unaffected. This crate depends on luna-core but luna-core does not depend on anything here. The CI gate (cargo tree -p luna-core --prefix none | grep -cE " v[0-9]") continues to report 1.

Modules§

cli
luna-aot CLI surface — clap-derive. Sub-commands:
embed
The AOT pipeline: parse + compile Lua source → dump luna bytecode → embed into an object file’s .luna.bytecode data section → link.
runtime_stub
The Rust runtime stub that the AOT-produced binary calls at process start. This module is library code today: the scaffold’s linked binary uses a tiny C main (see crate::embed) that prints the bytecode length. Swapping that C entry out for this Rust stub makes the binary run the embedded bytecode through a Vm.

Constants§

BYTECODE_END_SYMBOL
Symbol name marking the end of the embedded bytecode section. External (C-ABI) symbol; the runtime stub declares it as extern "C" { static __luna_bytecode_end: u8; } and computes the length as (&end as *const u8).offset_from(&start as *const u8).
BYTECODE_SECTION_NAME
Object-file section name for the embedded bytecode. ELF/Mach-O conventions: a leading dot is the standard for non-loader- special sections; we pick .luna.bytecode so objdump -s -j .luna.bytecode <out> displays the dump bytes for inspection.
BYTECODE_START_SYMBOL
Symbol name marking the start of the embedded bytecode section. External (C-ABI) symbol; the runtime stub declares it as extern "C" { static __luna_bytecode_start: u8; }.