Skip to content
/ clox Public

CLox is a high level language that uses byte-code interpretation technique for execution (VM is stack based).

License

Notifications You must be signed in to change notification settings

mstepan/clox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLox

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.

How to build and run

To create clox executable just run:

make 

To run compiled application, just execute:

make run

Run unit tests.

For unit tests install check library. On Mac OS just execute brew install check. For other platforms, see check-installation-page

High level architecture

Lexer

Creates tokens from source code stream.

Compiler.

Uses Lexer stream of tokens to generate bytecode representation. Compiler uses Pratt's top-down parsing technique.

VM

Stack based VM that executes generated bytecode.

Supported VM instructions

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

About

CLox is a high level language that uses byte-code interpretation technique for execution (VM is stack based).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published