- Notifications
You must be signed in to change notification settings - Fork0
mrjameshamilton/clox
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is an implementation of the C Lox compiler fromCrafting Interpreters.The implementation is mostly the same as in the book but with the following changes:
- Constants use 8 or 16-bit indices.
- New instructions:
OP_ZERO
push 0 onto the stackOP_ONE
push 1 onto the stackOP_MINUS_ONE
push -1 onto the stackOP_INTEGER
pushes an 8-bit integer onto the stackOP_INTEGER_16
pushes a 16-bit integer onto the stackOP_CONSTANT_16
push a 16-bit indexed constant onto the stack
- New native functions:
read()
reads a byte fromstdin
ornil
if end of streamutf(byte, byte, byte, byte)
converts 1, 2, 3, or 4 bytes into a UTF stringprinterr(string)
prints a string tostderr
exit(number)
exits with the specific exit code
These additions allow runningLox.lox, an Lox interpreter written in Lox. In particular, Lox.lox introduces more constants than the original limit 255 per-chunk in the original clox implementation and requires the 4 native functions.
$ gcc src/*.src -O3 -o clox
$ ./clox examples/helloworld.lox