{"id":17782730,"url":"https://github.com/sno2/xlang","last_synced_at":"2025-08-07T15:18:50.581Z","repository":{"id":259553149,"uuid":"873819666","full_name":"sno2/xlang","owner":"sno2","description":"Alternative implementation of ArithLang, VarLang, DefineLang, FuncLang, RefLang, and TypeLang used in COM S 3420.","archived":false,"fork":false,"pushed_at":"2024-11-20T21:54:20.000Z","size":4572,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T13:54:12.669Z","etag":null,"topics":["interpreter","programming-language","zig","ziglang"],"latest_commit_sha":null,"homepage":"https://xlang-web.vercel.app","language":"Zig","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/sno2.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-10-16T19:18:52.000Z","updated_at":"2024-11-20T21:54:24.000Z","dependencies_parsed_at":"2024-10-26T13:11:04.858Z","dependency_job_id":"7e8fee7f-75e5-499a-beda-1abdc34fd4ab","html_url":"https://github.com/sno2/xlang","commit_stats":{"total_commits":50,"total_committers":1,"mean_commits":50.0,"dds":0.0,"last_synced_commit":"80cc77c5f5ccaa3e154347519750501636703f08"},"previous_names":["sno2/xlang"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fxlang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fxlang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fxlang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fxlang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sno2","download_url":"https://codeload.github.com/sno2/xlang/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246709973,"owners_count":20821310,"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":["interpreter","programming-language","zig","ziglang"],"created_at":"2024-10-27T06:03:48.555Z","updated_at":"2025-08-07T15:18:50.569Z","avatar_url":"https://github.com/sno2.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xlang\n\nAlternative implementation of the [ArithLang](https://github.com/clayness/arithlang),\n[VarLang](https://github.com/clayness/varlang), [DefineLang](https://github.com/clayness/definelang),\n[FuncLang](https://github.com/clayness/funclang), [RefLang](https://github.com/clayness/reflang),\nand [TypeLang](https://github.com/clayness/typelang) languages used in COM S\n3420 at Iowa State University. The languages are described in the textbook _An\nExperiential Introduction to Principles of Programming Languages_ by Hridesh\nRajan.\n\n## Implementation details\n\nxlang is written using [Zig 0.14](https://ziglang.org/download/#release-0.14.0). Zig allows xlang to\nrun on many different platforms such as the web via [WebAssembly](https://webassembly.org/).\n\nThe tokenizer is piped directly into code generation and xlang compiles the\nsource code into a bytecode format on the fly. This technique is also used by\nthe [QuickJS JavaScript engine](https://bellard.org/quickjs/quickjs.html#Bytecode)\nand avoids the cost of building a parse tree.\n\nValues are efficiently stored in 64-bit floating point numbers using\n[NaN boxing](https://leonardschuetz.ch/blog/nan-boxing/). The NaN boxing\nimplementation used in xlang is adapted from the one I contributed to the\n[Kiesel JavaScript engine](https://codeberg.org/kiesel-js/kiesel/pulls/37).\n\nLocals are immutable memory but they must be allocated on the stack for every\nfunction call. Defines are mutable memory so they are allocated as a list of\nregisters at the top of the stack. Captured variables, i.e. using an outer\nfunction's local, are more complex and require attaching values to lambda\nvalues.\n\nThe tail call optimization reuses the stack of the current call when returning\nanother function call. Note that this is not limited to self-recursive functions\nbut also works when returning any function call to efficiently support\n[mutual recursion](https://wikipedia.org/wiki/Mutual_recursion).\n\nMemory is managed via a simple garbage collector that maintains a free list\namongst a list of pages. I did not spend any time optimizing the garbage\ncollector, but more efficient methods such as generational garbage collection\nwould most likely improve its performance.\n\n## Playground\n\nThe web playground uses the [Monaco Editor](https://microsoft.github.io/monaco-editor/),\n[xterm.js](https://xtermjs.org/), and a Wasm build of xlang to interpret\nprograms on the web. Build the playground using\n\n```\nzig build playground\n# --watch for build on save\n# -Doptimize=ReleaseFast for optimized Wasm\n```\n\n## Testing\n\nTest files are located in the [examples folder](./examples/). Run the tests\nagainst xlang:\n\n```\nzig build test -Djava_compat\n# --fuzz to enable fuzz testing\n```\n\nRun the tests against RefLang and TypeLang:\n\n```\nzig build test -Dreflang_source=../path/to/reflang -Dtypelang_source=../path/to/typelang\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsno2%2Fxlang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsno2%2Fxlang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsno2%2Fxlang/lists"}