This project is my own attempt to learn Rust by doing. I went through the book https://craftinginterpreters.com/ converting the Java examples to Rust without knowing much Rust, which might be evident by some design choices I made. Towards the end of the first part of the book I started looking for ways to improve the code a bit and I also added the original tests and tweaked them a bit to work with my code. The tests were really helpful in finding a few subtle bugs I had missed initially.
This repository is a Cargo workspace containing two independent packages:
rjlox— the Part I tree-walk interpreter.rclox— the Part II bytecode compiler and virtual machine (scaffolded and ready for implementation).
The implementations have separate source trees. rjlox/ contains the completed Part I interpreter and its test
harness; rclox/ is the independent Part II implementation. Both crates use the shared Lox fixture corpus in
tests/fixtures/. The tree-walk interpreter evaluates an AST, while the bytecode interpreter will compile directly to
bytecode and execute it on a VM.
cargo test --workspacecargo run -p rjlox -- tests/fixtures/lox/_my/programs/non-trivial.loxTo run the Part II scaffold:
cargo run -p rcloxAll benchmark tests are run with cargo run -p rjlox, which means they are unoptimized and with debuginfo symbols
embedded.
| Benchmark | Time (s) |
|---|---|
| binary_trees.lox | 561.40 |
| equality.lox | 83.84; 87.87; 4.02 |
| fib.lox | 283.67 |
| instantiation.lox | 85.20 |
| invocation.lox | 65.49 |
| method_call.lox | 69.07 |
| properties.lox | 134.05 |
| string_equality.lox | 170.44; 172.62; 2.17 |
| trees.lox | 1281.16 |
| zoo.lox | 205.78 |
| zoo_batch.lox | 10.20 |