Skip to content

Going through CraftingInterpreters C part but implementing it in C++

License

Notifications You must be signed in to change notification settings

MartinHelmut/cpplox

Repository files navigation

CppLox

Going through CraftingInterpreters C part but implementing it in C++. Note: This code is written on a Mac and not tested on other systems. Therefore tooling is used out of this perspective as well.

Contents

Required tools

cmake

Install on Mac (if not already present):

brew install cmake

LLVM

Tools from the LLVM toolchain are used. To install LLVM on Mac run:

brew install llvm

Tools used from the toolset:

  • clang-tidy
  • clang-format

To link these tools run:

ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"

Ninja

You can install Ninja on Mac via brew:

brew install ninja

Setup

Clone the project with all submodules:

git clone --recurse-submodules -j8 git@github.com:MartinHelmut/cpplox.git

Update

git pull && git submodule update --init

Build

Debug

Build the configuration files with cmake:

cmake -GNinja -DDEBUG=1 -DCMAKE_BUILD_TYPE=Debug --build build/debug

Build the application with Ninja:

ninja -C build/debug

Release

Build the configuration files with cmake:

cmake -GNinja -DDEBUG=0 -DCMAKE_BUILD_TYPE=Release --build build/release

Build the application with Ninja:

ninja -C build/release

Run

After building the application you can either run the client in debug or release mode:

# Debug
./build/debug/lox/client/Client

# Release
./build/release/lox/client/Client

Tests

You can build the application as you like (e.g. in debug mode) and run unit tests via:

./build/debug/lox/tests/Tests

Profiling

There is a special profiling build running cmake with PROFILE=1:

# Create config files
cmake -GNinja -DDEBUG=0 -DPROFILE=1 -DCMAKE_BUILD_TYPE=Release --build build/profile
# Build profile runner
ninja -C build/profile

Running the profiler executable will generate a lox-profile.json file that can be used with any Chromium based browser tracing tool, e.g. chrome://tracing. Just drag and drop the file into the tracing view. To generate the file run:

./build/profile/lox/client/Client

License addition

Just to be sure, here a reference to the license model of crafting interpreters: https://github.com/munificent/craftinginterpreters/blob/master/LICENSE

External dependencies

List of externally used dependencies:

About

Going through CraftingInterpreters C part but implementing it in C++

Topics

Resources

License

Stars

Watchers

Forks