gat-min Language Specification (Bootstrap Subset)
gat-min is the minimal frozen subset of the gat programming language used to implement the self-hosted compiler gatc-v1.
1. Features Included in gat-min
1.1 Types
- Primitives:
i64,bool,void,string - Value Structs:
struct Name { f1: T; f2: U; }(stack allocated, passed/copied by value) - Reference Classes:
class Name { f1: T; ... deinit { ... } }(heap allocated vianew, non-atomic ARC managed, optional RAIIdeinit) - Unsafe Raw Pointers:
raw T(e.g.raw i8,raw i64,raw Point), supporting index accessptr[idx]and address-ofraw expr
1.2 Declarations & Functions
- Top-level
struct,class,fn - Functions with typed parameters and explicit return types (
fn name(p1: T, p2: U) -> Ret) - Calling convention: borrowed by default for reference class parameters
1.3 Statements & Control Flow
- Variable declarations:
let name = expr;/let name: Type = expr; - Variable & field assignments:
x = expr;,obj.field = expr;,buf[idx] = expr; - Conditional branching:
if (cond) { ... } else { ... } - Iteration:
while (cond) { ... } - Function returns:
return;/return expr; - Expressions as statements: function calls,
print(...)
1.4 Operators & Expressions
- Arithmetic:
+,-,*,/,%, unary- - Relational & Equality:
==,!=,<,<=,>,>= - Logical:
&&,||,! - Member Access:
obj.field - Index Access:
buf[index](loads byte ifraw i8/string, 8 bytes ifraw i64/general pointer) - Instantiation:
new ClassName { field: val, ... }andStructName { field: val, ... } - Literals: decimal integers (
123), hex integers (0x7F), character literals ('a','\n'), strings ("..."), booleans (true,false),nil
1.5 Builtin Runtime Intrinsics
print(args...): Output strings, numbers, booleansread_file(path: string) -> string: Read whole file from diskwrite_file(path: string, data: string, len: i64) -> i64: Write bytes to diskalloc_mem(bytes: i64) -> raw i8: Allocate raw heap bufferfree_mem(ptr: raw i8): Free raw heap bufferstr_len(s: string) -> i64: Get string lengthstr_eq(a: string, b: string) -> bool: Compare two stringsstr_char(s: string, idx: i64) -> i64: Read ASCII byte at indexstr_sub(s: string, start: i64, len: i64) -> string: Substring extractionstr_concat(a: string, b: string) -> string: Concatenate two stringsstr_from_int(n: i64) -> string: Convert integer to stringget_cmd_arg(idx: i64) -> string: Retrieve command line argument
2. Features Implemented Post-Bootstrap (in Full gat)
- Generics: Uniform 64-bit word-sized generic type erasure (
class Pair<T, U>, functions) - First-Class Functions: Function pointer values and function types
fn(T1, T2) -> TRet - Pattern Matching: Exhaustive
matchon taggedenums - Cycle Collection:
weak Tnon-owning references andweak_upgrade - Concurrency: Native OS threading (
std/thread.gat) and synchronization (std/sync.gatMutex) with compile-time thread-boundary reference isolation
3. Deliberately Excluded Features (Current Scope Boundary)
- Full heap-captured closures (anonymous closures capturing outer scope)
- Shared mutable
classreference graphs across threads (thread-local heaps enforced) - Trait / Interface dynamic dispatch tables