A modern systems programming language compiler built in Rust, featuring LLVM-based code generation, static typing, and memory-aware constructs.
- Fast Lexical Analysis: Token-based lexer using the Logos crate
- LALR(1) Parser: Grammar-driven parsing with LALRPOP
- Static Type System: Type inference with explicit type annotations
- LLVM Code Generation: Native binary compilation via Inkwell
- Semantic Analysis: Symbol table management and type checking
- Memory Management: Built-in memory allocation primitives (
alloc,shared alloc,transfer) - Cross-Platform: Automatic target detection for Linux, macOS, and Windows
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Source Code βββββΆβ Lexer βββββΆβ Parser β
β (*.pebble) β β (tokens.rs) β β (parse.rs) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Native Binary ββββββ LLVM Codegen ββββββ AST β
β (executable) β β (codegen/) β β (ast.rs) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β² β
βββββββββββββββββββ βββββββββββββββββββ
β Target Machine β β Semantic Check β
β & Linker β β (semantic/) β
βββββββββββββββββββ βββββββββββββββββββ
let x = 42; // Type inference
let name: String = "Pebble"; // Explicit typing
fn add(a: int, b: int) -> int {
return a + b;
}
print(argc); // Print command-line argument count
print(argv); // Print command-line arguments array
let ptr = alloc(42); // Allocate memory
let shared = shared alloc(data); // Shared allocation
let moved = transfer(ptr); // Transfer ownership
- Rust 1.70+ with Cargo
- LLVM 18.1 development libraries
- GCC or Clang (for linking)
git clone https://github.com/mro95/pebble-rs.git
cd pebble-rs
cargo build --release# Create a Pebble source file
echo 'print("Hello, Pebble!");' > hello.pebble
# Compile and run
cargo run hello.pebble
./output_binInput (example.pebble):
print(argv);
print(argc);
Compilation:
$ cargo run example.pebble
Detected target: x86_64-unknown-linux-gnu
LLVM IR written to output.ll
Object file written to output.o
Successfully linked executable with gcc
Binary written to output_binExecution:
$ ./output_bin hello world
["./output_bin", "hello", "world"]
3src/
βββ main.rs # Compiler driver and CLI
βββ lib.rs # Library root and module declarations
βββ lexer.rs # Token stream processing
βββ tokens.rs # Token definitions and lexer rules
βββ parse.rs # Parser interface
βββ ast.rs # Abstract Syntax Tree definitions
βββ codegen/ # LLVM code generation
β βββ mod.rs # Code generator core
β βββ expressions.rs # Expression compilation
β βββ statements.rs # Statement compilation
β βββ functions.rs # Function compilation
β βββ printing.rs # Print statement implementation
β βββ types.rs # Type system integration
βββ semantic/ # Static analysis
β βββ mod.rs # Semantic analyzer
β βββ scope.rs # Symbol table management
β βββ expr.rs # Expression type checking
β βββ stmt.rs # Statement analysis
β βββ type.rs # Type system and error handling
βββ grammar/
βββ grammar.ebnf # Language grammar specification
βββ parser.lalrpop # LALRPOP parser definition
Run the test suite:
cargo testThe project includes comprehensive tests for:
- Parser functionality (
tests/parser_test.rs) - Type system validation
- Code generation accuracy
- Primitive Types:
int,String,void - Type Inference: Automatic type deduction where possible
- Array Types:
Array<T>with bounds checking - Function Types: First-class function support
argc: Command-line argument count (int)argv: Command-line arguments array (Array)
- Function declarations with parameters and return types
- Block scoping with proper variable shadowing
- Return statements with type validation
The compiler generates optimized LLVM IR and produces native executables:
- Target Detection: Automatic host architecture detection
- Cross-compilation: Support for multiple target architectures
- Optimization: LLVM optimization passes for performance
- Debug Info: Structured debug information generation (planned)
- 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
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
- logos
0.15.1- Fast lexical analysis - lalrpop
0.22.2- Parser generator - inkwell
0.6.0- LLVM bindings for Rust - thiserror
2.0- Error handling macros