Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gengjiawen/monkey-rust

Open more actions menu

Repository files navigation

monkey-rust

Rust monkey-interpreter npm version npm version

An interpreter and compiler for the Monkey programming language written in Rust

The Monkey Programming Language

What’s Monkey?

Compiler playground

https://monkey-lang-playground-jw.vercel.app/

AST Online playground

https://astexplorer.net/#/gist/e23a81ce309e8fcffe95ddd1b5661061/01d0b4b078304ddd9639eae9f4e6d342e2b9d075

Monkey has a C-like syntax, supports variable bindings, prefix and infix operators, has first-class and higher-order functions, can handle closures with ease and has integers, booleans, arrays and hashes built-in.

Features

  • Split packages to make everything minimum
  • REPL: A Read-Eval-Print-Loop (REPL) for Monkey tokenizer, parser, evaluator, compiler, and GC runtime
  • location info for ast
  • test for every module
  • Wasm: A WebAssembly target, thus run monkey on browser is directly supported.
  • Prettier Plugin: Format Monkey source code with Prettier via prettier-plugin-monkey.
  • Minifier (@gengjiawen/monkey-minifier): A semantics-preserving source-to-source minifier powered by the Rust/Wasm parser, with compact printing, identifier mangling, constant folding and propagation, dead let elimination, and Node/browser/CLI APIs.
  • VS Code Extension: First-class editor support with syntax highlighting, snippets, WASM-powered diagnostics, AST preview, and bytecode compilation commands.
  • bytecode viewer from source
  • GC (monkey-gc): alternate bytecode VM with QuickJS-style refcounting and three-phase cycle collection (gc_decrefgc_scangc_free_cycles) on a GcHeap, so cyclic object graphs can be reclaimed without changing object or the default Rc VM.
  • Bytecode snapshots (.mbc): QuickJS-style ahead-of-time compilation, mirroring qjscmonkey-gc compile foo.monkey serializes the compiled bytecode to a .mbc file and monkey-gc run foo.mbc executes it without the parser/compiler, treating the file as untrusted input behind a three-layer validation model (design doc).
  • ASM (monkey-asm): AOT arm64 (AArch64) assembly backend — single-pass lowering from the AST to AArch64 assembly text, assembled and linked against a cross-built Rust runtime into a native executable, in Linux/ELF and macOS/Mach-O flavors (the Linux flavor runs on any host via qemu-aarch64); the playground's ARM64 tab shows the same assembly godbolt-style (design doc).

Resources

Official site is: https://monkeylang.org/. It's has various implementation languages :).

There is a book about learning how to make an interpreter: Writing An Interpreter In Go. This is where the Monkey programming language come from.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.