C++ implementation of Robert Nystrom's toy language lox
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmarks
deps
src
tests
tool
.gitignore
.travis.yml
CMakeLists.txt
LICENSE
README.md README: Updated benchmarks Oct 28, 2018

README.md

Loxx

Master Build Status
Development Build Status

Loxx is a C++14 implementation of Bob Nystrom's toy language, Lox. Lox is syntatically similar to C and uses strong, dynamic types. For example:

var sum = 0;

for (var i = 0; i < 10; i = i + 1) {
  sum = sum + i;
}

print sum;

For more details on Lox's syntax, check out the description in Bob's book.

Compilation

Loxx uses no dependencies other than the C++14 standard library, so make sure you have a compiler that supports that standard. To run the build, you'll need CMake version 3 or greater. Once you've downloaded the source, in your terminal enter the root of the Loxx source tree and run:

mkdir build && cd build
cmake ..
make

Usage

Lox is an interpreted language. To run stuff interactively using a REPL, do

./loxx

Alternatively, execute source files like so

./loxx <your source filename>

Tests

Testing takes the form of a series of functional end-to-end tests that I effectively stole from Bob Nystrom's implemenations of Lox. To run the tests, use the python test-runner in the tests directory:

python tests/run_tests.py build/loxx

Benchmarks

Loxx is implemented as a bytecode virtual machine and performs reasonably well without having to micro-optimise the code and fine-tune compiler arguments. Here are some execution times (in seconds) from running each of the files in the benchmarks directory 20 times on an Intel i5-4300U (1.90 GHz) with a 3 MB L3 cache:

File Min. Mean Median Max. Std. Dev.
binary_trees.lox 0.78 0.80 0.79 0.88 0.02
equality.lox 4.92 4.97 4.96 5.11 0.05
fib.lox 0.17 0.18 0.18 0.20 0.01
invocation.lox 0.60 0.62 0.61 0.79 0.04
method_call.lox 0.33 0.34 0.33 0.35 0.01
properties.lox 0.73 0.74 0.73 0.77 0.01
string_equality.lox 2.11 2.12 2.12 2.14 0.01

Compared to Clox, Bob Nystrom's C implementation, this isn't so bad:

File Min. Mean Median Max. Std. Dev.
binary_trees.lox 0.58 0.59 0.59 0.60 0.01
equality.lox 5.32 5.35 5.33 5.51 0.05
fib.lox 0.12 0.12 0.12 0.13 0.00
invocation.lox 0.48 0.49 0.49 0.49 0.00
method_call.lox 0.27 0.27 0.27 0.28 0.00
properties.lox 0.66 0.66 0.66 0.67 0.00