{"id":50946320,"url":"https://github.com/ahojukka5/weavec2","last_synced_at":"2026-06-17T20:35:31.283Z","repository":{"id":360569177,"uuid":"1248555100","full_name":"ahojukka5/weavec2","owner":"ahojukka5","description":"Self-hosted Weave compiler — written in surface Weave itself. Top of the bootstrap chain; bootstrapped via weavefront + weavec1.","archived":false,"fork":false,"pushed_at":"2026-05-27T00:31:13.000Z","size":727,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-27T02:12:52.619Z","etag":null,"topics":["bootstrap","compiler","llvm","programming-language","self-hosting","weave-lang"],"latest_commit_sha":null,"homepage":null,"language":"LLVM","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/ahojukka5.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"NOTICE","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-24T19:48:37.000Z","updated_at":"2026-05-27T00:31:15.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ahojukka5/weavec2","commit_stats":null,"previous_names":["ahojukka5/weavec2"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ahojukka5/weavec2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2Fweavec2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2Fweavec2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2Fweavec2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2Fweavec2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahojukka5","download_url":"https://codeload.github.com/ahojukka5/weavec2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2Fweavec2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34465321,"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-17T02:00:05.408Z","response_time":127,"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":["bootstrap","compiler","llvm","programming-language","self-hosting","weave-lang"],"created_at":"2026-06-17T20:35:30.397Z","updated_at":"2026-06-17T20:35:31.271Z","avatar_url":"https://github.com/ahojukka5.png","language":"LLVM","funding_links":[],"categories":[],"sub_categories":[],"readme":"# weavec2 — Weave Surface-Language Compiler (self-hosted)\n\n[![ci](https://github.com/ahojukka5/weavec2/actions/workflows/ci.yml/badge.svg)](https://github.com/ahojukka5/weavec2/actions/workflows/ci.yml)\n\n\u003e The self-hosted Weave compiler. **Written in surface Weave**,\n\u003e bootstrapped by [`weavefront`](https://github.com/ahojukka5/weavefront)\n\u003e (surface → WIR) and [`weavec1`](https://github.com/ahojukka5/weavec1)\n\u003e (WIR → LLVM IR), then linked with [`weavec0`](https://github.com/ahojukka5/weavec0)'s\n\u003e runtime.\n\n## Overview\n\nThe Weave compiler chain is split across separate stages that each do\none thing well:\n\n```\n.weave  ──[ weavefront ]──\u003e  .wir  ──[ weavec1 / weavec2 ]──\u003e  .ll  ──[ clang ]──\u003e  exe\n```\n\n`weavec2` is the **top** of the chain. It is the first compiler in\nthe family to be written in **surface Weave** (the user-facing\nsyntax), not in WIR or LLVM IR. Once built, it can compile any\nsurface-Weave program — including, eventually, itself end-to-end\nthrough the surface pipeline.\n\nWhat's inside:\n\n- **Frontend** (`src/frontend/`) — surface Weave → WIR lowering,\n  including struct declarations, quantum-op normalisation, and\n  driver glue.\n- **Backend** (`src/llvm/`) — WIR → LLVM IR emission, including a\n  loop-phi optimisation pass for direct SSA codegen of loop-carried\n  scalars.\n- **Core** (`src/core/`) — shared helpers: C-runtime externs,\n  byte-write I/O, s-expression tree navigation.\n\nSee [`docs/`](docs/) for design notes on the loop-phi contract,\nLLVM codegen, quantum syntax, and the representation-lowering\nbridge.\n\n---\n\n## Prerequisites\n\n`weavec2` builds with a standard LLVM toolchain plus `git`:\n\n- `clang`, `llvm-as`, `llvm-link` — LLVM 14 or newer (opaque pointers).\n- `git` — to fetch the pinned dependencies on first build.\n- `bash` 4 or newer.\n\nInstallation hints:\n\n```sh\n# Debian / Ubuntu\nsudo apt-get install -y llvm clang git\n\n# macOS (Homebrew)\nbrew install llvm git\nexport PATH=\"$(brew --prefix llvm)/bin:$PATH\"\n```\n\nCI runs on `ubuntu-latest` and `macos-latest` against the\npackage-manager LLVMs.\n\n---\n\n## Quick start\n\n```sh\ngit clone https://github.com/ahojukka5/weavec2.git\ncd weavec2\n./build.sh\n./test-all.sh\n```\n\n**Note**: the first `./build.sh` is slower than subsequent runs —\nit also clones and builds the pinned `weavec0`, `weavec1`, and\n`weavefront` tags into `build/vendor/`. Re-runs reuse the cached\nvendor copies.\n\n---\n\n## Repository layout\n\n```text\nweavec2/\n  build.sh                    # build driver\n  test.sh                     # correctness tests\n  test-all.sh                 # full ladder (build + all test buckets)\n  selfhost.sh                 # deeper stage1/stage2 bootstrap (experimental)\n  surface-matrix.sh           # surface-corpus health probe\n  src/\n    main.weave                # entry point\n    core/                     # extern.weave, io.weave, util.weave\n    frontend/                 # surface → WIR (lower, emit, struct,\n                              # quantum_nativize, driver, ...)\n    llvm/                     # WIR → LLVM IR (ctx, types, locals,\n                              # strings, expr, loop-phi, stmt, fn,\n                              # module)\n  test/\n    correctness/              # 124 cases (.weave + .wir fixtures)\n    performance/              # 168 cases (.wir + .expected.ll goldens)\n    quantum/                  # validation + e2e quantum-op tests\n    selfhost/                 # weavec2 recompiles its own .wir\n  runtime/quantum_runtime.c   # tiny C runtime for quantum e2e tests\n  scripts/                    # performance-golden analyzer helpers\n  docs/                       # design notes\n  build/                      # build outputs (gitignored)\n    vendor/{weavec0,weavec1,weavefront}/   # auto-fetched dependencies\n```\n\n---\n\n## Build\n\n```sh\n./build.sh\n```\n\nEnvironment overrides:\n\n- `WEAVEC0=/path/to/weavec0` — point at an existing weavec0 source\n  tree. Skips the vendor fetch.\n- `WEAVEC1=/path/to/weavec1` — same idea for weavec1.\n- `WEAVEFRONT=/path/to/weavefront` — same idea for weavefront.\n- `WEAVEC0_TAG=vX.Y.Z` — change the pinned weavec0 tag (default\n  `v0.2.0`). Delete `build/vendor/weavec0/` to force a refetch.\n- `WEAVEC1_TAG=vX.Y.Z` — same idea for weavec1 (default `v0.1.0`).\n- `WEAVEFRONT_TAG=vX.Y.Z` — same idea for weavefront (default\n  `v0.1.0`).\n\nThe script:\n\n1. **Resolves weavec0** — via env or git-clone into\n   `build/vendor/weavec0/`. We need it for `runtime.c`.\n2. **Resolves weavec1** — via env or git-clone, then builds it\n   with `WEAVEC0=$WEAVEC0_DIR` pre-set so the dependency isn't\n   built twice.\n3. **Resolves weavefront** — via env or git-clone, then builds it\n   with both `WEAVEC0` and `WEAVEC1` pre-set.\n4. **Concatenates `src/**/*.weave`** into `build/weavec2.wir` via\n   `weavefront-cat.sh`.\n5. **Compiles `weavec2.wir` → `weavec2.ll`** with weavec1.\n6. **Links** with weavefront's parser-runtime modules\n   (`sexpr_*.ll`) and weavec0's `runtime.c` into `build/weavec2`.\n\n---\n\n## Tests\n\n`./test-all.sh` runs the full ladder:\n\n| Bucket | Driver | Count |\n|--------|--------|------:|\n| Correctness (surface + WIR end-to-end) | `test.sh` | 124 |\n| Performance (WIR + golden LLVM IR) | `test/performance/test.sh` | 168 |\n| Quantum validation | `test/quantum/test.sh` | 4 |\n| Quantum e2e (links `runtime/quantum_runtime.c`) | `test/quantum/test-e2e.sh` | 1 |\n| Self-host basic (recompile `build/weavec2.wir`) | `test/selfhost/test.sh` | 1 |\n\nA passing run ends with `all weavec2 checks passed`.\n\n### Performance goldens\n\n`test/performance/test.sh` diffs emitted LLVM against checked-in\n`*.expected.ll` fixtures. Regenerate with:\n\n```sh\n./test/performance/regen-golden.sh\n```\n\nReview the resulting `git diff` before committing.\n\n### Self-host workflows\n\n- `test/selfhost/test.sh` (run by `./test-all.sh`) is the basic\n  self-host gate: weavec2 compiles its own bootstrapped\n  `build/weavec2.wir`, and the output is accepted by `llvm-as` and\n  verified by `opt -passes=mem2reg`. This passes.\n- `./selfhost.sh` is the deeper bootstrap flow: re-run the\n  surface → WIR pass with the bootstrapped weavec2 and rebuild\n  through stages 1 → 2, then run three fixture smoke tests\n  against the stage2 binary. Passes end-to-end after the call-site\n  guards, `main`-first codegen, and pass-2 `main.weave` ordering\n  (see [`CHANGELOG.md`](CHANGELOG.md)).\n  Not in CI — local-only since it builds weavec2 three times.\n- `./build.sh` uses `weavefront-cat` for `build/weavec2.wir` and,\n  when `build/selfhost/stage2/weavec2` exists, compiles that WIR with\n  `weavec2 --backend` instead of weavec1. Override with\n  `WEAVEC2_BACKEND=/path/to/weavec2 ./build.sh`.\n- `./selfhost.sh` uses the same `SOURCES` order as `build.sh`\n  (`main.weave` last). Pass-2 lowering emits `main.weave` first;\n  the backend emits `(fn main ...)` before other functions in LLVM.\n\n### surface-matrix.sh\n\n`./surface-matrix.sh` walks `test/correctness/surface/` and reports\nhow many cases each pipeline stage (frontend, backend, llvm-as,\nclang, run) accepts. It's a development health probe, not a\npass/fail gate.\n\n---\n\n## Examples\n\nSuggested entry points for first-time readers:\n\n- [`test/correctness/surface/01_return_constant.weave`](test/correctness/surface/01_return_constant.weave)\n  — the smallest possible surface program.\n- [`test/correctness/surface/07_if.weave`](test/correctness/surface/07_if.weave)\n  — branching.\n- [`test/correctness/surface/08_while.weave`](test/correctness/surface/08_while.weave)\n  — loops and mutable locals.\n- [`test/correctness/surface/57_struct_basic.weave`](test/correctness/surface/57_struct_basic.weave)\n  — struct declarations and their lowered getter / setter accessors.\n- [`test/quantum/`](test/quantum) — surface quantum operations\n  (`qgate`, `qmeasure`) and their nativised WIR.\n\n---\n\n## Where weavec2 fits in the chain\n\nThe Weave compiler chain spans four separate repositories:\n\n| Stage | Repo | Role |\n|-------|------|------|\n| `weavec0` | [`ahojukka5/weavec0`](https://github.com/ahojukka5/weavec0) | Hand-written LLVM-IR seed compiler. Compiles WIR → LLVM. Tiny, frozen. |\n| `weavec1` | [`ahojukka5/weavec1`](https://github.com/ahojukka5/weavec1) | WIR-written compiler. Compiled by weavec0. Same WIR → LLVM contract, self-hosted. |\n| `weavefront` | [`ahojukka5/weavefront`](https://github.com/ahojukka5/weavefront) | Surface → WIR frontend. Written in WIR, compiled by weavec1. |\n| `weavec2` | **this repo** | Surface-Weave compiler (self-hosted). Same end-to-end role as `weavefront + weavec1` but in one binary written in surface Weave. |\n\nEventually `weavec2` should replace the `weavefront + weavec1`\nchain for surface inputs entirely. Until then both pipelines\ncoexist; weavec2 is bootstrapped through the older one.\n\n---\n\n## Known limitations\n\nThese are intentional scope choices — not bugs:\n\n- **No source-style checker for `.weave` modules yet.** The\n  weavec1 checker only validates WIR style. A surface-Weave\n  checker is a follow-up.\n- **`surface-matrix.sh` reports compile counts**, not pass/fail\n  thresholds. Development health probe, not a CI gate.\n- **The vendored dependency caches** at `build/vendor/{weavec0,\n  weavec1, weavefront}/` are not auto-updated when their `_TAG`\n  pins change. Delete the directories and re-run `./build.sh` to\n  refetch.\n- **`runtime/quantum_runtime.c` is a stub.** It implements just\n  enough surface area for the quantum e2e test (`test/quantum/`)\n  to link. Not a production quantum runtime.\n\n---\n\n## License\n\nLicensed under the Apache License, Version 2.0. See\n[`LICENSE`](LICENSE) and [`NOTICE`](NOTICE).\n\n## Contributing\n\nPull requests and issues are welcome. The merge bar is described in\n[`CONTRIBUTING.md`](CONTRIBUTING.md) — please read it, and the\n**Known limitations** section above, before opening a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahojukka5%2Fweavec2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahojukka5%2Fweavec2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahojukka5%2Fweavec2/lists"}