ruby2c 1.0.0.9 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +1 -1
- data/History.txt +71 -53
- data/README.txt +1 -1
- data/Rakefile +2 -0
- data/lib/crewriter.rb +35 -23
- data/lib/r2cenvironment.rb +3 -3
- data/lib/rewriter.rb +2 -2
- data/lib/ruby_to_ansi_c.rb +14 -18
- data/lib/ruby_to_ruby_c.rb +3 -3
- data/lib/type.rb +3 -3
- data/lib/type_checker.rb +97 -99
- data/lib/typed_sexp.rb +49 -25
- data/test/r2ctestcase.rb +321 -288
- data/test/test_crewriter.rb +127 -128
- data/test/test_extras.rb +4 -4
- data/test/test_function_table.rb +23 -23
- data/test/test_function_type.rb +39 -40
- data/test/test_handle.rb +2 -2
- data/test/test_r2cenvironment.rb +38 -38
- data/test/test_ruby_to_ansi_c.rb +58 -58
- data/test/test_ruby_to_ruby_c.rb +26 -26
- data/test/test_type.rb +38 -38
- data/test/test_type_checker.rb +165 -165
- data/test/test_typed_sexp.rb +62 -54
- metadata +97 -150
- metadata.gz.sig +0 -0
- data/.gemtest +0 -0
data/test/test_type.rb
CHANGED
@@ -3,16 +3,16 @@
|
|
3
3
|
$TESTING = true
|
4
4
|
|
5
5
|
require 'minitest/autorun' if $0 == __FILE__
|
6
|
-
require 'minitest/
|
6
|
+
require 'minitest/test'
|
7
7
|
require 'type'
|
8
8
|
require 'sexp_processor' # for deep clone FIX ?
|
9
9
|
|
10
|
-
class
|
10
|
+
class TestCType < Minitest::Test
|
11
11
|
def setup
|
12
|
-
@unknown =
|
13
|
-
@unknown_list =
|
14
|
-
@long =
|
15
|
-
@long_list =
|
12
|
+
@unknown = CType.unknown
|
13
|
+
@unknown_list = CType.unknown_list
|
14
|
+
@long = CType.long
|
15
|
+
@long_list = CType.new(:long, true)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_function?
|
@@ -20,7 +20,7 @@ class TestType < MiniTest::Unit::TestCase
|
|
20
20
|
assert ! @long_list.function?
|
21
21
|
assert ! @unknown.function?
|
22
22
|
assert ! @unknown_list.function?
|
23
|
-
assert
|
23
|
+
assert CType.function(CType.str, [CType.str], CType.str).function?
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_list
|
@@ -29,8 +29,8 @@ class TestType < MiniTest::Unit::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_list=
|
32
|
-
long =
|
33
|
-
long_list =
|
32
|
+
long = CType.long.deep_clone
|
33
|
+
long_list = CType.long_list.deep_clone
|
34
34
|
|
35
35
|
long.list = true
|
36
36
|
long_list.list = false
|
@@ -45,36 +45,36 @@ class TestType < MiniTest::Unit::TestCase
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_type_good
|
48
|
-
file =
|
49
|
-
assert_kind_of
|
48
|
+
file = CType.file
|
49
|
+
assert_kind_of CType, file
|
50
50
|
assert_equal :file, file.type.contents
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_type_bad
|
54
54
|
assert_raises(RuntimeError) do
|
55
|
-
|
55
|
+
CType.blahblah
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_type=
|
60
|
-
long =
|
60
|
+
long = CType.long.deep_clone
|
61
61
|
long.type = "something"
|
62
62
|
assert_equal "something", long.type
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_unknown_types
|
66
66
|
assert_raises(RuntimeError) do
|
67
|
-
|
67
|
+
CType.new(:some_made_up_type)
|
68
68
|
end
|
69
69
|
|
70
70
|
assert_raises(RuntimeError) do
|
71
|
-
|
71
|
+
CType.some_made_up_type
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_function
|
76
|
-
|
77
|
-
|
76
|
+
skip "actually TEST something here"
|
77
|
+
CType.function([CType.unknown], CType.unknown)
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_list_type
|
@@ -82,20 +82,20 @@ class TestType < MiniTest::Unit::TestCase
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_equals
|
85
|
-
type =
|
85
|
+
type = CType.long
|
86
86
|
refute_equal @unknown, type
|
87
87
|
assert_equal @long, type
|
88
88
|
refute_equal @long_list, type
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_hash
|
92
|
-
long1 =
|
93
|
-
long2 =
|
92
|
+
long1 = CType.long
|
93
|
+
long2 = CType.long
|
94
94
|
|
95
|
-
a =
|
95
|
+
a = CType.unknown
|
96
96
|
a.unify long1
|
97
97
|
|
98
|
-
b =
|
98
|
+
b = CType.unknown
|
99
99
|
b.unify long2
|
100
100
|
|
101
101
|
assert a == b, "=="
|
@@ -107,7 +107,7 @@ class TestType < MiniTest::Unit::TestCase
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def test_list_equal
|
110
|
-
type =
|
110
|
+
type = CType.new(:long, true)
|
111
111
|
refute_equal @unknown, type
|
112
112
|
refute_equal @long, type
|
113
113
|
assert_equal @long_list, type
|
@@ -119,20 +119,20 @@ class TestType < MiniTest::Unit::TestCase
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def test_unknown?
|
122
|
-
assert_equal
|
123
|
-
refute_same
|
122
|
+
assert_equal CType.unknown, CType.unknown
|
123
|
+
refute_same CType.unknown, CType.unknown
|
124
124
|
end
|
125
125
|
|
126
126
|
def test_unknown_list
|
127
|
-
assert_equal @unknown_list,
|
128
|
-
refute_same
|
127
|
+
assert_equal @unknown_list, CType.unknown_list
|
128
|
+
refute_same CType.unknown_list, CType.unknown_list
|
129
129
|
assert @unknown_list.list?
|
130
130
|
end
|
131
131
|
|
132
132
|
def test_unify_fail
|
133
|
-
long =
|
134
|
-
string =
|
135
|
-
long_list =
|
133
|
+
long = CType.new(:long)
|
134
|
+
string = CType.new(:str)
|
135
|
+
long_list = CType.new(:long, true)
|
136
136
|
|
137
137
|
assert_raises(TypeError) do
|
138
138
|
long.unify string
|
@@ -144,8 +144,8 @@ class TestType < MiniTest::Unit::TestCase
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def test_unify_simple
|
147
|
-
long =
|
148
|
-
unknown =
|
147
|
+
long = CType.new(:long)
|
148
|
+
unknown = CType.unknown
|
149
149
|
|
150
150
|
assert_equal @long, long
|
151
151
|
|
@@ -157,8 +157,8 @@ class TestType < MiniTest::Unit::TestCase
|
|
157
157
|
end
|
158
158
|
|
159
159
|
def test_unify_list
|
160
|
-
long_list =
|
161
|
-
unknown =
|
160
|
+
long_list = CType.new(:long, true)
|
161
|
+
unknown = CType.unknown
|
162
162
|
|
163
163
|
assert_equal @long_list, long_list
|
164
164
|
|
@@ -170,9 +170,9 @@ class TestType < MiniTest::Unit::TestCase
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_unify_link
|
173
|
-
unknown1 =
|
174
|
-
unknown2 =
|
175
|
-
long =
|
173
|
+
unknown1 = CType.unknown
|
174
|
+
unknown2 = CType.unknown
|
175
|
+
long = CType.new(:long)
|
176
176
|
|
177
177
|
unknown1.unify unknown2
|
178
178
|
assert_same(unknown1.type, unknown2.type,
|
@@ -185,7 +185,7 @@ class TestType < MiniTest::Unit::TestCase
|
|
185
185
|
end
|
186
186
|
|
187
187
|
def test_unify_function
|
188
|
-
fun =
|
188
|
+
fun = CType.function [CType.unknown], CType.unknown
|
189
189
|
@unknown.unify fun
|
190
190
|
assert_equal fun, @unknown
|
191
191
|
end
|
data/test/test_type_checker.rb
CHANGED
@@ -19,18 +19,18 @@ class TestTypeChecker < R2CTestCase
|
|
19
19
|
def setup
|
20
20
|
@type_checker = TypeChecker.new
|
21
21
|
@processor = @type_checker
|
22
|
-
@type_checker.env.add :argl,
|
23
|
-
@type_checker.env.add :args,
|
24
|
-
@type_checker.env.add :arrayl,
|
25
|
-
@type_checker.env.add :arrayl2,
|
26
|
-
@type_checker.env.add :arrays,
|
27
|
-
@type_checker.genv.add :SyntaxError,
|
28
|
-
@type_checker.genv.add :Exception,
|
22
|
+
@type_checker.env.add :argl, CType.long
|
23
|
+
@type_checker.env.add :args, CType.str
|
24
|
+
@type_checker.env.add :arrayl, CType.long_list
|
25
|
+
@type_checker.env.add :arrayl2, CType.long_list
|
26
|
+
@type_checker.env.add :arrays, CType.str_list
|
27
|
+
@type_checker.genv.add :SyntaxError, CType.fucked
|
28
|
+
@type_checker.genv.add :Exception, CType.fucked
|
29
29
|
|
30
30
|
# HACK
|
31
|
-
@type_checker.genv.add :$stdin,
|
32
|
-
@type_checker.genv.add :$stdout,
|
33
|
-
@type_checker.genv.add :$stderr,
|
31
|
+
@type_checker.genv.add :$stdin, CType.file
|
32
|
+
@type_checker.genv.add :$stdout, CType.file
|
33
|
+
@type_checker.genv.add :$stderr, CType.file
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_bootstrap
|
@@ -38,46 +38,46 @@ class TestTypeChecker < R2CTestCase
|
|
38
38
|
# TODO should we check for EVERYTHING we expect?
|
39
39
|
|
40
40
|
# HACK
|
41
|
-
# assert_equal
|
42
|
-
# assert_equal
|
43
|
-
# assert_equal
|
41
|
+
# assert_equal CType.file, @type_checker.genv.lookup(:$stdin)
|
42
|
+
# assert_equal CType.file, @type_checker.genv.lookup(:$stdout)
|
43
|
+
# assert_equal CType.file, @type_checker.genv.lookup(:$stderr)
|
44
44
|
|
45
|
-
assert_equal(
|
45
|
+
assert_equal(CType.function(CType.long, [CType.long], CType.bool),
|
46
46
|
@type_checker.functions[:>])
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_defn_call_unify
|
50
50
|
# pre-registered function, presumibly through another :call elsewhere
|
51
|
-
add_fake_function :specific,
|
51
|
+
add_fake_function :specific, CType.unknown, CType.unknown, CType.unknown
|
52
52
|
|
53
53
|
# now in specific, unify with a long
|
54
|
-
|
54
|
+
_ = @type_checker.process(s(:defn, :specific,
|
55
55
|
s(:args, :x),
|
56
56
|
s(:scope,
|
57
57
|
s(:block,
|
58
58
|
s(:lasgn, :x, s(:lit, 2))))))
|
59
59
|
s_type = @type_checker.functions[:specific]
|
60
60
|
|
61
|
-
assert_equal(
|
61
|
+
assert_equal(CType.long,
|
62
62
|
s_type.list_type.formal_types[0])
|
63
63
|
# HACK flunk "eric hasn't finished writing me yet. guilt. guilt. guilt."
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_env
|
67
|
-
@type_checker.env.add :blah,
|
68
|
-
assert_equal
|
67
|
+
@type_checker.env.add :blah, CType.long
|
68
|
+
assert_equal CType.long, @type_checker.env.lookup(:blah)
|
69
69
|
end
|
70
70
|
|
71
71
|
def test_functions
|
72
72
|
# bootstrap populates functions
|
73
73
|
assert @type_checker.functions.has_key?(:puts)
|
74
|
-
assert_equal(
|
74
|
+
assert_equal(CType.function(CType.long, [CType.long], CType.bool),
|
75
75
|
@type_checker.functions[:>])
|
76
76
|
end
|
77
77
|
|
78
78
|
# HACK
|
79
79
|
# def test_genv
|
80
|
-
# assert_equal
|
80
|
+
# assert_equal CType.file, @type_checker.genv.lookup(:$stderr)
|
81
81
|
# end
|
82
82
|
|
83
83
|
def test_process_args
|
@@ -85,8 +85,8 @@ class TestTypeChecker < R2CTestCase
|
|
85
85
|
|
86
86
|
input = t(:args, :foo, :bar)
|
87
87
|
output = t(:args,
|
88
|
-
t(:foo,
|
89
|
-
t(:bar,
|
88
|
+
t(:foo, CType.unknown),
|
89
|
+
t(:bar, CType.unknown))
|
90
90
|
|
91
91
|
assert_equal output, @type_checker.process(input)
|
92
92
|
end
|
@@ -100,27 +100,27 @@ class TestTypeChecker < R2CTestCase
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def test_process_array_multiple
|
103
|
-
add_fake_var :arg1,
|
104
|
-
add_fake_var :arg2,
|
103
|
+
add_fake_var :arg1, CType.long
|
104
|
+
add_fake_var :arg2, CType.str
|
105
105
|
|
106
106
|
input = t(:array, t(:lvar, :arg1), t(:lvar, :arg2))
|
107
107
|
output = t(:array,
|
108
|
-
t(:lvar, :arg1,
|
109
|
-
t(:lvar, :arg2,
|
108
|
+
t(:lvar, :arg1, CType.long),
|
109
|
+
t(:lvar, :arg2, CType.str))
|
110
110
|
|
111
111
|
assert_equal output, @type_checker.process(input)
|
112
112
|
end
|
113
113
|
|
114
114
|
def test_process_array_single
|
115
|
-
add_fake_var :arg1,
|
115
|
+
add_fake_var :arg1, CType.long
|
116
116
|
|
117
117
|
input = t(:array, t(:lvar, :arg1))
|
118
|
-
output = t(:array, t(:lvar, :arg1,
|
118
|
+
output = t(:array, t(:lvar, :arg1, CType.long))
|
119
119
|
|
120
120
|
result = @type_checker.process(input)
|
121
121
|
|
122
|
-
assert_equal
|
123
|
-
assert_equal [
|
122
|
+
assert_equal CType.homo, result.c_type
|
123
|
+
assert_equal [ CType.long ], result.c_types
|
124
124
|
assert_equal output, result
|
125
125
|
end
|
126
126
|
|
@@ -129,9 +129,9 @@ class TestTypeChecker < R2CTestCase
|
|
129
129
|
# FIX: should this really be void for return?
|
130
130
|
output = t(:block,
|
131
131
|
t(:return,
|
132
|
-
t(:nil,
|
133
|
-
|
134
|
-
|
132
|
+
t(:nil, CType.value),
|
133
|
+
CType.void),
|
134
|
+
CType.unknown)
|
135
135
|
|
136
136
|
assert_equal output, @type_checker.process(input)
|
137
137
|
end
|
@@ -141,51 +141,51 @@ class TestTypeChecker < R2CTestCase
|
|
141
141
|
t(:str, :foo),
|
142
142
|
t(:return, t(:nil)))
|
143
143
|
output = t(:block,
|
144
|
-
t(:str, :foo,
|
144
|
+
t(:str, :foo, CType.str),
|
145
145
|
t(:return,
|
146
|
-
t(:nil,
|
147
|
-
|
148
|
-
|
146
|
+
t(:nil, CType.value),
|
147
|
+
CType.void),
|
148
|
+
CType.unknown)
|
149
149
|
|
150
150
|
assert_equal output, @type_checker.process(input)
|
151
151
|
end
|
152
152
|
|
153
153
|
def test_process_call_case_equal_long
|
154
|
-
add_fake_var :number,
|
154
|
+
add_fake_var :number, CType.unknown
|
155
155
|
|
156
156
|
input = t(:call,
|
157
157
|
t(:lit, 1),
|
158
158
|
:===,
|
159
159
|
t(:arglist, t(:lvar, :number)))
|
160
160
|
output = t(:call,
|
161
|
-
t(:lit, 1,
|
161
|
+
t(:lit, 1, CType.long),
|
162
162
|
:case_equal_long,
|
163
163
|
t(:arglist,
|
164
|
-
t(:lvar, :number,
|
165
|
-
|
164
|
+
t(:lvar, :number, CType.long)),
|
165
|
+
CType.bool)
|
166
166
|
|
167
167
|
assert_equal output, @type_checker.process(input)
|
168
168
|
end
|
169
169
|
|
170
170
|
def test_process_call_case_equal_string
|
171
|
-
add_fake_var :string,
|
171
|
+
add_fake_var :string, CType.unknown
|
172
172
|
|
173
173
|
input = t(:call,
|
174
174
|
t(:str, 'foo'),
|
175
175
|
:===,
|
176
176
|
t(:arglist, t(:lvar, :string)))
|
177
177
|
output = t(:call,
|
178
|
-
t(:str, 'foo',
|
178
|
+
t(:str, 'foo', CType.str),
|
179
179
|
:case_equal_str,
|
180
180
|
t(:arglist,
|
181
|
-
t(:lvar, :string,
|
182
|
-
|
181
|
+
t(:lvar, :string, CType.str)),
|
182
|
+
CType.bool)
|
183
183
|
|
184
184
|
assert_equal output, @type_checker.process(input)
|
185
185
|
end
|
186
186
|
|
187
187
|
def test_process_call_defined
|
188
|
-
add_fake_function :name,
|
188
|
+
add_fake_function :name, CType.void, CType.long, CType.str
|
189
189
|
input = t(:call,
|
190
190
|
nil,
|
191
191
|
:name,
|
@@ -193,68 +193,68 @@ class TestTypeChecker < R2CTestCase
|
|
193
193
|
output = t(:call,
|
194
194
|
nil,
|
195
195
|
:name,
|
196
|
-
t(:arglist, t(:str, "foo",
|
197
|
-
|
196
|
+
t(:arglist, t(:str, "foo", CType.str)),
|
197
|
+
CType.long)
|
198
198
|
|
199
199
|
assert_equal output, @type_checker.process(input)
|
200
200
|
end
|
201
201
|
|
202
202
|
def test_process_call_defined_rhs
|
203
|
-
add_fake_function :name3,
|
203
|
+
add_fake_function :name3, CType.long, CType.long, CType.str
|
204
204
|
input = t(:call,
|
205
205
|
t(:lit, 1),
|
206
206
|
:name3,
|
207
207
|
t(:arglist, t(:str, "foo")))
|
208
208
|
output = t(:call,
|
209
|
-
t(:lit, 1,
|
209
|
+
t(:lit, 1, CType.long),
|
210
210
|
:name3,
|
211
|
-
t(:arglist, t(:str, "foo",
|
212
|
-
|
211
|
+
t(:arglist, t(:str, "foo", CType.str)),
|
212
|
+
CType.long)
|
213
213
|
|
214
214
|
assert_equal output, @type_checker.process(input)
|
215
215
|
end
|
216
216
|
|
217
217
|
def test_process_call_undefined
|
218
218
|
input = t(:call, nil, :name)
|
219
|
-
output = t(:call, nil, :name, t(:arglist),
|
219
|
+
output = t(:call, nil, :name, t(:arglist), CType.unknown)
|
220
220
|
|
221
221
|
assert_equal output, @type_checker.process(input)
|
222
222
|
# FIX returns unknown in s()
|
223
|
-
assert_equal(
|
223
|
+
assert_equal(CType.function(CType.unknown, [], CType.unknown),
|
224
224
|
@type_checker.functions[:name])
|
225
225
|
end
|
226
226
|
|
227
227
|
def test_process_call_unify_1
|
228
|
-
add_fake_var :number,
|
228
|
+
add_fake_var :number, CType.long
|
229
229
|
input = t(:call,
|
230
230
|
t(:lit, 1),
|
231
231
|
:==,
|
232
232
|
t(:arglist,
|
233
233
|
t(:lvar, :number)))
|
234
234
|
output = t(:call,
|
235
|
-
t(:lit, 1,
|
235
|
+
t(:lit, 1, CType.long),
|
236
236
|
:==,
|
237
237
|
t(:arglist,
|
238
|
-
t(:lvar, :number,
|
239
|
-
|
238
|
+
t(:lvar, :number, CType.long)),
|
239
|
+
CType.bool)
|
240
240
|
|
241
241
|
assert_equal output, @type_checker.process(input)
|
242
242
|
end
|
243
243
|
|
244
244
|
def test_process_call_unify_2
|
245
|
-
add_fake_var :number1,
|
246
|
-
add_fake_var :number2,
|
245
|
+
add_fake_var :number1, CType.unknown
|
246
|
+
add_fake_var :number2, CType.unknown
|
247
247
|
|
248
248
|
input = t(:call,
|
249
249
|
t(:lit, 1),
|
250
250
|
:==,
|
251
251
|
t(:arglist, t(:lvar, :number1)))
|
252
252
|
output = t(:call,
|
253
|
-
t(:lit, 1,
|
253
|
+
t(:lit, 1, CType.long),
|
254
254
|
:==,
|
255
255
|
t(:arglist,
|
256
|
-
t(:lvar, :number1,
|
257
|
-
|
256
|
+
t(:lvar, :number1, CType.long)),
|
257
|
+
CType.bool)
|
258
258
|
|
259
259
|
assert_equal output, @type_checker.process(input)
|
260
260
|
|
@@ -263,18 +263,18 @@ class TestTypeChecker < R2CTestCase
|
|
263
263
|
:==,
|
264
264
|
t(:arglist, t(:lit, 1)))
|
265
265
|
output = t(:call,
|
266
|
-
t(:lvar, :number2,
|
266
|
+
t(:lvar, :number2, CType.long),
|
267
267
|
:==,
|
268
268
|
t(:arglist,
|
269
|
-
t(:lit, 1,
|
270
|
-
|
269
|
+
t(:lit, 1, CType.long)),
|
270
|
+
CType.bool)
|
271
271
|
|
272
272
|
assert_equal output, @type_checker.process(input)
|
273
273
|
end
|
274
274
|
|
275
275
|
def test_process_call_unify_3
|
276
|
-
a_type =
|
277
|
-
add_fake_var :a, a_type # TODO:
|
276
|
+
a_type = CType.unknown
|
277
|
+
add_fake_var :a, a_type # TODO: CType.unknown
|
278
278
|
|
279
279
|
# def unify_3_outer(a)
|
280
280
|
#
|
@@ -284,7 +284,7 @@ class TestTypeChecker < R2CTestCase
|
|
284
284
|
# outer(., ., [+])
|
285
285
|
|
286
286
|
# assume the environment got everything set up correctly
|
287
|
-
add_fake_function(:unify_3_outer,
|
287
|
+
add_fake_function(:unify_3_outer, CType.void, CType.void, a_type)
|
288
288
|
|
289
289
|
assert_equal(a_type,
|
290
290
|
@type_checker.functions[:unify_3_outer].list_type.formal_types[0])
|
@@ -325,7 +325,7 @@ class TestTypeChecker < R2CTestCase
|
|
325
325
|
@type_checker.process t(:lasgn, :a, t(:lit, 1))
|
326
326
|
end
|
327
327
|
|
328
|
-
assert_equal a_type,
|
328
|
+
assert_equal a_type, CType.long
|
329
329
|
|
330
330
|
assert_equal(@type_checker.functions[:unify_3_inner].list_type.formal_types[0],
|
331
331
|
@type_checker.functions[:unify_3_outer].list_type.formal_types[0])
|
@@ -341,16 +341,16 @@ class TestTypeChecker < R2CTestCase
|
|
341
341
|
s(:lasgn, :x, s(:const, :VALUE))))))
|
342
342
|
output = t(:class, :X, :Object,
|
343
343
|
t(:defn, :meth,
|
344
|
-
t(:args, t(:x,
|
344
|
+
t(:args, t(:x, CType.long)),
|
345
345
|
t(:scope,
|
346
346
|
t(:block,
|
347
347
|
t(:lasgn, :x,
|
348
|
-
t(:const, :VALUE,
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
348
|
+
t(:const, :VALUE, CType.long),
|
349
|
+
CType.long),
|
350
|
+
CType.unknown),
|
351
|
+
CType.void),
|
352
|
+
CType.function(CType.unknown, [CType.long], CType.void)),
|
353
|
+
CType.zclass)
|
354
354
|
|
355
355
|
assert_equal output, @type_checker.process(input)
|
356
356
|
end
|
@@ -363,14 +363,14 @@ class TestTypeChecker < R2CTestCase
|
|
363
363
|
|
364
364
|
def test_process_cvar
|
365
365
|
input = s(:cvar, :name)
|
366
|
-
output = t(:cvar, :name,
|
366
|
+
output = t(:cvar, :name, CType.unknown)
|
367
367
|
|
368
368
|
assert_equal output, @type_checker.process(input)
|
369
369
|
end
|
370
370
|
|
371
371
|
def test_process_cvasgn
|
372
372
|
input = s(:cvasgn, :name, s(:lit, 4))
|
373
|
-
output = t(:cvasgn, :name, t(:lit, 4,
|
373
|
+
output = t(:cvasgn, :name, t(:lit, 4, CType.long), CType.unknown)
|
374
374
|
|
375
375
|
assert_equal output, @type_checker.process(input)
|
376
376
|
end
|
@@ -378,15 +378,15 @@ class TestTypeChecker < R2CTestCase
|
|
378
378
|
def test_process_dasgn_curr
|
379
379
|
@type_checker.env.extend
|
380
380
|
input = t(:dasgn_curr, :x)
|
381
|
-
output = t(:dasgn_curr, :x,
|
381
|
+
output = t(:dasgn_curr, :x, CType.unknown)
|
382
382
|
|
383
383
|
assert_equal output, @type_checker.process(input)
|
384
384
|
# HACK: is this a valid test??? it was in ruby_to_c:
|
385
|
-
# assert_equal
|
385
|
+
# assert_equal CType.long, @type_checker.env.lookup(:x)
|
386
386
|
end
|
387
387
|
|
388
388
|
def test_process_defn
|
389
|
-
function_type =
|
389
|
+
function_type = CType.function s(), CType.void
|
390
390
|
input = t(:defn,
|
391
391
|
:empty,
|
392
392
|
t(:args),
|
@@ -394,66 +394,66 @@ class TestTypeChecker < R2CTestCase
|
|
394
394
|
output = t(:defn,
|
395
395
|
:empty,
|
396
396
|
t(:args),
|
397
|
-
t(:scope,
|
397
|
+
t(:scope, CType.void),
|
398
398
|
function_type)
|
399
399
|
|
400
400
|
assert_equal output, @type_checker.process(input)
|
401
401
|
end
|
402
402
|
|
403
403
|
def test_process_dstr
|
404
|
-
add_fake_var :var,
|
404
|
+
add_fake_var :var, CType.str
|
405
405
|
input = t(:dstr,
|
406
406
|
"var is ",
|
407
407
|
t(:lvar, :var),
|
408
408
|
t(:str, ". So there."))
|
409
409
|
output = t(:dstr, "var is ",
|
410
|
-
t(:lvar, :var,
|
411
|
-
t(:str, ". So there.",
|
412
|
-
|
410
|
+
t(:lvar, :var, CType.str),
|
411
|
+
t(:str, ". So there.", CType.str),
|
412
|
+
CType.str)
|
413
413
|
|
414
414
|
assert_equal output, @type_checker.process(input)
|
415
415
|
end
|
416
416
|
|
417
417
|
def test_process_dvar
|
418
|
-
add_fake_var :dvar,
|
418
|
+
add_fake_var :dvar, CType.long
|
419
419
|
input = t(:dvar, :dvar)
|
420
|
-
output = t(:dvar, :dvar,
|
420
|
+
output = t(:dvar, :dvar, CType.long)
|
421
421
|
|
422
422
|
assert_equal output, @type_checker.process(input)
|
423
423
|
end
|
424
424
|
|
425
425
|
def test_process_false
|
426
426
|
input = t(:false)
|
427
|
-
output = t(:false,
|
427
|
+
output = t(:false, CType.bool)
|
428
428
|
|
429
429
|
assert_equal output, @type_checker.process(input)
|
430
430
|
end
|
431
431
|
|
432
432
|
def test_process_gasgn
|
433
433
|
input = s(:gasgn, :$blah, s(:lit, 42))
|
434
|
-
expected = t(:gasgn, :$blah, t(:lit, 42,
|
434
|
+
expected = t(:gasgn, :$blah, t(:lit, 42, CType.long), CType.long)
|
435
435
|
|
436
436
|
assert_equal expected, @type_checker.process(input)
|
437
437
|
end
|
438
438
|
|
439
439
|
def test_process_gvar_defined
|
440
|
-
add_fake_gvar :$arg,
|
440
|
+
add_fake_gvar :$arg, CType.long
|
441
441
|
input = t(:gvar, :$arg)
|
442
|
-
output = t(:gvar, :$arg,
|
442
|
+
output = t(:gvar, :$arg, CType.long)
|
443
443
|
|
444
444
|
assert_equal output, @type_checker.process(input)
|
445
445
|
end
|
446
446
|
|
447
447
|
def test_process_gvar_undefined
|
448
448
|
input = t(:gvar, :$arg)
|
449
|
-
output = t(:gvar, :$arg,
|
449
|
+
output = t(:gvar, :$arg, CType.unknown)
|
450
450
|
|
451
451
|
assert_equal output, @type_checker.process(input)
|
452
452
|
end
|
453
453
|
|
454
454
|
def test_process_iasgn
|
455
455
|
input = s(:iasgn, :@blah, s(:lit, 42))
|
456
|
-
expected = t(:iasgn, :@blah, t(:lit, 42,
|
456
|
+
expected = t(:iasgn, :@blah, t(:lit, 42, CType.long), CType.long)
|
457
457
|
|
458
458
|
assert_equal expected, @type_checker.process(input)
|
459
459
|
end
|
@@ -468,14 +468,14 @@ class TestTypeChecker < R2CTestCase
|
|
468
468
|
nil)
|
469
469
|
output = t(:if,
|
470
470
|
t(:call,
|
471
|
-
t(:lit, 1,
|
471
|
+
t(:lit, 1, CType.long),
|
472
472
|
:==,
|
473
473
|
t(:arglist,
|
474
|
-
t(:lit, 2,
|
475
|
-
|
476
|
-
t(:str, "not equal",
|
474
|
+
t(:lit, 2, CType.long)),
|
475
|
+
CType.bool),
|
476
|
+
t(:str, "not equal", CType.str),
|
477
477
|
nil,
|
478
|
-
|
478
|
+
CType.str)
|
479
479
|
|
480
480
|
assert_equal output, @type_checker.process(input)
|
481
481
|
end
|
@@ -490,20 +490,20 @@ class TestTypeChecker < R2CTestCase
|
|
490
490
|
t(:str, "equal"))
|
491
491
|
output = t(:if,
|
492
492
|
t(:call,
|
493
|
-
t(:lit, 1,
|
493
|
+
t(:lit, 1, CType.long),
|
494
494
|
:==,
|
495
|
-
t(:arglist, t(:lit, 2,
|
496
|
-
|
497
|
-
t(:str, "not equal",
|
498
|
-
t(:str, "equal",
|
499
|
-
|
495
|
+
t(:arglist, t(:lit, 2, CType.long)),
|
496
|
+
CType.bool),
|
497
|
+
t(:str, "not equal", CType.str),
|
498
|
+
t(:str, "equal", CType.str),
|
499
|
+
CType.str)
|
500
500
|
|
501
501
|
assert_equal output, @type_checker.process(input)
|
502
502
|
end
|
503
503
|
|
504
504
|
def test_process_iter
|
505
505
|
@type_checker.env.extend
|
506
|
-
var_type =
|
506
|
+
var_type = CType.long_list
|
507
507
|
add_fake_var :array, var_type
|
508
508
|
input = t(:iter,
|
509
509
|
t(:call,
|
@@ -524,27 +524,27 @@ class TestTypeChecker < R2CTestCase
|
|
524
524
|
t(:lvar, :array, var_type),
|
525
525
|
:each,
|
526
526
|
t(:arglist),
|
527
|
-
|
528
|
-
t(:args, t(:lasgn, :x, nil,
|
527
|
+
CType.unknown),
|
528
|
+
t(:args, t(:lasgn, :x, nil, CType.long)),
|
529
529
|
t(:call,
|
530
530
|
nil,
|
531
531
|
:puts,
|
532
532
|
t(:arglist,
|
533
533
|
t(:call,
|
534
|
-
t(:dvar, :x,
|
534
|
+
t(:dvar, :x, CType.long),
|
535
535
|
:to_s,
|
536
536
|
t(:arglist),
|
537
|
-
|
538
|
-
|
539
|
-
|
537
|
+
CType.str)),
|
538
|
+
CType.void),
|
539
|
+
CType.void)
|
540
540
|
|
541
541
|
assert_equal output, @type_checker.process(input)
|
542
542
|
end
|
543
543
|
|
544
544
|
def test_process_ivar
|
545
|
-
@type_checker.env.add :@blah,
|
545
|
+
@type_checker.env.add :@blah, CType.long
|
546
546
|
input = s(:ivar, :@blah)
|
547
|
-
expected = t(:ivar, :@blah,
|
547
|
+
expected = t(:ivar, :@blah, CType.long)
|
548
548
|
|
549
549
|
assert_equal expected, @type_checker.process(input)
|
550
550
|
end
|
@@ -563,8 +563,8 @@ class TestTypeChecker < R2CTestCase
|
|
563
563
|
# makes debugging very difficult
|
564
564
|
input = t(:lasgn, :var, t(:str, "foo"))
|
565
565
|
output = t(:lasgn, :var,
|
566
|
-
t(:str, "foo",
|
567
|
-
|
566
|
+
t(:str, "foo", CType.str),
|
567
|
+
CType.str)
|
568
568
|
|
569
569
|
assert_equal output, @type_checker.process(input)
|
570
570
|
end
|
@@ -578,9 +578,9 @@ class TestTypeChecker < R2CTestCase
|
|
578
578
|
t(:str, "bar")))
|
579
579
|
output = t(:lasgn, :var,
|
580
580
|
t(:array,
|
581
|
-
t(:str, "foo",
|
582
|
-
t(:str, "bar",
|
583
|
-
|
581
|
+
t(:str, "foo", CType.str),
|
582
|
+
t(:str, "bar", CType.str)),
|
583
|
+
CType.str_list)
|
584
584
|
|
585
585
|
assert_equal output, @type_checker.process(input)
|
586
586
|
end
|
@@ -588,36 +588,36 @@ class TestTypeChecker < R2CTestCase
|
|
588
588
|
def test_process_lasgn_masgn
|
589
589
|
@type_checker.env.extend
|
590
590
|
input = t(:lasgn, :var)
|
591
|
-
output = t(:lasgn, :var, nil,
|
591
|
+
output = t(:lasgn, :var, nil, CType.unknown)
|
592
592
|
|
593
593
|
assert_equal output, @type_checker.process(input)
|
594
594
|
end
|
595
595
|
|
596
596
|
def test_process_lit_float
|
597
597
|
input = t(:lit, 1.0)
|
598
|
-
output = t(:lit, 1.0,
|
598
|
+
output = t(:lit, 1.0, CType.float)
|
599
599
|
|
600
600
|
assert_equal output, @type_checker.process(input)
|
601
601
|
end
|
602
602
|
|
603
603
|
def test_process_lit_long
|
604
604
|
input = t(:lit, 1)
|
605
|
-
output = t(:lit, 1,
|
605
|
+
output = t(:lit, 1, CType.long)
|
606
606
|
|
607
607
|
assert_equal output, @type_checker.process(input)
|
608
608
|
end
|
609
609
|
|
610
610
|
def test_process_lit_sym
|
611
611
|
input = t(:lit, :sym)
|
612
|
-
output = t(:lit, :sym,
|
612
|
+
output = t(:lit, :sym, CType.symbol)
|
613
613
|
|
614
614
|
assert_equal output, @type_checker.process(input)
|
615
615
|
end
|
616
616
|
|
617
617
|
def test_process_lvar
|
618
|
-
add_fake_var :arg,
|
618
|
+
add_fake_var :arg, CType.long
|
619
619
|
input = t(:lvar, :arg)
|
620
|
-
output = t(:lvar, :arg,
|
620
|
+
output = t(:lvar, :arg, CType.long)
|
621
621
|
|
622
622
|
assert_equal output, @type_checker.process(input)
|
623
623
|
end
|
@@ -630,12 +630,12 @@ class TestTypeChecker < R2CTestCase
|
|
630
630
|
s(:array, s(:lit, 1), s(:lit, 2)))
|
631
631
|
output = t(:masgn,
|
632
632
|
t(:array,
|
633
|
-
t(:lasgn, :a, nil,
|
634
|
-
t(:lasgn, :b, nil,
|
633
|
+
t(:lasgn, :a, nil, CType.long),
|
634
|
+
t(:lasgn, :b, nil, CType.long)),
|
635
635
|
t(:array,
|
636
|
-
t(:lit, 1,
|
637
|
-
t(:lit, 2,
|
638
|
-
|
636
|
+
t(:lit, 1, CType.long),
|
637
|
+
t(:lit, 2, CType.long),
|
638
|
+
CType.long_list))
|
639
639
|
|
640
640
|
assert_equal output, @type_checker.process(input)
|
641
641
|
end
|
@@ -648,11 +648,11 @@ class TestTypeChecker < R2CTestCase
|
|
648
648
|
s(:to_ary, s(:lit, 1)))
|
649
649
|
output = t(:masgn,
|
650
650
|
t(:array,
|
651
|
-
t(:lasgn, :a, nil,
|
652
|
-
t(:lasgn, :b, nil,
|
651
|
+
t(:lasgn, :a, nil, CType.long),
|
652
|
+
t(:lasgn, :b, nil, CType.value)),
|
653
653
|
t(:to_ary,
|
654
|
-
t(:lit, 1,
|
655
|
-
|
654
|
+
t(:lit, 1, CType.long),
|
655
|
+
CType.long_list))
|
656
656
|
|
657
657
|
assert_equal output, @type_checker.process(input)
|
658
658
|
end
|
@@ -665,34 +665,34 @@ class TestTypeChecker < R2CTestCase
|
|
665
665
|
s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3)))
|
666
666
|
output = t(:masgn,
|
667
667
|
t(:array,
|
668
|
-
t(:lasgn, :a, nil,
|
669
|
-
t(:lasgn, :b, nil,
|
668
|
+
t(:lasgn, :a, nil, CType.long),
|
669
|
+
t(:lasgn, :b, nil, CType.long_list)),
|
670
670
|
t(:array,
|
671
|
-
t(:lit, 1,
|
672
|
-
t(:lit, 2,
|
673
|
-
t(:lit, 3,
|
674
|
-
|
671
|
+
t(:lit, 1, CType.long),
|
672
|
+
t(:lit, 2, CType.long),
|
673
|
+
t(:lit, 3, CType.long),
|
674
|
+
CType.long_list))
|
675
675
|
|
676
676
|
assert_equal output, @type_checker.process(input)
|
677
677
|
end
|
678
678
|
|
679
679
|
def test_process_nil
|
680
680
|
input = t(:nil)
|
681
|
-
output = t(:nil,
|
681
|
+
output = t(:nil, CType.value)
|
682
682
|
|
683
683
|
assert_equal output, @type_checker.process(input)
|
684
684
|
end
|
685
685
|
|
686
686
|
def test_process_not
|
687
687
|
input = t(:not, t(:true))
|
688
|
-
output = t(:not, t(:true,
|
688
|
+
output = t(:not, t(:true, CType.bool), CType.bool)
|
689
689
|
|
690
690
|
assert_equal output, @type_checker.process(input)
|
691
691
|
end
|
692
692
|
|
693
693
|
def test_process_or
|
694
694
|
input = t(:or, t(:true), t(:false))
|
695
|
-
output = t(:or, t(:true,
|
695
|
+
output = t(:or, t(:true, CType.bool), t(:false, CType.bool), CType.bool)
|
696
696
|
|
697
697
|
assert_equal output, @type_checker.process(input)
|
698
698
|
end
|
@@ -705,7 +705,7 @@ class TestTypeChecker < R2CTestCase
|
|
705
705
|
|
706
706
|
def test_process_return
|
707
707
|
input = t(:return, t(:nil))
|
708
|
-
output = t(:return, t(:nil,
|
708
|
+
output = t(:return, t(:nil, CType.value), CType.void)
|
709
709
|
|
710
710
|
assert_equal output, @type_checker.process(input)
|
711
711
|
end
|
@@ -717,24 +717,24 @@ class TestTypeChecker < R2CTestCase
|
|
717
717
|
output = t(:scope,
|
718
718
|
t(:block,
|
719
719
|
t(:return,
|
720
|
-
t(:nil,
|
721
|
-
|
722
|
-
|
723
|
-
|
720
|
+
t(:nil, CType.value),
|
721
|
+
CType.void),
|
722
|
+
CType.unknown), # FIX ? do we care about block?
|
723
|
+
CType.void)
|
724
724
|
|
725
725
|
assert_equal output, @type_checker.process(input)
|
726
726
|
end
|
727
727
|
|
728
728
|
def test_process_scope_empty
|
729
729
|
input = t(:scope)
|
730
|
-
output = t(:scope,
|
730
|
+
output = t(:scope, CType.void)
|
731
731
|
|
732
732
|
assert_equal output, @type_checker.process(input)
|
733
733
|
end
|
734
734
|
|
735
735
|
def test_process_str
|
736
736
|
input = t(:str, "foo")
|
737
|
-
output = t(:str, "foo",
|
737
|
+
output = t(:str, "foo", CType.str)
|
738
738
|
|
739
739
|
assert_equal output, @type_checker.process(input)
|
740
740
|
end
|
@@ -742,16 +742,16 @@ class TestTypeChecker < R2CTestCase
|
|
742
742
|
def test_process_to_ary
|
743
743
|
input = s(:to_ary, s(:lit, 1), s(:lit, 2))
|
744
744
|
output = t(:to_ary,
|
745
|
-
t(:lit, 1,
|
746
|
-
t(:lit, 2,
|
747
|
-
|
745
|
+
t(:lit, 1, CType.long),
|
746
|
+
t(:lit, 2, CType.long),
|
747
|
+
CType.long_list)
|
748
748
|
|
749
749
|
assert_equal output, @type_checker.process(input)
|
750
750
|
end
|
751
751
|
|
752
752
|
def test_process_true
|
753
753
|
input = t(:true)
|
754
|
-
output = t(:true,
|
754
|
+
output = t(:true, CType.bool)
|
755
755
|
|
756
756
|
assert_equal output, @type_checker.process(input)
|
757
757
|
end
|
@@ -766,14 +766,14 @@ class TestTypeChecker < R2CTestCase
|
|
766
766
|
t(:str, "equal"))
|
767
767
|
output = t(:if,
|
768
768
|
t(:call,
|
769
|
-
t(:lit, 1,
|
769
|
+
t(:lit, 1, CType.long),
|
770
770
|
:==,
|
771
771
|
t(:arglist,
|
772
|
-
t(:lit, 2,
|
773
|
-
|
772
|
+
t(:lit, 2, CType.long)),
|
773
|
+
CType.bool),
|
774
774
|
nil,
|
775
|
-
t(:str, "equal",
|
776
|
-
|
775
|
+
t(:str, "equal", CType.str),
|
776
|
+
CType.str)
|
777
777
|
|
778
778
|
assert_equal output, @type_checker.process(input)
|
779
779
|
end
|
@@ -781,16 +781,16 @@ class TestTypeChecker < R2CTestCase
|
|
781
781
|
def test_process_while
|
782
782
|
input = t(:while, t(:true), t(:call, t(:lit, 1), :to_s, nil), true)
|
783
783
|
expected = t(:while,
|
784
|
-
t(:true,
|
785
|
-
t(:call, t(:lit, 1,
|
786
|
-
|
784
|
+
t(:true, CType.bool),
|
785
|
+
t(:call, t(:lit, 1, CType.long), :to_s, t(:arglist),
|
786
|
+
CType.str), true)
|
787
787
|
|
788
788
|
assert_equal expected, @type_checker.process(input)
|
789
789
|
end
|
790
790
|
|
791
791
|
def add_fake_function(name, reciever_type, return_type, *arg_types)
|
792
792
|
@type_checker.functions.add_function(name,
|
793
|
-
|
793
|
+
CType.function(reciever_type, arg_types, return_type))
|
794
794
|
end
|
795
795
|
|
796
796
|
def add_fake_var(name, type)
|