{"id":41319710,"url":"https://github.com/t3m3d/krypton","last_synced_at":"2026-06-11T01:00:45.403Z","repository":{"id":334115545,"uuid":"1138853003","full_name":"t3m3d/krypton","owner":"t3m3d","description":"K Language (K)","archived":false,"fork":false,"pushed_at":"2026-06-06T23:17:17.000Z","size":94486,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-06T23:17:52.988Z","etag":null,"topics":["binary","expansion","k","klang","krypton","krypton-lang","lang","language","programming","quantum"],"latest_commit_sha":null,"homepage":"https://www.krypton-lang.org","language":"HTML","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/t3m3d.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"docs/roadmap.md","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-01-21T07:46:13.000Z","updated_at":"2026-06-06T23:17:21.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/t3m3d/krypton","commit_stats":null,"previous_names":["t3m3d/krypton"],"tags_count":235,"template":false,"template_full_name":null,"purl":"pkg:github/t3m3d/krypton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3m3d%2Fkrypton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3m3d%2Fkrypton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3m3d%2Fkrypton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3m3d%2Fkrypton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/t3m3d","download_url":"https://codeload.github.com/t3m3d/krypton/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t3m3d%2Fkrypton/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34177444,"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-10T02:00:07.152Z","response_time":89,"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":["binary","expansion","k","klang","krypton","krypton-lang","lang","language","programming","quantum"],"created_at":"2026-01-23T05:49:38.741Z","updated_at":"2026-06-11T01:00:45.382Z","avatar_url":"https://github.com/t3m3d.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Krypton\n\n**A self-hosting programming language that emits native machine code without a C compiler in the loop.**\n\n\u003e **Current version: 2.3.0** — KryptScript (`.ks`) extension convention.\n\u003e See [`CHANGELOG.md`](CHANGELOG.md) for the full history.\n\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)\n![Version](https://img.shields.io/badge/version-2.3.0-brightgreen)\n![macOS](https://img.shields.io/badge/macOS-arm64%202.3.0-success)\n![Linux](https://img.shields.io/badge/Linux-x86__64%202.3.0-yellow)\n![Windows](https://img.shields.io/badge/Windows-x86__64%202.3.0-orange)\n\n## File extensions\n\nKrypton recognises two sibling source extensions. **Same compiler, same\nsyntax** — the split is purely a naming convention.\n\n- **`.k`** — library or compiled program. `module foo`, exports, no shebang.\n- **`.ks`** — KryptScript (new in 2.2). A script meant to run directly.\n  Write it **top-to-bottom with no boilerplate** — `kr` auto-wraps the body\n  in `just run { }` when there's no explicit one, so `import`s, `func`s, and\n  statements just go at the top of the file (Swift-style). An explicit\n  `just run { }` still works if you want it. Add `#!/usr/bin/env kr` and\n  `chmod +x` to make it executable on POSIX. On Windows the installer\n  associates `.ks` with `kr.exe` so double-click + `myscript.ks foo bar`\n  from any shell Just Works — the Windows-native equivalent of a `.bat`.\n  Use `.ks` for one-off tools and build glue you'd otherwise reach for bash\n  or Python for. Read more at\n  [`krypton-lang.org/kryptscript`](https://krypton-lang.org/kryptscript.html).\n\n  ```bash\n  # hello.ks — no `just run` wrapper needed\n  import \"k:ansi\"\n  func greet(w) { emit \"Hello, \" + w + \"!\" }\n  kp(bold(cyan(greet(\"world\"))))\n\n  kr hello.ks            # run it\n  kr                     # start the interactive REPL\n  ```\n\n```bash\nkcc -r examples/hello.ks             # POSIX: compile + run + clean up\nchmod +x examples/hello.ks \u0026\u0026 ./examples/hello.ks   # POSIX shebang path\n```\n\n```bat\n:: Windows (after the installer's \"Associate .k/.ks files\" task)\nmyscript.ks foo bar                  :: double-click works too\n```\n\nThe web framework adds a third extension for templates:\n\n- **`.htk`** — htmk + ks template source built by `kweb`. Same Krypton syntax;\n  the convention signals \"this file is meant to render HTML.\"\n\n## What's new in 2.3\n\n**The compiler stopped needing C.** 2.3.0 is fully clang/gcc-free across build,\nrun, imports, and self-host on macOS (arm64), Linux (x86-64), and Windows\n(x86-64) — and the toolchain hosts itself on all three.\n\n\u003e ⚠️ **Breaking changes**\n\u003e - **`kcc.sh` removed.** `kcc` is now the Krypton-native driver (compiled from\n\u003e   `kcc.ks`, no bash dependency). Repoint any scripts/tooling that called `kcc.sh`.\n\u003e - **C path removed.** `--c` / `--gcc` / `--llvm` are gone (hard error). The\n\u003e   native code generators are the only path now.\n\n- **Clang/gcc-free self-host** on all three platforms — fixpoint byte-stable.\n- **Native StringBuilder** (growing-capacity, doubling realloc) — amortized O(1)\n  append; append-heavy code goes from minutes to seconds, self-host RAM drops sharply.\n- **Krypton-native `kcc.ks` driver** replaces the bash `kcc.sh`.\n- **Linux backend parity** — first-class functions/closures (`FUNCPTR`/`callPtr`,\n  `k:fp`), int-arg builtins, library-file + GC-diagnostic fixes, `--aarch64`\n  cross-compile (`--arm64` alias kept).\n- **Windows** — `kcc.exe`/`kcc-bin.exe` driver/backend split, native\n  `krypton_rt.dll` StringBuilder, `kr.exe` Swift-like auto-wrap + REPL.\n- **macOS** — Mach-O self-host crash fixed; fresh-clone build/install fixed.\n\n## What's new in 2.2\n\n- **KryptScript** — `.ks` everywhere the toolchain accepts `.k`. Installer +\n  VS Code extension associate both. `kcc` derives output basenames\n  correctly for either extension.\n- **WASM playground** — every tutorial lesson compiles to `.wasm` via the\n  Krypton-side emitter (`compiler/wasm32/wasm_self.k`) and ships into\n  `web/site/dist/learn/`. The lesson \"Run\" button picks up the precompiled\n  module via `wasm_runner.js` and falls back to the JS bridge when the code\n  box is edited. **16 lessons (01–15, 18, 19)** match `kcc -r` output\n  byte-for-byte through the Node loader; the others fall back transparently.\n- **New WASM helpers `$lineCount` / `$getLine`** — newline-separator\n  counterparts to `$count` / `$split`. Hand-emitted at function indices\n  20 and 21; `lineCount(\"a\\nb\\n\")` returns `2` (matches native\n  trailing-`\\n` discount). Unlocked lessons 18 + 19 with zero regressions.\n- **Krypton in the browser** — host-side ABI hooks let `.ks` modules drive\n  the DOM canvas directly (`canvas_clear`, `canvas_circle`, `canvas_line`,\n  `canvas_set_fill`, `canvas_set_stroke`, `canvas_width`, `canvas_height`,\n  `random_int`, `time_ms`). The site's hero particle animation is now a\n  Krypton-emitted `.wasm` module rather than inline JavaScript — view its\n  source at [`krypton-lang.org/particles.ks`](https://krypton-lang.org/particles.ks).\n- **kweb** — single-binary web framework CLI. Bundled in the Windows\n  installer; build from source on macOS / Linux. `krypton-lang.org` itself\n  is rendered by kweb.\n- **macOS Cocoa scaffold** *(in progress, agent m)* — `headers/objc.krh`,\n  `headers/cocoa.krh`, `stdlib/objc.k`, `stdlib/cocoa.k` land the\n  foundation for native macOS apps written in pure Krypton. Same\n  surface shape as `stdlib/gui.k` on Windows — `cocoaWindow`,\n  `cocoaButton`, `cocoaOnClick` — so a single `.ks` source can target\n  both. Sees `docs/cocoa_design.md` for the binding strategy + the\n  `objc_msgSend` arm64 ABI handoff to the macho backend.\n- **Zero-C HTTP server on macOS** *(agent m)* — `stdlib/server_native.k`\n  is a complete HTTP server in pure Krypton on top of new BSD-socket\n  builtins (`sockMake/Bind/Listen/Accept/Recv/RecvStr/Send/Close`) that\n  the macho backend emits as direct `svc` syscalls. No libc, no clang,\n  no `cfunc`. Verified end-to-end on macOS Tahoe arm64 with URL-decoded\n  query params and HTML/JSON responses. The legacy `k:server` (with\n  Winsock + POSIX `cfunc`) is still around for the Windows / `--gcc`\n  path; new macOS code should `import \"k:server_native\"`.\n\n**Platform release status (2026-06-06 — 2.3.0):**\n\n| Platform | Shipped version | Notes |\n|----------|-----------------|-------|\n| macOS arm64 | **2.3.0** | `brew install t3m3d/krypton/krypton`, the `.pkg`, or the tarball. Clang-free self-host; Krypton-native `kcc.ks` driver. |\n| Linux x86_64 | **2.3.0** | `brew install t3m3d/krypton/krypton` (kcc + kweb), the prebuilt tarball → `./install.sh`, or build from source. No C compiler. Self-hosting. aarch64 via `kcc --aarch64` cross-compile. |\n| Windows x86_64 | **2.3.0** | Inno Setup installer: `kcc.exe`/`kcc-bin.exe` driver/backend split, native `krypton_rt.dll`, `kr.exe` REPL, kweb, WASM, .k/.ks associations. |\n| **VS Code / Antigravity ext.** | **2.3.0** | `extensions/krypton-language-2.3.0.vsix`. Adds `.ks` (KryptScript) alongside `.k`, bundles the `kls` language server for Windows + macOS, ships `KryptScript` as a language-picker alias. |\n\nAll three native toolchains are **clang/gcc-free** for build, run, imports, and\nself-host. One GitHub release ([`2.3.0`](https://github.com/t3m3d/krypton/releases/tag/2.3.0))\ncarries every platform's artifact.\n\n**Bundled CLIs (one package, four commands):**\n\n- `kcc` / `krypton` — compiler.\n- `kr` (POSIX) / `kr.exe` (Windows) — KryptScript runner. POSIX is a\n  shebang-friendly bash shim over `kcc -r` that also (a) **auto-wraps**\n  top-level code in `just run { }` so `.ks` files need no boilerplate, and\n  (b) starts an **interactive REPL** when run with no arguments (`kr` →\n  `ks\u003e` prompt; remembers `import`/`func`/`let`, multi-line blocks, `:help`\n  / `:list` / `:reset` / `:q`). Windows is a tiny native PE\n  (`tools/kr/run.k` → `kr.exe`, ~16 KB) that compiles a `.k`/`.ks` script\n  to a temp file, runs it inheriting stdio, propagates the script's exit\n  code, then cleans up. The installer associates `.ks` with `kr.exe` so\n  Explorer double-click + cmd.exe `myscript.ks args` both Just Work — the\n  Windows-native equivalent of a `.bat` file. _(As of 2.3.0, Windows `kr.exe`\n  has the same top-level auto-wrap + REPL as the POSIX `kr`.)_\n- `kweb` — web framework CLI (`kweb init \u003cname\u003e`, `kweb build`, `kweb serve`,\n  `kweb deploy \u003chost\u003e \u003cuser\u003e`). **Windows-only as of 2.3.0**; the macOS port is\n  pending the `stdlib/fs.k` POSIX rewrite.\n\nKrypton is a dynamically typed language with clean syntax, ~150 built-in functions, and a compiler written in itself.\n\n**2.0 highlights** (see [`CHANGELOG.md`](CHANGELOG.md) for the full list):\n\n- **Mark-sweep GC** with shadow-stack rooting and freelist reuse —\n  long-running programs (LSP, servers, monitors) now stay flat in\n  memory after `gcCollect()`.\n- **Lambdas + closures** as first-class values (`stdlib/fp.k`).\n- **Typed pointers** (`*u8`, `*Vec3`) and `let local TYPE name` for\n  zero-overhead struct field access.\n- **Win32 ABI marshalling** at ~30 call sites — `Sleep(500)` and\n  `let t = GetTickCount()` work directly, no cfunc wrappers.\n- **Memory-mapped files** (`mmapFile` in `stdlib/mmap.k`) for\n  zero-copy file scanning.\n- **Inline asm primitives**: `pause()`, `mfence()`, `lfence()`,\n  `sfence()`, `rdtsc()`.\n\nThe **default** compilation pipeline produces a native executable on every supported platform — no gcc, no clang, no external toolchain at user-invocation time:\n\n| Platform | Backend | Output |\n|----------|---------|--------|\n| **Linux x86_64** | `compiler/linux_x86/elf.k` | Static ELF, direct syscalls, no libc |\n| **Windows x86_64** | `compiler/windows_x86/x64.k` | PE/COFF, kernel32-only via `runtime/krypton_rt.dll` |\n| **macOS arm64** | `compiler/macos_arm64/macho_arm64_self.k` | Mach-O with in-Krypton SHA-256 ad-hoc code signing |\n\nThe native code generators are the only path. The old C escape hatches\n(`--c` / `--gcc` / `--llvm`) were **removed in 2.3.0** — they now hard-error.\n\n```\njxt\ninc \"stdlib/math_utils.k\"\n\nfunc fibonacci(n) {\n    if n \u003c= 1 { emit n }\n    emit toInt(fibonacci(n - 1)) + toInt(fibonacci(n - 2)) + \"\"\n}\n\njust run {\n    kp(fibonacci(\"10\"))\n    kp(isPrime(\"17\"))\n}\n```\n\n---\n\n## Quick Start\n\n### Requirements\n\n**Nothing for end users.** All three supported platforms ship prebuilt seed binaries in `bootstrap/`. `git clone` and go.\n\n| Platform | Files in `bootstrap/` | Compiler at install time |\n|----------|----------------------|--------------------------|\n| Linux x86_64 | `kcc_seed_linux_x86_64`, `elf_host_linux_x86_64`, `optimize_host_linux_x86_64` | none (pure copy) |\n| Windows x86_64 | `kcc_seed_windows_x86_64.exe`, `x64_host_windows_x86_64.exe`, `optimize_host_windows_x86_64.exe` | none (pure copy) |\n| macOS arm64 | `kcc_seed_macos_aarch64` | none (pure copy); macho_host built on first `--native` call via clang |\n| Linux ARM64 | `kcc_seed_linux_aarch64` | none (pure copy); **C path only** — no native ELF aarch64 backend yet, `kcc --native` falls back to gcc/clang |\n\n**Optional, for development only (end users never need a C compiler):**\n- **gcc / clang** — one-time backend bootstrap *only* if you edit a backend\n  emitter (`compiler/linux_x86/elf.k`, `compiler/windows_x86/x64.k`, or\n  `compiler/macos_arm64/macho_arm64_self.k`) and need to rebuild its host seed.\n  Building and running normal programs never touches a C compiler.\n- **macOS**: the `macho_arm64_self.k` pipeline emits Mach-O directly with\n  in-Krypton SHA-256 ad-hoc signing — no clang or `codesign` invocation at\n  user-compile time.\n\n---\n\n### Linux / WSL\n\n**Install via Homebrew (recommended):**\n\n```bash\nbrew tap t3m3d/krypton\nbrew install krypton\n```\n\nInstalls `kcc` (or `krypton`) and `kweb` on PATH — prebuilt static ELF binaries,\nno C compiler. x86_64 only.\n\n**Or the prebuilt tarball / source:**\n\n```bash\ngit clone https://github.com/t3m3d/krypton \u0026\u0026 cd krypton \u0026\u0026 ./install.sh\n```\n\n(or `./build.sh` for a non-installing build).\n\n`./build.sh` copies `bootstrap/kcc_seed_linux_x86_64` directly as `./kcc-x64`. No compiler invoked. Smoke test runs `examples/fibonacci.k` through the native ELF pipeline:\n\n```bash\nkcc hello.k                          # default native pipeline (no gcc)\n./hello                                  # static ELF, direct syscalls, no libc\n```\n\nThe pipeline is `compile.k → .kir → optimize.k → compiler/linux_x86/elf.k → ELF binary`.\n\n### Windows x86_64\n\n**Install via Chocolatey (recommended):**\n\n```\nchoco install krypton\n```\n\nThen use `krypton` (or `kcc`) from any terminal.\n\n**Or build from source:**\n\n```\ngit clone https://github.com/t3m3d/krypton\ncd krypton\nbootstrap.bat\n```\n\n`bootstrap.bat` copies `kcc_seed_windows_x86_64.exe`, `x64_host_windows_x86_64.exe`, and `optimize_host_windows_x86_64.exe` from `bootstrap/` into place. No compiler required.\n\n```\nkcc hello.k                          # default native pipeline (no gcc)\nhello.exe                                # PE/COFF, kernel32-only\n```\n\nThe pipeline is `compile.k → .kir → optimize.k → compiler/windows_x86/x64.k → PE/COFF`. Output exes import only `kernel32.dll` via the bundled `runtime/krypton_rt.dll`.\n\nFor a from-source rebuild of the seed binaries, `build_v141.bat` uses [TDM-GCC](https://jmeubank.github.io/tdm-gcc/) or MSYS2 mingw-w64. End users don't need it.\n\n### macOS arm64\n\n**Install via Homebrew (recommended):**\n\n```bash\nbrew tap t3m3d/krypton\nbrew install krypton\n```\n\nThen use `kcc` (or `krypton`) from any terminal.\n\n**Or build from source:**\n\n```bash\ngit clone https://github.com/t3m3d/krypton \u0026\u0026 cd krypton \u0026\u0026 ./build.sh\n```\n\nThe macOS pipeline is `compile.k → .kir → compiler/macos_arm64/macho_arm64_self.k → Mach-O`. The Krypton-side emitter writes the entire Mach-O — load commands, `__TEXT`/`__DATA`/`__LINKEDIT`, chained fixups — and the SHA-256 ad-hoc code signature, all in Krypton. **No clang, no `as`, no `ld`, no external `codesign` invocation.**\n\n```bash\nkcc hello.k -o hello                  # default: native arm64 Mach-O\n./hello\n```\n\n`./scripts/verify_macho_self.sh` runs the end-to-end self-emitted Mach-O smoke tests.\n\nWhy this differs in implementation from Linux/Windows: macOS Tahoe+ AMFI rejects unsigned and improperly-formatted Mach-Os, so the emitter has to produce a properly chained-fixups dyld-linked binary AND embed a valid code signature. Both happen in pure Krypton.\n\n---\n\n### Write a program\n\n```\n// hello.k\njust run {\n    kp(\"Hello from Krypton!\")\n}\n```\n\nFor multi-file projects (anything with a `module \u003cname\u003e` decl on at\nleast one file), put the `just run { ... }` body in a file literally\nnamed `run.k`. The compiler emits a warning today when it isn't, and\nwill hard-error in the next major. Single-file scripts (no `module`\ndecl) are exempt — `myscript.ks` keeps working from anywhere.\n\n```\nmyproject/\n  run.k        # `just run { ... }` lives here\n  parser.k     # library code: `module myproject`, `func`, `struct`, ...\n  render.k     # library code\n```\n\n### Compile to a native binary (default)\n\n```bash\nkcc hello.k                # produces ./hello (Linux/macOS) or ./hello.exe (Windows)\n./hello\n```\n\nPer-platform pipeline (chosen automatically):\n\n- **Linux** — emits ELF64 directly via [compiler/elf.k](compiler/elf.k). Static binary, direct syscalls, no libc, no dynamic linker.\n- **Windows** — emits PE/COFF directly via [compiler/x64.k](compiler/x64.k). Imports only `kernel32.dll` (via `runtime/krypton_rt.dll`).\n- **macOS** — emits assembly via [compiler/macho.k](compiler/macho.k); `clang` assembles + links + signs into a Mach-O. (Tahoe AMFI rejects hand-rolled static binaries — clang produces a properly dyld-linked binary the kernel will accept.)\n\n### Other compilation modes (opt-in)\n\n```bash\nkcc --ir hello.k                      # emit Krypton IR (.kir) to stdout\nkcc --aarch64 hello.k -o hello        # Linux: cross-compile to a static aarch64 ELF\n```\n\n\u003e The C escape hatches `--c` / `--gcc` / `--llvm` were **removed in 2.3.0**\n\u003e (they now hard-error). Native code generation is the only path.\n\n---\n\n## Language\n\n### Variables\n\n```\nlet x = \"42\"\nlet name = \"Krypton\"\nconst pi = \"3.14159\"\n```\n\nAll values are strings at runtime. Arithmetic auto-detects numeric strings.\n\n### Type Annotations (optional)\n\n```\nlet x: int = \"42\"\nlet name: string = \"Krypton\"\n\nfunc add(a: int, b: int) -\u003e int {\n    emit toInt(a) + toInt(b) + \"\"\n}\n```\n\nAnnotations are parsed and discarded — they document intent for humans and future tooling.\n\n### Functions\n\n```\nfunc greet(name) {\n    emit \"Hello, \" + name + \"!\"\n}\n\njust run {\n    kp(greet(\"World\"))\n}\n```\n\n`emit` (or `return`) returns a value. `just run` is the program entry point.\n\n### Imports — jxt block\n\n**Bracketless form (recommended):**\n\n```\njxt\ninc \"stdlib/result.k\"\ninc \"stdlib/math_utils.k\"\ninc \"windows.h\"\n\njust run { ... }\n```\n\nThe block ends at the first non-`inc` line. Each `inc` is dispatched by the file extension:\n- `.k` → Krypton module (full source inlined at compile time)\n- `.h` / `.krh` → C header (emits `#include` in generated C)\n\n**Brace form (still supported):**\n\n```\njxt {\n    k \"stdlib/result.k\"\n    k \"stdlib/math_utils.k\"\n    c \"windows.h\"\n}\n```\n\n- `k` — Krypton module\n- `c` — C header\n- `t` — alias for `c` (family initial)\n\nThe legacy `import` keyword still works.\n\n### Closures / Lambdas\n\n```\n// Assign anonymous functions to variables\nlet double = func(x) { emit toInt(x) * 2 + \"\" }\nlet add = func(a, b) { emit toInt(a) + toInt(b) + \"\" }\n\nkp(double(\"5\"))      // 10\nkp(add(\"3\", \"4\"))    // 7\n\n// Pass as arguments to higher-order functions\nfunc applyTwice(f, x) { emit f(f(x)) }\nkp(applyTwice(double, \"3\"))   // 12\n```\n\n### Structs\n\n```\nstruct Point {\n    let x\n    let y\n}\n\nlet p = Point { x: \"10\", y: \"20\" }\nkp(p.x)\np.x = \"42\"\n```\n\n### String Interpolation\n\n```\nlet name = \"Krypton\"\nkp(`Hello, {name}!`)\nkp(`1 + 1 = {1 + 1}`)\n```\n\n### Control Flow\n\n```\n// if / else if / else\nif x \u003e 10 { kp(\"big\") } else if x \u003e 5 { kp(\"medium\") } else { kp(\"small\") }\n\n// while\nwhile i \u003c 10 { i += 1 }\n\n// for-in (comma-separated lists)\nfor item in \"a,b,c\" { kp(item) }\n\n// match\nmatch color {\n    \"red\"  { kp(\"warm\") }\n    \"blue\" { kp(\"cool\") }\n    else   { kp(\"other\") }\n}\n\n// try / catch / throw\ntry {\n    throw \"something went wrong\"\n} catch e {\n    kp(\"caught: \" + e)\n}\n```\n\n### Booleans\n\n```\nkp(true)               // \"true\"\nkp(false)              // \"false\"\n\nlet flag = true\nif flag       { kp(\"yes\") }\nif !false     { kp(\"yes\") }\nif \"0\"        { kp(\"never\") }     // \"0\" is falsy\nif \"false\"    { kp(\"never\") }     // \"false\" is falsy\nif \"\"         { kp(\"never\") }     // empty is falsy\nif \"anything\" { kp(\"yes\") }       // any other non-empty is truthy\n```\n\n`true` and `false` are language keywords — they evaluate to the strings\n`\"true\"` and `\"false\"`. There's no distinct boolean runtime type; the\ntruthiness rule (`\"\"` / `\"0\"` / `\"false\"` / `0` are falsy, everything else\ntruthy) carries the semantics through `if`, `while`, `!`, and `isTruthy`.\n\nComparison and logical ops (`==`, `\u003c`, `\u0026\u0026`, etc.) and builtins like\n`hasField` / `isDigit` return `\"1\"` / `\"0\"` for backward compatibility. So\n`true == (5 \u003e 3)` is *false* (`\"true\"` ≠ `\"1\"`) — both are truthy, but\nthey're different value forms. Use `stdlib/booleans.k`'s\n`bool(v)` / `boolEq(a, b)` / `kpBool(v)` helpers when you want to normalize.\n\n### Floats\n\n```\nlet result = fadd(\"3.14\", \"2.72\")\nkp(fformat(result, \"2\"))   // \"5.86\"\n```\n\nFloat builtins: `fadd`, `fsub`, `fmul`, `fdiv`, `fsqrt`, `ffloor`, `fceil`, `fround`, `fformat`, `flt`, `fgt`, `feq`\n\n---\n\n## Compilation Pipeline\n\nThe default `kcc source.k` invocation produces a native binary using a Krypton-only emitter. No C compiler or linker is invoked at user-call time on any of the three supported platforms:\n\n```\nsource.k\n    │\n    ├─ Linux x86_64   (default):  source.k → .kir → optimize.k →\n    │                              compiler/linux_x86/elf.k → ELF binary\n    │                              (direct syscalls, no libc, no linker)\n    │\n    ├─ Windows x86_64 (default):  source.k → .kir → optimize.k →\n    │                              compiler/windows_x86/x64.k → PE/COFF\n    │                              (kernel32-only via runtime/krypton_rt.dll)\n    │\n    ├─ macOS arm64    (default):  source.k → .kir →\n    │                              compiler/macos_arm64/macho_arm64_self.k →\n    │                              Mach-O (in-Krypton SHA-256 ad-hoc signing)\n    │\n    ├─ --aarch64      (Linux):    source.k → .kir →\n    │                              compiler/linux_aarch64/elf.k → static aarch64 ELF\n    │\n    └─ --ir:                      source.k → Krypton IR (.kir) to stdout\n\n  (The --c / --gcc / --llvm C escape hatches were removed in 2.3.0.)\n```\n\n### Krypton IR\n\n```\nkcc --ir source.k \u003e source.kir\n```\n\nEmits `.kir` — a stack-based intermediate representation, one instruction per line:\n\n```\nFUNC add 2\nPARAM a\nPARAM b\nLOCAL result\nLOAD a\nBUILTIN toInt 1\nLOAD b\nBUILTIN toInt 1\nADD\nPUSH \"\"\nADD\nRETURN\nEND\n```\n\n### IR Optimizer\n\n```\noptimize.exe source.kir \u003e source_opt.kir\n```\n\nSix passes: dead code elimination, constant folding, strength reduction,\nSTORE/LOAD elimination, empty jump removal, unused local removal.\n\n---\n\n## Standard Library\n\n77+ modules in `stdlib/`. Highlights:\n\n| Module | Contents |\n|--------|----------|\n| `math_utils.k` | gcd, lcm, isPrime, fibonacci, factorial, sqrt, abs, power |\n| `result.k` | ok/err/isOk/isErr/unwrap/unwrapErr/unwrapOr |\n| `option.k` | optSome/optNone/isSome/isNone/optUnwrap |\n| `json.k` | jsonStr/jsonBool/jsonArray/jsonObject/jsonNull |\n| `float_utils.k` | floatAdd/floatMul/floatSqrt/floatFormat/pi() |\n| `arch.k` | Host CPU detection — `arch()`, `isArm()`, `isX86()`, `is64Bit()` |\n| `x11.k` | X11 wire-protocol client (handshake + server-info parse; Linux GUI flagship) |\n| `server_native.k` | Pure-Krypton HTTP server on the macOS native socket builtins |\n| `color.k` | Hex/RGB/HSL conversion + lighten/darken/mix |\n| `mime.k` | MIME type lookup by extension or path |\n| `cookie.k` | HTTP cookie parse + build (`Set-Cookie:` attrs) |\n| `base64.k` / `hex.k` | RFC 4648 + standard hex encode/decode |\n| `csv.k` / `url.k` | RFC 4180 CSV + RFC 3986 URL parse / build |\n| ... | 65 more modules in `stdlib/` — see `ls stdlib/*.k` |\n\n---\n\n## Ecosystem\n\nSibling repos under the same GitHub org. Each is its own program/repo,\nbuilt against this Krypton checkout via `KRYPTON_ROOT/kcc`.\n\n| Repo | Language | Platforms | What it is |\n|---|---|---|---|\n| [kryofetch](https://github.com/t3m3d/kryofetch) | Krypton | Windows 10/11, Linux x86_64 | System-info CLI (neofetch-class). Talks to Win32 / `/proc` / `/sys` directly — no WMI, no PowerShell, no Python. |\n| [yubikrypt](https://github.com/t3m3d/yubikrypt) | KryptScript | macOS arm64, Linux x86_64 | YubiKey detector + OATH/TOTP authenticator. Single self-contained `.ks`. |\n| [kryoterm](https://github.com/t3m3d/kryoterm) | Krypton + KryptScript | Linux x86_64 (phase 0) | Krypton-native terminal emulator. Targets `stdlib/x11.k` for windowing once Phase B/C ship — no Qt, no GTK, no libX11. |\n| [terk](https://github.com/t3m3d/terk) | C++ / Qt6 | Windows, macOS, Linux | Pre-existing Qt6 terminal. Slated to retire once `kryoterm` reaches feature parity. |\n| [kmon](https://github.com/t3m3d/kmon) | Krypton | Windows 10/11 (requires Npcap) | Real-time network monitor — captures live packets, parses Ethernet + IPv4 + TCP/UDP/ICMP, streams to a browser dashboard via SSE. |\n\nEach app's repo ships its own `build_linux.sh` + `PKGBUILD` (where applicable).\nArch users: `git clone \u003crepo\u003e \u0026\u0026 cd \u003crepo\u003e \u0026\u0026 makepkg -si`.\n\n\u003e Linux aarch64 support for the Krypton-language apps lands once the aarch64\n\u003e backend reaches Milestone 4 (string concat). See [`LINUX_RELEASE_TODO.md`](LINUX_RELEASE_TODO.md).\n\n---\n\n## Project Structure\n\n```\nkrypton/\n├── compiler/\n│   ├── compile.k                       # Self-hosting frontend\n│   ├── optimize.k                      # IR optimizer\n│   ├── llvm.k                          # LLVM IR backend (optional)\n│   ├── run.k                           # Interpreter\n│   ├── linux_x86/elf.k                 # Linux x86_64 ELF emitter\n│   ├── windows_x86/x64.k               # Windows x86_64 PE/COFF emitter\n│   └── macos_arm64/macho_arm64_self.k  # macOS arm64 Mach-O emitter (with signing)\n├── runtime/\n│   ├── krypton_rt.k       # Krypton runtime (Phase 2 — self-hosted)\n│   └── krypton_rt.dll     # Windows bootstrap runtime (kernel32-only, hand-emitted by x64.k)\n├── bootstrap/                                # Prebuilt seeds — pure-copy install, no compiler\n│   ├── kcc_driver_\u003cos\u003e_\u003carch\u003e                # kcc.ks-built driver (the `kcc` command), per platform\n│   ├── kcc_seed_linux_x86_64                 # Linux x86_64 kcc ELF\n│   ├── elf_host_linux_x86_64                 # Linux x86_64 ELF emitter\n│   ├── optimize_host_linux_x86_64            # Linux x86_64 IR optimizer\n│   ├── kcc_seed_linux_aarch64                # Linux ARM64 kcc ELF (C path only — no ARM64 ELF emitter yet)\n│   ├── kcc_seed_windows_x86_64.exe           # Windows kcc PE\n│   ├── x64_host_windows_x86_64.exe           # Windows PE/COFF emitter\n│   ├── optimize_host_windows_x86_64.exe      # Windows IR optimizer\n│   ├── kcc_seed_macos_aarch64                # macOS arm64 kcc Mach-O\n│   └── REBUILD_SEED.md                       # How/when to rebuild seeds (covers all platforms)\n├── stdlib/                # Standard library modules (~30 files: result, option, json, math_utils, …)\n├── examples/              # Showcase programs (84 files: hello, fibonacci, calculator, hex_dump, …)\n├── algorithms/            # Textbook algorithm reference impls (35 files: sorts, DP, graph, KMP, …)\n├── tutorial/              # Step-by-step language intro (25 numbered lessons)\n├── tools/                 # Single-file CLI utilities written in Krypton (cat, grep, head, fmt, …)\n├── headers/               # .krh module headers (Win32, libc bindings)\n├── tests/                 # Test suite (38 tests, run via ./build.sh test)\n├── docs/                  # Roadmap + EBNF/types/functions specs\n├── grammar/               # Single-source EBNF (krypton.ebnf)\n├── extensions/            # Prebuilt VS Code extension (.vsix)\n├── krypton-lang/          # Source for the VS Code extension; syntaxes/ is a git submodule\n│                          # pinned to https://github.com/t3m3d/krypton-tmLanguage\n├── assets/                # Windows icon resource (krypton_rc.o)\n├── installer/             # Windows installer build artifacts\n├── scripts/               # Dev helpers — sweep_examples.sh, sweep_algorithms.sh, build_vsix.sh, …\n├── versions/              # Historical bootstrap binaries\n├── build.sh               # Linux/macOS/WSL build (uses prebuilt seed when available)\n├── bootstrap.bat          # Windows install (copies prebuilt binaries from bootstrap/)\n├── build_v141.bat         # Windows from-source rebuild (requires TDM-GCC, dev only)\n├── install.sh             # Linux install (build + symlink to /usr/local/bin)\n├── kcc                 # Compiler driver (dispatches to per-platform native emitter)\n├── Makefile               # Cross-platform make wrapper around build scripts\n├── CHANGELOG.md           # Full version history\n└── LICENSE                # Apache 2.0\n```\n\n---\n\n## Bootstrap\n\nKrypton solves the self-hosting chicken-and-egg problem by shipping prebuilt seed binaries in `bootstrap/` for every supported platform. A fresh clone needs **no compiler** to install.\n\n**End-user install (no compiler on any platform):**\n\n| Platform | Install command | What it does |\n|----------|-----------------|--------------|\n| Linux x86_64 | `./build.sh` | `cp bootstrap/kcc_seed_linux_x86_64 ./kcc-x64`, copies elf_host + optimize_host into place, smoke-tests fibonacci |\n| Windows x86_64 | `bootstrap.bat` | copies `kcc_seed_*.exe`, `x64_host_*.exe`, `optimize_host_*.exe` |\n| macOS arm64 | `./build.sh` | `cp bootstrap/kcc_seed_macos_aarch64 ./kcc-arm64` (M1/M2/M3) |\n\nPure `cp` — no compiler invoked at install. After that, `kcc source.k` runs the platform's native emitter end-to-end with no C tools.\n\n**Re-seeding (developer-only):**\n\nIf you edit `compiler/\u003cplatform\u003e/\u003cemitter\u003e.k` you may need to rebuild the seed. As of 2.3.0 the native toolchain regenerates its own seeds with **no C compiler** (the frontend self-hosts and the backend host is rebuilt by the native pipeline); the exact steps live in [bootstrap/REBUILD_SEED.md](bootstrap/REBUILD_SEED.md). (macOS still uses clang for the one-time `macho_host` rebuild if you edit `macho_arm64_self.k` and no prebuilt host is present.)\n\nThe compiler has been self-hosting since the v0.1 series. Historical bootstrap binaries live in `versions/`.\n\n---\n\n## Native Headers (.krh)\n\nHeaders in `headers/` declare external (C library / OS API) functions so\nKrypton programs can call them via FFI through the C-emitter pipeline.\n\n### C standard library\n\n| Header | Contents |\n|--------|----------|\n| `stdio.krh` | C stdio — printf, fopen, fread, fwrite, fgets |\n| `stdlib.krh` | malloc, free, atoi, atof, exit, system, getenv, qsort, rand |\n| `string.krh` | strlen, strcpy, strcat, strcmp, strstr, memcpy, memset |\n| `math.krh` | libm — sin, cos, sqrt, pow, log, exp, floor, ceil |\n| `time.krh` | time, ctime, strftime, clock, clock_gettime, nanosleep |\n| `ctype.krh` | isalpha, isdigit, isspace, tolower, toupper, etc. |\n| `errno.krh` | strerror, perror |\n| `assert.krh` | __assert_fail (Krypton's `assert` builtin is preferred) |\n| `signal.krh` | signal, raise, kill, sigaction |\n| `setjmp.krh` | setjmp, longjmp (Krypton's `try`/`catch` is preferred) |\n\n### POSIX (Linux / macOS)\n\n| Header | Contents |\n|--------|----------|\n| `unistd.krh` | read, write, close, fork, exec*, getpid, sleep, chdir |\n| `sys_stat.krh` | stat, fstat, mkdir, chmod, umask |\n| `fcntl.krh` | open, fcntl, posix_fadvise |\n| `dirent.krh` | opendir, readdir, closedir |\n| `sys_socket.krh` | POSIX sockets — socket, bind, listen, accept, send, recv |\n| `netinet_in.krh` | sockaddr_in, in6_addr, htons/htonl/ntohs/ntohl |\n| `arpa_inet.krh` | inet_pton, inet_ntop, inet_addr |\n| `netdb.krh` | getaddrinfo, gethostbyname, gai_strerror |\n| `sys_mman.krh` | mmap, munmap, mprotect, msync, shm_open |\n| `dlfcn.krh` | dlopen, dlsym, dlclose (link with `-ldl` on Linux) |\n| `pthread.krh` | pthread_create/join, mutex, cond, rwlock, once |\n\n### Windows\n\n| Header | Contents |\n|--------|----------|\n| `windows.krh` | Win32 system info, registry, console, PDH, toolhelp + GUI structs (RECT, POINT, MSG, WNDCLASSEXA, PAINTSTRUCT) |\n| `user32.krh` | Window classes, message pump, paint, dialogs, input — link with `-luser32` |\n| `gdi32.krh` | Text drawing, pens / brushes / fonts, shapes, bitmaps — link with `-lgdi32` |\n| `fileio.krh` | Windows file I/O — CreateFile, ReadFile, FindFirstFile |\n| `process.krh` | CreateProcess, WaitForSingleObject, CreateThread, Sleep |\n| `winsock.krh` | TCP/UDP networking (Winsock2) — link with `-lws2_32` |\n| `iphlpapi.krh` | Windows IP Helper API — GetAdaptersInfo, GetIfTable |\n| `conio.krh` | _kbhit, _getch (Windows console) |\n\n### Third-party / project-specific\n\n| Header | Contents |\n|--------|----------|\n| `pcap.krh` | libpcap packet capture (Linux: `-lpcap`, Win: `-lwpcap`) |\n| `fetcher.krh` | Internal — kryofetch C backend (`kfetch_api.h`) |\n\nUsage: `import \"headers/stdio.krh\"` then call `printf(\"hello\\n\")` directly.\nThe C-emitter pipeline picks up the corresponding `#include` and emits a\nmatching FFI call. The native pipeline doesn't yet wire FFI — these headers\nare C-path-only today.\n\n---\n\n## Built-in Functions (~150)\n\nI/O, strings, math, lists, maps, structs, floats, exceptions, line operations, system, type utilities, StringBuilder, plus the env / boolean / reverse runtime added in 1.5.0 — see [docs/spec/functions.md](docs/spec/functions.md) for the full reference, with each entry tagged native / C-path.\n\n---\n\n**Krypton** — Copyright 2026 [t3m3d](https://github.com/t3m3d) — Apache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft3m3d%2Fkrypton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ft3m3d%2Fkrypton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft3m3d%2Fkrypton/lists"}