Rusty Ruby Compiler
A modern, high-performance Ruby compiler and runtime written in Rust, featuring advanced compilation techniques and memory management.
π― Project Overview
Rusty Ruby is a complete Ruby implementation that combines the elegance of Ruby with the performance and safety of Rust. It features a multi-tier compilation architecture, advanced garbage collection, and a rich ecosystem of tools and libraries.
π Key Features
- Multi-tier Compilation: Interpreter, baseline compiler, and optimizing compiler for balanced performance
- Advanced Garbage Collection: Generational, incremental, and concurrent GC strategies
- JIT Compilation: Just-In-Time compilation for hot code paths
- FFI Interface: Seamless integration with C libraries
- Performance Analysis: Built-in profiler and debugging tools
- Register-based VM: Efficient virtual machine implementation
π Quick Start
use Ruby;
ποΈ Architecture
Compiler Pipeline
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Source Codeβ -> β Lexical β -> β Syntax β -> β AST β
β β β Analysis β β Analysis β β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β
βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Execution β <- β Execution β <- β VM β <- β IR β
β Results β β Engine β β Instructionsβ β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Multi-tier Compilation β
βββββββββββββββ¬ββββββββββββββ¬βββββββ
β β β
ββββββββΌβββββββ ββββββΌβββββββ ββββββΌβββββββ
β Interpreterβ β Baseline β β Optimizing β
β β β Compiler β β Compiler β
βββββββββββββββ ββββββββββββββ ββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Garbage Collection β
βββββββββββββββ¬ββββββββββββββ¬βββββββ
β β β
ββββββββΌβββββββ ββββββΌβββββββ ββββββΌβββββββ
β Generationalβ β Incrementalβ β Concurrentβ
β GC β β GC β β GC β
βββββββββββββββ ββββββββββββββ ββββββββββββββ
π Directory Structure
compilers/ruby/
βββ src/
β βββ lib.rs # Main entry point, Ruby runtime environment
β βββ vm.rs # Register-based virtual machine implementation
β βββ jit.rs # JIT compiler implementation
β βββ codegen.rs # Code generation (AST to IR to VM instructions)
β βββ architecture/ # Multi-tier compilation architecture
β β βββ mod.rs # Architecture module definition
β β βββ interpreter.rs # Interpreter implementation
β β βββ baseline_compiler.rs # Baseline compiler implementation
β β βββ optimizing_compiler.rs # Optimizing compiler implementation
β β βββ execution_engine.rs # Execution engine implementation
β β βββ hotness_detector.rs # Hotness detector implementation
β βββ gc/ # Garbage collection system
β β βββ mod.rs # GC module definition
β β βββ generational.rs # Generational garbage collector
β β βββ incremental.rs # Incremental garbage collector
β β βββ concurrent.rs # Concurrent garbage collector
β βββ profiler/ # Performance analysis and debugging tools
β βββ mod.rs # Tools module definition
β βββ profiler.rs # Profiler implementation
β βββ debugger.rs # Debugger implementation
β βββ visualizer.rs # Visualization tool implementation
βββ tests/ # Test suite
β βββ ffi_test.rs # FFI tests
β βββ gc_test.rs # Garbage collector tests
β βββ jit_test.rs # JIT compiler tests
β βββ vm_test.rs # Virtual machine tests
β βββ runtime_test.rs # Runtime tests
β βββ performance_test.rs # Performance tests
β βββ optimization_test.rs # Optimization tests
βββ Cargo.toml # Dependency configuration
π οΈ Development
# Build the project
# Run tests
# Run specific test
# Build in release mode
π Core Modules
Frontend
- Lexical Analysis: Converts source code to token stream
- Syntax Analysis: Builds abstract syntax tree (AST)
- Semantic Analysis: Checks types, scopes, etc.
Virtual Machine
- Register-based: Uses 16 general-purpose registers
- Instruction Set: Load/store, arithmetic, comparison, logic, control flow, method calls
- Execution Environment: Manages global, local, instance, and class variables
Garbage Collection
- Mark-Sweep Algorithm: Marks root objects, sweeps unmarked objects
- Memory Management: Tracks memory usage, automatically reclaims unused objects
- Root Objects: Global variables, local variables, instance variables, class variables
JIT Compiler
- Just-In-Time Compilation: Compiles hot code paths to machine code
- Optimization: Type inference, inlining, loop optimization, etc.
- Performance: Significantly faster execution for hot code
FFI Interface
- Dynamic Library Loading: Loads external C libraries
- Function Calling: Calls C functions and handles return values
- Type Conversion: Converts between Ruby values and C types
π€ Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to help improve Rusty Ruby.
π Future Development
- Complete Ruby Language Support: Implement all Ruby syntax features
- Advanced Optimization: More complex JIT optimizations, inline caching, escape analysis
- Multi-platform Support: Support for more operating systems and hardware architectures
- Debugging Tools: Enhanced debugger, performance analysis tools
- Garbage Collection Optimization: More efficient GC algorithms
- Concurrency Support: Better concurrent processing capabilities
- Ecosystem: Complete Ruby ecosystem, including standard library and gems