pa-compiler 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. pa_compiler-0.1.0/CHANGELOG.md +33 -0
  2. pa_compiler-0.1.0/LICENSE +21 -0
  3. pa_compiler-0.1.0/MANIFEST.in +6 -0
  4. pa_compiler-0.1.0/PKG-INFO +144 -0
  5. pa_compiler-0.1.0/README.md +104 -0
  6. pa_compiler-0.1.0/RELEASING.md +30 -0
  7. pa_compiler-0.1.0/examples/hashlib_pa/main.pa +235 -0
  8. pa_compiler-0.1.0/examples/hashlib_pa/verify.paw +122 -0
  9. pa_compiler-0.1.0/examples/pipeline_demo/data_fetcher.paw +12 -0
  10. pa_compiler-0.1.0/examples/pipeline_demo/main.pa +24 -0
  11. pa_compiler-0.1.0/examples/raytracer/main.pa +263 -0
  12. pa_compiler-0.1.0/examples/raytracer/rt_bridge.paw +52 -0
  13. pa_compiler-0.1.0/pa_compiler.egg-info/PKG-INFO +144 -0
  14. pa_compiler-0.1.0/pa_compiler.egg-info/SOURCES.txt +55 -0
  15. pa_compiler-0.1.0/pa_compiler.egg-info/dependency_links.txt +1 -0
  16. pa_compiler-0.1.0/pa_compiler.egg-info/entry_points.txt +2 -0
  17. pa_compiler-0.1.0/pa_compiler.egg-info/requires.txt +14 -0
  18. pa_compiler-0.1.0/pa_compiler.egg-info/top_level.txt +1 -0
  19. pa_compiler-0.1.0/pa_lang/__init__.py +2 -0
  20. pa_compiler-0.1.0/pa_lang/build.py +574 -0
  21. pa_compiler-0.1.0/pa_lang/cli.py +139 -0
  22. pa_compiler-0.1.0/pa_lang/codegen.py +1442 -0
  23. pa_compiler-0.1.0/pa_lang/diagnostics.py +196 -0
  24. pa_compiler-0.1.0/pa_lang/doctor.py +525 -0
  25. pa_compiler-0.1.0/pa_lang/infer.py +1090 -0
  26. pa_compiler-0.1.0/pa_lang/lsp_server.py +547 -0
  27. pa_compiler-0.1.0/pa_lang/modules.py +432 -0
  28. pa_compiler-0.1.0/pa_lang/paw.py +194 -0
  29. pa_compiler-0.1.0/pa_lang/runtime_bridge.c +548 -0
  30. pa_compiler-0.1.0/pa_lang/runtime_core.c +158 -0
  31. pa_compiler-0.1.0/pa_lang/skills/cpp-to-pa/SKILL.md +30 -0
  32. pa_compiler-0.1.0/pa_lang/skills/pa-coder/SKILL.md +64 -0
  33. pa_compiler-0.1.0/pa_lang/skills/py-to-pa/SKILL.md +70 -0
  34. pa_compiler-0.1.0/pa_lang/skills_cmd.py +129 -0
  35. pa_compiler-0.1.0/pa_lang/types.py +346 -0
  36. pa_compiler-0.1.0/pa_lang/validator.py +533 -0
  37. pa_compiler-0.1.0/pyproject.toml +57 -0
  38. pa_compiler-0.1.0/setup.cfg +4 -0
  39. pa_compiler-0.1.0/skills/cpp-to-pa/SKILL.md +30 -0
  40. pa_compiler-0.1.0/skills/pa-coder/SKILL.md +64 -0
  41. pa_compiler-0.1.0/skills/py-to-pa/SKILL.md +70 -0
  42. pa_compiler-0.1.0/tests/__init__.py +0 -0
  43. pa_compiler-0.1.0/tests/e2e_four_layer/py_adapter.py +112 -0
  44. pa_compiler-0.1.0/tests/test_codegen.py +380 -0
  45. pa_compiler-0.1.0/tests/test_csr_vec.py +138 -0
  46. pa_compiler-0.1.0/tests/test_doctor.py +242 -0
  47. pa_compiler-0.1.0/tests/test_e2e_four_layer.py +130 -0
  48. pa_compiler-0.1.0/tests/test_features.py +506 -0
  49. pa_compiler-0.1.0/tests/test_hardening.py +363 -0
  50. pa_compiler-0.1.0/tests/test_infer.py +183 -0
  51. pa_compiler-0.1.0/tests/test_lsp.py +113 -0
  52. pa_compiler-0.1.0/tests/test_lsp_stdio.py +202 -0
  53. pa_compiler-0.1.0/tests/test_modules.py +224 -0
  54. pa_compiler-0.1.0/tests/test_release.py +95 -0
  55. pa_compiler-0.1.0/tests/test_relocation.py +131 -0
  56. pa_compiler-0.1.0/tests/test_skills_cli.py +105 -0
  57. pa_compiler-0.1.0/tests/test_validator.py +154 -0
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
4
+ versioning: [SemVer](https://semver.org/) (`0.x` = alpha, the language and ABI may still change).
5
+
6
+ ## [0.1.0] - 2026-11-25
7
+
8
+ First public release.
9
+
10
+ ### Language and compiler
11
+ - `.pa` front end: zero-annotation type inference, stack-bounded escape analysis, `Vec<T>` RAII, `@struct`, 2-D indexing,
12
+ 1-level ragged `Vec[Vec[T]]` lowered to flat contiguous CSR (`data + offsets`), owned `String` + zero-copy `str_view` slicing (`s[a:b]`),
13
+ `**` exponentiation, `libm` intrinsics, default `int`/`uint`/`float` (`i64`/`u64`/`f64`) plus explicit narrow/unsigned types (`int32`, `uint8`, `uint32`, `uint64`, `float32`, `float64`), and `-> T` return annotations (`PA_E085`).
14
+ - Multi-file `.pa` modules: `import mod` / `from mod import ...` resolved via local directory, `-I` / `PA_PATH`, and `pa_lang.libs` pip entry points.
15
+ - `.paw` crossing zone: statically typed `In -> Out` signatures, embedded in the binary, two-way boundary customs,
16
+ `@allow_nan`, dev/prod modes, `pa_boundary_fault.json` with replayable `in_payload_snapshot`.
17
+ - LLVM code generator (`llvmlite`), runtime faults (`ZeroDivisionError`, `IndexError`, `ValueError`, `OverflowError`),
18
+ and `pac build --shared` emitting both guarded C-ABI wrappers and CPython `PyInit_<mod>` entry points for direct Python `import` with zero `ctypes` boilerplate.
19
+ - Hardening diagnostics `PA_E073`, `PA_E086`–`PA_E089`; Python-compatible `print`.
20
+
21
+ ### Tooling
22
+ - `pac check [--ai-diagnostic] [-I DIR]`, `pac build [--mode dev|prod] [--shared] [--relocatable] [-I DIR]`, `pac lsp`, `pac doctor`, `pac bundle [--with-stdlib]`, `pac skill`, `pac --version`.
23
+ - Relocatable binaries (runtime Python resolution via `PA_PYTHON_HOME` / `PA_PYPATH` / `VIRTUAL_ENV` / `PA_PATH`), pure-Python ELF / Mach-O / PE loader diagnostics across Linux, macOS, and Windows, and macOS Framework Python symlink / `@rpath` + re-signing fixes.
24
+ - Language server (`pac lsp`): diagnostics, hover memory-audit cards, inlay hints, Go to Definition (`textDocument/definition`) across `.pa` and `.paw` modules, and auto-restart.
25
+ - VS Code extension (`pa` / `paw`): hover-only default (`pa.inlayHints.detail = "off"`), `#DCDCAA` function highlighting, and transparent RGBA Pa/Paw icons.
26
+ - Skills: `pa-coder`, `py-to-pa`, `cpp-to-pa` (installable via `pac skill --install claude|cursor|codex|copilot|antigravity`).
27
+
28
+ ### Examples
29
+ - `pipeline_demo`, `hashlib_pa` (CRC-32 + SHA-256), and `raytracer` (`Ray Tracing in One Weekend` port).
30
+
31
+ ### Known limits
32
+ - Needs CPython 3.11–3.13 with development headers/shared library and a C compiler (`gcc`, `clang`, or MSVC `cl`).
33
+ - Stepped string slicing (`s[a:b:step]`), list slicing (`arr[a:b]` — use `span()`), `str` returns from `.paw`, and structs across the `.paw` boundary are not supported.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cyyier
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include LICENSE README.md CHANGELOG.md RELEASING.md
2
+ recursive-include pa_lang *.c *.md
3
+ recursive-include tests *.py
4
+ recursive-include skills *.md
5
+ recursive-include examples *.pa *.paw *.py *.md
6
+ global-exclude __pycache__ *.py[cod] *.so *.o
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: pa-compiler
3
+ Version: 0.1.0
4
+ Summary: Pa language: Python-syntax, C++-memory-layout, LLVM-compiled systems language with .paw bridges to the Python ecosystem
5
+ Author: cyyier
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://palang.dev
8
+ Project-URL: Repository, https://github.com/cyyier/pa
9
+ Project-URL: Issues, https://github.com/cyyier/pa/issues
10
+ Project-URL: Changelog, https://github.com/cyyier/pa/blob/main/CHANGELOG.md
11
+ Keywords: compiler,llvm,python,systems-programming,ffi,language
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: C
23
+ Classifier: Topic :: Software Development :: Compilers
24
+ Classifier: Topic :: Software Development :: Code Generators
25
+ Requires-Python: >=3.11
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: llvmlite>=0.50
29
+ Requires-Dist: pygls>=2.1
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest; extra == "dev"
32
+ Provides-Extra: web
33
+ Requires-Dist: fastapi; extra == "web"
34
+ Requires-Dist: httpx; extra == "web"
35
+ Requires-Dist: uvicorn; extra == "web"
36
+ Provides-Extra: release
37
+ Requires-Dist: build; extra == "release"
38
+ Requires-Dist: twine; extra == "release"
39
+ Dynamic: license-file
40
+
41
+ <p align="center">
42
+ <img src="https://raw.githubusercontent.com/cyyier/pa/main/site/Pa.png" alt="Pa logo" width="72" />
43
+ </p>
44
+
45
+ <h1 align="center">Pa</h1>
46
+
47
+ <p align="center">
48
+ Python-syntax, C++-memory-layout, LLVM-compiled systems language with typed <code>.paw</code> bridges to the Python ecosystem.<br/>
49
+ <a href="https://palang.dev">Website</a> ·
50
+ <a href="https://palang.dev/quickstart">Quickstart</a> ·
51
+ <a href="https://palang.dev/architecture">Architecture</a> ·
52
+ <a href="https://github.com/cyyier/pa/blob/main/CHANGELOG.md">Changelog</a>
53
+ </p>
54
+
55
+ ---
56
+
57
+ ## Installation & Minimal Example
58
+
59
+ Requires Linux x86-64, macOS, or Windows x64, CPython 3.11–3.13 (headers + shared Python library), and a C compiler (`gcc`, `clang`, or MSVC `cl`).
60
+
61
+ ```bash
62
+ pip install pa-compiler # installs `pac`
63
+ pac skill --install claude # optional: install AI skills (also: cursor, codex, copilot, antigravity)
64
+ ```
65
+
66
+ Create `hello.pa`:
67
+
68
+ ```python
69
+ def sum_squares(n) -> int:
70
+ total = 0
71
+ for i in range(n):
72
+ total += i * i
73
+ return total
74
+
75
+ def main() -> int:
76
+ print(sum_squares(100000))
77
+ return 0
78
+ ```
79
+
80
+ Compile and run:
81
+
82
+ ```bash
83
+ pac build hello.pa --mode prod -o hello && ./hello
84
+ ```
85
+
86
+ For `.paw` Python bridges, `--relocatable` bundles, `pac doctor`, and `--shared` C-ABI builds, see the full guide at <https://palang.dev/quickstart>.
87
+
88
+ ---
89
+
90
+ ## Repository Layout
91
+
92
+ ```text
93
+ pa/
94
+ ├── pa_lang/
95
+ │ ├── types.py, validator.py, infer.py # Front-end: subset checks, bidirectional inference, escape analysis
96
+ │ ├── paw.py, diagnostics.py # .paw header parser/linter & AI JSON repair tickets
97
+ │ ├── codegen.py, build.py # LLVM IR emission (llvmlite), -O2 object build, gcc link, @export
98
+ │ ├── runtime_core.c, runtime_bridge.c # RAII fault/print core & embedded CPython zero-copy .paw bridge
99
+ │ ├── cli.py, doctor.py, skills_cmd.py # `pac` CLI: check, build, doctor, bundle, skill
100
+ │ ├── lsp_server.py # Auto-reloading LSP server (inlay hints, hover memory audit cards)
101
+ │ └── skills/ # Bundled SKILL.md assets shipped inside the wheel
102
+ ├── skills/ # Source AI skills (pa-coder, py-to-pa, cpp-to-pa)
103
+ ├── vscode-pa/ # VS Code extension (TextMate grammar, LSP client, grammar tests)
104
+ ├── examples/ # pipeline_demo, hashlib_pa (Python port), raytracer (C++ port)
105
+ ├── site/ # palang.dev static site (index, quickstart, architecture)
106
+ └── tests/ # Pytest suites (front-end, codegen, hardening, LSP, doctor, skill)
107
+ ```
108
+
109
+ ---
110
+
111
+ ## Building from Source & Testing
112
+
113
+ ```bash
114
+ git clone https://github.com/cyyier/pa.git && cd pa
115
+ uv venv --python 3.12 .venv # or any CPython 3.11–3.13 with Python.h + shared libpython
116
+ source .venv/bin/activate
117
+ pip install -e ".[dev]"
118
+
119
+ pac doctor # verify gcc, llvmlite, Python.h, shared libpython
120
+ pac check examples tests # run Pa front-end checks
121
+ pytest -q # run full compiler, runtime, LSP, doctor, and CLI test suite
122
+ (cd vscode-pa && npm test) # run VS Code TextMate grammar tests
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Status & Roadmap
128
+
129
+ **Current (`v0.1.0` alpha):**
130
+ - **Supported:** Linux x86-64, macOS (arm64 / x86-64), Windows x64, CPython 3.11–3.13, `gcc` / `clang` / MSVC `cl`, LLVM via `llvmlite`.
131
+ - **Included:** zero-annotation `.pa` compiler (`int`/`uint`/`float`/`bool`, explicit widths `int32`/`uint8`/`uint32`/`uint64`/`float32` + short aliases `i32`/`u8`/`u32`/`u64`/`f32`, `**`, zero-copy `str_view` slicing, `@struct`, stack/RAII `Vec`, flat CSR `Vec[Vec[T]]`, `String`, `libm`, multi-file `.pa` module imports via local dirs / `-I` / `PA_PATH` / pip packages), `.paw` zero-copy CPython bridge with two-way customs, `--shared` guarded C-ABI libraries, `pac doctor` / `pac bundle` (ELF / Mach-O / PE), `pac skill`, `pac lsp`, and VS Code extension.
132
+
133
+ **Planned:**
134
+ - Standalone ecosystem packages (`pa-libs`) for common data, geometry, and parsing libraries (powered by multi-file `.pa` module imports).
135
+ - *(Low priority)* Nested `Vec` fields inside `@struct` with recursive RAII destructors (Pa recommends flat SoA arrays or CSR `Vec[Vec[T]]`).
136
+
137
+ **Non-goals (won't do):**
138
+ - Static `libpython` linking for single-file self-contained binaries — standard Python distributions do not ship portable `libpython.a` (especially on Windows/macOS), and third-party Python C extensions (`.pyd`/`.so` such as NumPy) require dynamic `libpython`. Use `pac build --bundle --with-stdlib` for self-contained directory distribution.
139
+
140
+ ---
141
+
142
+ ## License
143
+
144
+ MIT — see [LICENSE](https://github.com/cyyier/pa/blob/main/LICENSE). Release process: [RELEASING.md](https://github.com/cyyier/pa/blob/main/RELEASING.md).
@@ -0,0 +1,104 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/cyyier/pa/main/site/Pa.png" alt="Pa logo" width="72" />
3
+ </p>
4
+
5
+ <h1 align="center">Pa</h1>
6
+
7
+ <p align="center">
8
+ Python-syntax, C++-memory-layout, LLVM-compiled systems language with typed <code>.paw</code> bridges to the Python ecosystem.<br/>
9
+ <a href="https://palang.dev">Website</a> ·
10
+ <a href="https://palang.dev/quickstart">Quickstart</a> ·
11
+ <a href="https://palang.dev/architecture">Architecture</a> ·
12
+ <a href="https://github.com/cyyier/pa/blob/main/CHANGELOG.md">Changelog</a>
13
+ </p>
14
+
15
+ ---
16
+
17
+ ## Installation & Minimal Example
18
+
19
+ Requires Linux x86-64, macOS, or Windows x64, CPython 3.11–3.13 (headers + shared Python library), and a C compiler (`gcc`, `clang`, or MSVC `cl`).
20
+
21
+ ```bash
22
+ pip install pa-compiler # installs `pac`
23
+ pac skill --install claude # optional: install AI skills (also: cursor, codex, copilot, antigravity)
24
+ ```
25
+
26
+ Create `hello.pa`:
27
+
28
+ ```python
29
+ def sum_squares(n) -> int:
30
+ total = 0
31
+ for i in range(n):
32
+ total += i * i
33
+ return total
34
+
35
+ def main() -> int:
36
+ print(sum_squares(100000))
37
+ return 0
38
+ ```
39
+
40
+ Compile and run:
41
+
42
+ ```bash
43
+ pac build hello.pa --mode prod -o hello && ./hello
44
+ ```
45
+
46
+ For `.paw` Python bridges, `--relocatable` bundles, `pac doctor`, and `--shared` C-ABI builds, see the full guide at <https://palang.dev/quickstart>.
47
+
48
+ ---
49
+
50
+ ## Repository Layout
51
+
52
+ ```text
53
+ pa/
54
+ ├── pa_lang/
55
+ │ ├── types.py, validator.py, infer.py # Front-end: subset checks, bidirectional inference, escape analysis
56
+ │ ├── paw.py, diagnostics.py # .paw header parser/linter & AI JSON repair tickets
57
+ │ ├── codegen.py, build.py # LLVM IR emission (llvmlite), -O2 object build, gcc link, @export
58
+ │ ├── runtime_core.c, runtime_bridge.c # RAII fault/print core & embedded CPython zero-copy .paw bridge
59
+ │ ├── cli.py, doctor.py, skills_cmd.py # `pac` CLI: check, build, doctor, bundle, skill
60
+ │ ├── lsp_server.py # Auto-reloading LSP server (inlay hints, hover memory audit cards)
61
+ │ └── skills/ # Bundled SKILL.md assets shipped inside the wheel
62
+ ├── skills/ # Source AI skills (pa-coder, py-to-pa, cpp-to-pa)
63
+ ├── vscode-pa/ # VS Code extension (TextMate grammar, LSP client, grammar tests)
64
+ ├── examples/ # pipeline_demo, hashlib_pa (Python port), raytracer (C++ port)
65
+ ├── site/ # palang.dev static site (index, quickstart, architecture)
66
+ └── tests/ # Pytest suites (front-end, codegen, hardening, LSP, doctor, skill)
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Building from Source & Testing
72
+
73
+ ```bash
74
+ git clone https://github.com/cyyier/pa.git && cd pa
75
+ uv venv --python 3.12 .venv # or any CPython 3.11–3.13 with Python.h + shared libpython
76
+ source .venv/bin/activate
77
+ pip install -e ".[dev]"
78
+
79
+ pac doctor # verify gcc, llvmlite, Python.h, shared libpython
80
+ pac check examples tests # run Pa front-end checks
81
+ pytest -q # run full compiler, runtime, LSP, doctor, and CLI test suite
82
+ (cd vscode-pa && npm test) # run VS Code TextMate grammar tests
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Status & Roadmap
88
+
89
+ **Current (`v0.1.0` alpha):**
90
+ - **Supported:** Linux x86-64, macOS (arm64 / x86-64), Windows x64, CPython 3.11–3.13, `gcc` / `clang` / MSVC `cl`, LLVM via `llvmlite`.
91
+ - **Included:** zero-annotation `.pa` compiler (`int`/`uint`/`float`/`bool`, explicit widths `int32`/`uint8`/`uint32`/`uint64`/`float32` + short aliases `i32`/`u8`/`u32`/`u64`/`f32`, `**`, zero-copy `str_view` slicing, `@struct`, stack/RAII `Vec`, flat CSR `Vec[Vec[T]]`, `String`, `libm`, multi-file `.pa` module imports via local dirs / `-I` / `PA_PATH` / pip packages), `.paw` zero-copy CPython bridge with two-way customs, `--shared` guarded C-ABI libraries, `pac doctor` / `pac bundle` (ELF / Mach-O / PE), `pac skill`, `pac lsp`, and VS Code extension.
92
+
93
+ **Planned:**
94
+ - Standalone ecosystem packages (`pa-libs`) for common data, geometry, and parsing libraries (powered by multi-file `.pa` module imports).
95
+ - *(Low priority)* Nested `Vec` fields inside `@struct` with recursive RAII destructors (Pa recommends flat SoA arrays or CSR `Vec[Vec[T]]`).
96
+
97
+ **Non-goals (won't do):**
98
+ - Static `libpython` linking for single-file self-contained binaries — standard Python distributions do not ship portable `libpython.a` (especially on Windows/macOS), and third-party Python C extensions (`.pyd`/`.so` such as NumPy) require dynamic `libpython`. Use `pac build --bundle --with-stdlib` for self-contained directory distribution.
99
+
100
+ ---
101
+
102
+ ## License
103
+
104
+ MIT — see [LICENSE](https://github.com/cyyier/pa/blob/main/LICENSE). Release process: [RELEASING.md](https://github.com/cyyier/pa/blob/main/RELEASING.md).
@@ -0,0 +1,30 @@
1
+ # Releasing Pa
2
+
3
+ One version number, kept in sync by `tests/test_release.py`:
4
+ `pa_lang/__init__.py` (`__version__`, the wheel reads it) = `vscode-pa/package.json` (`version`) = top entry of `CHANGELOG.md`.
5
+
6
+ ## Checklist
7
+ 1. Update `CHANGELOG.md` (new `## [x.y.z] - date` section) and bump both version strings.
8
+ 2. `pytest -q` and `(cd vscode-pa && npm test)` must be green.
9
+ 3. Build and verify the artifacts:
10
+ ```bash
11
+ pip install -e ".[release]"
12
+ rm -rf dist && python -m build # dist/pa_lang-x.y.z.tar.gz + .whl
13
+ twine check dist/*
14
+ (cd vscode-pa && npm ci && npx @vscode/vsce package -o ../dist/pa-lang-x.y.z.vsix)
15
+ ```
16
+ 4. Dry run on TestPyPI, then a clean-venv smoke test:
17
+ ```bash
18
+ twine upload --repository testpypi dist/*
19
+ python -m venv /tmp/v && /tmp/v/bin/pip install --index-url https://test.pypi.org/simple/ \
20
+ --extra-index-url https://pypi.org/simple/ pa-compiler && /tmp/v/bin/pac doctor
21
+ ```
22
+ 5. Commit, tag and push: `git tag -a vX.Y.Z -m "Pa X.Y.Z" && git push origin main vX.Y.Z`.
23
+ The `release` workflow then builds everything, attaches the wheel/sdist/`.vsix` to a GitHub release and
24
+ publishes to PyPI through trusted publishing (configure the project once on pypi.org: owner `cyyier`, repo `pa`,
25
+ workflow `release.yml`, environment `pypi`).
26
+ 6. VS Code Marketplace / Open VSX (manual, needs a publisher account named `cyyier` and a PAT):
27
+ `npx @vscode/vsce publish` / `npx ovsx publish`.
28
+
29
+ ## Support matrix
30
+ Linux x86-64 (tested), CPython 3.11-3.13 with a shared `libpython` and headers, `gcc`. Run `pac doctor` to verify a machine.
@@ -0,0 +1,235 @@
1
+ import verify
2
+
3
+ # Pure-Pa CRC-32 (IEEE 802.3) and SHA-256 (FIPS 180-4).
4
+
5
+ MASK32 = 4294967295
6
+ TWO32 = 4294967296.0
7
+ CRC32_POLY = 3988292384
8
+
9
+
10
+ def rotr32(x, n) -> int:
11
+ return ((x >> n) | ((x << (32 - n)) & MASK32)) & MASK32
12
+
13
+
14
+ def build_crc32_table():
15
+ table = [0] * 256
16
+ for i in range(256):
17
+ c = i
18
+ for _ in range(8):
19
+ if (c & 1) != 0:
20
+ c = CRC32_POLY ^ (c >> 1)
21
+ else:
22
+ c = c >> 1
23
+ table[i] = c
24
+ return table
25
+
26
+
27
+ def crc32_u8(data, table) -> int:
28
+ crc = MASK32
29
+ n = len(data)
30
+ for i in range(n):
31
+ b = int(data[i])
32
+ idx = (crc ^ b) & 255
33
+ crc = table[idx] ^ (crc >> 8)
34
+ return crc ^ MASK32
35
+
36
+
37
+ def is_prime(n) -> bool:
38
+ if n < 2:
39
+ return False
40
+ d = 2
41
+ while d * d <= n:
42
+ if n % d == 0:
43
+ return False
44
+ d += 1
45
+ return True
46
+
47
+
48
+ def cbrt_frac32(n) -> int:
49
+ # Two Newton steps give full IEEE 754 f64 precision for the 32 fractional bits.
50
+ fn = float(n)
51
+ r = exp(log(fn) / 3.0)
52
+ r = (2.0 * r + fn / (r * r)) / 3.0
53
+ r = (2.0 * r + fn / (r * r)) / 3.0
54
+ return int((r - floor(r)) * TWO32) & MASK32
55
+
56
+
57
+ def build_sha256_k():
58
+ k = [0] * 64
59
+ found = 0
60
+ cand = 2
61
+ while found < 64:
62
+ if is_prime(cand):
63
+ k[found] = cbrt_frac32(cand)
64
+ found += 1
65
+ cand += 1
66
+ return k
67
+
68
+
69
+ def build_sha256_iv():
70
+ iv = [0] * 8
71
+ found = 0
72
+ cand = 2
73
+ while found < 8:
74
+ if is_prime(cand):
75
+ r = sqrt(float(cand))
76
+ iv[found] = int((r - floor(r)) * TWO32) & MASK32
77
+ found += 1
78
+ cand += 1
79
+ return iv
80
+
81
+
82
+ def sha256_pad(data) -> list[u8]:
83
+ n = len(data)
84
+ rem = (n + 9) % 64
85
+ pad_zeros = 0 if rem == 0 else (64 - rem)
86
+ total = n + 1 + pad_zeros + 8
87
+ out = [u8(0)] * total
88
+ for i in range(n):
89
+ out[i] = data[i]
90
+ out[n] = u8(128)
91
+ bit_len = n * 8
92
+ for i in range(8):
93
+ shift = (7 - i) * 8
94
+ out[total - 8 + i] = u8((bit_len >> shift) & 255)
95
+ return out
96
+
97
+
98
+ def sha256_schedule(block, off):
99
+ w = [0] * 64
100
+ for i in range(16):
101
+ j = off + i * 4
102
+ b0 = int(block[j])
103
+ b1 = int(block[j + 1])
104
+ b2 = int(block[j + 2])
105
+ b3 = int(block[j + 3])
106
+ w[i] = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3
107
+ for i in range(16, 64):
108
+ x = w[i - 15]
109
+ s0 = rotr32(x, 7) ^ rotr32(x, 18) ^ (x >> 3)
110
+ y = w[i - 2]
111
+ s1 = rotr32(y, 17) ^ rotr32(y, 19) ^ (y >> 10)
112
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) & MASK32
113
+ return w
114
+
115
+
116
+ def sha256_compress(state, block, off, k) -> void:
117
+ w = sha256_schedule(block, off)
118
+ a = state[0]
119
+ b = state[1]
120
+ c = state[2]
121
+ d = state[3]
122
+ e = state[4]
123
+ f = state[5]
124
+ g = state[6]
125
+ h = state[7]
126
+ for i in range(64):
127
+ s1 = rotr32(e, 6) ^ rotr32(e, 11) ^ rotr32(e, 25)
128
+ ch = (e & f) ^ ((~e & MASK32) & g)
129
+ t1 = (h + s1 + ch + k[i] + w[i]) & MASK32
130
+ s0 = rotr32(a, 2) ^ rotr32(a, 13) ^ rotr32(a, 22)
131
+ maj = (a & b) ^ (a & c) ^ (b & c)
132
+ t2 = (s0 + maj) & MASK32
133
+ h = g
134
+ g = f
135
+ f = e
136
+ e = (d + t1) & MASK32
137
+ d = c
138
+ c = b
139
+ b = a
140
+ a = (t1 + t2) & MASK32
141
+ state[0] = (state[0] + a) & MASK32
142
+ state[1] = (state[1] + b) & MASK32
143
+ state[2] = (state[2] + c) & MASK32
144
+ state[3] = (state[3] + d) & MASK32
145
+ state[4] = (state[4] + e) & MASK32
146
+ state[5] = (state[5] + f) & MASK32
147
+ state[6] = (state[6] + g) & MASK32
148
+ state[7] = (state[7] + h) & MASK32
149
+
150
+
151
+ def sha256_u8(data, k):
152
+ padded = sha256_pad(data)
153
+ state = build_sha256_iv()
154
+ n = len(padded)
155
+ off = 0
156
+ while off < n:
157
+ sha256_compress(
158
+ state=mut(state),
159
+ block=padded,
160
+ off=off,
161
+ k=k,
162
+ )
163
+ off += 64
164
+ return state
165
+
166
+
167
+ def make_payload(n, seed) -> list[u8]:
168
+ buf = [u8(0)] * n
169
+ s = seed
170
+ for i in range(n):
171
+ s = (s * 1103515245 + 12345) & 2147483647
172
+ buf[i] = u8((s >> 16) & 255)
173
+ return buf
174
+
175
+
176
+ def bench_crc32(data, iters) -> int:
177
+ table = build_crc32_table()
178
+ acc = 0
179
+ for _ in range(iters):
180
+ acc ^= crc32_u8(data, table)
181
+ return acc
182
+
183
+
184
+ def bench_sha256(data, iters) -> int:
185
+ k = build_sha256_k()
186
+ acc = 0
187
+ for _ in range(iters):
188
+ d = sha256_u8(data, k)
189
+ acc ^= d[0]
190
+ return acc
191
+
192
+
193
+ def check_case(buf, table, k) -> int:
194
+ crc = crc32_u8(buf, table)
195
+ sha = sha256_u8(buf, k)
196
+ return verify.verify_vector(buf, crc, sha)
197
+
198
+
199
+ def verify_all(table, k) -> int:
200
+ ok = 0
201
+ ok += check_case(buf=make_payload(0, 1), table=table, k=k)
202
+ ok += check_case(buf=make_payload(3, 2), table=table, k=k)
203
+ ok += check_case(buf=make_payload(55, 3), table=table, k=k)
204
+ ok += check_case(buf=make_payload(56, 4), table=table, k=k)
205
+ ok += check_case(buf=make_payload(63, 5), table=table, k=k)
206
+ ok += check_case(buf=make_payload(64, 6), table=table, k=k)
207
+ ok += check_case(buf=make_payload(65, 7), table=table, k=k)
208
+ ok += check_case(buf=make_payload(128, 8), table=table, k=k)
209
+ ok += check_case(buf=make_payload(4096, 9), table=table, k=k)
210
+ return ok
211
+
212
+
213
+ def main() -> int:
214
+ table = build_crc32_table()
215
+ k = build_sha256_k()
216
+ ok = verify_all(table, k)
217
+ print("Verified vectors:", ok, "/ 9")
218
+ if ok != 9:
219
+ return 1
220
+
221
+ payload = make_payload(100000, 42)
222
+ crc_iters = 50
223
+ sha_iters = 20
224
+
225
+ t0 = verify.now_ms()
226
+ c_acc = bench_crc32(payload, crc_iters)
227
+ pa_crc_ms = verify.now_ms() - t0
228
+
229
+ t1 = verify.now_ms()
230
+ s_acc = bench_sha256(payload, sha_iters)
231
+ pa_sha_ms = verify.now_ms() - t1
232
+
233
+ print("Checksums:", c_acc, s_acc)
234
+ verify.bench_python_and_report(payload, crc_iters, sha_iters, pa_crc_ms, pa_sha_ms)
235
+ return 0