40 lines
2.6 KiB
Markdown
40 lines
2.6 KiB
Markdown
|
# miniwasm
|
||
|
|
||
|
## Running the project
|
||
|
|
||
|
To compile and run the Cabal project, run the following command in the project's directory:
|
||
|
|
||
|
```sh
|
||
|
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:
|
||
|
|
||
|
```sh
|
||
|
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](src/MiniWasm/Syntax.hs): Contains the definition of the MiniWasm AST.
|
||
|
* [MiniWasm.Validation](src/MiniWasm/Validation.hs): 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](src/MiniWasm/Execution.hs): Contains a stub implementation of the interpreter. This is the only file that you need to modify and submit.
|
||
|
* [MiniWasm.TestCases.Programs](src/MiniWasm/TestCases/Programs.hs): Contains MiniWasm programs used as test cases for the interpreter.
|
||
|
* [MiniWasm.TestCases.SmallStep](src/MiniWasm/TestCases/SmallStep.hs): 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](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/control.html#extension-GHC2021)).
|
||
|
|
||
|
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 the `record.field` syntax, which is more similar to most other languages. The `record.field` syntax also disambiguates field names better than Haskell's default `field 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 of `Config{funcs, memory, locals, stack, instrs}` you can write `Config{..}`.
|
||
|
* `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 write `Config{stack}` instead of `Config{stack = stack}` if you're initializing the `stack` field with a local variable also named `stack`.
|
||
|
|
||
|
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.
|