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,152 @@
1
+ describe "A Return node" do
2
+ relates "return" do
3
+ compile do |g|
4
+ g.push :nil
5
+ g.ret
6
+ end
7
+ end
8
+
9
+ relates "return 1" do
10
+ compile do |g|
11
+ g.push 1
12
+ g.ret
13
+ end
14
+ end
15
+
16
+ ruby_version_is ""..."1.9" do
17
+ relates "return *1" do
18
+ compile do |g|
19
+ bottom = g.new_label
20
+
21
+ g.push 1
22
+ g.cast_array
23
+ g.dup
24
+ g.send :size, 0
25
+ g.push 1
26
+ g.send :>, 1
27
+ g.git bottom
28
+
29
+ g.push 0
30
+ g.send :at, 1
31
+
32
+ bottom.set!
33
+
34
+ g.ret
35
+ end
36
+ end
37
+
38
+ relates <<-ruby do
39
+ x = 1, 2
40
+ return *x
41
+ ruby
42
+
43
+ compile do |g|
44
+ g.push 1
45
+ g.push 2
46
+ g.make_array 2
47
+ g.set_local 0
48
+ g.pop
49
+
50
+ bottom = g.new_label
51
+
52
+ g.push_local 0
53
+ g.cast_array
54
+ g.dup
55
+ g.send :size, 0
56
+ g.push 1
57
+ g.send :>, 1
58
+ g.git bottom
59
+
60
+ g.push 0
61
+ g.send :at, 1
62
+
63
+ bottom.set!
64
+
65
+ g.ret
66
+ end
67
+ end
68
+
69
+ relates "return *[1]" do
70
+ compile do |g|
71
+ g.splatted_array
72
+ g.ret
73
+ end
74
+ end
75
+ end
76
+
77
+ ruby_version_is "1.9" do
78
+ relates "return *1" do
79
+ compile do |g|
80
+ bottom = g.new_label
81
+
82
+ g.push 1
83
+ g.cast_array
84
+
85
+ g.ret
86
+ end
87
+ end
88
+
89
+ relates <<-ruby do
90
+ x = 1, 2
91
+ return *x
92
+ ruby
93
+
94
+ compile do |g|
95
+ g.push 1
96
+ g.push 2
97
+ g.make_array 2
98
+ g.set_local 0
99
+ g.pop
100
+
101
+ g.push_local 0
102
+ g.cast_array
103
+
104
+ g.ret
105
+ end
106
+ end
107
+
108
+ relates "return *[1]" do
109
+ compile do |g|
110
+ bottom = g.new_label
111
+
112
+ g.push 1
113
+ g.make_array 1
114
+
115
+ g.ret
116
+ end
117
+ end
118
+ end
119
+
120
+ relates "return 1, 2, 3" do
121
+ compile do |g|
122
+ g.push 1
123
+ g.push 2
124
+ g.push 3
125
+ g.make_array 3
126
+ g.ret
127
+ end
128
+ end
129
+
130
+ relates "return 1, 2, *c" do
131
+ compile do |g|
132
+ g.push 1
133
+ g.push 2
134
+ g.make_array 2
135
+
136
+ g.push :self
137
+ g.send :c, 0, true
138
+ g.cast_array
139
+
140
+ g.send :+, 1
141
+ g.ret
142
+ end
143
+ end
144
+
145
+ relates "return [*[1]]" do
146
+ compile do |g|
147
+ g.push 1
148
+ g.make_array 1
149
+ g.ret
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,138 @@
1
+ describe "An Sclass node" do
2
+ relates <<-ruby do
3
+ class << self
4
+ 42
5
+ end
6
+ ruby
7
+
8
+ compile do |g|
9
+ g.push :self
10
+ g.push_type
11
+ g.swap
12
+ g.send :object_singleton_class, 1
13
+
14
+ d = new_generator(g)
15
+
16
+ g.create_block d
17
+
18
+ d.push_self
19
+ d.add_scope
20
+ d.push 42
21
+ d.ret
22
+
23
+ g.swap
24
+ g.push_scope
25
+ g.push_true
26
+ g.send :call_under, 3
27
+ end
28
+ end
29
+
30
+ relates <<-ruby do
31
+ class A
32
+ class << self
33
+ a
34
+ end
35
+ class B
36
+ end
37
+ end
38
+ ruby
39
+
40
+ compile do |g|
41
+ in_class :A do |d|
42
+
43
+
44
+ d.push :self
45
+ d.push_type
46
+ d.swap
47
+ d.send :object_singleton_class, 1
48
+
49
+ e = new_generator(g)
50
+
51
+ d.create_block(e)
52
+
53
+ e.push_self
54
+ e.add_scope
55
+ e.push :self
56
+ e.send :a, 0, true
57
+ e.ret
58
+
59
+ d.swap
60
+ d.push_scope
61
+ d.push_true
62
+ d.send :call_under, 3
63
+
64
+ d.pop
65
+ d.in_class :B
66
+ d.pop
67
+ d.push :nil
68
+ end
69
+ end
70
+ end
71
+
72
+ relates <<-ruby do
73
+ x = "a"
74
+ class << x
75
+ end
76
+ ruby
77
+
78
+ compile do |g|
79
+ g.push_literal "a"
80
+ g.string_dup
81
+ g.set_local 0
82
+ g.pop
83
+ g.push_local 0
84
+ g.push_type
85
+ g.swap
86
+ g.send :object_singleton_class, 1
87
+ g.pop
88
+ g.push :nil
89
+ end
90
+ end
91
+
92
+ relates <<-ruby do
93
+ x = "a"
94
+ m do
95
+ class << x
96
+ end
97
+ end
98
+ ruby
99
+
100
+ compile do |g|
101
+ g.push_literal "a"
102
+ g.string_dup
103
+ g.set_local 0
104
+ g.pop
105
+
106
+ g.push :self
107
+
108
+ g.in_block_send :m, :none do |d|
109
+ d.push_local_depth 1, 0
110
+ d.push_type
111
+ d.swap
112
+ d.send :object_singleton_class, 1
113
+ d.pop
114
+ d.push :nil
115
+ end
116
+ end
117
+ end
118
+
119
+ relates <<-ruby do
120
+ x = "a"
121
+ class << x
122
+ self
123
+ end
124
+ ruby
125
+
126
+ compile do |g|
127
+ g.push_literal "a"
128
+ g.string_dup
129
+ g.set_local 0
130
+ g.pop
131
+
132
+ g.push_local 0
133
+ g.push_type
134
+ g.swap
135
+ g.send :object_singleton_class, 1
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubinius/bridge'
2
+ require 'rubinius/toolset'
3
+
4
+ Rubinius::ToolSets.create :spec do
5
+ require "rubinius/melbourne"
6
+ require "rubinius/processor"
7
+ require "rubinius/compiler"
8
+ require "rubinius/ast"
9
+
10
+ require 'spec/custom/matchers/compile_as'
11
+ require 'spec/custom/runner/relates'
12
+ end
data/spec/str_spec.rb ADDED
@@ -0,0 +1,118 @@
1
+ describe "A Str node" do
2
+ relates '"x"' do
3
+ compile do |g|
4
+ g.push_literal "x"
5
+ g.string_dup
6
+ end
7
+ end
8
+
9
+ str_concat = lambda do |g|
10
+ g.push_literal "before after"
11
+ g.string_dup
12
+ end
13
+
14
+ relates <<-ruby do
15
+ "before" \
16
+ " after"
17
+ ruby
18
+
19
+ compile(&str_concat)
20
+ end
21
+
22
+ relates '"before" " after"' do
23
+ compile(&str_concat)
24
+ end
25
+
26
+ relates <<-ruby do
27
+ "file = \#{__FILE__}\n"
28
+ ruby
29
+
30
+ compile do |g|
31
+ g.push_literal "file = "
32
+
33
+ g.push_scope
34
+ g.send :active_path, 0
35
+ g.meta_to_s
36
+
37
+ g.push_literal "\n"
38
+
39
+ g.string_build 3
40
+ end
41
+ end
42
+
43
+ relates <<-ruby do
44
+ <<'EOM'.strip
45
+ blah
46
+ blah
47
+ EOM
48
+ ruby
49
+
50
+ compile do |g|
51
+ g.push_literal " blah\nblah\n"
52
+ g.string_dup
53
+ g.send :strip, 0, false
54
+ end
55
+ end
56
+
57
+ relates <<-ruby do
58
+ a += <<-H1 + b + <<-H2
59
+ first
60
+ H1
61
+ second
62
+ H2
63
+ ruby
64
+
65
+ compile do |g|
66
+ g.push_local 0
67
+
68
+ g.push_literal " first\n"
69
+ g.string_dup
70
+
71
+ g.push :self
72
+ g.send :b, 0, true
73
+ g.send :+, 1, false
74
+
75
+ g.push_literal " second\n"
76
+ g.string_dup
77
+
78
+ g.send :+, 1, false
79
+ g.send :+, 1, false
80
+
81
+ g.set_local 0
82
+ end
83
+ end
84
+
85
+ relates <<-ruby do
86
+ <<-EOM
87
+ blah
88
+ blah
89
+
90
+ EOM
91
+ ruby
92
+
93
+ compile do |g|
94
+ g.push_literal " blah\nblah\n\n"
95
+ g.string_dup
96
+ end
97
+ end
98
+
99
+ relates <<-ruby do
100
+ <<'EOM'
101
+ blah
102
+ blah
103
+ EOM
104
+ ruby
105
+
106
+ compile do |g|
107
+ g.push_literal " blah\nblah\n"
108
+ g.string_dup
109
+ end
110
+ end
111
+
112
+ relates "%(blah)" do
113
+ compile do |g|
114
+ g.push_literal "blah"
115
+ g.string_dup
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,170 @@
1
+ describe "A Super node" do
2
+ relates <<-ruby do
3
+ def x
4
+ super()
5
+ end
6
+ ruby
7
+
8
+ compile do |g|
9
+ in_method :x do |d|
10
+ d.push_block
11
+ d.send_super :x, 0
12
+ end
13
+ end
14
+ end
15
+
16
+ relates <<-ruby do
17
+ def x(&block)
18
+ super(&block)
19
+ end
20
+ ruby
21
+
22
+ compile do |g|
23
+ in_method :x do |d|
24
+ d.block_arg 0
25
+
26
+ is_nil = d.new_label
27
+ d.push_local 0
28
+ d.dup
29
+ d.is_nil
30
+ d.git is_nil
31
+ d.push_cpath_top
32
+ d.find_const :Proc
33
+ d.swap
34
+ d.send :__from_block__, 1
35
+ is_nil.set!
36
+ d.send_super :x, 0
37
+ end
38
+ end
39
+ end
40
+
41
+ relates <<-ruby do
42
+ def x
43
+ super([24, 42])
44
+ end
45
+ ruby
46
+
47
+ compile do |g|
48
+ in_method :x do |d|
49
+ d.push 24
50
+ d.push 42
51
+ d.make_array 2
52
+ d.push_block
53
+ d.send_super :x, 1
54
+ end
55
+ end
56
+ end
57
+
58
+ relates <<-ruby do
59
+ def x
60
+ super(4)
61
+ end
62
+ ruby
63
+
64
+ compile do |g|
65
+ in_method :x do |d|
66
+ d.push 4
67
+ d.push_block
68
+ d.send_super :x, 1
69
+ end
70
+ end
71
+ end
72
+
73
+ relates "super(a, &b)" do
74
+ compile do |g|
75
+ t = g.new_label
76
+
77
+ g.push :self
78
+ g.send :a, 0, true
79
+
80
+ g.push :self
81
+ g.send :b, 0, true
82
+
83
+ g.dup
84
+ g.is_nil
85
+ g.git t
86
+
87
+ g.push_cpath_top
88
+ g.find_const :Proc
89
+ g.swap
90
+
91
+ g.send :__from_block__, 1
92
+
93
+ t.set!
94
+
95
+ # nil here because the test isn't wrapped in a method, so
96
+ # there is no current method to pull the name of the method
97
+ # from
98
+ g.send_super nil, 1
99
+ end
100
+ end
101
+
102
+ relates "super(a, *b)" do
103
+ compile do |g|
104
+ g.push :self
105
+ g.send :a, 0, true
106
+
107
+ g.push :self
108
+ g.send :b, 0, true
109
+
110
+ g.cast_array
111
+
112
+ g.push_block
113
+
114
+ # nil here because the test isn't wrapped in a method, so
115
+ # there is no current method to pull the name of the method
116
+ # from
117
+ g.send_super nil, 1, true
118
+ end
119
+ end
120
+
121
+ relates <<-ruby do
122
+ def f(*)
123
+ super
124
+ end
125
+ ruby
126
+
127
+ compile do |g|
128
+ in_method :f do |d|
129
+ d.push_block
130
+ d.zsuper :f
131
+ end
132
+ end
133
+ end
134
+
135
+ relates <<-ruby do
136
+ def x
137
+ super(24, 42)
138
+ end
139
+ ruby
140
+
141
+ compile do |g|
142
+ in_method :x do |d|
143
+ d.push 24
144
+ d.push 42
145
+ d.push_block
146
+ d.send_super :x, 2
147
+ end
148
+ end
149
+ end
150
+
151
+ relates "super([*[1]])" do
152
+ compile do |g|
153
+ g.push 1
154
+ g.make_array 1
155
+ g.push_block
156
+ g.send_super nil, 1
157
+ end
158
+ end
159
+
160
+ relates "super(*[1])" do
161
+ compile do |g|
162
+ g.push 1
163
+ g.make_array 1
164
+ g.cast_array
165
+
166
+ g.push_block
167
+ g.send_super nil, 0, true
168
+ end
169
+ end
170
+ end