CLox is a high level language that uses byte-code interpretation technique for execution. VM is stack based. All code written in good old C.
To create clox
executable just run:
make
To run compiled application, just execute:
make run
For unit tests install check library. On Mac OS just execute brew install check
. For other platforms, see check-installation-page
Creates tokens from source code stream.
Uses Lexer stream of tokens to generate bytecode representation. Compiler uses Pratt's
top-down parsing technique.
Stack based VM that executes generated bytecode.
Opcode | Description | Total size, bytes |
---|---|---|
OP_CONST <1 byte index> | Load single value from constant pool to VM stack using 1 byte index. | 2 |
OP_CONST_LONG <3 bytes index> | Load constant stored in 3 bytes to VM stack. Bytes store in little-endian order (least-significant first) | 4 |
OP_ADD | Add two values from top of VM stack and push result back. | 1 |
OP_SUBTRACT | Subtract two values from top of VM stack and push result back. | 1 |
OP_MULTIPLY | Multiply two values from top of VM stack and push result back to VM stack. | 1 |
OP_DIVIDE | Divide two values from top of VM stack and push result back to VM stack. | 1 |
OP_NEGATE | Negate last value on top of VM stack. | 1 |
OP_RETURN | Return from function execution or just from VM execution | 1 |
OP_TRUE | Load true literal to VM stack | 1 |
OP_FALSE | Load false literal to VM stack | 1 |
OP_NIL | Load Nil literal to VM stack | 1 |