Code Monkey home page Code Monkey logo

rlox's Introduction

rlox

A rust implementation of the bytecode VM from crafting interpreters.

Heavlily inspired by rlox.

Todo:

  • Clean up all the fixme and todos in the code
  • Set up a proper test suite for rlox using the craftinginterpreters test harness
  • Bench rlox against clox
  • Start profiling and doing optimizations
  • Fix module

Main differences between my rlox and clox

  1. Functions are compiled into FunctionChunks that live on a vector in the compiler, runtime references to them are LoxFunction opcodes that hold an index into that vector
  2. Same idea for classes with ClassChunks. Due to this we can inherit superclasses at compile time instead of runtime
  3. Variable resolution was moved into it's own struct, Resolver, to manage the recursive nature of it. It doesn't 100% work to Lox spec, but it works for simple closures
  4. For both the Resolver and the Compiler, the linked-list structure of Compilers in clox is replaced with a vector acting as a stack of compilers, and a few "currently targetting this" struct values and functions.
  5. Only closures and class instances are "heap" allocated. The other values (double, string, bool) live on the rust stack and are automatically dropped by the rust runtime when they leave the lox vm stack. The heap allocated values use a "pointer" value which indexes into the "heap", which is just a vector that gets shuffled around a bit
  6. The gc ended up being quite different due to my choice of a vector to hold the HeapObj values, but it still implements mark-sweep and it works :).
  7. The VM is split into two parts, one that holds all the compilation information and reads off instructions from it (VM) and one that holds the stack and the heap and is responsible for all the execution state (VMState)

rlox's People

Watchers

Nafi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.