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/defn_spec.rb ADDED
@@ -0,0 +1,732 @@
1
+ describe "A Defn node" do
2
+ relates <<-ruby do
3
+ def m
4
+ begin
5
+ end
6
+ end
7
+ ruby
8
+
9
+ compile do |g|
10
+ in_method :m do |d|
11
+ d.push :nil
12
+ end
13
+ end
14
+ end
15
+
16
+ relates <<-ruby do
17
+ def m
18
+ return :a
19
+ ensure
20
+ return :b
21
+ end
22
+ ruby
23
+
24
+ compile do |g|
25
+ in_method :m do |d|
26
+ ensure_exc_lbl = d.new_label
27
+ ensure_noexc_lbl = d.new_label
28
+
29
+ d.setup_unwind ensure_exc_lbl
30
+
31
+ d.new_label.set!
32
+ exc = d.save_exception
33
+
34
+ d.push_literal :a
35
+ d.ensure_return
36
+ d.pop_unwind
37
+ d.goto ensure_noexc_lbl
38
+
39
+ ensure_exc_lbl.set!
40
+ d.push_exception_state
41
+ d.push_literal :b
42
+
43
+ d.restore_exception exc
44
+
45
+ d.ret
46
+ d.pop
47
+ d.restore_exception_state
48
+ d.reraise
49
+
50
+ ensure_noexc_lbl.set!
51
+ d.push_literal :b
52
+ d.ret
53
+ d.pop
54
+ end
55
+ end
56
+ end
57
+
58
+ relates <<-ruby do
59
+ def blah(*args, &block)
60
+ other(42, *args, &block)
61
+ end
62
+ ruby
63
+
64
+ compile do |g|
65
+ in_method :blah do |d|
66
+ no_proc = d.new_label
67
+ no_splat = d.new_label
68
+
69
+ d.push_proc
70
+ d.set_local 1
71
+ d.pop
72
+
73
+ d.push :self
74
+ d.push 42 # only line different from block_pass_splat
75
+ d.push_local 0
76
+ d.cast_array
77
+ d.push_local 1
78
+ d.dup
79
+ d.is_nil
80
+ d.git no_splat
81
+
82
+ d.push_cpath_top
83
+ d.find_const :Proc
84
+ d.swap
85
+ d.send :__from_block__, 1
86
+
87
+ no_splat.set!
88
+
89
+ d.send_with_splat :other, 1, true, false # ok, and this one
90
+ end
91
+ end
92
+ end
93
+
94
+ relates <<-ruby do
95
+ def blah(*args, &block)
96
+ other(*args, &block)
97
+ end
98
+ ruby
99
+
100
+ compile do |g|
101
+ g.in_method :blah do |d|
102
+ no_proc = d.new_label
103
+ no_splat = d.new_label
104
+
105
+ d.push_proc
106
+ d.set_local 1
107
+ d.pop
108
+
109
+ d.push :self
110
+ d.push_local 0
111
+ d.cast_array
112
+ d.push_local 1
113
+ d.dup
114
+ d.is_nil
115
+ d.git no_splat
116
+
117
+ d.push_cpath_top
118
+ d.find_const :Proc # FIX: why push_cpath/find vs push_const ?
119
+ d.swap
120
+ d.send :__from_block__, 1
121
+
122
+ no_splat.set!
123
+
124
+ d.send_with_splat :other, 0, true, false
125
+ end
126
+ end
127
+ end
128
+
129
+ relates <<-ruby do
130
+ def f
131
+ begin
132
+ b
133
+ rescue
134
+ c
135
+ end
136
+
137
+ d
138
+ end
139
+ ruby
140
+
141
+ compile do |g|
142
+ in_method :f do |d|
143
+
144
+ d.for_rescue do |rb|
145
+ rb.body do
146
+ d.push :self
147
+ d.send :b, 0, true
148
+ end
149
+
150
+ rb.condition :StandardError, true do
151
+ d.push :self
152
+ d.send :c, 0, true
153
+ end
154
+ end
155
+
156
+ d.pop
157
+
158
+ d.push :self
159
+ d.send :d, 0, true
160
+ end
161
+ end
162
+ end
163
+
164
+ relates <<-ruby do
165
+ def f
166
+ a
167
+ begin
168
+ b
169
+ rescue
170
+ c
171
+ end
172
+ end
173
+ ruby
174
+
175
+ compile do |g|
176
+ in_method :f do |d|
177
+ d.push :self
178
+ d.send :a, 0, true
179
+ d.pop
180
+
181
+ d.for_rescue do |rb|
182
+ rb.body do
183
+ d.push :self
184
+ d.send :b, 0, true
185
+ end
186
+
187
+ rb.condition :StandardError, true do
188
+ d.push :self
189
+ d.send :c, 0, true
190
+ end
191
+ end
192
+
193
+ end
194
+ end
195
+ end
196
+
197
+ relates <<-ruby do
198
+ def f
199
+ a
200
+ begin
201
+ b
202
+ rescue
203
+ c
204
+ end
205
+ d
206
+ end
207
+ ruby
208
+
209
+ compile do |g|
210
+ in_method :f do |d|
211
+ d.push :self
212
+ d.send :a, 0, true
213
+ d.pop
214
+
215
+ d.for_rescue do |rb|
216
+ rb.body do
217
+ d.push :self
218
+ d.send :b, 0, true
219
+ end
220
+
221
+ rb.condition :StandardError, true do
222
+ d.push :self
223
+ d.send :c, 0, true
224
+ end
225
+ end
226
+
227
+ d.pop
228
+
229
+ d.push :self
230
+ d.send :d, 0, true
231
+ end
232
+ end
233
+ end
234
+
235
+ relates <<-ruby do
236
+ def f(&block)
237
+ end
238
+ ruby
239
+
240
+ compile do |g|
241
+ in_method :f do |d|
242
+ d.block_arg 0
243
+ d.push :nil
244
+ end
245
+ end
246
+ end
247
+
248
+ relates <<-ruby do
249
+ def f(mand, opt = 42, &block)
250
+ end
251
+ ruby
252
+
253
+ compile do |g|
254
+ in_method :f do |d|
255
+ d.optional_arg 1
256
+ d.block_arg 2
257
+ d.push :nil
258
+ end
259
+ end
260
+ end
261
+
262
+ relates <<-ruby do
263
+ def f(x, a=x.b)
264
+ end
265
+ ruby
266
+
267
+ compile do |g|
268
+ in_method :f do |d|
269
+ if_set = d.new_label
270
+ d.passed_arg 1
271
+ d.git if_set
272
+ d.push_local 0
273
+ d.send :b, 0, false
274
+ d.set_local 1
275
+ d.pop
276
+ if_set.set!
277
+ d.push :nil
278
+ end
279
+ end
280
+ end
281
+
282
+ relates <<-ruby do
283
+ def f(mand, &block)
284
+ end
285
+ ruby
286
+
287
+ compile do |g|
288
+ in_method :f do |d|
289
+ d.block_arg 1
290
+ d.push :nil
291
+ end
292
+ end
293
+ end
294
+
295
+ relates <<-ruby do
296
+ def f(mand, opt = 42)
297
+ end
298
+ ruby
299
+
300
+ compile do |g|
301
+ in_method :f do |d|
302
+ d.optional_arg 1
303
+ d.push :nil
304
+ end
305
+ end
306
+ end
307
+
308
+ relates <<-ruby do
309
+ def f(mand, opt = 42, *rest, &block)
310
+ end
311
+ ruby
312
+
313
+ compile do |g|
314
+ in_method :f do |d|
315
+ d.optional_arg 1
316
+ d.block_arg 3
317
+ d.push :nil
318
+ end
319
+ end
320
+ end
321
+
322
+ relates <<-ruby do
323
+ def x(a, b = 42, *)
324
+ end
325
+ ruby
326
+
327
+ compile do |g|
328
+ in_method :x do |d|
329
+ d.optional_arg 1
330
+ d.push :nil
331
+ end
332
+ end
333
+ end
334
+
335
+ relates <<-ruby do
336
+ def f(mand, opt = 42, *rest)
337
+ end
338
+ ruby
339
+
340
+ compile do |g|
341
+ in_method :f do |d|
342
+ d.optional_arg 1
343
+ d.push :nil
344
+ end
345
+ end
346
+ end
347
+
348
+ relates <<-ruby do
349
+ def empty
350
+ end
351
+ ruby
352
+
353
+ compile do |g|
354
+ in_method :empty do |d|
355
+ d.push :nil
356
+ end
357
+ end
358
+ end
359
+
360
+ relates <<-ruby do
361
+ def f(mand)
362
+ end
363
+ ruby
364
+
365
+ compile do |g|
366
+ in_method :f do |d|
367
+ d.push :nil
368
+ end
369
+ end
370
+ end
371
+
372
+ relates <<-ruby do
373
+ def f(mand, *rest, &block)
374
+ end
375
+ ruby
376
+
377
+ compile do |g|
378
+ in_method :f do |d|
379
+ d.block_arg 2
380
+ d.push :nil
381
+ end
382
+ end
383
+ end
384
+
385
+ relates <<-ruby do
386
+ def x(a, *args)
387
+ p(a, args)
388
+ end
389
+ ruby
390
+
391
+ compile do |g|
392
+ in_method :x do |d|
393
+ d.push :self
394
+ d.push_local 0
395
+ d.push_local 1
396
+ d.send :p, 2, true
397
+ end
398
+ end
399
+ end
400
+
401
+ relates <<-ruby do
402
+ def f(mand, *rest)
403
+ end
404
+ ruby
405
+
406
+ compile do |g|
407
+ in_method :f do |d|
408
+ d.push :nil
409
+ end
410
+ end
411
+ end
412
+
413
+ relates <<-ruby do
414
+ def f(opt = 42, &block)
415
+ end
416
+ ruby
417
+
418
+ compile do |g|
419
+ in_method :f do |d|
420
+ d.optional_arg 0
421
+ d.block_arg 1
422
+ d.push :nil
423
+ end
424
+ end
425
+ end
426
+
427
+ relates <<-ruby do
428
+ def f(a = 42, b = '1', c=lambda {|n| n })
429
+ end
430
+ ruby
431
+
432
+ # defn args opt lambda
433
+ end
434
+
435
+ relates <<-ruby do
436
+ def f(opt = 42)
437
+ end
438
+ ruby
439
+
440
+ compile do |g|
441
+ in_method :f do |d|
442
+ d.optional_arg 0
443
+ d.push :nil
444
+ end
445
+ end
446
+ end
447
+
448
+ relates <<-ruby do
449
+ def f(opt = 42, *rest, &block)
450
+ end
451
+ ruby
452
+
453
+ compile do |g|
454
+ in_method :f do |d|
455
+ d.optional_arg 0
456
+ d.block_arg 2
457
+ d.push :nil
458
+ end
459
+ end
460
+ end
461
+
462
+ relates <<-ruby do
463
+ def x(b = 42, *)
464
+ end
465
+ ruby
466
+
467
+ compile do |g|
468
+ in_method :x do |d|
469
+ d.optional_arg 0
470
+ d.push :nil
471
+ end
472
+ end
473
+ end
474
+
475
+ relates <<-ruby do
476
+ def f(opt = 42, *rest)
477
+ end
478
+ ruby
479
+
480
+ compile do |g|
481
+ in_method :f do |d|
482
+ d.optional_arg 0
483
+ d.push :nil
484
+ end
485
+ end
486
+ end
487
+
488
+ relates <<-ruby do
489
+ def |(o)
490
+ end
491
+ ruby
492
+
493
+ compile do |g|
494
+ in_method :"|" do |d|
495
+ d.push :nil
496
+ end
497
+ end
498
+ end
499
+
500
+ relates <<-ruby do
501
+ def eql?(resource)
502
+ (self.uuid == resource.uuid)
503
+ rescue
504
+ false
505
+ end
506
+ ruby
507
+
508
+ compile do |g|
509
+ in_method :eql? do |d|
510
+
511
+ d.for_rescue do |rb|
512
+ rb.body do
513
+ d.push :self
514
+ d.send :uuid, 0, false
515
+ d.push_local 0
516
+ d.send :uuid, 0, false
517
+ d.send :==, 1, false
518
+ end
519
+
520
+ rb.condition :StandardError, true do
521
+ d.push :false
522
+ end
523
+ end
524
+ end
525
+ end
526
+ end
527
+
528
+ relates <<-ruby do
529
+ def something?
530
+ end
531
+ ruby
532
+
533
+ compile do |g|
534
+ in_method :something? do |d|
535
+ d.push :nil
536
+ end
537
+ end
538
+ end
539
+
540
+ relates <<-ruby do
541
+ def x(*)
542
+ end
543
+ ruby
544
+
545
+ compile do |g|
546
+ in_method :x do |d|
547
+ d.push :nil
548
+ end
549
+ end
550
+ end
551
+
552
+ relates <<-ruby do
553
+ def f(*rest)
554
+ end
555
+ ruby
556
+
557
+ compile do |g|
558
+ in_method :f do |d|
559
+ d.push :nil
560
+ end
561
+ end
562
+ end
563
+
564
+ relates <<-ruby do
565
+ def x(a, *)
566
+ p(a)
567
+ end
568
+ ruby
569
+
570
+ compile do |g|
571
+ in_method :x do |d|
572
+ d.push :self
573
+ d.push_local 0
574
+ d.send :p, 1, true
575
+ end
576
+ end
577
+ end
578
+
579
+ relates <<-ruby do
580
+ def zarray
581
+ a = []
582
+ return a
583
+ end
584
+ ruby
585
+
586
+ compile do |g|
587
+ in_method :zarray do |d|
588
+ d.make_array 0
589
+ d.set_local 0
590
+ d.pop
591
+ d.push_local 0
592
+ # TODO we emit a ret instruction even though the last statement
593
+ # is itself a return, so we get to return instructions, one
594
+ # after another. We could instead detect that an only output
595
+ # the one.
596
+ d.ret
597
+ end
598
+ end
599
+ end
600
+
601
+ relates <<-ruby do
602
+ b = 42
603
+ def a
604
+ c do
605
+ begin
606
+ do_stuff
607
+ rescue RuntimeError => b
608
+ puts(b)
609
+ end
610
+ end
611
+ end
612
+ ruby
613
+
614
+ compile do |g|
615
+ g.push 42
616
+ g.set_local 0
617
+ g.pop
618
+
619
+ g.in_method :a do |d|
620
+ d.push :self
621
+
622
+ d.in_block_send :c, 0 do |d2|
623
+
624
+ d2.for_rescue do |rb|
625
+ rb.body do
626
+ d2.push :self
627
+ d2.send :do_stuff, 0, true
628
+ end
629
+
630
+ rb.condition :RuntimeError do
631
+ d2.push_current_exception
632
+ d2.set_local 0
633
+ d2.pop
634
+ d2.push :self
635
+ d2.push_local 0
636
+ d2.send :puts, 1, true
637
+ end
638
+ end
639
+ end
640
+ end
641
+ end
642
+ end
643
+
644
+ relates <<-ruby do
645
+ def x(a=0.0,b=0.0)
646
+ a+b
647
+ end
648
+ ruby
649
+
650
+ compile do |g|
651
+ in_method :x do |d|
652
+ opt_arg_1 = d.new_label
653
+ opt_arg_2 = d.new_label
654
+
655
+ d.passed_arg 0
656
+ d.git opt_arg_1
657
+ d.push_literal 0.0
658
+ d.set_local 0
659
+ d.pop
660
+
661
+ opt_arg_1.set!
662
+
663
+ d.passed_arg 1
664
+ d.git opt_arg_2
665
+ d.push_literal 0.0
666
+ d.set_local 1
667
+ d.pop
668
+
669
+ opt_arg_2.set!
670
+
671
+ d.push_local 0
672
+ d.push_local 1
673
+ d.send :+, 1, false
674
+ end
675
+ end
676
+ end
677
+
678
+ relates <<-ruby do
679
+ def x(*b)
680
+ a(*b)
681
+ end
682
+ ruby
683
+
684
+ compile do |g|
685
+ in_method :x do |d|
686
+ d.push :self
687
+ d.push_local 0
688
+ d.cast_array
689
+ d.push :nil
690
+ d.send_with_splat :a, 0, true, false
691
+ end
692
+ end
693
+ end
694
+
695
+ relates <<-ruby do
696
+ def meth(b)
697
+ b
698
+ end
699
+ ruby
700
+
701
+ compile do |g|
702
+ in_method :meth do |d|
703
+ d.push_local 0
704
+ end
705
+ end
706
+ end
707
+
708
+ ruby_version_is "1.9" do
709
+ relates "(not true)" do
710
+ compile do |g|
711
+ g.push :true
712
+ g.send :"!", 0, false
713
+ end
714
+ end
715
+
716
+ relates <<-ruby do
717
+ a = 1
718
+ b = !a
719
+ ruby
720
+
721
+ compile do |g|
722
+ g.push 1
723
+ g.set_local 0
724
+ g.pop
725
+
726
+ g.push_local 0
727
+ g.send :"!", 0, false
728
+ g.set_local 1
729
+ end
730
+ end
731
+ end
732
+ end