1: Leaf


Contents


A high-level, general purpose programming language with a strong static type system.

Leaf is a complete language with fixed semantics. The type system, scoping rules, mutability model, and all language constructs are defined by the specification — there is no target-dependent variation. The compiler front-end fully defines what Leaf is; back-end compilation is a separate concern not covered by this specification.

Source files use the .leaf extension. See lang/definitions.md §5 for details.

1.1: Pipeline

Code -> Lex -> Parse -> AST -> Scopes -> Type check
(.leaf)

The compiler front-end is responsible for:

The front-end defines:

1.2: Assumptions

1.3: Built-in Types

Leaf has a fixed set of built-in types that are always available:

Primitive types:

Type Description
bool Boolean values (true, false)
byte Unsigned 8-bit integer (0 to 255)
int Signed 64-bit integer
uint Unsigned 64-bit integer
float IEEE 754 double-precision (64-bit) floating-point
str String values

Type-system types:

Type Description
never Bottom type — no value inhabits it; assignable to every type

Built-in generic types:

Type Description
Option[T] Optional value — Some(T) or None
Result[T, E] Success or failure — Ok(T) or Err(E)
List[T] Ordered, growable sequence
Map[K, V] Key-value collection
Set[T] Unordered collection of unique values
Buffer Mutable, growable byte sequence for binary data
Tuple[T1, T2, ...] Fixed-size heterogeneous collection (2–10 elements)
Generator[Y, R=(), N=never] Generator / coroutine type

Built-in enums:

Type Description
Ordering Comparison result — Less, Equal, or Greater
GeneratorResult[Y, R] Generator step — Yielded(Y) or Done(R)

The ? suffix is sugar for Option: int? means Option[int].

Link copied to clipboard!