Последняя активность 3 weeks ago

A VM with a tape of stacks.

stacky-tape.nv Исходник Playground
1|:: push to $x :value: $y| :stacks: $x $y
2|:: push $x to $y| :stacks: $y $x
3
4|:: pop from $x :stacks: $x $y|
5 :value: $y
6 :: reset stacks
7|:: pop from $x? :stacks: $z $y|
8 :seen: $z $y
9|:: pop from $x :default symbol: $y?|
10 :value: $y
11 :: reset stacks
12|:: pop from $x|
13 :: stop execution :error: pop from an empty or nonexistent stack $x
14
15|:: reset stacks? :seen: $x $y|
16 :stacks: $x $y
17|:: reset stacks|
18
19|:: move $direction :@math: $x|
20 :stack: $x
21|:: move left :stack: 1 :number of stacks: $x?|
22 :stack: $x
23|:: move left? :stack: $x|
24 :@math: subtract $x 1
25|:: move right :stack: $x :number of stacks: $x?|
26 :stack: 1
27|:: move right? :stack: $x|
28 :@math: add $x 1
29|:: move $direction?|
30 :stack: 1
31
32|:: compare and branch :value: ($x $x)|
33|:: compare and branch :value: ($x $y)|
34 :: seek forward :depth:
35
36|:: seek forward? :code: [|
37 :executed: [
38 :depth:
39|:: seek forward? :code: ] :depth: :depth:|
40 :executed: ]
41|:: seek forward :code: ] :depth:|
42 :executed: ]
43|:: seek forward? :code: $x|
44 :executed: $x
45|:: seek forward|
46
47|:: seek backward? :executed: ]|
48 :code: ]
49 :depth:
50|:: seek backward? :executed: [ :depth: :depth:|
51 :code: [
52|:: seek backward :executed: [ :depth:|
53 :code: [
54|:: seek backward? :executed: $x|
55 :code: $x
56|:: seek backward|
57
58|:: step :code: <|
59 :executed: <
60 :: move left
61|:: step :code: >|
62 :executed: >
63 :: move right
64|:: step :code: 0|
65 :executed: 0
66 :: push 0 to 1
67|:: step :code: 1|
68 :executed: 1
69 :: push 1 to 1
70|:: step :code: ^ :stack: $x?|
71 :executed: ^
72 :: pop from 1
73 :: push to $x
74|:: step :code: v :stack: $x?|
75 :executed: v
76 :: pop from $x
77 :: push to 1
78|:: step :code: [ :stack: $x?|
79 :executed: [
80 :: pop from 1
81 :: pop from $x
82 :: compare and branch
83|:: step :code: ]|
84 :executed: ]
85 :: seek backward
86|:: step :code: $x|
87|:: step| :halt:
88
89|:: run :halt:|
90 :: clean up
91|:: run?|
92 :: step
93
94|:: clean up? :executed: $x|
95|:: clean up? :code: $x|
96|:: clean up|
97
98|:: parse? :text: '<'| :parsed: <
99|:: parse? :text: '>'| :parsed: >
100|:: parse? :text: '0'| :parsed: 0
101|:: parse? :text: '1'| :parsed: 1
102|:: parse? :text: '^'| :parsed: ^
103|:: parse? :text: 'v'| :parsed: v
104|:: parse? :text: '['| :parsed: [
105|:: parse? :text: ']'| :parsed: ]
106|:: parse? :text: $x |
107|:: parse? :parsed: $x| :code: $x
108|:: parse|
109
110||:stack: 1
111
112|:: evaluate|
113 :: parse
114 :: run
115
116||:: evaluate :text: "0 1111 1111 1111 1^[>1^1^]"
117 :number of stacks: 50
118