Skip to content

Kod

Kod is a toy language that compiles to AArch64 (Apple Silicon) machine code for macOS. The self-hosted compiler (sh_kodc) compiles Kod programs, including itself.

func main() -> int64 {
    print("Hello, world!")
    return 0
}
$ ./kod build hello.kod
$ ./build/apps/hello/hello
Hello, world!

Features

  • Compiled to native ARM64 machine code (via as + clang)
  • Static types: int64, str, bool, arrays [T], structs, enums, optionals T?, generic types T[U, V] and functions f[T]
  • Union types: int64 | str, taken apart with n: int64 patterns
  • Pattern matching via match, plus if X is .Variant(bindings) sugar
  • F-string interpolation (f"hello {name}"), auto-to_str for non-string interpolands
  • Interfaces with vtable dispatch; primitives implement them via implicit boxing
  • Error handling via T or Error, try / must / throw
  • test "description" { ... } syntax with assert <expr> (source captured)
  • Modules and imports (import "kod/ast", import "./helper")
  • Self-hosted ARM64 codegen written in Kod itself

Status

The self-hosted compiler (sh_kodc) is the only implementation. A checked-in snapshot of it builds the current sources (see Self-hosting).