#compiler #aot

bop-compile

Ahead-of-time Bop to Rust source transpiler

1 unstable release

Uses new Rust 2024

0.3.0 Apr 21, 2026

#49 in #aot


Used in bop-cli

MIT/Apache

735KB
16K SLoC

bop-compile

Ahead-of-time Bop → Rust transpiler.

Given Bop source, bop-compile::transpile produces a human-readable Rust source file that links against bop-lang and bop-sys and compiles via cargo to a native binary. The fastest of Bop's three engines.

When to reach for the AOT

  • Scripts you'll run repeatedly — builds once, runs at native speed forever after.
  • Performance-sensitive workloads — where even the bytecode VM's 2–3× speedup isn't enough.
  • Deploying a script as a self-contained binarybop compile script.bop and ship the resulting executable.

For scripts you compile at the host's runtime, the bytecode VM in bop-vm is the right choice instead — AOT needs rustc on the target machine, which embedded hosts typically can't rely on.

CLI usage (the common path)

Most users never call bop-compile directly; they use bop-cli:

bop compile script.bop          # → ./script (native binary)
bop compile script.bop -o app   # → ./app
bop compile --emit-rs script.bop -o script.rs   # transpile only

Library usage

When you want to wire the transpiler into your own build pipeline (a build.rs, a custom tool, a CI job):

[dependencies]
bop-compile = "0.3"
use bop_compile::{transpile, Options};

let rust_source = transpile(
    r#"print("hello from bop")"#,
    &Options::default(),
)?;
// write rust_source to src/main.rs and run `cargo build`…

Options controls the output shape: standalone program vs. library, module name wrapping, sandbox mode for step/memory enforcement, and the module resolver callback for use statements.

Selling points

  • Native-speed scripts. The transpiled output is ordinary Rust — rustc optimises it the same way it optimises hand-written code.
  • Human-readable output. User-defined Bop functions become top-level Rust fns with reasonable names, so the generated code is debuggable.
  • Same semantics as walker + VM. The three-engine differential suite exercises hundreds of programs to catch any behavioural drift.
  • Same BopHost surface. The generated binary uses bop-sys::StdHost by default, so your custom hosts work without changes.

Features

feature default what it does
bop-std yes forwards to bop-lang's bop-std feature (bundles the Bop stdlib). Turn off with default-features = false when building a truly minimal AOT pipeline.
  • bop-lang — the language core the generated code depends on
  • bop-sys — the standard host the generated main() wires up
  • bop-cli — the bop compile command-line driver
  • bop-vm — bytecode VM, for when you need speed at the host's runtime rather than AOT

License

Dual-licensed under MIT or Apache 2.0, at your option.

Dependencies