rubinius-compiler 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -0
  3. data/lib/rubinius/compiler/compiled_file.rb +32 -32
  4. data/lib/rubinius/compiler/version.rb +2 -2
  5. data/rubinius-compiler.gemspec +6 -0
  6. data/spec/alias_spec.rb +39 -0
  7. data/spec/and_spec.rb +44 -0
  8. data/spec/array_spec.rb +110 -0
  9. data/spec/attrasgn_spec.rb +186 -0
  10. data/spec/back_ref_spec.rb +11 -0
  11. data/spec/call_spec.rb +580 -0
  12. data/spec/case_spec.rb +576 -0
  13. data/spec/cdecl_spec.rb +70 -0
  14. data/spec/class_spec.rb +120 -0
  15. data/spec/colon2_spec.rb +8 -0
  16. data/spec/colon3_spec.rb +8 -0
  17. data/spec/const_spec.rb +7 -0
  18. data/spec/custom/guards/profiler.rb +18 -0
  19. data/spec/custom/helpers/generator.rb +828 -0
  20. data/spec/custom/matchers/compile_as.rb +46 -0
  21. data/spec/custom/mspec.rb +15 -0
  22. data/spec/custom/runner/actions/debug.rb +10 -0
  23. data/spec/custom/runner/actions/gcstats.rb +17 -0
  24. data/spec/custom/runner/actions/memory.rb +11 -0
  25. data/spec/custom/runner/actions/parser.rb +14 -0
  26. data/spec/custom/runner/actions/profiler.rb +19 -0
  27. data/spec/custom/runner/relates.rb +86 -0
  28. data/spec/custom/utils/options.rb +40 -0
  29. data/spec/custom/utils/script.rb +50 -0
  30. data/spec/cvar_spec.rb +39 -0
  31. data/spec/cvasgn_spec.rb +33 -0
  32. data/spec/cvdecl_spec.rb +17 -0
  33. data/spec/defined_spec.rb +616 -0
  34. data/spec/defn_spec.rb +732 -0
  35. data/spec/defs_spec.rb +113 -0
  36. data/spec/dot2_spec.rb +16 -0
  37. data/spec/dot3_spec.rb +17 -0
  38. data/spec/dregx_spec.rb +160 -0
  39. data/spec/dstr_spec.rb +424 -0
  40. data/spec/dsym_spec.rb +18 -0
  41. data/spec/dxstr_spec.rb +24 -0
  42. data/spec/ensure_spec.rb +196 -0
  43. data/spec/false_spec.rb +7 -0
  44. data/spec/flip2_spec.rb +21 -0
  45. data/spec/flip3_spec.rb +12 -0
  46. data/spec/for_spec.rb +228 -0
  47. data/spec/gasgn_spec.rb +15 -0
  48. data/spec/generator/encode_spec.rb +34 -0
  49. data/spec/gvar_spec.rb +37 -0
  50. data/spec/hash_spec.rb +108 -0
  51. data/spec/iasgn_spec.rb +26 -0
  52. data/spec/if_spec.rb +415 -0
  53. data/spec/iter_spec.rb +1011 -0
  54. data/spec/lasgn_spec.rb +561 -0
  55. data/spec/lit_spec.rb +61 -0
  56. data/spec/masgn_spec.rb +1558 -0
  57. data/spec/match2_spec.rb +42 -0
  58. data/spec/match3_spec.rb +54 -0
  59. data/spec/match_spec.rb +29 -0
  60. data/spec/module_spec.rb +73 -0
  61. data/spec/nil_spec.rb +7 -0
  62. data/spec/not_spec.rb +47 -0
  63. data/spec/nth_ref_spec.rb +7 -0
  64. data/spec/op_asgn_spec.rb +563 -0
  65. data/spec/or_spec.rb +126 -0
  66. data/spec/postexe_spec.rb +11 -0
  67. data/spec/preexe_spec.rb +21 -0
  68. data/spec/regex_spec.rb +54 -0
  69. data/spec/rescue_spec.rb +763 -0
  70. data/spec/return_spec.rb +152 -0
  71. data/spec/sclass_spec.rb +138 -0
  72. data/spec/spec_helper.rb +12 -0
  73. data/spec/str_spec.rb +118 -0
  74. data/spec/super_spec.rb +170 -0
  75. data/spec/transforms/assembly_spec.rb +195 -0
  76. data/spec/transforms/block_given_spec.rb +75 -0
  77. data/spec/transforms/fast_coerce_spec.rb +112 -0
  78. data/spec/transforms/fast_new_spec.rb +255 -0
  79. data/spec/transforms/invoke_primitive_spec.rb +14 -0
  80. data/spec/transforms/kernel_methods_spec.rb +29 -0
  81. data/spec/transforms/primitive_spec.rb +33 -0
  82. data/spec/transforms/privately_spec.rb +24 -0
  83. data/spec/true_spec.rb +7 -0
  84. data/spec/undef_spec.rb +133 -0
  85. data/spec/until_spec.rb +254 -0
  86. data/spec/valias_spec.rb +11 -0
  87. data/spec/while_spec.rb +494 -0
  88. data/spec/xstr_spec.rb +10 -0
  89. data/spec/yield_spec.rb +92 -0
  90. data/spec/zsuper_spec.rb +63 -0
  91. metadata +258 -3
data/spec/case_spec.rb ADDED
@@ -0,0 +1,576 @@
1
+ describe "A Case node" do
2
+ relates <<-ruby do
3
+ var = 2
4
+ result = ""
5
+ case var
6
+ when 1 then
7
+ puts("something")
8
+ result = "red"
9
+ when 2, 3 then
10
+ result = "yellow"
11
+ when 4 then
12
+ # do nothing
13
+ else
14
+ result = "green"
15
+ end
16
+ case result
17
+ when "red" then
18
+ var = 1
19
+ when "yellow" then
20
+ var = 2
21
+ when "green" then
22
+ var = 3
23
+ else
24
+ # do nothing
25
+ end
26
+ ruby
27
+
28
+ compile do |g|
29
+ a1 = g.new_label
30
+ a2 = g.new_label
31
+ a3 = g.new_label
32
+ a4 = g.new_label
33
+ a_bottom = g.new_label
34
+
35
+ g.push 2
36
+ g.set_local 0
37
+ g.pop
38
+ g.push_literal ""
39
+ g.string_dup
40
+ g.set_local 1
41
+ g.pop
42
+
43
+ g.push_local 0
44
+ g.dup
45
+ g.push 1
46
+ g.swap
47
+ g.send :===, 1
48
+ g.gif a1
49
+
50
+ g.pop
51
+ g.push :self
52
+ g.push_literal "something"
53
+ g.string_dup
54
+ g.send :puts, 1, true
55
+ g.pop
56
+ g.push_literal "red"
57
+ g.string_dup
58
+ g.set_local 1
59
+ g.goto a_bottom
60
+
61
+ a1.set!
62
+
63
+ g.dup
64
+ g.push 2
65
+ g.swap
66
+ g.send :===, 1
67
+ g.git a2
68
+
69
+ g.dup
70
+ g.push 3
71
+ g.swap
72
+ g.send :===, 1
73
+ g.git a2
74
+ g.goto a3
75
+
76
+ a2.set!
77
+
78
+ g.pop
79
+ g.push_literal "yellow"
80
+ g.string_dup
81
+ g.set_local 1
82
+ g.goto a_bottom
83
+
84
+ a3.set!
85
+
86
+ g.dup
87
+ g.push 4
88
+ g.swap
89
+ g.send :===, 1
90
+ g.gif a4
91
+
92
+ g.pop
93
+ g.push :nil
94
+ g.goto a_bottom
95
+
96
+ a4.set!
97
+
98
+ g.pop
99
+ g.push_literal "green"
100
+ g.string_dup
101
+ g.set_local 1
102
+
103
+ a_bottom.set!
104
+
105
+ b1 = g.new_label
106
+ b2 = g.new_label
107
+ b3 = g.new_label
108
+ b_bottom = g.new_label
109
+
110
+ g.pop
111
+ g.push_local 1
112
+ g.dup
113
+ g.push_literal "red"
114
+ g.string_dup
115
+ g.swap
116
+ g.send :===, 1
117
+ g.gif b1
118
+
119
+ g.pop
120
+ g.push 1
121
+ g.set_local 0
122
+ g.goto b_bottom
123
+
124
+ b1.set!
125
+
126
+ g.dup
127
+ g.push_literal "yellow"
128
+ g.string_dup
129
+ g.swap
130
+ g.send :===, 1
131
+ g.gif b2
132
+
133
+ g.pop
134
+ g.push 2
135
+ g.set_local 0
136
+ g.goto b_bottom
137
+
138
+ b2.set!
139
+
140
+ g.dup
141
+ g.push_literal "green"
142
+ g.string_dup
143
+ g.swap
144
+ g.send :===, 1
145
+ g.gif b3
146
+
147
+ g.pop
148
+ g.push 3
149
+ g.set_local 0
150
+ g.goto b_bottom
151
+
152
+ b3.set!
153
+
154
+ g.pop
155
+ g.push :nil
156
+
157
+ b_bottom.set!
158
+ end
159
+ end
160
+
161
+ relates <<-ruby do
162
+ case a
163
+ when b then
164
+ case
165
+ when (d and e) then
166
+ f
167
+ else
168
+ # do nothing
169
+ end
170
+ else
171
+ # do nothing
172
+ end
173
+ ruby
174
+
175
+ compile do |g|
176
+ c2, bottom = g.new_label, g.new_label
177
+ i1, i2, ibottom = g.new_label, g.new_label, g.new_label
178
+
179
+ g.push :self
180
+ g.send :a, 0, true
181
+ g.dup
182
+ g.push :self
183
+ g.send :b, 0, true
184
+ g.swap
185
+ g.send :===, 1
186
+ g.gif c2
187
+
188
+ g.pop
189
+ g.push :self
190
+ g.send :d, 0, true
191
+ g.dup
192
+ g.gif i1 # TODO: lamest jump ever - should be ibottom
193
+
194
+ g.pop
195
+ g.push :self
196
+ g.send :e, 0, true
197
+
198
+ i1.set!
199
+
200
+ g.gif i2
201
+ g.push :self
202
+ g.send :f, 0, true
203
+
204
+ g.goto ibottom
205
+
206
+ i2.set!
207
+
208
+ g.push :nil
209
+
210
+ ibottom.set!
211
+
212
+ g.goto bottom
213
+
214
+ c2.set!
215
+ g.pop
216
+ g.push :nil
217
+
218
+ bottom.set!
219
+ end
220
+ end
221
+
222
+ relates <<-ruby do
223
+ var1 = 1
224
+ var2 = 2
225
+ result = nil
226
+ case var1
227
+ when 1 then
228
+ case var2
229
+ when 1 then
230
+ result = 1
231
+ when 2 then
232
+ result = 2
233
+ else
234
+ result = 3
235
+ end
236
+ when 2 then
237
+ case var2
238
+ when 1 then
239
+ result = 4
240
+ when 2 then
241
+ result = 5
242
+ else
243
+ result = 6
244
+ end
245
+ else
246
+ result = 7
247
+ end
248
+ ruby
249
+
250
+ compile do |g|
251
+ a2 = g.new_label
252
+ a3 = g.new_label
253
+ a_bottom = g.new_label
254
+
255
+ g.push 1
256
+ g.set_local 0
257
+ g.pop
258
+ g.push 2
259
+ g.set_local 1
260
+ g.pop
261
+ g.push :nil
262
+ g.set_local 2
263
+ g.pop
264
+
265
+ ########################################
266
+ b2 = g.new_label
267
+ b3 = g.new_label
268
+ b_bottom = g.new_label
269
+
270
+ g.push_local 0
271
+ g.dup
272
+ g.push 1
273
+ g.swap
274
+ g.send :===, 1
275
+ g.gif a2
276
+
277
+ g.pop
278
+ g.push_local 1
279
+ g.dup
280
+ g.push 1
281
+ g.swap
282
+ g.send :===, 1
283
+ g.gif b2
284
+
285
+ g.pop
286
+ g.push 1
287
+ g.set_local 2
288
+ g.goto b_bottom
289
+
290
+ b2.set!
291
+
292
+ g.dup
293
+ g.push 2
294
+ g.swap
295
+ g.send :===, 1
296
+ g.gif b3
297
+
298
+ g.pop
299
+ g.push 2
300
+ g.set_local 2
301
+ g.goto b_bottom
302
+
303
+ b3.set!
304
+
305
+ g.pop
306
+ g.push 3
307
+ g.set_local 2
308
+
309
+ b_bottom.set!
310
+
311
+ g.goto a_bottom
312
+
313
+ a2.set!
314
+
315
+ g.dup
316
+ g.push 2
317
+ g.swap
318
+ g.send :===, 1
319
+ g.gif a3
320
+
321
+ ########################################
322
+ c2 = g.new_label
323
+ c3 = g.new_label
324
+ c_bottom = g.new_label
325
+
326
+ g.pop
327
+ g.push_local 1
328
+ g.dup
329
+ g.push 1
330
+ g.swap
331
+ g.send :===, 1
332
+ g.gif c2
333
+
334
+ g.pop
335
+ g.push 4
336
+ g.set_local 2
337
+ g.goto c_bottom
338
+
339
+ c2.set!
340
+
341
+ g.dup
342
+ g.push 2
343
+ g.swap
344
+ g.send :===, 1
345
+ g.gif c3
346
+
347
+ g.pop
348
+ g.push 5
349
+ g.set_local 2
350
+ g.goto c_bottom
351
+
352
+ c3.set!
353
+
354
+ g.pop
355
+ g.push 6
356
+ g.set_local 2
357
+
358
+ c_bottom.set!
359
+
360
+ g.goto a_bottom
361
+
362
+ a3.set!
363
+
364
+ g.pop
365
+ g.push 7
366
+ g.set_local 2
367
+
368
+ a_bottom.set!
369
+ end
370
+ end
371
+
372
+ relates <<-ruby do
373
+ case
374
+ when (a == 1) then
375
+ :a
376
+ when (a == 2) then
377
+ :b
378
+ else
379
+ :c
380
+ end
381
+ ruby
382
+
383
+ compile do |g|
384
+ c2, c3, bottom = g.new_label, g.new_label, g.new_label
385
+
386
+ g.push :self
387
+ g.send :a, 0, true
388
+ g.push 1
389
+ g.send :==, 1, false
390
+ g.gif c2
391
+ g.push_literal :a
392
+ g.goto bottom
393
+
394
+ c2.set!
395
+
396
+ g.push :self
397
+ g.send :a, 0, true
398
+ g.push 2
399
+ g.send :==, 1, false
400
+ g.gif c3
401
+ g.push_literal :b
402
+ g.goto bottom
403
+
404
+ c3.set!
405
+ g.push_literal :c
406
+
407
+ bottom.set!
408
+ end
409
+ end
410
+
411
+ relates <<-ruby do
412
+ case a
413
+ when :b, *c then
414
+ d
415
+ else
416
+ e
417
+ end
418
+ ruby
419
+
420
+ compile do |g|
421
+ c1, c2, bottom = g.new_label, g.new_label, g.new_label
422
+
423
+ g.push :self
424
+ g.send :a, 0, true
425
+
426
+ g.dup
427
+ g.push_literal :b
428
+ g.swap
429
+ g.send :===, 1
430
+ g.git c1
431
+
432
+ g.dup
433
+ g.push :self
434
+ g.send :c, 0, true
435
+ g.cast_array
436
+ g.push_literal Rubinius::ToolSets::Spec::Compiler::Runtime
437
+ g.rotate(3)
438
+ g.send :matches_when, 2
439
+ g.git c1
440
+
441
+ g.goto c2
442
+
443
+ c1.set!
444
+
445
+ g.pop
446
+ g.push :self
447
+ g.send :d, 0, true
448
+ g.goto bottom
449
+
450
+ c2.set!
451
+
452
+ g.pop
453
+ g.push :self
454
+ g.send :e, 0, true
455
+
456
+ bottom.set!
457
+ end
458
+ end
459
+
460
+ relates <<-ruby do
461
+ case true
462
+ when String, *%w(foo bar baz) then
463
+ 12
464
+ end
465
+ ruby
466
+
467
+ compile do |g|
468
+ body = g.new_label
469
+ nxt = g.new_label
470
+ fin = g.new_label
471
+
472
+ g.push :true
473
+
474
+ g.dup
475
+ g.push_const :String
476
+ g.swap
477
+ g.send :===, 1
478
+ g.git body
479
+
480
+ g.dup
481
+ g.push_literal "foo"
482
+ g.string_dup
483
+ g.swap
484
+ g.send :===, 1
485
+ g.git body
486
+
487
+ g.dup
488
+ g.push_literal "bar"
489
+ g.string_dup
490
+ g.swap
491
+ g.send :===, 1
492
+ g.git body
493
+
494
+ g.dup
495
+ g.push_literal "baz"
496
+ g.string_dup
497
+ g.swap
498
+ g.send :===, 1
499
+ g.git body
500
+
501
+ g.goto nxt
502
+
503
+ body.set!
504
+ g.pop
505
+ g.push 12
506
+ g.goto fin
507
+
508
+ nxt.set!
509
+ g.pop
510
+ g.push :nil
511
+ fin.set!
512
+ end
513
+ end
514
+
515
+ relates <<-ruby do
516
+ case ()
517
+ when a
518
+ 1
519
+ end
520
+ ruby
521
+
522
+ compile do |g|
523
+ no_match = g.new_label
524
+ done = g.new_label
525
+
526
+ g.push :nil
527
+ g.dup
528
+ g.push :self
529
+ g.send :a, 0, true
530
+ g.swap
531
+ g.send :===, 1
532
+ g.gif no_match
533
+
534
+ g.pop
535
+ g.push 1
536
+ g.goto done
537
+
538
+ no_match.set!
539
+ g.pop
540
+ g.push :nil
541
+ done.set!
542
+ end
543
+ end
544
+
545
+ relates <<-ruby do
546
+ x = 1
547
+ case a
548
+ when x
549
+ 2
550
+ end
551
+ ruby
552
+
553
+ compile do |g|
554
+ no_match = g.new_label
555
+ done = g.new_label
556
+
557
+ g.push 1
558
+ g.set_local 0
559
+ g.pop
560
+ g.push :self
561
+ g.send :a, 0, true
562
+ g.dup
563
+ g.push_local 0
564
+ g.swap
565
+ g.send :===, 1
566
+ g.gif no_match
567
+ g.pop
568
+ g.push 2
569
+ g.goto done
570
+ no_match.set!
571
+ g.pop
572
+ g.push :nil
573
+ done.set!
574
+ end
575
+ end
576
+ end