Skip to content

veera-sivarajan/bessy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bessy

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.

Playground

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:

  1. skiff
  2. cstea

Build Instructions

This project is a workspace containing the following crates:

  1. core - lox bytecode interpreter as a library crate
  2. cli - command line interface as a binary crate
  3. wasm - web interface as a library crate

Step 1

Build all the crates:

cargo build

Build a specific crate:

cargo build -p $crate_name

Run the cli:

cargo run -p cli

Step 2

Compile to Wasm:

$ cd wasm/ 
$ wasm-pack build

This will create a pkg/ directory that contains the Wasm version of the compiler.

Step 3

Reinstall packages for the web:

$ cd web/
$ npm i

Now all the packages will get updated along with the changes made to the compiler.

Step 4

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.

Step 5

Push the bundled app to github:

gh-pages -d dist/

References

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.