bop-lang 0.3.0

A small, embeddable, dynamically-typed programming language with zero dependencies
Documentation
  • Coverage
  • 40.59%
    207 out of 510 items documented1 out of 194 items with examples
  • Size
  • Source code size: 597.53 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 25.73 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 31s Average build duration of successful builds.
  • all releases: 41s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • stevepryde/bop-lang
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • stevepryde

bop-lang

The core of Bop — a small, dynamically-typed, embeddable scripting language for Rust applications.

Hand your users or your AI a real programming language at runtime, without shipping a compiler to the target machine.

Note: Bop is experimental and not yet battle-tested. Fine for tooling, scripting, and embedding experiments; use with care in production.

What's in this crate

bop-lang is the language core:

  • Lexer + parser producing a typed AST
  • Tree-walking interpreter (bop::run) — simplest runtime, works everywhere
  • BopHost trait — the only thing embedders need to implement to wire Bop into their Rust app
  • Value type + builtin operators — the shared runtime surface every Bop engine uses
  • Resource limits (BopLimits) — step count and memory caps for safe sandboxing

For a faster runtime (2–3× this crate's tree-walker, same semantics), add bop-vm. For an AOT path to native Rust, see bop-compile.

Selling points

  • Embeddable. One trait (BopHost) to implement; everything else is handled by the engine.
  • Zero Rust deps Nothing to audit in your supply chain.
  • no_std support via the no_std feature (uses the libm crate internally for float math, nothing else).
  • WASM-compatible. Builds clean for wasm32-unknown-unknown. Use it in browsers, edge workers, or wherever you can run Rust.
  • Sandboxed by default. BopLimits caps step count and memory so a runaway user script can't hang or OOM your process.

Quick start

[dependencies]
bop-lang = "0.3"
use bop::{run, BopError, BopHost, BopLimits, Value};

struct MyHost;

impl BopHost for MyHost {
    fn call(&mut self, name: &str, _args: &[Value], _line: u32)
        -> Option<Result<Value, BopError>>
    {
        // Return Some(Ok(...)) to handle a custom function call,
        // Some(Err(...)) to raise, None to defer to builtins.
        match name {
            "greet" => Some(Ok(Value::new_str("hello!".to_string()))),
            _ => None,
        }
    }

    fn on_print(&mut self, msg: &str) {
        println!("{msg}");
    }
}

fn main() {
    let mut host = MyHost;
    let limits = BopLimits::standard();
    run(r#"print(greet())"#, &mut host, &limits).unwrap();
}

Features

feature default what it does
bop-std yes bundles the Bop stdlib (use std.math, std.json, std.collections, std.iter, std.string, std.test) as &'static str constants reachable via [bop::stdlib::resolve]
no_std no opt in for bare-metal / embedded / edge wasm targets. Pulls in libm for float math. Enable with default-features = false, features = ["no_std"] (add "bop-std" too if you want the bundled stdlib on those targets).

A truly minimal build — core language only, no bundled stdlib:

bop-lang = { version = "0.3", default-features = false }

WASM example

[dependencies]
bop-lang = { version = "0.3", default-features = false, features = ["no_std", "bop-std"] }

Build for wasm32-unknown-unknown as usual. See bop-vm for the faster runtime if you need it.

Related crates

  • bop-vm — bytecode compiler + VM, 2–3× faster than this crate's walker, same API
  • bop-compile — AOT Bop → Rust transpiler for native-speed scripts
  • bop-sys — ready-made StdHost with filesystem / stdio / env / time
  • bop-cli — the bop command-line tool (bop run, bop compile, REPL)

License

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