mstak 0.3.14

Minimal Stak Scheme interpreter
mstak-0.3.14 is not a library.

Stak Scheme

GitHub Action Crate Codecov License

The miniature, embeddable R7RS Scheme implementation in Rust

The full documentation is here.

Install

Library

To install Stak Scheme as a library in your Rust project, run:

cargo add stak

Command line tools

To install the Scheme interpreter and alike as command line tools, run:

# Install the Scheme interpreter.
cargo install stak

# Install the minimal Scheme interpreter (6 times smaller!)
cargo install mstak

# Install the Scheme-to-bytecode compiler and bytecode interpreter.
cargo install stak-compile
cargo install stak-interpret

Examples

Running a Scheme script

use core::error::Error;
use stak::{
    build::include_bytecode,
    device::StdioDevice,
    file::VoidFileSystem,
    process_context::VoidProcessContext,
    r7rs::{SmallError, SmallPrimitiveSet},
    time::VoidClock,
    vm::Vm,
};

const HEAP_SIZE: usize = 1 << 16;
const BYTECODES: &[u8] = include_bytecode!("hello.scm");

fn main() -> Result<(), Box<dyn Error>> {
    run(BYTECODES)?;

    Ok(())
}

fn run(bytecodes: &[u8]) -> Result<(), SmallError> {
    let mut heap = [Default::default(); HEAP_SIZE];
    let mut vm = Vm::new(
        &mut heap,
        SmallPrimitiveSet::new(
            StdioDevice::new(),
            VoidFileSystem::new(),
            VoidProcessContext::new(),
            VoidClock::new(),
        ),
    )?;

    vm.initialize(bytecodes.iter().copied())?;
    vm.run()
}

License

MIT