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,14 @@
1
+ describe "A Call node using InvokePrimitive transform" do
2
+ relates <<-ruby do
3
+ Rubinius.invoke_primitive :name, 1, 2, a
4
+ ruby
5
+
6
+ compile :invoke_primitive do |g|
7
+ g.push 1
8
+ g.push 2
9
+ g.push :self
10
+ g.send :a, 0, true
11
+ g.invoke_primitive :name, 3
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ describe "A Call node using kernel_methods transform" do
2
+ relates "4 / 2" do
3
+ compile do |g|
4
+ g.push 4
5
+ g.push 2
6
+ g.send :/, 1, false
7
+ end
8
+
9
+ compile :kernel_methods do |g|
10
+ g.push 4
11
+ g.push 2
12
+ g.send :divide, 1, false
13
+ end
14
+ end
15
+
16
+ relates "a.class" do
17
+ compile do |g|
18
+ g.push :self
19
+ g.send :a, 0, true
20
+ g.send :class, 0, false
21
+ end
22
+
23
+ compile :kernel_methods do |g|
24
+ g.push :self
25
+ g.send :a, 0, true
26
+ g.send :__class__, 0, false
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ describe "A Call node using PrimitiveDeclaration transform" do
2
+ relates <<-ruby do
3
+ def m
4
+ Rubinius.primitive :prim
5
+ raise PrimitiveFailure, "failed"
6
+ end
7
+ ruby
8
+
9
+ compile do |g|
10
+ in_method :m do |d|
11
+ d.push_const :Rubinius
12
+ d.push_literal :prim
13
+ d.send :primitive, 1, false
14
+ d.pop
15
+ d.push :self
16
+ d.push_const :PrimitiveFailure
17
+ d.push_literal "failed"
18
+ d.string_dup
19
+ d.send :raise, 2, true
20
+ end
21
+ end
22
+
23
+ compile :primitive do |g|
24
+ in_method :m do |d|
25
+ d.push :self
26
+ d.push_const :PrimitiveFailure
27
+ d.push_literal "failed"
28
+ d.string_dup
29
+ d.send :raise, 2, true
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ describe "A Call node using SendPrivately transform" do
2
+ relates <<-ruby do
3
+ def m
4
+ c = 1
5
+ Rubinius.privately {
6
+ a.b c
7
+ }
8
+ end
9
+ ruby
10
+
11
+ compile :privately do |g|
12
+ in_method :m do |d|
13
+ d.push 1
14
+ d.set_local 0
15
+ d.pop
16
+
17
+ d.push :self
18
+ d.send :a, 0, true
19
+ d.push_local 0
20
+ d.send :b, 1, true
21
+ end
22
+ end
23
+ end
24
+ end
data/spec/true_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ describe "A True node" do
2
+ relates "true" do
3
+ compile do |g|
4
+ g.push :true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,133 @@
1
+ describe "An Undef node" do
2
+ relates "undef :x" do
3
+ compile do |g|
4
+ undef_bytecode :x
5
+ end
6
+ end
7
+
8
+ relates "undef :x, :y" do
9
+ compile do |g|
10
+ undef_bytecode :x, :y
11
+ end
12
+ end
13
+
14
+ relates "undef :x, :y, :z" do
15
+ compile do |g|
16
+ undef_bytecode :x, :y, :z
17
+ end
18
+ end
19
+
20
+ relates <<-ruby do
21
+ f1
22
+ undef :x
23
+ ruby
24
+
25
+ compile do |g|
26
+ g.push :self
27
+ g.send :f1, 0, true
28
+ g.pop
29
+
30
+ undef_bytecode :x
31
+ end
32
+ end
33
+
34
+ relates <<-ruby do
35
+ f1
36
+ undef :x, :y
37
+ ruby
38
+
39
+ compile do |g|
40
+ g.push :self
41
+ g.send :f1, 0, true
42
+ g.pop
43
+
44
+ undef_bytecode :x, :y
45
+ end
46
+ end
47
+
48
+ relates <<-ruby do
49
+ undef :x, :y, :z
50
+ f2
51
+ ruby
52
+
53
+ compile do |g|
54
+ undef_bytecode :x, :y, :z
55
+ g.pop
56
+
57
+ g.push :self
58
+ g.send :f2, 0, true
59
+ end
60
+ end
61
+
62
+ relates <<-ruby do
63
+ f1
64
+ undef :x, :y, :z
65
+ ruby
66
+
67
+ compile do |g|
68
+ g.push :self
69
+ g.send :f1, 0, true
70
+ g.pop
71
+
72
+ undef_bytecode :x, :y, :z
73
+ end
74
+ end
75
+
76
+ relates <<-ruby do
77
+ f1
78
+ undef :x, :y, :z
79
+ f2
80
+ ruby
81
+
82
+ compile do |g|
83
+ g.push :self
84
+ g.send :f1, 0, true
85
+ g.pop
86
+
87
+ undef_bytecode :x, :y, :z
88
+ g.pop
89
+
90
+ g.push :self
91
+ g.send :f2, 0, true
92
+ end
93
+ end
94
+
95
+ relates "class B; undef :blah; end" do
96
+ compile do |g|
97
+ g.in_class :B do |d|
98
+ d.push_scope
99
+ d.push_literal :blah
100
+ d.send :__undef_method__, 1
101
+ end
102
+ end
103
+ end
104
+
105
+ relates <<-ruby do
106
+ undef :"x\#{1}", :"x\#{2}"
107
+ ruby
108
+
109
+ compile do |g|
110
+ g.push_scope
111
+ g.push_literal "x"
112
+
113
+ g.push 1
114
+ g.meta_to_s
115
+
116
+ g.string_build 2
117
+
118
+ g.send :to_sym, 0, true
119
+ g.send :__undef_method__, 1
120
+ g.pop
121
+
122
+ g.push_scope
123
+
124
+ g.push_literal "x"
125
+ g.push 2
126
+ g.meta_to_s
127
+ g.string_build 2
128
+
129
+ g.send :to_sym, 0, true
130
+ g.send :__undef_method__, 1
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,254 @@
1
+ describe "An Until node" do
2
+ pre_until = lambda do |g|
3
+ top = g.new_label
4
+ rdo = g.new_label
5
+ brk = g.new_label
6
+ post = g.new_label
7
+ bottom = g.new_label
8
+
9
+ g.push_modifiers
10
+
11
+ top.set!
12
+ g.push :self
13
+ g.send :a, 0, true
14
+ g.git bottom
15
+
16
+ rdo.set!
17
+ g.push :self
18
+ g.send :b, 0, true
19
+ g.push 1
20
+ g.send :+, 1, false
21
+
22
+ post.set!
23
+ g.pop
24
+ g.check_interrupts
25
+ g.goto top
26
+
27
+ bottom.set!
28
+ g.push :nil
29
+
30
+ brk.set!
31
+ g.pop_modifiers
32
+ end
33
+
34
+ post_until = lambda do |g|
35
+ top = g.new_label
36
+ brk = g.new_label
37
+ post = g.new_label
38
+ bottom = g.new_label
39
+
40
+ g.push_modifiers
41
+
42
+ top.set!
43
+
44
+ g.push :self
45
+ g.send :b, 0, true
46
+ g.push 1
47
+ g.send :+, 1, false
48
+
49
+ post.set!
50
+ g.pop
51
+ g.check_interrupts
52
+
53
+ g.push :self
54
+ g.send :a, 0, true
55
+ g.git bottom
56
+
57
+ g.goto top
58
+
59
+ bottom.set!
60
+ g.push :nil
61
+
62
+ brk.set!
63
+
64
+ g.pop_modifiers
65
+ end
66
+
67
+ ruby_version_is ""..."1.9" do
68
+ nil_condition = lambda do |g|
69
+ top = g.new_label
70
+ rdo = g.new_label
71
+ brk = g.new_label
72
+ post = g.new_label
73
+ bottom = g.new_label
74
+
75
+ g.push_modifiers
76
+ top.set!
77
+
78
+ g.push :nil
79
+ g.git bottom
80
+
81
+ rdo.set!
82
+ g.push :self
83
+ g.send :a, 0, true
84
+
85
+ post.set!
86
+ g.pop
87
+ g.check_interrupts
88
+ g.goto top
89
+
90
+ bottom.set!
91
+ g.push :nil
92
+
93
+ brk.set!
94
+ g.pop_modifiers
95
+ end
96
+
97
+ relates <<-ruby do
98
+ while not a
99
+ b + 1
100
+ end
101
+ ruby
102
+
103
+ compile(&pre_until)
104
+ end
105
+
106
+ relates "b + 1 while not a" do
107
+ compile(&pre_until)
108
+ end
109
+
110
+ relates <<-ruby do
111
+ begin
112
+ b + 1
113
+ end while not a
114
+ ruby
115
+
116
+ compile(&post_until)
117
+ end
118
+
119
+ relates "a while not ()" do
120
+ compile(&nil_condition)
121
+ end
122
+
123
+ relates <<-ruby do
124
+ while not ()
125
+ a
126
+ end
127
+ ruby
128
+
129
+ compile(&nil_condition)
130
+ end
131
+
132
+ relates "a while ! ()" do
133
+ compile(&nil_condition)
134
+ end
135
+
136
+ relates <<-ruby do
137
+ while ! ()
138
+ a
139
+ end
140
+ ruby
141
+
142
+ compile(&nil_condition)
143
+ end
144
+ end
145
+
146
+ ruby_version_is "1.9" do
147
+ nil_condition = lambda do |g|
148
+ top = g.new_label
149
+ rdo = g.new_label
150
+ brk = g.new_label
151
+ post = g.new_label
152
+ bottom = g.new_label
153
+
154
+ g.push_modifiers
155
+ top.set!
156
+
157
+ g.push :nil
158
+ g.git bottom
159
+
160
+ rdo.set!
161
+ g.push :self
162
+ g.send :a, 0, true
163
+
164
+ post.set!
165
+ g.pop
166
+ g.check_interrupts
167
+ g.goto top
168
+
169
+ bottom.set!
170
+ g.push :nil
171
+
172
+ brk.set!
173
+ g.pop_modifiers
174
+ end
175
+
176
+ relates "a until ()" do
177
+ compile(&nil_condition)
178
+ end
179
+
180
+ relates <<-ruby do
181
+ until ()
182
+ a
183
+ end
184
+ ruby
185
+
186
+ compile(&nil_condition)
187
+ end
188
+
189
+ not_nil_condition = lambda do |g|
190
+ top = g.new_label
191
+ rdo = g.new_label
192
+ brk = g.new_label
193
+ post = g.new_label
194
+ bottom = g.new_label
195
+
196
+ g.push_modifiers
197
+ top.set!
198
+
199
+ g.push :nil
200
+ g.send :"!", 0, false
201
+ g.git bottom
202
+
203
+ rdo.set!
204
+ g.push :self
205
+ g.send :a, 0, true
206
+
207
+ post.set!
208
+ g.pop
209
+ g.check_interrupts
210
+ g.goto top
211
+
212
+ bottom.set!
213
+ g.push :nil
214
+
215
+ brk.set!
216
+ g.pop_modifiers
217
+ end
218
+
219
+ relates "a until ! ()" do
220
+ compile(&not_nil_condition)
221
+ end
222
+
223
+ relates <<-ruby do
224
+ until ! ()
225
+ a
226
+ end
227
+ ruby
228
+
229
+ compile(&not_nil_condition)
230
+ end
231
+ end
232
+
233
+ relates <<-ruby do
234
+ until a
235
+ b + 1
236
+ end
237
+ ruby
238
+
239
+ compile(&pre_until)
240
+ end
241
+
242
+ relates "b + 1 until a" do
243
+ compile(&pre_until)
244
+ end
245
+
246
+ relates <<-ruby do
247
+ begin
248
+ b + 1
249
+ end until a
250
+ ruby
251
+
252
+ compile(&post_until)
253
+ end
254
+ end