Stag Programming Language

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.

License: Apache-2.0 Targets: Linux x64/arm64 · macOS arm64 · Windows x64 Latest: v0.1.0

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.

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.

stats.stag
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
Compile, Run & Test
$ 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)
Static Analysis Reports
$ 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 -

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.

Stag Ahead-of-Time Compilation Pipeline Source .stag + Kit Lexer / Parser Tokens & AST Sema & Const Types & HIR Static Analyses Mem · Par · Hints LLVM CodeGen IR · ABI · DWARF LLVM Optimizer -O0..O3 · SIMD Native Output exe · obj · asm

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.

Checksums: SHA256SUMS.txt · All versions: GitHub Releases

Visual Studio Code Extension

Stag VS Code Extension Icon

Stag Programming Language (stag-lang.stag-lang)

Official extension published on the Visual Studio Marketplace. Provides TextMate syntax highlighting for .stag files and connects automatically to stag-lsp for live diagnostics, hover types, go-to-definition, document symbols, signature help, and Standard Kit completions.

code --install-extension stag-lang.stag-lang

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.