Compile Method
After initializing the VM and setting up your environment, you can process and compile your bytecode configuration into a target binary.
Using TypeScript
For TypeScript, you can pass raw instruction arrays directly to the loader, apply optimization tools, and set up your compilation configurations seamlessly.
ts
import { Capability, FileType, LightVM, TargetArch } from 'lightvm';
const vm = new LightVM({ caps: [Capability.Control] });
const tools = vm.tools();
const raw = [
['push', 5],
['val', 'x'],
['set', 'x'],
['get', 'x'],
['println'],
];
const optimized = tools.optimizeBytecode(raw);
vm.load(optimized);
vm.compile({
targetArch: TargetArch.AArch64,
fileType: FileType.Binary,
path: './bin/output',
});Using Rust
In Rust, you typically work with raw instruction strings, optimize them using the helper tools, and pass a CompileConfig struct containing your TargetArch and FileType directly into the .compile() method.
rust
use lightvm::LightVM;
use lightvm::types::{
vmconfig::VmConfig,
capability::Capability,
compile_config::CompileConfig,
target_arch::TargetArch,
file_type::FileType
};
fn main() {
let vm = LightVM::new(VmConfig {
caps: vec![Capability::Control],
..Default::default()
});
let tools = vm.tools();
let raw = r#"[
["push", 5],
["val", "x"],
["set", "x"],
["get", "x"],
["println"]
]"#;
let optimized = tools.optimize_bytecode(raw);
vm.load(optimized.clone());
vm.compile(CompileConfig {
target_arch: TargetArch::AArch64,
file_type: FileType::Binary,
path: "./bin/output",
});
}rust
use lightvm::LightVM;
use lightvm::types::{
vmconfig::VmConfig,
capability::Capability,
compile_config::CompileConfig,
target_arch::TargetArch,
file_type::FileType
};
fn main() {
let vm = LightVM::new(VmConfig {
caps: vec![Capability::Control],
..Default::default()
});
let tools = vm.tools();
let raw = serde_json::json!([
["push", 5],
["val", "x"],
["set", "x"],
["get", "x"],
["println"]
]);
let optimized = tools.optimize_bytecode(raw);
vm.load(optimized.clone());
vm.compile(CompileConfig {
target_arch: TargetArch::AArch64,
file_type: FileType::Binary,
path: "./bin/output",
});
}Target Architecture
Here is the compilation status for supported hardware architectures:
| Architecture | Status | Compile |
|---|---|---|
AArch64 | nightly | ✓ |
File Type
Overview of the supported file formats used throughout the pipeline:
| Type | Description |
|---|---|
Assembly | A human-readable textual representation of low-level machine instructions, serving as an intermediate step before final bytecode or machine code generation. |
Binary | A compiled, machine-ready execution format consisting of raw bytes and opcodes designed for direct execution by the runtime or hardware. |
INFO
Capability Required: Control