https://github.com/pyjarrett/cxxlox
Bytecode Virtual Machine for Lox
https://github.com/pyjarrett/cxxlox
Last synced: about 2 months ago
JSON representation
Bytecode Virtual Machine for Lox
- Host: GitHub
- URL: https://github.com/pyjarrett/cxxlox
- Owner: pyjarrett
- License: mit
- Created: 2023-11-12T20:19:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-11T05:14:09.000Z (over 2 years ago)
- Last Synced: 2024-01-11T08:17:24.602Z (over 2 years ago)
- Language: C++
- Size: 1.29 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# C++ Lox Bytecode Virtual Machine
A C++ implementation of the bytecode virtual machine from "Crafting Interpreters"
by Robert Nystrom.
# Philosophy
This uses some elements of the C++ standard library, but tries to stay close
to the philosophy of "doing things from scratch" that the book uses.
For example, that means I use `` and `std::format`, but wrote a
simple resizable array type instead of using `std::vector`. It also means
using C-style tagged unions instead of `std::variant`.
I have never written a bytecode VM before, so I'm doing it as
close to the book in a more type-safe C++ way, and then refactoring into
more idiomatic C++ as I go. This won't ever be a production bytecode
VM, but it should eventually show my C++ version of how the book
does things.
# Building
This project currently uses `cmake`, so you can build as follows.
Use an out-of-tree build:
```
mkdir build
cd build
cmake .. # Generate project
cmake --build . # Build project
ctest # Run unit tests
```
# Running a `.lox` file
This will build the bytecode virtual machine and run the associated file:
Example:
```
python .\scripts\run_sample.py .\samples\expressions.lox --config Release
```
# Acceptance Test Battery
Acceptance tests compare the standard output of running the VM on a file ending
in `.lox`, against the expected output in a a similarly named `.expected` file.
The acceptance test script builds the VM and then runs the tests
in Release mode.
Run the test battery like:
```
python .\scripts\run_acceptance_test.py
```