Skip to content

An implementation of clox with the addtion of a x64 JIT compiler, threads, packages, generational gc and inlining

Notifications You must be signed in to change notification settings

JaimePolidura/lox-vm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lox-vm

An implementation of lox pending_bytecode interpreter described in "Crafting Interpreters" with a jit compiler, packages, threads etc.

New features

  • Basic x64 JIT Compiler When a function is called muliple times it is compiled into x64 native code. This is implemented in x64_jit_compiler.c and jit_compiler.c
  • Threads (vm_thread.h) When a function is called with "parallel" prefix, it will be run in other thread. Modified the garbage collector to run safely with multiple threads. Also implemented java l monitors value_as a synchronization tool.
  • Packages (package.h) Lox programs can consist of multiple files each of which can have public and private members (structs, methods and global variables)
  • Generational gc (generational_gc.h minor_gc.c major_gc.c) Implemented eden, survivor and memory regions with write barriers, card tables, mark compact, mark copy algorithms, mark bitmaps etc.
  • Compile time inlining (inliner.h) When a function is called with "inline" prefix, the function's pending_bytecode will get merged with the function's caller pending_bytecode.
  • Arrays

Features from "Crafting Interpreters" not implemented

  • OOP Inheritnace, classess with properties and methods are not implemented. Instead, they are replaced with C like structs, which only contains plain profile_data.
  • Closures

Examples

connection.lox

pub struct Connection {
    ip;
    port;
    writeBuffer;
    readBuffer;
}

pub fun acceptConnections() {
    sleep(500);

    var readBuffer[1024];
    var writeBuffer[1024];

    return Connection{
        "192.168.1.159",
        8888,
        readBuffer,
        writeBuffer
    };
}

pub fun readRequest(connection) {
    return nil;
}

main.lox

use "Connection.lox";

fun handleRequest(request) {
    ...
}

fun handleConnection(connection) {
    var request = inline Connection::readRequest(connection);
    inline handleRequest(request);
}

fun startServer() {
    while(true){
        var connection = Connection::acceptConnections();
        parallel handleConnection(connection);
    }
}

startServer();

About

An implementation of clox with the addtion of a x64 JIT compiler, threads, packages, generational gc and inlining

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published