{"id":30805510,"url":"https://github.com/andreev-io/monkey-compiler","last_synced_at":"2025-10-05T01:50:08.175Z","repository":{"id":54693377,"uuid":"335649608","full_name":"andreev-io/Monkey-Compiler","owner":"andreev-io","description":"A single-pass compiler for a toy language with custom byte code intermediate representation and a stack-based virtual machine.","archived":false,"fork":false,"pushed_at":"2021-02-06T20:41:34.000Z","size":68,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-13T04:52:10.097Z","etag":null,"topics":["compilers","monkey-programming-language","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreev-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-03T14:24:21.000Z","updated_at":"2025-03-19T22:12:48.000Z","dependencies_parsed_at":"2022-08-14T00:10:46.341Z","dependency_job_id":null,"html_url":"https://github.com/andreev-io/Monkey-Compiler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andreev-io/Monkey-Compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreev-io%2FMonkey-Compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreev-io%2FMonkey-Compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreev-io%2FMonkey-Compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreev-io%2FMonkey-Compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreev-io","download_url":"https://codeload.github.com/andreev-io/Monkey-Compiler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreev-io%2FMonkey-Compiler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278399610,"owners_count":25980331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compilers","monkey-programming-language","rust"],"created_at":"2025-09-06T00:58:21.139Z","updated_at":"2025-10-05T01:50:08.142Z","avatar_url":"https://github.com/andreev-io.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Monkey Compiler in Rust\n\nThis project is a single-pass custom bytecode compiler and a stack-based virtual machine that runs code written in Monkey. Under the hood, the parser uses Pratt parsing. \n\nThe language supports first-class functions (with arguments), anonymous functions, closures, return statements, if clauses, strings, integers, booleans, and arrays. \n\nRun `cargo run --release` to bring up a REPL.\n\nThe following are examples of some amazing Monkey programs:\n```\n\u003e\u003e\u003e let fibonacci = fn(x) {\n        if (x == 0) { \n            0\n        } else {\n            if (x == 1) {\n                return 1;\n            } else {\n                fibonacci(x - 1) + fibonacci(x - 2);\n            }\n        } \n};\n\nfibonacci(35);\n```\n\n```\n\u003e\u003e\u003e let wrapper = fn() {\n        let countDown = fn(x) {\n            if (x == 0) {\n                return 0;\n            } else {\n                countDown(x - 1);\n            } \n        };\n        countDown(1);\n};\nwrapper();\n```\n\nArrays and indexing:\n```\n\u003e\u003e\u003e let x = [1, 2, fn(x) { x }(5)]; \n\u003e\u003e\u003e x[2]\n\n5\n```\n\nNulls and truthy values:\n```\n\u003e\u003e\u003e !!fn() {}();\nfalse\n\n\u003e\u003e\u003e !!\"hi\"\ntrue\n```\n\n\nStrings:\n```\n\u003e\u003e\u003e let x = \"good\";\n\u003e\u003e\u003e let y = \"bye\";\n\u003e\u003e\u003e let goodbye = fn(x, y) { if (x+y == \"goodbye\") { 1 } else { 0 }};\n\u003e\u003e\u003e goodbye(x, y)\n\n1\n```\n\nAs shown above, the language supports anonymous functions and function literals.\nThe language doesn't have garbage collection and relies on Rust's ownership\nsemantics for memory management.\n\nAs far as the virtual machine goes, it correctly cleans up the call frame whenever a closure is exited.\n\n```\n\u003e\u003e\u003e let v = [1, 2, 3]; \n\nlet superfunc = fn(a) { \n    let b = a; \n    b[0] + b[1] \n}; \n\n3 == superfunc(v)\n```\n\nWhen `superfunc` is called, `b` is created by cloning the array `a`, but is deallocated when superfunc returns.\n\n\n```\nlet factorial = fn(x) {\n    if (x == 0) {\n        1\n    } else {\n        x * factorial(x-1)\n    }\n}\n\nfactorial(5)\n```\n\nNote that we could've allocated anything within the recursively called\nfunction, and the values would be successfully deallocated on return.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreev-io%2Fmonkey-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreev-io%2Fmonkey-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreev-io%2Fmonkey-compiler/lists"}