Pine is a statically typed, compiled programming language designed for learning, experimentation, and building a clean understanding of how compilers work. It features a simple syntax, first-class functions, and a clear compilation pipeline that exposes each stage from tokenization to LLVM IR generation.
This project includes a CLI compiler called pinec, which can build, analyze, and run Pine programs.
- Statically typed
- First-class functions
- Explicit function signatures
- Local variables with type annotations
- Arithmetic expressions
- Multiple compiler stages (tokens, AST, LLVM IR)
- Native executable output
pine/
βββ examples/
β βββ main.alp
βββ crates/
β βββ lexer/
β βββ parser/
β βββ analyzer/
β βββ linker/
β βββ codegen/
β βββ cli/
βββ tools/
β βββ pinec/
Create a file with the .alp extension:
fn add(n1: i32, n2: i32) -> i32 {
return n1 + n2
}
fn main() -> i32 {
let result: i32 = add(10, 20);
return result;
}
pinec build -s examples/main.alpThis will:
- Lex the source
- Parse it into an AST
- Type-check the program
- Generate LLVM IR
- Produce a native executable
The output binary will be created at:
./examples/main./examples/mainOne of Pineβs goals is transparency. You can inspect each compiler stage using subcommands.
Generate and print the token stream:
pinec build -s examples/main.alp tokensUseful for:
- Debugging lexer issues
- Understanding how source code is tokenized
Generate the AST and export it as a Graphviz DOT file:
pinec build -s examples/main.alp astYou can visualize it with:
dot -Tpng ast.dot -o ast.pngGenerate LLVM Intermediate Representation:
pinec build -s examples/main.alp llvm-irThis is useful for:
- Learning LLVM
- Debugging code generation
- Future optimizations
-
Primitive types:
i32i64u32u64booleanunit
-
Functions are first-class values
-
Function calls are type-checked using structural unification
-
All identifiers must be defined before use
Example:
fn mul(a: i32, b: i32, c: i32) -> i32 {
return a * b * c
}
fn main() {
let sum = add(10, 20);
let diff = sub(40, 10);
let prod = mul(1, 2, 3);
let quo = div(8, 4);
return sum + diff + prod + quo;
}
Output:
68
Contributions are welcome!
- Open issues for bugs or feature requests
- Submit pull requests with clear descriptions
- Keep changes small and focused
Apache License Version 2.0
Pine is a learning-focused language, but it is built with real compiler principles. If youβre interested in compilers, type systems, or LLVM, this project is meant to grow with you.
Happy hacking π²