Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 1.71 KB

README.md

File metadata and controls

47 lines (33 loc) · 1.71 KB

bslox

This project follows Bob Nystrom's excellent book, Crafting Interpreters which takes you through the process of writing an interpreter for a language called Lox.

The book describes two implementations. The first in Java and is a tree-walking interpreter. I have ported that version to Swift in my other project, slox. The final part of the book describes a bytecode interpreter in C. This is my Swift port of the bytecode interpreter. I also ported this bytecode interpreter to C++ in cloxpp.

The book is being released as chapters are completed, one chapter at a time.

Progress

Code from the following chapters is implemented in this port:

  1. Chunks of Bytecode.
  2. A Virtual Machine.
  3. Scanning on Demand.
  4. Compiling Expressions.
  5. Types of Values.
  6. Strings.
  7. Hash Tables. (no code required, will use Dictionary)
  8. Global Variables.
  9. Local Variables.
  10. Jumping Back and Forth.

Tests

The test suite is from the reference C implementation. To run the tests:

dart tool/bin/test.dart chap23_jumping --interpreter .build/release/bslox

The command specifies .build/release/bslox as the binary, which is where it ends up after running this command to compile the code:'

swift build -c release

For the test suite to run, you need to have the Dart programming language SDK installed. After that, you need to get the test runners dependencies by going to the tool directory and running:

pub get

Goals & Design

The goal is to get as close as possible to the C reference implementation in performance, while taking advantage of Swift's features.

License

MIT