https://github.com/ktanaka101/monkey.rs
🐵 Monkey interpreter and compiler-vm in Rust. 🚀
https://github.com/ktanaka101/monkey.rs
compiler interpreter language monkey programming-language repl rust vm
Last synced: 2 months ago
JSON representation
🐵 Monkey interpreter and compiler-vm in Rust. 🚀
- Host: GitHub
- URL: https://github.com/ktanaka101/monkey.rs
- Owner: ktanaka101
- License: mit
- Created: 2019-11-21T08:45:12.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-03T20:53:36.000Z (3 months ago)
- Last Synced: 2025-03-24T18:54:34.130Z (3 months ago)
- Topics: compiler, interpreter, language, monkey, programming-language, repl, rust, vm
- Language: Rust
- Homepage:
- Size: 472 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# monkey.rs
## Summury
We can learn how to make an interpreter and a compiler-vm in this book.
====> ☆☆☆ **["Writing An Interpreter in Go"](https://interpreterbook.com/)** ☆☆☆
====> ☆☆☆ **["Writing A Compiler In Go"](https://compilerbook.com/)** ☆☆☆
That interpreter and compiler-VM is called Monkey in the book.
The Monkey is written in Go in the book.
But in this repository it is written in Rust.## Supports
- [x] Lexer
- [x] Parser
- [x] Evaluator
- [x] Compiler
- [x] VM
- [x] REPL
- [x] Test case
- [x] Evaluator and VM benchmarks
- [x] Not use `unsafe`## Example
### REPL
```sh
$ cargo run
>> let a = 5
5
>> a + 10
15
>> let new_closure = fn(a) { fn() { a; }; };
Closure[CompiledFunction[0000 GetLocal 0¥n0002 Closure 3 1¥n0006 ReturnValue¥n] ]
>> let closure = new_closure(99);
Closure[CompiledFunction[0000 GetFree 0¥n0002 ReturnValue¥n] 99]
>> closure();
99
```### Fibonacchi
```monkey
let fibonacci = fn(x) {
if (x == 0) {
return 0;
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
fibonacci(15); #=> 610
```## Run test
```sh
$ cargo test --workspace
```## TODO
- [ ] Improve print output
- [ ] Improve REPL
- [ ] Refactoring
- [ ] Optimize data structure
- [ ] Support LLVM## Contributors
- [ktanaka101](https://github.com/ktanaka101) - creator, maintainer
## License
MIT