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,195 @@
1
+ describe "A Call node using InlineAssembly transform" do
2
+ relates <<-ruby do
3
+ Rubinius.asm(a) do |m|
4
+ push 1
5
+ end
6
+ ruby
7
+
8
+ compile do |g|
9
+ g.push_const :Rubinius
10
+ g.push :self
11
+ g.send :a, 0, true
12
+
13
+ g.in_block_send :asm, :single, nil, 1, false do |d|
14
+ d.push :self
15
+ d.push 1
16
+ d.send :push, 1, true
17
+ end
18
+ end
19
+
20
+ compile :assembly do |g|
21
+ g.push 1
22
+ end
23
+ end
24
+
25
+ relates <<-ruby do
26
+ def new(*args)
27
+ obj = allocate()
28
+
29
+ Rubinius.asm(args, obj) do |x, y|
30
+ run y
31
+ run x
32
+ push_block
33
+ send_with_splat :initialize, 0, true
34
+ end
35
+
36
+ return obj
37
+ end
38
+ ruby
39
+
40
+ compile do |g|
41
+ in_method :new do |d|
42
+ d.push :self
43
+ d.send :allocate, 0, true
44
+ d.set_local 1
45
+ d.pop
46
+
47
+ d.push_const :Rubinius
48
+ d.push_local 0
49
+ d.push_local 1
50
+
51
+ e = new_block_generator(g)
52
+
53
+ ruby_version_is ""..."1.9" do
54
+ e.cast_for_multi_block_arg
55
+ e.shift_array
56
+
57
+ e.set_local 0
58
+ e.pop
59
+ e.shift_array
60
+ e.set_local 1
61
+ e.pop
62
+ e.pop
63
+ end
64
+
65
+ e.push_modifiers
66
+ e.new_label.set!
67
+
68
+ e.push :self
69
+ e.push_local 1
70
+ e.send :run, 1, true
71
+ e.pop
72
+
73
+ e.push :self
74
+ e.push_local 0
75
+ e.send :run, 1, true
76
+ e.pop
77
+
78
+ e.push :self
79
+ e.send :push_block, 0, true
80
+ e.pop
81
+ e.push :self
82
+ e.push_literal :initialize
83
+ e.push 0
84
+ e.push :true
85
+ e.send :send_with_splat, 3, true
86
+
87
+ e.pop_modifiers
88
+ e.ret
89
+
90
+ d.create_block(e)
91
+ d.send_with_block :asm, 2, false
92
+ d.pop
93
+ d.push_local 1
94
+ d.ret
95
+ end
96
+ end
97
+
98
+ compile :assembly do |g|
99
+ in_method :new do |d|
100
+ d.push :self
101
+ d.send :allocate, 0, true
102
+ d.set_local 1
103
+ d.pop
104
+
105
+ d.push_local 1
106
+ d.push_local 0
107
+ d.push_block
108
+ d.send_with_splat :initialize, 0, true
109
+ d.pop
110
+ d.push_local 1
111
+ d.ret
112
+ end
113
+ end
114
+ end
115
+
116
+ relates <<-ruby do
117
+ def new(cnt)
118
+ obj = allocate_sized cnt
119
+ Rubinius.asm(obj) do |x|
120
+ push_block
121
+ run x
122
+ send_with_block :initialize, 0, true
123
+ end
124
+
125
+ return obj
126
+ end
127
+ ruby
128
+
129
+ compile do |g|
130
+ in_method :new do |d|
131
+ d.push :self
132
+ d.push_local 0
133
+ d.send :allocate_sized, 1, true
134
+ d.set_local 1
135
+ d.pop
136
+
137
+ d.push_const :Rubinius
138
+ d.push_local 1
139
+
140
+ e = new_block_generator(g)
141
+
142
+ ruby_version_is ""..."1.9" do
143
+ e.cast_for_single_block_arg
144
+
145
+ e.set_local 0
146
+ e.pop
147
+ end
148
+
149
+ e.push_modifiers
150
+ e.new_label.set!
151
+
152
+ e.push :self
153
+ e.send :push_block, 0, true
154
+ e.pop
155
+
156
+ e.push :self
157
+ e.push_local 0
158
+ e.send :run, 1, true
159
+ e.pop
160
+
161
+ e.push :self
162
+ e.push_literal :initialize
163
+ e.push 0
164
+ e.push :true
165
+ e.send :send_with_block, 3, true
166
+
167
+ e.pop_modifiers
168
+ e.ret
169
+
170
+ d.create_block(e)
171
+ d.send_with_block :asm, 1, false
172
+ d.pop
173
+ d.push_local 1
174
+ d.ret
175
+ end
176
+ end
177
+
178
+ compile :assembly do |g|
179
+ in_method :new do |d|
180
+ d.push :self
181
+ d.push_local 0
182
+ d.send :allocate_sized, 1, true
183
+ d.set_local 1
184
+ d.pop
185
+
186
+ d.push_block
187
+ d.push_local 1
188
+ d.send_with_block :initialize, 0, true
189
+ d.pop
190
+ d.push_local 1
191
+ d.ret
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,75 @@
1
+ describe "A Call node using BlockGiven transform" do
2
+ block_given = lambda do |g|
3
+ in_method :m do |d|
4
+ no_blk = d.new_label
5
+ done = d.new_label
6
+
7
+ d.push_has_block
8
+ d.gif no_blk
9
+
10
+ d.push 1
11
+ d.goto done
12
+
13
+ no_blk.set!
14
+ d.push :nil
15
+
16
+ done.set!
17
+ end
18
+ end
19
+
20
+ relates <<-ruby do
21
+ def m
22
+ 1 if block_given?
23
+ end
24
+ ruby
25
+
26
+ compile do |g|
27
+ in_method :m do |d|
28
+ no_blk = d.new_label
29
+ done = d.new_label
30
+
31
+ d.push :self
32
+ d.send :block_given?, 0, true
33
+ d.gif no_blk
34
+
35
+ d.push 1
36
+ d.goto done
37
+
38
+ no_blk.set!
39
+ d.push :nil
40
+
41
+ done.set!
42
+ end
43
+ end
44
+
45
+ compile(:block_given, &block_given)
46
+ end
47
+
48
+ relates <<-ruby do
49
+ def m
50
+ 1 if iterator?
51
+ end
52
+ ruby
53
+
54
+ compile do |g|
55
+ in_method :m do |d|
56
+ no_blk = d.new_label
57
+ done = d.new_label
58
+
59
+ d.push :self
60
+ d.send :iterator?, 0, true
61
+ d.gif no_blk
62
+
63
+ d.push 1
64
+ d.goto done
65
+
66
+ no_blk.set!
67
+ d.push :nil
68
+
69
+ done.set!
70
+ end
71
+ end
72
+
73
+ compile(:block_given, &block_given)
74
+ end
75
+ end
@@ -0,0 +1,112 @@
1
+ describe "A Call node using SendFastCoerceTo transform" do
2
+ relates <<-ruby do
3
+ a = b
4
+ Rubinius::Type.coerce_to a, Fixnum, :to_int
5
+ ruby
6
+
7
+ compile do |g|
8
+ g.push :self
9
+ g.send :b, 0, true
10
+ g.set_local 0
11
+ g.pop
12
+
13
+ g.push_type
14
+ g.push_local 0
15
+ g.push_const :Fixnum
16
+ g.push_literal :to_int
17
+ g.send :coerce_to, 3, false
18
+ end
19
+
20
+ compile :fast_coerce do |g|
21
+ done = g.new_label
22
+
23
+ g.push :self
24
+ g.send :b, 0, true
25
+ g.set_local 0
26
+ g.pop
27
+
28
+ g.push_local 0
29
+ g.dup
30
+ g.push_const :Fixnum
31
+ g.swap
32
+ g.kind_of
33
+ g.git done
34
+
35
+ g.pop
36
+ g.push_type
37
+ g.push_local 0
38
+ g.push_const :Fixnum
39
+ g.push_literal :to_int
40
+ g.send :coerce_to, 3, false
41
+
42
+ done.set!
43
+ end
44
+ end
45
+
46
+ relates <<-ruby do
47
+ Rubinius::Type.coerce_to a, Fixnum, :to_int
48
+ ruby
49
+
50
+ compile do |g|
51
+ g.push_type
52
+ g.push :self
53
+ g.send :a, 0, true
54
+ g.push_const :Fixnum
55
+ g.push_literal :to_int
56
+ g.send :coerce_to, 3, false
57
+ end
58
+
59
+ compile :fast_coerce do |g|
60
+ g.push_type
61
+ g.push :self
62
+ g.send :a, 0, true
63
+ g.push_const :Fixnum
64
+ g.push_literal :to_int
65
+ g.send :coerce_to, 3, false
66
+ end
67
+ end
68
+
69
+ relates <<-ruby do
70
+ a = b
71
+ Rubinius::Type.coerce_to a, String, :to_str
72
+ ruby
73
+
74
+ compile do |g|
75
+ g.push :self
76
+ g.send :b, 0, true
77
+ g.set_local 0
78
+ g.pop
79
+
80
+ g.push_type
81
+ g.push_local 0
82
+ g.push_const :String
83
+ g.push_literal :to_str
84
+ g.send :coerce_to, 3, false
85
+ end
86
+
87
+ compile :fast_coerce do |g|
88
+ done = g.new_label
89
+
90
+ g.push :self
91
+ g.send :b, 0, true
92
+ g.set_local 0
93
+ g.pop
94
+
95
+ g.push_local 0
96
+ g.dup
97
+ g.push_const :String
98
+ g.swap
99
+ g.kind_of
100
+ g.git done
101
+
102
+ g.pop
103
+ g.push_type
104
+ g.push_local 0
105
+ g.push_const :String
106
+ g.push_literal :to_str
107
+ g.send :coerce_to, 3, false
108
+
109
+ done.set!
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,255 @@
1
+ describe "A Call node using FastNew transform" do
2
+ relates "new(a)" do
3
+ compile do |g|
4
+ g.push :self
5
+ g.push :self
6
+ g.send :a, 0, true
7
+ g.send :new, 1, true
8
+ end
9
+
10
+ compile :fast_new do |g|
11
+ slow = g.new_label
12
+ done = g.new_label
13
+
14
+ g.push :self
15
+ g.dup
16
+ g.check_serial_private :new, Rubinius::CompiledCode::KernelMethodSerial
17
+ gif slow
18
+
19
+ g.send :allocate, 0, true
20
+ g.dup
21
+ g.push :self
22
+ g.send :a, 0, true
23
+ g.send :initialize, 1, true
24
+ g.pop
25
+ g.goto done
26
+
27
+ slow.set!
28
+ g.push :self
29
+ g.send :a, 0, true
30
+ g.send :new, 1, true
31
+
32
+ done.set!
33
+ end
34
+ end
35
+
36
+ relates "new(&block)" do
37
+ fast_new_with_block = lambda do |g|
38
+ g.push :self
39
+ g.push :self
40
+ g.send :block, 0, true
41
+ g.dup
42
+ g.is_nil
43
+
44
+ no_block = g.new_label
45
+ g.git no_block
46
+
47
+ g.push_cpath_top
48
+ g.find_const :Proc
49
+ g.swap
50
+ g.send :__from_block__, 1
51
+
52
+ no_block.set!
53
+ g.send_with_block :new, 0, true
54
+ end
55
+
56
+ compile(&fast_new_with_block)
57
+
58
+ compile(:fast_new, &fast_new_with_block)
59
+ end
60
+
61
+ relates "new(a, &block)" do
62
+ fast_new_with_arg_block = lambda do |g|
63
+ g.push :self
64
+ g.push :self
65
+ g.send :a, 0, true
66
+
67
+ g.push :self
68
+ g.send :block, 0, true
69
+ g.dup
70
+ g.is_nil
71
+
72
+ no_block = g.new_label
73
+ g.git no_block
74
+
75
+ g.push_cpath_top
76
+ g.find_const :Proc
77
+ g.swap
78
+ g.send :__from_block__, 1
79
+
80
+ no_block.set!
81
+ g.send_with_block :new, 1, true
82
+ end
83
+
84
+ compile(&fast_new_with_arg_block)
85
+
86
+ compile(:fast_new, &fast_new_with_arg_block)
87
+ end
88
+
89
+ relates "A.new" do
90
+ compile do |g|
91
+ g.push_const :A
92
+ g.send :new, 0, false
93
+ end
94
+
95
+ compile :fast_new do |g|
96
+ slow = g.new_label
97
+ done = g.new_label
98
+
99
+ g.push_const :A
100
+ g.dup
101
+ g.check_serial :new, Rubinius::CompiledCode::KernelMethodSerial
102
+ gif slow
103
+
104
+ g.send :allocate, 0, true
105
+ g.dup
106
+ g.send :initialize, 0, true
107
+ g.pop
108
+ g.goto done
109
+
110
+ slow.set!
111
+ g.send :new, 0, false
112
+
113
+ done.set!
114
+ end
115
+ end
116
+
117
+ relates "A.new(a)" do
118
+ compile do |g|
119
+ g.push_const :A
120
+ g.push :self
121
+ g.send :a, 0, true
122
+ g.send :new, 1, false
123
+ end
124
+
125
+ compile :fast_new do |g|
126
+ slow = g.new_label
127
+ done = g.new_label
128
+
129
+ g.push_const :A
130
+ g.dup
131
+ g.check_serial :new, Rubinius::CompiledCode::KernelMethodSerial
132
+ gif slow
133
+
134
+ g.send :allocate, 0, true
135
+ g.dup
136
+ g.push :self
137
+ g.send :a, 0, true
138
+ g.send :initialize, 1, true
139
+ g.pop
140
+ g.goto done
141
+
142
+ slow.set!
143
+ g.push :self
144
+ g.send :a, 0, true
145
+ g.send :new, 1, false
146
+
147
+ done.set!
148
+ end
149
+ end
150
+
151
+ relates "A.new(&block)" do
152
+ fast_new_with_block = lambda do |g|
153
+ g.push_const :A
154
+ g.push :self
155
+ g.send :block, 0, true
156
+ g.dup
157
+ g.is_nil
158
+
159
+ no_block = g.new_label
160
+ g.git no_block
161
+
162
+ g.push_cpath_top
163
+ g.find_const :Proc
164
+ g.swap
165
+ g.send :__from_block__, 1
166
+
167
+ no_block.set!
168
+ g.send_with_block :new, 0, false
169
+ end
170
+
171
+ compile(&fast_new_with_block)
172
+
173
+ compile(:fast_new, &fast_new_with_block)
174
+ end
175
+
176
+ relates "A.new(a, &block)" do
177
+ fast_new_with_arg_block = lambda do |g|
178
+ g.push_const :A
179
+ g.push :self
180
+ g.send :a, 0, true
181
+
182
+ g.push :self
183
+ g.send :block, 0, true
184
+ g.dup
185
+ g.is_nil
186
+
187
+ no_block = g.new_label
188
+ g.git no_block
189
+
190
+ g.push_cpath_top
191
+ g.find_const :Proc
192
+ g.swap
193
+ g.send :__from_block__, 1
194
+
195
+ no_block.set!
196
+ g.send_with_block :new, 1, false
197
+ end
198
+
199
+ compile(&fast_new_with_arg_block)
200
+
201
+ compile(:fast_new, &fast_new_with_arg_block)
202
+ end
203
+
204
+ ruby_version_is "1.9" do
205
+ relates "A.new(a { |(b, c)| })" do
206
+ compile :fast_new do
207
+ d = new_block_generator(g)
208
+ d.push_local 0
209
+ d.cast_array
210
+ d.shift_array
211
+ d.set_local 0
212
+ d.pop
213
+
214
+ d.shift_array
215
+ d.set_local 1
216
+ d.pop
217
+ d.pop
218
+
219
+ d.push_modifiers
220
+ d.new_label.set!
221
+ d.push :nil
222
+ d.pop_modifiers
223
+ d.ret
224
+
225
+ slow = g.new_label
226
+ done = g.new_label
227
+
228
+ g.push_const :A
229
+ g.dup
230
+ g.check_serial :new, Rubinius::CompiledCode::KernelMethodSerial
231
+ gif slow
232
+
233
+ g.send :allocate, 0, true
234
+ g.dup
235
+
236
+ g.push :self
237
+ g.create_block(d)
238
+ g.send_with_block :a, 0, true
239
+
240
+ g.send :initialize, 1, true
241
+ g.pop
242
+ g.goto done
243
+
244
+ slow.set!
245
+
246
+ g.push :self
247
+ g.create_block(d)
248
+ g.send_with_block :a, 0, true
249
+ g.send :new, 1, false
250
+
251
+ done.set!
252
+ end
253
+ end
254
+ end
255
+ end