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
@@ -0,0 +1,11 @@
1
+ describe "An Back_ref node" do
2
+ relates "[$&, $`, $', $+]" do
3
+ compile do |g|
4
+ g.last_match 1, 0
5
+ g.last_match 2, 0
6
+ g.last_match 3, 0
7
+ g.last_match 4, 0
8
+ g.make_array 4
9
+ end
10
+ end
11
+ end
data/spec/call_spec.rb ADDED
@@ -0,0 +1,580 @@
1
+ describe "A Call node" do
2
+ relates "self.method" do
3
+ compile do |g|
4
+ g.push :self
5
+ g.send :method, 0, false
6
+ end
7
+ end
8
+
9
+ relates "1.m(2)" do
10
+ compile do |g|
11
+ g.push 1
12
+ g.push 2
13
+ g.send :m, 1, false
14
+ end
15
+ end
16
+
17
+ relates "h(1, 2, *a)" do
18
+ compile do |g|
19
+ g.push :self
20
+ g.push 1
21
+ g.push 2
22
+ g.push :self
23
+ g.send :a, 0, true
24
+ g.cast_array
25
+
26
+ g.push :nil
27
+ g.send_with_splat :h, 2, true, false
28
+ end
29
+ end
30
+
31
+ relates <<-ruby do
32
+ begin
33
+ (1 + 1)
34
+ end
35
+ ruby
36
+
37
+ compile do |g|
38
+ g.push 1
39
+ g.push 1
40
+ g.send :+, 1, false
41
+ end
42
+ end
43
+
44
+ relates "blah(*a)" do
45
+ compile do |g|
46
+ g.push :self
47
+ g.push :self
48
+ g.send :a, 0, true
49
+ g.cast_array
50
+ g.push :nil
51
+ g.send_with_splat :blah, 0, true, false
52
+ end
53
+ end
54
+
55
+ relates "a.b(&c)" do
56
+ compile do |g|
57
+ t = g.new_label
58
+
59
+ g.push :self
60
+ g.send :a, 0, true
61
+ g.push :self
62
+ g.send :c, 0, true
63
+
64
+ g.dup
65
+ g.is_nil
66
+ g.git t
67
+
68
+ g.push_cpath_top
69
+ g.find_const :Proc
70
+ g.swap
71
+ g.send :__from_block__, 1
72
+
73
+ t.set!
74
+
75
+ g.send_with_block :b, 0, false
76
+ end
77
+ end
78
+
79
+ relates "a.b(4, &c)" do
80
+ compile do |g|
81
+ t = g.new_label
82
+
83
+ g.push :self
84
+ g.send :a, 0, true
85
+ g.push 4
86
+ g.push :self
87
+ g.send :c, 0, true
88
+
89
+ g.dup
90
+ g.is_nil
91
+ g.git t
92
+
93
+ g.push_cpath_top
94
+ g.find_const :Proc
95
+ g.swap
96
+ g.send :__from_block__, 1
97
+
98
+ t.set!
99
+
100
+ g.send_with_block :b, 1, false
101
+ end
102
+ end
103
+
104
+ relates "a.b(1, 2, 3, &c)" do
105
+ compile do |g|
106
+ t = g.new_label
107
+
108
+ g.push :self
109
+ g.send :a, 0, true
110
+ g.push 1
111
+ g.push 2
112
+ g.push 3
113
+ g.push :self
114
+ g.send :c, 0, true
115
+
116
+ g.dup
117
+ g.is_nil
118
+ g.git t
119
+
120
+ g.push_cpath_top
121
+ g.find_const :Proc
122
+ g.swap
123
+ g.send :__from_block__, 1
124
+
125
+ t.set!
126
+
127
+ g.send_with_block :b, 3, false
128
+ end
129
+ end
130
+
131
+ relates "a(&b)" do
132
+ compile do |g|
133
+ t = g.new_label
134
+
135
+ g.push :self
136
+ g.push :self
137
+ g.send :b, 0, true
138
+
139
+ g.dup
140
+ g.is_nil
141
+ g.git t
142
+
143
+ g.push_cpath_top
144
+ g.find_const :Proc
145
+ g.swap
146
+ g.send :__from_block__, 1
147
+
148
+ t.set!
149
+
150
+ g.send_with_block :a, 0, true
151
+ end
152
+ end
153
+
154
+ relates "a(4, &b)" do
155
+ compile do |g|
156
+ t = g.new_label
157
+
158
+ g.push :self
159
+ g.push 4
160
+ g.push :self
161
+ g.send :b, 0, true
162
+
163
+ g.dup
164
+ g.is_nil
165
+ g.git t
166
+
167
+ g.push_cpath_top
168
+ g.find_const :Proc
169
+ g.swap
170
+ g.send :__from_block__, 1
171
+
172
+ t.set!
173
+
174
+ g.send_with_block :a, 1, true
175
+ end
176
+ end
177
+
178
+ relates "a(1, 2, 3, &b)" do
179
+ compile do |g|
180
+ t = g.new_label
181
+
182
+ g.push :self
183
+ g.push 1
184
+ g.push 2
185
+ g.push 3
186
+ g.push :self
187
+ g.send :b, 0, true
188
+
189
+ g.dup
190
+ g.is_nil
191
+ g.git t
192
+
193
+ g.push_cpath_top
194
+ g.find_const :Proc
195
+ g.swap
196
+ g.send :__from_block__, 1
197
+
198
+ t.set!
199
+
200
+ g.send_with_block :a, 3, true
201
+ end
202
+ end
203
+
204
+ relates "define_attr_method(:x, :sequence_name, &Proc.new { |*args| nil })" do
205
+ compile do |g|
206
+ t = g.new_label
207
+
208
+ g.push :self
209
+ g.push_literal :x
210
+ g.push_literal :sequence_name
211
+
212
+ g.push_const :Proc
213
+ in_block_send :new, :splat, nil, 0, false do |d|
214
+ d.push :nil
215
+ end
216
+
217
+ g.dup
218
+ g.is_nil
219
+ g.git t
220
+
221
+ g.push_cpath_top
222
+ g.find_const :Proc
223
+ g.swap
224
+ g.send :__from_block__, 1
225
+
226
+ t.set!
227
+
228
+ g.send_with_block :define_attr_method, 2, true
229
+ end
230
+ end
231
+
232
+ relates "r.read_body(dest, &block)" do
233
+ compile do |g|
234
+ t = g.new_label
235
+
236
+ g.push :self
237
+ g.send :r, 0, true
238
+ g.push :self
239
+ g.send :dest, 0, true
240
+ g.push :self
241
+ g.send :block, 0, true
242
+
243
+ g.dup
244
+ g.is_nil
245
+ g.git t
246
+
247
+ g.push_cpath_top
248
+ g.find_const :Proc
249
+ g.swap
250
+ g.send :__from_block__, 1
251
+
252
+ t.set!
253
+
254
+ g.send_with_block :read_body, 1, false
255
+ end
256
+ end
257
+
258
+ relates "o.m(:a => 1, :b => 2)" do
259
+ compile do |g|
260
+ g.push :self
261
+ g.send :o, 0, true
262
+ g.push_cpath_top
263
+ g.find_const :Hash
264
+ g.push 2
265
+ g.send :new_from_literal, 1
266
+
267
+ g.dup
268
+ g.push_literal :a
269
+ g.push 1
270
+ g.send :[]=, 2
271
+ g.pop
272
+
273
+ g.dup
274
+ g.push_literal :b
275
+ g.push 2
276
+ g.send :[]=, 2
277
+ g.pop
278
+
279
+ g.send :m, 1, false
280
+ end
281
+ end
282
+
283
+ relates "o.m(42, :a => 1, :b => 2)" do
284
+ compile do |g|
285
+ g.push :self
286
+ g.send :o, 0, true
287
+ g.push 42
288
+ g.push_cpath_top
289
+ g.find_const :Hash
290
+ g.push 2
291
+ g.send :new_from_literal, 1
292
+
293
+ g.dup
294
+ g.push_literal :a
295
+ g.push 1
296
+ g.send :[]=, 2
297
+ g.pop
298
+
299
+ g.dup
300
+ g.push_literal :b
301
+ g.push 2
302
+ g.send :[]=, 2
303
+ g.pop
304
+
305
+ g.send :m, 2, false
306
+ end
307
+ end
308
+
309
+ ruby_version_is ""..."1.9" do
310
+ relates "o.m(42, :a => 1, :b => 2, *c)" do
311
+ compile do |g|
312
+ g.push :self
313
+ g.send :o, 0, true
314
+ g.push 42
315
+ g.push_cpath_top
316
+ g.find_const :Hash
317
+ g.push 2
318
+ g.send :new_from_literal, 1
319
+
320
+ g.dup
321
+ g.push_literal :a
322
+ g.push 1
323
+ g.send :[]=, 2
324
+ g.pop
325
+
326
+ g.dup
327
+ g.push_literal :b
328
+ g.push 2
329
+ g.send :[]=, 2
330
+ g.pop
331
+
332
+ g.push :self
333
+ g.send :c, 0, true
334
+ g.cast_array
335
+ g.push :nil
336
+ g.send_with_splat :m, 2, false, false
337
+ end
338
+ end
339
+ end
340
+
341
+ ruby_version_is ""..."1.9" do
342
+ relates "a (1,2,3)" do
343
+ compile do |g|
344
+ g.push :self
345
+ g.push 1
346
+ g.push 2
347
+ g.push 3
348
+ g.send :a, 3, true
349
+ end
350
+ end
351
+ end
352
+
353
+ relates "o.puts(42)" do
354
+ compile do |g|
355
+ g.push :self
356
+ g.send :o, 0, true
357
+ g.push 42
358
+ g.send :puts, 1, false
359
+ end
360
+ end
361
+
362
+ relates "1.b(c)" do
363
+ compile do |g|
364
+ g.push 1
365
+ g.push :self
366
+ g.send :c, 0, true
367
+ g.send :b, 1, false
368
+ end
369
+ end
370
+
371
+ relates "(v = (1 + 1)).zero?" do
372
+ compile do |g|
373
+ g.push 1
374
+ g.push 1
375
+ g.send :+, 1, false
376
+ g.set_local 0
377
+ g.send :zero?, 0, false
378
+ end
379
+ end
380
+
381
+ relates "-2**31" do
382
+ compile do |g|
383
+ g.push 2
384
+ g.push 31
385
+ g.send :**, 1, false
386
+ g.send :-@, 0, false
387
+ end
388
+ end
389
+
390
+ relates "a[]" do
391
+ compile do |g|
392
+ g.push :self
393
+ g.send :a, 0, true
394
+ g.send :[], 0, false
395
+ end
396
+ end
397
+
398
+ relates "m(:a => 1, :b => 2)" do
399
+ compile do |g|
400
+ g.push :self
401
+ g.push_cpath_top
402
+ g.find_const :Hash
403
+ g.push 2
404
+ g.send :new_from_literal, 1
405
+
406
+ g.dup
407
+ g.push_literal :a
408
+ g.push 1
409
+ g.send :[]=, 2
410
+ g.pop
411
+
412
+ g.dup
413
+ g.push_literal :b
414
+ g.push 2
415
+ g.send :[]=, 2
416
+ g.pop
417
+
418
+ g.send :m, 1, true
419
+ end
420
+ end
421
+
422
+ relates "m(42, :a => 1, :b => 2)" do
423
+ compile do |g|
424
+ g.push :self
425
+ g.push 42
426
+ g.push_cpath_top
427
+ g.find_const :Hash
428
+ g.push 2
429
+ g.send :new_from_literal, 1
430
+
431
+ g.dup
432
+ g.push_literal :a
433
+ g.push 1
434
+ g.send :[]=, 2
435
+ g.pop
436
+
437
+ g.dup
438
+ g.push_literal :b
439
+ g.push 2
440
+ g.send :[]=, 2
441
+ g.pop
442
+
443
+ g.send :m, 2, true
444
+ end
445
+ end
446
+
447
+ ruby_version_is ""..."1.9" do
448
+ relates "m(42, :a => 1, :b => 2, *c)" do
449
+ compile do |g|
450
+ g.push :self
451
+ g.push 42
452
+ g.push_cpath_top
453
+ g.find_const :Hash
454
+ g.push 2
455
+ g.send :new_from_literal, 1
456
+
457
+ g.dup
458
+ g.push_literal :a
459
+ g.push 1
460
+ g.send :[]=, 2
461
+ g.pop
462
+
463
+ g.dup
464
+ g.push_literal :b
465
+ g.push 2
466
+ g.send :[]=, 2
467
+ g.pop
468
+
469
+ g.push :self
470
+ g.send :c, 0, true
471
+ g.cast_array
472
+ g.push :nil
473
+
474
+ g.send_with_splat :m, 2, true, false
475
+ end
476
+ end
477
+ end
478
+
479
+ relates "m(42)" do
480
+ compile do |g|
481
+ g.push :self
482
+ g.push 42
483
+ g.send :m, 1, true
484
+ end
485
+ end
486
+
487
+ relates "a(:b) { :c }" do
488
+ compile do |g|
489
+ g.push :self
490
+ g.push_literal :b
491
+
492
+ g.in_block_send :a, :none, nil, 1 do |d|
493
+ d.push_literal :c
494
+ end
495
+ end
496
+ end
497
+
498
+ relates "a [42]" do
499
+ compile do |g|
500
+ g.push :self
501
+ g.push 42
502
+ g.make_array 1
503
+ g.send :a, 1, true
504
+ end
505
+ end
506
+
507
+ relates "42 if block_given?" do
508
+ compile do |g|
509
+ t = g.new_label
510
+ f = g.new_label
511
+
512
+ g.push :self
513
+ g.send :block_given?, 0, true
514
+ g.gif f
515
+ g.push 42
516
+ g.goto t
517
+ f.set!
518
+ g.push :nil
519
+ t.set!
520
+ end
521
+ end
522
+
523
+ relates "method" do
524
+ compile do |g|
525
+ g.push :self
526
+ g.send :method, 0, true
527
+ end
528
+ end
529
+
530
+ relates <<-ruby do
531
+ a << begin
532
+ b
533
+ rescue
534
+ c
535
+ end
536
+ ruby
537
+
538
+ compile do |g|
539
+ g.push :self
540
+ g.send :a, 0, true
541
+
542
+ for_rescue do |rb|
543
+ rb.body do
544
+ g.push :self
545
+ g.send :b, 0, true
546
+ end
547
+
548
+ rb.condition :StandardError, true do
549
+ g.push :self
550
+ g.send :c, 0, true
551
+ end
552
+ end
553
+
554
+ g.send :<<, 1, false
555
+ end
556
+ end
557
+
558
+ relates "meth([*[1]])" do
559
+ compile do |g|
560
+ g.push :self
561
+ g.push 1
562
+ g.make_array 1
563
+ g.send :meth, 1, true
564
+ end
565
+ end
566
+
567
+ relates "meth(*[1])" do
568
+ compile do |g|
569
+ g.push :self
570
+
571
+ g.push 1
572
+ g.make_array 1
573
+ g.cast_array
574
+
575
+ g.push :nil
576
+
577
+ g.send_with_splat :meth, 0, true, false
578
+ end
579
+ end
580
+ end