{"id":50575412,"url":"https://github.com/code-by-sia/x","last_synced_at":"2026-06-09T00:01:26.130Z","repository":{"id":362160658,"uuid":"1257653921","full_name":"code-by-sia/x","owner":"code-by-sia","description":"The Ξ (Xi) Programming Language","archived":false,"fork":false,"pushed_at":"2026-06-07T23:02:14.000Z","size":1629,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-07T23:23:36.663Z","etag":null,"topics":["compiler","compiler-design","language","programming","programming-language","x","xi"],"latest_commit_sha":null,"homepage":"https://code-by-sia.github.io/x/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/code-by-sia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-02T22:12:00.000Z","updated_at":"2026-06-07T23:02:11.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/code-by-sia/x","commit_stats":null,"previous_names":["code-by-sia/x"],"tags_count":67,"template":false,"template_full_name":null,"purl":"pkg:github/code-by-sia/x","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-by-sia%2Fx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-by-sia%2Fx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-by-sia%2Fx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-by-sia%2Fx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-by-sia","download_url":"https://codeload.github.com/code-by-sia/x/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-by-sia%2Fx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34085321,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","compiler-design","language","programming","programming-language","x","xi"],"created_at":"2026-06-04T22:00:18.541Z","updated_at":"2026-06-09T00:01:26.044Z","avatar_url":"https://github.com/code-by-sia.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"docs/assets/logo-white.svg\"\u003e\n    \u003cimg alt=\"Xi programming language logo\" src=\"docs/assets/logo.svg\" width=\"140\" height=\"140\"\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eThe Ξ (Xi) Programming Language\u003c/h1\u003e\n\nXi is a **statically-typed, ahead-of-time compiled** language with **first-class\ndependency injection**, **seven function kinds**, and **refined types** that\nenforce their constraints. It compiles to native binaries through a C99 backend,\nand its compiler is **written in Xi and self-hosting**.\n\n```x\ninterface Greeter { mapper greet(name: String) -\u003e String }\n\nclass Friendly implements Greeter {\n    deps {}\n    mapper greet(name: String) -\u003e String {\n        return \"Hello, \" + name + \"!\"\n    }\n}\n\nasync entry main(args: String[]) -\u003e Integer {\n    let g = App.resolve(Greeter)          // auto-wired — no manual construction\n    system.stdout.writeln(g.greet(\"Ada\"))\n    return 0\n}\n\nmodule App {}                             // resolution is automatic\n```\n\n## Why Xi\n\n- **Dependency injection \u0026 IoC are part of the language**, not a framework.\n  Implementations are discovered and wired automatically; `bind` is an optional\n  override. See [below](#dependency-injection--ioc).\n- **Seven function kinds** name a function's role and intent —\n  `mapper`, `projector`, `predicate`, `consumer`, `producer`, `reducer`,\n  `creator` — and the compiler enforces purity for the pure ones.\n- **Decision tables** (`decision` kind) express business rules as\n  `when \u003ccond\u003e =\u003e \u003cresult\u003e` arms — and, being a function kind, they're\n  DI-injectable and can call predicates. See\n  [decision tables](#decision-tables-dxt).\n- **Interrupts** — resumable conditions: a function `signal`s and **suspends**;\n  an enclosing `try`/`catch` decides to `recover` (resume) or `skip` (abandon).\n  See [Interrupts](https://code-by-sia.github.io/x/interrupts).\n- **Atoms** — active-state stores: an immutable `state` changed only via\n  `transition` reducers (Redux-style). See [Atoms](https://code-by-sia.github.io/x/atoms).\n- **Machines** — finite state machines as immutable values: named `states`,\n  machine-wide `data`, transitions with parameters, `where` guards and `update`\n  clauses, `.can(...)`, and illegal moves that raise the resumable\n  `IllegalTransition` interrupt. See [Machines](https://code-by-sia.github.io/x/machines).\n- **Events** — built-in typed publish/subscribe. Producers `publish(topic, dto)`\n  any DTO; the `listener` kind subscribes to a topic and receives the **typed**\n  value (no JSON). The default transport queues in memory with zero serialization;\n  bind your own `PublisherService`/`ConsumerService` to go external — producers and\n  listeners are unchanged. See [Events](https://code-by-sia.github.io/x/events).\n- **Refined types** carry constraints (`type Age = Number where value \u003e= 0`)\n  that are **checked at construction**.\n- **Result-based error handling** (`T!`, `ok`/`err`, `?` propagation) — no\n  exceptions.\n- **`where`-guarded overloading**, `match`, optionals (`T?`), arrays (`T[]`),\n  and a `Bytes` type for binary data.\n- **Multi-file projects** with `import` and `namespace`.\n- **A growing standard library** — math, text, bytes, convert, **serialization\n  (json / yaml / xml)**, fs, path, **net (TCP sockets)**, **http (HTTP/1.1\n  client)**, process, time — see\n  [the standard library](https://code-by-sia.github.io/x/stdlib) and\n  [serialization](https://code-by-sia.github.io/x/serialization).\n- **Native, dependency-light output**: Xi → C99 → a native binary via your `cc`.\n\nFull feature matrix: **[FEATURES.md](FEATURES.md)**. Full guide:\n**[code-by-sia.github.io/x](https://code-by-sia.github.io/x/)**.\n\n## Quick start\n\n```sh\n# Build the compiler. bootstrap.sh downloads the matching released `xc` binary\n# (the seed), compiles compiler/xc.x with it, then rebuilds from source with\n# itself. Produces ./compiler/xc and ./bin/xi (the REPL / run tool).\n# Needs curl + a C compiler. Build offline with XC_SEED=/path/to/xc.\n./compiler/bootstrap.sh\n\nexport XC_RUNTIME=\"$PWD/runtime\"\n./compiler/xc examples/greeting.x   # -\u003e build/greeting\n./build/greeting\n\n# Or compile-and-run, or start the REPL, with `x`:\nexport XC=\"$PWD/compiler/xc\"\n./bin/xi examples/greeting.x          # compile + run\n./bin/xi                              # interactive REPL\n```\n\nRuns on **Linux** (x86_64/arm64) and **macOS** (arm64/x86_64). On **Windows**,\nuse **WSL2** and follow the Linux steps (no native Windows build yet).\n\n## Dependency injection \u0026 IoC\n\nDI is built into the language. A class declares what it needs in a `deps { }`\nblock; at a use site `App.resolve(Interface)` returns a fully-wired instance.\nThe compiler **discovers implementations automatically** — a `bind` is only\nneeded to *steer* resolution. When an interface has several implementations, a\ndependency disambiguates with a `where` guard, a list type `I[]`, or an `or`\nfallback.\n\n```x\ninterface Logger { consumer log(msg: String) }\nclass ConsoleLogger implements Logger {\n    deps {}\n    consumer log(msg: String) { system.stdout.writeln(msg) }\n}\n\ninterface Calculator { predicate precise() }\nclass BasicCalc   implements Calculator { deps {} predicate precise() { return false } }\nclass PreciseCalc implements Calculator { deps {} predicate precise() { return true } }\n\ninterface TaxRule { mapper rate() -\u003e Number }\nclass Vat implements TaxRule { deps {} mapper rate() -\u003e Number { return 20 } }\nclass Gst implements TaxRule { deps {} mapper rate() -\u003e Number { return 5 } }\n\ninterface Repository { mapper name() -\u003e String }\nclass EmptyRepository implements Repository { deps {} mapper name() -\u003e String { return \"empty\" } }\n\ninterface Service { consumer run() }\nclass Checkout implements Service {\n    deps {\n        log:   Logger\n        calc:  Calculator where calc.precise()   // pick the impl whose guard holds\n        rules: TaxRule[]                          // inject ALL implementations\n        repo:  Repository or EmptyRepository      // fall back if none found\n    }\n    consumer run() {\n        log.log(\"precise? \" + calc.precise())\n        log.log(\"rules   = \" + rules.len)\n        log.log(\"repo    = \" + repo.name())\n    }\n}\n\n// Functions can declare dependencies too.\nmapper { log: Logger } describe(name: String) -\u003e String {\n    log.log(\"describing \" + name)\n    return \"\u003c\" + name + \"\u003e\"\n}\n\nasync entry main(args: String[]) -\u003e Integer {\n    let svc = App.resolve(Service)   // auto-wired; no bind needed\n    svc.run()\n    system.stdout.writeln(describe(\"widget\"))\n    return 0\n}\n\nmodule App {}   // empty: resolution is automatic. Add `bind`s here only to steer,\n                // e.g.  bind Logger -\u003e ConsoleLogger as singleton\n```\n\nRunnable as [`examples/di_auto.x`](examples/di_auto.x). `singleton` / `transient`\nscopes are selected with `bind I -\u003e Impl as singleton`.\n\n## Decision tables (DxT)\n\nThe `decision` function kind expresses rules as `when \u003ccondition\u003e =\u003e \u003cresult\u003e`\narms with a final `else`. Conditions are ordinary expressions, so they can call\npredicates and use injected dependencies; `hit first` returns the first match.\n\n```x\ndecision creditTier(score: Number, income: Number) -\u003e String {\n    hit first\n    when score \u003e= 750                      =\u003e \"gold\"\n    when score \u003e= 650 and income \u003e= 50000  =\u003e \"gold\"\n    when score \u003e= 650                      =\u003e \"silver\"\n    else                                   =\u003e \"bronze\"\n}\n```\n\nBecause it's a function kind, a `decision` can implement an interface method —\nmaking the whole policy DI-injectable:\n\n```x\ninterface Pricing { decision quote(score: Number, base: Number) -\u003e Number }\nclass StdPricing implements Pricing {\n    deps { risk: RiskModel }\n    decision quote(score: Number, base: Number) -\u003e Number {\n        hit first\n        when risk.risky(score) =\u003e base * 2      // condition uses an injected dep\n        when score \u003e= 700      =\u003e base * 0.9\n        else                   =\u003e base\n    }\n}\n```\n\nFor multi-dimensional rules there is also a **table form** — `in`/`out` columns\nand one `| … =\u003e … |` row per rule, with a small cell DSL (`-`, `\u003e= n`, `[a .. b]`,\n`in {…}`, `not`, `?(expr)`):\n\n```x\ndecision shipping {\n    in weight: Number   in zone: String   out cost: Number   hit first\n    |  \u003c= 1     | \"US\"            =\u003e  5 |\n    |  [1 .. 5] | -               =\u003e 15 |\n    |  -        | -               =\u003e 25 |   // default\n}\n```\n\nA decision desugars to an `if/return` chain (zero runtime overhead). See\n[decision tables](https://code-by-sia.github.io/x/decisions),\n[`examples/decision_demo.x`](examples/decision_demo.x), and\n[`examples/decision_table_demo.x`](examples/decision_table_demo.x).\n\n## A tour of the rest\n\n**Refined types** — constraints enforced when a value is constructed:\n\n```x\ntype Age    = Number where value \u003e= 0 and value \u003c= 130\ntype Person = { name: String, age: Age }\npredicate isAdult(p: Person) { return p.age \u003e= 18 }   // pure: cannot mutate\n```\n\n**Error handling** with `T!`, `ok`/`err`, and `?`:\n\n```x\nmapper checkAge(n: Number) -\u003e Age! {\n    if n \u003c 0   { return err(\"age is negative\") }\n    if n \u003e 130 { return err(\"age too large\") }\n    return ok(n)\n}\nmapper classify(n: Number) -\u003e String! {\n    let a = checkAge(n)?              // propagate the Err, else unwrap\n    if a \u003c 18 { return ok(\"minor\") }\n    return ok(\"adult\")\n}\n```\n\n**`where`-guarded overloading** — the compiler builds a dispatcher that picks the\nfirst overload whose guard holds:\n\n```x\nmapper mapResponse(r: ApiResponse) -\u003e String where r.status == 200 { return \"OK: \" + r.body }\nmapper mapResponse(r: ApiResponse) -\u003e String where r.status \u003e= 500 { return \"Server Error\" }\nmapper mapResponse(r: ApiResponse) -\u003e String { return \"Unhandled \" + r.status }   // default\n```\n\n**`match`**, **multi-file `import` / `namespace`**, the **standard library**, and\nmore are covered in the [guide](https://code-by-sia.github.io/x/). See [`examples/`](examples/) for runnable\nprograms (incl. [`fs_demo.x`](examples/fs_demo.x) and a loopback TCP echo in\n[`net_demo.x`](examples/net_demo.x)).\n\n## How it compiles\n\n```\nsource.x (+ imported files)\n  ↓ load     resolve `import`s, apply `namespace` prefixing   (compiler/driver.x)\n  ↓ lex      tokeniser                                        (compiler/lexer.x)\n  ↓ parse    recursive-descent parser                         (compiler/parser.x)\n  ↓ codegen  C99: DI wiring, vtables, refined types, overloads, results, match\n  ↓ cc       C → native binary (invoked automatically)\n```\n\nThe compiler is itself an Xi program (`compiler/*.x`); `selfhost.sh` proves the\nfixpoint (successive self-compiles emit byte-identical C). See\n[internals](https://code-by-sia.github.io/x/internals).\n\n## Project layout\n\n```\ncompiler/   the compiler, written in Xi (lexer, parser, codegen, driver) + xc_helpers.c\n            plus bootstrap.sh / fetch-seed.sh / selfhost.sh\nruntime/    the C runtime (runtime.h, runtime.c) — the Xi equivalent of libc/libcore\nstd/        standard library (math, text, bytes, convert, json, yaml, xml, events, io, fs, path, net, process, time)\nexamples/   runnable programs, incl. proj/ (multi-file) and showcase/ (full project)\ndocs/       MkDocs documentation\neditors/    Tree-sitter grammar, Zed extension, Vim plugin\n```\n\n## Editor support\n\nA Tree-sitter grammar plus **Zed** and **Vim** integrations live in\n[`editors/`](editors/). The grammar parses every `.x` file in this repo.\n\n## License\n\nXi is licensed under the **Apache License 2.0** — see [LICENSE](LICENSE) and\n[NOTICE](NOTICE) (the same license Kotlin uses). It is provided **\"AS IS\",\nwithout warranties of any kind, and with no obligation of support**\n(Apache-2.0 §7–§8). It's an experimental personal project — issues/PRs are\nwelcome, but no support or maintenance is guaranteed. See\n[CONTRIBUTING.md](CONTRIBUTING.md) and [SUPPORT.md](SUPPORT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-by-sia%2Fx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-by-sia%2Fx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-by-sia%2Fx/lists"}