A modern, JIT-compilable programming language with automatic memory management (garbage collection) and a virtual machine runtime.
CJ is a modern programming language with a hybrid type system that supports both static typing with explicit type annotations and dynamic typing with type inference:
- Virtual Machine: Custom bytecode VM with stack-based execution
- Garbage Collection: Automatic memory management with configurable GC algorithms
- JIT Compilation: Just-in-time compilation for performance optimization
- Modern Syntax: Clean, expressive syntax similar to JavaScript/TypeScript
- Built-in Types: Numbers, strings, booleans, arrays, objects, functions
- Error Handling: Comprehensive error reporting and recovery
- Hybrid Type System: Static typing with type annotations and dynamic typing with inference
- Variables (
var,const) with optional type annotations - Functions with closures
- Control flow (
if/else,while,for) - Object-oriented programming (
class, inheritance) - Exception handling (
try/catch/finally) - Module system (
import/export)
- Virtual Machine: Stack-based bytecode interpreter
- Garbage Collector: Mark-and-sweep, copying, and generational GC
- JIT Compiler: x86-64 native code generation with optimizations
- Memory Management: Automatic allocation and deallocation
- Built-in Functions: Type checking, I/O, string manipulation
- Compiler: Source-to-bytecode compilation
- REPL: Interactive read-eval-print loop
- Debugger: Breakpoints, stack traces, variable inspection
- Profiler: Performance analysis and optimization hints
- C++20 compatible compiler (GCC 10+, Clang 12+, MSVC 2019+)
- CMake 3.20+
- Git
git clone https://github.com/Flickyyy/Cj.git
cd Cj
mkdir build && cd build
cmake ..
make -j$(nproc)# Run the REPL
./bin/cj-repl
# Execute a CJ file
./bin/cj-vm ../examples/hello.cj
# Compile a CJ file
./bin/cj-compiler ../examples/fibonacci.cj -o fibonacci.cjb
# Run the complete language demo
./bin/examples/complete_demo
# Run the SSA (Static Single Assignment) demo
./bin/examples/ssa_demo
# View CJ standard library examples (future syntax)
cat ../stdlib/README.md
cat ../examples/stdlib_demo.cj// Dynamic typing with type inference
var name = "CJ Language";
var version = 0.1;
var is_ready = true;
// Static typing with explicit type annotations
var age: int = 25;
var price: float = 19.99;
var message: string = "Hello";
var active: bool = true;
// Constants
const PI = 3.14159;
const MAX_SIZE = 1000;// Function declaration
function greet(name) {
return "Hello, " + name + "!";
}
// Function expression
var add = function(a, b) {
return a + b;
};
// Arrow function (planned)
var multiply = (a, b) => a * b;// Conditional statements
if (age >= 18) {
print("Adult");
} else {
print("Minor");
}
// Loops
for (var i = 0; i < 10; i++) {
print(i);
}
while (condition) {
// loop body
}// Arrays
var numbers = [1, 2, 3, 4, 5];
var mixed = [1, "hello", true, nil];
// Objects
var person = {
name: "Alice",
age: 30,
greet: function() {
return "Hi, I'm " + this.name;
}
};class Animal {
constructor(name) {
this.name = name;
}
speak() {
print(this.name + " makes a sound");
}
}
class Dog extends Animal {
speak() {
print(this.name + " barks");
}
}Cj/
├── include/cj/ # Header files
│ ├── common.h # Common definitions
│ ├── lexer/ # Lexical analysis
│ ├── parser/ # Syntax analysis
│ ├── ast/ # Abstract syntax tree
│ ├── ir/ # Intermediate representation
│ ├── vm/ # Virtual machine
│ ├── gc/ # Garbage collector
│ ├── jit/ # JIT compiler
│ └── types/ # Type system
├── src/ # Source files
│ ├── lexer/ # Lexer implementation
│ ├── parser/ # Parser implementation
│ ├── ast/ # AST implementation
│ ├── ir/ # IR implementation
│ ├── vm/ # VM implementation
│ ├── gc/ # GC implementation
│ ├── jit/ # JIT implementation
│ └── utils/ # Utilities
├── tests/ # Test files
├── examples/ # Example programs
├── docs/ # Documentation
└── tools/ # Development tools
- Tokenizes source code into lexical tokens
- Handles keywords, operators, literals, identifiers
- Supports comments and whitespace handling
- Recursive descent parser
- Generates Abstract Syntax Tree (AST)
- Error recovery and reporting
- Tree representation of parsed code
- Visitor pattern for traversal
- Pretty printing and analysis
- Stack-based bytecode instructions
- Control flow graph representation
- Optimization passes
- Stack-based execution engine
- Built-in function support
- Error handling and debugging
- Automatic memory management
- Multiple GC algorithms (mark-and-sweep, copying, generational)
- Concurrent and incremental collection
- Native code generation
- Optimization passes (constant folding, dead code elimination)
- Platform-specific backends (x86-64, ARM64)
cmake -DCMAKE_BUILD_TYPE=Debug ..
make -j$(nproc)# Build and run all tests
make test
# Run specific test
./bin/cj-tests
# Run manual tests
./bin/tests/manual_test_lexer
./bin/tests/manual_test_parserThe project follows the Google C++ Style Guide. Use clang-format for consistent formatting:
# Format all source files
find . -name "*.cpp" -o -name "*.h" -o -name "*.hpp" | xargs clang-format -iComprehensive documentation is available in the docs/ directory:
- Compiler Architecture: Complete guide to the CJ compiler toolchain, components, and concepts
- SSA Implementation: Deep dive into Static Single Assignment form and optimization techniques
The documentation covers essential compiler concepts including:
- Compilation Pipeline: Lexer → Parser → AST → IR → Optimization → Code Generation
- Static Single Assignment (SSA): Modern intermediate representation for advanced optimizations
- Dominance Analysis: Control flow analysis for phi function placement
- JIT Compilation: Runtime code generation and optimization
- Garbage Collection: Automatic memory management
- Type System: Static typing with inference and compatibility rules
Generate API documentation with Doxygen:
# In build directory
make docs
# Open docs/html/index.html- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Google C++ Style Guide
- Write comprehensive tests for new features
- Document public APIs with Doxygen comments
- Use meaningful variable and function names
- Keep functions small and focused
- Basic lexer and parser
- AST generation and traversal
- IR generation
- Virtual machine with basic instructions
- Garbage collector (mark-and-sweep)
- JIT compiler framework
- SSA (Static Single Assignment) form
- SSA-based optimizations (constant propagation, dead code elimination)
- REPL and command-line tools
- Complete language feature implementation
- Module system
- Standard library
- Improved error messages
- Performance optimizations
- Object-oriented programming
- Advanced GC algorithms
- Debugging tools
- Package manager
- Language server protocol
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by modern language design principles
- Built with modern C++ best practices
- Uses Google Test for unit testing
- Documentation generated with Doxygen
- GitHub: Flickyyy/Cj
- Issues: GitHub Issues
CJ Language - A modern language for the future ✨