fromscratch-pycpu 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.
- fromscratch_pycpu-0.1.0/.github/workflows/ci.yml +14 -0
- fromscratch_pycpu-0.1.0/.github/workflows/docs.yml +16 -0
- fromscratch_pycpu-0.1.0/.github/workflows/release.yml +58 -0
- fromscratch_pycpu-0.1.0/.gitignore +14 -0
- fromscratch_pycpu-0.1.0/.pre-commit-config.yaml +56 -0
- fromscratch_pycpu-0.1.0/CLAUDE.md +58 -0
- fromscratch_pycpu-0.1.0/CONTRIBUTING.md +212 -0
- fromscratch_pycpu-0.1.0/LICENSE +21 -0
- fromscratch_pycpu-0.1.0/PKG-INFO +232 -0
- fromscratch_pycpu-0.1.0/README.md +195 -0
- fromscratch_pycpu-0.1.0/conftest.py +21 -0
- fromscratch_pycpu-0.1.0/docs/build-it-yourself.md +136 -0
- fromscratch_pycpu-0.1.0/docs/concepts/a-tour-of-the-cockpit.md +244 -0
- fromscratch_pycpu-0.1.0/docs/concepts/adding.md +249 -0
- fromscratch_pycpu-0.1.0/docs/concepts/assembly-language.md +192 -0
- fromscratch_pycpu-0.1.0/docs/concepts/bits-and-binary.md +118 -0
- fromscratch_pycpu-0.1.0/docs/concepts/calling-and-returning.md +179 -0
- fromscratch_pycpu-0.1.0/docs/concepts/choosing-and-decoding.md +158 -0
- fromscratch_pycpu-0.1.0/docs/concepts/fetch-decode-execute.md +299 -0
- fromscratch_pycpu-0.1.0/docs/concepts/from-pebble-to-machine-code.md +269 -0
- fromscratch_pycpu-0.1.0/docs/concepts/gates.md +195 -0
- fromscratch_pycpu-0.1.0/docs/concepts/guided-walks.md +223 -0
- fromscratch_pycpu-0.1.0/docs/concepts/how-a-function-call-really-works.md +310 -0
- fromscratch_pycpu-0.1.0/docs/concepts/how-big-is-our-memory.md +193 -0
- fromscratch_pycpu-0.1.0/docs/concepts/if-and-while-as-jumps.md +375 -0
- fromscratch_pycpu-0.1.0/docs/concepts/looking-inside.md +163 -0
- fromscratch_pycpu-0.1.0/docs/concepts/machine-code.md +189 -0
- fromscratch_pycpu-0.1.0/docs/concepts/multiply-and-divide.md +208 -0
- fromscratch_pycpu-0.1.0/docs/concepts/negative-numbers.md +171 -0
- fromscratch_pycpu-0.1.0/docs/concepts/pausing-and-rewinding.md +207 -0
- fromscratch_pycpu-0.1.0/docs/concepts/printing-a-number.md +156 -0
- fromscratch_pycpu-0.1.0/docs/concepts/ram.md +214 -0
- fromscratch_pycpu-0.1.0/docs/concepts/registers.md +138 -0
- fromscratch_pycpu-0.1.0/docs/concepts/remembering.md +182 -0
- fromscratch_pycpu-0.1.0/docs/concepts/simulating-a-circuit.md +216 -0
- fromscratch_pycpu-0.1.0/docs/concepts/stepping-a-pebble-line.md +296 -0
- fromscratch_pycpu-0.1.0/docs/concepts/switches-and-nand.md +121 -0
- fromscratch_pycpu-0.1.0/docs/concepts/the-alu.md +220 -0
- fromscratch_pycpu-0.1.0/docs/concepts/the-clock.md +175 -0
- fromscratch_pycpu-0.1.0/docs/concepts/the-cockpit.md +1046 -0
- fromscratch_pycpu-0.1.0/docs/concepts/the-code-behind-a-part.md +133 -0
- fromscratch_pycpu-0.1.0/docs/concepts/the-control-unit.md +178 -0
- fromscratch_pycpu-0.1.0/docs/concepts/the-magnifying-glass.md +295 -0
- fromscratch_pycpu-0.1.0/docs/concepts/the-stack.md +216 -0
- fromscratch_pycpu-0.1.0/docs/concepts/two-engines.md +209 -0
- fromscratch_pycpu-0.1.0/docs/concepts/variables-in-memory.md +237 -0
- fromscratch_pycpu-0.1.0/docs/concepts/watching-it-run.md +200 -0
- fromscratch_pycpu-0.1.0/docs/concepts/what-happens-when-things-go-wrong.md +217 -0
- fromscratch_pycpu-0.1.0/docs/concepts/what-is-a-cpu.md +149 -0
- fromscratch_pycpu-0.1.0/docs/concepts/what-just-happened.md +257 -0
- fromscratch_pycpu-0.1.0/docs/concepts/why-16-bit-numbers-wrap.md +143 -0
- fromscratch_pycpu-0.1.0/docs/from-scratch.md +132 -0
- fromscratch_pycpu-0.1.0/docs/index.md +169 -0
- fromscratch_pycpu-0.1.0/docs/reference/instruction-set.md +128 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/plans/2026-11-01-pycpu-01-gates-to-memory.md +553 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/plans/2026-11-01-pycpu-roadmap.md +416 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/plans/2026-11-02-pycpu-02-cpu-and-assembler.md +391 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/plans/2026-11-03-pycpu-03-pebble-on-the-cpu.md +346 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/plans/2026-11-03-pycpu-04-the-cockpit.md +425 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/plans/2026-11-04-pycpu-05-cockpit-for-learners.md +432 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/plans/2026-11-07-pycpu-06-build-and-watch.md +210 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/plans/2026-11-12-pycpu-07-integration-and-release.md +107 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/specs/2026-11-01-pycpu-design.md +188 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/specs/2026-11-04-pycpu-cockpit-for-learners-design.md +148 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/specs/2026-11-07-pycpu-build-and-watch-design.md +63 -0
- fromscratch_pycpu-0.1.0/docs/superpowers/specs/2026-11-12-pycpu-integration-and-release-design.md +95 -0
- fromscratch_pycpu-0.1.0/docs/you-built-a-computer.md +116 -0
- fromscratch_pycpu-0.1.0/examples/add_two_numbers.py +32 -0
- fromscratch_pycpu-0.1.0/examples/alu_tour.py +42 -0
- fromscratch_pycpu-0.1.0/examples/cockpit_tour.py +91 -0
- fromscratch_pycpu-0.1.0/examples/counter.py +39 -0
- fromscratch_pycpu-0.1.0/examples/run_assembly.py +46 -0
- fromscratch_pycpu-0.1.0/examples/run_pebble.py +36 -0
- fromscratch_pycpu-0.1.0/mkdocs.yml +91 -0
- fromscratch_pycpu-0.1.0/pyproject.toml +176 -0
- fromscratch_pycpu-0.1.0/scripts/measure_engines.py +35 -0
- fromscratch_pycpu-0.1.0/scripts/prove_ram.py +41 -0
- fromscratch_pycpu-0.1.0/scripts/ram_tails.py +119 -0
- fromscratch_pycpu-0.1.0/src/pycpu/__init__.py +11 -0
- fromscratch_pycpu-0.1.0/src/pycpu/__main__.py +68 -0
- fromscratch_pycpu-0.1.0/src/pycpu/_version.py +24 -0
- fromscratch_pycpu-0.1.0/src/pycpu/arithmetic.py +176 -0
- fromscratch_pycpu-0.1.0/src/pycpu/assembler.py +580 -0
- fromscratch_pycpu-0.1.0/src/pycpu/circuit.py +359 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/__init__.py +8 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/app.py +545 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/code.py +161 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/examples/countdown.pebble +7 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/examples/divide-by-zero.pebble +7 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/examples/factorial.pebble +9 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/examples/greeting.pebble +4 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/examples/times-table.pebble +6 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/examples/tour.pebble +31 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/explain.py +660 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/page.html +1261 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/picture.py +470 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/session.py +778 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/walks/a-call-and-the-stack.toml +47 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/walks/many-instructions.toml +39 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/walks/subtracting-with-gates.toml +39 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/walks/where-n-lives.toml +39 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/walks/why-the-clock-ticks.toml +50 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cockpit/walks.py +518 -0
- fromscratch_pycpu-0.1.0/src/pycpu/computer.py +175 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cpu.py +648 -0
- fromscratch_pycpu-0.1.0/src/pycpu/cpu_parts.py +140 -0
- fromscratch_pycpu-0.1.0/src/pycpu/fast.py +320 -0
- fromscratch_pycpu-0.1.0/src/pycpu/isa.py +243 -0
- fromscratch_pycpu-0.1.0/src/pycpu/logic.py +222 -0
- fromscratch_pycpu-0.1.0/src/pycpu/memory.py +268 -0
- fromscratch_pycpu-0.1.0/src/pycpu/proof.py +263 -0
- fromscratch_pycpu-0.1.0/src/pycpu/py.typed +0 -0
- fromscratch_pycpu-0.1.0/src/pycpu/simulator.py +361 -0
- fromscratch_pycpu-0.1.0/src/pycpu/state.py +146 -0
- fromscratch_pycpu-0.1.0/src/pycpu/translator/__init__.py +29 -0
- fromscratch_pycpu-0.1.0/src/pycpu/translator/codegen.py +493 -0
- fromscratch_pycpu-0.1.0/src/pycpu/translator/program.py +211 -0
- fromscratch_pycpu-0.1.0/src/pycpu/translator/runtime.py +166 -0
- fromscratch_pycpu-0.1.0/src/pycpu/translator/subset.py +688 -0
- fromscratch_pycpu-0.1.0/src/pycpu/view.py +55 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/arithmetic.pebble +16 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/comparisons.pebble +23 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/conditional_return.pebble +13 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/countdown.pebble +7 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/divide_by_zero.pebble +6 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/edges.pebble +10 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/factorial.pebble +10 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/fibonacci.pebble +10 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/gcd.pebble +18 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/grades.pebble +19 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/logic.pebble +25 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/modulo_by_zero_in_function.pebble +9 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/nested_loops.pebble +10 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/parameters.pebble +10 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/primes.pebble +23 -0
- fromscratch_pycpu-0.1.0/tests/pebble_programs/statements.pebble +17 -0
- fromscratch_pycpu-0.1.0/tests/test_arithmetic.py +253 -0
- fromscratch_pycpu-0.1.0/tests/test_assembler.py +351 -0
- fromscratch_pycpu-0.1.0/tests/test_cockpit.py +2320 -0
- fromscratch_pycpu-0.1.0/tests/test_cockpit_session.py +160 -0
- fromscratch_pycpu-0.1.0/tests/test_code_view.py +236 -0
- fromscratch_pycpu-0.1.0/tests/test_combined_stack.py +98 -0
- fromscratch_pycpu-0.1.0/tests/test_computer.py +344 -0
- fromscratch_pycpu-0.1.0/tests/test_conformance.py +1000 -0
- fromscratch_pycpu-0.1.0/tests/test_cpu.py +513 -0
- fromscratch_pycpu-0.1.0/tests/test_cpu_parts.py +203 -0
- fromscratch_pycpu-0.1.0/tests/test_dependency_pins.py +38 -0
- fromscratch_pycpu-0.1.0/tests/test_depths.py +252 -0
- fromscratch_pycpu-0.1.0/tests/test_docs.py +531 -0
- fromscratch_pycpu-0.1.0/tests/test_docstrings.py +44 -0
- fromscratch_pycpu-0.1.0/tests/test_engine_speed.py +130 -0
- fromscratch_pycpu-0.1.0/tests/test_examples.py +33 -0
- fromscratch_pycpu-0.1.0/tests/test_examples_programs.py +140 -0
- fromscratch_pycpu-0.1.0/tests/test_explain.py +697 -0
- fromscratch_pycpu-0.1.0/tests/test_fast.py +463 -0
- fromscratch_pycpu-0.1.0/tests/test_frames.py +180 -0
- fromscratch_pycpu-0.1.0/tests/test_functions.py +535 -0
- fromscratch_pycpu-0.1.0/tests/test_isa.py +193 -0
- fromscratch_pycpu-0.1.0/tests/test_line_steps.py +463 -0
- fromscratch_pycpu-0.1.0/tests/test_live.py +549 -0
- fromscratch_pycpu-0.1.0/tests/test_lockstep.py +167 -0
- fromscratch_pycpu-0.1.0/tests/test_logic.py +224 -0
- fromscratch_pycpu-0.1.0/tests/test_memory.py +224 -0
- fromscratch_pycpu-0.1.0/tests/test_parts_view.py +322 -0
- fromscratch_pycpu-0.1.0/tests/test_pebble_faults.py +243 -0
- fromscratch_pycpu-0.1.0/tests/test_ram.py +286 -0
- fromscratch_pycpu-0.1.0/tests/test_ram_proof.py +162 -0
- fromscratch_pycpu-0.1.0/tests/test_runtime.py +260 -0
- fromscratch_pycpu-0.1.0/tests/test_simulator.py +358 -0
- fromscratch_pycpu-0.1.0/tests/test_smoke.py +9 -0
- fromscratch_pycpu-0.1.0/tests/test_translator.py +683 -0
- fromscratch_pycpu-0.1.0/tests/test_view.py +219 -0
- fromscratch_pycpu-0.1.0/tests/test_walks.py +1003 -0
- fromscratch_pycpu-0.1.0/uv.lock +1425 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Deploy Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
workflow_dispatch: {}
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
docs:
|
|
10
|
+
uses: robcox2910/robcox2910.github.io/.github/workflows/docs.yml@v1
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
pages: write
|
|
14
|
+
id-token: write
|
|
15
|
+
with:
|
|
16
|
+
coverage-report: false
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*.*.*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v7
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
|
|
20
|
+
- name: Install uv
|
|
21
|
+
uses: astral-sh/setup-uv@v7
|
|
22
|
+
with:
|
|
23
|
+
version: "latest"
|
|
24
|
+
|
|
25
|
+
- name: Set up Python
|
|
26
|
+
run: uv python install 3.14
|
|
27
|
+
|
|
28
|
+
- name: Build distributions
|
|
29
|
+
run: uv build
|
|
30
|
+
|
|
31
|
+
- name: Upload build artifacts
|
|
32
|
+
uses: actions/upload-artifact@v7
|
|
33
|
+
with:
|
|
34
|
+
name: dist
|
|
35
|
+
path: dist/
|
|
36
|
+
|
|
37
|
+
- name: Upload to GitHub Release
|
|
38
|
+
uses: softprops/action-gh-release@v3
|
|
39
|
+
with:
|
|
40
|
+
files: dist/*
|
|
41
|
+
|
|
42
|
+
publish:
|
|
43
|
+
needs: build
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
environment:
|
|
46
|
+
name: pypi
|
|
47
|
+
url: https://pypi.org/project/fromscratch-pycpu/
|
|
48
|
+
permissions:
|
|
49
|
+
id-token: write
|
|
50
|
+
steps:
|
|
51
|
+
- name: Download build artifacts
|
|
52
|
+
uses: actions/download-artifact@v8
|
|
53
|
+
with:
|
|
54
|
+
name: dist
|
|
55
|
+
path: dist/
|
|
56
|
+
|
|
57
|
+
- name: Publish to PyPI
|
|
58
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
default_language_version:
|
|
2
|
+
python: python3.14
|
|
3
|
+
|
|
4
|
+
repos:
|
|
5
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
6
|
+
rev: v5.0.0
|
|
7
|
+
hooks:
|
|
8
|
+
# Pages paste real pytest output, trailing spaces included.
|
|
9
|
+
- id: trailing-whitespace
|
|
10
|
+
exclude: ^docs/property-testing\.md$
|
|
11
|
+
- id: end-of-file-fixer
|
|
12
|
+
exclude: ^docs/property-testing\.md$
|
|
13
|
+
- id: check-yaml
|
|
14
|
+
args: ['--unsafe']
|
|
15
|
+
- id: check-added-large-files
|
|
16
|
+
- id: check-json
|
|
17
|
+
- id: check-toml
|
|
18
|
+
- id: check-merge-conflict
|
|
19
|
+
- id: debug-statements
|
|
20
|
+
|
|
21
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
22
|
+
rev: v0.15.4
|
|
23
|
+
hooks:
|
|
24
|
+
- id: ruff
|
|
25
|
+
args: [--fix, --exit-non-zero-on-fix]
|
|
26
|
+
- id: ruff-format
|
|
27
|
+
|
|
28
|
+
- repo: https://github.com/RobertCraigie/pyright-python
|
|
29
|
+
rev: v1.1.408
|
|
30
|
+
hooks:
|
|
31
|
+
- id: pyright
|
|
32
|
+
|
|
33
|
+
- repo: local
|
|
34
|
+
hooks:
|
|
35
|
+
- id: pip-audit
|
|
36
|
+
name: pip-audit
|
|
37
|
+
language: system
|
|
38
|
+
pass_filenames: false
|
|
39
|
+
files: ^(pyproject\.toml|uv\.lock)$
|
|
40
|
+
entry: >-
|
|
41
|
+
bash -c 'f=$(mktemp) &&
|
|
42
|
+
uv export --frozen --no-emit-project --all-extras --no-hashes -o "$f" >/dev/null &&
|
|
43
|
+
uvx pip-audit==2.10.0 -r "$f" --disable-pip --no-deps;
|
|
44
|
+
status=$?; rm -f "$f"; exit $status'
|
|
45
|
+
|
|
46
|
+
- repo: https://github.com/rhysd/actionlint
|
|
47
|
+
rev: v1.7.7
|
|
48
|
+
hooks:
|
|
49
|
+
- id: actionlint
|
|
50
|
+
|
|
51
|
+
- repo: https://github.com/commitizen-tools/commitizen
|
|
52
|
+
rev: v4.13.8
|
|
53
|
+
hooks:
|
|
54
|
+
- id: commitizen
|
|
55
|
+
stages: [commit-msg]
|
|
56
|
+
additional_dependencies: [typing_extensions]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Claude Code Instructions
|
|
2
|
+
|
|
3
|
+
<!-- standard:start -->
|
|
4
|
+
## Code Style
|
|
5
|
+
|
|
6
|
+
- All public functions, methods, classes, and modules **must** have a docstring
|
|
7
|
+
- Use imperative mood: "Return the result." not "Returns the result."
|
|
8
|
+
- One-line docstrings for simple functions; multi-line with summary + details for complex ones
|
|
9
|
+
- Follow the Google docstring convention (D211, D212 selected via ruff)
|
|
10
|
+
|
|
11
|
+
## Linting
|
|
12
|
+
|
|
13
|
+
- Ruff enforces a comprehensive rule set -- run `uv run ruff check .` before committing
|
|
14
|
+
- Pyright runs in strict mode -- run `uv run pyright src tests` before committing
|
|
15
|
+
- All violations must be fixed, not ignored. Exceptions are the repo-owned `ignore` and `per-file-ignores` lists in `pyproject.toml`, which belong to this repo; the series sync never edits them
|
|
16
|
+
|
|
17
|
+
## Testing
|
|
18
|
+
|
|
19
|
+
- TDD workflow: Red-Green-Refactor
|
|
20
|
+
- Coverage is enforced by pytest-cov; the floor in `pyproject.toml` is repo-owned
|
|
21
|
+
- Test classes and methods also require docstrings
|
|
22
|
+
- Use named constants instead of magic values (PLR2004)
|
|
23
|
+
- Run `uv run pytest` before committing
|
|
24
|
+
- Property-based tests (Hypothesis) live in `tests/test_properties.py` and `tests/test_model.py`; the shared profiles are in the root `conftest.py` (owned by `series sync`). Run `uv run pytest --hypothesis-profile=thorough` before a release.
|
|
25
|
+
|
|
26
|
+
## Commits
|
|
27
|
+
|
|
28
|
+
- Use conventional commits: `feat:`, `fix:`, `refactor:`, `test:`, `docs:`, `ci:`, `chore:`
|
|
29
|
+
- All changes go via PR from a feature branch (main is protected); merge when CI is green
|
|
30
|
+
|
|
31
|
+
## Dependencies
|
|
32
|
+
|
|
33
|
+
- Package manager: uv
|
|
34
|
+
- Run `uv sync --all-extras` after modifying dependencies
|
|
35
|
+
- `uv.lock` is committed; CI and pre-commit audit it with pip-audit through `uvx`, so pip-audit is not a project dependency
|
|
36
|
+
- Sibling projects, where used, are their PyPI releases (`fromscratch-<name>>=X.Y.Z`); never use `path` or git sources
|
|
37
|
+
|
|
38
|
+
## Releasing
|
|
39
|
+
|
|
40
|
+
- A release is a `vX.Y.Z` tag on main after the PR is merged
|
|
41
|
+
- Docs-only and tooling-only changes do not get a release tag
|
|
42
|
+
- Docs are built with `mkdocs build --strict` and deployed to GitHub Pages by the docs workflow
|
|
43
|
+
<!-- standard:end -->
|
|
44
|
+
|
|
45
|
+
## Project notes
|
|
46
|
+
|
|
47
|
+
PyCPU is an educational computer simulated from NAND gates. Teaching comes first.
|
|
48
|
+
|
|
49
|
+
- **NAND is the single primitive.** Nothing above `simulator.py` may compute a logic result in Python, except test helpers and `peek`/`poke`.
|
|
50
|
+
- **Never fake the gate view.** What the glass shows must be the real circuit computing the real value.
|
|
51
|
+
- **RAM is 4K words of 16 bits, every bit real gates.** If that proves unworkable, shrink the RAM; never add a behavioural store.
|
|
52
|
+
- 16-bit words. Buses are tuples of wires, least significant bit first.
|
|
53
|
+
- Never use `TYPE_CHECKING` or `from __future__ import annotations`.
|
|
54
|
+
- Documentation ranks above every other rule. Write each concept page before its code, for a curious 12-year-old: everyday analogy first, a table, a runnable `## Try It`, `## How It Works`, `## Why Does This Matter?`, `## What's Next`. Numbers in docs are measured, never invented.
|
|
55
|
+
- Every public module, class and function has a docstring; module docstrings open with an analogy and run at least 3 lines.
|
|
56
|
+
- Add each new page to `mkdocs.yml` and to `KEY_IDEAS` in `tests/test_docs.py`.
|
|
57
|
+
- Coverage floor is 90%. Slow tests carry `@pytest.mark.slow` and are skipped by default.
|
|
58
|
+
- PyCPU's Hypothesis tests are named by subject (`test_lockstep.py` and the like) rather than `test_properties.py`.
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Contributing to PyCPU
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing! This guide covers everything you need
|
|
4
|
+
to get started.
|
|
5
|
+
|
|
6
|
+
## Prerequisites
|
|
7
|
+
|
|
8
|
+
| Tool | Version | Install |
|
|
9
|
+
|------|---------|---------|
|
|
10
|
+
| Python | 3.14+ | [python.org](https://www.python.org/downloads/) |
|
|
11
|
+
| uv | latest | `curl -LsSf https://astral.sh/uv/install.sh \| sh` |
|
|
12
|
+
| git | 2.x+ | [git-scm.com](https://git-scm.com/) |
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Clone the repo
|
|
18
|
+
git clone https://github.com/robcox2910/pycpu.git
|
|
19
|
+
cd pycpu
|
|
20
|
+
|
|
21
|
+
# Install all dependencies (including dev and docs tools)
|
|
22
|
+
uv sync --all-extras
|
|
23
|
+
|
|
24
|
+
# Install pre-commit hooks (linting + commit message validation)
|
|
25
|
+
uv run pre-commit install
|
|
26
|
+
uv run pre-commit install --hook-type commit-msg
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Verify everything works:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uv run pytest # tests pass, >= 90% coverage
|
|
33
|
+
uv run ruff check . # no lint errors
|
|
34
|
+
uv run pyright src tests # no type errors
|
|
35
|
+
uv run mkdocs build --strict # the docs build cleanly
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## The Rules That Make PyCPU PyCPU
|
|
39
|
+
|
|
40
|
+
These matter more than any style rule below:
|
|
41
|
+
|
|
42
|
+
- **NAND is the only building block.** Nothing above `simulator.py` may work out
|
|
43
|
+
a logic result in plain Python, except test helpers and `peek`/`poke`.
|
|
44
|
+
- **Never fake the gate view.** What the zoom shows must be the real circuit
|
|
45
|
+
computing the real value.
|
|
46
|
+
- **RAM is real gates.** Never add a shortcut store that skips them.
|
|
47
|
+
- **Docs come first.** Write a concept page before its code (see below).
|
|
48
|
+
|
|
49
|
+
## TDD Workflow
|
|
50
|
+
|
|
51
|
+
We follow **Red-Green-Refactor** for every code change:
|
|
52
|
+
|
|
53
|
+
1. **Red** -- Write a failing test that describes the behaviour you want.
|
|
54
|
+
2. **Green** -- Write the simplest code that makes the test pass.
|
|
55
|
+
3. **Refactor** -- Clean up while keeping all tests green.
|
|
56
|
+
|
|
57
|
+
Never skip the red step. A new concept page's `## Try It` counts as a failing
|
|
58
|
+
test: `tests/test_docs.py` runs it, so it fails until the code exists.
|
|
59
|
+
|
|
60
|
+
## Branch Naming
|
|
61
|
+
|
|
62
|
+
Create a branch from `main` using one of these prefixes:
|
|
63
|
+
|
|
64
|
+
| Prefix | When to use |
|
|
65
|
+
|--------|-------------|
|
|
66
|
+
| `feat/` | New feature or circuit |
|
|
67
|
+
| `fix/` | Bug fix |
|
|
68
|
+
| `refactor/` | Restructuring without behaviour change |
|
|
69
|
+
| `test/` | Test-only changes |
|
|
70
|
+
| `docs/` | Documentation updates |
|
|
71
|
+
| `ci/` | CI/CD workflow changes |
|
|
72
|
+
| `chore/` | Dependency bumps, config tweaks |
|
|
73
|
+
|
|
74
|
+
Example: `feat/program-counter`, `fix/ram-write-hazard`
|
|
75
|
+
|
|
76
|
+
## Conventional Commits
|
|
77
|
+
|
|
78
|
+
Every commit message must follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
<type>: <short description in imperative mood>
|
|
82
|
+
|
|
83
|
+
Optional longer explanation.
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Types match the branch prefixes: `feat:`, `fix:`, `refactor:`, `test:`,
|
|
87
|
+
`docs:`, `ci:`, `chore:`.
|
|
88
|
+
|
|
89
|
+
Good examples:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
feat: add a 16-bit register
|
|
93
|
+
fix: settle before the write pulse
|
|
94
|
+
docs: add the clock concept page
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Bad examples:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
updated stuff # no type, vague description
|
|
101
|
+
feat: adds register # not imperative mood ("adds" -> "add")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Code Style
|
|
105
|
+
|
|
106
|
+
### Modern Python
|
|
107
|
+
|
|
108
|
+
Use Python 3.14 idioms everywhere:
|
|
109
|
+
|
|
110
|
+
- `X | Y` for union types (not `Union[X, Y]` or `Optional[X]`)
|
|
111
|
+
- `match/case` instead of if/elif chains where appropriate
|
|
112
|
+
- Never use `TYPE_CHECKING` or `from __future__ import annotations`
|
|
113
|
+
|
|
114
|
+
### Wires and Buses
|
|
115
|
+
|
|
116
|
+
- Words are 16 bits.
|
|
117
|
+
- A bus is a tuple of wires, **least significant bit first**.
|
|
118
|
+
|
|
119
|
+
### Docstrings
|
|
120
|
+
|
|
121
|
+
Every public function, method, class, and module needs a docstring:
|
|
122
|
+
|
|
123
|
+
- Use **imperative mood**: "Return the sum." not "Returns the sum."
|
|
124
|
+
- One-liner for simple functions, multi-line (Google style) for complex ones.
|
|
125
|
+
- Module docstrings open with an everyday analogy and run at least 3 lines.
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
def half_adder(c: Circuit, a: int, b: int) -> tuple[int, int]:
|
|
129
|
+
"""Add two bits and return the sum bit and the carry bit."""
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Named Constants
|
|
133
|
+
|
|
134
|
+
Use named constants instead of magic numbers in tests and source code. Ruff
|
|
135
|
+
rule PLR2004 enforces this.
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
# Good
|
|
139
|
+
GATES_IN_A_HALF_ADDER = 6
|
|
140
|
+
assert c.gate_count == GATES_IN_A_HALF_ADDER
|
|
141
|
+
|
|
142
|
+
# Bad
|
|
143
|
+
assert c.gate_count == 6
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Linting and Type Checking
|
|
147
|
+
|
|
148
|
+
Run these before every commit (pre-commit hooks enforce them automatically):
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
uv run ruff check . # lint
|
|
152
|
+
uv run ruff format . # format (or --check to verify)
|
|
153
|
+
uv run pyright src tests # type check (strict mode)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Fix all violations. Inline `# noqa:` is acceptable only when tools genuinely
|
|
157
|
+
conflict.
|
|
158
|
+
|
|
159
|
+
## Testing
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
uv run pytest # run the tests (slow ones are skipped)
|
|
163
|
+
uv run pytest -m slow # run the slow tests, such as the 4K RAM proof
|
|
164
|
+
uv run pytest tests/test_ram.py # run a specific file
|
|
165
|
+
uv run pytest -k "half_adder" # run tests matching a pattern
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
- Minimum **90% coverage** is enforced.
|
|
169
|
+
- Test classes and methods need docstrings too.
|
|
170
|
+
- Long-running tests carry `@pytest.mark.slow`.
|
|
171
|
+
- Every program in `examples/` is run by `tests/test_examples.py`.
|
|
172
|
+
|
|
173
|
+
## Documentation Style
|
|
174
|
+
|
|
175
|
+
Our docs target a **curious 12-year-old who has never heard of a logic gate**.
|
|
176
|
+
Documentation ranks above every other rule: a change with good code and weak
|
|
177
|
+
docs is not finished.
|
|
178
|
+
|
|
179
|
+
Each concept page in `docs/concepts/` has:
|
|
180
|
+
|
|
181
|
+
- an everyday analogy first, and a table;
|
|
182
|
+
- `## Try It`, a runnable example with its exact output after `# Output:`;
|
|
183
|
+
- `## How It Works`, showing how the thing is built from the layer below;
|
|
184
|
+
- `## Why Does This Matter?` and `## What's Next`, which links the next page.
|
|
185
|
+
|
|
186
|
+
Numbers in the docs are measured, never invented. Add each new page to
|
|
187
|
+
`mkdocs.yml` and to `KEY_IDEAS` in `tests/test_docs.py`.
|
|
188
|
+
|
|
189
|
+
Good:
|
|
190
|
+
|
|
191
|
+
> A register is like a row of light switches with a "save" button: you can
|
|
192
|
+
> set the switches however you like, but the row only remembers them when the
|
|
193
|
+
> clock says "now".
|
|
194
|
+
|
|
195
|
+
Bad:
|
|
196
|
+
|
|
197
|
+
> A register is an array of edge-triggered D flip-flops sharing a common
|
|
198
|
+
> enable and clock net.
|
|
199
|
+
|
|
200
|
+
## Pull Request Process
|
|
201
|
+
|
|
202
|
+
1. Create a feature branch from `main`.
|
|
203
|
+
2. Make your changes following TDD, docs first.
|
|
204
|
+
3. Ensure all checks pass: `uv run ruff check .`, `uv run pyright src tests`,
|
|
205
|
+
`uv run pytest`, `uv run mkdocs build --strict`.
|
|
206
|
+
4. Push your branch and open a PR against `main`.
|
|
207
|
+
5. PRs are squash-merged to keep history clean.
|
|
208
|
+
|
|
209
|
+
## Questions?
|
|
210
|
+
|
|
211
|
+
Open an issue on [GitHub](https://github.com/robcox2910/pycpu/issues) --
|
|
212
|
+
we're happy to help!
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rob Cox
|
|
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.
|