Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/poteto/monkers
Bytecode compiler and VM for the Monkeylang language, written in Rust
https://github.com/poteto/monkers
compiler interpreter monkey-language programming-language rust
Last synced: 2 months ago
JSON representation
Bytecode compiler and VM for the Monkeylang language, written in Rust
- Host: GitHub
- URL: https://github.com/poteto/monkers
- Owner: poteto
- License: mit
- Created: 2020-03-17T05:16:43.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-05-24T12:41:42.000Z (over 1 year ago)
- Last Synced: 2024-10-08T05:58:23.494Z (3 months ago)
- Topics: compiler, interpreter, monkey-language, programming-language, rust
- Language: Rust
- Homepage:
- Size: 184 KB
- Stars: 44
- Watchers: 4
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# monkers 🐒 + 🦀
[![Rust](https://github.com/poteto/monkers/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/poteto/monkers/actions/workflows/rust.yml)
Short for `monkey-rs`. An implementation of [monkeylang](https://monkeylang.org/). Previously, I implemented the interpreter in [TypeScript](https://github.com/poteto/boba-js). I am re-implementing the interpreter and later compiler in Rust as a learning exercise.
## Building
```shell
$ cargo build --release# See help
$ target/release/monkers --help# Run the REPL with bytecode compilation
$ target/release/monkers# Run the REPL with the tree-walking interpreter
$ target/release/monkers -s interpreted
```## Developing
### Development REPL
Start the REPL by running `cargo run`, then entering some Monkey:
```
🐒 >> let a = 5;
5
🐒 >> let b = a > 3;
true
🐒 >> let c = a * 99;
495
🐒 >> if (b) { 10 } else { 1 };
10
🐒 >> let d = if (c > a) { 99 } else { 100 };
99
🐒 >> d;
99
🐒 >> d * c * a;
245025
```Options can also be enabled:
```
$ cargo run -- -d # debug mode
$ cargo run -- -s interpreted # eval with interpreter
```Command history is saved in `history.txt`.
By default, monkers REPL will compile your code into bytecode, then evaluate the bytecode with its VM. You can switch to the slower tree-walking interpreter with an arg:
```
cargo run -- interpreted
```### Helpful crates
#### [`cargo-watch`](https://github.com/passcod/cargo-watch)
`cargo-watch` watches over your Cargo project's source. I use it to run my tests and `cargo check` whenever a file changes. It's aliased to `cargo dev`, which expands to:
```
cargo watch -x check -x test
```Optionally you can append the `RUST_BACKTRACE=1` flag to get backtraces.
## Contributing
PRs are welcome! I am not a Rust expert, so I welcome any recommendations on more idiomatic Rust code.