Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioAriasC committed Jan 29, 2022
1 parent 396b3e8 commit 2e059df
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Monyet

[Crystal](https://crystal-lang.org/reference/1.2/index.html) implementation of the [Monkey Language](https://monkeylang.org/)
[Crystal](https://crystal-lang.org/reference/1.2/index.html) implementation of
the [Monkey Language](https://monkeylang.org/)

Monyet has a sibling implementation for Kotlin: [monkey.kt](https://github.com/MarioAriasC/monkey.kt)

Expand All @@ -13,10 +14,23 @@ and [Writing A Compiler in Go](https://compilerbook.com/)) are implemented.

Before running the command you must have crystal and shards installed on your machine

| Script | Description |
|-----------------|--------------------------------------------------------------------------------------------------------------------|
| `tests.sh` | Run all the tests |
| `checks.sh` | Run format tool and ameba checks |
| `build.sh` | Release build |
| `benchmarks.sh` | Run the classic monkey benchmark (fibonacci(35)), requires one command (`--eval`,`--eval-fast`,`--vm`,`--vm-fast`) |
| `repl.sh` | Run the Monyet REPL |
| Script | Description |
|----------------------------------|----------------------------------------------------------------------------------------------------------------------|
| [`tests.sh`](tests.sh) | Run all the tests |
| [`checks.sh`](checks.sh) | Run format tool and ameba checks |
| [`build.sh`](build.sh) | Release build |
| [`benchmarks.sh`](benchmarks.sh) | Run the classic monkey benchmark (`fibonacci(35)`), requires one command (`--eval`,`--eval-fast`,`--vm`,`--vm-fast`) |
| [`repl.sh`](repl.sh) | Run the Monyet REPL |

## Compiling variants

There are two different implementations for the compiler/VM.

* The default variant, based on `Array(UInt8)` as Bytecode and `OffsetArray` arrays for read operations
* The slices variant, based purely on `Slice(UInt8)`

The slices variant is more idiomatic but the default variant has better performance (around 10%).

To compile with a different variant you can the flag `--define=slice` to your compile or test. Additionally,
both [`build.sh`](build.sh) and [`test.sh`](tests.sh) have lines that you can comment/uncomment to enable different
variants
6 changes: 5 additions & 1 deletion src/code.cr
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ module Code
alias MBytes = OffsetArray | Instructions

private def offset(ins : Instructions, i : Int32) : MBytes
OffsetArray.new(ins, i)
{% if flag?(:slice) %}
ins[i...(ins.size)]
{% else %}
OffsetArray.new(ins, i)
{% end %}
end

def read_int(ins : Instructions, i : Int32) : Int32
Expand Down
4 changes: 2 additions & 2 deletions tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
crystal spec --verbose --define=slice
#crystal spec --verbose
#crystal spec --verbose --define=slice
crystal spec --verbose

0 comments on commit 2e059df

Please sign in to comment.