Skip to main content

Crate bop_compile

Crate bop_compile 

Source
Expand description

AOT Bop → Rust transpiler.

transpile takes a Bop source string, parses it with bop-lang, and emits Rust source that links against bop-lang (for Value, operators, and language-level builtins) and optionally bop-sys (for the standard host).

The emitted code is intentionally human-readable: user-defined Bop functions become top-level Rust fns, the top-level program becomes run_program, and the main entry point drives it against [bop_sys::StandardHost]. Run the output with rustc or cargo build to produce a native binary.

§Scope (v1 starter)

Supported today:

  • All literals (numbers, strings, bools, none, arrays, dicts)
  • Binary / unary operators, including short-circuit && / ||
  • let, assign, compound assign on plain variables
  • if / else (both as statement and expression)
  • while, repeat, for x in ... (over arrays, ranges, or strings)
  • break, continue
  • Built-in function calls (print, range, str, int, type, abs, min, max, rand, len, inspect)
  • User-defined functions with recursion
  • Indexed reads (arr[i], dict[k], "str"[i])

Not yet emitted (tracked for follow-ups — the transpiler returns an error naming the missing feature):

  • Method calls (e.g. arr.push(1))
  • String interpolation ("hi {name}")
  • Indexed writes (arr[i] = val, arr[i] += 1)
  • BopLimits sandbox mode (step / memory enforcement in the emitted code)

Structs§

Options
Options that control the shape of the emitted Rust.

Functions§

modules_from_map
Build a ModuleResolver from an in-memory name→source map. Convenience for tests and simple embedders.
transpile
Parse Bop source and emit the equivalent Rust source.
transpile_ast
Lower-level entry point: emit Rust from an already-parsed AST.

Type Aliases§

ModuleResolver
A compile-time module resolver. The AOT runs this eagerly for every use it encounters, threading the entire module graph into the generated Rust. Same contract as bop::BopHost::resolve_module: None = not handled, Some(Ok(source)) = module source text, Some(Err(_)) = resolver failure.