Skip to content

Latest commit

 

History

History
30 lines (19 loc) · 1.41 KB

README.md

File metadata and controls

30 lines (19 loc) · 1.41 KB

loxjit

This is a simple lox JIT compiler targeting x64. It is essentially a port of clox, but generating x64 assembly instead of bytecode for the interpreter. Under the hood dynasm-rs is used to assemble the instructions.

loxjit uses inline caches (ICs) to speed up property lookups and method calls.

Another optimization that has a noticeable effect is the removal of hash lookups for accessing global variables. Instead, global variables are addressed by an index assigned by the compiler.

Blog Post

You can read more loxjit in this blog post.

Compiling

Nightly Rust is required to compile loxjit.

Running LoxLox

loxjit supports running LoxLox, a Lox interpreter written in Lox. Support is enabled using the LOX_LOX_EXTENSIONS constant in lib/common.rs (defaults to true). To run a lox script in LoxLox, run cargo run --release lox.lox < script.lox.

Running LoxLox inside of LoxLox

To enable LoxLox to run itself the getc extension considers a null byte as EOF. Therefore, when running

(cat lox.lox; printf "\0"; cat script.lox) | cargo r --release lox.lox

first, loxjit will run the first LoxLox instance, which will read stdin until the null byte is encountered. Then it will start to run the second LoxLox instance, which will continue to read stdin and execute script.lox.