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.
- fromscratch_pycpu-0.1.0.dist-info/METADATA +232 -0
- fromscratch_pycpu-0.1.0.dist-info/RECORD +47 -0
- fromscratch_pycpu-0.1.0.dist-info/WHEEL +4 -0
- fromscratch_pycpu-0.1.0.dist-info/entry_points.txt +2 -0
- fromscratch_pycpu-0.1.0.dist-info/licenses/LICENSE +21 -0
- pycpu/__init__.py +11 -0
- pycpu/__main__.py +68 -0
- pycpu/_version.py +24 -0
- pycpu/arithmetic.py +176 -0
- pycpu/assembler.py +580 -0
- pycpu/circuit.py +359 -0
- pycpu/cockpit/__init__.py +8 -0
- pycpu/cockpit/app.py +545 -0
- pycpu/cockpit/code.py +161 -0
- pycpu/cockpit/examples/countdown.pebble +7 -0
- pycpu/cockpit/examples/divide-by-zero.pebble +7 -0
- pycpu/cockpit/examples/factorial.pebble +9 -0
- pycpu/cockpit/examples/greeting.pebble +4 -0
- pycpu/cockpit/examples/times-table.pebble +6 -0
- pycpu/cockpit/examples/tour.pebble +31 -0
- pycpu/cockpit/explain.py +660 -0
- pycpu/cockpit/page.html +1261 -0
- pycpu/cockpit/picture.py +470 -0
- pycpu/cockpit/session.py +778 -0
- pycpu/cockpit/walks/a-call-and-the-stack.toml +47 -0
- pycpu/cockpit/walks/many-instructions.toml +39 -0
- pycpu/cockpit/walks/subtracting-with-gates.toml +39 -0
- pycpu/cockpit/walks/where-n-lives.toml +39 -0
- pycpu/cockpit/walks/why-the-clock-ticks.toml +50 -0
- pycpu/cockpit/walks.py +518 -0
- pycpu/computer.py +175 -0
- pycpu/cpu.py +648 -0
- pycpu/cpu_parts.py +140 -0
- pycpu/fast.py +320 -0
- pycpu/isa.py +243 -0
- pycpu/logic.py +222 -0
- pycpu/memory.py +268 -0
- pycpu/proof.py +263 -0
- pycpu/py.typed +0 -0
- pycpu/simulator.py +361 -0
- pycpu/state.py +146 -0
- pycpu/translator/__init__.py +29 -0
- pycpu/translator/codegen.py +493 -0
- pycpu/translator/program.py +211 -0
- pycpu/translator/runtime.py +166 -0
- pycpu/translator/subset.py +688 -0
- pycpu/view.py +55 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
title = "What a function call does to the stack"
|
|
2
|
+
example = "factorial"
|
|
3
|
+
see_also = "how-a-function-call-really-works"
|
|
4
|
+
|
|
5
|
+
[[steps]]
|
|
6
|
+
say = "This program has a function, fact, that works out 5 times 4 times 3 times 2 times 1 by calling itself."
|
|
7
|
+
do = "start"
|
|
8
|
+
look = "line"
|
|
9
|
+
show = "pebble.line"
|
|
10
|
+
|
|
11
|
+
[[steps]]
|
|
12
|
+
say = "We ran until fact started: line 8 called it with n = 5, and the call put a return address on the stack so the CPU can find its way back."
|
|
13
|
+
do = "run to line 3"
|
|
14
|
+
look = "line"
|
|
15
|
+
show = "stack"
|
|
16
|
+
|
|
17
|
+
[[steps]]
|
|
18
|
+
say = "Running to line 3 again, fact has called itself with n = 4, and the stack has grown with a second frame for it."
|
|
19
|
+
do = "run to line 3"
|
|
20
|
+
look = "line"
|
|
21
|
+
show = "stack"
|
|
22
|
+
|
|
23
|
+
[[steps]]
|
|
24
|
+
say = "We ran on until n reached 1, so the copies of fact for 5, 4, 3 and 2 are all waiting on the stack."
|
|
25
|
+
do = "run to line 4"
|
|
26
|
+
look = "line"
|
|
27
|
+
show = "stack"
|
|
28
|
+
|
|
29
|
+
[[steps]]
|
|
30
|
+
say = "Line 4 returns 1: the CPU took the return address off the stack and went back into the copy of fact that called it."
|
|
31
|
+
do = "step line"
|
|
32
|
+
look = "line"
|
|
33
|
+
show = "stack"
|
|
34
|
+
|
|
35
|
+
[[steps]]
|
|
36
|
+
say = "Each copy of fact finished in turn, the stack shrank back, and the screen shows 120."
|
|
37
|
+
do = "run to line 9"
|
|
38
|
+
look = "line"
|
|
39
|
+
show = "output"
|
|
40
|
+
|
|
41
|
+
[try]
|
|
42
|
+
task = "Press Step into until the copy of fact working on n = 1 is running, and count the copies of fact waiting on the stack."
|
|
43
|
+
look = "line"
|
|
44
|
+
step = "into"
|
|
45
|
+
check = "variable n == 1"
|
|
46
|
+
show = "stack"
|
|
47
|
+
solution = ["step line into", "step line into", "step line into", "step line into", "step line into", "step line into", "step line into", "step line into", "step line into", "step line into", "step line into", "step line into", "step line into"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
title = "A line of Pebble is many tiny instructions"
|
|
2
|
+
example = "countdown"
|
|
3
|
+
see_also = "stepping-a-pebble-line"
|
|
4
|
+
|
|
5
|
+
[[steps]]
|
|
6
|
+
say = "This is the countdown program, and the marked line is the one that runs next."
|
|
7
|
+
do = "start"
|
|
8
|
+
look = "line"
|
|
9
|
+
show = "pebble.line"
|
|
10
|
+
|
|
11
|
+
[[steps]]
|
|
12
|
+
say = "We ran the program to line 5, n = n - 1, which takes 1 away from n."
|
|
13
|
+
do = "run to line 5"
|
|
14
|
+
look = "line"
|
|
15
|
+
show = "pebble.line"
|
|
16
|
+
|
|
17
|
+
[[steps]]
|
|
18
|
+
say = "Look closer: the CPU runs a line as tiny instructions, and this first one only copied n, which is 5, into r1."
|
|
19
|
+
do = "step instruction"
|
|
20
|
+
look = "instruction"
|
|
21
|
+
show = "instruction"
|
|
22
|
+
|
|
23
|
+
[[steps]]
|
|
24
|
+
say = "The next tiny instruction put that 5 on the stack, a pile where the CPU keeps numbers for later."
|
|
25
|
+
do = "step instruction"
|
|
26
|
+
look = "instruction"
|
|
27
|
+
show = "stack"
|
|
28
|
+
|
|
29
|
+
[[steps]]
|
|
30
|
+
say = "Stepping the rest of the line ran 8 more tiny instructions, so n = n - 1 is 10 instructions in all, and n is now 4."
|
|
31
|
+
do = "step line"
|
|
32
|
+
look = "line"
|
|
33
|
+
show = "variables"
|
|
34
|
+
|
|
35
|
+
[try]
|
|
36
|
+
task = "Press Step until n is 0."
|
|
37
|
+
look = "line"
|
|
38
|
+
check = "variable n == 0"
|
|
39
|
+
solution = ["step line", "step line", "step line", "step line", "step line", "step line", "step line", "step line", "step line", "step line", "step line", "step line"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
title = "How the computer subtracts, down to the gates"
|
|
2
|
+
example = "countdown"
|
|
3
|
+
see_also = "the-alu"
|
|
4
|
+
|
|
5
|
+
[[steps]]
|
|
6
|
+
say = "This walk follows line 5 of the countdown, n = n - 1, all the way down to the gates that take 1 away."
|
|
7
|
+
do = "start"
|
|
8
|
+
look = "line"
|
|
9
|
+
show = "pebble.line"
|
|
10
|
+
|
|
11
|
+
[[steps]]
|
|
12
|
+
say = "We ran to line 5, and n is 5, so the computer is about to work out 5 take away 1."
|
|
13
|
+
do = "run to line 5"
|
|
14
|
+
look = "line"
|
|
15
|
+
show = "variables"
|
|
16
|
+
|
|
17
|
+
[[steps]]
|
|
18
|
+
say = "Six tiny instructions got the two numbers ready, so r1 holds 5, r2 holds 1, and the next instruction is a subtract."
|
|
19
|
+
do = "run 6 instructions"
|
|
20
|
+
look = "instruction"
|
|
21
|
+
show = "registers"
|
|
22
|
+
|
|
23
|
+
[[steps]]
|
|
24
|
+
say = "We stepped one gate at a time until a gate inside the ALU, the part of the CPU that does sums, did some work."
|
|
25
|
+
do = "step gate until cpu.alu"
|
|
26
|
+
look = "gate"
|
|
27
|
+
show = "last_gate"
|
|
28
|
+
|
|
29
|
+
[[steps]]
|
|
30
|
+
say = "Finishing the instruction let all the ALU's gates settle on the answer: 5 take away 1 is 4."
|
|
31
|
+
do = "step instruction"
|
|
32
|
+
look = "instruction"
|
|
33
|
+
show = "registers"
|
|
34
|
+
|
|
35
|
+
[try]
|
|
36
|
+
task = "Press Step until n's box holds 4."
|
|
37
|
+
look = "instruction"
|
|
38
|
+
check = "variable n == 4"
|
|
39
|
+
solution = ["step instruction", "step instruction", "step instruction"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
title = "Where does n live? A box in memory"
|
|
2
|
+
example = "countdown"
|
|
3
|
+
see_also = "variables-in-memory"
|
|
4
|
+
|
|
5
|
+
[[steps]]
|
|
6
|
+
say = "The countdown keeps its number in a variable called n, and n is really one box in the computer's memory."
|
|
7
|
+
do = "start"
|
|
8
|
+
look = "line"
|
|
9
|
+
show = "pebble.line"
|
|
10
|
+
|
|
11
|
+
[[steps]]
|
|
12
|
+
say = "Line 2, let n = 5, put 5 into n's box."
|
|
13
|
+
do = "step line"
|
|
14
|
+
look = "line"
|
|
15
|
+
show = "variables"
|
|
16
|
+
|
|
17
|
+
[[steps]]
|
|
18
|
+
say = "We ran on to line 5, which will take 1 away from n."
|
|
19
|
+
do = "run to line 5"
|
|
20
|
+
look = "line"
|
|
21
|
+
show = "pebble.line"
|
|
22
|
+
|
|
23
|
+
[[steps]]
|
|
24
|
+
say = "The CPU can only do sums in its registers, so its first instruction copied 5 out of n's box into r1."
|
|
25
|
+
do = "step instruction"
|
|
26
|
+
look = "instruction"
|
|
27
|
+
show = "memory"
|
|
28
|
+
|
|
29
|
+
[[steps]]
|
|
30
|
+
say = "The rest of line 5 took 1 away and copied the answer, 4, back into n's box."
|
|
31
|
+
do = "step line"
|
|
32
|
+
look = "line"
|
|
33
|
+
show = "variables"
|
|
34
|
+
|
|
35
|
+
[try]
|
|
36
|
+
task = "Press Step until n's box holds 2."
|
|
37
|
+
look = "line"
|
|
38
|
+
check = "variable n == 2"
|
|
39
|
+
solution = ["step line", "step line", "step line", "step line", "step line", "step line"]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
title = "Why the clock ticks"
|
|
2
|
+
example = "countdown"
|
|
3
|
+
see_also = "the-clock"
|
|
4
|
+
|
|
5
|
+
[[steps]]
|
|
6
|
+
say = "This walk watches the clock, the drummer that tells every part of the computer when to move."
|
|
7
|
+
do = "start"
|
|
8
|
+
look = "gate"
|
|
9
|
+
|
|
10
|
+
[[steps]]
|
|
11
|
+
say = "The first gate step did not work a gate at all: it moved the write clock wire up, the moment when the memory may save a number."
|
|
12
|
+
do = "step gate"
|
|
13
|
+
look = "gate"
|
|
14
|
+
show = "happened"
|
|
15
|
+
|
|
16
|
+
[[steps]]
|
|
17
|
+
say = "The next step is a real NAND gate in the memory, which worked because one of its two inputs is the write wire."
|
|
18
|
+
do = "step gate"
|
|
19
|
+
look = "gate"
|
|
20
|
+
show = "last_gate"
|
|
21
|
+
|
|
22
|
+
[[steps]]
|
|
23
|
+
say = "Then the write wire went back down, so the saving moment is over before anything else moves."
|
|
24
|
+
do = "step gate"
|
|
25
|
+
look = "gate"
|
|
26
|
+
show = "happened"
|
|
27
|
+
|
|
28
|
+
[[steps]]
|
|
29
|
+
say = "That same memory gate worked again, because the write wire it listens to moved again."
|
|
30
|
+
do = "step gate"
|
|
31
|
+
look = "gate"
|
|
32
|
+
show = "last_gate"
|
|
33
|
+
|
|
34
|
+
[[steps]]
|
|
35
|
+
say = "Now the main clock wire went up: this is the beat itself, when every register steps to its new number at the same moment."
|
|
36
|
+
do = "step gate"
|
|
37
|
+
look = "gate"
|
|
38
|
+
show = "happened"
|
|
39
|
+
|
|
40
|
+
[[steps]]
|
|
41
|
+
say = "Finishing this beat let the gates the clock woke up settle, and the CPU has read its first instruction, getsp r1."
|
|
42
|
+
do = "step part"
|
|
43
|
+
look = "part"
|
|
44
|
+
show = "instruction"
|
|
45
|
+
|
|
46
|
+
[try]
|
|
47
|
+
task = "Press Step, one beat at a time, until the instruction li r3, 13 has put 13 into r3, and count the beats: every instruction takes two, a fetch beat and an execute beat."
|
|
48
|
+
look = "part"
|
|
49
|
+
check = "register r3 == 13"
|
|
50
|
+
solution = ["step part", "step part", "step part", "step part", "step part", "step part", "step part"]
|