{"id":26679612,"url":"https://github.com/lucwl/cluck","last_synced_at":"2026-05-07T15:35:39.938Z","repository":{"id":255265719,"uuid":"847122999","full_name":"lucwl/cluck","owner":"lucwl","description":"A mini C compiler made in Haskell with LLVM","archived":false,"fork":false,"pushed_at":"2025-03-15T18:18:34.000Z","size":116,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T21:39:06.620Z","etag":null,"topics":["c","compiler","haskell","llvm","llvm-hs"],"latest_commit_sha":null,"homepage":"","language":"Haskell","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/lucwl.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-24T23:13:07.000Z","updated_at":"2025-03-15T18:17:15.000Z","dependencies_parsed_at":"2024-08-28T23:42:23.389Z","dependency_job_id":"a00938a4-8edc-4d4f-a945-584e5f70dc33","html_url":"https://github.com/lucwl/cluck","commit_stats":null,"previous_names":["luc-wallace/cluc","luc-wallace/cluck","lucwl/cluck"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucwl%2Fcluck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucwl%2Fcluck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucwl%2Fcluck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucwl%2Fcluck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucwl","download_url":"https://codeload.github.com/lucwl/cluck/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245598314,"owners_count":20641884,"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":["c","compiler","haskell","llvm","llvm-hs"],"created_at":"2025-03-26T06:16:44.263Z","updated_at":"2025-10-16T19:04:11.235Z","avatar_url":"https://github.com/lucwl.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cluck\n\nA compiler for a subset of C written in Haskell.\n\nInspired by [MicroC](https://blog.josephmorag.com/posts/mcc0/)\n\nGenerates LLVM IR, uses Clang as a backend.\n\n## Features\n\n- Variable and function declarations\n- Return, if, for, while, do-while and switch statements\n- Expressions and precedence\n- Number, char and float literals\n- Binary and unary operators (most implemented)\n- Detailed syntax errors\n- Static analysis for bindings and types\n- Code generation for expressions and functions\n- Pointer types\n- Type casts\n- Arrays (1-dimensional)\n\nBuilt-in functions (no includes required):\n\n```c\nvoid* malloc(int);\nvoid free(void*);\nint scanf(char*, void*);\nint printf(char*, ...);\ndouble sqrt(double);\ndouble pow(double, double);\n```\n\n## Differences with C\n\nAlthough Cluck implements a language extremely similar to C, there are a few notable language differences:\n- there is no preprocessor, the built-in functions are implicitly imported into every program\n- `float` is implemented as a `double` underneath, this means %lf must be used in format strings\n- `bool` is implemented as a primitive type\n- switch statements have implicit fallthrough and there is no `default` case\n- arrays decay in the scope they are defined in to a single pointer, this means that `sizeof` does not work as expected\n- arrays cannot be defined in more than 1 dimension\n- there is no implicit casting with literal expressions, so if the value 0 wants to be used in a float expression\n  then it must be initialised as '0.0' or casted explicitly\n \n## Resources used\n\n[C89 Draft](https://port70.net/%7Ensz/c/c89/c89-draft.html)\n\n[Writing a C Compiler - Nora Sandler](https://norasandler.com/2017/11/29/Write-a-Compiler.html)\n\n[Functional Parsing - Computerphile](https://www.youtube.com/watch?v=dDtZLm7HIJs)\n\n[Megaparsec tutorial](https://markkarpov.com/tutorial/megaparsec.html)\n\n[Compiling a functional language to LLVM - Daniel J. Harvey](https://danieljharvey.github.io/posts/2023-02-08-llvm-compiler-part-1.html)\n\n[Micro C - Joseph Morag](https://blog.josephmorag.com/posts/mcc0/)\n\n[Godbolt Compiler Explorer](https://godbolt.org/)\n\n## Usage\n\nOnly compatible with GHC 8.8.\n\nRequires LLVM 14 to be installed including Clang 14.\n\nOn Ubuntu:\n\n```\nsudo apt install clang-14\n```\n\n```\nghcup install cabal\n```\n\n```\ncabal build\n```\n\nBinary is located in ./dist-newstyle/build\n\n```\n./cluck \u003cinput file\u003e.c\n```\n\nIf no input file is provided, code can be entered directly via standard input.\n\nUse Ctrl + D to submit once typed.\n\n## Options\n\n`-o` - Specify output file\n\n`-A` - Output AST\n\n`-H` - Generate header file\n\n`-S` - Output LLVM IR\n\n`--help` - Output help page\n\n## Examples\n\nThe [examples](examples) folder contains some supported programs used to test the compiler's capabilities.\n\n| Example                       | Description                                                             |\n| ----------------------------- | ----------------------------------------------------------------------- |\n| [primes.c](examples/primes.c) | An implementation of the Sieve of Eratosthenes algorithm.               |\n| [merge.c](examples/merge.c)   | An implementation of Merge sort.                                        |\n| [trig.c](examples/trig.c)     | The sin, cos and tan functions approximated using the Maclaurin Series. |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucwl%2Fcluck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucwl%2Fcluck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucwl%2Fcluck/lists"}