A stack-based virtual machine that interprets simple arithmetic programs written in a basic assembly language.
AbstractVM is a C++20 implementation of a simple virtual machine capable of executing assembly-like programs. It features a stack-based architecture with five operand types and supports basic arithmetic operations with automatic type precision handling.
- Five Operand Types: Int8, Int16, Int32, Float, Double
- Stack-Based Architecture: All operations manipulate a stack
- Type Precision System: Operations preserve the highest precision type
- Comprehensive Error Handling: Overflow, underflow, division by zero, and more
- Factory Design Pattern: Operand creation through factory
- Command Design Pattern: Instructions as executable objects
- Lexer/Parser: Structured lexical and syntactic analysis
- Doxygen Documentation: Extensive inline documentation
./avm
push int32(42)
push int32(33)
add
dump
exit
;;The ;; marker indicates the end of the program when reading from stdin.
; Example program
push int32(42)
push int32(33)
add
push float(44.55)
mul
push double(42.42)
dump
pop
assert double(42.42)
exitpush <value>- Push a value onto the stackpop- Remove the top value from the stackdump- Display all stack values (most recent first)assert <value>- Assert the top value matches the given valueadd- Add the top two valuessub- Subtract the top two valuesmul- Multiply the top two valuesdiv- Divide the top two valuesmod- Calculate modulo of the top two valuesprint- Print the top value as an ASCII character (must be Int8)exit- Terminate the program
int8(n)- 8-bit signed integerint16(n)- 16-bit signed integerint32(n)- 32-bit signed integerfloat(z)- Single-precision floating-pointdouble(z)- Double-precision floating-point
- IOperand Interface: Abstract interface for all operand types
- Operand Template: Generic operand implementation
- OperandFactory: Creates operands using the Factory pattern
- ICommand Interface: Abstract interface for all instructions
- Command Classes: Concrete implementations of each instruction
- Lexer: Tokenizes input into tokens
- Parser: Validates syntax and generates commands
- VirtualMachine: Main execution engine
- Factory Pattern: Used for operand creation
- Command Pattern: Used for instruction encapsulation
- Template Method: Used in operand implementation
- Interface Segregation: Clean separation of concerns
Full documentation is generated using Doxygen and Sphinx:
make htmlThen open doc/_build/html/index.html in your browser.