mirah 0.0.12-java → 0.1.0-java
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/History.txt +372 -0
- data/README.txt +4 -5
- data/Rakefile +178 -55
- data/examples/appengine/Readme +3 -3
- data/examples/appengine/src/org/mirah/MirahApp.mirah +1 -1
- data/examples/appengine/src/org/mirah/list.dhtml +1 -1
- data/examples/bintrees.mirah +1 -1
- data/examples/edb.mirah +1 -1
- data/examples/fib.mirah +1 -1
- data/examples/interfaces.mirah +1 -1
- data/examples/macros/{string-each-char.mirah → string_each_char.mirah} +4 -5
- data/examples/maven/README.txt +1 -1
- data/examples/maven/src/main/mirah/hello_mirah.mirah +1 -1
- data/examples/plugins/appengine/Rakefile +1 -1
- data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/MetaModel.mirah +1 -1
- data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/Model.duby +1 -1
- data/examples/plugins/appengine/test/com/google/appengine/ext/duby/db/ModelTest.duby +1 -1
- data/examples/rosettacode/100-doors.mirah +6 -6
- data/examples/rosettacode/README.txt +3 -3
- data/examples/rosettacode/boolean-values.mirah +1 -1
- data/examples/rosettacode/comments.mirah +1 -1
- data/examples/rosettacode/count-occurrences-of-a-substring.mirah +1 -1
- data/examples/rosettacode/factorial.mirah +1 -1
- data/examples/rosettacode/fibonacci.mirah +1 -1
- data/examples/rosettacode/fizz-buzz.mirah +2 -2
- data/examples/rosettacode/flatten-a-list.mirah +4 -4
- data/examples/rosettacode/guess-the-number.mirah +2 -2
- data/examples/rosettacode/hamming-numbers.mirah +4 -4
- data/examples/rosettacode/is-string-numeric.mirah +22 -22
- data/examples/rosettacode/palindrome.mirah +2 -2
- data/examples/rosettacode/random-numbers.mirah +1 -1
- data/examples/rosettacode/repeat-a-string.mirah +1 -1
- data/examples/rosettacode/reverse-a-string.mirah +1 -1
- data/examples/rosettacode/rot-13.mirah +5 -5
- data/examples/rosettacode/secure-temporary-file.mirah +2 -2
- data/examples/rosettacode/sleep.mirah +1 -1
- data/examples/rosettacode/string-length.mirah +5 -5
- data/examples/swing.mirah +1 -1
- data/examples/test.edb +1 -1
- data/javalib/mirah-bootstrap.jar +0 -0
- data/javalib/mirah-builtins.jar +0 -0
- data/javalib/mirah-parser.jar +0 -0
- data/javalib/mirah-util.jar +0 -0
- data/lib/duby.rb +1 -1
- data/lib/mirah.rb +50 -28
- data/lib/mirah/ast.rb +15 -605
- data/lib/mirah/ast/scope.rb +98 -69
- data/lib/mirah/commands.rb +1 -1
- data/lib/mirah/commands/base.rb +7 -7
- data/lib/mirah/commands/compile.rb +3 -3
- data/lib/mirah/commands/parse.rb +7 -5
- data/lib/mirah/commands/run.rb +12 -19
- data/lib/mirah/compiler.rb +15 -23
- data/lib/mirah/errors.rb +16 -1
- data/lib/mirah/generator.rb +79 -39
- data/lib/mirah/jvm/compiler.rb +1 -19
- data/lib/mirah/jvm/compiler/base.rb +233 -90
- data/lib/mirah/jvm/compiler/jvm_bytecode.rb +675 -363
- data/lib/mirah/jvm/method_lookup.rb +134 -65
- data/lib/mirah/jvm/typer.rb +10 -5
- data/lib/mirah/jvm/types.rb +10 -2
- data/lib/mirah/jvm/types/array_type.rb +10 -12
- data/lib/mirah/{compiler/type.rb → jvm/types/ast_ext.rb} +12 -8
- data/lib/mirah/jvm/types/basic_types.rb +26 -33
- data/lib/mirah/jvm/types/bitescript_ext.rb +1 -1
- data/lib/mirah/jvm/types/block_type.rb +15 -0
- data/lib/mirah/jvm/types/boolean.rb +8 -4
- data/lib/mirah/jvm/types/dynamic_type.rb +12 -13
- data/lib/mirah/jvm/types/enumerable.rb +7 -7
- data/lib/mirah/jvm/types/extensions.rb +11 -6
- data/lib/mirah/jvm/types/factory.rb +624 -94
- data/lib/mirah/jvm/types/floats.rb +21 -15
- data/lib/mirah/jvm/types/generic_type.rb +72 -0
- data/lib/mirah/jvm/types/implicit_nil_type.rb +29 -0
- data/lib/mirah/jvm/types/integers.rb +26 -71
- data/lib/mirah/jvm/types/interface_definition.rb +3 -3
- data/lib/mirah/jvm/types/intrinsics.rb +203 -168
- data/lib/mirah/jvm/types/literals.rb +6 -6
- data/lib/mirah/jvm/types/meta_type.rb +13 -4
- data/lib/mirah/jvm/types/methods.rb +281 -93
- data/lib/mirah/jvm/types/null_type.rb +17 -5
- data/lib/mirah/jvm/types/number.rb +10 -7
- data/lib/mirah/jvm/types/primitive_type.rb +17 -6
- data/lib/mirah/jvm/types/source_mirror.rb +12 -7
- data/lib/mirah/jvm/types/type.rb +107 -23
- data/lib/mirah/jvm/types/type_definition.rb +25 -10
- data/lib/mirah/jvm/types/unreachable_type.rb +1 -1
- data/lib/mirah/jvm/types/void_type.rb +3 -3
- data/lib/mirah/parser.rb +154 -16
- data/lib/mirah/plugin/edb.rb +1 -1
- data/lib/mirah/transform.rb +1 -2
- data/lib/mirah/transform/ast_ext.rb +24 -43
- data/lib/mirah/transform/transformer.rb +29 -224
- data/lib/mirah/typer.rb +2 -16
- data/lib/mirah/util/argument_processor.rb +25 -10
- data/lib/mirah/util/class_loader.rb +1 -1
- data/lib/mirah/util/compilation_state.rb +16 -17
- data/lib/mirah/util/delegate.rb +2 -2
- data/lib/mirah/util/logging.rb +110 -0
- data/lib/mirah/util/process_errors.rb +69 -11
- data/lib/mirah/version.rb +1 -1
- data/test/core/commands_test.rb +6 -24
- data/test/core/env_test.rb +5 -5
- data/{lib/mirah/jvm/source_generator/typer.rb → test/core/generator_test.rb} +9 -9
- data/test/core/typer_test.rb +196 -158
- data/test/core/util/argument_processor_test.rb +10 -10
- data/test/core/util/class_loader_test.rb +6 -5
- data/test/fixtures/org/foo/LowerCaseInnerClass$inner.class +0 -0
- data/test/fixtures/org/foo/LowerCaseInnerClass.class +0 -0
- data/test/fixtures/org/foo/LowerCaseInnerClass.java +7 -0
- data/test/jvm/annotations_test.rb +5 -5
- data/test/jvm/blocks_test.rb +140 -88
- data/test/jvm/bytecode_test_helper.rb +112 -94
- data/test/jvm/cast_test.rb +162 -0
- data/test/jvm/constructors_test.rb +18 -8
- data/test/jvm/enumerable_test.rb +77 -44
- data/test/jvm/example_test.rb +53 -0
- data/test/jvm/factory_test.rb +7 -1
- data/test/jvm/generics_test.rb +57 -0
- data/test/jvm/hash_test.rb +106 -0
- data/test/jvm/import_test.rb +81 -0
- data/test/jvm/interface_test.rb +73 -0
- data/test/jvm/java_typer_test.rb +92 -66
- data/{lib/mirah/typer/base.rb → test/jvm/jvm_commands_test.rb} +6 -10
- data/test/jvm/jvm_compiler_test.rb +170 -604
- data/test/jvm/list_extensions_test.rb +23 -0
- data/test/jvm/macros_test.rb +197 -32
- data/test/jvm/main_method_test.rb +4 -4
- data/test/jvm/numeric_extensions_test.rb +13 -0
- data/test/jvm/rescue_test.rb +73 -16
- data/test/jvm/varargs_test.rb +65 -0
- data/test/test_helper.rb +1 -2
- metadata +234 -251
- data/examples/SortClosure$__xform_tmp_1.class +0 -0
- data/examples/SortClosure$__xform_tmp_2.class +0 -0
- data/examples/SortClosure.class +0 -0
- data/examples/macros/StringEachChar$Extension1.class +0 -0
- data/lib/mirah/ast/call.rb +0 -345
- data/lib/mirah/ast/class.rb +0 -359
- data/lib/mirah/ast/flow.rb +0 -381
- data/lib/mirah/ast/intrinsics.rb +0 -563
- data/lib/mirah/ast/literal.rb +0 -178
- data/lib/mirah/ast/local.rb +0 -112
- data/lib/mirah/ast/method.rb +0 -408
- data/lib/mirah/ast/structure.rb +0 -387
- data/lib/mirah/ast/type.rb +0 -146
- data/lib/mirah/commands/base.rb~ +0 -57
- data/lib/mirah/compiler/call.rb +0 -45
- data/lib/mirah/compiler/class.rb +0 -81
- data/lib/mirah/compiler/flow.rb +0 -109
- data/lib/mirah/compiler/literal.rb +0 -130
- data/lib/mirah/compiler/local.rb +0 -59
- data/lib/mirah/compiler/method.rb +0 -44
- data/lib/mirah/compiler/structure.rb +0 -65
- data/lib/mirah/jvm/compiler/java_source.rb +0 -787
- data/lib/mirah/jvm/method_lookup.rb~ +0 -247
- data/lib/mirah/jvm/source_generator/builder.rb +0 -468
- data/lib/mirah/jvm/source_generator/loops.rb +0 -131
- data/lib/mirah/jvm/source_generator/precompile.rb +0 -210
- data/lib/mirah/plugin/gwt.rb +0 -189
- data/lib/mirah/plugin/java.rb +0 -70
- data/lib/mirah/transform/error.rb +0 -13
- data/lib/mirah/transform/helper.rb +0 -765
- data/lib/mirah/typer/simple.rb +0 -384
- data/lib/mirah/version.rb~ +0 -18
- data/test/core/ast_test.rb +0 -382
- data/test/core/compilation_test.rb +0 -130
- data/test/core/macros_test.rb +0 -61
- data/test/jvm/javac_test_helper.rb +0 -89
- data/test/jvm/jvm_compiler_test.rb~ +0 -2181
- data/test/plugins/gwt_test.rb +0 -69
data/lib/mirah/ast/structure.rb
DELETED
|
@@ -1,387 +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::AST
|
|
17
|
-
class Body < Node
|
|
18
|
-
include Java::DubyLangCompiler.Body
|
|
19
|
-
|
|
20
|
-
def initialize(parent, line_number, &block)
|
|
21
|
-
super(parent, line_number, &block)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Type of a block is the type of its final element
|
|
25
|
-
def infer(typer, expression)
|
|
26
|
-
unless @inferred_type
|
|
27
|
-
@typer ||= typer
|
|
28
|
-
@self_type ||= typer.self_type
|
|
29
|
-
|
|
30
|
-
if children.empty?
|
|
31
|
-
@inferred_type = typer.no_type
|
|
32
|
-
else
|
|
33
|
-
children[0..-2].each do |child|
|
|
34
|
-
typer.infer(child, false)
|
|
35
|
-
end
|
|
36
|
-
@inferred_type = typer.infer(children.last, expression)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
if @inferred_type
|
|
40
|
-
resolved!
|
|
41
|
-
else
|
|
42
|
-
typer.defer(self)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
@inferred_type
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def string_value
|
|
50
|
-
if children.size == 1
|
|
51
|
-
children[0].string_value
|
|
52
|
-
else
|
|
53
|
-
super
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def <<(node)
|
|
58
|
-
super
|
|
59
|
-
if @typer
|
|
60
|
-
orig_self = @typer.self_type
|
|
61
|
-
@typer.known_types['self'] = @self_type
|
|
62
|
-
@typer.infer(node, true)
|
|
63
|
-
@typer.known_types['self'] = orig_self
|
|
64
|
-
end
|
|
65
|
-
self
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def add_node(node)
|
|
69
|
-
self << node
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# class << self
|
|
75
|
-
class ClassAppendSelf < Body
|
|
76
|
-
include Scope
|
|
77
|
-
include Scoped
|
|
78
|
-
|
|
79
|
-
def initialize(parent, line_number, &block)
|
|
80
|
-
super(parent, line_number, &block)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def infer(typer, expression)
|
|
84
|
-
static_scope.self_type = scope.static_scope.self_type.meta
|
|
85
|
-
super
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
class ScopedBody < Body
|
|
90
|
-
include Scope
|
|
91
|
-
include Scoped
|
|
92
|
-
|
|
93
|
-
def infer(typer, expression)
|
|
94
|
-
static_scope.self_type ||= typer.self_type
|
|
95
|
-
super
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def binding_type(mirah=nil)
|
|
99
|
-
static_scope.binding_type(defining_class, mirah)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def binding_type=(type)
|
|
103
|
-
static_scope.binding_type = type
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def has_binding?
|
|
107
|
-
static_scope.has_binding?
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def type_reference(typer)
|
|
111
|
-
raise Mirah::SyntaxError.new("Invalid type", self) unless children.size == 1
|
|
112
|
-
children[0].type_reference(typer)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def inspect_children(indent=0)
|
|
116
|
-
indent_str = ' ' * indent
|
|
117
|
-
str = ''
|
|
118
|
-
if static_scope.self_node
|
|
119
|
-
str << "\n#{indent_str}self: "
|
|
120
|
-
if Node === static_scope.self_node
|
|
121
|
-
str << "\n" << static_scope.self_node.inspect(indent + 1)
|
|
122
|
-
else
|
|
123
|
-
str << static_scope.self_node.inspect
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
str << "\n#{indent_str}body:" << super(indent + 1)
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
class Block < Node
|
|
131
|
-
include Scoped
|
|
132
|
-
include Scope
|
|
133
|
-
include Java::DubyLangCompiler::Block
|
|
134
|
-
child :args
|
|
135
|
-
child :body
|
|
136
|
-
|
|
137
|
-
def initialize(parent, position, &block)
|
|
138
|
-
super(parent, position) do
|
|
139
|
-
static_scope.parent = scope.static_scope
|
|
140
|
-
yield(self) if block_given?
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def prepare(typer, method)
|
|
145
|
-
mirah = typer.transformer
|
|
146
|
-
interface_or_abstract_class = method.argument_types[-1]
|
|
147
|
-
outer_class = scope.defining_class
|
|
148
|
-
|
|
149
|
-
binding = scope.binding_type(mirah)
|
|
150
|
-
|
|
151
|
-
name = "#{outer_class.name}$#{mirah.tmp}"
|
|
152
|
-
|
|
153
|
-
klass = mirah.define_closure(position, name, outer_class)
|
|
154
|
-
case
|
|
155
|
-
when interface_or_abstract_class.interface?
|
|
156
|
-
klass.interfaces = [interface_or_abstract_class]
|
|
157
|
-
when interface_or_abstract_class.abstract?
|
|
158
|
-
klass.superclass = interface_or_abstract_class
|
|
159
|
-
else
|
|
160
|
-
raise "#{interface_or_abstract_class.name} isn't an interface or abstract"
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
klass.define_constructor(position,
|
|
164
|
-
['binding', binding]) do |c|
|
|
165
|
-
mirah.eval("@binding = binding", '-', c, 'binding')
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
@defining_class = klass.static_scope.self_type
|
|
169
|
-
|
|
170
|
-
# TODO We need a special scope here that allows access to the
|
|
171
|
-
# outer class.
|
|
172
|
-
static_scope.self_type = typer.infer(klass, true)
|
|
173
|
-
|
|
174
|
-
add_methods(klass, binding, typer)
|
|
175
|
-
|
|
176
|
-
call = parent
|
|
177
|
-
instance = Call.new(call, position, 'new')
|
|
178
|
-
instance.target = Constant.new(call, position, name)
|
|
179
|
-
instance.parameters = [
|
|
180
|
-
BindingReference.new(instance, position, binding)
|
|
181
|
-
]
|
|
182
|
-
call.parameters << instance
|
|
183
|
-
call.block = nil
|
|
184
|
-
typer.infer(instance, true)
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def defining_class
|
|
188
|
-
@defining_class
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# TODO extract this & matching methods into a module
|
|
192
|
-
def binding_type(mirah=nil)
|
|
193
|
-
static_scope.binding_type(defining_class, mirah)
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def add_methods(klass, binding, typer)
|
|
197
|
-
method_definitions = body.select{ |node| node.kind_of? MethodDefinition }
|
|
198
|
-
|
|
199
|
-
if method_definitions.empty?
|
|
200
|
-
build_method(klass, binding, typer)
|
|
201
|
-
else
|
|
202
|
-
# TODO warn if there are non method definition nodes
|
|
203
|
-
# they won't be used at all currently--so it'd be nice to note that.
|
|
204
|
-
method_definitions.each do |node|
|
|
205
|
-
|
|
206
|
-
node.static_scope = static_scope
|
|
207
|
-
node.binding_type = binding
|
|
208
|
-
# node.children.each {|child| child.instance_variable_set '@scope', nil }
|
|
209
|
-
klass.append_node(node)
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def build_method(klass, binding, typer)
|
|
215
|
-
# find all methods which would not otherwise be on java.lang.Object
|
|
216
|
-
impl_methods = find_abstract_methods(klass).select do |m|
|
|
217
|
-
begin
|
|
218
|
-
# Very cumbersome. Not sure how it got this way.
|
|
219
|
-
mirror = BiteScript::ASM::ClassMirror.for_name('java.lang.Object')
|
|
220
|
-
mtype = Mirah::JVM::Types::Type.new(mirror)
|
|
221
|
-
mtype.java_method m.name, *m.argument_types
|
|
222
|
-
rescue NameError
|
|
223
|
-
# not found on Object
|
|
224
|
-
next true
|
|
225
|
-
end
|
|
226
|
-
# found on Object
|
|
227
|
-
next false
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
# It could also just define all the methods w/ the block as the implementation, assuming the args check out
|
|
231
|
-
# instead of it being an error.
|
|
232
|
-
if impl_methods.size > 1
|
|
233
|
-
raise Mirah::NodeError.new("Multiple abstract methods found within interface #{klass.interfaces.map(&:name).inspect} [#{impl_methods.map(&:name).join(', ')}]; cannot use block", self)
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
impl_methods.each do |method|
|
|
237
|
-
if args.args.length != method.argument_types.length
|
|
238
|
-
raise Mirah::NodeError.new("Block can't implement #{method.name}: wrong number of arguments. Expected #{method.argument_types.length}, but was #{args.args.length}", self)
|
|
239
|
-
end
|
|
240
|
-
mdef = klass.define_method(position,
|
|
241
|
-
method.name,
|
|
242
|
-
method.return_type,
|
|
243
|
-
args.dup) do |mdef|
|
|
244
|
-
mdef.static_scope = static_scope
|
|
245
|
-
mdef.binding_type = binding
|
|
246
|
-
mdef.body = body.dup
|
|
247
|
-
end
|
|
248
|
-
typer.infer(mdef.body, method.return_type != typer.no_type)
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def find_abstract_methods(klass)
|
|
253
|
-
methods = []
|
|
254
|
-
interfaces = klass.interfaces.dup
|
|
255
|
-
until interfaces.empty?
|
|
256
|
-
interface = interfaces.pop
|
|
257
|
-
methods += interface.declared_instance_methods.select {|m| m.abstract?}
|
|
258
|
-
interfaces.concat(interface.interfaces)
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
if klass.superclass && klass.superclass.abstract?
|
|
262
|
-
methods += klass.superclass.declared_instance_methods.select{|m| m.abstract? }
|
|
263
|
-
end
|
|
264
|
-
methods
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
class BindingReference < Node
|
|
269
|
-
def initialize(parent, position, type)
|
|
270
|
-
super(parent, position)
|
|
271
|
-
@inferred_type = type
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def infer(typer, expression)
|
|
275
|
-
resolved! unless resolved?
|
|
276
|
-
@inferred_type
|
|
277
|
-
end
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
class Noop < Node
|
|
281
|
-
def infer(typer, expression)
|
|
282
|
-
resolved!
|
|
283
|
-
@inferred_type ||= typer.no_type
|
|
284
|
-
end
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
class Script < Node
|
|
288
|
-
include Scope
|
|
289
|
-
include Binding
|
|
290
|
-
child :body
|
|
291
|
-
|
|
292
|
-
attr_accessor :defining_class
|
|
293
|
-
attr_reader :filename
|
|
294
|
-
|
|
295
|
-
def initialize(parent, line_number, &block)
|
|
296
|
-
super(parent, line_number, &block)
|
|
297
|
-
@package = ""
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
def infer(typer, expression)
|
|
301
|
-
resolve_if(typer) do
|
|
302
|
-
typer.set_filename(self, filename)
|
|
303
|
-
@defining_class ||= begin
|
|
304
|
-
static_scope.self_type = typer.self_type
|
|
305
|
-
end
|
|
306
|
-
typer.infer(body, false)
|
|
307
|
-
end
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
def filename=(filename)
|
|
311
|
-
@filename = filename
|
|
312
|
-
if Script.explicit_packages
|
|
313
|
-
static_scope.package = ''
|
|
314
|
-
else
|
|
315
|
-
package = File.dirname(@filename).tr('/', '.')
|
|
316
|
-
package.sub! /^\.+/, ''
|
|
317
|
-
static_scope.package = package
|
|
318
|
-
end
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
class << self
|
|
322
|
-
attr_accessor :explicit_packages
|
|
323
|
-
end
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
class Annotation < Node
|
|
327
|
-
attr_reader :values
|
|
328
|
-
attr_accessor :runtime
|
|
329
|
-
alias runtime? runtime
|
|
330
|
-
|
|
331
|
-
child :name_node
|
|
332
|
-
|
|
333
|
-
def initialize(parent, position, name=nil, &block)
|
|
334
|
-
super(parent, position, &block)
|
|
335
|
-
if name
|
|
336
|
-
@name = if name.respond_to?(:class_name)
|
|
337
|
-
name.class_name
|
|
338
|
-
else
|
|
339
|
-
name.name
|
|
340
|
-
end
|
|
341
|
-
end
|
|
342
|
-
@values = {}
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
def name
|
|
346
|
-
@name
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
def type
|
|
350
|
-
BiteScript::ASM::Type.getObjectType(@name.tr('.', '/'))
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
def []=(name, value)
|
|
354
|
-
@values[name] = value
|
|
355
|
-
end
|
|
356
|
-
|
|
357
|
-
def [](name)
|
|
358
|
-
@values[name]
|
|
359
|
-
end
|
|
360
|
-
|
|
361
|
-
def infer(typer, expression)
|
|
362
|
-
@inferred ||= begin
|
|
363
|
-
@name = name_node.type_reference(typer).name if name_node
|
|
364
|
-
@values.each do |name, value|
|
|
365
|
-
if Node === value
|
|
366
|
-
@values[name] = annotation_value(value, typer)
|
|
367
|
-
end
|
|
368
|
-
end
|
|
369
|
-
true
|
|
370
|
-
end
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
def annotation_value(node, typer)
|
|
374
|
-
case node
|
|
375
|
-
when String
|
|
376
|
-
java.lang.String.new(node.literal)
|
|
377
|
-
when Fixnum
|
|
378
|
-
java.lang.Integer.new(node.literal)
|
|
379
|
-
when Array
|
|
380
|
-
node.children.map {|node| annotation_value(node, typer)}
|
|
381
|
-
else
|
|
382
|
-
# TODO Support other types
|
|
383
|
-
raise "Unsupported Annotation Value Type"
|
|
384
|
-
end
|
|
385
|
-
end
|
|
386
|
-
end
|
|
387
|
-
end
|
data/lib/mirah/ast/type.rb
DELETED
|
@@ -1,146 +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::AST
|
|
17
|
-
class Import < Node
|
|
18
|
-
include Scoped
|
|
19
|
-
attr_accessor :short
|
|
20
|
-
attr_accessor :long
|
|
21
|
-
def initialize(parent, line_number, short, long)
|
|
22
|
-
@short = short
|
|
23
|
-
@long = long
|
|
24
|
-
super(parent, line_number, [])
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def to_s
|
|
28
|
-
"Import(#{short} = #{long})"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def infer(typer, expression)
|
|
32
|
-
resolve_if(typer) do
|
|
33
|
-
scope.static_scope.import(long, short)
|
|
34
|
-
typer.type_reference(scope, @long) if short != '*'
|
|
35
|
-
typer.no_type
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def top_level?
|
|
40
|
-
true
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
defmacro('import') do |transformer, fcall, parent|
|
|
45
|
-
case fcall.parameters.size
|
|
46
|
-
when 1
|
|
47
|
-
node = fcall.parameters[0]
|
|
48
|
-
case node
|
|
49
|
-
when String
|
|
50
|
-
long = node.literal
|
|
51
|
-
short = long[(long.rindex('.') + 1)..-1]
|
|
52
|
-
when Call
|
|
53
|
-
case node.parameters.size
|
|
54
|
-
when 0
|
|
55
|
-
pieces = [node.name]
|
|
56
|
-
while Call === node
|
|
57
|
-
node = node.target
|
|
58
|
-
pieces << node.name
|
|
59
|
-
end
|
|
60
|
-
long = pieces.reverse.join '.'
|
|
61
|
-
short = pieces[0]
|
|
62
|
-
when 1
|
|
63
|
-
arg = node.parameters[0]
|
|
64
|
-
unless (FunctionalCall === arg &&
|
|
65
|
-
arg.name == 'as' && arg.parameters.size == 1)
|
|
66
|
-
raise Mirah::TransformError.new("unknown import syntax", fcall)
|
|
67
|
-
end
|
|
68
|
-
short = arg.parameters[0].name
|
|
69
|
-
pieces = [node.name]
|
|
70
|
-
while Call === node
|
|
71
|
-
node = node.target
|
|
72
|
-
pieces << node.name
|
|
73
|
-
end
|
|
74
|
-
long = pieces.reverse.join '.'
|
|
75
|
-
else
|
|
76
|
-
raise Mirah::TransformError.new("unknown import syntax", fcall)
|
|
77
|
-
end
|
|
78
|
-
else
|
|
79
|
-
raise Mirah::TransformError.new("unknown import syntax", fcall)
|
|
80
|
-
end
|
|
81
|
-
when 2
|
|
82
|
-
short = fcall.parameters[0].literal
|
|
83
|
-
long = fcall.parameters[1].literal
|
|
84
|
-
else
|
|
85
|
-
raise Mirah::TransformError.new("unknown import syntax", fcall)
|
|
86
|
-
end
|
|
87
|
-
Import.new(parent, fcall.position, short, long)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
defmacro('package') do |transformer, fcall, parent|
|
|
91
|
-
node = fcall.parameters[0]
|
|
92
|
-
block = fcall.block
|
|
93
|
-
case node
|
|
94
|
-
when String
|
|
95
|
-
name = node.literal
|
|
96
|
-
when Call
|
|
97
|
-
pieces = [node.name]
|
|
98
|
-
block ||= node.block
|
|
99
|
-
while Call === node
|
|
100
|
-
node = node.target
|
|
101
|
-
pieces << node.name
|
|
102
|
-
block ||= node.block
|
|
103
|
-
end
|
|
104
|
-
name = pieces.reverse.join '.'
|
|
105
|
-
when FunctionalCall
|
|
106
|
-
name = node.name
|
|
107
|
-
block ||= node.block
|
|
108
|
-
else
|
|
109
|
-
raise Mirah::TransformError.new("unknown package syntax", fcall)
|
|
110
|
-
end
|
|
111
|
-
if block
|
|
112
|
-
raise Mirah::TransformError.new("unknown package syntax", block)
|
|
113
|
-
new_scope = ScopedBody.new(parent, fcall.position)
|
|
114
|
-
new_scope.static_scope.package = name
|
|
115
|
-
new_scope << block.body
|
|
116
|
-
else
|
|
117
|
-
fcall.scope.static_scope.package = name
|
|
118
|
-
Noop.new(parent, fcall.position)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
class EmptyArray < Node
|
|
123
|
-
attr_accessor :size
|
|
124
|
-
attr_accessor :component_type
|
|
125
|
-
child :type_node
|
|
126
|
-
child :size
|
|
127
|
-
|
|
128
|
-
def initialize(*args)
|
|
129
|
-
super(*args)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def infer(typer, expression)
|
|
133
|
-
resolve_if(typer) do
|
|
134
|
-
@component_type = type_node.type_reference(typer)
|
|
135
|
-
typer.infer(size, true)
|
|
136
|
-
typer.type_reference(nil, @component_type, true)
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
class Builtin < Node
|
|
142
|
-
def infer(typer, expression)
|
|
143
|
-
resolve_if(typer) {Mirah::AST.type(nil, 'mirah.impl.Builtin')}
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|