LLVM Ahead-of-Time Compiler
Stag
A statically typed systems programming language compiling directly to native machine code via LLVM. Built with lexical arena zone memory management, static move and escape analysis, dependence-proved loop auto-parallelization, C ABI interoperability, an embedded 18-module Standard Kit, and a native Language Server.
Automatically detects OS and CPU architecture (linux-x64, linux-arm64, macos-arm64), resolves the latest release, verifies SHA-256 checksums, and installs stagc and stag-lsp:
curl -fsSL https://stag-lang.github.io/install.sh | bash
Non-interactive CI mode: curl -fsSL https://stag-lang.github.io/install.sh | bash -s -- --yes · Inspect install.sh
Download and run the native Windows x64 setup wizard. Installs stagc to your PATH and optionally installs stag-lsp:
Requires C++20 (Clang 18+ or GCC 13+), CMake 3.20+, Ninja, and LLVM 20–23:
git clone https://github.com/stag-lang/stag.git && cmake -S stag -B stag/build -G Ninja -DCMAKE_BUILD_TYPE=Release && cmake --build stag/build -j
Run ctest --test-dir stag/build --output-on-failure to execute unit, end-to-end, Standard Kit, and regression suites.
Language Sample
Explicit Types, Deterministic Cleanup, Native Code
Stag supports both indentation-delimited and brace-delimited blocks, monomorphized generics, exhaustive tagged unions, and zero-dependency Standard Kit modules embedded inside the compiler binary.
use kit.check
use kit.io (Console)
use kit.list (List)
use kit.math
func norm_l2(xs: []f64) -> f64:
var sum: f64 = 0.0
for i in 0..xs.len:
sum += xs[i] * xs[i]
math.sqrt_f64(sum)
test "norm_l2 computes Euclidean magnitude":
var v = List[f64].new()
v.push(3.0)
v.push(4.0)
check.near_f64(norm_l2(v.as_slice()), 5.0, 1e-12, "3-4-5 triangle")
func main() -> i32:
var data = List[f64].new()
for i in 1..5:
data.push(i as f64)
mag := norm_l2(data.as_slice())
msg := f"||data||_2 = {mag}"
Console.println(msg.as_str())
0i32
$ stagc stats.stag -O2 --cpu=native -o stats
$ ./stats
||data||_2 = 5.47722557505166
$ stagc --test -O2 stats.stag
[PASS] norm_l2 computes Euclidean magnitude
Summary: 1 passed, 0 failed (total 1)
$ stagc stats.stag --emit=mem -o -
$ stagc stats.stag --emit=par --par=auto -o -
$ stagc stats.stag --emit=hints -o -
$ stagc stats.stag --emit=ir -O3 -o -
Architecture
Design Pillars
Static Type System & Generics
Monomorphized generic records, tagged unions (choice) with exhaustive match, traits with associated types, compile-time const evaluation, fixed arrays, fat-pointer slices ([]T, []mut T), and UTF-8 str.
Zones, RAII & Memory Analysis
Deterministic stack layout, lexically scoped arena zone blocks, compiler-inserted Drop calls and defer cleanup, static use-after-move and escape diagnostics (--emit=mem), and runtime bounds/overflow traps (--unchecked to disable).
Dependence-Proved Parallelism
Static affine subscript, alias, and reduction analysis automatically parallelizes proved loops across a lock-free C11 thread pool (--par=auto|force|autotune) with per-loop proof reports via --emit=par.
Embedded 18-Module Standard Kit
alloc, args, check, hash, io, json, list, math, maybe, mem, outcome, path, rand, scribe, sys, table, text, and time are embedded directly in stagc and tested at -O0 and -O2.
C ABI & Inline Assembly
Direct extern func linkage, C-compatible extern record, packed, and extern union layout lowering for Win64, System V AMD64, and AArch64, raw pointers, and target-native inline asm blocks.
LSP & C++20 Embedding API
Standalone stag-lsp language server for editor diagnostics, hover, definitions, symbols, and Standard Kit completions, plus an LLVM-header-free C++20 library interface (<stag/Stag.hpp>) for external tools.
Prebuilt Toolchains
Downloads (v0.1.0)
Links below resolve automatically to the latest published release of stag-lang/stag. Every artifact is built and verified via CTest across all four architectures before publication.
| Platform | Architecture | Installer | Portable Archive |
|---|---|---|---|
| Windows | x86_64 |
stag-setup-0.1.0-windows-x64.exe | stag-0.1.0-windows-x64.zip |
| Linux | x86_64 |
stag-setup-0.1.0-linux-x64 | stag-0.1.0-linux-x64.tar.gz |
| Linux | arm64 |
stag-setup-0.1.0-linux-arm64 | stag-0.1.0-linux-arm64.tar.gz |
| macOS | arm64 (Apple Silicon) |
Use install.sh |
stag-0.1.0-macos-arm64.tar.gz |
Checksums: SHA256SUMS.txt ·
All versions: GitHub Releases
Editor Support
Visual Studio Code Extension
Reference Manuals
Documentation
Language & Compiler Reference
Complete formal guide covering lexical structure, grammar, type system, generics, traits, zones, move analysis, auto-parallelism, C FFI, inline assembly, CLI flags, worked input/output specifications, diagnostics, LSP, and fuzzing.
Standard Kit API Reference
Complete reference for all 18 embedded Standard Kit modules with parameter/return input-output tables, trait implementations, and runnable Stag examples with expected outputs.
C++20 Embedding API
Reference for integrating libstag_lib and <stag/Stag.hpp> into external tools, static analyzers, build systems, and custom IDE frontends.