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,15 @@
1
+ describe "A Gasgn node" do
2
+ relates "$x = 42" do
3
+ compile do |g|
4
+ g.push_rubinius
5
+ g.find_const :Globals
6
+ g.push_literal :"$x" # REFACTOR g.get_global("$x")
7
+ g.push 42
8
+ g.send :[]=, 2
9
+ end
10
+ end
11
+
12
+ relates "$a = *[1]" do
13
+ # gasgn splat
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ describe "Rubinius::Generator#encode" do
2
+ before :each do
3
+ @g = Rubinius::ToolSets::Spec::Generator.new
4
+ @g.set_line 1
5
+ end
6
+
7
+ it "raises a CompileError if the method exits with an empty stack" do
8
+ @g.ret
9
+ @g.close
10
+
11
+ lambda { @g.encode }.should raise_error(Rubinius::ToolSets::Spec::CompileError)
12
+ end
13
+
14
+ it "raises a CompileError if pop is called on an empty stack" do
15
+ @g.pop
16
+ @g.ret
17
+ @g.close
18
+
19
+ lambda { @g.encode }.should raise_error(Rubinius::ToolSets::Spec::CompileError)
20
+ end
21
+
22
+ it "raises a CompileError if a BasicBlock's minimum stack size is negative" do
23
+ label = @g.new_label
24
+ @g.push :nil
25
+ @g.gif label
26
+ label.set!
27
+ @g.pop
28
+ @g.push :true
29
+ @g.ret
30
+ @g.close
31
+
32
+ lambda { @g.encode }.should raise_error(Rubinius::ToolSets::Spec::CompileError)
33
+ end
34
+ end
data/spec/gvar_spec.rb ADDED
@@ -0,0 +1,37 @@
1
+ describe "A Gvar node" do
2
+ relates "$x" do
3
+ compile do |g|
4
+ g.push_rubinius
5
+ g.find_const :Globals
6
+ g.push_literal :"$x" # REFACTOR g.get_global("$x")
7
+ g.send :[], 1
8
+ end
9
+ end
10
+
11
+ relates "$stderr" do
12
+ compile do |g|
13
+ g.push_rubinius
14
+ g.find_const :Globals
15
+ g.push_literal :"$stderr"
16
+ g.send :[], 1
17
+ end
18
+ end
19
+
20
+ relates "$__blah" do
21
+ compile do |g|
22
+ g.push_rubinius
23
+ g.find_const :Globals
24
+ g.push_literal :"$__blah"
25
+ g.send :[], 1
26
+ end
27
+ end
28
+
29
+ relates "$_" do
30
+ compile do |g|
31
+ g.push_rubinius
32
+ g.find_const :Globals
33
+ g.push_literal :"$_"
34
+ g.send :[], 1
35
+ end
36
+ end
37
+ end
data/spec/hash_spec.rb ADDED
@@ -0,0 +1,108 @@
1
+ describe "A Hash node" do
2
+ relates "{ 1 => 2, 3 => 4 }" do
3
+ compile do |g|
4
+ g.push_cpath_top
5
+ g.find_const :Hash
6
+ g.push 2
7
+ g.send :new_from_literal, 1
8
+
9
+ g.dup
10
+ g.push 1
11
+ g.push 2
12
+ g.send :[]=, 2
13
+ g.pop
14
+
15
+ g.dup
16
+ g.push 3
17
+ g.push 4
18
+ g.send :[]=, 2
19
+ g.pop
20
+ end
21
+ end
22
+
23
+ relates "{ 1 => (2 rescue 3) }" do
24
+ compile do |g|
25
+ g.push_cpath_top
26
+ g.find_const :Hash
27
+ g.push 1
28
+ g.send :new_from_literal, 1
29
+
30
+ g.dup
31
+ g.push 1
32
+
33
+ g.for_rescue do |rb|
34
+ rb.body do
35
+ g.push 2
36
+ end
37
+
38
+ rb.condition :StandardError, true do
39
+ g.push 3
40
+ end
41
+ end
42
+
43
+ g.send :[]=, 2
44
+ g.pop
45
+ end
46
+ end
47
+
48
+ relates "{ 1 => [*1] }" do
49
+ compile do |g|
50
+ g.push_cpath_top
51
+ g.find_const :Hash
52
+ g.push 1
53
+ g.send :new_from_literal, 1
54
+
55
+ g.dup
56
+ g.push 1
57
+ g.push 1
58
+ g.cast_array
59
+ g.send :[]=, 2
60
+ g.pop
61
+ end
62
+ end
63
+
64
+ relates <<-ruby do
65
+ a = 1
66
+ { :a => a }
67
+ ruby
68
+
69
+ compile do |g|
70
+ g.push 1
71
+ g.set_local 0
72
+ g.pop
73
+ g.push_cpath_top
74
+ g.find_const :Hash
75
+ g.push 1
76
+ g.send :new_from_literal, 1
77
+
78
+ g.dup
79
+ g.push_literal :a
80
+ g.push_local 0
81
+ g.send :[]=, 2
82
+ g.pop
83
+ end
84
+ end
85
+
86
+ ruby_version_is "1.9" do
87
+ relates "{ a: 1, b: 2 }" do
88
+ compile do |g|
89
+ g.push_cpath_top
90
+ g.find_const :Hash
91
+ g.push 2
92
+ g.send :new_from_literal, 1
93
+
94
+ g.dup
95
+ g.push_literal :a
96
+ g.push 1
97
+ g.send :[]=, 2
98
+ g.pop
99
+
100
+ g.dup
101
+ g.push_literal :b
102
+ g.push 2
103
+ g.send :[]=, 2
104
+ g.pop
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,26 @@
1
+ describe "A Iasgn node" do
2
+ relates "@a = 4" do
3
+ compile do |g|
4
+ g.push 4
5
+ g.set_ivar :@a
6
+ end
7
+ end
8
+
9
+ relates "@a = *[1]" do
10
+ # iasgn splat
11
+ end
12
+
13
+ relates <<-ruby do
14
+ a = 1
15
+ @a = a
16
+ ruby
17
+
18
+ compile do |g|
19
+ g.push 1
20
+ g.set_local 0
21
+ g.pop
22
+ g.push_local 0
23
+ g.set_ivar :@a
24
+ end
25
+ end
26
+ end
data/spec/if_spec.rb ADDED
@@ -0,0 +1,415 @@
1
+ describe "An If node" do
2
+ nil_condition = lambda do |g|
3
+ f = g.new_label
4
+ done = g.new_label
5
+
6
+ g.push :nil
7
+ g.gif f
8
+
9
+ g.push :self
10
+ g.send :a, 0, true
11
+ g.goto done
12
+
13
+ f.set!
14
+ g.push :nil
15
+
16
+ done.set!
17
+ end
18
+
19
+ not_nil_condition = lambda do |g|
20
+ f = g.new_label
21
+ done = g.new_label
22
+
23
+ g.push :nil
24
+ g.send :"!", 0, false
25
+ g.gif f
26
+
27
+ g.push :nil
28
+ g.goto done
29
+
30
+ f.set!
31
+ g.push :self
32
+ g.send :a, 0, true
33
+
34
+ done.set!
35
+ end
36
+
37
+ relates <<-ruby do
38
+ if true then
39
+ 10
40
+ else
41
+ 12
42
+ end
43
+ ruby
44
+
45
+ compile do |g|
46
+ g.push :true
47
+ els = g.new_label
48
+ fin = g.new_label
49
+ g.gif els
50
+ g.push 10
51
+ g.goto fin
52
+ els.set!
53
+ g.push 12
54
+ fin.set!
55
+ end
56
+ end
57
+
58
+ relates "if b then a end" do
59
+ compile do |g|
60
+ nope = g.new_label
61
+ done = g.new_label
62
+
63
+ g.push :self
64
+ g.send :b, 0, true
65
+ g.gif nope
66
+
67
+ g.push :self
68
+ g.send :a, 0, true
69
+ g.goto done
70
+
71
+ nope.set!
72
+ g.push :nil
73
+
74
+ done.set!
75
+ end
76
+ end
77
+
78
+ relates <<-ruby do
79
+ if (x = 5
80
+ (x + 1)) then
81
+ nil
82
+ end
83
+ ruby
84
+
85
+ compile do |g|
86
+ f = g.new_label
87
+ bottom = g.new_label
88
+
89
+ g.push 5
90
+ g.set_local 0
91
+ g.pop
92
+
93
+ g.push_local 0
94
+ g.push 1
95
+ g.send :+, 1, false
96
+ g.gif f
97
+
98
+ g.push :nil
99
+ g.goto bottom
100
+
101
+ f.set!
102
+ g.push :nil
103
+
104
+ bottom.set!
105
+ end
106
+ end
107
+
108
+ relates <<-ruby do
109
+ if x = obj.x then
110
+ x.do_it
111
+ end
112
+ ruby
113
+
114
+ compile do |g|
115
+ f = g.new_label
116
+ bottom = g.new_label
117
+
118
+ g.push :self
119
+ g.send :obj, 0, true
120
+ g.send :x, 0, false
121
+ g.set_local 0
122
+
123
+ g.gif f
124
+
125
+ g.push_local 0
126
+ g.send :do_it, 0, false
127
+ g.goto bottom
128
+
129
+ f.set!
130
+ g.push :nil
131
+
132
+ bottom.set!
133
+ end
134
+ end
135
+
136
+ relates "return if false unless true" do
137
+ compile do |g|
138
+ else1 = g.new_label
139
+ else2 = g.new_label
140
+ done1 = g.new_label
141
+ done2 = g.new_label
142
+
143
+ g.push :true
144
+ g.gif else1
145
+ g.push :nil
146
+ g.goto done1
147
+
148
+ else1.set!
149
+ g.push :false
150
+ g.gif else2
151
+ g.push :nil
152
+ g.ret
153
+ g.goto done2
154
+
155
+ else2.set!
156
+ g.push :nil
157
+
158
+ done2.set!
159
+ done1.set!
160
+ end
161
+ end
162
+
163
+ relates "a if b" do
164
+ compile do |g|
165
+ nope = g.new_label
166
+ done = g.new_label
167
+
168
+ g.push :self
169
+ g.send :b, 0, true
170
+ g.gif nope
171
+
172
+ g.push :self
173
+ g.send :a, 0, true
174
+ g.goto done
175
+
176
+ nope.set!
177
+ g.push :nil
178
+
179
+ done.set!
180
+ end
181
+ end
182
+
183
+ relates "if b then a end" do
184
+ compile do |g|
185
+ nope = g.new_label
186
+ done = g.new_label
187
+
188
+ g.push :self
189
+ g.send :b, 0, true
190
+ g.gif nope
191
+
192
+ g.push :self
193
+ g.send :a, 0, true
194
+ g.goto done
195
+
196
+ nope.set!
197
+ g.push :nil
198
+
199
+ done.set!
200
+ end
201
+ end
202
+
203
+ relates "a if ()" do
204
+ compile(&nil_condition)
205
+ end
206
+
207
+ relates "if () then a end" do
208
+ compile(&nil_condition)
209
+ end
210
+
211
+ relates "a unless b" do
212
+ compile do |g|
213
+ else_label = g.new_label
214
+ done = g.new_label
215
+
216
+ g.push :self
217
+ g.send :b, 0, true
218
+ g.gif else_label
219
+ g.push :nil
220
+ g.goto done
221
+
222
+ else_label.set!
223
+ g.push :self
224
+ g.send :a, 0, true
225
+
226
+ done.set!
227
+ end
228
+ end
229
+
230
+ relates "unless b then a end" do
231
+ compile do |g|
232
+ else_label = g.new_label
233
+ done = g.new_label
234
+
235
+ g.push :self
236
+ g.send :b, 0, true
237
+ g.gif else_label
238
+ g.push :nil
239
+ g.goto done
240
+
241
+ else_label.set!
242
+ g.push :self
243
+ g.send :a, 0, true
244
+
245
+ done.set!
246
+ end
247
+ end
248
+
249
+ ruby_version_is ""..."1.9" do
250
+ relates "a if not b" do
251
+ compile do |g|
252
+ else_label = g.new_label
253
+ done = g.new_label
254
+
255
+ g.push :self
256
+ g.send :b, 0, true
257
+ g.gif else_label
258
+ g.push :nil
259
+ g.goto done
260
+
261
+ else_label.set!
262
+ g.push :self
263
+ g.send :a, 0, true
264
+
265
+ done.set!
266
+ end
267
+ end
268
+
269
+ relates "if not b then a end" do
270
+ compile do |g|
271
+ else_label = g.new_label
272
+ done = g.new_label
273
+
274
+ g.push :self
275
+ g.send :b, 0, true
276
+ g.gif else_label
277
+ g.push :nil
278
+ g.goto done
279
+
280
+ else_label.set!
281
+ g.push :self
282
+ g.send :a, 0, true
283
+
284
+ done.set!
285
+ end
286
+ end
287
+
288
+ relates "a unless ! ()" do
289
+ compile(&nil_condition)
290
+ end
291
+
292
+ relates "unless ! () then a end" do
293
+ compile(&nil_condition)
294
+ end
295
+
296
+ relates "a unless not b" do
297
+ compile do |g|
298
+ nope = g.new_label
299
+ done = g.new_label
300
+
301
+ g.push :self
302
+ g.send :b, 0, true
303
+ g.gif nope
304
+
305
+ g.push :self
306
+ g.send :a, 0, true
307
+ g.goto done
308
+
309
+ nope.set!
310
+ g.push :nil
311
+
312
+ done.set!
313
+ end
314
+ end
315
+
316
+ relates "unless not b then a end" do
317
+ compile do |g|
318
+ nope = g.new_label
319
+ done = g.new_label
320
+
321
+ g.push :self
322
+ g.send :b, 0, true
323
+ g.gif nope
324
+
325
+ g.push :self
326
+ g.send :a, 0, true
327
+ g.goto done
328
+
329
+ nope.set!
330
+ g.push :nil
331
+
332
+ done.set!
333
+ end
334
+ end
335
+ end
336
+
337
+ ruby_version_is "1.9" do
338
+ relates "a if not b" do
339
+ compile do |g|
340
+ f = g.new_label
341
+ done = g.new_label
342
+
343
+ g.push :self
344
+ g.send :b, 0, true
345
+ g.send :"!", 0, false
346
+ g.gif f
347
+
348
+ g.push :self
349
+ g.send :a, 0, true
350
+ g.goto done
351
+
352
+ f.set!
353
+ g.push :nil
354
+
355
+ done.set!
356
+ end
357
+ end
358
+
359
+ relates "if not b then a end" do
360
+ compile do |g|
361
+ f = g.new_label
362
+ done = g.new_label
363
+
364
+ g.push :self
365
+ g.send :b, 0, true
366
+ g.send :"!", 0, false
367
+ g.gif f
368
+
369
+ g.push :self
370
+ g.send :a, 0, true
371
+ g.goto done
372
+
373
+ f.set!
374
+ g.push :nil
375
+
376
+ done.set!
377
+ end
378
+ end
379
+
380
+ relates "a unless ! ()" do
381
+ compile(&not_nil_condition)
382
+ end
383
+
384
+ relates "unless ! () then a end" do
385
+ compile(&not_nil_condition)
386
+ end
387
+
388
+ unless_not_condition = lambda do |g|
389
+ f = g.new_label
390
+ done = g.new_label
391
+
392
+ g.push :self
393
+ g.send :b, 0, true
394
+ g.send :"!", 0, false
395
+ g.gif f
396
+
397
+ g.push :nil
398
+ g.goto done
399
+
400
+ f.set!
401
+ g.push :self
402
+ g.send :a, 0, true
403
+
404
+ done.set!
405
+ end
406
+
407
+ relates "a unless not b" do
408
+ compile(&unless_not_condition)
409
+ end
410
+
411
+ relates "unless not b then a end" do
412
+ compile(&unless_not_condition)
413
+ end
414
+ end
415
+ end