stak_vm/lib.rs
1//! A virtual machine and its runtime values.
2//!
3//! # Examples
4//!
5//! ```rust
6//! use stak_device::FixedBufferDevice;
7//! use stak_file::VoidFileSystem;
8//! use stak_macro::compile_r7rs;
9//! use stak_process_context::VoidProcessContext;
10//! use stak_r7rs::SmallPrimitiveSet;
11//! use stak_time::VoidClock;
12//! use stak_vm::Vm;
13//!
14//! const HEAP_SIZE: usize = 1 << 16;
15//! const BUFFER_SIZE: usize = 1 << 10;
16//!
17//! let mut heap = [Default::default(); HEAP_SIZE];
18//! let device = FixedBufferDevice::<BUFFER_SIZE, 0>::new(&[]);
19//! let mut vm = Vm::new(
20//! &mut heap,
21//! SmallPrimitiveSet::new(
22//! device,
23//! VoidFileSystem::new(),
24//! VoidProcessContext::new(),
25//! VoidClock::new(),
26//! ),
27//! )
28//! .unwrap();
29//!
30//! const BYTECODE: &[u8] = compile_r7rs!(
31//! r#"
32//! (import (scheme write))
33//!
34//! (display "Hello, world!")
35//! "#
36//! );
37//!
38//! vm.initialize(BYTECODE.iter().copied()).unwrap();
39//! vm.run().unwrap();
40//!
41//! assert_eq!(vm.primitive_set().device().output(), b"Hello, world!");
42//! ```
43
44#![cfg_attr(all(doc, not(doctest)), feature(doc_cfg))]
45#![no_std]
46
47#[cfg(test)]
48extern crate alloc;
49#[cfg(any(feature = "trace_instruction", test))]
50extern crate std;
51
52mod code;
53mod cons;
54mod error;
55mod exception;
56mod instruction;
57mod memory;
58mod number;
59mod primitive_set;
60mod profiler;
61mod stack_slot;
62mod r#type;
63mod value;
64mod value_inner;
65mod vm;
66
67pub use cons::{Cons, Tag};
68pub use error::Error;
69pub use exception::Exception;
70pub use memory::Memory;
71pub use number::Number;
72pub use primitive_set::PrimitiveSet;
73pub use profiler::Profiler;
74pub use stack_slot::StackSlot;
75pub use r#type::Type;
76pub use value::Value;
77pub use vm::Vm;