Skip to content

hashemi/bslox

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

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

About

Lox bytecode VM written in Swift - Based on Part III of Bob Nystrom's Book "Crafting Interpreters"

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published