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/defs_spec.rb ADDED
@@ -0,0 +1,113 @@
1
+ describe "A Defs node" do
2
+ relates <<-ruby do
3
+ def self.x(y)
4
+ (y + 1)
5
+ end
6
+ ruby
7
+
8
+ compile do |g|
9
+ in_singleton_method :x, [:push, :self] do |d|
10
+ d.push_local 0
11
+ d.push 1
12
+ d.send :+, 1, false
13
+ end
14
+ end
15
+ end
16
+
17
+ relates <<-ruby do
18
+ def self.setup(ctx)
19
+ bind = allocate
20
+ bind.context = ctx
21
+ return bind
22
+ end
23
+ ruby
24
+
25
+ compile do |g|
26
+ g.in_singleton_method :setup, [:push, :self] do |d|
27
+ d.push :self
28
+ d.send :allocate, 0, true
29
+ d.set_local 1
30
+ d.pop
31
+
32
+ d.push_local 1
33
+ d.push_local 0
34
+ d.dup
35
+ d.move_down 2
36
+ d.send :context=, 1, false
37
+ d.pop
38
+ d.pop
39
+
40
+ d.push_local 1
41
+ d.ret # TODO: why extra return?
42
+ end
43
+ end
44
+ end
45
+
46
+ relates <<-ruby do
47
+ def self.empty(*)
48
+ end
49
+ ruby
50
+
51
+ compile do |g|
52
+ in_singleton_method :empty, [:push, :self] do |d|
53
+ d.push :nil
54
+ end
55
+ end
56
+ end
57
+
58
+ relates <<-ruby do
59
+ def self.empty
60
+ end
61
+ ruby
62
+
63
+ compile do |g|
64
+ in_singleton_method :empty, [:push, :self] do |d|
65
+ d.push :nil
66
+ end
67
+ end
68
+ end
69
+
70
+ relates <<-ruby do
71
+ def (a.b).empty(*)
72
+ end
73
+ ruby
74
+
75
+ compile do |g|
76
+ g.push_rubinius
77
+
78
+ g.push_literal :empty
79
+
80
+ d = new_generator(g, name)
81
+ d.push :nil
82
+ d.ret
83
+
84
+ g.push_literal(d)
85
+ g.push_scope
86
+
87
+ g.push :self
88
+ g.send :a, 0, true
89
+ g.send :b, 0, false
90
+
91
+ g.send :attach_method, 4
92
+ end
93
+ end
94
+
95
+ relates <<-ruby do
96
+ x = "a"
97
+ def x.m(a)
98
+ a
99
+ end
100
+ ruby
101
+
102
+ compile do |g|
103
+ g.push_literal "a"
104
+ g.string_dup
105
+ g.set_local 0
106
+ g.pop
107
+
108
+ in_singleton_method :m, [:push_local, 0] do |d|
109
+ d.push_local 0
110
+ end
111
+ end
112
+ end
113
+ end
data/spec/dot2_spec.rb ADDED
@@ -0,0 +1,16 @@
1
+ describe "A Dot2 node" do
2
+ relates "(a..b)" do
3
+ compile do |g|
4
+ g.push_cpath_top
5
+ g.find_const :Range
6
+ g.send :allocate, 0, true
7
+ g.dup
8
+ g.push :self
9
+ g.send :a, 0, true
10
+ g.push :self
11
+ g.send :b, 0, true
12
+ g.send :initialize, 2, true
13
+ g.pop
14
+ end
15
+ end
16
+ end
data/spec/dot3_spec.rb ADDED
@@ -0,0 +1,17 @@
1
+ describe "A Dot3 node" do
2
+ relates "(a...b)" do
3
+ compile do |g|
4
+ g.push_cpath_top
5
+ g.find_const :Range
6
+ g.send :allocate, 0, true
7
+ g.dup
8
+ g.push :self
9
+ g.send :a, 0, true
10
+ g.push :self
11
+ g.send :b, 0, true
12
+ g.push :true
13
+ g.send :initialize, 3, true
14
+ g.pop
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,160 @@
1
+ describe "A Dregx node" do
2
+ ruby_version_is ""..."1.9" do
3
+ # TODO: Fix 1.8 parser
4
+ relates <<-ruby do
5
+ /(\#{})/
6
+ ruby
7
+
8
+ compile do |g|
9
+ g.push_cpath_top
10
+ g.find_const :Regexp
11
+ g.push_literal "("
12
+ g.push_literal ")"
13
+ g.string_build 2
14
+ g.push 0
15
+ g.send :new, 2
16
+ end
17
+ end
18
+
19
+ relates "/a\#{}b/" do
20
+ compile do |g|
21
+ g.push_cpath_top
22
+ g.find_const :Regexp
23
+
24
+ g.push_literal "a"
25
+ g.push_literal "b"
26
+ g.string_build 2
27
+
28
+ g.push 0
29
+ g.send :new, 2
30
+ end
31
+ end
32
+ end
33
+
34
+ ruby_version_is "1.9" do
35
+ relates <<-ruby do
36
+ /(\#{})/
37
+ ruby
38
+
39
+ compile do |g|
40
+ g.push_cpath_top
41
+ g.find_const :Regexp
42
+ g.push_literal "("
43
+ g.push :nil
44
+ g.meta_to_s
45
+ g.push_literal ")"
46
+ g.string_build 3
47
+ g.push 0
48
+ g.send :new, 2
49
+ end
50
+ end
51
+
52
+ relates "/a\#{}b/" do
53
+ compile do |g|
54
+ g.push_cpath_top
55
+ g.find_const :Regexp
56
+
57
+ g.push_literal "a"
58
+ g.push :nil
59
+ g.meta_to_s
60
+ g.push_literal "b"
61
+ g.string_build 3
62
+
63
+ g.push 0
64
+ g.send :new, 2
65
+ end
66
+ end
67
+ end
68
+
69
+ relates "/x\#{(1 + 1)}y/" do
70
+ compile do |g|
71
+ g.push_cpath_top
72
+ g.find_const :Regexp
73
+
74
+ g.push_literal "x" # 1
75
+
76
+ g.push 1 # 2
77
+ g.push 1
78
+ g.send :+, 1, false
79
+ g.meta_to_s
80
+
81
+ g.push_literal "y" # 3
82
+
83
+ g.string_build 3
84
+
85
+ g.push 0
86
+ g.send :new, 2
87
+ end
88
+ end
89
+
90
+ relates "/\#{@rakefile}/" do
91
+ compile do |g|
92
+ g.push_cpath_top
93
+ g.find_const :Regexp
94
+
95
+ g.push_ivar :@rakefile
96
+ g.meta_to_s
97
+ g.string_build 1
98
+
99
+ g.push 0
100
+ g.send :new, 2
101
+ end
102
+ end
103
+
104
+ relates "/\#{1}/n" do
105
+ compile do |g|
106
+ g.push_cpath_top
107
+ g.find_const :Regexp
108
+
109
+ g.push 1
110
+ g.meta_to_s
111
+ g.string_build 1
112
+
113
+ g.push 512
114
+ g.send :new, 2
115
+ end
116
+ end
117
+
118
+ relates "/\#{IAC}\#{SB}/no" do
119
+ compile do |g|
120
+ memoize do
121
+ g.push_cpath_top
122
+ g.find_const :Regexp
123
+
124
+ g.push_const :IAC # 1
125
+ g.meta_to_s
126
+
127
+ g.push_const :SB # 2
128
+ g.meta_to_s
129
+
130
+ g.string_build 2
131
+
132
+ g.push 512
133
+ g.send :new, 2
134
+ end
135
+ end
136
+ end
137
+
138
+ relates "/x\#{(1 + 1)}y/o" do
139
+ compile do |g|
140
+ memoize do
141
+ g.push_cpath_top
142
+ g.find_const :Regexp
143
+
144
+ g.push_literal "x" # 1
145
+
146
+ g.push 1 # 2
147
+ g.push 1
148
+ g.send :+, 1, false
149
+ g.meta_to_s
150
+
151
+ g.push_literal "y" # 3
152
+
153
+ g.string_build 3
154
+
155
+ g.push 0
156
+ g.send :new, 2
157
+ end
158
+ end
159
+ end
160
+ end
data/spec/dstr_spec.rb ADDED
@@ -0,0 +1,424 @@
1
+ describe "A Dstr node" do
2
+ ruby_version_is ""..."1.9" do
3
+ relates <<-ruby do
4
+ "\#{}"
5
+ ruby
6
+
7
+ compile do |g|
8
+ g.push_literal ""
9
+ g.string_dup
10
+ end
11
+ end
12
+
13
+ relates <<-ruby do
14
+ "\#{}\#{}"
15
+ ruby
16
+
17
+ compile do |g|
18
+ g.push_literal ""
19
+ g.string_dup
20
+ end
21
+ end
22
+
23
+ relates <<-ruby do
24
+ "\#{}hello\#{}"
25
+ ruby
26
+
27
+ compile do |g|
28
+ g.push_literal "hello"
29
+ g.string_build 1
30
+ end
31
+ end
32
+
33
+ relates <<-ruby do
34
+ "hello \#{}"
35
+ ruby
36
+
37
+ compile do |g|
38
+ g.push_literal "hello "
39
+ g.string_dup
40
+ end
41
+ end
42
+
43
+ relates <<-ruby do
44
+ "\#{} hello"
45
+ ruby
46
+
47
+ compile do |g|
48
+ g.push_literal " hello"
49
+ g.string_build 1
50
+ end
51
+ end
52
+ end
53
+
54
+ ruby_version_is "1.9" do
55
+ relates <<-ruby do
56
+ "\#{}"
57
+ ruby
58
+
59
+ compile do |g|
60
+ g.push :nil
61
+ g.meta_to_s
62
+ g.string_build 1
63
+ end
64
+ end
65
+
66
+ relates <<-ruby do
67
+ "\#{}\#{}"
68
+ ruby
69
+
70
+ compile do |g|
71
+ g.push :nil
72
+ g.meta_to_s
73
+ g.push :nil
74
+ g.meta_to_s
75
+ g.string_build 2
76
+ end
77
+ end
78
+
79
+ relates <<-ruby do
80
+ "\#{}hello\#{}"
81
+ ruby
82
+
83
+ compile do |g|
84
+ g.push :nil
85
+ g.meta_to_s
86
+ g.push_literal "hello"
87
+ g.push :nil
88
+ g.meta_to_s
89
+ g.string_build 3
90
+ end
91
+ end
92
+
93
+ relates <<-ruby do
94
+ "hello \#{}"
95
+ ruby
96
+
97
+ compile do |g|
98
+ g.push_literal "hello "
99
+ g.push :nil
100
+ g.meta_to_s
101
+ g.string_build 2
102
+ end
103
+ end
104
+
105
+ relates <<-ruby do
106
+ "\#{} hello"
107
+ ruby
108
+
109
+ compile do |g|
110
+ g.push :nil
111
+ g.meta_to_s
112
+ g.push_literal " hello"
113
+ g.string_build 2
114
+ end
115
+ end
116
+ end
117
+
118
+ relates <<-ruby do
119
+ "\#{a}"
120
+ ruby
121
+
122
+ compile do |g|
123
+ g.push :self
124
+ g.send :a, 0, true
125
+ g.meta_to_s
126
+ g.string_build 1
127
+ end
128
+ end
129
+
130
+ relates <<-ruby do
131
+ "hello \#{a}"
132
+ ruby
133
+
134
+ compile do |g|
135
+ g.push_literal "hello "
136
+ g.push :self
137
+ g.send :a, 0, true
138
+ g.meta_to_s
139
+ g.string_build 2
140
+ end
141
+ end
142
+
143
+ relates <<-ruby do
144
+ "\#{a} hello"
145
+ ruby
146
+
147
+ compile do |g|
148
+ g.push :self
149
+ g.send :a, 0, true
150
+ g.meta_to_s
151
+ g.push_literal " hello"
152
+ g.string_build 2
153
+ end
154
+ end
155
+
156
+ relates <<-ruby do
157
+ argl = 1
158
+ "x\#{argl}y"
159
+ ruby
160
+
161
+ compile do |g|
162
+ g.push 1
163
+ g.set_local 0
164
+ g.pop
165
+
166
+ g.push_literal "x" # 1
167
+
168
+ g.push_local 0 # 2
169
+ g.meta_to_s
170
+
171
+ g.push_literal "y" # 3
172
+
173
+ g.string_build 3
174
+ end
175
+ end
176
+
177
+ relates <<-ruby do
178
+ argl = 1
179
+ "x\#{("%.2f" % 3.14159)}y"
180
+ ruby
181
+
182
+ compile do |g|
183
+ g.push 1
184
+ g.set_local 0
185
+ g.pop
186
+
187
+ g.push_literal "x" # 1
188
+
189
+ g.push_literal "%.2f" # 2
190
+ g.string_dup
191
+ g.push_literal 3.14159
192
+ g.send :%, 1, false
193
+ g.meta_to_s
194
+
195
+ g.push_literal "y" # 3
196
+
197
+ g.string_build 3
198
+ end
199
+ end
200
+
201
+ relates <<-ruby do
202
+ max = 2
203
+ argl = 1
204
+ "x\#{("%.\#{max}f" % 3.14159)}y" # "
205
+ ruby
206
+
207
+ compile do |g|
208
+ g.push 2
209
+ g.set_local 0
210
+ g.pop
211
+ g.push 1
212
+ g.set_local 1
213
+ g.pop
214
+
215
+ g.push_literal "x" # - # 1
216
+
217
+ g.push_literal "%." # 1
218
+
219
+ g.push_local 0 # 2
220
+ g.meta_to_s
221
+
222
+ g.push_literal "f" # 3
223
+
224
+ g.string_build 3
225
+
226
+ g.push_literal 3.14159 # - # 2
227
+ g.send :%, 1, false
228
+ g.meta_to_s
229
+
230
+ g.push_literal "y" # - # 3
231
+
232
+ g.string_build 3
233
+ end
234
+ end
235
+
236
+ relates '"#{22}aa" "cd#{44}" "55" "#{66}"' do
237
+ compile do |g|
238
+ g.push 22 # 1
239
+ g.meta_to_s
240
+
241
+ g.push_literal "aa" # 2
242
+ g.push_literal "cd" # 3
243
+
244
+ g.push 44 # 4
245
+ g.meta_to_s
246
+
247
+ g.push_literal "55" # 5
248
+
249
+ g.push 66 # 6
250
+ g.meta_to_s
251
+
252
+ g.string_build 6
253
+ end
254
+ end
255
+
256
+ relates '"a #$global b #@ivar c #@@cvar d"' do
257
+ compile do |g|
258
+ g.push_literal "a " # 1
259
+
260
+ g.push_rubinius # 2
261
+ g.find_const :Globals
262
+ g.push_literal :$global
263
+ g.send :[], 1
264
+ g.meta_to_s
265
+
266
+ g.push_literal " b " # 3
267
+
268
+ g.push_ivar :@ivar # 4
269
+ g.meta_to_s
270
+
271
+ g.push_literal " c " # 5
272
+
273
+ g.push_scope # 6
274
+ g.push_literal :@@cvar
275
+ g.send :class_variable_get, 1
276
+ g.meta_to_s
277
+
278
+ g.push_literal " d" # 7
279
+
280
+ g.string_build 7
281
+ end
282
+ end
283
+
284
+ relates <<-ruby do
285
+ <<EOM
286
+ foo
287
+ \#{1 + 1}blah
288
+ EOM
289
+ ruby
290
+
291
+ compile do |g|
292
+ g.push_literal " foo\n" # 1
293
+
294
+ g.push 1 # 2
295
+ g.push 1
296
+ g.send :+, 1, false
297
+ g.meta_to_s
298
+
299
+ g.push_literal "blah\n" # 3
300
+
301
+ g.string_build 3
302
+ end
303
+ end
304
+
305
+ relates <<-ruby do
306
+ <<-EOF
307
+ def test_\#{action}_valid_feed
308
+ EOF
309
+ ruby
310
+
311
+ compile do |g|
312
+ g.push_literal "def test_" # 1
313
+
314
+ g.push :self # 2
315
+ g.send :action, 0, true
316
+ g.meta_to_s
317
+
318
+ g.push_literal "_valid_feed\n" # 1
319
+
320
+ g.string_build 3
321
+ end
322
+ end
323
+
324
+ relates <<-ruby do
325
+ <<-EOF
326
+ s1 '\#{RUBY_PLATFORM}' s2
327
+ \#{__FILE__}
328
+ EOF
329
+ ruby
330
+
331
+ compile do |g|
332
+ g.push_literal "s1 '" # 1
333
+
334
+ g.push_const :RUBY_PLATFORM # 2
335
+ g.meta_to_s
336
+
337
+ g.push_literal "' s2\n" # 3
338
+
339
+ g.push_scope # 4
340
+ g.send :active_path, 0
341
+ g.meta_to_s
342
+
343
+ g.push_literal "\n" # 5
344
+
345
+ g.string_build 5
346
+ end
347
+ end
348
+
349
+ relates "%Q[before [\#{nest}] after]" do
350
+ compile do |g|
351
+ g.push_literal "before [" # 1
352
+
353
+ g.push :self # 2
354
+ g.send :nest, 0, true
355
+ g.meta_to_s
356
+
357
+ g.push_literal "] after" # 3
358
+
359
+ g.string_build 3
360
+ end
361
+ end
362
+
363
+ relates '"#{"blah"}#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})"' do
364
+ compile do |g|
365
+ g.push_literal "blah" # 1
366
+
367
+ g.push_scope # 2
368
+ g.send :active_path, 0
369
+ g.meta_to_s
370
+
371
+ g.push_literal ":" # 3
372
+
373
+ g.push 1 # 4
374
+ g.meta_to_s
375
+
376
+ g.push_literal ": warning: " # 5
377
+
378
+ g.push_current_exception # 6
379
+ g.send :message, 0, false
380
+ g.meta_to_s
381
+
382
+ g.push_literal " (" # 7
383
+
384
+ g.push_current_exception # 8
385
+ g.send :class, 0, false
386
+ g.meta_to_s
387
+
388
+ g.push_literal ")" # 9
389
+
390
+ g.string_build 9
391
+ end
392
+ end
393
+
394
+ relates '"before #{from} middle #{to} (#{__FILE__}:#{__LINE__})"' do
395
+ compile do |g|
396
+ g.push_literal "before " # 1
397
+
398
+ g.push :self # 2
399
+ g.send :from, 0, true
400
+ g.meta_to_s
401
+
402
+ g.push_literal " middle " # 3
403
+
404
+ g.push :self # 4
405
+ g.send :to, 0, true
406
+ g.meta_to_s
407
+
408
+ g.push_literal " (" # 5
409
+
410
+ g.push_scope # 6
411
+ g.send :active_path, 0
412
+ g.meta_to_s
413
+
414
+ g.push_literal ":" # 7
415
+
416
+ g.push 1 # 8
417
+ g.meta_to_s
418
+
419
+ g.push_literal ")" # 9
420
+
421
+ g.string_build 9
422
+ end
423
+ end
424
+ end