C++/Go Inspired C Transpiler + Managed Runtime, including automatic memory management, green-threads, and pluggable allocators.
- Reference Counting: Configurable option (suffers from cycles)
- Mark-Sweep Garbage Collection: Conservative garbage collection with configurable thresholds
- Simple Allocator: Traditional malloc/free
- Pluggable Runtime: Switch allocators at compile-time via command-line flags
- Class System: Object-oriented programming with inheritance and virtual methods
- Constructor Syntax: Modern initialization with automatic memory allocation
- Method Calls: Dot and arrow notation with automatic
thisparameter injection
./build.sh tests/examples/test.jb# Reference counting (default)
./build.sh tests/examples/test.jb reference_count
# Mark-sweep garbage collection
./build.sh tests/examples/test.jb mark_sweep
# Simple malloc/free
./build.sh tests/examples/test.jb simple./build.sh tests/examples/test.jb mark_sweep --debug#include <stdio.h>
class Point {
int x;
int y;
Point(int nx, int ny) {
this->x = nx;
this->y = ny;
}
void print() {
printf("Point(%d, %d)\n", this->x, this->y);
}
virtual void move(int dx, int dy) {
this->x += dx;
this->y += dy;
}
};
int main() {
Point* p = new Point(3, 4);
p->print(); // Point(3, 4)
p->move(1, 1);
p->print(); // Point(4, 5)
return 0;
}typedef struct Node {
int value;
struct Node* next;
} Node;
Node* create_list(int n) {
Node* head = new Node;
head->value = n;
head->next = (n > 1) ? create_list(n-1) : NULL;
return head;
// Automatic reference counting or mark & sweep handles cleanup
}class Animal {
int age;
virtual void speak() {
printf("Animal sound\n");
}
};
class Dog : Animal {
Dog(int a) : Animal(a) {}
void speak() { // Override
printf("Woof! I'm %d years old\n", this->age);
}
};- ANTLR4 Grammar: Parses JBLang syntax into AST
- Type System: Resolves types, handles inheritance hierarchies
- Code Generator: Emits C code with runtime calls
- Runtime Integration: Links with runtime providing allocator, garbage collection, and green-thread scheduler
typedef struct {
void* (*alloc)(size_t bytes);
void (*dealloc)(void* ptr);
void (*gc)(void);
void (*inc_ref_count)(void* ptr, void* other);
void (*dec_ref_count)(void* ptr, size_t offset);
} RuntimeAllocator;- CMake
- C++23 compiler
- ANTLR4 runtime library
- Java runtime (for grammar compilation)
- Testing has only been performed on MacOS, milage with other OS's may vary
mkdir build && cd build
cmake ..
cmake --build .python run_cram_tests.py # Integration tests