stak_vm/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
//! A virtual machine and its runtime values.
//!
//! # Examples
//!
//! ```rust
//! 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 PROGRAM: &[u8] = compile_r7rs!(r#"
//! (import (scheme write))
//!
//! (display "Hello, world!")
//! "#);
//!
//! vm.initialize(PROGRAM.iter().copied()).unwrap();
//! vm.run().unwrap();
//!
//! assert_eq!(vm.primitive_set().device().output(), b"Hello, world!");
//! ```
#![no_std]
#[cfg(test)]
extern crate alloc;
#[cfg(any(feature = "trace_instruction", test))]
extern crate std;
mod code;
mod cons;
mod error;
mod instruction;
mod memory;
mod number;
mod primitive_set;
mod profiler;
mod stack_slot;
mod r#type;
mod value;
mod vm;
pub use cons::{Cons, Tag};
pub use error::Error;
pub use memory::Memory;
pub use number::{Number, NumberRepresentation};
pub use primitive_set::PrimitiveSet;
pub use profiler::Profiler;
pub use r#type::Type;
pub use stack_slot::StackSlot;
pub use value::Value;
pub use vm::Vm;