-
Notifications
You must be signed in to change notification settings - Fork 1
/
notes.txt
204 lines (156 loc) · 2.82 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
true # pushable
[ consequent_1 consequent_2 ] # pushable
[ alternative_1 alternative_2 ] # pushable
3 # pushable
4 # pushable
if # command
+ # command
###### after if
# [ 3 4 consequent_block_result ]
######################### after +
# [ consequent_block_result 7 ]
3
1
2
"three"
qq # command
# [ [1 2 "three"] ]
3
4
"a"
qalloc
# [ 4 "a" [_ _ _] ]
"foo"
[ ...block ]
def # command
2
1
2
pack # or, since length is known statically: [ 1 2 ]
foo
# fnq: [ ["foo" [...block]] ]
# qq: [ foo ]
2 # num_args
1 # argv
2
"foo" # fn_name
pack
call # command
# qq: [ "foo" [1 2] ]
call
"foo bar"
to_a
# [ 7 "f" "o" ... ]
enq
deq
MVP:
* Numbers (pushable)
* Math operators (commands)
V1:
* Strings
* Code blocks
* Procedures Subqueues +
V2:
* Conditionals
* Loops
V3:
* Bootstrap?
true
not
# [ false ]
###
13 # [ 13 ]
1 # [ 13 1 ]
>= # [ true ]
[ "hello" print ] # [ true `[ "hello" print ] ]
if # []
# prints "hello"
# queue is []
Block([ # intend to immediately evaluate
Number("13"),
Number("1"),
Command(">="),
Queue([]),
])
true # [ true ]
14 # [ true 14 ]
if # [ 14 ] or ERROR: cannot execute 14
true # [ true ]
[ 14 ] # [ true [ 14 ] ]
if # [ 14 ]
14
] # end of pack
[ # pack
[ 1 2 [ 3 ] + ] # [ [ 1 2 [3] + ] 6 7 ... ]
6
7
...
# [ 6 7 ... 1 2 [ 3 ] ]
exec # [ ... 1 2 [ 3 ] 13 ]
"get_name"
[ io_recv ] # receives "Jeremy"
def # register "func" as [ ... ]
"get_name"
[ 1 2 ] # [ "get_name" [ 1 2 ] ]
call # [ [ 1 2 "Jeremy" ] ] or [ 1 2 "Jeremy" ]
# It would be up to "get_name" to pop the first two elements.
get_name: [ pop pop io_recv ]
get_name: [ drain io_recv ]
# If we wanted [ [ "Jeremy" ] ]
# [ [1 2 3] [4 5 6] ]
concat
# [ [1 2 3 4 5 6] ]
# [ [ 1 2 3 ] "a" ]
qpop
# [ "a" [ 2 3 ] ]
# [ [ 1 2 3 ] "a" ]
pop
# [ "a" ]
# [ "a" "b" ... ]
rot
# [ ... "b" "a" ]
## ASQ
instructions = Queue([
Number("1"),
Number("2"),
String("abcdef"),
Identifier("+"),
Identifier("multiply_strings"),
Block([Number("3"), Number("4"), ...]),
Keyword("if"),
Boolean("true"),
Boolean("false"),
])
queue_frame = []
instructions.execute(queue_frame)
class Number:
def __init__(self, flt):
self.val = flt
def execute(self, frame):
frame.push(self)
class Plus:
def execute(self, frame):
l = frame.pop()
r = frame.pop()
frame.push(Number(l.val + r.val))
# 1 + 1 - 3
1
1
+
# [ 2 ]
3
# [ 2 3 ]
-
# [ -1 ]
1
1
3
# [ 1 1 3 ]
+
# [ 3 2 ]
-
# [ 1 ]
QQ # print the whole queue and crash
JK: parser
JW: + - * /
RG: QQ read_line read_num print