https://github.com/ZaneDubya/LoxScript
A bytecode compiler and virtual machine for the Lox language, in C#. Includes a C# / Lox object interface generator and bytecode serialization.
https://github.com/ZaneDubya/LoxScript
bytecode compiler lox lox-language virtual-machine
Last synced: 2 months ago
JSON representation
A bytecode compiler and virtual machine for the Lox language, in C#. Includes a C# / Lox object interface generator and bytecode serialization.
- Host: GitHub
- URL: https://github.com/ZaneDubya/LoxScript
- Owner: ZaneDubya
- License: mit
- Created: 2020-04-20T21:54:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-02T21:27:24.000Z (4 months ago)
- Last Synced: 2025-04-25T00:53:16.304Z (2 months ago)
- Topics: bytecode, compiler, lox, lox-language, virtual-machine
- Language: C#
- Homepage:
- Size: 443 KB
- Stars: 19
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LoxScript
LoxScript is a bytecode compiler and virtual machine ("Gears") for Bob Nystrom's [Lox language](http://craftinginterpreters.com/the-lox-language.html), both written in C#.
The LoxScript bytecode virtual machine is called [Gears](https://github.com/ZaneDubya/LoxScript/tree/master/XptScriptLib/Core/Scripting/LoxScript/VirtualMachine). Gears executes bytecode created by the LoxScript compiler. The output of Gears matches the reference "clox" virtual machine described in Chapters 14-30 of Bob's book [Crafting Interpreters](http://craftinginterpreters.com). However, the internal implementation of the virtual machine is different, and the bytecode generated by the Gears compiler will not run on clox.
Improvements over Lox/clox:
- Compiler can write bytecode to a binary file and load/run this at runtime.
- Native interfaces allow Lox files to interact with native C# functions and objects.
- Support for switch statement! This only took hours, and the code is horrifying.Performance:
- Gears runs the reference 'fibonnaci' benchmark roughly 69x slower than native c# code.