mirah 0.0.12-java → 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/History.txt +372 -0
  2. data/README.txt +4 -5
  3. data/Rakefile +178 -55
  4. data/examples/appengine/Readme +3 -3
  5. data/examples/appengine/src/org/mirah/MirahApp.mirah +1 -1
  6. data/examples/appengine/src/org/mirah/list.dhtml +1 -1
  7. data/examples/bintrees.mirah +1 -1
  8. data/examples/edb.mirah +1 -1
  9. data/examples/fib.mirah +1 -1
  10. data/examples/interfaces.mirah +1 -1
  11. data/examples/macros/{string-each-char.mirah → string_each_char.mirah} +4 -5
  12. data/examples/maven/README.txt +1 -1
  13. data/examples/maven/src/main/mirah/hello_mirah.mirah +1 -1
  14. data/examples/plugins/appengine/Rakefile +1 -1
  15. data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/MetaModel.mirah +1 -1
  16. data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/Model.duby +1 -1
  17. data/examples/plugins/appengine/test/com/google/appengine/ext/duby/db/ModelTest.duby +1 -1
  18. data/examples/rosettacode/100-doors.mirah +6 -6
  19. data/examples/rosettacode/README.txt +3 -3
  20. data/examples/rosettacode/boolean-values.mirah +1 -1
  21. data/examples/rosettacode/comments.mirah +1 -1
  22. data/examples/rosettacode/count-occurrences-of-a-substring.mirah +1 -1
  23. data/examples/rosettacode/factorial.mirah +1 -1
  24. data/examples/rosettacode/fibonacci.mirah +1 -1
  25. data/examples/rosettacode/fizz-buzz.mirah +2 -2
  26. data/examples/rosettacode/flatten-a-list.mirah +4 -4
  27. data/examples/rosettacode/guess-the-number.mirah +2 -2
  28. data/examples/rosettacode/hamming-numbers.mirah +4 -4
  29. data/examples/rosettacode/is-string-numeric.mirah +22 -22
  30. data/examples/rosettacode/palindrome.mirah +2 -2
  31. data/examples/rosettacode/random-numbers.mirah +1 -1
  32. data/examples/rosettacode/repeat-a-string.mirah +1 -1
  33. data/examples/rosettacode/reverse-a-string.mirah +1 -1
  34. data/examples/rosettacode/rot-13.mirah +5 -5
  35. data/examples/rosettacode/secure-temporary-file.mirah +2 -2
  36. data/examples/rosettacode/sleep.mirah +1 -1
  37. data/examples/rosettacode/string-length.mirah +5 -5
  38. data/examples/swing.mirah +1 -1
  39. data/examples/test.edb +1 -1
  40. data/javalib/mirah-bootstrap.jar +0 -0
  41. data/javalib/mirah-builtins.jar +0 -0
  42. data/javalib/mirah-parser.jar +0 -0
  43. data/javalib/mirah-util.jar +0 -0
  44. data/lib/duby.rb +1 -1
  45. data/lib/mirah.rb +50 -28
  46. data/lib/mirah/ast.rb +15 -605
  47. data/lib/mirah/ast/scope.rb +98 -69
  48. data/lib/mirah/commands.rb +1 -1
  49. data/lib/mirah/commands/base.rb +7 -7
  50. data/lib/mirah/commands/compile.rb +3 -3
  51. data/lib/mirah/commands/parse.rb +7 -5
  52. data/lib/mirah/commands/run.rb +12 -19
  53. data/lib/mirah/compiler.rb +15 -23
  54. data/lib/mirah/errors.rb +16 -1
  55. data/lib/mirah/generator.rb +79 -39
  56. data/lib/mirah/jvm/compiler.rb +1 -19
  57. data/lib/mirah/jvm/compiler/base.rb +233 -90
  58. data/lib/mirah/jvm/compiler/jvm_bytecode.rb +675 -363
  59. data/lib/mirah/jvm/method_lookup.rb +134 -65
  60. data/lib/mirah/jvm/typer.rb +10 -5
  61. data/lib/mirah/jvm/types.rb +10 -2
  62. data/lib/mirah/jvm/types/array_type.rb +10 -12
  63. data/lib/mirah/{compiler/type.rb → jvm/types/ast_ext.rb} +12 -8
  64. data/lib/mirah/jvm/types/basic_types.rb +26 -33
  65. data/lib/mirah/jvm/types/bitescript_ext.rb +1 -1
  66. data/lib/mirah/jvm/types/block_type.rb +15 -0
  67. data/lib/mirah/jvm/types/boolean.rb +8 -4
  68. data/lib/mirah/jvm/types/dynamic_type.rb +12 -13
  69. data/lib/mirah/jvm/types/enumerable.rb +7 -7
  70. data/lib/mirah/jvm/types/extensions.rb +11 -6
  71. data/lib/mirah/jvm/types/factory.rb +624 -94
  72. data/lib/mirah/jvm/types/floats.rb +21 -15
  73. data/lib/mirah/jvm/types/generic_type.rb +72 -0
  74. data/lib/mirah/jvm/types/implicit_nil_type.rb +29 -0
  75. data/lib/mirah/jvm/types/integers.rb +26 -71
  76. data/lib/mirah/jvm/types/interface_definition.rb +3 -3
  77. data/lib/mirah/jvm/types/intrinsics.rb +203 -168
  78. data/lib/mirah/jvm/types/literals.rb +6 -6
  79. data/lib/mirah/jvm/types/meta_type.rb +13 -4
  80. data/lib/mirah/jvm/types/methods.rb +281 -93
  81. data/lib/mirah/jvm/types/null_type.rb +17 -5
  82. data/lib/mirah/jvm/types/number.rb +10 -7
  83. data/lib/mirah/jvm/types/primitive_type.rb +17 -6
  84. data/lib/mirah/jvm/types/source_mirror.rb +12 -7
  85. data/lib/mirah/jvm/types/type.rb +107 -23
  86. data/lib/mirah/jvm/types/type_definition.rb +25 -10
  87. data/lib/mirah/jvm/types/unreachable_type.rb +1 -1
  88. data/lib/mirah/jvm/types/void_type.rb +3 -3
  89. data/lib/mirah/parser.rb +154 -16
  90. data/lib/mirah/plugin/edb.rb +1 -1
  91. data/lib/mirah/transform.rb +1 -2
  92. data/lib/mirah/transform/ast_ext.rb +24 -43
  93. data/lib/mirah/transform/transformer.rb +29 -224
  94. data/lib/mirah/typer.rb +2 -16
  95. data/lib/mirah/util/argument_processor.rb +25 -10
  96. data/lib/mirah/util/class_loader.rb +1 -1
  97. data/lib/mirah/util/compilation_state.rb +16 -17
  98. data/lib/mirah/util/delegate.rb +2 -2
  99. data/lib/mirah/util/logging.rb +110 -0
  100. data/lib/mirah/util/process_errors.rb +69 -11
  101. data/lib/mirah/version.rb +1 -1
  102. data/test/core/commands_test.rb +6 -24
  103. data/test/core/env_test.rb +5 -5
  104. data/{lib/mirah/jvm/source_generator/typer.rb → test/core/generator_test.rb} +9 -9
  105. data/test/core/typer_test.rb +196 -158
  106. data/test/core/util/argument_processor_test.rb +10 -10
  107. data/test/core/util/class_loader_test.rb +6 -5
  108. data/test/fixtures/org/foo/LowerCaseInnerClass$inner.class +0 -0
  109. data/test/fixtures/org/foo/LowerCaseInnerClass.class +0 -0
  110. data/test/fixtures/org/foo/LowerCaseInnerClass.java +7 -0
  111. data/test/jvm/annotations_test.rb +5 -5
  112. data/test/jvm/blocks_test.rb +140 -88
  113. data/test/jvm/bytecode_test_helper.rb +112 -94
  114. data/test/jvm/cast_test.rb +162 -0
  115. data/test/jvm/constructors_test.rb +18 -8
  116. data/test/jvm/enumerable_test.rb +77 -44
  117. data/test/jvm/example_test.rb +53 -0
  118. data/test/jvm/factory_test.rb +7 -1
  119. data/test/jvm/generics_test.rb +57 -0
  120. data/test/jvm/hash_test.rb +106 -0
  121. data/test/jvm/import_test.rb +81 -0
  122. data/test/jvm/interface_test.rb +73 -0
  123. data/test/jvm/java_typer_test.rb +92 -66
  124. data/{lib/mirah/typer/base.rb → test/jvm/jvm_commands_test.rb} +6 -10
  125. data/test/jvm/jvm_compiler_test.rb +170 -604
  126. data/test/jvm/list_extensions_test.rb +23 -0
  127. data/test/jvm/macros_test.rb +197 -32
  128. data/test/jvm/main_method_test.rb +4 -4
  129. data/test/jvm/numeric_extensions_test.rb +13 -0
  130. data/test/jvm/rescue_test.rb +73 -16
  131. data/test/jvm/varargs_test.rb +65 -0
  132. data/test/test_helper.rb +1 -2
  133. metadata +234 -251
  134. data/examples/SortClosure$__xform_tmp_1.class +0 -0
  135. data/examples/SortClosure$__xform_tmp_2.class +0 -0
  136. data/examples/SortClosure.class +0 -0
  137. data/examples/macros/StringEachChar$Extension1.class +0 -0
  138. data/lib/mirah/ast/call.rb +0 -345
  139. data/lib/mirah/ast/class.rb +0 -359
  140. data/lib/mirah/ast/flow.rb +0 -381
  141. data/lib/mirah/ast/intrinsics.rb +0 -563
  142. data/lib/mirah/ast/literal.rb +0 -178
  143. data/lib/mirah/ast/local.rb +0 -112
  144. data/lib/mirah/ast/method.rb +0 -408
  145. data/lib/mirah/ast/structure.rb +0 -387
  146. data/lib/mirah/ast/type.rb +0 -146
  147. data/lib/mirah/commands/base.rb~ +0 -57
  148. data/lib/mirah/compiler/call.rb +0 -45
  149. data/lib/mirah/compiler/class.rb +0 -81
  150. data/lib/mirah/compiler/flow.rb +0 -109
  151. data/lib/mirah/compiler/literal.rb +0 -130
  152. data/lib/mirah/compiler/local.rb +0 -59
  153. data/lib/mirah/compiler/method.rb +0 -44
  154. data/lib/mirah/compiler/structure.rb +0 -65
  155. data/lib/mirah/jvm/compiler/java_source.rb +0 -787
  156. data/lib/mirah/jvm/method_lookup.rb~ +0 -247
  157. data/lib/mirah/jvm/source_generator/builder.rb +0 -468
  158. data/lib/mirah/jvm/source_generator/loops.rb +0 -131
  159. data/lib/mirah/jvm/source_generator/precompile.rb +0 -210
  160. data/lib/mirah/plugin/gwt.rb +0 -189
  161. data/lib/mirah/plugin/java.rb +0 -70
  162. data/lib/mirah/transform/error.rb +0 -13
  163. data/lib/mirah/transform/helper.rb +0 -765
  164. data/lib/mirah/typer/simple.rb +0 -384
  165. data/lib/mirah/version.rb~ +0 -18
  166. data/test/core/ast_test.rb +0 -382
  167. data/test/core/compilation_test.rb +0 -130
  168. data/test/core/macros_test.rb +0 -61
  169. data/test/jvm/javac_test_helper.rb +0 -89
  170. data/test/jvm/jvm_compiler_test.rb~ +0 -2181
  171. data/test/plugins/gwt_test.rb +0 -69
@@ -1,131 +0,0 @@
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 JVM
18
- module Compiler
19
- class JavaSource < Base
20
- class SimpleWhileLoop
21
- attr_reader :compiler, :loop
22
- def initialize(loop, compiler)
23
- @loop = loop
24
- @compiler = compiler
25
- end
26
-
27
- def break
28
- compiler.method.puts "break;"
29
- end
30
-
31
- def next
32
- compiler.method.puts "continue;"
33
- end
34
-
35
- def redo
36
- raise "#{self.class.name} doesn't support redo"
37
- end
38
-
39
- def compile(expression)
40
- prepare
41
- @loop.init.compile(compiler, false) if @loop.init?
42
- @start.call
43
- compiler.method.block do
44
- @loop.pre.compile(compiler, false) if @loop.pre?
45
- compile_body
46
- @loop.post.compile(compiler, false) if @loop.post?
47
- end
48
- if @end_check
49
- @end_check.call
50
- compiler.method.puts ';'
51
- end
52
- if expression
53
- compiler.method.puts "#{compiler.lvalue}null;"
54
- end
55
- end
56
-
57
- def compile_body
58
- loop.body.compile(compiler, false) if loop.body
59
- end
60
-
61
- def prepare
62
- predicate = loop.condition.predicate.precompile(compiler)
63
- negative = loop.negative ? '!' : ''
64
- check = lambda do
65
- compiler.method.print "while (#{negative}"
66
- predicate.compile(compiler, true)
67
- compiler.method.print ')'
68
- end
69
- if loop.check_first
70
- @start = check
71
- else
72
- @start = lambda {compiler.method.print 'do'}
73
- @end_check = check
74
- end
75
- end
76
- end
77
-
78
- module Redoable
79
- def compile_with_redo(block)
80
- @redo = compiler.method.tmp(JVMTypes::Boolean)
81
- compiler.method.puts "#{@inner}:"
82
- compiler.method.block "do" do
83
- compiler.method.puts "#{@redo} = false;"
84
- block.compile(compiler, false) if block
85
- end
86
- compiler.method.puts "while (#{@redo});"
87
- end
88
-
89
- def break
90
- compiler.method.puts "break #{@outer};"
91
- end
92
-
93
- def next
94
- compiler.method.puts "break #{@inner};"
95
- end
96
-
97
- def redo
98
- compiler.method.puts "#{@redo} = true;"
99
- compiler.method.puts "continue #{@inner};"
100
- end
101
- end
102
-
103
- class ComplexWhileLoop < SimpleWhileLoop
104
- include Redoable
105
- def prepare
106
- super
107
- @outer = compiler.method.label
108
- @inner = compiler.method.label
109
- @complex_predicate = !loop.condition.predicate.expr?(compiler)
110
- super_start = @start
111
- @start = lambda do
112
- compiler.method.puts "#{@outer}:"
113
- super_start.call
114
- end
115
- end
116
-
117
- def compile_body
118
- if @loop.redo?
119
- compile_with_redo(@loop.body)
120
- else
121
- compiler.method.puts "#{@inner}:"
122
- compiler.method.block do
123
- loop.body.compile(compiler, false) if loop.body
124
- end
125
- end
126
- end
127
- end
128
- end
129
- end
130
- end
131
- end
@@ -1,210 +0,0 @@
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
- require 'mirah/ast'
17
-
18
- module Mirah::AST
19
- class TempValue
20
- def initialize(node, compiler=nil, value=nil)
21
- if compiler.nil?
22
- @tempname = node
23
- else
24
- @tempname = compiler.temp(node, value)
25
- @tempvalue = value || node
26
- end
27
- end
28
-
29
- def compile(compiler, expression)
30
- if expression
31
- compiler.method.print @tempname
32
- end
33
- end
34
-
35
- def reload(compiler)
36
- compiler.assign(@tempname, @tempvalue)
37
- end
38
- end
39
-
40
- class Node
41
- def expr?(compiler)
42
- true
43
- end
44
-
45
- def precompile(compiler)
46
- if expr?(compiler)
47
- self
48
- else
49
- temp(compiler)
50
- end
51
- end
52
-
53
- def temp(compiler, value=nil)
54
- TempValue.new(self, compiler, value)
55
- end
56
- end
57
-
58
- class Body
59
- def expr?(compiler)
60
- false
61
- end
62
- end
63
-
64
- class If
65
- def expr?(compiler)
66
- return false unless condition.predicate.expr?(compiler)
67
- return false unless body.nil? || body.expr?(compiler)
68
- return false unless self.else.nil? || self.else.expr?(compiler)
69
- true
70
- end
71
- end
72
-
73
- class Loop
74
- def expr?(compiler)
75
- false
76
- end
77
-
78
- def precompile(compiler)
79
- compile(compiler, false)
80
- temp(compiler, 'null')
81
- end
82
- end
83
-
84
- class Call
85
- def method(compiler=nil)
86
- @method ||= begin
87
- arg_types = parameters.map {|p| p.inferred_type}
88
- target.inferred_type.get_method(name, arg_types)
89
- end
90
- end
91
-
92
- def expr?(compiler)
93
- target.expr?(compiler) &&
94
- parameters.all? {|p| p.expr?(compiler)} &&
95
- cast || (
96
- !method.return_type.kind_of?(Mirah::AST::InlineCode) &&
97
- !method.return_type.void?)
98
- end
99
-
100
- def precompile_target(compiler)
101
- if method.return_type.void? && target.expr?(compiler)
102
- TempValue.new(target, compiler)
103
- else
104
- target.precompile(compiler)
105
- end
106
- end
107
- end
108
-
109
- class FunctionalCall
110
- def method(compiler)
111
- @method ||= begin
112
- arg_types = parameters.map {|p| p.inferred_type}
113
- @self_type.get_method(name, arg_types)
114
- end
115
- end
116
-
117
- def expr?(compiler)
118
- parameters.all? {|p| p.expr?(compiler)} &&
119
- (cast? || !method(compiler).return_type.void?)
120
- end
121
- end
122
-
123
- # TODO merge with FunctionalCall logic (almost identical)
124
- class Super
125
- def method(compiler)
126
- @method ||= begin
127
- arg_types = parameters.map {|p| p.inferred_type}
128
- compiler.self_type.superclass.get_method(name, arg_types)
129
- end
130
- end
131
-
132
- def expr?(compiler)
133
- parameters.all? {|p| p.expr?(compiler)} &&
134
- !method(compiler).return_type.void?
135
- end
136
- end
137
-
138
- class EmtpyArray
139
- def expr?(compiler)
140
- size.expr?(compiler)
141
- end
142
- end
143
-
144
- class LocalAssignment
145
- def expr?(compiler)
146
- compiler.method.local?(name) && value.expr?(compiler)
147
- end
148
-
149
- def precompile(compiler)
150
- if expr?(compiler)
151
- self
152
- else
153
- compile(compiler, false)
154
- TempValue.new(name)
155
- end
156
- end
157
- end
158
-
159
- class ToString
160
- def expr?(compiler)
161
- body.expr?(compiler)
162
- end
163
-
164
- def temp(compiler, value=nil)
165
- TempValue.new(body, compiler, value)
166
- end
167
- end
168
-
169
- class StringConcat
170
- def expr?(compiler)
171
- children.all? {|x| x.expr?(compiler)}
172
- end
173
- end
174
-
175
- class Return
176
- def expr?(compiler)
177
- false
178
- end
179
- end
180
-
181
- class Raise
182
- def expr?(compiler)
183
- false
184
- end
185
- end
186
-
187
- class Rescue
188
- def expr?(compiler)
189
- false
190
- end
191
- end
192
-
193
- class Ensure
194
- def expr?(compiler)
195
- false
196
- end
197
- end
198
-
199
- class FieldAssignment
200
- def expr?(compiler)
201
- false
202
- end
203
- end
204
-
205
- class Colon2
206
- def expr?(compiler)
207
- true
208
- end
209
- end
210
- end
@@ -1,189 +0,0 @@
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
- require 'mirah/jvm/source_generator/builder'
17
-
18
- module Mirah::JavaSource
19
- class ClassBuilder
20
- def build_jsni_method(name, visibility, static, exceptions, type, *args)
21
- finish_declaration
22
- type ||= Mirah::AST.type(nil, :void)
23
- @methods << JsniMethodBuilder.new(self,
24
- :name => name,
25
- :visibility => visibility,
26
- :static => static,
27
- :return => type,
28
- :args => args,
29
- :exceptions => exceptions)
30
- @methods[-1]
31
- end
32
- end
33
-
34
- class JsniMethodBuilder < MethodBuilder
35
- include Helper
36
-
37
- attr_accessor :name, :type, :out
38
-
39
- def initialize(cls, options)
40
- super(cls, options)
41
- end
42
-
43
- # Based on superclass's method.
44
- def start
45
- print "public#{@static} native #{@typename} #{@name}("
46
- @args.each_with_index do |(type, name), i|
47
- print ', ' unless i == 0
48
- print "#{type.to_source} #{name}"
49
- end
50
- print ')'
51
- unless @exceptions.empty?
52
- print ' throws '
53
- @exceptions.each_with_index do |exception, i|
54
- print ', ' unless i == 0
55
- print exception.name
56
- end
57
- end
58
- puts ' /*-{'
59
- end
60
-
61
- # Based on superclass's method.
62
- def stop
63
- puts '}-*/;'
64
- end
65
- end
66
- end
67
-
68
- module Mirah::JVM::Compiler
69
- class Base
70
- alias :original_create_method_builder :create_method_builder
71
- # arg_types must be an Array
72
- def create_method_builder(name, node, static, exceptions, return_type, arg_types)
73
- unless node.class == Mirah::AST::JsniMethodDefinition
74
- original_create_method_builder(name, node, static, exceptions, return_type, arg_types)
75
- else
76
- @class.build_jsni_method(name.to_s, node.visibility, static,
77
- exceptions, return_type, *arg_types)
78
- end
79
- end
80
- end
81
-
82
- class JavaSource < Base
83
- def define_jsni_method(node)
84
- base_define_method(node, false) do |method, arg_types|
85
- with :method => method do
86
- log "Starting new JSNI method #{node.name}"
87
- @method.start
88
-
89
- @method.puts node.body.literal.chomp
90
-
91
- log "JSNI method #{node.name} complete!"
92
- @method.stop
93
- end
94
- end
95
- end
96
- end
97
- end
98
-
99
- module Mirah::AST
100
- class JsniMethodDefinition < MethodDefinition
101
- def initialize(static, parent, line_number, name, annotations=[], &block)
102
- super(parent, line_number, name, annotations, &block)
103
- @static = static
104
- end
105
-
106
- def compile(compiler, expression)
107
- compiler.define_jsni_method(self)
108
- end
109
-
110
- def infer(typer, expression)
111
- @static ||= scope.static_scope.self_type.meta? unless scope.nil?
112
- @defining_class ||= begin
113
- static_scope.self_node = :self
114
- static_scope.self_type = if static?
115
- scope.static_scope.self_type.meta
116
- else
117
- scope.static_scope.self_type
118
- end
119
- end
120
- resolve_if(typer) do
121
- argument_types = typer.infer(arguments, true)
122
- if argument_types.all?
123
- typer.learn_method_type(defining_class, name, argument_types,
124
- signature[:return], signature[:throws])
125
- end
126
- end
127
- end
128
-
129
- # JSNI can't be abstract.
130
- def abstract?
131
- false
132
- end
133
-
134
- def static?
135
- @static
136
- end
137
- end
138
-
139
- defmacro 'def_jsni' do |transformer, fcall, parent|
140
- args = fcall.parameters
141
-
142
- unless args.size == 3
143
- raise "def_jsni must have 3 arguments."
144
- end
145
-
146
- call_node = args[1]
147
- if Self === call_node.target
148
- is_static = true
149
- end
150
-
151
- JsniMethodDefinition.new(is_static,
152
- parent,
153
- fcall.position,
154
- call_node.name,
155
- transformer.annotations) do |defn|
156
-
157
- signature = {:return => Mirah::AST.type(nil, args[0].name)}
158
- method = call_node.parameters[0]
159
-
160
- unless method.nil?
161
- hash_node = method.parameters[0]
162
-
163
- args = Arguments.new(defn, defn.position) do |args_new|
164
- arg_list = []
165
- hash_node.child_nodes.each_slice(2) do |name, type|
166
- position = name.position + type.position
167
- name = name.literal
168
- type = Mirah::AST.type(nil, type.name)
169
- signature[name.intern] = type
170
- arg_list.push(RequiredArgument.new(args_new, position, name))
171
- end
172
- [arg_list, nil, nil, nil]
173
- end
174
- else
175
- args = Arguments.new(defn, defn.position) do |args_new|
176
- [nil, nil, nil, nil]
177
- end
178
- end
179
-
180
- body_node = fcall.parameters[-1]
181
-
182
- [
183
- signature,
184
- args,
185
- body_node
186
- ]
187
- end
188
- end
189
- end