{"id":18861110,"url":"https://github.com/vivelev/lolita","last_synced_at":"2026-02-09T07:30:21.785Z","repository":{"id":254010472,"uuid":"823269522","full_name":"VIVelev/lolita","owner":"VIVelev","description":"Tower of interpreters!","archived":false,"fork":false,"pushed_at":"2024-08-20T19:07:17.000Z","size":343,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T07:14:37.733Z","etag":null,"topics":[],"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/VIVelev.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-07-02T17:50:45.000Z","updated_at":"2024-08-20T19:10:59.000Z","dependencies_parsed_at":"2024-08-20T22:26:26.058Z","dependency_job_id":null,"html_url":"https://github.com/VIVelev/lolita","commit_stats":null,"previous_names":["vivelev/lolita"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VIVelev%2Flolita","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VIVelev%2Flolita/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VIVelev%2Flolita/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VIVelev%2Flolita/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VIVelev","download_url":"https://codeload.github.com/VIVelev/lolita/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239800405,"owners_count":19699129,"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-08T04:28:06.575Z","updated_at":"2026-02-09T07:30:21.591Z","avatar_url":"https://github.com/VIVelev.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A naive LISP interpreted by a tower of interpreters, compiled to C\n\nlolita is a zero-dependency (using only the 'base' package) implementation of a LISP with full support of macros\nthat compiles to C. Of interest is the way macros are achieved - lazily building an infinite tower of interpreters.\n\n## A Tower of Interpreters\n\nConsider the `unless` macro\n```scheme\n(begin\n  (defmacro (unless cond body)\n    `(if ,cond 'passthrough ,body))\n\n  (unless #t (+ 2 2)))\n```\n`defmacro` is a special keyword that defines new keywords. In this case,\nthe keyword `unless` is defined. Once a new keyword is defined, each occurrence\nis \"expanded\" by evaluating the body of the macro in a new meta-level interpreter.\n\nIf the body of the macro itself contains macro definitions and invocations,\nthose macros are in turn expanded, thus, a new meta-meta-level interpreter is created.\nThe process is repeated as many times as necessary.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/tower.svg\" alt=\"Tower of interpreters\"\u003e\n\u003c/p\u003e\n\n## Compilation to C\n\nCode is compiled to C and executed via the `scheme.h` runtime. The output C code is expressed in C macros\ndefined in `scheme.h` for simplicity and readability. The strategy adopted preserves the flavour of an\nexpression-centered language like LISP as much as possible.\n\n### How to compile?\n\nTo compile, for example, `factorial.scm` run:\n```bash\ncabal run lolita -- factorial.scm\n```\nThis will output a `out.c` file which can then be compiled and ran:\n```bash\ncc out.c \u0026\u0026 ./a.out\n```\n## Source files\n\n- `src/`\n  - `Main.hs` - the command line interface\n  - `MonadT.hs` - simple monad transformers library ala [mtl](https://hackage.haskell.org/package/mtl)\n  - `Parse.hs` - LISP reader implemented with combinators\n  - `Objectify.hs` - AST builder and macro expansion\n  - `Walk.hs` - various code walkers for processing the AST\n  - `Codegen.hs` - performs the final step of converting the processed AST to C code\n- `scheme.h` - the C runtime required to execute the output C code\n\n## Leftovers and limitations (things I meant to do, but didn't end up doing)\n\nIt should be relatively straightforward to implement mutation in the language via `set!`. An appropriate API\nshould be added to `scheme.h` and a code walker to label mutable variables.\n\nCurrently, there is no garbage collector whatsoever; however, a [Boehm](https://en.wikipedia.org/wiki/Boehm_garbage_collector) style\ngarbage collector should be relatively straightforward to adopt.\n\n## Credits\n\nVarious sources have been referenced throughout the codebase; however, one source has been paramount\nin the development of lolita: _Lisp in Small Pieces_ by Christian Queinnec.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivelev%2Flolita","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvivelev%2Flolita","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivelev%2Flolita/lists"}