{"id":28628256,"url":"https://github.com/fgeller/gcc","last_synced_at":"2025-06-12T10:11:51.623Z","repository":{"id":19112005,"uuid":"22340823","full_name":"fgeller/gcc","owner":"fgeller","description":null,"archived":false,"fork":false,"pushed_at":"2014-08-10T05:51:01.000Z","size":220,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-12T04:48:17.204Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","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/fgeller.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":"2014-07-28T11:52:18.000Z","updated_at":"2014-07-28T11:52:32.000Z","dependencies_parsed_at":"2022-07-13T01:20:26.404Z","dependency_job_id":null,"html_url":"https://github.com/fgeller/gcc","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/fgeller/gcc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgeller%2Fgcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgeller%2Fgcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgeller%2Fgcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgeller%2Fgcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fgeller","download_url":"https://codeload.github.com/fgeller/gcc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgeller%2Fgcc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259444983,"owners_count":22858553,"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":"2025-06-12T10:11:51.082Z","updated_at":"2025-06-12T10:11:51.612Z","avatar_url":"https://github.com/fgeller.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcc\n\nSmall compiler for the other MLISP down to GCC written in Clojure.\n\nMain approach:\n\n1. Use the reader to parse a set of given files into an S-Expression AST.\n2. Convert the AST for all top-level `defun`s into GCC instructions with relative and absolute references.\n3. Concatenate all instructions, moving a defun with name `main` to the front if given.\n4. Replace references with line numbers.\n5. Write output to file and STDOUT.\n\n## Implementation details\n\nThe main mapping from MLISP to GCC happens in `compile-sexp-to-gcc` based on a big\n`cond` statement. Given that the assembly has so support for LISPy\nfunctionality, the mapping from our MLISP to GCC is mostly straight-forward.\n\nThere is support for the main primitives `CEQ`, `CGT`, `CGTE`, `CONS`, `CAR`,\n`CDR`, `ADD`, `SUB`, `MUL`, `DIV`, `ATOM`, `DBUG`, `BRK` and `true`, `false` and\n`nil` are mapped to the respective constants. It adds a couple if built-in\nfunctions with varargs for convenience:\n\n```lisp\n    (mklist 1 1 2 3 5)\n    (mktuple 8 13 21 34 55)\n```\n\ngcc attempts to find tail calls and produces the respective `TSEL` and `TAP`\ninstructions automatically.\n\n`defun`, `lambda` and `let` support multiple forms in their bodies.\n\n`let` is implemented via a translation to lambda applications.\n\n## MLISP examples\n\nThe top-level defuns are wrapped in a pair of parenthesis for parsing.\n\n```lisp\n    (\n      (defun add (lhs rhs) (+ lhs rhs))\n    )\n```\n\nOr more interestingly:    \n    \n```lisp\n    (\n      (defun fold-left (lst acc fun)\n        (if (atom? lst)\n          acc\n          (fold-left (cdr lst)\n                     (fun acc (car lst))\n                     fun)))\n                     \n      (defun reverse (lst)\n        (fold-left lst nil (lambda (acc next)\n                                   (cons next acc))))\n    )\n```\n    \nWhich compiles to:\n\n    LD 0 1 ; $lambda-1\n    LD 0 0\n    CONS\n    RTN\n    LD 0 0 ; reverse\n    LDC 0\n    LDF 0\n    LDF 10\n    AP 3\n    RTN\n    LD 0 0 ; fold-left\n    ATOM\n    TSEL 13 15\n    LD 0 1\n    RTN\n    LD 0 0\n    CDR\n    LD 0 1\n    LD 0 0\n    CAR\n    LD 0 2\n    AP 2\n    LD 0 2\n    LDF 10\n    TAP 3\n\n## Usage\n\nYou'll need [leiningen](http://leiningen.org/) to build or run gcc.\n\nCommand line:\n\n    $ lein uberjar\n    $ java -jar $PWD/target/gcc-0.1.0-SNAPSHOT-standalone.jar $INPUTFILE1 $INPUTFILE2\n\nInteractively:\n\n    $ lein repl\n    \u003e (use 'gcc.core)\n    \u003e (gcc '((defun x () 23)))\n\nRun tests for hacking:\n\n    $ lein repl\n    \u003e (use 'midje.repl)\n    \u003e (autotest)\n\n## License\n\nNo restrictions.\n\nThis was written for the very fun ICFP Contest 2014, if this can be of any help to you -- happy hacking!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgeller%2Fgcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffgeller%2Fgcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgeller%2Fgcc/lists"}