sardonyx 0.1.843 → 0.2.0
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.
- checksums.yaml +4 -4
- data/bin/sdx +1 -1
- data/lib/sdx/compiler/parser.rb +207 -99
- data/lib/sdx/vm/datatypes.rb +0 -2
- data/lib/sdx/vm/vm.rb +5 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b28cfaca2d8790be84bad3e1f6bffd5ead67aeaa6be749643a68828530b68bbe
|
|
4
|
+
data.tar.gz: 92a7ea6bccf98cf8099fbe8665e20c1a6548c6c7fe4a7c92289ce8dda7ca6393
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89cde9393ea7e0f22af24ebe35c18a0b414c9dd115df9d378bcc98b4686f246cd550210ef3ed7f417f00e71b1bc866ccdc3611230c2d63379f8bdae93e651ba4
|
|
7
|
+
data.tar.gz: 19dc7e4ccf4700d2158d29812fedfc673ad68fb893c99d9ff98f5bc3d8044b3f0cf10efa9738fbe41931f683e2a276d5f5cf8823509428f9b75540b68f371dcc
|
data/bin/sdx
CHANGED
data/lib/sdx/compiler/parser.rb
CHANGED
|
@@ -11,11 +11,12 @@ module Parser
|
|
|
11
11
|
/\Anew/ => :new,
|
|
12
12
|
/\Arequire/ => :require,
|
|
13
13
|
/\A(true|false)/ => :bool,
|
|
14
|
-
/\A(<|>|<=|>=|==|!=)/ => :op,
|
|
15
|
-
/\A(\+|-|\*|\/|%)?=/ => :eq,
|
|
16
|
-
/\A(\+|-|\*|\/|%)/ => :op,
|
|
17
|
-
/\A-?[0-9]+/ => :number,
|
|
18
14
|
/\A-?[0-9]+\.[0-9]+/ => :float,
|
|
15
|
+
/\A-?[0-9]+/ => :number,
|
|
16
|
+
/\A(\+|-)/ => :l1op,
|
|
17
|
+
/\A(\/|\*|%|\^)/ => :l2op,
|
|
18
|
+
/\A(<|>|<=|>=|==|!=)/ => :l1op,
|
|
19
|
+
/\A(\+|-|\*|\/|%)?=/ => :eq,
|
|
19
20
|
/\A"([^"]|\\")*"/ => :string,
|
|
20
21
|
/\Anil/ => :nil,
|
|
21
22
|
/\A\(/ => :lpar,
|
|
@@ -124,13 +125,15 @@ module Parser
|
|
|
124
125
|
|
|
125
126
|
def self.parse_parens(tokens)
|
|
126
127
|
if self.expect tokens, :lpar
|
|
127
|
-
tokens = tokens[1
|
|
128
|
-
|
|
128
|
+
tokens = tokens[1..-1]
|
|
129
|
+
res = self.parse_expr tokens
|
|
130
|
+
unless res
|
|
129
131
|
return nil
|
|
130
132
|
end
|
|
131
133
|
e, part = self.parse_expr tokens
|
|
132
|
-
tokens = tokens[part
|
|
133
|
-
|
|
134
|
+
tokens = tokens[part..-1]
|
|
135
|
+
res = self.expect tokens, :rpar
|
|
136
|
+
unless res
|
|
134
137
|
return nil
|
|
135
138
|
end
|
|
136
139
|
return [e, part + 2]
|
|
@@ -143,7 +146,7 @@ module Parser
|
|
|
143
146
|
unless (self.expect tokens, :lbrack)
|
|
144
147
|
return nil
|
|
145
148
|
end
|
|
146
|
-
tokens = tokens[1
|
|
149
|
+
tokens = tokens[1..-1]
|
|
147
150
|
children = []
|
|
148
151
|
total = 1
|
|
149
152
|
while true
|
|
@@ -151,13 +154,14 @@ module Parser
|
|
|
151
154
|
total += 1
|
|
152
155
|
break
|
|
153
156
|
end
|
|
154
|
-
|
|
157
|
+
res = self.parse_expr tokens
|
|
158
|
+
unless res
|
|
155
159
|
return nil
|
|
156
160
|
end
|
|
157
|
-
e, part =
|
|
161
|
+
e, part = res
|
|
158
162
|
children << e
|
|
159
163
|
total += part
|
|
160
|
-
tokens = tokens[part
|
|
164
|
+
tokens = tokens[part..-1]
|
|
161
165
|
if self.expect tokens, :rbrack
|
|
162
166
|
total += 1
|
|
163
167
|
break
|
|
@@ -166,7 +170,7 @@ module Parser
|
|
|
166
170
|
return nil
|
|
167
171
|
end
|
|
168
172
|
total += 1
|
|
169
|
-
tokens = tokens[1
|
|
173
|
+
tokens = tokens[1..-1]
|
|
170
174
|
end
|
|
171
175
|
[ (Node.new :list, "", children), total ]
|
|
172
176
|
end
|
|
@@ -175,7 +179,7 @@ module Parser
|
|
|
175
179
|
unless (self.expect tokens, :lbrace)
|
|
176
180
|
return nil
|
|
177
181
|
end
|
|
178
|
-
tokens = tokens[1
|
|
182
|
+
tokens = tokens[1..-1]
|
|
179
183
|
children = []
|
|
180
184
|
total = 1
|
|
181
185
|
while true
|
|
@@ -187,7 +191,7 @@ module Parser
|
|
|
187
191
|
if e
|
|
188
192
|
children << e[0]
|
|
189
193
|
total += e[1]
|
|
190
|
-
tokens = tokens[e[1]
|
|
194
|
+
tokens = tokens[e[1]..-1]
|
|
191
195
|
else
|
|
192
196
|
puts "Syntax error at token ", tokens[0]
|
|
193
197
|
Kernel.exit 1
|
|
@@ -198,41 +202,52 @@ module Parser
|
|
|
198
202
|
end
|
|
199
203
|
|
|
200
204
|
def self.parse_literal(tokens)
|
|
201
|
-
(self.parse_block tokens) ||
|
|
205
|
+
(self.parse_block tokens) ||
|
|
206
|
+
(self.parse_bool tokens) ||
|
|
207
|
+
(self.parse_float tokens) ||
|
|
208
|
+
(self.parse_name tokens) ||
|
|
209
|
+
(self.parse_number tokens) ||
|
|
210
|
+
(self.parse_list tokens) ||
|
|
211
|
+
(self.parse_string tokens) ||
|
|
212
|
+
(self.parse_nil tokens) ||
|
|
213
|
+
(self.parse_parens tokens)
|
|
202
214
|
end
|
|
203
215
|
|
|
204
216
|
def self.parse_call(tokens)
|
|
205
|
-
|
|
217
|
+
res = (self.parse_literal tokens)
|
|
218
|
+
unless res
|
|
206
219
|
return nil
|
|
207
220
|
end
|
|
208
|
-
callee =
|
|
221
|
+
callee = res
|
|
209
222
|
total = callee[1]
|
|
210
|
-
tokens = tokens[total
|
|
223
|
+
tokens = tokens[total..-1]
|
|
211
224
|
callee = callee[0]
|
|
212
225
|
if self.expect tokens, :lpar
|
|
213
226
|
args = []
|
|
214
|
-
tokens = tokens[1
|
|
227
|
+
tokens = tokens[1..-1]
|
|
215
228
|
total += 1
|
|
216
229
|
if self.expect tokens, :rpar
|
|
217
230
|
return [ (Node.new :call, callee, args), total + 1 ]
|
|
218
231
|
end
|
|
219
232
|
while true
|
|
220
|
-
|
|
233
|
+
res = (self.parse_expr tokens)
|
|
234
|
+
unless res
|
|
221
235
|
return nil
|
|
222
236
|
end
|
|
223
|
-
arg, part =
|
|
237
|
+
arg, part = res
|
|
224
238
|
total += part
|
|
225
|
-
tokens = tokens[part
|
|
239
|
+
tokens = tokens[part..-1]
|
|
226
240
|
args << arg
|
|
227
|
-
total += 1
|
|
228
241
|
if self.expect tokens, :rpar
|
|
229
|
-
tokens = tokens[1
|
|
242
|
+
tokens = tokens[1..-1]
|
|
243
|
+
total += 1
|
|
230
244
|
break
|
|
231
245
|
end
|
|
232
246
|
unless (self.expect tokens, :comma)
|
|
233
247
|
return nil
|
|
234
248
|
end
|
|
235
|
-
|
|
249
|
+
total += 1
|
|
250
|
+
tokens = tokens[1..-1]
|
|
236
251
|
end
|
|
237
252
|
return [ (Node.new :call, callee, args), total ]
|
|
238
253
|
else
|
|
@@ -245,36 +260,38 @@ module Parser
|
|
|
245
260
|
return nil
|
|
246
261
|
end
|
|
247
262
|
total = 1
|
|
248
|
-
tokens = tokens[1
|
|
263
|
+
tokens = tokens[1..-1]
|
|
249
264
|
if self.lookahead tokens, :lpar, 1
|
|
250
|
-
|
|
265
|
+
res = (self.parse_literal tokens)
|
|
266
|
+
unless res
|
|
251
267
|
return nil
|
|
252
268
|
end
|
|
253
|
-
callee =
|
|
269
|
+
callee = res
|
|
254
270
|
callee = callee[0]
|
|
255
271
|
args = []
|
|
256
|
-
tokens = tokens[2
|
|
272
|
+
tokens = tokens[2..-1]
|
|
257
273
|
total += 2
|
|
258
274
|
if self.expect tokens, :rpar
|
|
259
275
|
return [ (Node.new :call, callee, args), total + 1 ]
|
|
260
276
|
end
|
|
261
277
|
while true
|
|
262
|
-
|
|
278
|
+
res = (self.parse_expr tokens)
|
|
279
|
+
unless res
|
|
263
280
|
return nil
|
|
264
281
|
end
|
|
265
|
-
arg, part =
|
|
282
|
+
arg, part = res
|
|
266
283
|
total += part
|
|
267
|
-
tokens = tokens[part
|
|
284
|
+
tokens = tokens[part..-1]
|
|
268
285
|
args << arg
|
|
269
286
|
total += 1
|
|
270
287
|
if self.expect tokens, :rpar
|
|
271
|
-
tokens = tokens[1
|
|
288
|
+
tokens = tokens[1..-1]
|
|
272
289
|
break
|
|
273
290
|
end
|
|
274
291
|
unless (self.expect tokens, :comma)
|
|
275
292
|
return nil
|
|
276
293
|
end
|
|
277
|
-
tokens = tokens[1
|
|
294
|
+
tokens = tokens[1..-1]
|
|
278
295
|
end
|
|
279
296
|
return [ (Node.new :new, callee, args), total ]
|
|
280
297
|
else
|
|
@@ -287,30 +304,33 @@ module Parser
|
|
|
287
304
|
return nil
|
|
288
305
|
end
|
|
289
306
|
total = 1
|
|
290
|
-
tokens = tokens[1
|
|
291
|
-
|
|
307
|
+
tokens = tokens[1..-1]
|
|
308
|
+
res = self.parse_expr tokens
|
|
309
|
+
unless res
|
|
292
310
|
return nil
|
|
293
311
|
end
|
|
294
|
-
e, part =
|
|
312
|
+
e, part = res
|
|
295
313
|
total += part
|
|
296
|
-
tokens = tokens[part
|
|
297
|
-
|
|
314
|
+
tokens = tokens[part..-1]
|
|
315
|
+
res = self.parse_expr tokens
|
|
316
|
+
unless res
|
|
298
317
|
return nil
|
|
299
318
|
end
|
|
300
|
-
block, part =
|
|
319
|
+
block, part = res
|
|
301
320
|
total += part
|
|
302
|
-
tokens = tokens[part
|
|
321
|
+
tokens = tokens[part..-1]
|
|
303
322
|
el = nil
|
|
304
323
|
if self.expect tokens, :else
|
|
305
324
|
total += 1
|
|
306
|
-
tokens = tokens[1
|
|
307
|
-
|
|
325
|
+
tokens = tokens[1..-1]
|
|
326
|
+
res = self.parse_expr tokens
|
|
327
|
+
unless res
|
|
308
328
|
return nil
|
|
309
329
|
end
|
|
310
|
-
el, part =
|
|
330
|
+
el, part = res
|
|
311
331
|
total += part
|
|
312
332
|
end
|
|
313
|
-
|
|
333
|
+
[ (Node.new :if, e, [block, el]), total ]
|
|
314
334
|
end
|
|
315
335
|
|
|
316
336
|
def self.parse_while(tokens)
|
|
@@ -318,19 +338,21 @@ module Parser
|
|
|
318
338
|
return nil
|
|
319
339
|
end
|
|
320
340
|
total = 1
|
|
321
|
-
tokens = tokens[1
|
|
322
|
-
|
|
341
|
+
tokens = tokens[1..-1]
|
|
342
|
+
res = self.parse_expr tokens
|
|
343
|
+
unless res
|
|
323
344
|
return nil
|
|
324
345
|
end
|
|
325
|
-
e, part =
|
|
346
|
+
e, part = res
|
|
326
347
|
total += part
|
|
327
|
-
tokens = tokens[part
|
|
328
|
-
|
|
348
|
+
tokens = tokens[part..-1]
|
|
349
|
+
res = self.parse_expr tokens
|
|
350
|
+
unless res
|
|
329
351
|
return nil
|
|
330
352
|
end
|
|
331
|
-
block, part =
|
|
353
|
+
block, part = res
|
|
332
354
|
total += part
|
|
333
|
-
|
|
355
|
+
[ (Node.new :while, e, [block]), total ]
|
|
334
356
|
end
|
|
335
357
|
|
|
336
358
|
def self.parse_for(tokens)
|
|
@@ -338,47 +360,120 @@ module Parser
|
|
|
338
360
|
return nil
|
|
339
361
|
end
|
|
340
362
|
total = 1
|
|
341
|
-
tokens = tokens[1
|
|
363
|
+
tokens = tokens[1..-1]
|
|
342
364
|
name = nil
|
|
343
365
|
if self.expect tokens, :name and self.lookahead tokens, :in, 1
|
|
344
366
|
name = tokens[0][0]
|
|
345
367
|
total += 2
|
|
346
|
-
tokens = tokens[2
|
|
368
|
+
tokens = tokens[2..-1]
|
|
347
369
|
end
|
|
348
|
-
|
|
370
|
+
res = self.parse_expr tokens
|
|
371
|
+
unless res
|
|
349
372
|
return nil
|
|
350
373
|
end
|
|
351
|
-
e, part =
|
|
374
|
+
e, part = res
|
|
352
375
|
total += part
|
|
353
|
-
tokens = tokens[part
|
|
354
|
-
|
|
376
|
+
tokens = tokens[part..-1]
|
|
377
|
+
res = self.parse_expr tokens
|
|
378
|
+
unless res
|
|
355
379
|
return nil
|
|
356
380
|
end
|
|
357
|
-
block, part =
|
|
381
|
+
block, part = res
|
|
358
382
|
total += part
|
|
359
|
-
|
|
383
|
+
[ (Node.new :for, e, [name, block]), total ]
|
|
360
384
|
end
|
|
361
385
|
|
|
362
|
-
def self.
|
|
386
|
+
def self.parse_factor(tokens)
|
|
387
|
+
(self.parse_call tokens) ||
|
|
388
|
+
(self.parse_require tokens) ||
|
|
389
|
+
(self.parse_new tokens) ||
|
|
390
|
+
(self.parse_object tokens) ||
|
|
391
|
+
(self.parse_fn tokens) ||
|
|
392
|
+
(self.parse_assign tokens) ||
|
|
393
|
+
(self.parse_literal tokens) ||
|
|
394
|
+
(self.parse_if tokens) ||
|
|
395
|
+
(self.parse_while tokens) ||
|
|
396
|
+
(self.parse_for tokens)
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
def self.parse_term(tokens)
|
|
363
400
|
total = 0
|
|
364
|
-
|
|
401
|
+
res = self.parse_factor tokens
|
|
402
|
+
unless res
|
|
365
403
|
return nil
|
|
366
404
|
end
|
|
367
|
-
lhs, part =
|
|
405
|
+
lhs, part = res
|
|
368
406
|
total += part
|
|
369
|
-
tokens = tokens[part
|
|
370
|
-
unless self.expect tokens, :
|
|
407
|
+
tokens = tokens[part..-1]
|
|
408
|
+
unless self.expect tokens, :l2op
|
|
409
|
+
return [lhs, part]
|
|
410
|
+
end
|
|
411
|
+
op = tokens[0][0]
|
|
412
|
+
total += 1
|
|
413
|
+
tokens = tokens[1..-1]
|
|
414
|
+
res = self.parse_factor tokens
|
|
415
|
+
unless res
|
|
371
416
|
return nil
|
|
372
417
|
end
|
|
418
|
+
rhs, part = res
|
|
419
|
+
total += part
|
|
420
|
+
tokens = tokens[part..-1]
|
|
421
|
+
out = (Node.new :op, op, [lhs])
|
|
422
|
+
while self.expect tokens, :l2op
|
|
423
|
+
op = tokens[0][0]
|
|
424
|
+
total += 1
|
|
425
|
+
tokens = tokens[1..-1]
|
|
426
|
+
res = self.parse_term tokens
|
|
427
|
+
unless res
|
|
428
|
+
return nil
|
|
429
|
+
end
|
|
430
|
+
rhs2, part = res
|
|
431
|
+
total += part
|
|
432
|
+
tokens = tokens[part..-1]
|
|
433
|
+
rhs = Node.new :op, op, [rhs, rhs2]
|
|
434
|
+
end
|
|
435
|
+
out.children << rhs
|
|
436
|
+
[out, total]
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
def self.parse_op(tokens)
|
|
440
|
+
total = 0
|
|
441
|
+
res = self.parse_term tokens
|
|
442
|
+
unless res
|
|
443
|
+
return nil
|
|
444
|
+
end
|
|
445
|
+
lhs, part = res
|
|
446
|
+
total += part
|
|
447
|
+
tokens = tokens[part..-1]
|
|
448
|
+
unless self.expect tokens, :l1op
|
|
449
|
+
return [lhs, part]
|
|
450
|
+
end
|
|
373
451
|
op = tokens[0][0]
|
|
374
452
|
total += 1
|
|
375
|
-
tokens = tokens[1
|
|
376
|
-
|
|
453
|
+
tokens = tokens[1..-1]
|
|
454
|
+
res = self.parse_term tokens
|
|
455
|
+
unless res
|
|
377
456
|
return nil
|
|
378
457
|
end
|
|
379
|
-
rhs, part =
|
|
458
|
+
rhs, part = res
|
|
380
459
|
total += part
|
|
381
|
-
|
|
460
|
+
tokens = tokens[part..-1]
|
|
461
|
+
out = (Node.new :op, op, [lhs])
|
|
462
|
+
while self.expect tokens, :l1op
|
|
463
|
+
op = tokens[0][0]
|
|
464
|
+
total += 1
|
|
465
|
+
tokens = tokens[1..-1]
|
|
466
|
+
res = self.parse_term tokens
|
|
467
|
+
unless res
|
|
468
|
+
return nil
|
|
469
|
+
end
|
|
470
|
+
rhs2, part = res
|
|
471
|
+
total += part
|
|
472
|
+
tokens = tokens[part..-1]
|
|
473
|
+
rhs = Node.new :op, op, [rhs, rhs2]
|
|
474
|
+
end
|
|
475
|
+
out.children << rhs
|
|
476
|
+
[out, total]
|
|
382
477
|
end
|
|
383
478
|
|
|
384
479
|
def self.parse_assign(tokens)
|
|
@@ -388,19 +483,20 @@ module Parser
|
|
|
388
483
|
end
|
|
389
484
|
name = tokens[0][0]
|
|
390
485
|
total += 1
|
|
391
|
-
tokens = tokens[1
|
|
486
|
+
tokens = tokens[1..-1]
|
|
392
487
|
unless self.expect tokens, :eq
|
|
393
488
|
return nil
|
|
394
489
|
end
|
|
395
490
|
eq = tokens[0][0]
|
|
396
491
|
total += 1
|
|
397
|
-
tokens = tokens[1
|
|
398
|
-
|
|
492
|
+
tokens = tokens[1..-1]
|
|
493
|
+
res = self.parse_expr tokens
|
|
494
|
+
unless res
|
|
399
495
|
return nil
|
|
400
496
|
end
|
|
401
|
-
rhs, part =
|
|
497
|
+
rhs, part = res
|
|
402
498
|
total += part
|
|
403
|
-
|
|
499
|
+
[ (Node.new :assign, eq, [name, rhs]), total]
|
|
404
500
|
end
|
|
405
501
|
|
|
406
502
|
def self.parse_fn(tokens)
|
|
@@ -408,23 +504,23 @@ module Parser
|
|
|
408
504
|
return nil
|
|
409
505
|
end
|
|
410
506
|
total = 1
|
|
411
|
-
tokens = tokens[1
|
|
507
|
+
tokens = tokens[1..-1]
|
|
412
508
|
unless self.expect tokens, :name
|
|
413
509
|
return nil
|
|
414
510
|
end
|
|
415
511
|
name = tokens[0][0]
|
|
416
512
|
total += 1
|
|
417
|
-
tokens = tokens[1
|
|
513
|
+
tokens = tokens[1..-1]
|
|
418
514
|
unless self.expect tokens, :lpar
|
|
419
515
|
return nil
|
|
420
516
|
end
|
|
421
517
|
total += 1
|
|
422
|
-
tokens = tokens[1
|
|
518
|
+
tokens = tokens[1..-1]
|
|
423
519
|
args = []
|
|
424
520
|
while true
|
|
425
521
|
if self.expect tokens, :rpar
|
|
426
522
|
total += 1
|
|
427
|
-
tokens = tokens[1
|
|
523
|
+
tokens = tokens[1..-1]
|
|
428
524
|
break
|
|
429
525
|
end
|
|
430
526
|
unless self.expect tokens, :name
|
|
@@ -432,24 +528,25 @@ module Parser
|
|
|
432
528
|
end
|
|
433
529
|
args << tokens[0][0]
|
|
434
530
|
total += 1
|
|
435
|
-
tokens = tokens[1
|
|
531
|
+
tokens = tokens[1..-1]
|
|
436
532
|
if self.expect tokens, :rpar
|
|
437
533
|
total += 1
|
|
438
|
-
tokens = tokens[1
|
|
534
|
+
tokens = tokens[1..-1]
|
|
439
535
|
break
|
|
440
536
|
end
|
|
441
537
|
unless self.expect tokens, :comma
|
|
442
538
|
return nil
|
|
443
539
|
end
|
|
444
540
|
total += 1
|
|
445
|
-
tokens = tokens[1
|
|
541
|
+
tokens = tokens[1..-1]
|
|
446
542
|
end
|
|
447
|
-
|
|
543
|
+
res = self.parse_expr tokens
|
|
544
|
+
unless res
|
|
448
545
|
return nil
|
|
449
546
|
end
|
|
450
|
-
body, part =
|
|
547
|
+
body, part = res
|
|
451
548
|
total += part
|
|
452
|
-
|
|
549
|
+
[ (Node.new :fn, name, [args, body]), total ]
|
|
453
550
|
end
|
|
454
551
|
|
|
455
552
|
def self.parse_object(tokens)
|
|
@@ -457,21 +554,21 @@ module Parser
|
|
|
457
554
|
return nil
|
|
458
555
|
end
|
|
459
556
|
total = 1
|
|
460
|
-
tokens = tokens[1
|
|
557
|
+
tokens = tokens[1..-1]
|
|
461
558
|
unless self.expect tokens, :name
|
|
462
559
|
return nil
|
|
463
560
|
end
|
|
464
561
|
name = tokens[0][0]
|
|
465
562
|
total += 1
|
|
466
|
-
tokens = tokens[1
|
|
563
|
+
tokens = tokens[1..-1]
|
|
467
564
|
args = []
|
|
468
565
|
if self.expect tokens, :lpar
|
|
469
566
|
total += 1
|
|
470
|
-
tokens = tokens[1
|
|
567
|
+
tokens = tokens[1..-1]
|
|
471
568
|
while true
|
|
472
569
|
if self.expect tokens, :rpar
|
|
473
570
|
total += 1
|
|
474
|
-
tokens = tokens[1
|
|
571
|
+
tokens = tokens[1..-1]
|
|
475
572
|
break
|
|
476
573
|
end
|
|
477
574
|
unless self.expect tokens, :name
|
|
@@ -479,40 +576,51 @@ module Parser
|
|
|
479
576
|
end
|
|
480
577
|
args << tokens[0][0]
|
|
481
578
|
total += 1
|
|
482
|
-
tokens = tokens[1
|
|
579
|
+
tokens = tokens[1..-1]
|
|
483
580
|
if self.expect tokens, :rpar
|
|
484
581
|
total += 1
|
|
485
|
-
tokens = tokens[1
|
|
582
|
+
tokens = tokens[1..-1]
|
|
486
583
|
break
|
|
487
584
|
end
|
|
488
585
|
unless self.expect tokens, :comma
|
|
489
586
|
return nil
|
|
490
587
|
end
|
|
491
588
|
total += 1
|
|
492
|
-
tokens = tokens[1
|
|
589
|
+
tokens = tokens[1..-1]
|
|
493
590
|
end
|
|
494
591
|
end
|
|
495
|
-
|
|
592
|
+
res = self.parse_expr tokens
|
|
593
|
+
unless res
|
|
496
594
|
return nil
|
|
497
595
|
end
|
|
498
|
-
body, part =
|
|
596
|
+
body, part = res
|
|
499
597
|
total += part
|
|
500
|
-
|
|
598
|
+
[ (Node.new :object, name, [args, body]), total ]
|
|
501
599
|
end
|
|
502
600
|
|
|
503
601
|
def self.parse_require(tokens)
|
|
504
602
|
unless self.expect tokens, :require
|
|
505
603
|
return nil
|
|
506
604
|
end
|
|
507
|
-
tokens = tokens[1
|
|
605
|
+
tokens = tokens[1..-1]
|
|
508
606
|
unless self.expect tokens, :string
|
|
509
607
|
return nil
|
|
510
608
|
end
|
|
511
|
-
|
|
609
|
+
[ (Node.new :require, tokens[0][0][1..-2], []), 2 ]
|
|
512
610
|
end
|
|
513
611
|
|
|
514
612
|
def self.parse_expr(tokens)
|
|
515
|
-
(self.
|
|
613
|
+
(self.parse_op tokens) ||
|
|
614
|
+
(self.parse_call tokens) ||
|
|
615
|
+
(self.parse_require tokens) ||
|
|
616
|
+
(self.parse_new tokens) ||
|
|
617
|
+
(self.parse_object tokens) ||
|
|
618
|
+
(self.parse_fn tokens) ||
|
|
619
|
+
(self.parse_assign tokens) ||
|
|
620
|
+
(self.parse_literal tokens) ||
|
|
621
|
+
(self.parse_if tokens) ||
|
|
622
|
+
(self.parse_while tokens) ||
|
|
623
|
+
(self.parse_for tokens)
|
|
516
624
|
end
|
|
517
625
|
|
|
518
626
|
def self.parse(tokens, path)
|
|
@@ -539,7 +647,7 @@ module Parser
|
|
|
539
647
|
else
|
|
540
648
|
parsed << e[0]
|
|
541
649
|
end
|
|
542
|
-
tokens = tokens[e[1]
|
|
650
|
+
tokens = tokens[e[1]..-1]
|
|
543
651
|
else
|
|
544
652
|
puts "Syntax error at token ", tokens[0][1]
|
|
545
653
|
Kernel.exit 1
|
data/lib/sdx/vm/datatypes.rb
CHANGED
data/lib/sdx/vm/vm.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require 'sdx/vm/variables'
|
|
2
|
-
require 'sdx/vm/datatypes'
|
|
3
|
-
require 'sdx/vm/scope'
|
|
1
|
+
require './lib/sdx/vm/variables'
|
|
2
|
+
require './lib/sdx/vm/datatypes'
|
|
3
|
+
require './lib/sdx/vm/scope'
|
|
4
4
|
|
|
5
5
|
def codify(val)
|
|
6
6
|
if val.value.fields["__as_code_string"]
|
|
@@ -165,7 +165,8 @@ class VM
|
|
|
165
165
|
0x36 => :lt,
|
|
166
166
|
0x37 => :gt,
|
|
167
167
|
0x38 => :le,
|
|
168
|
-
0x39 => :ge
|
|
168
|
+
0x39 => :ge,
|
|
169
|
+
0x28 => :pow,
|
|
169
170
|
}
|
|
170
171
|
bytes = []
|
|
171
172
|
begin
|