Ruby IR
Intermediate Representation for Ruby code in Rusty Ruby, providing a foundation for optimization and code generation.
🎯 Project Overview
Ruby-IR is a crate that provides the intermediate representation (IR) for Ruby code compilation in the Rusty Ruby project. It defines the data structures and traversal utilities for representing Ruby code in a form suitable for optimization and code generation.
🌟 Key Features
- Abstract Syntax Tree (AST) Representation: Structured representation of Ruby code
- Traversal Utilities: Tools for navigating and manipulating IR nodes
- Serialization Support: Convert IR objects to and from serialized formats
- Optimization Framework: Foundation for code optimization passes
- Integration: Seamlessly works with other Rusty Ruby components
🚀 Quick Start
use *;
// Create IR nodes
let expression = Constant;
// Traverse and manipulate IR
;
let mut visitor = MyVisitor;
visitor.visit_expression;
🏗️ Architecture
Core Components
- Expressions: Represent Ruby expressions like constants, variables, method calls, etc.
- Statements: Represent Ruby statements like assignments, conditionals, loops, etc.
- Symbols: Represent Ruby symbols and identifiers
- Types: Represent Ruby types and type information
- Traversal: Utilities for visiting and manipulating IR nodes
Optimization Passes
- Constant Folding: Evaluate constant expressions at compile time
- Dead Code Elimination: Remove unreachable code
- Inline Expansion: Inline method calls for better performance
- Type Inference: Infer types for variables and expressions
🛠️ Development
# Build the project
# Run tests
# Build in release mode
📚 Usage Examples
Basic IR Creation
use *;
// Create a binary expression: 1 + 2
let left = Constant;
let right = Constant;
let add_expr = BinaryOp;
// Create an assignment statement
let variable = Variable;
let assignment = Assignment;
// Create a program
let program = Program ;
IR Traversal
use *;
let mut collector = ConstantCollector ;
collector.visit_program;
println!;
🤝 Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to help improve Ruby-IR.