{"id":19682100,"url":"https://github.com/ssloy/tinycompiler","last_synced_at":"2025-05-16T12:10:56.899Z","repository":{"id":216890464,"uuid":"742629355","full_name":"ssloy/tinycompiler","owner":"ssloy","description":"Writing a compiler in a week-end","archived":false,"fork":false,"pushed_at":"2025-03-07T15:07:06.000Z","size":294,"stargazers_count":374,"open_issues_count":0,"forks_count":19,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T08:34:35.583Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ssloy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2024-01-12T22:53:54.000Z","updated_at":"2025-04-11T13:58:47.000Z","dependencies_parsed_at":"2025-01-28T21:05:01.408Z","dependency_job_id":"b6ab2cd6-5b4b-4ea2-9f28-b917b085d1e8","html_url":"https://github.com/ssloy/tinycompiler","commit_stats":{"total_commits":68,"total_committers":1,"mean_commits":68.0,"dds":0.0,"last_synced_commit":"5c8ad67eba6072ee7f081d9fe356e9b8b19c6901"},"previous_names":["ssloy/tinycompiler"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssloy%2Ftinycompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssloy%2Ftinycompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssloy%2Ftinycompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssloy%2Ftinycompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssloy","download_url":"https://codeload.github.com/ssloy/tinycompiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"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":[],"created_at":"2024-11-11T18:09:41.371Z","updated_at":"2025-05-16T12:10:56.882Z","avatar_url":"https://github.com/ssloy.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# TinyCompiler - a 500-ish lines of code compiler in a weekend\n\nHave you ever wondered how a compiler works, but you never found courage to find out?\nThen this project is for you (**N.B.: a detailed description is available [here](https://ssloy.github.io/tinycompiler/)**).\n\nI have never had the chance to look under the hood either, but one week-end I have decided to to write a translator from the esoteric programming language *wend* (short for week-end),\nwhich I just invented myself, into regular GNU assembly.\nThe goal is to keep the code as tiny as possible, 500-ish lines of python sounds great.\n\nHere is a program that uses virtually all concepts in Wend:\n```cpp\nmain() {\n    // square root of a fixed-point number\n    // stored in a 32 bit integer variable, shift is the precision\n\n    int sqrt(int n, int shift) {\n        int x;\n        int x_old;\n        int n_one;\n\n        if n \u003e 2147483647/shift { // pay attention to potential overflows\n            return 2 * sqrt(n / 4, shift);\n        }\n        x = shift; // initial guess 1.0, can do better, but oh well\n        n_one = n * shift; // need to compensate for fixp division\n        while true {\n            x_old = x;\n            x = (x + n_one / x) / 2;\n            if abs(x - x_old) \u003c= 1 {\n                return x;\n            }\n        }\n    }\n\n    int abs(int x) {\n        if x \u003c 0 {\n            return -x;\n        } else {\n            return x;\n        }\n    }\n\n    // 25735 is approximately equal to pi * 8192;\n    // expected value of the output is sqrt(pi) * 8192 approx 14519\n\n    println sqrt(25735, 8192);\n}\n```\n\n## run tests\n```sh\nmake test\n```\n\n## Graphics!\nIt is so dull to compute Fibonacci numbers, so here are more eyecandy examples for our compiler,  check [test-programs/gfx/*.wend](https://github.com/ssloy/tinycompiler/tree/main/test-programs/gfx) files.\n```sh\nmake gfx\n```\n### Mandelbrot set\n\u003cimg src=\"https://ssloy.github.io/tinycompiler/home/mandelbrot.png\" width=\"336\"\u003e\n\n### Ray tracer\n![](https://ssloy.github.io/tinycompiler/home/raytracer.png)\n\n### Zero-player breakout game\n![](https://ssloy.github.io/tinycompiler/home/breakout.gif)\n\n### Fire\n![](https://ssloy.github.io/tinycompiler/home/fire.gif)\n\n### Sunset race\n![](https://ssloy.github.io/tinycompiler/home/sunset-race.gif)\n\n### Metaballs\n![](https://ssloy.github.io/tinycompiler/home/metaballs.gif)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssloy%2Ftinycompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssloy%2Ftinycompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssloy%2Ftinycompiler/lists"}