Expand description
Bytecode artifact format (.cdlb) and the VM-only load/run API.
This mirrors an AOT model: the full candela toolchain (compiler + VM)
compiles a .cdl source to a compact, self-contained bytecode artifact
(ProgramImage serialized via serialize_image), and the VM-only
candela-vm binary loads it (load_program) and runs it
(RuntimeProgram::run) WITHOUT the parser, compiler, or REPL.
An embedding host gets the same two halves the Engine/Program pair
gives it, minus the compiler: it supplies a HostRegistry at load so the
artifact’s host functions bind to Rust closures, and it invokes script
functions by name through RuntimeProgram::call, which runs a trampoline
the compiler emitted at build time.
The on-disk format is: a 4-byte magic (CDLB), a 1-byte format version, then
a postcard-encoded ProgramImage. postcard was chosen over bincode
because it is no_std/alloc-friendly and its varint encoding keeps the
artifact small; it also pulls in the least code, which matters for the
candela-vm binary-size budget.
ProgramImage carries pub fields so the candela crate’s build
subcommand can populate it from a fresh compile; everything needed to LOAD
and RUN it lives here.
Structs§
- DefImage
- The type of one value an instruction writes.
- DynLib
FnImage - Serializable recipe for one dynamic-library binding: enough to re-open the library and re-resolve the symbol by name at load, with no embedded bytes.
- Enum
Image - Enum
Variant Image - Export
Image - One host-callable function, with the call trampoline
candela buildcompiled for it. - Function
Image - One compiled function in a
FunctionTable:main, or one specialisation of a declared function or closure. - Function
Table - What the compiler knows about each function of a program, written after
the
ProgramImagein a.cdlb. - Host
FnImage - Serializable recipe for one
hostfunction: its fully-qualified name and marshalling signature, so an embedding runtime can re-bind it by name. - Instr
SrcImage - Native
Function Image - One function in a
NativeImage. - Native
Image - Machine code
candela buildgenerated for one kind of machine, and what the VM needs to know to run it. - Native
Site Image - A call instruction the VM points at a native function once it loads.
- Program
Image - Serializable mirror of a compiled program’s runtime state.
- Runtime
Program - A loaded, ready-to-run program image with owned runtime state.
- Source
Image - Struct
Image
Enums§
- Call
Error - Why a
RuntimeProgram::calldid not produce a value. - Load
Error - Why a
.cdlbartifact could not be loaded. - Native
Arch - An architecture machine code is built for.
- Native
Os - An operating system whose calling convention machine code follows.
Functions§
- load_
program - Loads a
.cdlbbytecode artifact into a runnableRuntimeProgram. - read_
artifact - Reads a
.cdlbback into its image and the function table that follows it, for a tool that works on the program rather than runs it. The table isNonefor an artifact written without one. - serialize_
image - Serializes a
ProgramImageto.cdlbbytes (magic + version + body), followed by the function table when there is one.
Type Aliases§
- Data
Words - The pair of words a value is recorded as. See
Data::into_words.