pcardune / hackvm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HackVM

This repository contains a reimplementation of the hack virtual machine described in the nand2tetris online class which runs in a web browser.

Try it out here

Directory Layout

  • hackvm - contains the virtual machine code, which is implemented in Rust and compiles to WebAssembly
  • web - contains a web frontend for the virtual machine along with some demo programs, implemented with Typescript and React.

Building

Build Dependencies

  1. Install wasm-pack

Build Steps

There are two parts to the build. First we must compile the rust code into web assembly.

From the hackvm directory run:

wasm-pack build

Next we must compile all the Typescript/React code into plain html/javascript.

From the web directory run:

bun install
bun run build

There should now be a web/dist which can be published to any static file hosting site. To view the contents in a web browser, you'll need to actually serve the files via a real http server (browsers can't load Web Assembly binaries from the local file system for security reasons):

From the web/dist directory:

python3 -m http.server

For more details about building the website or the vm, refer to the README files in the hackvm and web subdirectories.

Building During Developement

During development, to avoid constantly having to run bun install while making changes to and compiling the rust code, you'll want to use bun link to symlink the hackvm/pkg directory. From the repository root, this can be done with the following:

cd hackvm/pkg
bun link
cd ../../web
bun link hackvm

About

License:MIT License


Languages

Language:Rust 72.2%Language:TypeScript 26.1%Language:HTML 0.9%Language:JavaScript 0.5%Language:CSS 0.4%