oryx 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -1
- data/.travis.yml +15 -2
- data/README.md +13 -1
- data/doc/ast.md +110 -0
- data/doc/cflat.md +71 -0
- data/doc/conclusion.md +0 -0
- data/doc/fibonacci.md +15 -0
- data/doc/img/fib_parse.jpg +0 -0
- data/doc/intermediate_lang.md +0 -0
- data/doc/intro.md +89 -0
- data/doc/lexer.md +33 -0
- data/doc/parser.md +11 -0
- data/doc/symbol_table.md +23 -0
- data/doc/tools.md +9 -0
- data/doc/x86_translation.md +0 -0
- data/lib/oryx/ast.rb +34 -8
- data/lib/oryx/contractor.rb +185 -0
- data/lib/oryx/error.rb +8 -0
- data/lib/oryx/parser.rb +31 -7
- data/lib/oryx/runner.rb +30 -1
- data/lib/oryx/symbol_table.rb +48 -0
- data/lib/oryx/version.rb +1 -1
- data/lib/oryx.rb +3 -0
- data/test/data/add.c +3 -0
- data/test/data/div.c +3 -0
- data/test/data/eq.c +6 -0
- data/test/data/fib.c +8 -0
- data/test/data/fun_1.c +7 -0
- data/test/data/ge.c +6 -0
- data/test/data/geq.c +6 -0
- data/test/data/gvar_1.c +5 -0
- data/test/data/gvar_2.c +6 -0
- data/test/data/gvar_3.c +6 -0
- data/test/data/if.c +15 -0
- data/test/data/le.c +6 -0
- data/test/data/leq.c +6 -0
- data/test/data/mul.c +3 -0
- data/test/data/neq.c +6 -0
- data/test/data/return.c +3 -0
- data/test/data/sub.c +3 -0
- data/test/lib/oryx/error_test.rb +19 -0
- data/test/lib/oryx/runner_test.rb +25 -0
- data/test/lib/oryx/symbol_table_test.rb +147 -0
- data/test/shoulda_macros/runner.rb +58 -0
- data/test/test_helper.rb +1 -0
- metadata +61 -4
@@ -0,0 +1,147 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
module Oryx
|
4
|
+
class TestSymbolTable < Test::Unit::TestCase
|
5
|
+
context "basics" do
|
6
|
+
attr_accessor :st
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@st = SymbolTable.new
|
10
|
+
end
|
11
|
+
|
12
|
+
should "exist" do
|
13
|
+
st = SymbolTable.new
|
14
|
+
assert_not_nil st
|
15
|
+
end
|
16
|
+
|
17
|
+
should "have base scope" do
|
18
|
+
assert_equal st.current_scope, 0
|
19
|
+
end
|
20
|
+
|
21
|
+
should "store an empty variable" do
|
22
|
+
st.insert :a
|
23
|
+
assert_equal st.lookup(:a), nil
|
24
|
+
end
|
25
|
+
|
26
|
+
should "store an assigned variable" do
|
27
|
+
st.insert :b, 7
|
28
|
+
assert_equal 7, st.lookup(:b)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "scope basics " do
|
33
|
+
attr_accessor :st
|
34
|
+
|
35
|
+
setup do
|
36
|
+
@st = SymbolTable.new
|
37
|
+
@initial_values = {a: 1, b:2, c:3, d:4, e:'a', f: 1.2}
|
38
|
+
@initial_values.each{ |k, v| st.insert k, v }
|
39
|
+
end
|
40
|
+
|
41
|
+
should "increase the scope" do
|
42
|
+
st.enter_scope
|
43
|
+
assert_equal 1, st.current_scope
|
44
|
+
end
|
45
|
+
|
46
|
+
should "decrease the scope" do
|
47
|
+
st.enter_scope
|
48
|
+
assert_nothing_raised do
|
49
|
+
st.exit_scope
|
50
|
+
end
|
51
|
+
|
52
|
+
assert_equal 0, st.current_scope
|
53
|
+
end
|
54
|
+
|
55
|
+
should "increase and decrease the scope many times" do
|
56
|
+
n = 73
|
57
|
+
(0..n).map do |i|
|
58
|
+
st.enter_scope
|
59
|
+
assert_equal i+1, st.current_scope
|
60
|
+
n-i
|
61
|
+
end.map do |i|
|
62
|
+
st.exit_scope
|
63
|
+
assert_equal i, st.current_scope
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
should "leave base values alone" do
|
68
|
+
st.enter_scope
|
69
|
+
st.exit_scope
|
70
|
+
@initial_values.each{ |k, v| assert_equal v, st.lookup(k) }
|
71
|
+
end
|
72
|
+
|
73
|
+
should "find values from lower scope" do
|
74
|
+
st.enter_scope
|
75
|
+
@initial_values.each{ |k, v| assert_equal v, st.lookup(k) }
|
76
|
+
end
|
77
|
+
|
78
|
+
should "mask previously defined variables" do
|
79
|
+
st.enter_scope
|
80
|
+
st.insert :a, "pi"
|
81
|
+
assert_equal "pi", st.lookup(:a)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "not delete lower scoped values" do
|
85
|
+
st.enter_scope
|
86
|
+
st.insert :a, "pi"
|
87
|
+
st.exit_scope
|
88
|
+
assert_equal 1, st.lookup(:a)
|
89
|
+
end
|
90
|
+
|
91
|
+
should "update variable" do
|
92
|
+
st.update :a, "5"
|
93
|
+
assert_equal "5", st.lookup(:a)
|
94
|
+
end
|
95
|
+
|
96
|
+
should "update variable in correct scope" do
|
97
|
+
st.enter_scope
|
98
|
+
st.insert :c, "cow"
|
99
|
+
st.update :c, "monkey"
|
100
|
+
assert_equal "monkey", st.lookup(:c)
|
101
|
+
|
102
|
+
st.exit_scope
|
103
|
+
assert_equal 3, st.lookup(:c)
|
104
|
+
end
|
105
|
+
|
106
|
+
should "update variable in previous scope" do
|
107
|
+
st.enter_scope
|
108
|
+
st.update :c, 100
|
109
|
+
st.exit_scope
|
110
|
+
|
111
|
+
assert_equal 100, st.lookup(:c)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "errors" do
|
116
|
+
setup do
|
117
|
+
@st = SymbolTable.new
|
118
|
+
end
|
119
|
+
|
120
|
+
should "raise an exception when exiting global scope" do
|
121
|
+
assert_raise SymbolTableError do
|
122
|
+
st.exit_scope
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
should "raise an error if variable is not found" do
|
127
|
+
assert_raise SymbolTableError do
|
128
|
+
st.lookup :a
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
should "raise an error if re-inserting variable" do
|
133
|
+
st.insert :a
|
134
|
+
assert_raise SymbolTableError do
|
135
|
+
st.insert :a
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
should "raise an error if updating non-existant variable" do
|
140
|
+
assert_raise SymbolTableError do
|
141
|
+
st.update :a
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Oryx
|
2
|
+
class Test::Unit::TestCase
|
3
|
+
def self.should_generate_toolchain_output base_name, return_value
|
4
|
+
context base_name do
|
5
|
+
setup do
|
6
|
+
setup_helper base_name
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
teardown_helper base_name
|
11
|
+
end
|
12
|
+
|
13
|
+
should "create LLVM IR" do
|
14
|
+
path = @directory + "#{@base_name}.ll"
|
15
|
+
assert path.exist?, "#{path} was not created"
|
16
|
+
end
|
17
|
+
|
18
|
+
should "translate IR into Assembly" do
|
19
|
+
path = @directory + "#{@base_name}.s"
|
20
|
+
assert path.exist?, "#{path} was not created"
|
21
|
+
end
|
22
|
+
|
23
|
+
should "create executable" do
|
24
|
+
path = @directory + "#{@base_name}.out"
|
25
|
+
assert path.exist?, "#{path} was not created"
|
26
|
+
assert path.executable?, "#{path} is not an executable"
|
27
|
+
end
|
28
|
+
|
29
|
+
should "return the correct result" do
|
30
|
+
path = @directory + "#{@base_name}.out"
|
31
|
+
assert_equal return_value, %x[#{path}; echo $?].to_i
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def stfu
|
38
|
+
orig_stdout = $stdout.clone
|
39
|
+
orig_stderr = $stderr.clone
|
40
|
+
$stdout.reopen "/dev/null", "w"
|
41
|
+
$stderr.reopen "/dev/null", "w"
|
42
|
+
yield if block_given?
|
43
|
+
$stdout.reopen orig_stdout
|
44
|
+
$stderr.reopen orig_stderr
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_helper file
|
48
|
+
@directory = Pathname.new "test/data/"
|
49
|
+
@base_name = file
|
50
|
+
r = Runner.new [(@directory+"#{@base_name}.c")]
|
51
|
+
stfu {r.run}
|
52
|
+
end
|
53
|
+
|
54
|
+
def teardown_helper file
|
55
|
+
%w[ll s out].each { |e| (@directory+"#{@base_name}.#{e}").delete }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oryx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -90,17 +90,53 @@ files:
|
|
90
90
|
- README.md
|
91
91
|
- Rakefile
|
92
92
|
- bin/oryx
|
93
|
+
- doc/ast.md
|
94
|
+
- doc/cflat.md
|
95
|
+
- doc/conclusion.md
|
96
|
+
- doc/fibonacci.md
|
97
|
+
- doc/img/fib_parse.jpg
|
98
|
+
- doc/intermediate_lang.md
|
99
|
+
- doc/intro.md
|
100
|
+
- doc/lexer.md
|
101
|
+
- doc/parser.md
|
102
|
+
- doc/symbol_table.md
|
103
|
+
- doc/tools.md
|
104
|
+
- doc/x86_translation.md
|
93
105
|
- lib/oryx.rb
|
94
106
|
- lib/oryx/ast.rb
|
107
|
+
- lib/oryx/contractor.rb
|
108
|
+
- lib/oryx/error.rb
|
95
109
|
- lib/oryx/lexer.rb
|
96
110
|
- lib/oryx/options.rb
|
97
111
|
- lib/oryx/parser.rb
|
98
112
|
- lib/oryx/runner.rb
|
113
|
+
- lib/oryx/symbol_table.rb
|
99
114
|
- lib/oryx/version.rb
|
100
115
|
- oryx.gemspec
|
116
|
+
- test/data/add.c
|
117
|
+
- test/data/div.c
|
118
|
+
- test/data/eq.c
|
119
|
+
- test/data/fib.c
|
120
|
+
- test/data/fun_1.c
|
121
|
+
- test/data/ge.c
|
122
|
+
- test/data/geq.c
|
123
|
+
- test/data/gvar_1.c
|
124
|
+
- test/data/gvar_2.c
|
125
|
+
- test/data/gvar_3.c
|
126
|
+
- test/data/if.c
|
127
|
+
- test/data/le.c
|
128
|
+
- test/data/leq.c
|
129
|
+
- test/data/mul.c
|
130
|
+
- test/data/neq.c
|
131
|
+
- test/data/return.c
|
132
|
+
- test/data/sub.c
|
133
|
+
- test/lib/oryx/error_test.rb
|
101
134
|
- test/lib/oryx/lexer_test.rb
|
102
135
|
- test/lib/oryx/parser_test.rb
|
136
|
+
- test/lib/oryx/runner_test.rb
|
137
|
+
- test/lib/oryx/symbol_table_test.rb
|
103
138
|
- test/lib/oryx/version_test.rb
|
139
|
+
- test/shoulda_macros/runner.rb
|
104
140
|
- test/test_helper.rb
|
105
141
|
homepage: http://github.com/rampantmonkey/oryx
|
106
142
|
licenses: []
|
@@ -116,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
152
|
version: '0'
|
117
153
|
segments:
|
118
154
|
- 0
|
119
|
-
hash:
|
155
|
+
hash: 1968373242303314984
|
120
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
157
|
none: false
|
122
158
|
requirements:
|
@@ -125,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
161
|
version: '0'
|
126
162
|
segments:
|
127
163
|
- 0
|
128
|
-
hash:
|
164
|
+
hash: 1968373242303314984
|
129
165
|
requirements: []
|
130
166
|
rubyforge_project:
|
131
167
|
rubygems_version: 1.8.23
|
@@ -133,7 +169,28 @@ signing_key:
|
|
133
169
|
specification_version: 3
|
134
170
|
summary: Take a program written in C-Flat and convert it to x86 assembly
|
135
171
|
test_files:
|
172
|
+
- test/data/add.c
|
173
|
+
- test/data/div.c
|
174
|
+
- test/data/eq.c
|
175
|
+
- test/data/fib.c
|
176
|
+
- test/data/fun_1.c
|
177
|
+
- test/data/ge.c
|
178
|
+
- test/data/geq.c
|
179
|
+
- test/data/gvar_1.c
|
180
|
+
- test/data/gvar_2.c
|
181
|
+
- test/data/gvar_3.c
|
182
|
+
- test/data/if.c
|
183
|
+
- test/data/le.c
|
184
|
+
- test/data/leq.c
|
185
|
+
- test/data/mul.c
|
186
|
+
- test/data/neq.c
|
187
|
+
- test/data/return.c
|
188
|
+
- test/data/sub.c
|
189
|
+
- test/lib/oryx/error_test.rb
|
136
190
|
- test/lib/oryx/lexer_test.rb
|
137
191
|
- test/lib/oryx/parser_test.rb
|
192
|
+
- test/lib/oryx/runner_test.rb
|
193
|
+
- test/lib/oryx/symbol_table_test.rb
|
138
194
|
- test/lib/oryx/version_test.rb
|
195
|
+
- test/shoulda_macros/runner.rb
|
139
196
|
- test/test_helper.rb
|