fromscratch-pycpu 0.1.0__py3-none-any.whl

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 (47) hide show
  1. fromscratch_pycpu-0.1.0.dist-info/METADATA +232 -0
  2. fromscratch_pycpu-0.1.0.dist-info/RECORD +47 -0
  3. fromscratch_pycpu-0.1.0.dist-info/WHEEL +4 -0
  4. fromscratch_pycpu-0.1.0.dist-info/entry_points.txt +2 -0
  5. fromscratch_pycpu-0.1.0.dist-info/licenses/LICENSE +21 -0
  6. pycpu/__init__.py +11 -0
  7. pycpu/__main__.py +68 -0
  8. pycpu/_version.py +24 -0
  9. pycpu/arithmetic.py +176 -0
  10. pycpu/assembler.py +580 -0
  11. pycpu/circuit.py +359 -0
  12. pycpu/cockpit/__init__.py +8 -0
  13. pycpu/cockpit/app.py +545 -0
  14. pycpu/cockpit/code.py +161 -0
  15. pycpu/cockpit/examples/countdown.pebble +7 -0
  16. pycpu/cockpit/examples/divide-by-zero.pebble +7 -0
  17. pycpu/cockpit/examples/factorial.pebble +9 -0
  18. pycpu/cockpit/examples/greeting.pebble +4 -0
  19. pycpu/cockpit/examples/times-table.pebble +6 -0
  20. pycpu/cockpit/examples/tour.pebble +31 -0
  21. pycpu/cockpit/explain.py +660 -0
  22. pycpu/cockpit/page.html +1261 -0
  23. pycpu/cockpit/picture.py +470 -0
  24. pycpu/cockpit/session.py +778 -0
  25. pycpu/cockpit/walks/a-call-and-the-stack.toml +47 -0
  26. pycpu/cockpit/walks/many-instructions.toml +39 -0
  27. pycpu/cockpit/walks/subtracting-with-gates.toml +39 -0
  28. pycpu/cockpit/walks/where-n-lives.toml +39 -0
  29. pycpu/cockpit/walks/why-the-clock-ticks.toml +50 -0
  30. pycpu/cockpit/walks.py +518 -0
  31. pycpu/computer.py +175 -0
  32. pycpu/cpu.py +648 -0
  33. pycpu/cpu_parts.py +140 -0
  34. pycpu/fast.py +320 -0
  35. pycpu/isa.py +243 -0
  36. pycpu/logic.py +222 -0
  37. pycpu/memory.py +268 -0
  38. pycpu/proof.py +263 -0
  39. pycpu/py.typed +0 -0
  40. pycpu/simulator.py +361 -0
  41. pycpu/state.py +146 -0
  42. pycpu/translator/__init__.py +29 -0
  43. pycpu/translator/codegen.py +493 -0
  44. pycpu/translator/program.py +211 -0
  45. pycpu/translator/runtime.py +166 -0
  46. pycpu/translator/subset.py +688 -0
  47. pycpu/view.py +55 -0
pycpu/view.py ADDED
@@ -0,0 +1,55 @@
1
+ """The circuit view: a street map you can zoom, drawn from the real circuit.
2
+
3
+ A good map app lets you start with the whole country, tap a town, then tap a
4
+ street, then a single house. Nothing on the map is a drawing made up for show;
5
+ it is the real place, just shown at a different size. `circuit_view` does that
6
+ for a circuit. Ask for `""` and you see the biggest parts. Ask for `"alu"` and
7
+ you see the parts inside it. Keep zooming until you reach individual NAND
8
+ gates, each shown with the values on its wires right now.
9
+
10
+ The view reads the very same wire values the `Simulator` is using. It keeps no
11
+ copy and works nothing out, so it cannot disagree with the circuit it shows.
12
+ """
13
+
14
+ from pycpu.simulator import Simulator
15
+
16
+
17
+ def circuit_view(sim: Simulator, path: str) -> dict[str, object]:
18
+ """Describe one part of a running circuit, at the zoom level of `path`.
19
+
20
+ Args:
21
+ sim: The simulator whose live circuit to look at.
22
+ path: The dotted path of the part, such as `"alu.adder"`. Use `""` for
23
+ the whole circuit.
24
+
25
+ Returns:
26
+ A dictionary with three keys. `path` is the path asked for. `children`
27
+ lists the parts inside it as `{"name", "gate_count"}`, where the count
28
+ includes everything nested deeper. `gates` lists the NAND gates sitting
29
+ directly in it as `{"id", "a", "b", "out", "value_a", "value_b",
30
+ "value_out"}`: the three wires of the gate and the 0 or 1 on each.
31
+
32
+ Raises:
33
+ KeyError: If no part of the circuit has that path.
34
+
35
+ """
36
+ circuit = sim.circuit
37
+ names = circuit.children(path) # raises KeyError for an unknown path
38
+ prefix = f"{path}." if path else ""
39
+ children = [
40
+ {"name": name, "gate_count": circuit.gate_count_in(f"{prefix}{name}")} for name in names
41
+ ]
42
+ first, second, out = circuit.gate_wires
43
+ gates = [
44
+ {
45
+ "id": gate,
46
+ "a": first[gate],
47
+ "b": second[gate],
48
+ "out": out[gate],
49
+ "value_a": sim.get(first[gate]),
50
+ "value_b": sim.get(second[gate]),
51
+ "value_out": sim.get(out[gate]),
52
+ }
53
+ for gate in circuit.gates_in(path)
54
+ ]
55
+ return {"path": path, "children": children, "gates": gates}