mirah 0.0.7-java → 0.0.8-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. data/History.txt +181 -0
  2. data/README.txt +6 -10
  3. data/Rakefile +86 -9
  4. data/bin/mirah +2 -0
  5. data/bin/mirahc +2 -0
  6. data/bin/mirahp +2 -0
  7. data/{bin/dubyp → examples/interfaces.mirah} +16 -9
  8. data/examples/macros/square.mirah +12 -0
  9. data/examples/macros/square_int.mirah +12 -0
  10. data/examples/macros/string-each-char.mirah +14 -0
  11. data/examples/maven/README.txt +2 -0
  12. data/examples/maven/pom.xml +23 -0
  13. data/examples/maven/src/main/mirah/hello_mirah.mirah +9 -0
  14. data/examples/rosettacode/100-doors.mirah +44 -0
  15. data/examples/rosettacode/99-bottles-of-beer.mirah +13 -0
  16. data/examples/rosettacode/README.txt +9 -0
  17. data/examples/rosettacode/boolean-values.mirah +29 -0
  18. data/examples/rosettacode/comments.mirah +2 -0
  19. data/examples/rosettacode/copy-a-string.mirah +10 -0
  20. data/examples/rosettacode/count-occurrences-of-a-substring.mirah +40 -0
  21. data/examples/rosettacode/create-a-file.mirah +6 -0
  22. data/examples/rosettacode/empty-string.mirah +9 -0
  23. data/examples/rosettacode/factorial.mirah +10 -0
  24. data/examples/rosettacode/fibonacci.mirah +21 -0
  25. data/examples/rosettacode/file-size.mirah +5 -0
  26. data/examples/rosettacode/fizz-buzz.mirah +21 -0
  27. data/examples/rosettacode/flatten-a-list.mirah +24 -0
  28. data/examples/rosettacode/guess-the-number.mirah +21 -0
  29. data/examples/rosettacode/is-string-numeric.mirah +127 -0
  30. data/examples/rosettacode/palindrome.mirah +14 -0
  31. data/examples/rosettacode/repeat-a-string.mirah +9 -0
  32. data/examples/rosettacode/reverse-a-string.mirah +6 -0
  33. data/examples/rosettacode/rot-13.mirah +20 -0
  34. data/examples/rosettacode/user-input.mirah +4 -0
  35. data/examples/sort_closure.mirah +1 -1
  36. data/javalib/dynalink-0.2.jar +0 -0
  37. data/javalib/mirah-bootstrap.jar +0 -0
  38. data/lib/mirah.rb +7 -16
  39. data/lib/mirah/ast.rb +22 -92
  40. data/lib/mirah/ast/call.rb +41 -9
  41. data/lib/mirah/ast/class.rb +34 -6
  42. data/lib/mirah/ast/flow.rb +17 -5
  43. data/lib/mirah/ast/intrinsics.rb +50 -8
  44. data/lib/mirah/ast/literal.rb +7 -0
  45. data/lib/mirah/ast/local.rb +9 -1
  46. data/lib/mirah/ast/method.rb +21 -8
  47. data/lib/mirah/ast/scope.rb +1 -1
  48. data/lib/mirah/ast/structure.rb +81 -15
  49. data/lib/mirah/ast/type.rb +4 -0
  50. data/{bin/dubyc → lib/mirah/commands.rb} +4 -11
  51. data/lib/mirah/commands/base.rb +54 -0
  52. data/lib/mirah/commands/compile.rb +39 -0
  53. data/{examples/wiki/Rakefile → lib/mirah/commands/parse.rb} +18 -17
  54. data/lib/mirah/commands/run.rb +73 -0
  55. data/lib/mirah/compiler.rb +37 -417
  56. data/lib/mirah/compiler/call.rb +45 -0
  57. data/lib/mirah/compiler/class.rb +81 -0
  58. data/lib/mirah/compiler/flow.rb +109 -0
  59. data/lib/mirah/compiler/literal.rb +130 -0
  60. data/lib/mirah/compiler/local.rb +59 -0
  61. data/lib/mirah/compiler/method.rb +44 -0
  62. data/lib/mirah/compiler/structure.rb +65 -0
  63. data/lib/mirah/compiler/type.rb +27 -0
  64. data/lib/mirah/env.rb +4 -6
  65. data/lib/mirah/generator.rb +61 -0
  66. data/lib/mirah/jvm/compiler.rb +8 -867
  67. data/lib/mirah/jvm/compiler/base.rb +270 -0
  68. data/lib/mirah/jvm/compiler/java_source.rb +779 -0
  69. data/lib/mirah/jvm/compiler/jvm_bytecode.rb +851 -0
  70. data/lib/mirah/jvm/method_lookup.rb +21 -2
  71. data/lib/mirah/jvm/source_generator/builder.rb +10 -13
  72. data/lib/mirah/jvm/source_generator/loops.rb +99 -93
  73. data/lib/mirah/jvm/source_generator/precompile.rb +3 -2
  74. data/lib/mirah/jvm/typer.rb +3 -3
  75. data/lib/mirah/jvm/types.rb +10 -426
  76. data/lib/mirah/jvm/types/array_type.rb +62 -0
  77. data/lib/mirah/jvm/types/basic_types.rb +1 -0
  78. data/lib/mirah/jvm/types/dynamic_type.rb +46 -0
  79. data/lib/mirah/jvm/types/factory.rb +23 -5
  80. data/lib/mirah/jvm/types/interface_definition.rb +20 -0
  81. data/lib/mirah/jvm/types/intrinsics.rb +15 -3
  82. data/lib/mirah/jvm/types/meta_type.rb +45 -0
  83. data/lib/mirah/jvm/types/methods.rb +12 -5
  84. data/lib/mirah/jvm/types/null_type.rb +27 -0
  85. data/lib/mirah/jvm/types/primitive_type.rb +38 -0
  86. data/lib/mirah/jvm/types/source_mirror.rb +266 -0
  87. data/lib/mirah/jvm/types/type.rb +173 -0
  88. data/lib/mirah/jvm/types/type_definition.rb +55 -0
  89. data/lib/mirah/jvm/types/unreachable_type.rb +27 -0
  90. data/lib/mirah/jvm/types/void_type.rb +19 -0
  91. data/lib/mirah/parser.rb +90 -0
  92. data/lib/mirah/plugin/gwt.rb +5 -5
  93. data/lib/mirah/plugin/java.rb +1 -1
  94. data/lib/mirah/transform.rb +4 -321
  95. data/lib/mirah/transform/ast_ext.rb +63 -0
  96. data/lib/mirah/transform/error.rb +13 -0
  97. data/lib/mirah/transform/helper.rb +761 -0
  98. data/lib/mirah/transform/transformer.rb +255 -0
  99. data/lib/mirah/typer.rb +2 -383
  100. data/{bin/duby → lib/mirah/typer/base.rb} +12 -10
  101. data/lib/mirah/typer/simple.rb +377 -0
  102. data/lib/mirah/util/argument_processor.rb +114 -0
  103. data/lib/mirah/util/class_loader.rb +37 -0
  104. data/lib/mirah/util/compilation_state.rb +51 -0
  105. data/lib/mirah/util/process_errors.rb +33 -0
  106. data/lib/mirah/version.rb +1 -1
  107. data/lib/mirah_task.rb +3 -2
  108. data/test/{test_ast.rb → core/test_ast.rb} +6 -0
  109. data/test/{test_compilation.rb → core/test_compilation.rb} +0 -0
  110. data/test/{test_env.rb → core/test_env.rb} +24 -25
  111. data/test/{test_macros.rb → core/test_macros.rb} +2 -4
  112. data/test/{test_typer.rb → core/test_typer.rb} +0 -3
  113. data/test/jvm/bytecode_test_helper.rb +181 -0
  114. data/test/{test_javac_compiler.rb → jvm/javac_test_helper.rb} +38 -22
  115. data/test/jvm/test_enumerable.rb +304 -0
  116. data/test/{test_java_typer.rb → jvm/test_java_typer.rb} +2 -4
  117. data/test/{test_jvm_compiler.rb → jvm/test_jvm_compiler.rb} +146 -443
  118. data/test/jvm/test_macros.rb +147 -0
  119. data/test/jvm/test_main_method.rb +15 -0
  120. data/test/{test_gwt.rb → plugins/test_gwt.rb} +0 -2
  121. metadata +103 -91
  122. data/bin/jrubyp +0 -52
  123. data/examples/wiki/src/org/mirah/wiki/MirahWiki.duby +0 -339
  124. data/examples/wiki/src/org/mirah/wiki/edit.eduby.html +0 -42
  125. data/examples/wiki/src/org/mirah/wiki/error.eduby.html +0 -2
  126. data/examples/wiki/src/org/mirah/wiki/layout.eduby.html +0 -69
  127. data/examples/wiki/src/org/mirah/wiki/parser.eduby.html +0 -7
  128. data/examples/wiki/src/org/mirah/wiki/view.eduby.html +0 -15
  129. data/examples/wiki/war/WEB-INF/classes/test/HeredocContext.class +0 -0
  130. data/examples/wiki/war/WEB-INF/classes/test/MirahParser.class +0 -0
  131. data/examples/wiki/war/WEB-INF/lib/appengine-api.jar +0 -0
  132. data/examples/wiki/war/WEB-INF/lib/dubydatastore.jar +0 -0
  133. data/examples/wiki/war/WEB-INF/lib/jmeta-runtime.jar +0 -0
  134. data/examples/wiki/war/WEB-INF/lib/pegdown-stubs.jar +0 -0
  135. data/examples/wiki/war/WEB-INF/pegdown.jar +0 -0
  136. data/examples/wiki/war/app.yaml +0 -21
  137. data/examples/wiki/war/public/favicon.ico +0 -0
  138. data/examples/wiki/war/public/images/appengine_duby.png +0 -0
  139. data/examples/wiki/war/public/images/back.gif +0 -0
  140. data/examples/wiki/war/public/images/dir.gif +0 -0
  141. data/examples/wiki/war/public/images/file.gif +0 -0
  142. data/examples/wiki/war/public/javascripts/prettify.js +0 -61
  143. data/examples/wiki/war/public/robots.txt +0 -0
  144. data/examples/wiki/war/public/stylesheets/main.css +0 -156
  145. data/examples/wiki/war/public/stylesheets/prettify.css +0 -1
  146. data/examples/wiki/war/public/stylesheets/sh_style.css +0 -66
  147. data/examples/wiki/war/public/stylesheets/source.css +0 -21
  148. data/examples/wiki/war/public/wmd/images/bg-fill.png +0 -0
  149. data/examples/wiki/war/public/wmd/images/bg.png +0 -0
  150. data/examples/wiki/war/public/wmd/images/blockquote.png +0 -0
  151. data/examples/wiki/war/public/wmd/images/bold.png +0 -0
  152. data/examples/wiki/war/public/wmd/images/code.png +0 -0
  153. data/examples/wiki/war/public/wmd/images/h1.png +0 -0
  154. data/examples/wiki/war/public/wmd/images/hr.png +0 -0
  155. data/examples/wiki/war/public/wmd/images/img.png +0 -0
  156. data/examples/wiki/war/public/wmd/images/italic.png +0 -0
  157. data/examples/wiki/war/public/wmd/images/link.png +0 -0
  158. data/examples/wiki/war/public/wmd/images/ol.png +0 -0
  159. data/examples/wiki/war/public/wmd/images/redo.png +0 -0
  160. data/examples/wiki/war/public/wmd/images/separator.png +0 -0
  161. data/examples/wiki/war/public/wmd/images/ul.png +0 -0
  162. data/examples/wiki/war/public/wmd/images/undo.png +0 -0
  163. data/examples/wiki/war/public/wmd/images/wmd-on.png +0 -0
  164. data/examples/wiki/war/public/wmd/images/wmd.png +0 -0
  165. data/examples/wiki/war/public/wmd/showdown.js +0 -421
  166. data/examples/wiki/war/public/wmd/wmd-base.js +0 -1799
  167. data/examples/wiki/war/public/wmd/wmd-plus.js +0 -311
  168. data/examples/wiki/war/public/wmd/wmd.js +0 -73
  169. data/examples/wiki/war/src/org/mirah/wiki/MirahWiki.duby +0 -339
  170. data/examples/wiki/war/src/org/mirah/wiki/edit.eduby.html +0 -42
  171. data/examples/wiki/war/src/org/mirah/wiki/error.eduby.html +0 -2
  172. data/examples/wiki/war/src/org/mirah/wiki/layout.eduby.html +0 -69
  173. data/examples/wiki/war/src/org/mirah/wiki/parser.eduby.html +0 -7
  174. data/examples/wiki/war/src/org/mirah/wiki/view.eduby.html +0 -15
  175. data/javalib/dynalink-0.1.jar +0 -0
  176. data/javalib/jsr292-mock.jar +0 -0
  177. data/lib/mirah/class_loader.rb +0 -35
  178. data/lib/mirah/compilation_state.rb +0 -28
  179. data/lib/mirah/impl.rb +0 -273
  180. data/lib/mirah/jvm/base.rb +0 -267
  181. data/lib/mirah/jvm/source_compiler.rb +0 -760
  182. data/lib/mirah/transform2.rb +0 -752
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Mirah
17
+ module AST
18
+ class FunctionalCall
19
+ def compile(compiler, expression)
20
+ compiler.line(line_number)
21
+ compiler.self_call(self, expression)
22
+ rescue Exception => ex
23
+ raise Mirah::InternalCompilerError.wrap(ex, self)
24
+ end
25
+ end
26
+
27
+ class Call
28
+ def compile(compiler, expression)
29
+ compiler.line(line_number)
30
+ compiler.call(self, expression)
31
+ rescue Exception => ex
32
+ raise Mirah::InternalCompilerError.wrap(ex, self)
33
+ end
34
+ end
35
+
36
+ class Super
37
+ def compile(compiler, expression)
38
+ compiler.line(line_number)
39
+ compiler.super_call(self, expression)
40
+ rescue Exception => ex
41
+ raise Mirah::InternalCompilerError.wrap(ex, self)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,81 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Mirah
17
+ module AST
18
+ class ClassDefinition
19
+ def compile(compiler, expression)
20
+ compiler.define_class(self, expression)
21
+ rescue Exception => ex
22
+ raise Mirah::InternalCompilerError.wrap(ex, self)
23
+ end
24
+ end
25
+
26
+ class ClosureDefinition
27
+ def compile(compiler, expression)
28
+ compiler.define_closure(self, expression)
29
+ rescue Exception => ex
30
+ raise Mirah::InternalCompilerError.wrap(ex, self)
31
+ end
32
+ end
33
+
34
+ class AccessLevel
35
+ def compile(compiler, expression); end
36
+ end
37
+
38
+ class FieldDeclaration
39
+ def compile(compiler, expression)
40
+ compiler.field_declare(name, inferred_type, annotations, static)
41
+ rescue Exception => ex
42
+ raise Mirah::InternalCompilerError.wrap(ex, self)
43
+ end
44
+ end
45
+
46
+ class FieldAssignment
47
+ def compile(compiler, expression)
48
+ compiler.line(line_number)
49
+ compiler.field_assign(name, inferred_type, expression, value, annotations, static)
50
+ rescue Exception => ex
51
+ raise Mirah::InternalCompilerError.wrap(ex, self)
52
+ end
53
+ end
54
+
55
+ class Field
56
+ def compile(compiler, expression)
57
+ compiler.line(line_number)
58
+ if expression
59
+ compiler.field(name, inferred_type, annotations, static)
60
+ end
61
+ rescue Exception => ex
62
+ raise Mirah::InternalCompilerError.wrap(ex, self)
63
+ end
64
+ end
65
+
66
+ class Include
67
+ def compile(compiler, expression); end
68
+ end
69
+
70
+ class Constant
71
+ def compile(compiler, expression)
72
+ if expression
73
+ compiler.line(line_number)
74
+ compiler.constant(self)
75
+ end
76
+ rescue Exception => ex
77
+ raise Mirah::InternalCompilerError.wrap(ex, self)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,109 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Mirah
17
+ module AST
18
+ class If
19
+ def compile(compiler, expression)
20
+ compiler.line(line_number)
21
+ compiler.branch(self, expression)
22
+ rescue Exception => ex
23
+ raise Mirah::InternalCompilerError.wrap(ex, self)
24
+ end
25
+ end
26
+
27
+ class Condition
28
+ def compile(compiler, expression)
29
+ # TODO: can a condition ever be an expression? I don't think it can...
30
+ compiler.line(line_number)
31
+ predicate.compile(compiler, expression)
32
+ rescue Exception => ex
33
+ raise Mirah::InternalCompilerError.wrap(ex, self)
34
+ end
35
+ end
36
+
37
+ class Loop
38
+ def compile(compiler, expression)
39
+ compiler.line(line_number)
40
+ compiler.loop(self, expression)
41
+ rescue Exception => ex
42
+ raise Mirah::InternalCompilerError.wrap(ex, self)
43
+ end
44
+ end
45
+
46
+ class Return
47
+ def compile(compiler, expression)
48
+ compiler.line(line_number)
49
+ compiler.return(self)
50
+ rescue Exception => ex
51
+ raise Mirah::InternalCompilerError.wrap(ex, self)
52
+ end
53
+ end
54
+
55
+ class Break
56
+ def compile(compiler, expression)
57
+ compiler.line(line_number)
58
+ compiler.break(self)
59
+ rescue Exception => ex
60
+ raise Mirah::InternalCompilerError.wrap(ex, self)
61
+ end
62
+ end
63
+
64
+ class Next
65
+ def compile(compiler, expression)
66
+ compiler.line(line_number)
67
+ compiler.next(self)
68
+ rescue Exception => ex
69
+ raise Mirah::InternalCompilerError.wrap(ex, self)
70
+ end
71
+ end
72
+
73
+ class Redo
74
+ def compile(compiler, expression)
75
+ compiler.line(line_number)
76
+ compiler.redo(self)
77
+ rescue Exception => ex
78
+ raise Mirah::InternalCompilerError.wrap(ex, self)
79
+ end
80
+ end
81
+
82
+ class Raise
83
+ def compile(compiler, expression)
84
+ compiler.line(line_number)
85
+ compiler._raise(exception)
86
+ rescue Exception => ex
87
+ raise Mirah::InternalCompilerError.wrap(ex, self)
88
+ end
89
+ end
90
+
91
+ class Rescue
92
+ def compile(compiler, expression)
93
+ compiler.line(line_number)
94
+ compiler.rescue(self, expression)
95
+ rescue Exception => ex
96
+ raise Mirah::InternalCompilerError.wrap(ex, self)
97
+ end
98
+ end
99
+
100
+ class Ensure
101
+ def compile(compiler, expression)
102
+ compiler.line(line_number)
103
+ compiler.ensure(self, expression)
104
+ rescue Exception => ex
105
+ raise Mirah::InternalCompilerError.wrap(ex, self)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,130 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Mirah
17
+ module AST
18
+ class Fixnum
19
+ def compile(compiler, expression)
20
+ if expression
21
+ compiler.line(line_number)
22
+ compiler.fixnum(inferred_type, literal)
23
+ end
24
+ rescue Exception => ex
25
+ raise Mirah::InternalCompilerError.wrap(ex, self)
26
+ end
27
+ end
28
+
29
+ class Regexp
30
+ def compile(compiler, expression)
31
+ if expression
32
+ compiler.line(line_number)
33
+ compiler.regexp(literal)
34
+ end
35
+ rescue Exception => ex
36
+ raise Mirah::InternalCompilerError.wrap(ex, self)
37
+ end
38
+ end
39
+
40
+ class String
41
+ def compile(compiler, expression)
42
+ if expression
43
+ compiler.line(line_number)
44
+ compiler.string(literal)
45
+ end
46
+ rescue Exception => ex
47
+ raise Mirah::InternalCompilerError.wrap(ex, self)
48
+ end
49
+ end
50
+
51
+ class StringConcat
52
+ def compile(compiler, expression)
53
+ compiler.build_string(children, expression)
54
+ rescue Exception => ex
55
+ raise Mirah::InternalCompilerError.wrap(ex, self)
56
+ end
57
+ end
58
+
59
+ class ToString
60
+ def compile(compiler, expression)
61
+ compiler.to_string(body, expression)
62
+ rescue Exception => ex
63
+ raise Mirah::InternalCompilerError.wrap(ex, self)
64
+ end
65
+ end
66
+
67
+ class Float
68
+ def compile(compiler, expression)
69
+ if expression
70
+ compiler.line(line_number)
71
+ compiler.float(inferred_type, literal)
72
+ end
73
+ rescue Exception => ex
74
+ raise Mirah::InternalCompilerError.wrap(ex, self)
75
+ end
76
+ end
77
+
78
+ class Boolean
79
+ def compile(compiler, expression)
80
+ if expression
81
+ compiler.line(line_number)
82
+ compiler.boolean(literal)
83
+ end
84
+ rescue Exception => ex
85
+ raise Mirah::InternalCompilerError.wrap(ex, self)
86
+ end
87
+ end
88
+
89
+ class Array
90
+ def compile(compiler, expression)
91
+ compiler.array(self, expression)
92
+ rescue Exception => ex
93
+ raise Mirah::InternalCompilerError.wrap(ex, self)
94
+ end
95
+ end
96
+
97
+ class Null
98
+ def compile(compiler, expression)
99
+ if expression
100
+ compiler.line(line_number)
101
+ compiler.null
102
+ end
103
+ rescue Exception => ex
104
+ raise Mirah::InternalCompilerError.wrap(ex, self)
105
+ end
106
+ end
107
+
108
+ class EmptyArray
109
+ def compile(compiler, expression)
110
+ if expression
111
+ compiler.line(line_number)
112
+ compiler.empty_array(component_type, size)
113
+ end
114
+ rescue Exception => ex
115
+ raise Mirah::InternalCompilerError.wrap(ex, self)
116
+ end
117
+ end
118
+
119
+ class Self
120
+ def compile(compiler, expression)
121
+ if expression
122
+ compiler.line(line_number)
123
+ compiler.compile_self
124
+ end
125
+ rescue Exception => ex
126
+ raise Mirah::InternalCompilerError.wrap(ex, self)
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Mirah
17
+ module AST
18
+ class LocalDeclaration
19
+ def compile(compiler, expression)
20
+ compiler.line(line_number)
21
+ if captured? && scope.has_binding?
22
+ compiler.captured_local_declare(containing_scope, name, type)
23
+ else
24
+ compiler.local_declare(containing_scope, name, type)
25
+ end
26
+ rescue Exception => ex
27
+ raise Mirah::InternalCompilerError.wrap(ex, self)
28
+ end
29
+ end
30
+
31
+ class LocalAssignment
32
+ def compile(compiler, expression)
33
+ compiler.line(line_number)
34
+ if captured? && scope.has_binding?
35
+ compiler.captured_local_assign(self, expression)
36
+ else
37
+ compiler.local_assign(containing_scope, name, inferred_type, expression, value)
38
+ end
39
+ rescue Exception => ex
40
+ raise Mirah::InternalCompilerError.wrap(ex, self)
41
+ end
42
+ end
43
+
44
+ class Local
45
+ def compile(compiler, expression)
46
+ if expression
47
+ compiler.line(line_number)
48
+ if captured? && scope.has_binding?
49
+ compiler.captured_local(containing_scope, name, inferred_type)
50
+ else
51
+ compiler.local(containing_scope, name, inferred_type)
52
+ end
53
+ end
54
+ rescue Exception => ex
55
+ raise Mirah::InternalCompilerError.wrap(ex, self)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Mirah
17
+ module AST
18
+ class Arguments
19
+ def compile(compiler, expression)
20
+ # TODO: what does it mean for a method to be an expression?
21
+ args.each {|arg| compiler.declare_argument(arg.name, arg.inferred_type)} if args
22
+ rescue Exception => ex
23
+ raise Mirah::InternalCompilerError.wrap(ex, self)
24
+ end
25
+ end
26
+
27
+ class MethodDefinition
28
+ def compile(compiler, expression)
29
+ # TODO: what does it mean for a method to be an expression?
30
+ compiler.define_method(self)
31
+ rescue Exception => ex
32
+ raise Mirah::InternalCompilerError.wrap(ex, self)
33
+ end
34
+ end
35
+
36
+ class ConstructorDefinition
37
+ def compile(compiler, expression)
38
+ compiler.constructor(self)
39
+ rescue Exception => ex
40
+ raise Mirah::InternalCompilerError.wrap(ex, self)
41
+ end
42
+ end
43
+ end
44
+ end