ruby2c 1.0.0.9 → 1.1.1
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 +1 -0
- data/History.txt +78 -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 +6 -2
- data/lib/ruby_to_ansi_c.rb +18 -18
- data/lib/ruby_to_ruby_c.rb +3 -3
- data/lib/type.rb +3 -3
- data/lib/type_checker.rb +101 -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
- data.tar.gz.sig +2 -1
- metadata +101 -153
- metadata.gz.sig +0 -0
- data/.gemtest +0 -0
data/test/test_function_type.rb
CHANGED
@@ -3,53 +3,53 @@
|
|
3
3
|
$TESTING = true
|
4
4
|
|
5
5
|
require 'minitest/autorun' if $0 == __FILE__
|
6
|
-
require 'minitest/
|
6
|
+
require 'minitest/test'
|
7
7
|
require 'function_type'
|
8
8
|
require 'type'
|
9
9
|
|
10
|
-
class TestFunctionType <
|
10
|
+
class TestFunctionType < Minitest::Test
|
11
11
|
def setup
|
12
|
-
@function_type = FunctionType.new
|
12
|
+
@function_type = FunctionType.new CType.void, [CType.long, CType.str], CType.value
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_formal_types
|
16
|
-
assert_equal [
|
16
|
+
assert_equal [CType.long, CType.str], @function_type.formal_types
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_formal_types=
|
20
|
-
@function_type.formal_types = [
|
21
|
-
assert_equal [
|
20
|
+
@function_type.formal_types = [CType.str, CType.long]
|
21
|
+
assert_equal [CType.str, CType.long], @function_type.formal_types
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_receiver_type
|
25
|
-
assert_equal
|
25
|
+
assert_equal CType.void, @function_type.receiver_type
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_receiver_type=
|
29
|
-
@function_type.receiver_type =
|
30
|
-
assert_equal
|
29
|
+
@function_type.receiver_type = CType.str
|
30
|
+
assert_equal CType.str, @function_type.receiver_type
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_return_type
|
34
|
-
assert_equal
|
34
|
+
assert_equal CType.value, @function_type.return_type
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_return_type=
|
38
|
-
@function_type.return_type =
|
39
|
-
assert_equal
|
38
|
+
@function_type.return_type = CType.long
|
39
|
+
assert_equal CType.long, @function_type.return_type
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_equals
|
43
43
|
funs = []
|
44
|
-
funs << FunctionType.new(
|
45
|
-
funs << FunctionType.new(
|
46
|
-
funs << FunctionType.new(
|
47
|
-
funs << FunctionType.new(
|
48
|
-
funs << FunctionType.new(
|
49
|
-
funs << FunctionType.new(
|
50
|
-
funs << FunctionType.new(
|
51
|
-
funs << FunctionType.new(
|
52
|
-
#funs << FunctionType.new(
|
44
|
+
funs << FunctionType.new(CType.unknown, [], CType.unknown)
|
45
|
+
funs << FunctionType.new(CType.unknown, [CType.unknown], CType.unknown)
|
46
|
+
funs << FunctionType.new(CType.unknown, [], CType.long)
|
47
|
+
funs << FunctionType.new(CType.unknown, [CType.long], CType.unknown)
|
48
|
+
funs << FunctionType.new(CType.unknown, [CType.long], CType.long)
|
49
|
+
funs << FunctionType.new(CType.unknown, [CType.unknown, CType.unknown], CType.unknown)
|
50
|
+
funs << FunctionType.new(CType.unknown, [CType.long, CType.unknown], CType.unknown)
|
51
|
+
funs << FunctionType.new(CType.unknown, [CType.long, CType.long], CType.long)
|
52
|
+
#funs << FunctionType.new(CType.unknown, [], CType.long)
|
53
53
|
|
54
54
|
funs.each_with_index do |fun1, i|
|
55
55
|
funs.each_with_index do |fun2, j|
|
@@ -63,59 +63,59 @@ class TestFunctionType < MiniTest::Unit::TestCase
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_unify_components
|
66
|
-
fun1 = FunctionType.new(
|
67
|
-
fun2 = FunctionType.new(
|
66
|
+
fun1 = FunctionType.new(CType.unknown, [CType.unknown], CType.unknown)
|
67
|
+
fun2 = FunctionType.new(CType.long, [CType.long], CType.long)
|
68
68
|
fun1.unify_components fun2
|
69
69
|
assert_equal fun2, fun1
|
70
70
|
|
71
|
-
fun3 = FunctionType.new(
|
72
|
-
fun4 = FunctionType.new(
|
71
|
+
fun3 = FunctionType.new(CType.unknown, [CType.long], CType.unknown)
|
72
|
+
fun4 = FunctionType.new(CType.long, [CType.unknown], CType.long)
|
73
73
|
fun3.unify_components fun4
|
74
74
|
assert_equal fun4, fun3
|
75
75
|
|
76
|
-
fun5 = FunctionType.new(
|
77
|
-
fun6 = FunctionType.new(
|
76
|
+
fun5 = FunctionType.new(CType.unknown, [], CType.unknown)
|
77
|
+
fun6 = FunctionType.new(CType.long, [], CType.long)
|
78
78
|
fun5.unify_components fun6
|
79
79
|
assert_equal fun6, fun5
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_initialize_fail
|
83
83
|
assert_raises(RuntimeError) do
|
84
|
-
FunctionType.new(
|
84
|
+
FunctionType.new(CType.unknown, nil, CType.long)
|
85
85
|
end
|
86
86
|
|
87
87
|
assert_raises(RuntimeError)do
|
88
|
-
FunctionType.new(
|
88
|
+
FunctionType.new(CType.unknown, [], nil)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_unify_components_fail
|
93
|
-
fun1 = FunctionType.new(
|
94
|
-
fun2 = FunctionType.new(
|
93
|
+
fun1 = FunctionType.new(CType.long, [CType.str], CType.unknown)
|
94
|
+
fun2 = FunctionType.new(CType.unknown, [CType.long], CType.long)
|
95
95
|
assert_raises(TypeError) do
|
96
96
|
fun1.unify_components fun2
|
97
97
|
end
|
98
98
|
|
99
|
-
fun3 = FunctionType.new(
|
100
|
-
fun4 = FunctionType.new(
|
99
|
+
fun3 = FunctionType.new(CType.long, [], CType.unknown)
|
100
|
+
fun4 = FunctionType.new(CType.unknown, [CType.unknown], CType.long)
|
101
101
|
assert_raises(TypeError) do
|
102
102
|
fun3.unify_components fun4
|
103
103
|
end
|
104
104
|
|
105
|
-
fun5 = FunctionType.new(
|
106
|
-
fun6 = FunctionType.new(
|
105
|
+
fun5 = FunctionType.new(CType.long, [CType.unknown], CType.unknown)
|
106
|
+
fun6 = FunctionType.new(CType.unknown, [], CType.long)
|
107
107
|
assert_raises(TypeError) do
|
108
108
|
fun5.unify_components fun6
|
109
109
|
end
|
110
110
|
|
111
|
-
fun7 = FunctionType.new(
|
112
|
-
fun8 = FunctionType.new(
|
111
|
+
fun7 = FunctionType.new(CType.long, [], CType.str)
|
112
|
+
fun8 = FunctionType.new(CType.unknown, [], CType.long)
|
113
113
|
assert_raises(TypeError) do
|
114
114
|
fun7.unify_components fun8
|
115
115
|
end
|
116
116
|
|
117
|
-
fun9 = FunctionType.new(
|
118
|
-
funa = FunctionType.new(
|
117
|
+
fun9 = FunctionType.new(CType.long, [], CType.str)
|
118
|
+
funa = FunctionType.new(CType.str, [], CType.unknown)
|
119
119
|
|
120
120
|
fun9, funa = funa, fun9 # get rid of unused warnings but keep them rooted
|
121
121
|
|
@@ -125,4 +125,3 @@ class TestFunctionType < MiniTest::Unit::TestCase
|
|
125
125
|
end
|
126
126
|
|
127
127
|
end
|
128
|
-
|
data/test/test_handle.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
$TESTING = true
|
4
4
|
|
5
5
|
require 'minitest/autorun' if $0 == __FILE__
|
6
|
-
require 'minitest/
|
6
|
+
require 'minitest/test'
|
7
7
|
require 'handle'
|
8
8
|
|
9
|
-
class TestHandle <
|
9
|
+
class TestHandle < Minitest::Test
|
10
10
|
|
11
11
|
def setup
|
12
12
|
@handle = Handle.new("text")
|
data/test/test_r2cenvironment.rb
CHANGED
@@ -3,31 +3,31 @@
|
|
3
3
|
$TESTING = true
|
4
4
|
|
5
5
|
require 'minitest/autorun' if $0 == __FILE__
|
6
|
-
require 'minitest/
|
6
|
+
require 'minitest/test'
|
7
7
|
require 'r2cenvironment'
|
8
8
|
require 'type'
|
9
9
|
|
10
|
-
class TestR2CEnvironment <
|
10
|
+
class TestR2CEnvironment < Minitest::Test
|
11
11
|
|
12
12
|
def setup
|
13
13
|
@env = R2CEnvironment.new
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_add
|
17
|
-
assert_equal
|
18
|
-
assert_equal
|
17
|
+
assert_equal CType.long, @env.add(:var, CType.long)
|
18
|
+
assert_equal CType.long, @env.lookup(:var)
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_add_depth
|
22
22
|
@env.scope do
|
23
|
-
assert_equal
|
23
|
+
assert_equal CType.long, @env.add(:var, CType.long, 1)
|
24
24
|
end
|
25
|
-
assert_equal
|
25
|
+
assert_equal CType.long, @env.lookup(:var)
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_add_raises_on_illegal
|
29
29
|
assert_raises RuntimeError do
|
30
|
-
@env.add nil,
|
30
|
+
@env.add nil, CType.long
|
31
31
|
end
|
32
32
|
|
33
33
|
assert_raises RuntimeError do
|
@@ -37,8 +37,8 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
|
|
37
37
|
|
38
38
|
def test_add_segmented
|
39
39
|
@env.scope do
|
40
|
-
@env.add :var,
|
41
|
-
assert_equal
|
40
|
+
@env.add :var, CType.long
|
41
|
+
assert_equal CType.long, @env.lookup(:var)
|
42
42
|
end
|
43
43
|
|
44
44
|
assert_raises NameError do
|
@@ -47,30 +47,30 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_current
|
50
|
-
@env.add :var,
|
50
|
+
@env.add :var, CType.long
|
51
51
|
@env.set_val :var, 42
|
52
|
-
|
53
|
-
expected = { :var => [
|
52
|
+
|
53
|
+
expected = { :var => [CType.long, 42] }
|
54
54
|
assert_equal expected, @env.current
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_all
|
58
58
|
@env.scope do
|
59
|
-
@env.add :x,
|
59
|
+
@env.add :x, CType.long
|
60
60
|
|
61
61
|
@env.scope do
|
62
|
-
@env.add :y,
|
63
|
-
@env.add :x,
|
62
|
+
@env.add :y, CType.str
|
63
|
+
@env.add :x, CType.float
|
64
64
|
|
65
|
-
expected = { :x => [
|
65
|
+
expected = { :x => [CType.float], :y => [CType.str] }
|
66
66
|
assert_equal expected, @env.all
|
67
67
|
end
|
68
68
|
|
69
|
-
expected = { :x => [
|
69
|
+
expected = { :x => [CType.long] }
|
70
70
|
assert_equal expected, @env.all
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def test_depth
|
75
75
|
assert_equal 1, @env.depth
|
76
76
|
|
@@ -86,28 +86,28 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_get_val
|
89
|
-
@env.add :var,
|
89
|
+
@env.add :var, CType.long
|
90
90
|
@env.set_val :var, 42
|
91
91
|
|
92
92
|
assert_equal 42, @env.get_val(:var)
|
93
93
|
end
|
94
94
|
|
95
95
|
def test_set_val
|
96
|
-
@env.add :var,
|
96
|
+
@env.add :var, CType.long
|
97
97
|
assert_equal 42, @env.set_val(:var, 42)
|
98
98
|
|
99
99
|
assert_equal 42, @env.get_val(:var)
|
100
100
|
end
|
101
101
|
|
102
102
|
def test_set_val_static_array
|
103
|
-
@env.add :var,
|
103
|
+
@env.add :var, CType.long
|
104
104
|
assert_equal "[2]", @env.set_val(:var, "[2]")
|
105
105
|
|
106
106
|
assert_equal "[2]", @env.get_val(:var)
|
107
107
|
end
|
108
108
|
|
109
109
|
def test_get_val_unset
|
110
|
-
@env.add :var,
|
110
|
+
@env.add :var, CType.long
|
111
111
|
|
112
112
|
assert_nil @env.get_val(:var)
|
113
113
|
end
|
@@ -126,8 +126,8 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
|
|
126
126
|
end
|
127
127
|
|
128
128
|
def test_lookup
|
129
|
-
@env.add :var,
|
130
|
-
assert_equal
|
129
|
+
@env.add :var, CType.long
|
130
|
+
assert_equal CType.long, @env.lookup(:var)
|
131
131
|
end
|
132
132
|
|
133
133
|
def test_lookup_raises
|
@@ -137,49 +137,49 @@ class TestR2CEnvironment < MiniTest::Unit::TestCase
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def test_lookup_scope
|
140
|
-
@env.add :var,
|
141
|
-
assert_equal
|
140
|
+
@env.add :var, CType.long
|
141
|
+
assert_equal CType.long, @env.lookup(:var)
|
142
142
|
|
143
143
|
@env.scope do
|
144
|
-
assert_equal
|
144
|
+
assert_equal CType.long, @env.lookup(:var)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
def test_scope
|
149
|
-
@env.add :var,
|
150
|
-
assert_equal
|
149
|
+
@env.add :var, CType.long
|
150
|
+
assert_equal CType.long, @env.lookup(:var)
|
151
151
|
|
152
152
|
@env.scope do
|
153
|
-
@env.add :var,
|
154
|
-
assert_equal
|
153
|
+
@env.add :var, CType.float
|
154
|
+
assert_equal CType.float, @env.lookup(:var)
|
155
155
|
end
|
156
156
|
|
157
|
-
assert_equal
|
157
|
+
assert_equal CType.long, @env.lookup(:var)
|
158
158
|
end
|
159
159
|
|
160
160
|
def test_scope_raise
|
161
|
-
@env.add :a,
|
161
|
+
@env.add :a, CType.float
|
162
162
|
|
163
163
|
begin
|
164
164
|
@env.scope do
|
165
|
-
@env.add :a,
|
166
|
-
@env.add :b,
|
165
|
+
@env.add :a, CType.long
|
166
|
+
@env.add :b, CType.long
|
167
167
|
raise "woo"
|
168
168
|
end
|
169
169
|
rescue
|
170
170
|
# should replicate baddies
|
171
171
|
end
|
172
172
|
|
173
|
-
expected = { :a => [
|
173
|
+
expected = { :a => [CType.float] }
|
174
174
|
assert_equal expected, @env.all
|
175
175
|
end
|
176
176
|
|
177
177
|
def test_unextend
|
178
178
|
@env.extend
|
179
179
|
|
180
|
-
@env.add :var,
|
180
|
+
@env.add :var, CType.long
|
181
181
|
|
182
|
-
assert_equal
|
182
|
+
assert_equal CType.long, @env.lookup(:var)
|
183
183
|
|
184
184
|
@env.unextend
|
185
185
|
|