{"id":38869270,"url":"https://github.com/markoelez/minicompiler","last_synced_at":"2026-01-17T14:28:15.012Z","repository":{"id":217043740,"uuid":"738664024","full_name":"markoelez/minicompiler","owner":"markoelez","description":"Mini C compiler","archived":false,"fork":false,"pushed_at":"2024-01-30T20:31:24.000Z","size":51,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-01-31T05:23:29.979Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markoelez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2024-01-03T18:49:52.000Z","updated_at":"2024-01-30T20:29:16.000Z","dependencies_parsed_at":"2024-01-28T05:22:56.658Z","dependency_job_id":"0f384dfc-eebe-4e9f-ab6b-0b735ae73521","html_url":"https://github.com/markoelez/minicompiler","commit_stats":null,"previous_names":["markoelez/minicompiler"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/markoelez/minicompiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markoelez%2Fminicompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markoelez%2Fminicompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markoelez%2Fminicompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markoelez%2Fminicompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markoelez","download_url":"https://codeload.github.com/markoelez/minicompiler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markoelez%2Fminicompiler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28509948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-17T14:28:14.274Z","updated_at":"2026-01-17T14:28:15.003Z","avatar_url":"https://github.com/markoelez.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# minicompiler\n\n[![CI](https://github.com/markoelez/minicompiler/actions/workflows/ci.yaml/badge.svg)](https://github.com/markoelez/minicompiler/actions/workflows/ci.yaml)\n\n\n### Example\n\nRunning: `PYTHONPATH=. python minicompiler/eval.py`\n\nProduces the following visual output:\n\n```sh\n********************************************************************************\nint _start() {\n    int x = 3;\n    int y = 4;\n    int res = x + y;\n    return res;\n}\n********************************************************************************\n|-Root()\n    |-FunctionDecl(rtype=T(type=\u003cTokType.INT\u003e, data='int'), ident=_start)\n        |-CompoundStmt()\n            |-DeclStmt()\n                |-VarDecl(type='int', ident='x')\n                    |-NumExpr(val=3)\n            |-DeclStmt()\n                |-VarDecl(type='int', ident='y')\n                    |-NumExpr(val=4)\n            |-DeclStmt()\n                |-VarDecl(type='int', ident='res')\n                    |-AddOp()\n                        |-DeclRefExpr(ident='x')\n                        |-DeclRefExpr(ident='y')\n            |-ReturnStmt()\n                |-DeclRefExpr(ident='res')\n********************************************************************************\n.global _start\n_start:\nMOV X16, #3\nMOV X18, X16\nMOV X26, #4\nMOV X15, X26\nADD X7, X18, X15\nMOV X12, X7\nMOV X0, X12\nRET\n********************************************************************************\nDirective(name='.global', subject='_start')\nLabel(name='_start')\nMOV(X16, #3)         0x70 0x00 0x80 0xD2   01110000 00000000 10000000 11010010\nMOV(X18, X16)        0xF2 0x03 0x10 0xAA   11110010 00000011 00010000 10101010\nMOV(X26, #4)         0x9A 0x00 0x80 0xD2   10011010 00000000 10000000 11010010\nMOV(X15, X26)        0xEF 0x03 0x1A 0xAA   11101111 00000011 00011010 10101010\nADD(X7, X18, X15)    0x47 0x02 0x0F 0x8B   01000111 00000010 00001111 10001011\nMOV(X12, X7)         0xEC 0x03 0x07 0xAA   11101100 00000011 00000111 10101010\nMOV(X0, X12)         0xE0 0x03 0x0C 0xAA   11100000 00000011 00001100 10101010\nRET()                0xC0 0x03 0x5F 0xD6   11000000 00000011 01011111 11010110\n********************************************************************************\n```\n\nIn addition to an object file `tmp.o`, and an executable Mach-O binary `out`.\n\nThe raw C program goes through the following distinct transformations:\n\n(compiler)\n- C program -\u003e C language tokens\n- C language tokens -\u003e AST\n- AST -\u003e ARM64 assembly\n\n(assembler)\n- ARM64 assembly -\u003e ARM64 tokens\n- ARM64 tokens -\u003e Mach-O object file\n\n(linker -- uses GNU linker)\n- Mach-O object file -\u003e Mach-O executable file\n\n### Reference\n\nARM:\n- https://developer.arm.com/documentation/102374/latest/\n- http://163.238.35.161/~zhangs/arm64simulator/\n\nCompilation:\n- https://clang.llvm.org/docs/IntroductionToTheClangAST.html\n\nMach-O: \n- https://alexdremov.me/mystery-of-mach-o-object-file-builders/\n- https://github.com/alexdremov/MachOBuilder/tree/main\n- https://github.com/aidansteele/osx-abi-macho-file-format-reference?ref=alexdremov.me\n- https://en.wikipedia.org/wiki/Mach-O#Mach-O_file_layout\n- https://medium.com/@travmath/understanding-the-mach-o-file-format-66cf0354e3f4\n\n### Todo\n- better support for functions\n    - support multiple functions + populate symbol/string tables\n    - support stack frames\n    - support calling functions with arguments\n- put raw data into data section in object file\n- support more instructions\n    - conditionals\n    - other binops (MUL, SUB, ...)\n    - pointers, malloc, etc.\n- support stdlib\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkoelez%2Fminicompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkoelez%2Fminicompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkoelez%2Fminicompiler/lists"}