ruby2c 1.0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +1 -0
- data/.autotest +21 -0
- data/History.txt +173 -0
- data/Manifest.txt +35 -0
- data/README.txt +76 -0
- data/Rakefile +21 -0
- data/demo/char.rb +13 -0
- data/demo/factorial.rb +11 -0
- data/demo/hello.rb +11 -0
- data/demo/misc.rb +25 -0
- data/demo/newarray.rb +11 -0
- data/demo/strcat.rb +12 -0
- data/lib/crewriter.rb +199 -0
- data/lib/function_table.rb +45 -0
- data/lib/function_type.rb +46 -0
- data/lib/handle.rb +14 -0
- data/lib/r2cenvironment.rb +59 -0
- data/lib/rewriter.rb +35 -0
- data/lib/ruby_to_ansi_c.rb +673 -0
- data/lib/ruby_to_ruby_c.rb +382 -0
- data/lib/type.rb +148 -0
- data/lib/type_checker.rb +920 -0
- data/lib/typed_sexp.rb +88 -0
- data/test/r2ctestcase.rb +1196 -0
- data/test/test_crewriter.rb +328 -0
- data/test/test_extras.rb +68 -0
- data/test/test_function_table.rb +90 -0
- data/test/test_function_type.rb +125 -0
- data/test/test_handle.rb +39 -0
- data/test/test_r2cenvironment.rb +191 -0
- data/test/test_rewriter.rb +16 -0
- data/test/test_ruby_to_ansi_c.rb +487 -0
- data/test/test_ruby_to_ruby_c.rb +161 -0
- data/test/test_type.rb +193 -0
- data/test/test_type_checker.rb +805 -0
- data/test/test_typed_sexp.rb +138 -0
- metadata +164 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
require 'minitest/autorun' if $0 == __FILE__
|
4
|
+
require 'test_sexp'
|
5
|
+
require 'typed_sexp'
|
6
|
+
|
7
|
+
class TestTypedSexp < TestSexp
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
@sexp.sexp_type = Type.str
|
11
|
+
end
|
12
|
+
|
13
|
+
def test__set_sexp_type
|
14
|
+
assert_equal Type.str, @sexp.sexp_type
|
15
|
+
@sexp._set_sexp_type Type.bool
|
16
|
+
assert_equal Type.bool, @sexp.sexp_type
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_equals2_tsexp
|
20
|
+
sexp2 = s(1, 2, 3)
|
21
|
+
sexp3 = t(1, 2, 3, Type.str)
|
22
|
+
assert_equal(@sexp, sexp3)
|
23
|
+
refute_equal(@sexp, sexp2)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_equals_array_typed
|
27
|
+
# can't use assert_equals because it uses array as receiver
|
28
|
+
refute_equal(@sexp, [1, 2, 3, Type.str],
|
29
|
+
"Sexp must not be equal to equivalent array")
|
30
|
+
# both directions just in case
|
31
|
+
refute_equal([1, 2, 3, Type.str], @sexp,
|
32
|
+
"Sexp must not be equal to equivalent array")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_equals_not_body_typed
|
36
|
+
sexp2 = t(1, 2, 5)
|
37
|
+
sexp2.sexp_type = Type.str
|
38
|
+
refute_equal(@sexp, sexp2)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_equals_not_type
|
42
|
+
sexp2 = t(1, 2, 3)
|
43
|
+
sexp2.sexp_type = Type.long
|
44
|
+
refute_equal(@sexp, sexp2)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_equals_sexp
|
48
|
+
sexp2 = t(1, 2, 3, Type.str)
|
49
|
+
assert_equal(@sexp, sexp2)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_equals_sexp_typed
|
53
|
+
sexp2 = t(1, 2, 3)
|
54
|
+
sexp2.sexp_type = Type.str
|
55
|
+
assert_equal(@sexp, sexp2)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_new_nested_typed
|
59
|
+
@sexp = TypedSexp.new(:lasgn, "var", TypedSexp.new(:str, "foo", Type.str), Type.str)
|
60
|
+
assert_equal('t(:lasgn, "var", t(:str, "foo", Type.str), Type.str)',
|
61
|
+
@sexp.inspect)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_pretty_print_typed
|
65
|
+
util_pretty_print("t(Type.str)",
|
66
|
+
t(Type.str))
|
67
|
+
util_pretty_print("t(:a, Type.long)",
|
68
|
+
t(:a, Type.long))
|
69
|
+
util_pretty_print("t(:a, :b, Type.long)",
|
70
|
+
t(:a, :b, Type.long))
|
71
|
+
util_pretty_print("t(:a, t(:b, Type.long), Type.str)",
|
72
|
+
t(:a, t(:b, Type.long), Type.str))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_sexp_type
|
76
|
+
assert_equal(Type.str, @sexp.sexp_type)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_sexp_type=
|
80
|
+
assert_equal(Type.str, @sexp.sexp_type)
|
81
|
+
# FIX: we can't set sexp_type a second time, please expand tests
|
82
|
+
@sexp._set_sexp_type 24
|
83
|
+
assert_equal(24, @sexp.sexp_type)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_sexp_type_array_hetero
|
87
|
+
@sexp = t(:array, t(:lit, 1, Type.long),
|
88
|
+
t(:str, "foo", Type.str))
|
89
|
+
assert_equal(Type.hetero, @sexp.sexp_type)
|
90
|
+
assert_equal([Type.long, Type.str], @sexp.sexp_types)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_sexp_type_array_homo
|
94
|
+
@sexp = t(:array, t(:lit, 1, Type.long),
|
95
|
+
t(:lit, 2, Type.long))
|
96
|
+
assert_equal(Type.homo, @sexp.sexp_type)
|
97
|
+
assert_equal([Type.long, Type.long], @sexp.sexp_types)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_sexp_type_array_nested
|
101
|
+
@sexp = t(:array, t(:lit, 1, Type.long),
|
102
|
+
t(:array, t(:lit, 1, Type.long)))
|
103
|
+
assert_equal(Type.hetero, @sexp.sexp_type)
|
104
|
+
assert_equal([Type.long, Type.homo], @sexp.sexp_types)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_sexp_types
|
108
|
+
assert_raises(RuntimeError) do
|
109
|
+
@sexp.sexp_types
|
110
|
+
end
|
111
|
+
|
112
|
+
@sexp = t(:array, t(:lit, 1, Type.long), t(:str, "blah", Type.str))
|
113
|
+
|
114
|
+
assert_equal([Type.long, Type.str], @sexp.sexp_types)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_to_a
|
118
|
+
@sexp = t(1, 2, 3)
|
119
|
+
assert_equal([1, 2, 3], @sexp.to_a)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_to_a_typed
|
123
|
+
assert_equal([1, 2, 3, Type.str], @sexp.to_a)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_to_s_typed
|
127
|
+
k = @sexp_class
|
128
|
+
n = k.name[0].chr.downcase
|
129
|
+
assert_equal("#{n}(Type.long)",
|
130
|
+
k.new(Type.long).inspect)
|
131
|
+
assert_equal("#{n}(:a, Type.long)",
|
132
|
+
k.new(:a, Type.long).inspect)
|
133
|
+
assert_equal("#{n}(:a, :b, Type.long)",
|
134
|
+
k.new(:a, :b, Type.long).inspect)
|
135
|
+
assert_equal("#{n}(:a, #{n}(:b, Type.long), Type.str)",
|
136
|
+
k.new(:a, k.new(:b, Type.long), Type.str).inspect)
|
137
|
+
end
|
138
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby2c
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Davis
|
8
|
+
- Eric Hodel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- |
|
13
|
+
-----BEGIN CERTIFICATE-----
|
14
|
+
MIIDPjCCAiagAwIBAgIBADANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
|
15
|
+
ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
|
16
|
+
GRYDY29tMB4XDTA5MDMwNjE4NTMxNVoXDTEwMDMwNjE4NTMxNVowRT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ICATE-----
|
33
|
+
|
34
|
+
date: 2009-06-23 00:00:00 -07:00
|
35
|
+
default_executable:
|
36
|
+
dependencies:
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: ruby_parser
|
39
|
+
type: :runtime
|
40
|
+
version_requirement:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: hoe
|
49
|
+
type: :development
|
50
|
+
version_requirement:
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
56
|
+
version:
|
57
|
+
description: |-
|
58
|
+
ruby_to_c translates a static ruby subset to C. Hopefully it works.
|
59
|
+
|
60
|
+
NOTE ! NOTE ! NOTE ! NOTE ! NOTE ! NOTE ! NOTE ! NOTE ! NOTE
|
61
|
+
|
62
|
+
THIS IS BETA SOFTWARE!
|
63
|
+
|
64
|
+
NOTE ! NOTE ! NOTE ! NOTE ! NOTE ! NOTE ! NOTE ! NOTE ! NOTE
|
65
|
+
|
66
|
+
RubyToC has the following modules:
|
67
|
+
|
68
|
+
* Rewriter - massages the sexp into a more consistent form.
|
69
|
+
* TypeChecker - type inferencer for the above sexps.
|
70
|
+
* RubyToRubyC - converts a ruby (subset) sexp to ruby interals C.
|
71
|
+
* RubyToAnsiC - converts a ruby (subset) sexp to ANSI C.
|
72
|
+
|
73
|
+
and the following tools:
|
74
|
+
|
75
|
+
* translate.rb - Translates a given file to C.
|
76
|
+
email:
|
77
|
+
- ryand-ruby@zenspider.com
|
78
|
+
- drbrain@segment7.net
|
79
|
+
executables: []
|
80
|
+
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files:
|
84
|
+
- History.txt
|
85
|
+
- Manifest.txt
|
86
|
+
- README.txt
|
87
|
+
files:
|
88
|
+
- .autotest
|
89
|
+
- History.txt
|
90
|
+
- Manifest.txt
|
91
|
+
- README.txt
|
92
|
+
- Rakefile
|
93
|
+
- demo/char.rb
|
94
|
+
- demo/factorial.rb
|
95
|
+
- demo/hello.rb
|
96
|
+
- demo/misc.rb
|
97
|
+
- demo/newarray.rb
|
98
|
+
- demo/strcat.rb
|
99
|
+
- lib/crewriter.rb
|
100
|
+
- lib/function_table.rb
|
101
|
+
- lib/function_type.rb
|
102
|
+
- lib/handle.rb
|
103
|
+
- lib/r2cenvironment.rb
|
104
|
+
- lib/rewriter.rb
|
105
|
+
- lib/ruby_to_ansi_c.rb
|
106
|
+
- lib/ruby_to_ruby_c.rb
|
107
|
+
- lib/type.rb
|
108
|
+
- lib/type_checker.rb
|
109
|
+
- lib/typed_sexp.rb
|
110
|
+
- test/r2ctestcase.rb
|
111
|
+
- test/test_crewriter.rb
|
112
|
+
- test/test_extras.rb
|
113
|
+
- test/test_function_table.rb
|
114
|
+
- test/test_function_type.rb
|
115
|
+
- test/test_handle.rb
|
116
|
+
- test/test_r2cenvironment.rb
|
117
|
+
- test/test_rewriter.rb
|
118
|
+
- test/test_ruby_to_ansi_c.rb
|
119
|
+
- test/test_ruby_to_ruby_c.rb
|
120
|
+
- test/test_type.rb
|
121
|
+
- test/test_type_checker.rb
|
122
|
+
- test/test_typed_sexp.rb
|
123
|
+
has_rdoc: true
|
124
|
+
homepage: http://rubyforge.org/projects/ruby2c/
|
125
|
+
licenses: []
|
126
|
+
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options:
|
129
|
+
- --main
|
130
|
+
- README.txt
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: "0"
|
138
|
+
version:
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: "0"
|
144
|
+
version:
|
145
|
+
requirements: []
|
146
|
+
|
147
|
+
rubyforge_project: ruby2c
|
148
|
+
rubygems_version: 1.3.4
|
149
|
+
signing_key:
|
150
|
+
specification_version: 3
|
151
|
+
summary: ruby_to_c translates a static ruby subset to C
|
152
|
+
test_files:
|
153
|
+
- test/test_crewriter.rb
|
154
|
+
- test/test_extras.rb
|
155
|
+
- test/test_function_table.rb
|
156
|
+
- test/test_function_type.rb
|
157
|
+
- test/test_handle.rb
|
158
|
+
- test/test_r2cenvironment.rb
|
159
|
+
- test/test_rewriter.rb
|
160
|
+
- test/test_ruby_to_ansi_c.rb
|
161
|
+
- test/test_ruby_to_ruby_c.rb
|
162
|
+
- test/test_type.rb
|
163
|
+
- test/test_type_checker.rb
|
164
|
+
- test/test_typed_sexp.rb
|
metadata.gz.sig
ADDED
Binary file
|