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 instruction;
55mod memory;
56mod number;
57mod primitive_set;
58mod profiler;
59mod stack_slot;
60mod r#type;
61mod value;
62mod value_inner;
63mod vm;
64
65pub use cons::{Cons, Tag};
66pub use error::Error;
67pub use exception::Exception;
68pub use memory::{Heap, Memory};
69pub use number::Number;
70pub use primitive_set::PrimitiveSet;
71pub use profiler::Profiler;
72pub use stack_slot::StackSlot;
73pub use r#type::Type;
74pub use value::Value;
75pub use vm::Vm;