{"id":51466080,"url":"https://github.com/dhotnetworks/kai","last_synced_at":"2026-07-06T11:02:07.356Z","repository":{"id":367902134,"uuid":"1282748391","full_name":"DHOTNetworks/KAI","owner":"DHOTNetworks","description":"Welcome to the self-hosted version of the Kai systems programming language compiler!","archived":false,"fork":false,"pushed_at":"2026-07-05T11:16:09.000Z","size":2542,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-05T13:09:17.747Z","etag":null,"topics":["ai","c","kai-lang","language","new-programming-language","programming","systems-programming"],"latest_commit_sha":null,"homepage":"https://zephyria.site/kai","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DHOTNetworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-28T06:37:59.000Z","updated_at":"2026-07-05T11:16:12.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/DHOTNetworks/KAI","commit_stats":null,"previous_names":["dhotnetworks/kai"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DHOTNetworks/KAI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DHOTNetworks%2FKAI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DHOTNetworks%2FKAI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DHOTNetworks%2FKAI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DHOTNetworks%2FKAI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DHOTNetworks","download_url":"https://codeload.github.com/DHOTNetworks/KAI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DHOTNetworks%2FKAI/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35187655,"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-07-06T02:00:07.184Z","response_time":106,"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":["ai","c","kai-lang","language","new-programming-language","programming","systems-programming"],"created_at":"2026-07-06T11:02:06.531Z","updated_at":"2026-07-06T11:02:07.341Z","avatar_url":"https://github.com/DHOTNetworks.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kai Compiler (Self-Hosted Version)\n\nWelcome to the clean, self-hosted version of the **Kai** systems programming language compiler! \n\nThis repository has been fully transitioned from the original Python bootstrap compiler. All compiler development, standard library modules, and feature enhancements are now written entirely in Kai and compiled by Kai itself.\n\n---\n\n## 1. Project Structure\n\n- **`src/`**: The self-hosted compiler source code:\n  - [`compiler.kai`](file:///Users/karan/kai-c/src/compiler.kai): Main compiler driver and command-line entrypoint.\n  - [`lexer.kai`](file:///Users/karan/kai-c/src/lexer.kai): Lexical analyzer converting source code to tokens.\n  - [`parser.kai`](file:///Users/karan/kai-c/src/parser.kai): Parser converting tokens to AST nodes. Supports parsing traits, generics, error unions, block curly braces, and inline assembly.\n  - [`type_checker.kai`](file:///Users/karan/kai-c/src/type_checker.kai): Resolves types, tracks mutability/move semantics, and validates symbol scopes.\n  - [`codegen.kai`](file:///Users/karan/kai-c/src/codegen.kai): Transpiles the AST to highly portable C code.\n  - [`ast_nodes.kai`](file:///Users/karan/kai-c/src/ast_nodes.kai) \u0026 [`token_defs.kai`](file:///Users/karan/kai-c/src/token_defs.kai): AST node structure and token type definitions.\n  - [`symbol_table.kai`](file:///Users/karan/kai-c/src/symbol_table.kai): Manages scopes and variable descriptors.\n- **`std/`**: The standard library:\n  - `std/core/allocator.kai`: Allocators and memory management.\n  - `std/collections/`: Core collections (`ArrayList`, `HashMap`, `StringBuilder`).\n  - `std/io/`: Basic I/O and file handling.\n- **`compiler_bootstrap.c`**: The verified C transpilation output of the compiler, used as the zero-dependency bootstrapper.\n\n---\n\n## 2. Current Implementation Status\n\n### A. Unified Pointer System (Option A)\n- **Types**: We only have `*T` (const/immutable pointer) and `*mut T` (mutable pointer). Legacy references (`\u0026T` / `\u0026mut T`) are mapped to pointers in the parser.\n- **Address-Of**: `\u0026x` automatically infers pointer mutability (`*mut T` if the target is a `var`, `*T` if the target is a `let`).\n- **Dereference**: `*ptr` is safe by default and does not require an `unsafe` block.\n- **Type Checking**: Strict type checking prevents assigning `*T` to `*mut T` (const correctness).\n\n### B. Transpiler Feature Alignment\nThe self-hosted compiler supports all core language features 1:1 with the Python reference backend, including:\n- Struct/Enum factory constructors (e.g., `ArrayList\u003cInt\u003e(\u0026allocator)`).\n- Semicolons and curly brace delimiters.\n- C-style `sizeof(Type)` parsing and codegen.\n- Slices, ranges, array literals, and tuple initialization expressions.\n- GCC Inline Assembly (`asm`) blocks with volatile prefixes, inputs, outputs, and clobbers.\n\n---\n\n## 3. How to Bootstrap \u0026 Compile\n\nTo build the compiler from scratch without any pre-existing binaries or Python dependencies:\n\n### Step 1: Build the Bootstrap Compiler\nCompile the C bootstrap file directly using `clang` or `gcc`:\n```bash\nclang -O3 compiler_bootstrap.c -o ./kai_bootstrap\n```\n\n### Step 2: Recompile the Compiler from Source (Self-Hosting)\nCompile the Kai source files using the bootstrapped compiler binary:\n```bash\n./kai_bootstrap src/compiler.kai -o ./kai\n```\n\n### Step 3: Verify the Compiler (Stage 2)\nVerify that the new compiler binary is functional by compiling a target program or recompiling itself:\n```bash\n./kai src/compiler.kai -o ./kai_self_compiled\n```\n## Cross Compilation via Zig\n\n### 1. Translate C output to Zig, skipping the inline C get_exe_dir implementation\n```\nzig translate-c -DNO_GET_EXE_DIR compiler.c \u003e compiler.zig\n```\n\n### 2. Append the Windows compatibility imports\n```\necho 'comptime { _ = @import(\"windows_compat.zig\"); }' \u003e\u003e compiler.zig\n```\n\n### 3. Cross-compile\n```\nzig build-exe compiler.zig -target aarch64-windows-gnu -lc -femit-bin=compiler\n\nzig build-exe compiler.zig -target x86_64-windows-gnu -lc -femit-bin=compiler\n\n```\n\n---\n\n## 4. Next Action Plans / Roadmap\n\nFor the next agent working on this codebase, the priorities are:\n1. **Error Unions implementation (Phase 3)**:\n   [DONE]- Implement status-integer error unions (`T!E`), restoring the `try` / `catch` propagation check logic natively inside the self-hosted type checker and C code generator.\n2. **Standard Library Expansion**:\n   [DONE]- Add native networking, threading wrappers, and standard formatting routines directly into the `std/` directory.\n3. **Compiler Speed Optimizations**:\n   - Modifier compiler structures (e.g., AST pooling, string allocation) to increase the self-compilation throughput.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhotnetworks%2Fkai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhotnetworks%2Fkai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhotnetworks%2Fkai/lists"}