{"id":26474184,"url":"https://github.com/mrizaln/loxx","last_synced_at":"2025-03-19T22:45:21.632Z","repository":{"id":255657947,"uuid":"853142868","full_name":"mrizaln/loxx","owner":"mrizaln","description":"Lox interpreter in Rust","archived":false,"fork":false,"pushed_at":"2024-10-20T17:55:54.000Z","size":399,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-20T21:44:16.651Z","etag":null,"topics":["bytecode-interpreter","interpreter","lox","lox-interpreter","lox-programming-language","tree-walk-interpreter"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/mrizaln.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-06T04:30:22.000Z","updated_at":"2024-10-20T17:55:57.000Z","dependencies_parsed_at":"2024-09-06T15:47:57.668Z","dependency_job_id":"a76cc8ed-4971-4e72-8e09-3ec7f39c01f8","html_url":"https://github.com/mrizaln/loxx","commit_stats":null,"previous_names":["mrizaln/crafting-interpreters"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrizaln%2Floxx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrizaln%2Floxx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrizaln%2Floxx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrizaln%2Floxx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrizaln","download_url":"https://codeload.github.com/mrizaln/loxx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244520022,"owners_count":20465624,"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":["bytecode-interpreter","interpreter","lox","lox-interpreter","lox-programming-language","tree-walk-interpreter"],"created_at":"2025-03-19T22:45:21.032Z","updated_at":"2025-03-19T22:45:21.619Z","avatar_url":"https://github.com/mrizaln.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# loxx\n\nLox interpreter written in Rust (Lox is a scripting language created by Robert Nystrom for [this book](https://craftinginterpreters.com/))\n\nThis repository contains two packages that corresponds to the following in the book\n\n- `loxi ` \u0026rarr; `jlox`: a tree-walk interpreter (**implementation complete**)\n- `loxii` \u0026rarr; `clox`: a bytecode interpreter (not implemented yet)\n\n## Building\n\n```sh\ncargo build --bin loxi              # or loxii\ncargo run --bin loxi -- --help      # opens help\n```\n\n## Testing\n\nThe tests are performed using a python script\n\n```sh\n./test.py \u003cinterpreter\u003e -c \u003cchapter\u003e\n```\n\nUse the `-h` flag to see how to use it.\n\n## Benchmarks\n\n### Running\n\nYou can run the benchmarks yourself using the python script\n\n```sh\n./benchmark.py \u003cinterpreter\u003e \u003crepeat\u003e\n```\n\nUse the `-h` flag to see how to use it.\n\n\u003e You can add other interpreters to the script by adding more enumeration to `Interpreter` class yourself.\n\u003e That is what I do to add and benchmark `jlox` below.\n\n### Result\n\nThe benchmarks are performed on an **Intel Core i5-10500H machine with the frequency locked at 2.5GHz**. Each benchmark are repeated 5 times and then averaged to get better result.\n\n#### Tree-walk interpreter\n\n|                       |        loxi |        jlox |         diff |\n| --------------------- | ----------: | ----------: | -----------: |\n| `binary_trees.lox`    | 14.443941 s |  9.880800 s |   _+46.18 %_ |\n| `equality.lox`        |  9.941284 s |  5.494600 s |   _+80.93 %_ |\n| `fib.lox`             | 12.876985 s |  6.060200 s |  _+112.48 %_ |\n| `instantiation.lox`   |  3.923048 s |  2.008800 s |   _+95.29 %_ |\n| `invocation.lox`      |  4.071392 s |  1.759000 s |  _+131.46 %_ |\n| `method_call.lox`     |  2.020660 s |  2.427200 s | **-16.75 %** |\n| `properties.lox`      |  5.592753 s |  6.464400 s | **-13.48 %** |\n| `string_equality.lox` |  3.659577 s |  6.170000 s | **-40.69 %** |\n| `trees.lox`           | 27.242201 s | 32.009400 s | **-14.89 %** |\n| `zoo.lox`             |  3.839772 s |  6.017600 s | **-36.20 %** |\n| `zoo_batch.lox`       | 10.007977 s | 10.014200 s |  **-0.06 %** |\n\n#### Bytecode interpreter\n\n\u003e **Not implemented yet**\n\n## Extension\n\n\u003e enable using cargo `--features` flag\n\n- `unicode`: allows non-whitespace unicode as identifier.\n- `debug`: adds a new statement, debug statement, that is similar to print but instead of printing to `stdout`, it prints to `stderr`.\n- `loxlox`: provides the following functions that facilitate [LoxLox](https://github.com/benhoyt/loxlox).\n  - `getc()`: gets char from `stdin` as number (currently not handling `utf8` properly).\n  - `chr(ch)`: turns char code number into `string` (currently not handling `utf8` properly, if they are encountered `chr` will return `nil` instead).\n  - `exit(status)`: exits with given status code.\n  - `print_error(msg)`: prints message to `stderr` (I modify it so it can print any kind of Lox [`Value`](./loxi/src/interp/value.rs)).\n\n## TODO\n\nThese are from the challenges, I guess I'll add it as extension for the language and using cargo feature flag to enable it\n\n- [ ] Add support for C-style block comments (`/* ... */`)\n- [ ] Implement bitwise, shift, modulo, and conditional operators\n- [ ] Add support for comma expressions (like in C)\n- [ ] Add support for C-style conditional or \"ternary\" operator `?:`\n- [ ] Add option to raise a runtime error on division by zero\n- [ ] Make it a runtime error to access a variable that has not been initialized or been assigned\n- [ ] Add support for `break` and `continue` statements in a loop\n- [ ] Add anonymous function support\n- [ ] Extend the resolver to raise an error if a local variable is never used\n- [ ] Implement static methods (use `class` to mark a method as static)\n- [ ] Support \"getter\" and \"setter\" for class members (see the book on challenges section on classes chapter for the syntax)\n- [ ] Add support for string interpolation\n\nOther challenges but lower priority\n\n\u003e Reasons for lower priority including but not limited to\n\u003e\n\u003e - Implementing these as features will make programming more error-prone\n\n- [ ] Allow ordering with different type (e.g. `3 \u003c \"pancake\"`)\n- [ ] For `+` operator, if either of the operand is a string, convert the other operand to string.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrizaln%2Floxx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrizaln%2Floxx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrizaln%2Floxx/lists"}