mirah 0.0.5-java → 0.0.6-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +33 -0
- data/README.txt +2 -3
- data/Rakefile +5 -0
- data/bin/duby +0 -0
- data/bin/dubyc +0 -0
- data/bin/dubyp +0 -0
- data/bin/jrubyp +0 -0
- data/bin/mirah +0 -0
- data/bin/mirah.cmd +14 -14
- data/bin/mirahc +0 -0
- data/bin/mirahc.cmd +14 -14
- data/bin/mirahp +0 -0
- data/bin/mirahp.cmd +14 -14
- data/examples/Dynamic.class +0 -0
- data/examples/SizeThing.class +0 -0
- data/examples/plugins/appengine/Rakefile +3 -1
- data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/MetaModel.mirah +385 -0
- data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/Model.duby +58 -15
- data/examples/wiki/war/public/javascripts/prettify.js +0 -0
- data/examples/wiki/war/public/stylesheets/prettify.css +0 -0
- data/javalib/dynalink-0.1.jar +0 -0
- data/javalib/jsr292-mock.jar +0 -0
- data/javalib/mirah-bootstrap.jar +0 -0
- data/javalib/mirah-parser.jar +0 -0
- data/lib/mirah.rb +45 -25
- data/lib/mirah/ast.rb +81 -27
- data/lib/mirah/ast/call.rb +62 -71
- data/lib/mirah/ast/class.rb +23 -26
- data/lib/mirah/ast/flow.rb +38 -62
- data/lib/mirah/ast/intrinsics.rb +59 -37
- data/lib/mirah/ast/literal.rb +16 -14
- data/lib/mirah/ast/local.rb +8 -8
- data/lib/mirah/ast/method.rb +33 -19
- data/lib/mirah/ast/structure.rb +54 -13
- data/lib/mirah/ast/type.rb +8 -11
- data/lib/mirah/compiler.rb +86 -0
- data/lib/mirah/errors.rb +60 -0
- data/lib/mirah/jvm/base.rb +5 -11
- data/lib/mirah/jvm/compiler.rb +12 -1
- data/lib/mirah/jvm/source_compiler.rb +10 -2
- data/lib/mirah/jvm/source_generator/builder.rb +3 -1
- data/lib/mirah/jvm/source_generator/precompile.rb +6 -0
- data/lib/mirah/jvm/typer.rb +6 -1
- data/lib/mirah/jvm/types.rb +8 -0
- data/lib/mirah/jvm/types/factory.rb +34 -10
- data/lib/mirah/jvm/types/intrinsics.rb +12 -5
- data/lib/mirah/jvm/types/methods.rb +5 -9
- data/lib/mirah/plugin/gwt.rb +3 -2
- data/lib/mirah/transform.rb +68 -10
- data/lib/mirah/transform2.rb +10 -1
- data/lib/mirah/typer.rb +5 -10
- data/lib/mirah/version.rb +1 -1
- data/test/test_compilation.rb +1 -1
- data/test/test_java_typer.rb +10 -0
- data/test/test_javac_compiler.rb +4 -2
- data/test/test_jvm_compiler.rb +132 -9
- data/test/test_macros.rb +51 -0
- data/test/test_typer.rb +29 -25
- metadata +13 -21
- data/examples/plugins/appengine/lib/com/google/appengine/ext/duby/db/datastore.rb +0 -390
- data/javalib/JRubyParser.jar +0 -0
- data/javalib/dynalang-invoke-0.1.jar +0 -0
- data/lib/mirah/nbcompiler.rb +0 -44
data/lib/mirah/ast/call.rb
CHANGED
@@ -13,43 +13,7 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
require 'delegate'
|
17
|
-
|
18
16
|
module Mirah::AST
|
19
|
-
class NodeProxy < DelegateClass(Node)
|
20
|
-
include Java::DubyLangCompiler::Node
|
21
|
-
def __inline__(node)
|
22
|
-
node.parent = parent
|
23
|
-
__setobj__(node)
|
24
|
-
end
|
25
|
-
|
26
|
-
def dup
|
27
|
-
value = __getobj__.dup
|
28
|
-
if value.respond_to?(:proxy=)
|
29
|
-
new = super
|
30
|
-
new.__setobj__(value)
|
31
|
-
new.proxy = new
|
32
|
-
new
|
33
|
-
else
|
34
|
-
value
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def _dump(depth)
|
39
|
-
Marshal.dump(__getobj__)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self._load(str)
|
43
|
-
value = Marshal.load(str)
|
44
|
-
if value.respond_to?(:proxy=)
|
45
|
-
proxy = NodeProxy.new(value)
|
46
|
-
proxy.proxy = proxy
|
47
|
-
else
|
48
|
-
value
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
17
|
class FunctionalCall < Node
|
54
18
|
include Java::DubyLangCompiler.Call
|
55
19
|
include Named
|
@@ -67,18 +31,16 @@ module Mirah::AST
|
|
67
31
|
|
68
32
|
def initialize(parent, line_number, name, &kids)
|
69
33
|
super(parent, line_number, &kids)
|
70
|
-
|
34
|
+
self.name = name
|
71
35
|
@cast = false
|
72
36
|
end
|
73
37
|
|
74
38
|
def arguments
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
args.add(param)
|
79
|
-
end
|
80
|
-
args
|
39
|
+
args = java.util.ArrayList.new(parameters.size)
|
40
|
+
parameters.each do |param|
|
41
|
+
args.add(param)
|
81
42
|
end
|
43
|
+
args
|
82
44
|
end
|
83
45
|
|
84
46
|
def target
|
@@ -88,20 +50,21 @@ module Mirah::AST
|
|
88
50
|
def validate_parameters
|
89
51
|
parameters.each_with_index do |child, i|
|
90
52
|
if UnquotedValue === child
|
53
|
+
child = child.node
|
91
54
|
child.parent = self
|
92
|
-
parameters[i] = child
|
55
|
+
parameters[i] = child
|
93
56
|
end
|
94
57
|
end
|
95
58
|
end
|
96
59
|
|
97
|
-
def infer(typer)
|
60
|
+
def infer(typer, expression)
|
98
61
|
unless @inferred_type
|
99
62
|
@self_type ||= scope.static_scope.self_type
|
100
63
|
receiver_type = @self_type
|
101
64
|
should_defer = false
|
102
65
|
|
103
66
|
parameter_types = parameters.map do |param|
|
104
|
-
typer.infer(param) || should_defer = true
|
67
|
+
typer.infer(param, true) || should_defer = true
|
105
68
|
end
|
106
69
|
|
107
70
|
parameter_types << Mirah::AST.block_type if block
|
@@ -115,14 +78,14 @@ module Mirah::AST
|
|
115
78
|
elsif parameters.size == 0 && scope.static_scope.include?(name)
|
116
79
|
@inlined = Local.new(parent, position, name)
|
117
80
|
proxy.__inline__(@inlined)
|
118
|
-
return proxy.infer(typer)
|
81
|
+
return proxy.infer(typer, expression)
|
119
82
|
else
|
120
83
|
@inferred_type = typer.method_type(receiver_type, name,
|
121
84
|
parameter_types)
|
122
85
|
if @inferred_type.kind_of? InlineCode
|
123
86
|
@inlined = @inferred_type.inline(typer.transformer, self)
|
124
87
|
proxy.__inline__(@inlined)
|
125
|
-
return proxy.infer(typer)
|
88
|
+
return proxy.infer(typer, expression)
|
126
89
|
end
|
127
90
|
end
|
128
91
|
end
|
@@ -174,34 +137,33 @@ module Mirah::AST
|
|
174
137
|
|
175
138
|
def initialize(parent, line_number, name, &kids)
|
176
139
|
super(parent, line_number, &kids)
|
177
|
-
|
140
|
+
self.name = name
|
178
141
|
end
|
179
142
|
|
180
143
|
def validate_parameters
|
181
144
|
parameters.each_with_index do |child, i|
|
182
145
|
if UnquotedValue === child
|
146
|
+
child = child.node
|
183
147
|
child.parent = self
|
184
|
-
parameters[i] = child
|
148
|
+
parameters[i] = child
|
185
149
|
end
|
186
150
|
end
|
187
151
|
end
|
188
152
|
|
189
153
|
def arguments
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
args.add(param)
|
194
|
-
end
|
195
|
-
args
|
154
|
+
args = java.util.ArrayList.new(parameters.size)
|
155
|
+
parameters.each do |param|
|
156
|
+
args.add(param)
|
196
157
|
end
|
158
|
+
args
|
197
159
|
end
|
198
160
|
|
199
|
-
def infer(typer)
|
161
|
+
def infer(typer, expression)
|
200
162
|
unless @inferred_type
|
201
|
-
receiver_type = typer.infer(target)
|
163
|
+
receiver_type = typer.infer(target, true)
|
202
164
|
should_defer = receiver_type.nil?
|
203
165
|
parameter_types = parameters.map do |param|
|
204
|
-
typer.infer(param) || should_defer = true
|
166
|
+
typer.infer(param, true) || should_defer = true
|
205
167
|
end
|
206
168
|
|
207
169
|
parameter_types << Mirah::AST.block_type if block
|
@@ -212,7 +174,7 @@ module Mirah::AST
|
|
212
174
|
if @inferred_type.kind_of? InlineCode
|
213
175
|
@inlined = @inferred_type.inline(typer.transformer, self)
|
214
176
|
proxy.__inline__(@inlined)
|
215
|
-
return proxy.infer(typer)
|
177
|
+
return proxy.infer(typer, expression)
|
216
178
|
end
|
217
179
|
end
|
218
180
|
|
@@ -266,11 +228,15 @@ module Mirah::AST
|
|
266
228
|
|
267
229
|
# join and load
|
268
230
|
class_name = elements.join(".")
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
231
|
+
typer.type_reference(scope, class_name, array)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
class Colon2 < Call
|
237
|
+
def infer(typer, expression)
|
238
|
+
resolve_if(typer) do
|
239
|
+
type_reference(typer).meta
|
274
240
|
end
|
275
241
|
end
|
276
242
|
end
|
@@ -285,23 +251,29 @@ module Mirah::AST
|
|
285
251
|
|
286
252
|
def initialize(parent, line_number)
|
287
253
|
super(parent, line_number)
|
288
|
-
@call_parent = parent
|
289
|
-
@call_parent = (@call_parent = @call_parent.parent) until MethodDefinition === @call_parent
|
290
254
|
@cast = false
|
291
255
|
end
|
292
256
|
|
257
|
+
def call_parent
|
258
|
+
@call_parent ||= begin
|
259
|
+
node = parent
|
260
|
+
node = (node && node.parent) until MethodDefinition === node
|
261
|
+
node
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
293
265
|
def name
|
294
|
-
|
266
|
+
call_parent.name
|
295
267
|
end
|
296
268
|
|
297
|
-
def infer(typer)
|
269
|
+
def infer(typer, expression)
|
298
270
|
@self_type ||= scope.static_scope.self_type.superclass
|
299
271
|
|
300
272
|
unless @inferred_type
|
301
|
-
receiver_type =
|
273
|
+
receiver_type = call_parent.defining_class.superclass
|
302
274
|
should_defer = receiver_type.nil?
|
303
275
|
parameter_types = parameters.map do |param|
|
304
|
-
typer.infer(param) || should_defer = true
|
276
|
+
typer.infer(param, true) || should_defer = true
|
305
277
|
end
|
306
278
|
|
307
279
|
unless should_defer
|
@@ -314,6 +286,25 @@ module Mirah::AST
|
|
314
286
|
|
315
287
|
@inferred_type
|
316
288
|
end
|
289
|
+
|
290
|
+
alias originial_parameters parameters
|
291
|
+
|
292
|
+
def parameters
|
293
|
+
if originial_parameters.nil?
|
294
|
+
self.parameters = default_parameters
|
295
|
+
end
|
296
|
+
originial_parameters
|
297
|
+
end
|
298
|
+
|
299
|
+
def default_parameters
|
300
|
+
node = self
|
301
|
+
node = node.parent until MethodDefinition === node || node.nil?
|
302
|
+
return [] if node.nil?
|
303
|
+
args = node.arguments.children.map {|x| x || []}
|
304
|
+
args.flatten.map do |arg|
|
305
|
+
Local.new(self, position, arg.name)
|
306
|
+
end
|
307
|
+
end
|
317
308
|
end
|
318
309
|
|
319
310
|
class BlockPass < Node
|
data/lib/mirah/ast/class.rb
CHANGED
@@ -18,6 +18,8 @@ module Mirah::AST
|
|
18
18
|
include Annotated
|
19
19
|
include Named
|
20
20
|
include Scope
|
21
|
+
include Java::DubyLangCompiler.ClassDefinition
|
22
|
+
|
21
23
|
attr_accessor :interfaces
|
22
24
|
attr_accessor :current_access_level
|
23
25
|
attr_accessor :abstract
|
@@ -32,7 +34,7 @@ module Mirah::AST
|
|
32
34
|
@annotations = annotations
|
33
35
|
@interfaces = []
|
34
36
|
@interface_nodes = []
|
35
|
-
|
37
|
+
self.name = name
|
36
38
|
self.parent = parent
|
37
39
|
if Mirah::AST.type_factory.respond_to? :define_type
|
38
40
|
Mirah::AST.type_factory.define_type(self)
|
@@ -52,11 +54,6 @@ module Mirah::AST
|
|
52
54
|
node
|
53
55
|
end
|
54
56
|
|
55
|
-
def define_inner_class(position, name, &block)
|
56
|
-
name = "#{self.name}$#{name}"
|
57
|
-
append_node ClassDefinition.new(nil, position, name, &block)
|
58
|
-
end
|
59
|
-
|
60
57
|
def define_method(position, name, type, *args)
|
61
58
|
append_node(_define_method(MethodDefinition, position, name, type, args))
|
62
59
|
end
|
@@ -103,14 +100,14 @@ module Mirah::AST
|
|
103
100
|
append_node(field)
|
104
101
|
end
|
105
102
|
|
106
|
-
def infer(typer)
|
103
|
+
def infer(typer, expression)
|
107
104
|
resolve_if(typer) do
|
108
105
|
@superclass = superclass_node.type_reference(typer) if superclass_node
|
109
|
-
@annotations.each {|a| a.infer(typer)} if @annotations
|
106
|
+
@annotations.each {|a| a.infer(typer, true)} if @annotations
|
110
107
|
@interfaces.concat(@interface_nodes.map{|n| n.type_reference(typer)})
|
111
108
|
typer.define_type(self, name, superclass, @interfaces) do
|
112
109
|
static_scope.self_type = typer.self_type
|
113
|
-
typer.infer(body) if body
|
110
|
+
typer.infer(body, false) if body
|
114
111
|
end
|
115
112
|
end
|
116
113
|
end
|
@@ -147,12 +144,12 @@ module Mirah::AST
|
|
147
144
|
def initialize(parent, position, name, annotations)
|
148
145
|
super(parent, position, name, annotations) {|p| }
|
149
146
|
@abstract = true
|
150
|
-
|
147
|
+
self.name = name
|
151
148
|
@children = [[], nil]
|
152
149
|
@children = yield(self)
|
153
150
|
end
|
154
151
|
|
155
|
-
def infer(typer)
|
152
|
+
def infer(typer, expression)
|
156
153
|
resolve_if(typer) do
|
157
154
|
@interfaces = interface_nodes.map {|i| i.type_reference(typer)}
|
158
155
|
super
|
@@ -175,7 +172,7 @@ module Mirah::AST
|
|
175
172
|
end
|
176
173
|
|
177
174
|
defmacro('interface') do |transformer, fcall, parent|
|
178
|
-
raise "Interface name required" unless fcall.parameters.size > 0
|
175
|
+
raise Mirah::SyntaxError.new("Interface name required", fcall) unless fcall.parameters.size > 0
|
179
176
|
interfaces = fcall.parameters
|
180
177
|
interface_name = interfaces.shift
|
181
178
|
if (Call === interface_name &&
|
@@ -210,13 +207,13 @@ module Mirah::AST
|
|
210
207
|
def initialize(parent, position, name, annotations=[], static = false, &block)
|
211
208
|
@annotations = annotations
|
212
209
|
super(parent, position, &block)
|
213
|
-
|
210
|
+
self.name = name
|
214
211
|
@static = static
|
215
212
|
end
|
216
213
|
|
217
|
-
def infer(typer)
|
214
|
+
def infer(typer, expression)
|
218
215
|
resolve_if(typer) do
|
219
|
-
@annotations.each {|a| a.infer(typer)} if @annotations
|
216
|
+
@annotations.each {|a| a.infer(typer, true)} if @annotations
|
220
217
|
@type = type_node.type_reference(typer)
|
221
218
|
end
|
222
219
|
end
|
@@ -243,17 +240,17 @@ module Mirah::AST
|
|
243
240
|
def initialize(parent, position, name, annotations=[], static = false, &block)
|
244
241
|
@annotations = annotations
|
245
242
|
super(parent, position, &block)
|
246
|
-
|
243
|
+
self.name = name
|
247
244
|
@static = static
|
248
245
|
end
|
249
246
|
|
250
|
-
def infer(typer)
|
247
|
+
def infer(typer, expression)
|
251
248
|
resolve_if(typer) do
|
252
|
-
@annotations.each {|a| a.infer(typer)} if @annotations
|
249
|
+
@annotations.each {|a| a.infer(typer, true)} if @annotations
|
253
250
|
if static
|
254
|
-
typer.learn_static_field_type(class_scope, name, typer.infer(value))
|
251
|
+
typer.learn_static_field_type(class_scope, name, typer.infer(value, true))
|
255
252
|
else
|
256
|
-
typer.learn_field_type(class_scope, name, typer.infer(value))
|
253
|
+
typer.learn_field_type(class_scope, name, typer.infer(value, true))
|
257
254
|
end
|
258
255
|
end
|
259
256
|
end
|
@@ -269,13 +266,13 @@ module Mirah::AST
|
|
269
266
|
def initialize(parent, position, name, annotations=[], static = false, &block)
|
270
267
|
@annotations = annotations
|
271
268
|
super(parent, position, &block)
|
272
|
-
|
269
|
+
self.name = name
|
273
270
|
@static = static
|
274
271
|
end
|
275
272
|
|
276
|
-
def infer(typer)
|
273
|
+
def infer(typer, expression)
|
277
274
|
resolve_if(typer) do
|
278
|
-
@annotations.each {|a| a.infer(typer)} if @annotations
|
275
|
+
@annotations.each {|a| a.infer(typer, true)} if @annotations
|
279
276
|
if static
|
280
277
|
typer.static_field_type(class_scope, name)
|
281
278
|
else
|
@@ -291,11 +288,11 @@ module Mirah::AST
|
|
291
288
|
|
292
289
|
def initialize(parent, line_number, name)
|
293
290
|
super(parent, line_number)
|
294
|
-
|
291
|
+
self.name = name
|
295
292
|
class_scope.current_access_level = name.to_sym
|
296
293
|
end
|
297
294
|
|
298
|
-
def infer(typer)
|
295
|
+
def infer(typer, expression)
|
299
296
|
typer.no_type
|
300
297
|
end
|
301
298
|
end
|
@@ -303,7 +300,7 @@ module Mirah::AST
|
|
303
300
|
class Include < Node
|
304
301
|
include Scoped
|
305
302
|
|
306
|
-
def infer(typer)
|
303
|
+
def infer(typer, expression)
|
307
304
|
children.each do |type|
|
308
305
|
typeref = type.type_reference(typer)
|
309
306
|
the_scope = scope.static_scope
|
data/lib/mirah/ast/flow.rb
CHANGED
@@ -22,16 +22,16 @@ module Mirah
|
|
22
22
|
super(parent, line_number, &block)
|
23
23
|
end
|
24
24
|
|
25
|
-
def infer(typer)
|
25
|
+
def infer(typer, expression)
|
26
26
|
unless resolved?
|
27
|
-
@inferred_type = typer.infer(predicate)
|
27
|
+
@inferred_type = typer.infer(predicate, true)
|
28
28
|
if @inferred_type && !@inferred_type.primitive?
|
29
29
|
call = Call.new(parent, position, '!=') do |call|
|
30
30
|
predicate.parent = call
|
31
31
|
[predicate, [Null.new(call, position)]]
|
32
32
|
end
|
33
33
|
self.predicate = call
|
34
|
-
@inferred_type = typer.infer(predicate)
|
34
|
+
@inferred_type = typer.infer(predicate, true)
|
35
35
|
end
|
36
36
|
|
37
37
|
@inferred_type ? resolved! : typer.defer(self)
|
@@ -50,60 +50,40 @@ module Mirah
|
|
50
50
|
super(parent, line_number, &block)
|
51
51
|
end
|
52
52
|
|
53
|
-
def infer(typer)
|
53
|
+
def infer(typer, expression)
|
54
54
|
unless resolved?
|
55
|
-
condition_type = typer.infer(condition)
|
55
|
+
condition_type = typer.infer(condition, true)
|
56
56
|
unless condition_type
|
57
57
|
typer.defer(condition)
|
58
58
|
end
|
59
59
|
|
60
60
|
# condition type is unrelated to body types, so we proceed with bodies
|
61
|
-
then_type = typer.infer(body) if body
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
if
|
69
|
-
# we have neither type, defer until later
|
70
|
-
typer.defer(self)
|
71
|
-
else
|
72
|
-
# we have else but not then, defer only then and use else type for now
|
73
|
-
@inferred_type = else_type
|
74
|
-
if body
|
75
|
-
typer.defer(self)
|
76
|
-
else
|
77
|
-
resolved! if condition_type
|
78
|
-
end
|
79
|
-
end
|
80
|
-
else
|
81
|
-
# no then type could be inferred and no else body, defer for now
|
82
|
-
typer.defer(self)
|
83
|
-
end
|
84
|
-
else
|
85
|
-
if self.else
|
86
|
-
else_type = typer.infer(self.else)
|
87
|
-
|
88
|
-
if !else_type
|
89
|
-
# we determined a then type, so we use that and defer the else body
|
90
|
-
@inferred_type = then_type
|
91
|
-
typer.defer(self)
|
92
|
-
else
|
61
|
+
then_type = typer.infer(body, expression) if body
|
62
|
+
else_type = typer.infer(self.else, expression) if self.else
|
63
|
+
|
64
|
+
if expression
|
65
|
+
have_body_type = body.nil? || then_type
|
66
|
+
have_else_type = self.else.nil? || else_type
|
67
|
+
if have_body_type && have_else_type
|
68
|
+
if then_type && else_type
|
93
69
|
# both then and else inferred, ensure they're compatible
|
94
70
|
if then_type.compatible?(else_type)
|
95
71
|
# types are compatible...if condition is resolved, we're done
|
96
72
|
@inferred_type = then_type.narrow(else_type)
|
97
73
|
resolved! if condition_type
|
98
74
|
else
|
99
|
-
raise Typer::InferenceError.new("if statement with incompatible result types #{then_type} and #{else_type}")
|
75
|
+
raise Mirah::Typer::InferenceError.new("if statement with incompatible result types #{then_type} and #{else_type}")
|
100
76
|
end
|
77
|
+
else
|
78
|
+
@inferred_type = then_type || else_type
|
79
|
+
resolved!
|
101
80
|
end
|
102
81
|
else
|
103
|
-
|
104
|
-
@inferred_type = then_type
|
105
|
-
resolved! if condition_type
|
82
|
+
typer.defer(self)
|
106
83
|
end
|
84
|
+
else
|
85
|
+
@inferred_type = typer.no_type
|
86
|
+
resolved!
|
107
87
|
end
|
108
88
|
end
|
109
89
|
|
@@ -136,13 +116,13 @@ module Mirah
|
|
136
116
|
end
|
137
117
|
end
|
138
118
|
|
139
|
-
def infer(typer)
|
119
|
+
def infer(typer, expression)
|
140
120
|
unless resolved?
|
141
121
|
child_types = children.map do |c|
|
142
122
|
if c.nil? || (Body === c && c.empty?)
|
143
123
|
typer.no_type
|
144
124
|
else
|
145
|
-
typer.infer(c)
|
125
|
+
typer.infer(c, true)
|
146
126
|
end
|
147
127
|
end
|
148
128
|
if child_types.any? {|t| t.nil?}
|
@@ -211,10 +191,10 @@ module Mirah
|
|
211
191
|
super(parent, line_number, &block)
|
212
192
|
end
|
213
193
|
|
214
|
-
def infer(typer)
|
194
|
+
def infer(typer, expression)
|
215
195
|
resolve_if(typer) do
|
216
196
|
if value
|
217
|
-
typer.infer(value)
|
197
|
+
typer.infer(value, true)
|
218
198
|
else
|
219
199
|
typer.no_type
|
220
200
|
end
|
@@ -223,7 +203,7 @@ module Mirah
|
|
223
203
|
end
|
224
204
|
|
225
205
|
class Break < Node;
|
226
|
-
def infer(typer)
|
206
|
+
def infer(typer, expression)
|
227
207
|
unless resolved?
|
228
208
|
resolved!
|
229
209
|
@inferred_type = typer.null_type
|
@@ -245,12 +225,12 @@ module Mirah
|
|
245
225
|
super(parent, line_number, &block)
|
246
226
|
end
|
247
227
|
|
248
|
-
def infer(typer)
|
228
|
+
def infer(typer, expression)
|
249
229
|
unless resolved?
|
250
230
|
@inferred_type = AST.unreachable_type
|
251
231
|
throwable = AST.type(nil, 'java.lang.Throwable')
|
252
232
|
if children.size == 1
|
253
|
-
arg_type = typer.infer(self.exception)
|
233
|
+
arg_type = typer.infer(self.exception, true)
|
254
234
|
unless arg_type
|
255
235
|
typer.defer(self)
|
256
236
|
return
|
@@ -261,7 +241,7 @@ module Mirah
|
|
261
241
|
end
|
262
242
|
end
|
263
243
|
|
264
|
-
arg_types = children.map {|c| typer.infer(c)}
|
244
|
+
arg_types = children.map {|c| typer.infer(c, true)}
|
265
245
|
if arg_types.any? {|c| c.nil?}
|
266
246
|
typer.defer(self)
|
267
247
|
else
|
@@ -275,7 +255,7 @@ module Mirah
|
|
275
255
|
end
|
276
256
|
resolved!
|
277
257
|
@children = [exception]
|
278
|
-
typer.infer(exception)
|
258
|
+
typer.infer(exception, true)
|
279
259
|
end
|
280
260
|
end
|
281
261
|
@inferred_type
|
@@ -302,7 +282,7 @@ module Mirah
|
|
302
282
|
end
|
303
283
|
end
|
304
284
|
|
305
|
-
def infer(typer)
|
285
|
+
def infer(typer, expression)
|
306
286
|
unless resolved?
|
307
287
|
@types ||= type_nodes.map {|n| n.type_reference(typer)}
|
308
288
|
if name
|
@@ -311,11 +291,7 @@ module Mirah
|
|
311
291
|
@type = types.size == 1 ? types[0] : AST.type(nil, 'java.lang.Throwable')
|
312
292
|
typer.learn_local_type(static_scope, name, @type)
|
313
293
|
end
|
314
|
-
@inferred_type = typer.infer(body)
|
315
|
-
|
316
|
-
if (@inferred_type && !body.resolved?)
|
317
|
-
puts "#{body} not resolved"
|
318
|
-
end
|
294
|
+
@inferred_type = typer.infer(body, true)
|
319
295
|
|
320
296
|
(@inferred_type && body.resolved?) ? resolved! : typer.defer(self)
|
321
297
|
end
|
@@ -344,9 +320,9 @@ module Mirah
|
|
344
320
|
@body, @clauses = children
|
345
321
|
end
|
346
322
|
|
347
|
-
def infer(typer)
|
323
|
+
def infer(typer, expression)
|
348
324
|
unless resolved?
|
349
|
-
types = [typer.infer(body)] + clauses.map {|c| typer.infer(c)}
|
325
|
+
types = [typer.infer(body, true )] + clauses.map {|c| typer.infer(c, true)}
|
350
326
|
if types.any? {|t| t.nil?}
|
351
327
|
typer.defer(self)
|
352
328
|
else
|
@@ -362,16 +338,16 @@ module Mirah
|
|
362
338
|
class Ensure < Node
|
363
339
|
child :body
|
364
340
|
child :clause
|
365
|
-
attr_accessor :state # Used by
|
341
|
+
attr_accessor :state # Used by some compilers.
|
366
342
|
|
367
343
|
def initialize(parent, position, &block)
|
368
344
|
super(parent, position, &block)
|
369
345
|
end
|
370
346
|
|
371
|
-
def infer(typer)
|
347
|
+
def infer(typer, expression)
|
372
348
|
resolve_if(typer) do
|
373
|
-
typer.infer(clause)
|
374
|
-
typer.infer(body)
|
349
|
+
typer.infer(clause, false)
|
350
|
+
typer.infer(body, true)
|
375
351
|
end
|
376
352
|
end
|
377
353
|
end
|