Skip to main content

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 device = FixedBufferDevice::<BUFFER_SIZE, 0>::new(&[]);
18//! let mut vm = Vm::new(
19//!     [Default::default(); HEAP_SIZE],
20//!     SmallPrimitiveSet::new(
21//!         device,
22//!         VoidFileSystem::new(),
23//!         VoidProcessContext::new(),
24//!         VoidClock::new(),
25//!     ),
26//! )
27//! .unwrap();
28//!
29//! const BYTECODE: &[u8] = compile_r7rs!(
30//!     r#"
31//!     (import (scheme write))
32//!
33//!     (display "Hello, world!")
34//!     "#
35//! );
36//!
37//! vm.run(BYTECODE.iter().copied()).unwrap();
38//!
39//! assert_eq!(vm.primitive_set().device().output(), b"Hello, world!");
40//! ```
41
42#![cfg_attr(all(doc, not(doctest)), feature(doc_cfg))]
43#![no_std]
44
45#[cfg(test)]
46extern crate alloc;
47#[cfg(any(feature = "trace_instruction", test))]
48extern crate std;
49
50mod code;
51mod cons;
52mod error;
53mod exception;
54mod heap;
55mod instruction;
56mod memory;
57mod number;
58mod primitive_set;
59mod profiler;
60mod stack_slot;
61mod r#type;
62mod value;
63mod value_inner;
64mod vm;
65
66pub use cons::{Cons, Tag};
67pub use error::Error;
68pub use exception::Exception;
69pub use heap::Heap;
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;