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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5acab156c744b74d3701a97ce2a936ed5a626e4
4
- data.tar.gz: 01b7e1db56052cc7f8959251505415f955772ad8
3
+ metadata.gz: 5ce7bfe87d566ab6ce14b3394c0f73c684ec7296
4
+ data.tar.gz: 2d164dc5242d6c385ea3d0b156c37c77d545b387
5
5
  SHA512:
6
- metadata.gz: fd08452cfd3e40636214c3db841365131ad15cafb2aa15e1517b0ae33add7aceb82e34a8f67da2bf504682a33a96b61bac1052fd94b3731ba6705ba29f6d02dd
7
- data.tar.gz: 2324f6df47926b6e38818e482083b0305ab0031c7c92094c98f944c2b67fe0ef369573c633bbe49db5e692c26a4be8bcd5446389bc541a1225a2e619e4214573
6
+ metadata.gz: 95d55cdba119ed0403f6f5b8cbfacabbdfe14f17f0a04fcac1edf130335d125a52c7b2829199f35c9a3e9490c901d557a185584816352d0e0f71d88783a240b6
7
+ data.tar.gz: 54f4932a5a13faf06119fd393fa5e63b5f625e3a17da25410bd3e37eb14ef57efbe36e3f34c38b5c3d2c0a51afd60f51812e81bcb7fe07799e3347e25a514082
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ env:
3
+ - RUBYLIB=lib:.
4
+ before_install: gem install rubinius-toolset
5
+ script: mspec -r spec/spec_helper spec
6
+ rvm:
7
+ - 2.1.0
8
+ - rbx-2
@@ -1,4 +1,4 @@
1
- # -*- encoding: us-ascii -*-
1
+ # -*- encoding: ascii-8bit -*-
2
2
 
3
3
  module Rubinius::ToolSets.current::ToolSet
4
4
  ##
@@ -137,13 +137,13 @@ module Rubinius::ToolSets.current::ToolSet
137
137
  enc = unmarshal_data
138
138
  count = next_string.to_i
139
139
  str = next_bytes count
140
- str.force_encoding enc if enc and defined?(Encoding)
140
+ str.force_encoding enc if enc
141
141
  return str
142
142
  when 120 # ?x
143
143
  enc = unmarshal_data
144
144
  count = next_string.to_i
145
145
  str = next_bytes count
146
- str.force_encoding enc if enc and defined?(Encoding)
146
+ str.force_encoding enc if enc
147
147
  return str.to_sym
148
148
  when 99 # ?c
149
149
  count = next_string.to_i
@@ -170,7 +170,7 @@ module Rubinius::ToolSets.current::ToolSet
170
170
  when 69 # ?E
171
171
  count = next_string.to_i
172
172
  name = next_bytes count
173
- return Encoding.find(name) if defined?(Encoding)
173
+ return Encoding.find(name)
174
174
  when 77 # ?M
175
175
  version = next_string.to_i
176
176
  if version != 1
@@ -238,6 +238,26 @@ module Rubinius::ToolSets.current::ToolSet
238
238
 
239
239
  private :next_bytes
240
240
 
241
+ ##
242
+ # A helper function to force strings to ASCII-8BIT encoding. This is
243
+ # needed because Ruby's encoding system causes the result of a UTF-8
244
+ # string interpolated in a file (like this one) with a ASCII-8BIT
245
+ # encoding magic comment to be UTF-8. In other words, given the
246
+ # following script:
247
+ #
248
+ # # -*- encoding: ascii-8bit -*s
249
+ #
250
+ # x = "❤"
251
+ # s = "abc #{x}"
252
+ #
253
+ # the string, s, will have UTF-8 encoding, NOT ASCII-8BIT encoding.
254
+
255
+ def b(val)
256
+ val.force_encoding Encoding::ASCII_8BIT
257
+ end
258
+
259
+ private :b
260
+
241
261
  ##
242
262
  # For object +val+, return a String represetation.
243
263
 
@@ -250,40 +270,20 @@ module Rubinius::ToolSets.current::ToolSet
250
270
  when NilClass
251
271
  "n\n"
252
272
  when Fixnum, Bignum
253
- "I\n#{val.to_s(16)}\n"
273
+ b "I\n#{val.to_s(16)}\n"
254
274
  when String
255
- if defined?(Encoding)
256
- # We manually construct the Encoding data to avoid recursion
257
- # marshaling an Encoding name as a String.
258
- name = val.encoding.name
259
- enc_name = "E\n#{name.bytesize}\n#{name}\n"
260
- else
261
- # The kernel code is all US-ASCII. When building melbourne for 1.8
262
- # Ruby, we fake a bunch of encoding stuff so force US-ASCII here.
263
- enc_name = "E\n8\nUS-ASCII\n"
264
- end
265
-
266
- "s\n#{enc_name}#{val.bytesize}\n#{val}\n"
275
+ name = val.encoding.name
276
+ enc_name = "E\n#{name.bytesize}\n#{name}\n"
277
+ b "s\n#{enc_name}#{val.bytesize}\n#{val}\n"
267
278
  when Symbol
268
279
  s = val.to_s
269
- if defined?(Encoding)
270
- # We manually construct the Encoding data to avoid recursion
271
- # marshaling an Encoding name as a String.
272
- name = s.encoding.name
273
- enc_name = "E\n#{name.bytesize}\n#{name}\n"
274
- else
275
- # The kernel code is all US-ASCII. When building melbourne for 1.8
276
- # Ruby, we fake a bunch of encoding stuff so force US-ASCII here.
277
- enc_name = "E\n8\nUS-ASCII\n"
278
- end
279
-
280
- "x\n#{enc_name}#{s.bytesize}\n#{s}\n"
280
+ name = s.encoding.name
281
+ enc_name = "E\n#{name.bytesize}\n#{name}\n"
282
+ b "x\n#{enc_name}#{s.bytesize}\n#{s}\n"
281
283
  when Rubinius::Tuple
282
284
  str = "p\n#{val.size}\n"
283
285
  val.each do |ele|
284
- data = marshal(ele)
285
- data.force_encoding(str.encoding) if defined?(Encoding)
286
- str.append data
286
+ str.append marshal(ele)
287
287
  end
288
288
  str
289
289
  when Float
@@ -1,5 +1,5 @@
1
1
  module Rubinius::ToolSets.current::ToolSet
2
- module Compiler
3
- VERSION = "2.1.0"
2
+ class Compiler
3
+ VERSION = "2.1.1"
4
4
  end
5
5
  end
@@ -19,4 +19,10 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.3"
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "mspec", "~> 1.5"
23
+ spec.add_development_dependency "rubinius-toolset", "~> 2.2"
24
+ spec.add_development_dependency "rubinius-processor", "~> 2.0"
25
+ spec.add_development_dependency "rubinius-ast", "~> 2.0"
26
+ spec.add_development_dependency "rubinius-bridge", "~> 1.0"
27
+ spec.add_development_dependency "redcard", "~> 1.0"
22
28
  end
@@ -0,0 +1,39 @@
1
+ describe "An Alias node" do
2
+ alias_both = lambda do |g|
3
+ g.push_scope
4
+ g.push_literal :y
5
+ g.push_literal :x
6
+ g.send :alias_method, 2, true
7
+ end
8
+
9
+ relates "alias :y :x" do
10
+ compile(&alias_both)
11
+ end
12
+
13
+ relates "alias y x" do
14
+ compile(&alias_both)
15
+ end
16
+
17
+ relates <<-ruby do
18
+ alias :"y\#{1}" :"x\#{2}"
19
+ ruby
20
+
21
+ compile do |g|
22
+ g.push_scope
23
+
24
+ g.push_literal "y"
25
+ g.push 1
26
+ g.meta_to_s
27
+ g.string_build 2
28
+ g.send :to_sym, 0, true
29
+
30
+ g.push_literal "x"
31
+ g.push 2
32
+ g.meta_to_s
33
+ g.string_build 2
34
+ g.send :to_sym, 0, true
35
+
36
+ g.send :alias_method, 2, true
37
+ end
38
+ end
39
+ end
data/spec/and_spec.rb ADDED
@@ -0,0 +1,44 @@
1
+ describe "An And node" do
2
+ relates "(a and b)" do
3
+ compile do |g|
4
+ g.push :self
5
+ g.send :a, 0, true
6
+ g.dup
7
+
8
+ lhs_true = g.new_label
9
+ g.gif lhs_true
10
+
11
+ g.pop
12
+ g.push :self
13
+ g.send :b, 0, true
14
+
15
+ lhs_true.set!
16
+ end
17
+ end
18
+
19
+ relates "() and a" do
20
+ compile do |g|
21
+ f = g.new_label
22
+ g.push :nil
23
+ g.dup
24
+ g.gif f
25
+ g.pop
26
+ g.push :self
27
+ g.send :a, 0, true
28
+ f.set!
29
+ end
30
+ end
31
+
32
+ relates "a and ()" do
33
+ compile do |g|
34
+ f = g.new_label
35
+ g.push :self
36
+ g.send :a, 0, true
37
+ g.dup
38
+ g.gif f
39
+ g.pop
40
+ g.push :nil
41
+ f.set!
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,110 @@
1
+ describe "An Array node" do
2
+ relates '[1, :b, "c"]' do
3
+ compile do |g|
4
+ g.push 1
5
+ g.push_literal :b
6
+ g.push_literal "c"
7
+ g.string_dup
8
+ g.make_array 3
9
+ end
10
+ end
11
+
12
+ relates "%w[a b c]" do
13
+ compile do |g|
14
+ g.push_literal "a"
15
+ g.string_dup
16
+ g.push_literal "b"
17
+ g.string_dup
18
+ g.push_literal "c"
19
+ g.string_dup
20
+ g.make_array 3
21
+ end
22
+ end
23
+
24
+ relates '%w[a #{@b} c]' do
25
+ compile do |g|
26
+ g.push_literal "a"
27
+ g.string_dup
28
+
29
+ g.push_literal "\#{@b}"
30
+ g.string_dup
31
+
32
+ g.push_literal "c"
33
+ g.string_dup
34
+ g.make_array 3
35
+ end
36
+ end
37
+
38
+ relates "%W[a b c]" do
39
+ compile do |g|
40
+ g.push_literal "a"
41
+ g.string_dup
42
+ g.push_literal "b"
43
+ g.string_dup
44
+ g.push_literal "c"
45
+ g.string_dup
46
+ g.make_array 3
47
+ end
48
+ end
49
+
50
+ relates '%W[a #{@b} c]' do
51
+ compile do |g|
52
+ g.push_literal "a"
53
+ g.string_dup
54
+
55
+ g.push_ivar :@b
56
+ g.meta_to_s
57
+ g.string_build 1
58
+
59
+ g.push_literal "c"
60
+ g.string_dup
61
+ g.make_array 3
62
+ end
63
+ end
64
+
65
+ relates "[*[1]]" do
66
+ compile do |g|
67
+ g.push 1
68
+ g.make_array 1
69
+ end
70
+ end
71
+
72
+ relates "[*1]" do
73
+ compile do |g|
74
+ g.push 1
75
+ g.cast_array
76
+ end
77
+ end
78
+
79
+ relates "[[*1]]" do
80
+ compile do |g|
81
+ g.push 1
82
+ g.cast_array
83
+ g.make_array 1
84
+ end
85
+ end
86
+
87
+ relates "[1, *2]" do
88
+ compile do |g|
89
+ g.push 1
90
+ g.make_array 1
91
+
92
+ g.push 2
93
+ g.cast_array
94
+
95
+ g.send :+, 1
96
+ end
97
+ end
98
+
99
+ relates "[1, *c()]" do
100
+ # TODO
101
+ end
102
+
103
+ relates <<-ruby do
104
+ x = [2]
105
+ [1, *x]
106
+ ruby
107
+
108
+ # TODO
109
+ end
110
+ end
@@ -0,0 +1,186 @@
1
+ describe "An Attrasgn node" do
2
+ relates <<-ruby do
3
+ y = 0
4
+ 42.method = y
5
+ ruby
6
+
7
+ compile do |g|
8
+ g.push 0
9
+ g.set_local 0
10
+ g.pop
11
+ g.push 42
12
+ g.push_local 0
13
+ g.dup
14
+ g.move_down 2
15
+ g.send :method=, 1, false
16
+ g.pop
17
+ end
18
+ end
19
+
20
+ relates "a.m = *[1]" do
21
+ # attrasgn_splat
22
+ end
23
+
24
+ relates "a[*b] = c" do
25
+ compile do |g|
26
+ g.push :self
27
+ g.send :a, 0, true
28
+ g.push :self
29
+ g.send :b, 0, true
30
+ g.cast_array
31
+ g.push :self
32
+ g.send :c, 0, true
33
+ g.dup
34
+ g.move_down 3
35
+ g.swap
36
+ g.push :nil
37
+ g.send_with_splat :[]=, 1, false, true
38
+ g.pop
39
+ end
40
+ end
41
+
42
+ relates "a[b, *c] = d" do
43
+ compile do |g|
44
+ g.push :self
45
+ g.send :a, 0, true
46
+ g.push :self
47
+ g.send :b, 0, true
48
+ g.make_array 1
49
+ g.push :self
50
+ g.send :c, 0, true
51
+ g.cast_array
52
+ g.send :+, 1
53
+ g.push :self
54
+ g.send :d, 0, true
55
+ g.dup
56
+ g.move_down 3
57
+ g.swap
58
+ g.push :nil
59
+ g.send_with_splat :[]=, 1, false, true
60
+ g.pop
61
+ end
62
+ end
63
+
64
+ relates "a[b, *c] = *d" do
65
+ compile do |g|
66
+ g.push :self
67
+ g.send :a, 0, true
68
+ g.push :self
69
+ g.send :b, 0, true
70
+ g.make_array 1
71
+ g.push :self
72
+ g.send :c, 0, true
73
+ g.cast_array
74
+ g.send :+, 1
75
+ g.push :self
76
+ g.send :d, 0, true
77
+ g.cast_array
78
+ g.dup
79
+ g.move_down 3
80
+ g.swap
81
+ g.push :nil
82
+ g.send_with_splat :[]=, 1, false, true
83
+ g.pop
84
+ end
85
+ end
86
+
87
+ relates "a[b, *c] = d, e" do
88
+ compile do |g|
89
+ g.push :self
90
+ g.send :a, 0, true
91
+ g.push :self
92
+ g.send :b, 0, true
93
+ g.make_array 1
94
+ g.push :self
95
+ g.send :c, 0, true
96
+ g.cast_array
97
+ g.send :+, 1
98
+ g.push :self
99
+ g.send :d, 0, true
100
+ g.push :self
101
+ g.send :e, 0, true
102
+ g.make_array 2
103
+ g.dup
104
+ g.move_down 3
105
+ g.swap
106
+ g.push :nil
107
+ g.send_with_splat :[]=, 1, false, true
108
+ g.pop
109
+ end
110
+ end
111
+
112
+ relates "a[42] = 24" do
113
+ compile do |g|
114
+ g.push :self
115
+ g.send :a, 0, true
116
+ g.push 42
117
+ g.push 24
118
+ g.dup
119
+ g.move_down 3
120
+ g.send :[]=, 2, false
121
+ g.pop
122
+ end
123
+ end
124
+
125
+ relates "self[index, 0] = other_string" do
126
+ compile do |g|
127
+ g.push :self
128
+ g.push :self
129
+ g.send :index, 0, true
130
+ g.push 0
131
+ g.push :self
132
+ g.send :other_string, 0, true
133
+ g.dup
134
+ g.move_down 4
135
+ g.send :[]=, 3, true
136
+ g.pop
137
+ end
138
+ end
139
+
140
+ relates <<-ruby do
141
+ a = []
142
+ a [42] = 24
143
+ ruby
144
+
145
+ compile do |g|
146
+ g.make_array 0
147
+ g.set_local 0
148
+ g.pop
149
+ g.push_local 0
150
+ g.push 42
151
+ g.push 24
152
+ g.dup
153
+ g.move_down 3
154
+ g.send :[]=, 2, false
155
+ g.pop
156
+ end
157
+ end
158
+
159
+ ruby_version_is ""..."1.9" do
160
+ relates "m { |a.b| }" do
161
+ compile do |g|
162
+ g.push :self
163
+
164
+ d = new_block_generator(g)
165
+
166
+ d.cast_for_single_block_arg
167
+
168
+ d.push :self
169
+ d.send :a, 0, true
170
+ d.swap
171
+ d.send :b=, 1, false
172
+ d.pop
173
+
174
+ d.push_modifiers
175
+ d.new_label.set!
176
+ d.push :nil
177
+ d.pop_modifiers
178
+ d.ret
179
+
180
+ g.create_block(d)
181
+
182
+ g.send_with_block :m, 0, true
183
+ end
184
+ end
185
+ end
186
+ end