Advanced Hybrid Architecture
Easy to read. Powerful to wield.
A modern programming language with an LLVM backend โ designed to be understood at a glance, yet strong enough to build real software.
AHA! is built on a simple belief: a language should feel obvious when you read it, and effortless when you run it. No magic, no surprises โ just tools that work the way you expect.
- โก LLVM-Powered: Compiles source to LLVM IR and executes it through a built-in JIT โ native-level performance from day one.
- ๐ง Expressive Type Discipline: First-class
Int,Bool, andStringtypes with a real type-checking pass. Type errors are caught at compile time, not at runtime. - ๐ข Boolean Algebra That Composes: All boolean-producing operators (
==,!=,<,>,<=,>=,&&,||) returnInt0/1โ so logic results flow straight into arithmetic:is_even(n) * 100just works. - ๐ฆ Strings Done Right: Strings are a real
{pointer, length}struct โ safe concatenation,==/!=comparison, and an O(1)len()builtin. - ๐ Modern Control Flow:
if/else,while, andforloops withbreak/continue, functions with parameters,return, forward references, and mutual recursion. - ๐ Module System:
use "file"imports functions and structs from another.ahafile โ recursive resolution, cycle detection, zero config. - ๐งฉ Enums & Pattern Matching:
enumkeyword with unit and tuple variants,matchexpressions with destructuring, wildcard arms, and nested patterns โ compiled to efficient LLVM switch + phi. - ๐ ๏ธ Honest Tooling: A clean CLI (
--file,--emit-ir,--version), a VS Code syntax-highlighting extension, and a CI pipeline that runs 581+ tests on every commit.
- Rust (stable toolchain)
- LLVM 14 with Clang 14 and Polly
sudo apt-get update
sudo apt-get install -y llvm-14-dev clang-14 libpolly-14-devgit clone https://github.com/qwetls/aha-lang.git
cd aha-lang
cargo build --releasecargo run --release -- --file example.ahaCLI options:
| Option | Description |
|---|---|
--file <path> |
Source file to compile and execute |
--dir <path> |
Directory for module resolution (default: .) |
--emit-ir <path> |
Save the generated LLVM IR to a file |
--version |
Print the compiler version |
--help |
Show usage information |
Create example.aha:
// AHA! is expression-oriented โ the last expression is the result
let x = 10;
let y = 20;
if x > y {
x
} else {
y
}
Run it:
cargo run --release -- --file example.ahaExpected output:
--- AHA! COMPILER ---
Reading file: example.aha
[1] LEXING...
[2] PARSING...
Parsing successful!
[3] CODE GENERATION...
LLVM IR generated successfully!
--- LLVM IR OUTPUT ---
; ModuleID = 'aha_module'
...
----------------------
[4] EXECUTION (JIT)...
Program executed successfully. Result: 20
Functions & mutual recursion:
fn is_even(n) {
n % 2 == 0
}
fn is_odd(n) {
if is_even(n) { 0 } else { 1 }
}
let count = 0;
for i 0..10 {
if is_odd(i) {
count = count + 1;
}
}
count // 5
Strings:
let name = "world";
let greeting = "Hello, " + name;
print_str(greeting); // Hello, world
print(len(name)); // 5
Enums & pattern matching:
enum Day { Mon, Tue, Wed, Thu, Fri, Sat, Sun }
fn is_weekend(d: Day) -> int {
match d {
Sat => 1,
Sun => 1,
_ => 0,
}
}
let d = Sat()
is_weekend(d) // 1
enum Op { Add(int, int), Sub(int, int) }
fn calc(op: Op) -> int {
match op {
Add(a, b) => a + b,
Sub(a, b) => a - b,
_ => 0,
}
}
calc(Add(10, 20)) // 30
Source Code โ Lexer โ Parser (Pratt) โ AST โ Code Generator โ LLVM IR โ JIT Execution
| Stage | Module | What it does |
|---|---|---|
| Lexer | src/lexer.rs |
Tokenizes source: identifiers, integers, strings (with escapes), operators, line & block comments |
| Parser | src/parser.rs |
Pratt parser producing the AST โ expression-oriented, with correct operator precedence |
| Type System | src/types.rs |
AhaType + TypedValue; compile-time checks for binary/prefix operators |
| Codegen | src/codegen.rs |
LLVM IR generation via inkwell: functions (with return-type inference), loops, strings, arrays, C-runtime linkage (malloc, memcpy, strcmp) |
| Driver | src/main.rs |
CLI: lex โ parse โ codegen โ print IR โ JIT execute |
| Type | Notes |
|---|---|
Int |
64-bit integer โ the universal numeric type |
Bool |
true / false literals; produced by ! |
String |
"..." with escape sequences (\n, \t, \\, \", \r, \0) |
Enum |
enum Name { A, B(int), C(int, int) } โ unit or tuple variants, matched with match |
Struct |
struct Name { field: type } โ named fields, created with Name { field: val } |
| Category | Operators |
|---|---|
| Arithmetic | + - * / % |
| Comparison | == != < > <= >= (โ Int 0/1) |
| Logical | && || (โ Int 0/1) |
| Prefix | -x, !x |
| Assignment | x = value |
if cond { ... } else { ... }โ an expression; the last expression of each branch is the valuewhile cond { ... }for x a..b { ... }โ range loop withbreak/continue
| Builtin | Description |
|---|---|
print(int) |
Print an integer |
print_str(string) |
Print a string |
len(string) |
Length in O(1) |
abs(x), min(a, b), max(a, b) |
Numeric helpers |
Import functions and structs from another .aha file:
use "math"
use "utils"
let result = add(2, 3);
use "math"resolves tomath.ahain the same directory- Imports are recursive โ if
math.ahauses"helper", that file is resolved too - Cycle detection prevents infinite loops
- CLI:
aha run main.aha --dir ./src
- Lexer & Pratt parser with full error reporting
-
Int,Bool,Stringtypes - Arithmetic, comparison,
&&/||, prefix, assignment -
if/else,while,for(withbreak/continue) - Functions: parameters,
return, forward references, mutual recursion, string params & returns - String struct, concatenation, comparison,
len() - Array literals & indexing (codegen)
- Block comments, string escapes,
!=fix, type-checking pass - Builtins:
print,print_str,abs,min,max,len - JIT execution via LLVM
- CLI (
--file,--emit-ir,--version) - VS Code syntax-highlighting extension (
editors/vscode) - Module system:
use "file"for multi-file compilation (v1.5.0) - CI:
cargo check, 581+ tests,cargo build --release
- Struct codegen & field access at runtime
- Type inference & annotations
- Generics / parametric types (List, Map<K,V>)
- Module system (
use "file"imports, multi-file compilation) โ v1.5.0 - Resource lifetimes โ compiler-inserted free, scope-based auto-free for Map/List
- Actor-model concurrency (message passing, threading)
- Enum keyword + pattern matching (
match, destructuring, wildcards) โ v1.6.0 - AOT compilation (
--emit-exe)
- FFI support โ call C libraries from AHA!
- Error handling โ
Result<T, E>type - TCP/UDP sockets โ networking foundation
- HTTP server โ built-in HTTP/1.1
- JSON ser/deser โ data interchange
- Async I/O โ event loop, non-blocking
- String builder โ efficient response building
- Game engine foundation โ audio, input, rendering
- Window management (SDL/GLFW integration via FFI)
- Package manager (
aha install) - Self-hosting โ the AHA! compiler written in AHA! (long-term)
We welcome contributions of all kinds โ bug reports, feature ideas, or code.
See CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License. See the LICENSE file for details.
Great tools don't add complexity โ they remove it. AHA! was built on one simple principle: a language easy enough to read like prose, powerful enough to write like a system. No ceremony, no boilerplate โ just clear code that runs at native speed.
Join us in writing the next chapter of computing.