Xi is a statically-typed, ahead-of-time compiled language with first-class dependency injection, seven function kinds, and refined types that enforce their constraints. It compiles to native binaries through a C99 backend, and its compiler is written in Xi and self-hosting.
interface Greeter { mapper greet(name: String) -> String }
class Friendly implements Greeter {
deps {}
mapper greet(name: String) -> String {
return "Hello, " + name + "!"
}
}
async entry main(args: String[]) -> Integer {
let g = App.resolve(Greeter) // auto-wired — no manual construction
system.stdout.writeln(g.greet("Ada"))
return 0
}
module App {} // resolution is automatic
- Dependency injection & IoC are part of the language, not a framework.
Implementations are discovered and wired automatically;
bindis an optional override. - Eight function kinds name a function's role and intent —
mapper,projector,predicate,consumer,producer,reducer,creator,action— and the compiler enforces purity for the pure ones. - Decision tables (
decisionkind) express business rules aswhen <cond> => <result>arms (or a tabularin/outgrid) — and, being a function kind, they're DI-injectable and can call predicates. - Interrupts — resumable conditions: a function
signals and suspends; an enclosingtry/catchdecides torecover(resume) orskip(abandon). See Interrupts. - Atoms — active-state stores: an immutable
statechanged only viatransitionreducers (Redux-style). See Atoms. - Machines — finite state machines as immutable values: named
states, machine-widedata, transitions with parameters,whereguards andupdateclauses,.can(...), and illegal moves that raise the resumableIllegalTransitioninterrupt. See Machines. - Events — built-in typed publish/subscribe. Producers
publish(topic, dto)any DTO; thelistenerkind subscribes to a topic and receives the typed value (no JSON). The default transport queues in memory with zero serialization; bind your ownPublisherService/ConsumerServiceto go external — producers and listeners are unchanged. See Events. - Web framework — implement
WebRequestHandlerand route by overloadingaction handle(req, res)withwhereguards;res.send(dto)/req.parse(T)auto-(de)serialize via a pluggableWebTransport(JSON by default). No manual JSON. See Web. - Refined types carry constraints (
type Age = Number where value >= 0) that are checked at construction. - Result-based error handling (
T!,ok/err,?propagation) — no exceptions. where-guarded overloading,match, optionals (T?), arrays (T[]), and aBytestype for binary data.- Multi-file projects with
importandnamespace. - A growing standard library — math, text, bytes, convert, serialization (json / yaml / xml), crypto (SHA/HMAC/base64/CSPRNG), fs, path, net (TCP sockets), http (HTTP/1.1 client), web (REST framework), process, time — see the standard library and serialization.
- Native, dependency-light output: Xi → C99 → a native binary via your
cc.
Full feature matrix: FEATURES.md. Full guide: code-by-sia.github.io/x.
Download a prebuilt toolchain for your platform from the
releases page, unpack it, and
put its bin/ on your PATH:
# grab the asset for your platform, e.g. xi-<version>-macos-arm64.tar.gz
tar -xzf xi-<version>-<os>-<arch>.tar.gz
export PATH="$PWD/xi-<version>-<os>-<arch>/bin:$PATH"
xc hello.xi # compile -> build/hello
xi hello.xi # compile and run
xi # interactive REPLThe bundle ships the xc compiler, the xi REPL / run tool, the runtime, and
the standard library; the bin/ wrappers set XC_RUNTIME / XC_STD for you.
You need a C compiler (cc / clang / gcc) on PATH, since xc produces
native binaries via C. (To build from source instead, run
./compiler/bootstrap.sh — see
github.com/code-by-sia/x.)
Runs on Linux (x86_64/arm64) and macOS (arm64/x86_64). On Windows, use WSL2 and follow the Linux steps, or run the toolchain in Docker (no native Windows build yet):
docker build -t xi .
docker run --rm -v "${PWD}:/work" xi xi hello.xi # compile + run
docker run --rm -v "${PWD}:/work" xi xc hello.xi # compile -> build/hello
docker run --rm -it -v "${PWD}:/work" xi xi # REPLThe image downloads a published release; pin one with
--build-arg XI_VERSION=v0.0.14. See the Dockerfile.
Full documentation — the language guide, dependency injection & IoC, decision tables, interrupts, atoms, state machines, events, serialization, the standard library, and the compiler internals — lives in the repository at github.com/code-by-sia/x (rendered at code-by-sia.github.io/x).
compiler/ the compiler, written in Xi (lexer, parser, codegen, driver) + xc_helpers.c
plus bootstrap.sh / fetch-seed.sh / selfhost.sh
runtime/ the C runtime (runtime.h, runtime.c) — the Xi equivalent of libc/libcore
std/ standard library (math, text, bytes, convert, json, yaml, xml, crypto, events, web, io, fs, path, net, http, process, time)
examples/ runnable programs, incl. proj/ (multi-file) and showcase/ (full project)
docs/ documentation (Docusaurus site under website/)
editors/ Tree-sitter grammar, Zed extension, Vim plugin
A Tree-sitter grammar plus Zed and Vim integrations live in
editors/. The grammar parses every .xi file in this repo.
Xi is licensed under the Apache License 2.0 — see LICENSE and NOTICE (the same license Kotlin uses). It is provided "AS IS", without warranties of any kind, and with no obligation of support (Apache-2.0 §7–§8). It's an experimental personal project — issues/PRs are welcome, but no support or maintenance is guaranteed. See CONTRIBUTING.md and SUPPORT.md.