A C++ reimplementation of teac targeting AArch64 Darwin (macOS ARM64) assembly. Written in C++23 with Flex/Bison for lexing and parsing.
TeaLang is a statically typed, imperative language with C-like syntax and Rust-inspired declarations. Here's a taste:
use std;
fn gcd(a: i32, b: i32) -> i32 {
if b == 0 {
return a;
} else {
return gcd(b, a - (a / b) * b);
}
}
fn main() -> i32 {
let x: i32 = std::getint();
let y: i32 = std::getint();
std::putint(gcd(x, y));
std::putch(10);
return 0;
}Key language features:
- Types:
i32, fixed-size arrays ([i32; 16]),void - Declarations:
letbindings, global variables,fnfunctions with typed parameters - Control flow:
if/else,while,break,continue,return - Expressions: arithmetic, comparison, logical (
&&,||,!), array indexing - Modules:
use std;imports the standard library, accessed viastd::prefix - Standard library (
std):getint,getch,putint,putch,putarray,timer_start,timer_stop
- CMake >= 3.16
- A C++23 compiler (Clang or GCC)
- Homebrew
bison(>= 3.2) andflexon macOS
brew install bison flexcmake -B build && cmake --build buildThe teac binary is produced at build/teac.
teac <input.tea> [-d ast|ir|ssa|s] [-o output]
| Flag | Description |
|---|---|
-d ast |
Dump the Abstract Syntax Tree |
-d ir |
Dump the Intermediate Representation (pre-optimization) |
-d ssa |
Dump the IR after mem2reg (SSA form with phi nodes) |
-d s |
Emit AArch64 assembly (default) |
-o file |
Write output to a file instead of stdout |
# Compile TeaLang source to assembly
./build/teac program.tea -o program.s
# Assemble and link with the standard library
clang program.s tests/std/std.o -o program -arch arm64
# Run
./programVerifies that teac can produce assembly for every test case without errors:
cd build && ctestCompiles each test, links it, runs the binary, and compares stdout (plus the exit code) against the expected .out file:
./scripts/run_tests.shEach test lives in its own directory under tests/<name>/:
| File | Purpose |
|---|---|
<name>.tea |
Source file |
<name>.in |
Stdin input (optional) |
<name>.out |
Expected output (stdout followed by the return value on the last line, per SysY convention) |
The test suite includes 29 programs covering algorithms like BFS, DFS, Dijkstra, sorting, binary search, matrix multiplication, convolution, a Brainfuck interpreter, and more.
teac-cpp/
├── include/teac/ # Public headers
│ ├── ast/ # AST node definitions
│ ├── codegen/ # Code generation interfaces
│ │ └── aarch64/ # AArch64-specific codegen
│ ├── common/ # Shared utilities (Indirect<T>, error types, Overloaded)
│ ├── driver/ # Compiler driver interface
│ └── ir/ # IR types, modules, passes
├── src/ # Implementation
│ ├── ast/ # AST display/utilities
│ ├── codegen/ # Layout, stack frame, AArch64 backend
│ ├── driver/ # Compiler orchestration, preprocessor
│ ├── ir/ # IR generation, CFG, dominance, mem2reg, optimization passes
│ ├── parser/ # Flex lexer (.l), Bison grammar (.y), ParserDriver
│ └── main.cpp # Entry point and CLI argument parsing
├── tests/ # Test suite
│ ├── std/std.c # C runtime library (getint, putint, etc.)
│ └── <name>/ # Individual test cases
├── scripts/
│ └── run_tests.sh # End-to-end test runner
└── CMakeLists.txt