Skip to content
Ridgun
English

Ridgun

The language itself: a compiler that compiles itself, the stable project tool, the specification and the book

A tabular, pure-by-default functional & systems programming language built for massive parallelism, native isolated agents, symbolic tensor algebra, and deterministic zero-GC memory management.

Ridgun combines the declarative clarity of tabular functional programming with native systems performance. Its self-hosted compiler (ridgunc) and project manager/formatter (stable) are written 100% in pure Ridgun (src/main/ridgun/, zero Rust/C code or external compiler dependencies) and emit standalone, statically linked Linux ELF64 executables (x86_64 and ARM64 / Raspberry Pi) directly to disk with zero Garbage Collector pauses.


๐Ÿ“– The Ridgun Book โ€” Complete Guide in 8 Languages

Learn Ridgun from scratchโ€”from your first tabular function to parallel DAGs, the Native Agent Model (agent, send ... to, receive from), symbolic tensors, and RMM1/RMM2 deterministic memory managementโ€”in your preferred language:

LanguageOnline Interactive Book (HTML)Markdown Chapters (00โ€“08)
๐Ÿ‡ช๐Ÿ‡ธ EspaรฑolEl Libro de Ridgun (es/index.html)docs/book/es/INDEX.md โ€” Cap. 00 ยท 01 ยท 02 ยท 03 ยท 04 ยท 05 ยท 06 ยท 07 ยท 08
๐Ÿ‡ฌ๐Ÿ‡ง EnglishThe Ridgun Book (en/index.html)docs/book/en/INDEX.md โ€” Ch. 00 ยท 01 ยท 02 ยท 03 ยท 04 ยท 05 ยท 06 ยท 07 ยท 08
๐Ÿ‡ฎ๐Ÿ‡น ItalianoIl Libro di Ridgun (it/index.html)docs/book/it/INDEX.md โ€” Cap. 00 ยท 01 ยท 02 ยท 03 ยท 04 ยท 05 ยท 06 ยท 07 ยท 08
๐Ÿ‡ต๐Ÿ‡น PortuguรชsO Livro do Ridgun (pt/index.html)docs/book/pt/INDEX.md โ€” Cap. 00 ยท 01 ยท 02 ยท 03 ยท 04 ยท 05 ยท 06 ยท 07 ยท 08
๐Ÿ‡ธ๐Ÿ‡ช SvenskaBoken om Ridgun (sv/index.html)docs/book/sv/INDEX.md โ€” Kap. 00 ยท 01 ยท 02 ยท 03 ยท 04 ยท 05 ยท 06 ยท 07 ยท 08
๐Ÿด Catalร El Llibre de Ridgun (ca/index.html)docs/book/ca/INDEX.md โ€” Cap. 00 ยท 01 ยท 02 ยท 03 ยท 04 ยท 05 ยท 06 ยท 07 ยท 08
๐Ÿด GalegoO Libro de Ridgun (gl/index.html)docs/book/gl/INDEX.md โ€” Cap. 00 ยท 01 ยท 02 ยท 03 ยท 04 ยท 05 ยท 06 ยท 07 ยท 08
๐Ÿด EuskaraRidgun Liburua (eu/index.html)docs/book/eu/INDEX.md โ€” 00. kap. ยท 01 ยท 02 ยท 03 ยท 04 ยท 05 ยท 06 ยท 07 ยท 08

Quick Start

Ridgun ships with two self-hosted toolsโ€”ridgunc (the single-file compiler & runner) and stable (the project manager, typechecker, test runner, and canonical tabular formatter)โ€”configured via a pure Ridgun build.rg file (no YAML, JSON, or TOML):

# Type-check all project modules in src/main/ridgun/
./target/stable check

# Compile & run all test suites in src/test/ridgun/
./target/stable test

# Format all .rg source files into canonical tabular alignment
./target/stable format

# Build all project targets into target/ (or install into ~/.local/bin/)
./target/stable built
./target/stable built lib
./target/stable install

# Scaffold a new app or library project, list tasks/plugins, or sync dependencies
./target/stable new my_app
./target/stable new --lib my_lib
./target/stable tasks
./target/stable plugins
./target/stable deps

# Compile or run a single .rg file or library directly with ridgunc (x86_64 or ARM64 Raspberry Pi)
./target/ridgunc check my_program.rg
./target/ridgunc run my_program.rg
./target/ridgunc build my_program.rg -o my_program
./target/ridgunc build --lib my_lib.rg -o my_lib.rglib
./target/ridgunc build --so my_lib.rg -o libmy_lib.so
./target/ridgunc build --target arm64-linux my_program.rg -o my_program_arm64

Release Verification (minisign)

Official Ridgun release downloads (SHA256SUMS) are signed with minisign using the following Ed25519 public key:

RWQuKPmgklF+8SxAc6VK4RdRg/vw1/jBXvq5E0YcBN5QcFjezotHHWvq

Verify a downloaded release before unpacking:

minisign -Vm SHA256SUMS -P RWQuKPmgklF+8SxAc6VK4RdRg/vw1/jBXvq5E0YcBN5QcFjezotHHWvq
sha256sum -c SHA256SUMS

What Makes Ridgun Different?

  1. Code as a 2D Table (=>, =, ->): Type signatures act as column headers. Pattern-matching clauses align each argument beneath its type and align = beneath =>. stable format (and GNU Emacs ridgun-mode) formats your code automatically.
  2. Unified = Block Grammar ((none), |, ||) & Compact Nested Closers (|. / ||.):
  • Every = (in functions, operators, local bindings x =, or guard branches) accepts sequential lines, conditional guard blocks (|), or parallel DAG blocks (||).
  • Guard branches can nest 3โ€“4+ levels deep to form rich decision trees, using the compact inline |. closer (| otherwise = val |.) only when returning to an outer branch level below.
  1. Parallel DAG Blocks (|| expr -> var), Multicore Combinators (||map, ||filter), and the Native Agent Model (agent, send ... to, receive from):
  • Parallel dataflow dependencies are declared directly with || expr -> var (no where keyword required). The static analyzer verifies cycle freedom at compile time and schedules independent branches in parallel.
  • map, filter, and fold execute sequentially left-to-right, while ||map and ||filter distribute list elements across multicore worker threads using Ridgun's || parallel prefix.
  • Zero-boilerplate Native Agent Model & Smart Compile-Time Strategy Selection (FR-COMP-009): Any standard function or operator (fn :: or op ::) can be wrapped into an isolated concurrent agent in one line (ag = agent (my fn) for stateless agents, or ag = agent (step fn) init_state for stateful/session agents S M => S and S M => S R). Communicate via statically typed send msg to ag (or multi-argument send a b to ag), blocking receive from ag, non-blocking try receive from ag (Some r | None), and stop ag (which deterministically frees the agent's isolated state via RMM1/RMM2). At compile time, ridgunc analyzes each function's call depth and computational cost across ||, ||map, ||filter, and agent, executing lightweight functions (StratInlineSequential) as zero-overhead green-thread steps and automatically dispatching heavy or deeply recursive functions (StratLazyStealableTask / StratKernelWorkerJob) across real OS kernel threads (SYS_clone).
  1. Immutable by Default (x = ...) with Explicit mut (mut x = ...):
  • Local bindings are immutable constants unless declared with mut x = expr, preventing accidental rebinding in the same scope.
  1. Deterministic Memory Without a Garbage Collector (RMM1, RMM2 & with region):
  • Policy RMM1 (Compiled Memory Management): Static last-use deallocation (rg_cmm_drop), zero-copy return moves (rg_cmm_move), and 1-cycle pointer-identity guards (ptr(a) != ptr(c)) for branching functions.
  • Policy RMM2 (Assignment & Cascaded Structure Counting): Incoming function arguments are untouched (+0/-0), local/container assignments add +1, returned locals are spared in transit, and non-returned locals cascade -1 through child structures on scope exit.
  • Lexical Regions (with region 64_KB do) & Timeouts (with timeout 250_ms): Enforce hard byte quotas and wall-clock execution deadlines on untrusted workloads and free entire arenas in $O(1)$.
  1. Natural-Language Spaces in fn :: & op ::, Unified Tuple/Sequence Signatures (FR-COMP-008), Open expand type, Polymorphism (A..Z), and Symbolic Tensors (@):
  • Define multi-word functions and N-ary operators with natural spaces instead of underscores (fn :: format err AppErr => String, op :: clamp Int between Int and Int => Int).
  • Argument sequences and tuples are unified (FR-COMP-008): write clean space-separated tuple and return type signatures (=> Int Int [String String] String, [String String], (A B)) without comma clutter.
  • Share ADT constructor names across types (Error, Var), use bare type names as variants (type Something = String | Int | MyStruct Float Int), extend types via expand type, and merge new fn :: clauses automatically before _ catch-alls.
  • Single uppercase letters (A..Z) act as zero-noise polymorphic type variables.
  • Native Tensor[N, K] types check symbolic dimensions at compile time and support Einstein summation (A_ik @ B_kj) and Hadamard broadcasting (A_ij * B_j).

A Taste of Ridgun

-- 1. Tabular pattern matching, natural spaces & zero-noise polymorphism (A..Z)
head or [A]   A => A
head or []    d =  d
head or (x:_) _ =  x

-- 2. Bare type-name variants, `expand type` & automatic `fn ::` clause merging
type Something = String | Int | MyStruct Float Int

fn :: describe something Something          => String
      describe something (String   s)       =  "str:{s}"
      describe something (Int      n)       =  "int:{n}"
      describe something (MyStruct f count) =  "struct:{f}:{count}"
      describe something _                  =  "other"

expand type Something = Bool

fn :: describe something Something => String
      describe something (Bool b)  =  "bool:{b}"

-- 3. Natural-language mixfix operator with `=` + `|` guards
op :: clamp Int between Int and Int => Int
      clamp x   between lo  and hi  =
        | x < lo    = lo
        | x > hi    = hi
        | otherwise = x

-- 4. Multi-level decision tree with compact inline `|.` closers
fn :: route request Int    Int  Bool      Bool     Int        Int          => Int
      route request method role is_signed is_admin payload_kb rate_limited =
        | method == 0 =
          | payload_kb == 0 = 204
          | otherwise       = 200 |.
        | method == 1 =
          | not is_signed = 401
          | otherwise =
            | rate_limited > 0 =
              | is_admin =
                | payload_kb > 10000 = 413
                | otherwise          = 202 |.
              | otherwise = 429 |.
            | payload_kb > 1000 =
              | role >= 2 and is_admin = 201
              | otherwise              = 413 |.
            | otherwise = 201 |.
        | otherwise = 405

-- 5. Parallel DAG block (`|| expr -> var`) without `where` + `||.` closer
fn :: quarterly balance Int  => Int
      quarterly balance base =
        || base * 100                 -> gross_sales
        || base * 40                  -> fixed_costs
        || gross_sales - fixed_costs  -> gross_profit ||.
        gross_profit * 80 / 100

-- 6. Conditional local variable (`x = | ...`) and explicit `mut` accumulator
fn :: compute total Bool   Int => Int
      compute total is_vip raw =
        discount =
          | is_vip and raw > 50 = 20
          | otherwise           = 0
        mut total = raw - discount
        total = total + 5
        total

-- 7. Symbolic-dimension Tensor contraction (Einstein summation `@`)
fn :: linear layer Tensor[B, In] Tensor[In, Out] Tensor[B, Out] => Tensor[B, Out]
      linear layer x             weights         bias           =  (x_bi @ weights_io) + bias

-- 8. Native Agent Model (`agent`, `send ... to`, `receive from`, `stop`)
fn :: add visit Int Int => Int
      add visit acc n   =  acc + n

fn :: track visits Int => Int
      track visits delta =
        counter = agent (add visit) 10
        send delta to counter
        total = receive from counter
        stop counter
        total

Self-Hosted Architecture (src/main/ridgun/)

Ridgun Source (.rg) + build.rg
              โ”‚
              โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  lexer.rg & parser.rg  โ”‚  Tokenization, Mixfix Resolution, Unified `=` (`|`, `||`, `|.`, `||.`)
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
              โ”‚
              โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚      typecheck.rg      โ”‚  Polymorphic `A..Z`, `mut` Immutability Check, Symbolic Tensor Dims
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
              โ”‚
              โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚       analyzer.rg      โ”‚  Static `||` DAG Cycle Detection & Work-Stealing Strategy Inference
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
              โ”‚
              โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚       compiler.rg      โ”‚  Call-Graph Tree-Shaking, TCO (`loop`), `RMM1` & `RMM2` Lowering
  โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚            โ”‚
        โ–ผ            โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    Bytecode (`.rgc`)
  โ”‚ x86_64.rg โ”‚   (`vm.rg` Stack VM)
  โ”‚ arm64.rg  โ”‚
  โ”‚ elf64.rg  โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
        โ–ผ
  Native ELF64 (`x86_64` / `ARM64`)

Project Layout

ridgun/
โ”œโ”€โ”€ build.rg                   # Pure-Ridgun project manifest for `stable`
โ”œโ”€โ”€ editors/
โ”‚   โ””โ”€โ”€ emacs/ridgun-mode.el   # GNU Emacs major mode with tabular alignment
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main/ridgun/
โ”‚   โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ast.rg         # Compiler & VM Algebraic Data Types
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ lexer.rg       # Lexical scanner & byte-unit literals (_KB, _MB, _GB)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ parser.rg      # Recursive-descent parser & mixfix normalizer
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ typecheck.rg   # Typechecker, A..Z unification & tensor shape checker
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ analyzer.rg    # Static parallel DAG & strategy analyzer
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ compiler.rg    # RMM1/RMM2 analyzer, native IR lowerer & .rgc compiler
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ elf64.rg       # Direct Linux ELF64 executable binary emitter
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ x86_64.rg      # Pure-Ridgun 2-pass x86_64 machine-code assembler & kernel
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ arm64.rg       # Pure-Ridgun 2-pass ARM64 (AArch64 / Raspberry Pi) assembler
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ formatter.rg   # Canonical tabular code formatter (`stable format`)
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ vm.rg          # Meta-circular stack virtual machine
โ”‚   โ”‚   โ”œโ”€โ”€ ridgunc/main.rg    # Self-hosted `ridgunc` CLI entry point
โ”‚   โ”‚   โ””โ”€โ”€ stable/main.rg     # Self-hosted `stable` project manager CLI entry point
โ”‚   โ””โ”€โ”€ test/ridgun/           # Self-hosted Ridgun test suites (`test_*.rg`)
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ book/                  # The Ridgun Book in 7 languages (es, ca, gl, eu, en, pt, sv)
โ”‚   โ”œโ”€โ”€ lang/spec.md           # Formal language specification
โ”‚   โ”œโ”€โ”€ etc/cmm_architecture.md# RMM1 & RMM2 memory management architecture
โ”‚   โ””โ”€โ”€ requirements/          # Functional requirements (FR-COMP-*, FR-TOOL-*, FR-VM-*)
โ””โ”€โ”€ target/                    # Compiled self-hosted ELF64 binaries (`ridgunc`, `stable`)

Technical Documentation

DocumentDescription
Language Specification (docs/lang/spec.md)Complete syntax, type system, unified = blocks, `
RMM Memory Architecture (docs/etc/cmm_architecture.md)Detailed design of RMM1 (Linear & Conditional CMM) and RMM2 (Assignment & Cascaded Structure Counting)
Low-Level Runtime Design (docs/etc/low_level_ridgun_runtime_design.md)Architecture and instruction design for the 100% pure-Ridgun symbolic x86_64 and ARM64 runtime kernels
FR-COMP-009 (docs/requirements/functional/compiler/)Requirement specification for Ridgun's Native Agent Model (agent, send ... to, receive from, try receive from, stop)
FR-COMP-008 (docs/requirements/functional/compiler/)Requirement specification for unified space-separated tuple and sequence type signatures
FR-COMP-004 (docs/requirements/functional/compiler/)Requirement specification for 100% pure-Ridgun native ELF64 machine-code generation (x86_64 and ARM64 Raspberry Pi) without Rust or rustc
FR-COMP-003 (docs/requirements/functional/compiler/)Requirement specification for unified = grammar, `
FR-COMP-002 (docs/requirements/functional/compiler/)Requirement specification for RMM1 and RMM2 deterministic memory management
Roadmap & Active Tasks (docs/road-map/INDEX.md)Current session state, completed milestones, and backlog

License

Apache 2.0 โ€” see LICENSE.