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.initialize(BYTECODE.iter().copied()).unwrap();
38//! vm.run().unwrap();
39//!
40//! assert_eq!(vm.primitive_set().device().output(), b"Hello, world!");
41//! ```
42
43#![cfg_attr(all(doc, not(doctest)), feature(doc_auto_cfg))]
44#![no_std]
45
46#[cfg(any(feature = "alloc", test))]
47extern crate alloc;
48#[cfg(any(feature = "trace_instruction", test))]
49extern crate std;
50
51mod code;
52mod cons;
53mod error;
54mod exception;
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 memory::{Heap, Memory};
70pub use number::Number;
71pub use primitive_set::PrimitiveSet;
72pub use profiler::Profiler;
73pub use stack_slot::StackSlot;
74pub use r#type::Type;
75pub use value::Value;
76pub use vm::Vm;