koi-reference-compiler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.gitignore +3 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +76 -0
  4. data/Rakefile +42 -0
  5. data/VERSION +1 -0
  6. data/lib/koi-reference-compiler.rb +10 -0
  7. data/lib/koi-reference-compiler/exceptions.rb +2 -0
  8. data/lib/koi-reference-compiler/koi-reference-compiler.rb +23 -0
  9. data/lib/koi-reference-compiler/node_extensions/assignment/assignment.rb +12 -0
  10. data/lib/koi-reference-compiler/node_extensions/blocks/block.rb +13 -0
  11. data/lib/koi-reference-compiler/node_extensions/control_flow/if.rb +14 -0
  12. data/lib/koi-reference-compiler/node_extensions/control_flow/unless.rb +14 -0
  13. data/lib/koi-reference-compiler/node_extensions/expressions/additive_expression.rb +13 -0
  14. data/lib/koi-reference-compiler/node_extensions/expressions/comparative_expression.rb +13 -0
  15. data/lib/koi-reference-compiler/node_extensions/expressions/expression.rb +9 -0
  16. data/lib/koi-reference-compiler/node_extensions/expressions/multitive_expression.rb +13 -0
  17. data/lib/koi-reference-compiler/node_extensions/functions/function_call.rb +54 -0
  18. data/lib/koi-reference-compiler/node_extensions/functions/function_definition.rb +19 -0
  19. data/lib/koi-reference-compiler/node_extensions/hash_literals/hash_access.rb +12 -0
  20. data/lib/koi-reference-compiler/node_extensions/hash_literals/hash_accessor.rb +15 -0
  21. data/lib/koi-reference-compiler/node_extensions/hash_literals/hash_accessor_list.rb +26 -0
  22. data/lib/koi-reference-compiler/node_extensions/hash_literals/hash_assignment.rb +17 -0
  23. data/lib/koi-reference-compiler/node_extensions/hash_literals/hash_literal.rb +11 -0
  24. data/lib/koi-reference-compiler/node_extensions/hash_literals/key_value.rb +13 -0
  25. data/lib/koi-reference-compiler/node_extensions/hash_literals/key_value_list.rb +13 -0
  26. data/lib/koi-reference-compiler/node_extensions/identifiers/identifier.rb +31 -0
  27. data/lib/koi-reference-compiler/node_extensions/literals/false_literal.rb +9 -0
  28. data/lib/koi-reference-compiler/node_extensions/literals/float_literal.rb +9 -0
  29. data/lib/koi-reference-compiler/node_extensions/literals/integer_literal.rb +9 -0
  30. data/lib/koi-reference-compiler/node_extensions/literals/nil_literal.rb +9 -0
  31. data/lib/koi-reference-compiler/node_extensions/literals/string_literal.rb +9 -0
  32. data/lib/koi-reference-compiler/node_extensions/literals/true_literal.rb +9 -0
  33. data/lib/koi-reference-compiler/node_extensions/operators/addition_operator.rb +9 -0
  34. data/lib/koi-reference-compiler/node_extensions/operators/assignment_operator.rb +6 -0
  35. data/lib/koi-reference-compiler/node_extensions/operators/division_operator.rb +9 -0
  36. data/lib/koi-reference-compiler/node_extensions/operators/equality_operator.rb +9 -0
  37. data/lib/koi-reference-compiler/node_extensions/operators/great_than_operator.rb +9 -0
  38. data/lib/koi-reference-compiler/node_extensions/operators/inequality_operator.rb +9 -0
  39. data/lib/koi-reference-compiler/node_extensions/operators/less_than_operator.rb +9 -0
  40. data/lib/koi-reference-compiler/node_extensions/operators/multiplication_operator.rb +9 -0
  41. data/lib/koi-reference-compiler/node_extensions/operators/subtraction_operator.rb +9 -0
  42. data/lib/koi-reference-compiler/node_extensions/statements/statement.rb +9 -0
  43. data/lib/koi-reference-compiler/syntax_node.rb +18 -0
  44. data/lib/koi-reference-compiler/vm_opcodes.rb +70 -0
  45. data/test/compiler/unit/ast_hash_loader/ast_hash_loader_test.rb +46 -0
  46. data/test/compiler/unit/node_extensions/assignment/assignment_test.rb +22 -0
  47. data/test/compiler/unit/node_extensions/blocks/block_test.rb +37 -0
  48. data/test/compiler/unit/node_extensions/control_flow/if_test.rb +39 -0
  49. data/test/compiler/unit/node_extensions/control_flow/unless_test.rb +40 -0
  50. data/test/compiler/unit/node_extensions/expressions/additive_expression_test.rb +21 -0
  51. data/test/compiler/unit/node_extensions/expressions/comparative_expression_test.rb +21 -0
  52. data/test/compiler/unit/node_extensions/expressions/expression_test.rb +17 -0
  53. data/test/compiler/unit/node_extensions/expressions/multitive_expression_test.rb +21 -0
  54. data/test/compiler/unit/node_extensions/functions/function_call_test.rb +296 -0
  55. data/test/compiler/unit/node_extensions/functions/function_definition_test.rb +37 -0
  56. data/test/compiler/unit/node_extensions/hash_literals/hash_accessor_list_test.rb +83 -0
  57. data/test/compiler/unit/node_extensions/hash_literals/hash_accessor_test.rb +33 -0
  58. data/test/compiler/unit/node_extensions/hash_literals/hash_literal_test.rb +29 -0
  59. data/test/compiler/unit/node_extensions/hash_literals/key_value_list_test.rb +37 -0
  60. data/test/compiler/unit/node_extensions/hash_literals/key_value_test.rb +24 -0
  61. data/test/compiler/unit/node_extensions/identifiers/identifier_test.rb +103 -0
  62. data/test/compiler/unit/node_extensions/literals/false_literal_test.rb +13 -0
  63. data/test/compiler/unit/node_extensions/literals/float_literal_test.rb +13 -0
  64. data/test/compiler/unit/node_extensions/literals/integer_literal_test.rb +13 -0
  65. data/test/compiler/unit/node_extensions/literals/nil_literal_test.rb +13 -0
  66. data/test/compiler/unit/node_extensions/literals/string_literal_test.rb +13 -0
  67. data/test/compiler/unit/node_extensions/literals/true_literal_test.rb +13 -0
  68. data/test/compiler/unit/node_extensions/operators/addition_operator_test.rb +13 -0
  69. data/test/compiler/unit/node_extensions/operators/division_operator_test.rb +13 -0
  70. data/test/compiler/unit/node_extensions/operators/equality_operator_test.rb +13 -0
  71. data/test/compiler/unit/node_extensions/operators/greater_than_operator_test.rb +13 -0
  72. data/test/compiler/unit/node_extensions/operators/inequality_operator_test.rb +13 -0
  73. data/test/compiler/unit/node_extensions/operators/less_than_operator_test.rb +13 -0
  74. data/test/compiler/unit/node_extensions/operators/multiplication_operator_test.rb +13 -0
  75. data/test/compiler/unit/node_extensions/operators/subtraction_operator_test.rb +13 -0
  76. data/test/compiler/unit/node_extensions/statements/statement_test.rb +24 -0
  77. data/test/setup/test_unit_extensions.rb +21 -0
  78. data/test/test_helper.rb +10 -0
  79. metadata +177 -0
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class AdditionOperatorTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile AdditionOperator" do
8
+ tree = AdditionOperator.new("+", 0)
9
+ bytecode = tree.compile
10
+ assert_equal [ADD], bytecode
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class DivisionOperatorTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile DivisionnOperator" do
8
+ tree = DivisionOperator.new("/", 0)
9
+ bytecode = tree.compile
10
+ assert_equal [DIVIDE], bytecode
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class EqualityOperatorTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile EqualityOperator" do
8
+ tree = EqualityOperator.new("==", 0)
9
+ bytecode = tree.compile
10
+ assert_equal [EQUAL], bytecode
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class GreaterThanOperatorTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile GreaterThanOperator" do
8
+ tree = GreaterThanOperator.new(">", 0)
9
+ bytecode = tree.compile
10
+ assert_equal [GREATER_THAN], bytecode
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class InqualityOperatorTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile InqualityOperator" do
8
+ tree = InequalityOperator.new("!=", 0)
9
+ bytecode = tree.compile
10
+ assert_equal [EQUAL, INVERT], bytecode
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class LessThanOperatorTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile LessThanOperator" do
8
+ tree = LessThanOperator.new("<", 0)
9
+ bytecode = tree.compile
10
+ assert_equal [LESS_THAN], bytecode
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class MultiplicationOperatorTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile MultiplicationOperator" do
8
+ tree = MultiplicationOperator.new("*", 0)
9
+ bytecode = tree.compile
10
+ assert_equal [MULTIPLY], bytecode
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class SubtractionOperatorTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile SubtractionOperator" do
8
+ tree = SubtractionOperator.new("-", 0)
9
+ bytecode = tree.compile
10
+ assert_equal [SUBTRACT], bytecode
11
+ end
12
+
13
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper.rb'))
2
+
3
+ class StatementTest < Test::Unit::TestCase
4
+
5
+ include KoiReferenceCompiler
6
+
7
+ test "should compile Statement" do
8
+ tree = Statement.new("test = 1", 0, [
9
+ Assignment.new("test = 1", 0, [
10
+ Identifier.new("test", 0),
11
+ AssignmentOperator.new("=", 5),
12
+ Expression.new("1", 7, [
13
+ IntegerLiteral.new("1", 7)
14
+ ])
15
+ ])
16
+ ])
17
+ bytecode = tree.compile
18
+ assert_equal [
19
+ PUSH_INT, 1,
20
+ SET_LOCAL, :test
21
+ ], bytecode
22
+ end
23
+
24
+ end
@@ -0,0 +1,21 @@
1
+ module Test::Unit
2
+ # Used to fix a minor minitest/unit incompatibility in flexmock
3
+ AssertionFailedError = Class.new(StandardError)
4
+
5
+ class TestCase
6
+
7
+ def self.test(name, &block)
8
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
9
+ defined = instance_method(test_name) rescue false
10
+ raise "#{test_name} is already defined in #{self}" if defined
11
+ if block_given?
12
+ define_method(test_name, &block)
13
+ else
14
+ define_method(test_name) do
15
+ flunk "No implementation provided for #{name}"
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ require_files = []
5
+ require_files << File.join(File.dirname(__FILE__), '..', 'lib', 'koi-reference-compiler.rb')
6
+ require_files.concat Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')]
7
+
8
+ require_files.each do |file|
9
+ require File.expand_path(file)
10
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koi-reference-compiler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Aaron Gough
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-31 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: The reference compiler for the Koi language.
22
+ email: aaron@aarongough.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - MIT-LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .gitignore
32
+ - MIT-LICENSE
33
+ - README.rdoc
34
+ - Rakefile
35
+ - VERSION
36
+ - lib/koi-reference-compiler.rb
37
+ - lib/koi-reference-compiler/exceptions.rb
38
+ - lib/koi-reference-compiler/koi-reference-compiler.rb
39
+ - lib/koi-reference-compiler/node_extensions/assignment/assignment.rb
40
+ - lib/koi-reference-compiler/node_extensions/blocks/block.rb
41
+ - lib/koi-reference-compiler/node_extensions/control_flow/if.rb
42
+ - lib/koi-reference-compiler/node_extensions/control_flow/unless.rb
43
+ - lib/koi-reference-compiler/node_extensions/expressions/additive_expression.rb
44
+ - lib/koi-reference-compiler/node_extensions/expressions/comparative_expression.rb
45
+ - lib/koi-reference-compiler/node_extensions/expressions/expression.rb
46
+ - lib/koi-reference-compiler/node_extensions/expressions/multitive_expression.rb
47
+ - lib/koi-reference-compiler/node_extensions/functions/function_call.rb
48
+ - lib/koi-reference-compiler/node_extensions/functions/function_definition.rb
49
+ - lib/koi-reference-compiler/node_extensions/hash_literals/hash_access.rb
50
+ - lib/koi-reference-compiler/node_extensions/hash_literals/hash_accessor.rb
51
+ - lib/koi-reference-compiler/node_extensions/hash_literals/hash_accessor_list.rb
52
+ - lib/koi-reference-compiler/node_extensions/hash_literals/hash_assignment.rb
53
+ - lib/koi-reference-compiler/node_extensions/hash_literals/hash_literal.rb
54
+ - lib/koi-reference-compiler/node_extensions/hash_literals/key_value.rb
55
+ - lib/koi-reference-compiler/node_extensions/hash_literals/key_value_list.rb
56
+ - lib/koi-reference-compiler/node_extensions/identifiers/identifier.rb
57
+ - lib/koi-reference-compiler/node_extensions/literals/false_literal.rb
58
+ - lib/koi-reference-compiler/node_extensions/literals/float_literal.rb
59
+ - lib/koi-reference-compiler/node_extensions/literals/integer_literal.rb
60
+ - lib/koi-reference-compiler/node_extensions/literals/nil_literal.rb
61
+ - lib/koi-reference-compiler/node_extensions/literals/string_literal.rb
62
+ - lib/koi-reference-compiler/node_extensions/literals/true_literal.rb
63
+ - lib/koi-reference-compiler/node_extensions/operators/addition_operator.rb
64
+ - lib/koi-reference-compiler/node_extensions/operators/assignment_operator.rb
65
+ - lib/koi-reference-compiler/node_extensions/operators/division_operator.rb
66
+ - lib/koi-reference-compiler/node_extensions/operators/equality_operator.rb
67
+ - lib/koi-reference-compiler/node_extensions/operators/great_than_operator.rb
68
+ - lib/koi-reference-compiler/node_extensions/operators/inequality_operator.rb
69
+ - lib/koi-reference-compiler/node_extensions/operators/less_than_operator.rb
70
+ - lib/koi-reference-compiler/node_extensions/operators/multiplication_operator.rb
71
+ - lib/koi-reference-compiler/node_extensions/operators/subtraction_operator.rb
72
+ - lib/koi-reference-compiler/node_extensions/statements/statement.rb
73
+ - lib/koi-reference-compiler/syntax_node.rb
74
+ - lib/koi-reference-compiler/vm_opcodes.rb
75
+ - test/compiler/unit/ast_hash_loader/ast_hash_loader_test.rb
76
+ - test/compiler/unit/node_extensions/assignment/assignment_test.rb
77
+ - test/compiler/unit/node_extensions/blocks/block_test.rb
78
+ - test/compiler/unit/node_extensions/control_flow/if_test.rb
79
+ - test/compiler/unit/node_extensions/control_flow/unless_test.rb
80
+ - test/compiler/unit/node_extensions/expressions/additive_expression_test.rb
81
+ - test/compiler/unit/node_extensions/expressions/comparative_expression_test.rb
82
+ - test/compiler/unit/node_extensions/expressions/expression_test.rb
83
+ - test/compiler/unit/node_extensions/expressions/multitive_expression_test.rb
84
+ - test/compiler/unit/node_extensions/functions/function_call_test.rb
85
+ - test/compiler/unit/node_extensions/functions/function_definition_test.rb
86
+ - test/compiler/unit/node_extensions/hash_literals/hash_accessor_list_test.rb
87
+ - test/compiler/unit/node_extensions/hash_literals/hash_accessor_test.rb
88
+ - test/compiler/unit/node_extensions/hash_literals/hash_literal_test.rb
89
+ - test/compiler/unit/node_extensions/hash_literals/key_value_list_test.rb
90
+ - test/compiler/unit/node_extensions/hash_literals/key_value_test.rb
91
+ - test/compiler/unit/node_extensions/identifiers/identifier_test.rb
92
+ - test/compiler/unit/node_extensions/literals/false_literal_test.rb
93
+ - test/compiler/unit/node_extensions/literals/float_literal_test.rb
94
+ - test/compiler/unit/node_extensions/literals/integer_literal_test.rb
95
+ - test/compiler/unit/node_extensions/literals/nil_literal_test.rb
96
+ - test/compiler/unit/node_extensions/literals/string_literal_test.rb
97
+ - test/compiler/unit/node_extensions/literals/true_literal_test.rb
98
+ - test/compiler/unit/node_extensions/operators/addition_operator_test.rb
99
+ - test/compiler/unit/node_extensions/operators/division_operator_test.rb
100
+ - test/compiler/unit/node_extensions/operators/equality_operator_test.rb
101
+ - test/compiler/unit/node_extensions/operators/greater_than_operator_test.rb
102
+ - test/compiler/unit/node_extensions/operators/inequality_operator_test.rb
103
+ - test/compiler/unit/node_extensions/operators/less_than_operator_test.rb
104
+ - test/compiler/unit/node_extensions/operators/multiplication_operator_test.rb
105
+ - test/compiler/unit/node_extensions/operators/subtraction_operator_test.rb
106
+ - test/compiler/unit/node_extensions/statements/statement_test.rb
107
+ - test/setup/test_unit_extensions.rb
108
+ - test/test_helper.rb
109
+ has_rdoc: true
110
+ homepage: http://github.com/aarongough/min-koi
111
+ licenses: []
112
+
113
+ post_install_message:
114
+ rdoc_options:
115
+ - --charset=UTF-8
116
+ - --line-numbers
117
+ - --inline-source
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project:
139
+ rubygems_version: 1.3.7
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: The reference compiler for the Koi language.
143
+ test_files:
144
+ - test/compiler/unit/ast_hash_loader/ast_hash_loader_test.rb
145
+ - test/compiler/unit/node_extensions/assignment/assignment_test.rb
146
+ - test/compiler/unit/node_extensions/blocks/block_test.rb
147
+ - test/compiler/unit/node_extensions/control_flow/if_test.rb
148
+ - test/compiler/unit/node_extensions/control_flow/unless_test.rb
149
+ - test/compiler/unit/node_extensions/expressions/additive_expression_test.rb
150
+ - test/compiler/unit/node_extensions/expressions/comparative_expression_test.rb
151
+ - test/compiler/unit/node_extensions/expressions/expression_test.rb
152
+ - test/compiler/unit/node_extensions/expressions/multitive_expression_test.rb
153
+ - test/compiler/unit/node_extensions/functions/function_call_test.rb
154
+ - test/compiler/unit/node_extensions/functions/function_definition_test.rb
155
+ - test/compiler/unit/node_extensions/hash_literals/hash_accessor_list_test.rb
156
+ - test/compiler/unit/node_extensions/hash_literals/hash_accessor_test.rb
157
+ - test/compiler/unit/node_extensions/hash_literals/hash_literal_test.rb
158
+ - test/compiler/unit/node_extensions/hash_literals/key_value_list_test.rb
159
+ - test/compiler/unit/node_extensions/hash_literals/key_value_test.rb
160
+ - test/compiler/unit/node_extensions/identifiers/identifier_test.rb
161
+ - test/compiler/unit/node_extensions/literals/false_literal_test.rb
162
+ - test/compiler/unit/node_extensions/literals/float_literal_test.rb
163
+ - test/compiler/unit/node_extensions/literals/integer_literal_test.rb
164
+ - test/compiler/unit/node_extensions/literals/nil_literal_test.rb
165
+ - test/compiler/unit/node_extensions/literals/string_literal_test.rb
166
+ - test/compiler/unit/node_extensions/literals/true_literal_test.rb
167
+ - test/compiler/unit/node_extensions/operators/addition_operator_test.rb
168
+ - test/compiler/unit/node_extensions/operators/division_operator_test.rb
169
+ - test/compiler/unit/node_extensions/operators/equality_operator_test.rb
170
+ - test/compiler/unit/node_extensions/operators/greater_than_operator_test.rb
171
+ - test/compiler/unit/node_extensions/operators/inequality_operator_test.rb
172
+ - test/compiler/unit/node_extensions/operators/less_than_operator_test.rb
173
+ - test/compiler/unit/node_extensions/operators/multiplication_operator_test.rb
174
+ - test/compiler/unit/node_extensions/operators/subtraction_operator_test.rb
175
+ - test/compiler/unit/node_extensions/statements/statement_test.rb
176
+ - test/setup/test_unit_extensions.rb
177
+ - test/test_helper.rb