{"id":13782804,"url":"https://github.com/irori/unlambda","last_synced_at":"2025-04-12T18:24:07.287Z","repository":{"id":143406926,"uuid":"133209369","full_name":"irori/unlambda","owner":"irori","description":"Unlambda interpreter","archived":false,"fork":false,"pushed_at":"2024-07-09T01:16:57.000Z","size":34,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T12:46:31.075Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","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/irori.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":"2018-05-13T05:44:07.000Z","updated_at":"2025-02-13T15:05:56.000Z","dependencies_parsed_at":"2024-08-03T18:13:15.667Z","dependency_job_id":"a45c9af0-34a5-407a-9612-6bf52c087de0","html_url":"https://github.com/irori/unlambda","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irori%2Funlambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irori%2Funlambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irori%2Funlambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irori%2Funlambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/irori","download_url":"https://codeload.github.com/irori/unlambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248611213,"owners_count":21133068,"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-08-03T18:01:44.961Z","updated_at":"2025-04-12T18:24:07.242Z","avatar_url":"https://github.com/irori.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# Unlambda interpreter\n\nThis is a fast and memory-efficient interpreter of the\n[Unlambda](http://www.madore.org/~david/programs/unlambda/) programming\nlanguage.\n\n## Performance\n\nCompared to [unl.c](http://users.math.cas.cz/~jerabek/ptakoviny/index.html#unl)\nby Emil Jeřábek, which itself is 50-100 times faster than the official c-refcnt\ninterpreter, this interpreter is about 2 times faster and uses about 1/2 of\nthe memory.\n\n| Benchmark     | unl.c | This interpreter |\n|---------------|-------|------------------|\n| adventure[^1] | 0.72s |   0.41s          |\n| lisp[^2]      | 2.05s |   1.28s          |\n| elvm-8cc[^3]  | 44.3s |   20.1s          |\n\n[^1]: Complete [Adventure](https://github.com/irori/advent-unlambda) with the highest score (350 points).\n[^2]: Compute `(fib 16)` in [Unlambda Lisp](https://github.com/irori/unlambda-lisp).\n[^3]: Compile a [simple C program](https://github.com/shinh/elvm/blob/master/test/8cc.in) with `8cc.c.eir.unl` generated by [ELVM](https://github.com/shinh/elvm/) (`make unl`).\n\n### Combinator Substitution\n\nTo achieve this performance, this interpreter introduces several new\ncombinators (`B`, `C`, `T`, and `V`) used only internally to substitute\nexpressions under evaluation by pattern matching. The following substitution\nrules are implemented:\n\n```\n     `S`Kf -\u003e `Bf    where ```Bfgx = `f`gx\n   ``Sf`Kg -\u003e ``Cfg  where ```Cfgx = ``fxg\n   ``SI`Kx -\u003e `Tx    where   ``Txy = `yx\n ``S`Tx`Ky -\u003e ``Vxy  where ```Vxyz = ``zxy\n```\n\n(Note that `V` is the \"pair\" combinator (also known as \"cons\") and unrelated to\nthe Unlambda's `v` (\"black hole\" function) builtin.)\n\nFor example, when the first argument is given to `S`, if it is a partial\napplication of `K` (with one argument `f` given), it is replaced by `` `Bf``.\n\nThese auxiliary combinators use less memory and evaluate faster than the\noriginal SKI-only combinator expressions.\n\n### Garbage Collection\n\nThe object graph of Unlambda execution does not cycle, so memory management\ncan be done using reference counting. In fact, the c-refcnt interpreter and\nunl.c both use reference counting.\n\nHowever, since Unlambda frequently creates and destroys objects, reference\ncounting can be quite an overhead. Also, optimizing things like omitting\nreference counter operations where possible, or overwriting and reusing objects\nwhen the counter is 1, as unl.c does, can make the code more complicated.\n\nTherefore, this interpreter adopted a generational garbage collector. For new\ngeneration it uses two regions for 256k objects and performs copying GC.\nObjects that have survived this minor GC twice are moved to the old generation\nregion. When the old generation area is full, a mark-sweep GC is performed on\nthe entire heap as a major GC.\n\nGenerational GC is very effective in Unlambda, often collecting more than 99%\nof objects in minor GC. In benchmark measurements, GC accounted for about 1% of\nthe overall execution time.\n\nIn general, Generational GC requires a write barrier to keep track of\nreferences from the old generation area to the new generation area. But in this\ninterpreter, once an object is created, it is never rewritten, so references\nfrom the old generation to the new generation do not occur. Since no write\nbarrier is needed, the evaluator can be written without worrying too much\nabout GC (although copy GC changes object addresses).\n\n## Building\n\n```sh\n$ make\n```\n\n## Usage\n\n```sh\n$ unlambda [options] [program-file]\n```\n\nIf _program-file_ is not specified, Unlambda program is read from the standard input.\n\nOptions:\n\n- `-h`: Print help and exit.\n- `-v`: Print version and exit.\n- `-v0` (default): Do not print any debug information.\n- `-v1`: Print some statistics after execution.\n- `-v2`: Print logs for major GCs.\n- `-v3`: Print logs for minor GCs.\n\n## License\n\nThis software is released under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firori%2Funlambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Firori%2Funlambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firori%2Funlambda/lists"}