Expand description
A safe, dynamically-typed virtual machine
This crate provides a stack-based virtual machine that can be used to implement dynamically typed languages. Bud is the language that this crate was originally designed for.
Safety
This crate uses #[forbid(unsafe_code)]
and has no external dependencies. The
only unsafe code blocks are located within Rust’s standard library. Any panics
encountered should be considered a bug and reported.
How to use
Bud can be used as a complete example of how to build a language and REPL with this crate. There are two simpler examples demonstrating a recursive fibonacci number function:
- fib-vm: Implemented using virtual machine instructions.
- fib-ir: Implemented using intermediate representation (IR) with conveniences like variable management and labels.
In all cases, the VirtualMachine
type is used to execute instructions.
Its documentation goes into detail how it operates.
Modules
- A
HashMap
implementation that provides a defined iteration order. - An intermediate representation of virtual machine instructions.
- Utilities shared between Bud Assembly and Bud.
Structs
- An
Environment
that allows executing an amount of instructions before pausing the virtual machine. - A block of code that can be executed on the virtual machine.
- Displays a
CodeBlock
with optional indentation. - A Rust value that has been wrapped for use in the virtual machine.
- An unexpected event occurred while executing the virtual machine.
- A stack frame entry of a
Fault
. - A virtual machine function.
- A wrapper for
std::collections::HashMap<Value,Value>
that prevents using aValue
that does not support hashing by returning an error. - A List type for Bud, which wraps a
VecDeque<Value>
. - An intrinsic that does nothing.
- A paused code execution.
- An iterator over a sequence of values being removed from the top of a
Stack
. - A stack of
Value
s. - A
Display
implementor that converts a string value to its literal form including wrapping double quotes. - A String-like type that ensures only one instance of each Symbol exists per value, enabling quicker lookups by not requiring string comparisons.
- A Bud virtual machine instance.
Enums
- An action to take during an
Instruction::Compare
. - A method for comparing
Value
s. - A destination for a value.
- All errors that can be encountered executing Bud code.
- The virtual machine behavior returned from
Environment::step()
. - An unexpected event within the virtual machine.
- A reason for a virtual machine
Fault
. - A virtual machine instruction.
- A collection of
Instruction
s that may be borrowed. - A virtual machine value.
- All primitive
Value
kinds. - A value or a location of a value
- The source of a value.
Traits
- A type that can be used in the virtual machine using
Value::dynamic
. - Customizes the behavior of a virtual machine instance.
- A type that can be constructed from popping from the virtual machine stack.
- A native function for Bud.