{"id":20995094,"url":"https://github.com/tom-mohr/compiler","last_synced_at":"2026-04-16T17:44:25.535Z","repository":{"id":153862072,"uuid":"428441784","full_name":"tom-mohr/compiler","owner":"tom-mohr","description":"I made a custom programming language from scratch","archived":false,"fork":false,"pushed_at":"2022-02-07T21:32:46.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T12:46:18.407Z","etag":null,"topics":["compiler-design","deno","programming-language"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/tom-mohr.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-15T22:33:22.000Z","updated_at":"2023-12-03T21:29:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"30dc8f8e-0d0b-40c8-80c9-a5bd808642da","html_url":"https://github.com/tom-mohr/compiler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tom-mohr/compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-mohr%2Fcompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-mohr%2Fcompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-mohr%2Fcompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-mohr%2Fcompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tom-mohr","download_url":"https://codeload.github.com/tom-mohr/compiler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tom-mohr%2Fcompiler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265947518,"owners_count":23853383,"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","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":["compiler-design","deno","programming-language"],"created_at":"2024-11-19T07:21:33.894Z","updated_at":"2026-04-16T17:44:25.484Z","avatar_url":"https://github.com/tom-mohr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About This Project\n\nI wanted to see if I could create a programming language. It worked!\n\nThis project can be divided into two parts:\n- The runtime, a simple stack machine that runs custom bytecode.\n- The compiler, that can compile my custom language's source code into bytecode for the runtime.\n\n# Example Code\n\n```\nfib(n)\n    return = 1\n    if \u003e(n, 2)\n        return = add(fib(add(n, -1)), fib(add(n, -2)))\n```\nThis computes the n-th [Fibonacci number](https://en.wikipedia.org/wiki/Fibonacci_number).\n\n\n# Project Setup\n\nYou need the following tools:\n- [npm](https://www.npmjs.com/package/npm)\n- [Deno](https://deno.land/)\n\nAfter checking out the git repository, run `npm install` to install the dependencies.\n\n# How to Compile and Execute Code\n\n```sh\ndeno run --allow-read run.ts \u003cfilename\u003e [\u003cfunction name\u003e [program arguments]]\n```\n\nExample:\n\n1.  Save the following in a text file called `myprogram.txt`:\n\n    ```\n    myfunction(a, b, c)\n        return = add(a, mul(b, c))\n    ```\n2.  Open the console inside the project directory and execute\n\n    ```sh\n    deno run --allow-read run.ts myprogram.txt myfunction 1 2 3\n    ```\n    \n    This should print `7` to the console.\n    If you stored your file in a diffent location, simply change `myprogram.txt` to the actual path of your file.\n\nYou can also add a `main()` function *to the end of your file*:\n\n```\nmyfunction(a, b, c)\n    return = add(a, mul(b, c))\n\nmain()\n    return = myfunction(1, 2, 3)\n```\n\nThe runtime looks for a \"main\" function by default. Therefore, you can now simply run:\n\n```sh\ndeno run --allow-read run.ts myprogram.txt\n```\n\nTo see what the compiler does, add the `--debug` flag when running your program from the console. This will show you:\n- debug information while the compiler is compiling your code\n- the compiler output (bytecode)\n- debug information while the runtime is executing the bytecode\n\nFor the Fibonacci example above, the bytecode will look something like this:\n```\n[0]  load 1\n[1]  write -1\n[2]  read 0\n[3]  push\n[4]  load 2\n[5]  push\n[6]  native greater\n[7]  jumpIfNot 30\n[8]  load 0\n[9]  push\n[10] read 0\n[11] push\n[12] load -1\n[13] push\n[14] native add\n[15] push\n[16] jumpFunction 0\n[17] push\n[18] load 0\n[19] push\n[20] read 0\n[21] push\n[22] load -2\n[23] push\n[24] native add\n[25] push\n[26] jumpFunction 0\n[27] push\n[28] native add\n[29] write -1\n[30] pop\n[31] pop\n[32] return\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom-mohr%2Fcompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftom-mohr%2Fcompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftom-mohr%2Fcompiler/lists"}