.vscode | ||
app | ||
src/MiniWasm | ||
test | ||
.gitignore | ||
cabal.project.local | ||
flake.lock | ||
flake.nix | ||
miniwasm.cabal | ||
README.md |
miniwasm
Running the project
To compile and run the Cabal project, run the following command in the project's directory:
cabal run miniwasm # Prints the help menu
cabal run miniwasm <program> # Runs the specified MiniWasm program
To run the project's test suite, use the following command:
cabal run miniwasm-test
cabal run miniwasm-test -- <program> # Run just 1 test case (the -- is required)
Implementation notes
The project contains 4 main Haskell modules:
- MiniWasm.Syntax: Contains the definition of the MiniWasm AST.
- MiniWasm.Validation: Contains a fully-implemeted validation algorithm. You don't necessarily have to read this file, but it might help you when debugging if you get validation errors.
- MiniWasm.Execution: Contains a stub implementation of the interpreter. This is the only file that you need to modify and submit.
- MiniWasm.TestCases.Programs: Contains MiniWasm programs used as test cases for the interpreter.
- MiniWasm.TestCases.SmallStep: Contains small unit tests verifying single steps of your interpreter.
Haskell language extensions
The project uses the GHC2021
language by default, which enables most "sane" language extensions (you can find the full list here).
On top of this, some record-related language extensions are enabled by default, since you'll likely be using records quite a lot in the interpreter:
OverloadedRecordDot
: This enables therecord.field
syntax, which is more similar to most other languages. Therecord.field
syntax also disambiguates field names better than Haskell's defaultfield record
notation.RecordWildCards
: This extension lets you bring all of a record's fields into scope when pattern-matching on it, helping avoid duplication, e.g. instead ofConfig{funcs, memory, locals, stack, instrs}
you can writeConfig{..}
.NamedFieldPuns
: This extension adds a shorter notation for creating and updating records, when setting fields to local variables of the same name. For example, it lets you writeConfig{stack}
instead ofConfig{stack = stack}
if you're initializing thestack
field with a local variable also namedstack
.
You don't have to use the extensions if you don't want to, and you can also enable additional extensions, just make sure to enable them in the Execution.hs
file (using the {-# LANGUAGE #-}
pragma), and not in the .cabal
file, as you won't be submitting back the .cabal
file.