leviathan-lang.com / docs / reference
Language Reference
A precise specification of Leviathan as it is implemented today. Design rationale lives in the working spec; this reference documents syntax and behavior, category by category, with a runnable example for nearly every entity.
How to read this reference
- planned marks a feature that is designed but not yet built.
- engines notes appear where a feature runs on some compiler backends and not others. The four active engines are the tree-walk oracle, the IR interpreter, emit-C++, and LLVM (the primary AOT backend). A frozen pure x86-64/ELF backend is retained only as a differential-testing anchor and is never extended.
- Code blocks are real Leviathan. Source files use the
.levextension; the compiler binary isleviathanand the build driver istrident.
The one idea behind everything
Most of what other languages treat as a special case, Leviathan treats as one general rule applied consistently:
A member is a typed slot bound to a label. A constructor is a method marked by a keyword. An operator is a method whose name is a symbol. A property is a typed view over a slot. Fields and methods aren't two kinds of thing — "method" just means the member's type is callable. Access, inheritance, collisions, interface requirements, and get/set views all follow from that single rule.
Three more principles recur throughout:
- Resolution is by type, everywhere. Overloads, field access, operators, and assignment targets all resolve on type. A bare read with no type in context is the one thing that can't resolve — so it's an error, never a guess.
- Honesty over hidden magic. A type annotation never secretly means something else. A function returning
Promise<T>returns an actual promise; there is no implicit wrapping. - Gate the dangerous, guarantee the safe. Raw memory and interception live behind explicit markers so the safe majority keeps its guarantees.
Browse by category
Foundations
Comments, identifiers, keywords, and every literal form.
Types & GenericsPrimitives as objects, unions & optionals, generics, value vs reference.
Expressions & OperatorsPrecedence, calls, member access, dispatch, and match.
Declarations
Multiple inheritance and distinct collision resolution.
Fields, methods, constructors, operators, accessors, mutation control.
Structs & EnumsValue types with copy semantics and closed member sets.
Namespaces & InjectionImports and bind/inject dependency injection.
Control & Errors
Declarations, loops, and loop control.
Errors & ResourcesExceptions and deterministic using cleanup.
Standard Library
Array, Map, Set, iterators, lazy Seq.
The string toolkit, UTF-8 char, and the regex engine.
Promises, tasks, workers, channels, cancellation.
Streams, I/O & NetworkFiles, sockets, HTTP, TLS, timers, processes.
JSON, Time & Bytesjson, DateTime, encoding, math, Block.
Attributes, rules, comptime, macros.
Toolchain
New to the language? The Learn Leviathan tutorial walks the same material as a guided narrative — start there, then use this reference to look up the details.