Skip to content

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 { TargetArch, FileType } from "lightvm";

const raw = [
  ['push', 5],
  ['val', 'x'],
  ['set', 'x'],
];
const optimized = tools.optimizeBytecode(raw);
vm.load(optimized)
  .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::types::{
  compile_config::CompileConfig,
  target_arch::TargetArch,
  file_type::FileType
};

let raw = r#"[
  ["push", 5],
  ["val", "x"],
  ["set", "x"]
]"#;
let optimized = tools.optimize_bytecode(raw);
vm.load(optimized.clone())
  .compile(CompileConfig {
    target_arch: TargetArch::AArch64,
    file_type: FileType::Binary,
    path: "./bin/output",
  });
rust
use lightvm::types::{
  compile_config::CompileConfig,
  target_arch::TargetArch,
  file_type::FileType
};

let raw = serde_json::json!([
  ["push", 5],
  ["val", "x"],
  ["set", "x"]
]);
let optimized = tools.optimize_bytecode(raw);
vm.load(optimized.clone())
  .compile(CompileConfig {
    target_arch: TargetArch::AArch64,
    file_type: FileType::Binary,
    path: "./bin/output",
  });

Target Architecture

Here is the compilation status for supported hardware architectures:

ArchitectureStatusCompile
AArch64nightly

File Type

Overview of the supported file formats used throughout the pipeline:

TypeDescription
AssemblyA human-readable textual representation of low-level machine instructions, serving as an intermediate step before final bytecode or machine code generation.
BinaryA compiled, machine-ready execution format consisting of raw bytes and opcodes designed for direct execution by the runtime or hardware.

INFO

Capability Required: Control