A work-in-progress bytecode interpreter based on Crafting Interpreters. My primary goal with this project is to learn and understand how a scanner, compiler and virtual machine work to run a piece of code. So performance and efficiency will take a backseat for now.
Thanks to wasm
, you can use the compiler through a web text editor.
Compiling it to wasm
was done by following this tutorial. User interface is written in vanilla javascript using CodeMirror for text editor and Xterm.js for displaying the output.
This web interface was inspired by:
This project is a workspace containing the following crates:
- core - lox bytecode interpreter as a library crate
- cli - command line interface as a binary crate
- wasm - web interface as a library crate
Build all the crates:
cargo build
Build a specific crate:
cargo build -p $crate_name
Run the cli:
cargo run -p cli
Compile to Wasm:
$ cd wasm/
$ wasm-pack build
This will create a pkg/
directory that contains the Wasm version of the compiler.
Reinstall packages for the web:
$ cd web/
$ npm i
Now all the packages will get updated along with the changes made to the compiler.
Run the web interface locally:
npm run start
Bundle all the packages into a hostable application:
npm run build
Now the dist
directory will contain the bundled app.
Push the bundled app to github:
gh-pages -d dist/
I’m fairly new to programming in Rust so I refer to these projects whenever I struggle with translating a piece of C code to Rust.