Crate stak_vm

Source
Expand description

A virtual machine and its runtime values.

§Examples

use stak_device::FixedBufferDevice;
use stak_file::VoidFileSystem;
use stak_macro::compile_r7rs;
use stak_process_context::VoidProcessContext;
use stak_r7rs::SmallPrimitiveSet;
use stak_time::VoidClock;
use stak_vm::Vm;

const HEAP_SIZE: usize = 1 << 16;
const BUFFER_SIZE: usize = 1 << 10;

let mut heap = [Default::default(); HEAP_SIZE];
let device = FixedBufferDevice::<BUFFER_SIZE, 0>::new(&[]);
let mut vm = Vm::new(
    &mut heap,
    SmallPrimitiveSet::new(
        device,
        VoidFileSystem::new(),
        VoidProcessContext::new(),
        VoidClock::new(),
    ),
)
.unwrap();

const BYTECODE: &[u8] = compile_r7rs!(
    r#"
    (import (scheme write))

    (display "Hello, world!")
    "#
);

vm.initialize(BYTECODE.iter().copied()).unwrap();
vm.run().unwrap();

assert_eq!(vm.primitive_set().device().output(), b"Hello, world!");

Structs§

Cons
A cons.
Memory
A memory on a virtual machine.
Number
A number.
Value
A value.
Vm
A virtual machine.

Enums§

Error
An error of a virtual machine.
StackSlot
A tag of a stack slot.
Type
A type in Scheme.

Traits§

Exception
An exception.
PrimitiveSet
A primitive set.
Profiler
A profiler.

Type Aliases§

Tag
A tag.