about summary refs log tree commit diff stats
path: root/arc/.traces/channel-read
blob: 8a2a393f59a1820b5549dba9e0c232043ce064ac (plain) (blame)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
c{0: 0 (((1 channel-address)) <- ((init-channel)) ((3 literal))) -- nil
c{0: 1 (((2 integer)) <- ((copy)) ((34 literal))) -- nil
c{0: 2 (((3 tagged-value)) <- ((save-type)) ((2 integer))) -- nil
c{0: 3 (((1 channel-address) (deref)) <- ((write)) ((1 channel-address)) ((3 tagged-value))) -- nil
c{0: 4 (((5 tagged-value)) ((1 channel-address) (deref)) <- ((read)) ((1 channel-address))) -- nil
c{0: 5 (((7 integer)) <- ((maybe-coerce)) ((5 tagged-value)) ((integer literal))) -- nil
c{0: 6 (((8 integer)) <- ((get)) ((1 channel-address) (deref)) ((first-full offset))) -- nil
c{0: 7 (((9 integer)) <- ((get)) ((1 channel-address) (deref)) ((first-free offset))) -- nil
c{1: 0 ✓ (((1 channel-address)) <- ((init-channel)) ((3 literal)))
c{1: 1 ✓ (((2 integer)) <- ((copy)) ((34 literal)))
c{1: 2 ✓ (((3 tagged-value)) <- ((save-type)) ((2 integer)))
c{1: 3 ✓ (((1 channel-address) (deref)) <- ((write)) ((1 channel-address)) ((3 tagged-value)))
c{1: 4 ✓ (((5 tagged-value)) ((1 channel-address) (deref)) <- ((read)) ((1 channel-address)))
c{1: 5 ✓ (((7 integer)) <- ((maybe-coerce)) ((5 tagged-value)) ((integer literal)))
c{1: 6 ✓ (((8 integer)) <- ((get)) ((1 channel-address) (deref)) ((first-full offset)))
c{1: 7 ✓ (((9 integer)) <- ((get)) ((1 channel-address) (deref)) ((first-free offset)))
cn0: convert-names in main
cn0: (((1 channel-address)) <- ((init-channel)) ((3 literal))) nil nil
cn0: checking arg ((3 literal))
cn0: checking oarg ((1 channel-address))
maybe-add: ((1 channel-address))
cn0: (((2 integer)) <- ((copy)) ((34 literal))) nil nil
cn0: checking arg ((34 literal))
cn0: checking oarg ((2 integer))
maybe-add: ((2 integer))
cn0: (((3 tagged-value)) <- ((save-type)) ((2 integer))) nil nil
cn0: checking arg ((2 integer))
maybe-add: ((2 integer))
cn0: checking oarg ((3 tagged-value))
maybe-add: ((3 tagged-value))
cn0: (((1 channel-address) (deref)) <- ((write)) ((1 channel-address)) ((3 tagged-value))) nil nil
cn0: checking arg ((1 channel-address))
maybe-add: ((1 channel-address))
cn0: checking arg ((3 tagged-value))
maybe-add: ((3 tagged-value))
cn0: checking oarg ((1 channel-address) (deref))
maybe-add: ((1 channel-address) (deref))
cn0: (((5 tagged-value)) ((1 channel-address) (deref)) <- ((read)) ((1 channel-address))) nil nil
cn0: checking arg ((1 channel-address))
maybe-add: ((1 channel-address))
cn0: checking oarg ((5 tagged-value))
maybe-add: ((5 tagged-value))
cn0: checking oarg ((1 channel-address) (deref))
maybe-add: ((1 channel-address) (deref))
cn0: (((7 integer)) <- ((maybe-coerce)) ((5 tagged-value)) ((integer literal))) nil nil
cn0: checking arg ((5 tagged-value))
maybe-add: ((5 tagged-value))
cn0: checking arg ((integer literal))
cn0: checking oarg ((7 integer))
maybe-add: ((7 integer))
cn0: (((8 integer)) <- ((get)) ((1 channel-address) (deref)) ((first-full offset))) nil nil
cn0: field-access first-full in 1channel-addressderef of type channel
cn0: new field; computing location
cn0: field location 0
cn0: checking arg ((1 channel-address) (deref))
maybe-add: ((1 channel-address) (deref))
cn0: checking arg ((first-full offset))
cn0: checking oarg ((8 integer))
maybe-add: ((8 integer))
cn0: (((9 integer)) <- ((get)) ((1 channel-address) (deref)) ((first-free offset))) ((first-full 0)) ((first-full t))
cn0: field-access first-free in 1channel-addressderef of type channel
cn0: new field; computing location
cn0: field location 1
cn0: checking arg ((1 channel-address) (deref))
maybe-add: ((1 channel-address) (deref))
cn0: checking arg ((first-free offset))
cn0: checking oarg ((9 integer))
maybe-add: ((9 integer))
cn1: (((1 channel-address)) <- ((init-channel)) ((3 literal)))
cn1: (((2 integer)) <- ((copy)) ((34 literal)))
cn1: (((3 tagged-value)) <- ((save-type)) ((2 integer)))
cn1: (((1 channel-address) (deref)) <- ((write)) ((1 channel-address)) ((3 tagged-value)))
cn1: (((5 tagged-value)) ((1 channel-address) (deref)) <- ((read)) ((1 channel-address)))
cn1: (((7 integer)) <- ((maybe-coerce)) ((5 tagged-value)) ((integer literal)))
cn1: (((8 integer)) <- ((get)) ((1 channel-address) (deref)) ((0 offset)))
cn1: (((9 integer)) <- ((get)) ((1 channel-address) (deref)) ((1 offset)))
schedule: main
run: main 0: (((1 channel-address)) <- ((init-channel)) ((3 literal)))
run: init-channel/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: init-channel/main 0: 1000 => ((default-space space-address))
run: init-channel/main 1: (((1 channel-address)) <- ((new)) ((channel literal)))
run: init-channel/main 1: 1031 => ((1 channel-address))
mem: ((1 channel-address)): 1002 <= 1031
run: init-channel/main 2: (((2 integer-address)) <- ((get-address)) ((1 channel-address) (deref)) ((0 offset)))
run: init-channel/main 2: 1031 => ((2 integer-address))
mem: ((2 integer-address)): 1003 <= 1031
run: init-channel/main 3: (((2 integer-address) (deref)) <- ((copy)) ((0 literal)))
run: init-channel/main 3: 0 => ((2 integer-address) (deref))
mem: ((2 integer-address) (deref)): 1031 <= 0
run: init-channel/main 4: (((3 integer-address)) <- ((get-address)) ((1 channel-address) (deref)) ((1 offset)))
run: init-channel/main 4: 1032 => ((3 integer-address))
mem: ((3 integer-address)): 1004 <= 1032
run: init-channel/main 5: (((3 integer-address) (deref)) <- ((copy)) ((0 literal)))
run: init-channel/main 5: 0 => ((3 integer-address) (deref))
mem: ((3 integer-address) (deref)): 1032 <= 0
run: init-channel/main 6: (((4 integer)) <- ((next-input)))
arg: nil 0 (3)
run: init-channel/main 6: 3 => ((4 integer))
mem: ((4 integer)): 1005 <= 3
run: init-channel/main 7: (((4 integer)) <- ((add)) ((4 integer)) ((1 literal)))
mem: ((4 integer)) => 3
run: init-channel/main 7: 4 => ((4 integer))
mem: ((4 integer)): 1005 <= 4
run: init-channel/main 8: (((5 tagged-value-array-address-address)) <- ((get-address)) ((1 channel-address) (deref)) ((2 offset)))
run: init-channel/main 8: 1033 => ((5 tagged-value-array-address-address))
mem: ((5 tagged-value-array-address-address)): 1006 <= 1033
run: init-channel/main 9: (((5 tagged-value-array-address-address) (deref)) <- ((new)) ((tagged-value-array literal)) ((4 integer)))
mem: ((4 integer)) => 4
run: init-channel/main 9: 1034 => ((5 tagged-value-array-address-address) (deref))
mem: ((5 tagged-value-array-address-address) (deref)): 1033 <= 1034
run: init-channel/main 10: (((reply)) ((1 channel-address)))
mem: ((1 channel-address)) => 1031
run: main 0: 1031 => ((1 channel-address))
mem: ((1 channel-address)): 1 <= 1031
run: main 1: (((2 integer)) <- ((copy)) ((34 literal)))
run: main 1: 34 => ((2 integer))
mem: ((2 integer)): 2 <= 34
run: main 2: (((3 tagged-value)) <- ((save-type)) ((2 integer)))
mem: ((2 integer)) => 34
run: main 2: #(tagged record (integer 34)) => ((3 tagged-value))
mem: ((3 tagged-value)): 3 <= integer
mem: ((3 tagged-value)): 4 <= 34
run: main 3: (((1 channel-address) (deref)) <- ((write)) ((1 channel-address)) ((3 tagged-value)))
mem: ((1 channel-address)) => 1031
mem: ((3 tagged-value)) => #(tagged record (integer 34 . nil))
run: write/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: write/main 0: 1043 => ((default-space space-address))
run: write/main 1: (((1 channel-address)) <- ((next-input)))
arg: nil 0 (1031 #(tagged record (integer 34 . nil)))
run: write/main 1: 1031 => ((1 channel-address))
mem: ((1 channel-address)): 1045 <= 1031
run: write/main 2: (((2 tagged-value)) <- ((next-input)))
arg: nil 1 (1031 #(tagged record (integer 34 . nil)))
run: write/main 2: #(tagged record (integer 34 . nil)) => ((2 tagged-value))
mem: ((2 tagged-value)): 1046 <= integer
mem: ((2 tagged-value)): 1047 <= 34
run: write/main 3: (((4 boolean)) <- ((full?)) ((1 channel-address) (deref)))
mem: ((1 channel-address) (deref)) => #(tagged record (0 0 1034 . nil))
run: full?/write/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: full?/write/main 0: 1074 => ((default-space space-address))
run: full?/write/main 1: (((1 channel)) <- ((next-input)))
arg: nil 0 (#(tagged record (0 0 1034 . nil)))
run: full?/write/main 1: #(tagged record (0 0 1034 . nil)) => ((1 channel))
mem: ((1 channel)): 1076 <= 0
mem: ((1 channel)): 1077 <= 0
mem: ((1 channel)): 1078 <= 1034
run: full?/write/main 2: (((4 integer)) <- ((get)) ((1 channel)) ((1 offset)))
mem: ((1077 integer) (raw)) => 0
run: full?/write/main 2: 0 => ((4 integer))
mem: ((4 integer)): 1079 <= 0
run: full?/write/main 3: (((4 integer)) <- ((add)) ((4 integer)) ((1 literal)))
mem: ((4 integer)) => 0
run: full?/write/main 3: 1 => ((4 integer))
mem: ((4 integer)): 1079 <= 1
run: full?/write/main 4: (((5 integer)) <- ((capacity)) ((1 channel)))
mem: ((1 channel)) => #(tagged record (0 0 1034 . nil))
run: capacity/full?/write/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: capacity/full?/write/main 0: 1105 => ((default-space space-address))
run: capacity/full?/write/main 1: (((1 channel)) <- ((next-input)))
arg: nil 0 (#(tagged record (0 0 1034 . nil)))
run: capacity/full?/write/main 1: #(tagged record (0 0 1034 . nil)) => ((1 channel))
mem: ((1 channel)): 1107 <= 0
mem: ((1 channel)): 1108 <= 0
mem: ((1 channel)): 1109 <= 1034
run: capacity/full?/write/main 2: (((4 tagged-value-array-address)) <- ((get)) ((1 channel)) ((2 offset)))
mem: ((1109 tagged-value-array-address) (raw)) => 1034
run: capacity/full?/write/main 2: 1034 => ((4 tagged-value-array-address))
mem: ((4 tagged-value-array-address)): 1110 <= 1034
run: capacity/full?/write/main 3: (((5 integer)) <- ((length)) ((4 tagged-value-array-address) (deref)))
array-len: ((4 tagged-value-array-address) (deref))
mem: ((1034 integer) (raw)) => 4
run: capacity/full?/write/main 3: 4 => ((5 integer))
mem: ((5 integer)): 1111 <= 4
run: capacity/full?/write/main 4: (((reply)) ((5 integer)))
mem: ((5 integer)) => 4
run: full?/write/main 4: 4 => ((5 integer))
mem: ((5 integer)): 1080 <= 4
run: full?/write/main 5: (((6 boolean)) <- ((less-than)) ((4 integer)) ((5 integer)))
mem: ((4 integer)) => 1
mem: ((5 integer)) => 4
run: full?/write/main 5: t => ((6 boolean))
mem: ((6 boolean)): 1081 <= t
run: full?/write/main 6: (((jump-if)) ((6 boolean)) ((1 offset)))
mem: ((6 boolean)) => t
run: full?/write/main 8: (((7 integer)) <- ((get)) ((1 channel)) ((0 offset)))
mem: ((1076 integer) (raw)) => 0
run: full?/write/main 8: 0 => ((7 integer))
mem: ((7 integer)): 1082 <= 0
run: full?/write/main 9: (((8 boolean)) <- ((equal)) ((7 integer)) ((4 integer)))
mem: ((7 integer)) => 0
mem: ((4 integer)) => 1
run: full?/write/main 9: nil => ((8 boolean))
mem: ((8 boolean)): 1083 <= nil
run: full?/write/main 10: (((reply)) ((8 boolean)))
mem: ((8 boolean)) => nil
run: write/main 3: nil => ((4 boolean))
mem: ((4 boolean)): 1048 <= nil
run: write/main 4: (((jump-unless)) ((4 boolean)) ((2 offset)))
mem: ((4 boolean)) => nil
run: write/main 7: (((6 tagged-value-array-address)) <- ((get)) ((1 channel-address) (deref)) ((2 offset)))
mem: ((1033 tagged-value-array-address) (raw)) => 1034
run: write/main 7: 1034 => ((6 tagged-value-array-address))
mem: ((6 tagged-value-array-address)): 1050 <= 1034
run: write/main 8: (((7 integer-address)) <- ((get-address)) ((1 channel-address) (deref)) ((1 offset)))
run: write/main 8: 1032 => ((7 integer-address))
mem: ((7 integer-address)): 1051 <= 1032
run: write/main 9: (((8 tagged-value-address)) <- ((index-address)) ((6 tagged-value-array-address) (deref)) ((7 integer-address) (deref)))
mem: ((7 integer-address) (deref)) => 0
array-len: ((1034 tagged-value-array) (raw))
mem: ((1034 integer) (raw)) => 4
run: write/main 9: 1035 => ((8 tagged-value-address))
mem: ((8 tagged-value-address)): 1052 <= 1035
run: write/main 10: (((8 tagged-value-address) (deref)) <- ((copy)) ((2 tagged-value)))
mem: ((2 tagged-value)) => #(tagged record (integer 34 . nil))
run: write/main 10: #(tagged record (integer 34 . nil)) => ((8 tagged-value-address) (deref))
mem: ((8 tagged-value-address) (deref)): 1035 <= integer
mem: ((8 tagged-value-address) (deref)): 1036 <= 34
run: write/main 11: (((7 integer-address) (deref)) <- ((add)) ((7 integer-address) (deref)) ((1 literal)))
mem: ((7 integer-address) (deref)) => 0
run: write/main 11: 1 => ((7 integer-address) (deref))
mem: ((7 integer-address) (deref)): 1032 <= 1
run: write/main 12: (((9 integer)) <- ((length)) ((6 tagged-value-array-address) (deref)))
array-len: ((6 tagged-value-array-address) (deref))
mem: ((1034 integer) (raw)) => 4
run: write/main 12: 4 => ((9 integer))
mem: ((9 integer)): 1053 <= 4
run: write/main 13: (((10 boolean)) <- ((less-than)) ((7 integer-address) (deref)) ((9 integer)))
mem: ((7 integer-address) (deref)) => 1
mem: ((9 integer)) => 4
run: write/main 13: t => ((10 boolean))
mem: ((10 boolean)): 1054 <= t
run: write/main 14: (((jump-if)) ((10 boolean)) ((1 offset)))
mem: ((10 boolean)) => t
run: write/main 16: (((reply)) ((1 channel-address) (deref) (same-as-arg 0)))
mem: ((1 channel-address) (deref) (same-as-arg 0)) => #(tagged record (0 1 1034 . nil))
run: main 3: #(tagged record (0 1 1034 . nil)) => ((1 channel-address) (deref))
mem: ((1 channel-address) (deref)): 1031 <= 0
mem: ((1 channel-address) (deref)): 1032 <= 1
mem: ((1 channel-address) (deref)): 1033 <= 1034
run: main 4: (((5 tagged-value)) ((1 channel-address) (deref)) <- ((read)) ((1 channel-address)))
mem: ((1 channel-address)) => 1031
run: read/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: read/main 0: 1136 => ((default-space space-address))
run: read/main 1: (((1 channel-address)) <- ((next-input)))
arg: nil 0 (1031)
run: read/main 1: 1031 => ((1 channel-address))
mem: ((1 channel-address)): 1138 <= 1031
run: read/main 2: (((2 boolean)) <- ((empty?)) ((1 channel-address) (deref)))
mem: ((1 channel-address) (deref)) => #(tagged record (0 1 1034 . nil))
run: empty?/read/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: empty?/read/main 0: 1167 => ((default-space space-address))
run: empty?/read/main 1: (((1 channel)) <- ((next-input)))
arg: nil 0 (#(tagged record (0 1 1034 . nil)))
run: empty?/read/main 1: #(tagged record (0 1 1034 . nil)) => ((1 channel))
mem: ((1 channel)): 1169 <= 0
mem: ((1 channel)): 1170 <= 1
mem: ((1 channel)): 1171 <= 1034
run: empty?/read/main 2: (((4 integer)) <- ((get)) ((1 channel)) ((0 offset)))
mem: ((1169 integer) (raw)) => 0
run: empty?/read/main 2: 0 => ((4 integer))
mem: ((4 integer)): 1172 <= 0
run: empty?/read/main 3: (((5 integer)) <- ((get)) ((1 channel)) ((1 offset)))
mem: ((1170 integer) (raw)) => 1
run: empty?/read/main 3: 1 => ((5 integer))
mem: ((5 integer)): 1173 <= 1
run: empty?/read/main 4: (((6 boolean)) <- ((equal)) ((4 integer)) ((5 integer)))
mem: ((4 integer)) => 0
mem: ((5 integer)) => 1
run: empty?/read/main 4: nil => ((6 boolean))
mem: ((6 boolean)): 1174 <= nil
run: empty?/read/main 5: (((reply)) ((6 boolean)))
mem: ((6 boolean)) => nil
run: read/main 2: nil => ((2 boolean))
mem: ((2 boolean)): 1139 <= nil
run: read/main 3: (((jump-unless)) ((2 boolean)) ((2 offset)))
mem: ((2 boolean)) => nil
run: read/main 6: (((4 integer-address)) <- ((get-address)) ((1 channel-address) (deref)) ((0 offset)))
run: read/main 6: 1031 => ((4 integer-address))
mem: ((4 integer-address)): 1141 <= 1031
run: read/main 7: (((5 tagged-value-array-address)) <- ((get)) ((1 channel-address) (deref)) ((2 offset)))
mem: ((1033 tagged-value-array-address) (raw)) => 1034
run: read/main 7: 1034 => ((5 tagged-value-array-address))
mem: ((5 tagged-value-array-address)): 1142 <= 1034
run: read/main 8: (((6 tagged-value)) <- ((index)) ((5 tagged-value-array-address) (deref)) ((4 integer-address) (deref)))
mem: ((4 integer-address) (deref)) => 0
array-len: ((1034 tagged-value-array) (raw))
mem: ((1034 integer) (raw)) => 4
mem: ((1035 tagged-value) (raw)) => #(tagged record (integer 34 . nil))
run: read/main 8: #(tagged record (integer 34 . nil)) => ((6 tagged-value))
mem: ((6 tagged-value)): 1143 <= integer
mem: ((6 tagged-value)): 1144 <= 34
run: read/main 9: (((4 integer-address) (deref)) <- ((add)) ((4 integer-address) (deref)) ((1 literal)))
mem: ((4 integer-address) (deref)) => 0
run: read/main 9: 1 => ((4 integer-address) (deref))
mem: ((4 integer-address) (deref)): 1031 <= 1
run: read/main 10: (((8 integer)) <- ((length)) ((5 tagged-value-array-address) (deref)))
array-len: ((5 tagged-value-array-address) (deref))
mem: ((1034 integer) (raw)) => 4
run: read/main 10: 4 => ((8 integer))
mem: ((8 integer)): 1145 <= 4
run: read/main 11: (((9 boolean)) <- ((less-than)) ((4 integer-address) (deref)) ((8 integer)))
mem: ((4 integer-address) (deref)) => 1
mem: ((8 integer)) => 4
run: read/main 11: t => ((9 boolean))
mem: ((9 boolean)): 1146 <= t
run: read/main 12: (((jump-if)) ((9 boolean)) ((1 offset)))
mem: ((9 boolean)) => t
run: read/main 14: (((reply)) ((6 tagged-value)) ((1 channel-address) (deref) (same-as-arg 0)))
mem: ((6 tagged-value)) => #(tagged record (integer 34 . nil))
mem: ((1 channel-address) (deref) (same-as-arg 0)) => #(tagged record (1 1 1034 . nil))
run: main 4: #(tagged record (integer 34 . nil)) => ((5 tagged-value))
mem: ((5 tagged-value)): 5 <= integer
mem: ((5 tagged-value)): 6 <= 34
run: main 4: #(tagged record (1 1 1034 . nil)) => ((1 channel-address) (deref))
mem: ((1 channel-address) (deref)): 1031 <= 1
mem: ((1 channel-address) (deref)): 1032 <= 1
mem: ((1 channel-address) (deref)): 1033 <= 1034
run: main 5: (((7 integer)) <- ((maybe-coerce)) ((5 tagged-value)) ((integer literal)))
mem: ((5 tagged-value)) => #(tagged record (integer 34 . nil))
run: maybe-coerce/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: maybe-coerce/main 0: 1198 => ((default-space space-address))
run: maybe-coerce/main 1: (((1 tagged-value-address)) <- ((new)) ((tagged-value literal)))
run: maybe-coerce/main 1: 1229 => ((1 tagged-value-address))
mem: ((1 tagged-value-address)): 1200 <= 1229
run: maybe-coerce/main 2: (((1 tagged-value-address) (deref)) <- ((next-input)))
arg: nil 0 (#(tagged record (integer 34 . nil)) integer)
run: maybe-coerce/main 2: #(tagged record (integer 34 . nil)) => ((1 tagged-value-address) (deref))
mem: ((1 tagged-value-address) (deref)): 1229 <= integer
mem: ((1 tagged-value-address) (deref)): 1230 <= 34
run: maybe-coerce/main 3: (((2 type)) <- ((next-input)))
arg: nil 1 (#(tagged record (integer 34 . nil)) integer)
run: maybe-coerce/main 3: integer => ((2 type))
mem: ((2 type)): 1201 <= integer
run: maybe-coerce/main 4: (((3 type)) <- ((get)) ((1 tagged-value-address) (deref)) ((0 offset)))
mem: ((1229 type) (raw)) => integer
run: maybe-coerce/main 4: integer => ((3 type))
mem: ((3 type)): 1202 <= integer
run: maybe-coerce/main 5: (((4 boolean)) <- ((equal)) ((3 type)) ((2 type)))
mem: ((3 type)) => integer
mem: ((2 type)) => integer
run: maybe-coerce/main 5: t => ((4 boolean))
mem: ((4 boolean)): 1203 <= t
run: maybe-coerce/main 6: (((jump-if)) ((4 boolean)) ((1 offset)))
mem: ((4 boolean)) => t
run: maybe-coerce/main 8: (((5 location)) <- ((get)) ((1 tagged-value-address) (deref)) ((1 offset)))
mem: ((1230 location) (raw)) => 34
run: maybe-coerce/main 8: 34 => ((5 location))
mem: ((5 location)): 1204 <= 34
run: maybe-coerce/main 9: (((reply)) ((5 location)) ((4 boolean)))
mem: ((5 location)) => 34
mem: ((4 boolean)) => t
run: main 5: 34 => ((7 integer))
mem: ((7 integer)): 7 <= 34
run: main 6: (((8 integer)) <- ((get)) ((1 channel-address) (deref)) ((0 offset)))
mem: ((1031 integer) (raw)) => 1
run: main 6: 1 => ((8 integer))
mem: ((8 integer)): 8 <= 1
run: main 7: (((9 integer)) <- ((get)) ((1 channel-address) (deref)) ((1 offset)))
mem: ((1032 integer) (raw)) => 1
run: main 7: 1 => ((9 integer))
mem: ((9 integer)): 9 <= 1
schedule: done with routine nil
p">, NULL); } else if (curr_uni == ' ') { tokens = g_slist_append(tokens, g_strndup(token_start, token_size)); token_size = 0; in_token = FALSE; } else { token_size += g_unichar_to_utf8(curr_uni, NULL); } } } } if (in_token) { tokens = g_slist_append(tokens, g_strndup(token_start, token_size)); } free(copy); int num = g_slist_length(tokens) - 1; // if num args not valid return NULL if ((num < min) || (num > max)) { g_slist_free_full(tokens, free); *result = FALSE; return NULL; // if min allowed is 0 and 0 found, return empty char* array } else if (min == 0 && num == 0) { g_slist_free_full(tokens, free); gchar** args = g_malloc((num + 1) * sizeof(*args)); args[0] = NULL; *result = TRUE; return args; // otherwise return args array } else { gchar** args = g_malloc((num + 1) * sizeof(*args)); GSList* token = tokens; token = g_slist_next(token); int arg_count = 0; while (token) { args[arg_count++] = strdup(token->data); token = g_slist_next(token); } args[arg_count] = NULL; g_slist_free_full(tokens, free); *result = TRUE; return args; } } /* * Take a full line of input and return an array of strings representing * the arguments of a command. * If the number of arguments found is less than min, or more than max * NULL is returned. * * inp - The line of input * min - The minimum allowed number of arguments * max - The maximum allowed number of arguments * * Returns - An NULL terminated array of strings representing the arguments * of the command, or NULL if the validation fails. * * E.g. the following input line: * * /cmd arg1 arg2 * * Will return a pointer to the following array: * * { "arg1", "arg2", NULL } * */ gchar** parse_args(const char* const inp, int min, int max, gboolean* result) { return _parse_args_helper(inp, min, max, result, FALSE); } /* * Take a full line of input and return an array of strings representing * the arguments of a command. This function handles when the last parameter * to the command is free text e.g. * * /msg user@host here is a message * * If the number of arguments found is less than min, or more than max * NULL is returned. * * inp - The line of input * min - The minimum allowed number of arguments * max - The maximum allowed number of arguments * * Returns - An NULL terminated array of strings representing the arguments * of the command, or NULL if the validation fails. * * E.g. the following input line: * * /cmd arg1 arg2 some free text * * Will return a pointer to the following array: * * { "arg1", "arg2", "some free text", NULL } * */ gchar** parse_args_with_freetext(const char* const inp, int min, int max, gboolean* result) { return _parse_args_helper(inp, min, max, result, TRUE); } /* * Will just take everything after the first space as the argument. * Used for `/correct` so that we also include quotation marks. */ gchar** parse_args_as_one(const char* const inp, int min, int max, gboolean* result) { gchar** args = g_malloc0(2 * sizeof(*args)); int length = g_utf8_strlen(inp, -1); gchar* space = g_utf8_strchr(inp, length, ' '); if (space) { int sub_length = g_utf8_strlen(space, -1); if (sub_length > 1) { args[0] = g_strdup(space + 1); *result = TRUE; return args; } else { g_free(args); } } else { g_free(args); } *result = FALSE; return NULL; } int count_tokens(const char* const string) { int length = g_utf8_strlen(string, -1); gboolean in_quotes = FALSE; int num_tokens = 0; // include first token num_tokens++; for (int i = 0; i < length; i++) { gchar* curr_ch = g_utf8_offset_to_pointer(string, i); gunichar curr_uni = g_utf8_get_char(curr_ch); if (curr_uni == ' ') { if (!in_quotes) { num_tokens++; } } else if (curr_uni == '"') { if (in_quotes) { in_quotes = FALSE; } else { in_quotes = TRUE; } } } return num_tokens; } char* get_start(const char* const string, int tokens) { GString* result = g_string_new(""); int length = g_utf8_strlen(string, -1); gboolean in_quotes = FALSE; int num_tokens = 0; // include first token num_tokens++; for (int i = 0; i < length; i++) { gchar* curr_ch = g_utf8_offset_to_pointer(string, i); gunichar curr_uni = g_utf8_get_char(curr_ch); if (num_tokens < tokens) { gchar* uni_char = g_malloc(7); int len = g_unichar_to_utf8(curr_uni, uni_char); uni_char[len] = '\0'; g_string_append(result, uni_char); g_free(uni_char); } if (curr_uni == ' ') { if (!in_quotes) { num_tokens++; } } else if (curr_uni == '"') { if (in_quotes) { in_quotes = FALSE; } else { in_quotes = TRUE; } } } return g_string_free(result, FALSE); } GHashTable* parse_options(gchar** args, gchar** opt_keys, gboolean* res) { GList* keys = NULL; for (int i = 0; i < g_strv_length(opt_keys); i++) { keys = g_list_append(keys, opt_keys[i]); } GHashTable* options = NULL; // no options found, success if (args[0] == NULL) { options = g_hash_table_new(g_str_hash, g_str_equal); *res = TRUE; g_list_free(keys); return options; } // validate options GList* found_keys = NULL; for (int curr = 0; curr < g_strv_length(args); curr += 2) { // check if option valid if (g_list_find_custom(keys, args[curr], (GCompareFunc)g_strcmp0) == NULL) { *res = FALSE; g_list_free(found_keys); g_list_free(keys); return options; } // check if duplicate if (g_list_find_custom(found_keys, args[curr], (GCompareFunc)g_strcmp0)) { *res = FALSE; g_list_free(found_keys); g_list_free(keys); return options; } // check value given if (args[curr + 1] == NULL) { *res = FALSE; g_list_free(found_keys); g_list_free(keys); return options; } found_keys = g_list_append(found_keys, args[curr]); } g_list_free(found_keys); g_list_free(keys); // create map options = g_hash_table_new(g_str_hash, g_str_equal); *res = TRUE; for (int curr = 0; curr < g_strv_length(args); curr += 2) { g_hash_table_insert(options, args[curr], args[curr + 1]); } return options; } void options_destroy(GHashTable* options) { if (options) { g_hash_table_destroy(options); } }