mirah 0.0.9-java → 0.0.10-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,43 @@
1
+ === 0.0.10 / 2011-11-20
2
+
3
+ f6035d0 set version to 0.0.10
4
+ 3b06353 use test_helper in gwt test
5
+ 4d29eeb turns out a number of things rely on MirahCommands being truthy on success
6
+ 46e6719 fixes 156 for real, also do the ant lowercase thing
7
+ 9e40121 don't exit on successful compile
8
+ 1155765 move comment about class loader to line it refers to
9
+ 985c70f add jvm_version option to Compile ant task w/ 1.6 default
10
+ e5a60b2 replace duby with mirah in lib/mirah/ast/flow.rb
11
+ 5690e6f split rescue error tests to deal w/ caching expression value
12
+ 1f77ed8 add some white space, use #empty? instead of size==0
13
+ 677e4aa fixes #52 by raising an inference error when types arent compat
14
+ 81be877 add assert_raise_java to get around the NativeException thing
15
+ d744f44 use assert_raise instead of begin;fail/rescue
16
+ 05afc6e pull out rescue tests for jvm into separate file
17
+ 7a933f3 raise an inference error when method has same name as macro. fixes #123
18
+ 6517a90 clean up the Block#add_methods method a bit
19
+ 0a826dd ensure that a block body is created even when the block is empty
20
+ d8b0641 change duby to mirah in Binding#binding_type
21
+ 47883e9 change duby to mirah in StaticScope#binding_type
22
+ 8f3fddf Fix whitespace.
23
+ 74b6195 use turn for prettying up test output
24
+ 23d0693 add license header to test_macros
25
+ 143ac6c add a test_helper to put global test config in
26
+ 6fe3241 fix #149 exit 1 when there are errors
27
+ 31074c6 fix #146 by not reassigning self to Builtin
28
+ 8fb471e s/duby/mirah/ in jvm types intrinsics
29
+ ff06791 s/qote/quote/
30
+ 972a9f9 refactor void checking on method return into method
31
+ 605c377 fix #148 in the simplest way possible
32
+ f1b5c19 fix inspect_children typo
33
+ 4140fa7 use case statements instead of === & if elses in UnquotedValueAssign#node
34
+ b82bbeb in Node#inspect_children, replace if elses w/ a case statement
35
+ 049a4cf clean up body inference a little
36
+ d9e92b4 Merge remote branch 'thomaslee/master' into thomaslee
37
+ 0c72195 fix name of compilation test
38
+ cfbf4c5 bump versions to 0.0.10{.dev,-SNAPSHOT}
39
+ 8c0ecec Fix test_empty_array.
40
+
1
41
  === 0.0.9 / 2011-09-12
2
42
 
3
43
  a5963ef use self hosted classloader fixes #144
data/Rakefile CHANGED
@@ -56,6 +56,7 @@ namespace :test do
56
56
 
57
57
  desc "run the core tests"
58
58
  Rake::TestTask.new :core do |t|
59
+ t.libs << 'test'
59
60
  t.test_files = FileList["test/core/**/test*.rb"]
60
61
  java.lang.System.set_property("jruby.duby.enabled", "true")
61
62
  end
@@ -75,7 +76,7 @@ namespace :test do
75
76
  namespace :jvm do
76
77
  desc "run jvm tests compiling to bytecode"
77
78
  Rake::TestTask.new :bytecode do |t|
78
- t.libs << 'test/jvm'
79
+ t.libs << 'test' <<'test/jvm'
79
80
  t.ruby_opts.concat ["-r", "bytecode_test_helper"]
80
81
  t.test_files = FileList["test/jvm/**/test*.rb"]
81
82
  java.lang.System.set_property("jruby.duby.enabled", "true")
@@ -83,7 +84,7 @@ namespace :test do
83
84
 
84
85
  desc "run jvm tests compiling to java source, then bytecode"
85
86
  Rake::TestTask.new :javac do |t|
86
- t.libs << 'test/jvm'
87
+ t.libs << 'test' <<'test/jvm'
87
88
  t.ruby_opts.concat ["-r", "javac_test_helper"]
88
89
  t.test_files = FileList["test/jvm/**/test*.rb"]
89
90
  java.lang.System.set_property("jruby.duby.enabled", "true")
Binary file
@@ -160,23 +160,33 @@ module Mirah
160
160
  extra_indent = 0
161
161
  if child
162
162
  name = self.class.child_name(i)
163
+
164
+ wrong_parent = lambda do |child|
165
+ if Node === child && child.parent != self
166
+ "\n#{indent_str} (wrong parent)"
167
+ else
168
+ ""
169
+ end
170
+ end
171
+
163
172
  if Mirah::AST.verbose && name
164
173
  str << "\n#{indent_str} #{name}:"
165
174
  extra_indent = 1
166
175
  end
167
- if ::Array === child
168
- child.each {|ary_child|
169
- if Mirah::AST.verbose && Node === ary_child && ary_child.parent != self
170
- str << "\n#{indent_str} (wrong parent)"
171
- end
176
+
177
+ case child
178
+ when ::Array
179
+ child.each do |ary_child|
180
+
181
+ str << wrong_parent[ary_child] if Mirah::AST.verbose
182
+
172
183
  str << "\n#{ary_child.inspect(indent + extra_indent + 1)}"
173
- }
174
- elsif ::Hash === child || ::String === child
184
+ end
185
+ when ::Hash, ::String
175
186
  str << "\n#{indent_str} #{child.inspect}"
176
187
  else
177
- if Mirah::AST.verbose && Node === child && child.parent != self
178
- str << "\n#{indent_str} (wrong parent)"
179
- end
188
+ str << wrong_parent[child] if Mirah::AST.verbose
189
+
180
190
  begin
181
191
  str << "\n#{child.inspect(indent + extra_indent + 1)}"
182
192
  rescue ArgumentError => ex
@@ -358,8 +368,8 @@ module Mirah
358
368
  end
359
369
 
360
370
  module Binding
361
- def binding_type(duby=nil)
362
- static_scope.binding_type(defining_class, duby)
371
+ def binding_type(mirah=nil)
372
+ static_scope.binding_type(defining_class, mirah)
363
373
  end
364
374
 
365
375
  def binding_type=(type)
@@ -64,6 +64,7 @@ module Mirah
64
64
  if expression
65
65
  have_body_type = body.nil? || then_type
66
66
  have_else_type = self.else.nil? || else_type
67
+
67
68
  if have_body_type && have_else_type
68
69
  if then_type && else_type
69
70
  # both then and else inferred, ensure they're compatible
@@ -299,8 +300,8 @@ module Mirah
299
300
  @inferred_type
300
301
  end
301
302
 
302
- def binding_type(duby=nil)
303
- static_scope.parent.binding_type(defining_class, duby)
303
+ def binding_type(mirah=nil)
304
+ static_scope.parent.binding_type(defining_class, mirah)
304
305
  end
305
306
 
306
307
  def binding_type=(type)
@@ -323,24 +324,37 @@ module Mirah
323
324
 
324
325
  def infer(typer, expression)
325
326
  unless resolved?
326
- types = []
327
- body_type = typer.infer(body, else_node.nil?) if body
328
- else_type = typer.infer(else_node, true) if else_node
329
- if else_node
330
- types << else_type
327
+ # TODO: generalize this s.t.
328
+ # the problem with deferred inference
329
+ # assuming expression == true is dealt with
330
+ @expression = expression if @expression == nil
331
+ expression = @expression
332
+
333
+ primary_type = if else_node
334
+ typer.infer(body, false) if body
335
+ typer.infer(else_node, expression)
331
336
  elsif body
332
- types << body_type
337
+ typer.infer(body, expression)
333
338
  end
334
- types += clauses.map {|c| typer.infer(c, true)}
339
+
340
+ clause_types = clauses.map {|c| typer.infer(c, expression)}
341
+ types = []
342
+ types << primary_type if primary_type
343
+ types += clause_types
335
344
  if types.any? {|t| t.nil?}
336
345
  typer.defer(self)
337
346
  else
338
- # TODO check types for compatibility (maybe only if an expression)
339
- resolved!
340
- types.each do |type|
341
- @inferred_type ||= type unless type.unreachable?
347
+ if !expression || clause_types.all?{ |t| primary_type.compatible? t}
348
+ resolved!
349
+ types.each do |type|
350
+ @inferred_type ||= type unless type.unreachable?
351
+ end
352
+ @inferred_type ||= primary_type
353
+ else
354
+ clause, clause_type = clauses.zip(clause_types).find{ |clause, t| !primary_type.compatible? t }
355
+
356
+ raise Mirah::Typer::InferenceError.new("rescue statement with incompatible result types #{primary_type} and #{clause_type}", clause)
342
357
  end
343
- @inferred_type ||= types[0]
344
358
  end
345
359
  end
346
360
  @inferred_type
@@ -51,19 +51,19 @@ module Mirah::AST
51
51
  end
52
52
 
53
53
  def self.__extracted
54
- Thread.current[:'Mirah::AST::Unqote.extracted']
54
+ Thread.current[:'Mirah::AST::Unquote.extracted']
55
55
  end
56
56
 
57
57
  def self.__extracted=(value)
58
- Thread.current[:'Mirah::AST::Unqote.extracted'] = value
58
+ Thread.current[:'Mirah::AST::Unquote.extracted'] = value
59
59
  end
60
60
 
61
61
  def self.__injected
62
- Thread.current[:'Mirah::AST::Unqote.injected']
62
+ Thread.current[:'Mirah::AST::Unquote.injected']
63
63
  end
64
64
 
65
65
  def self.__injected=(value)
66
- Thread.current[:'Mirah::AST::Unqote.injected'] = value
66
+ Thread.current[:'Mirah::AST::Unquote.injected'] = value
67
67
  end
68
68
 
69
69
  def self.extract_values
@@ -212,27 +212,30 @@ module Mirah::AST
212
212
  else
213
213
  name_node = self.name_node
214
214
  end
215
+
215
216
  klass = LocalAssignment
216
- if Field === name_node
217
- name = name_node.name
218
- klass = FieldAssignment
219
- # TODO support AttrAssign
220
- elsif Named === name_node
221
- name = name_node.name
222
- elsif String === name_node
223
- name = name_node.literal
224
- elsif ::String === name_node
225
- name = name_node
226
- else
227
- raise "Bad unquote value"
228
- end
217
+ name = case name_node
218
+ when Field
219
+ # TODO support AttrAssign
220
+ klass = FieldAssignment
221
+ name_node.name
222
+ when Named
223
+ name_node.name
224
+ when String
225
+ name_node.literal
226
+ else
227
+ raise "Bad unquote value"
228
+ end
229
+
229
230
  if name[0] == ?@
230
231
  name = name[1, name.length]
231
232
  klass = FieldAssignment
232
233
  end
234
+
233
235
  n = klass.new(nil, position, name)
234
236
  n << value
235
237
  n.validate_children
238
+
236
239
  if scope
237
240
  scope.children.clear
238
241
  scope << n
@@ -255,6 +255,7 @@ module Mirah::AST
255
255
  end
256
256
  signature[:return] = @return_type.type_reference(typer)
257
257
  end
258
+
258
259
  if @exceptions
259
260
  signature[:throws] = @exceptions.map {|e| e.type_reference(typer)}
260
261
  end
@@ -264,11 +265,16 @@ module Mirah::AST
264
265
  inferred_type = body ? typer.infer(body, body_is_expression) : typer.no_type
265
266
 
266
267
  if inferred_type && arguments.inferred_type.all?
267
- actual_type = if forced_type.nil?
268
- inferred_type
269
- else
268
+ actual_type = if forced_type
270
269
  forced_type
270
+ else
271
+ inferred_type
272
+ end
273
+
274
+ if actual_type.kind_of? Mirah::AST::InlineCode
275
+ raise Mirah::Typer::InferenceError.new("Method %s has the same signature as macro of the same name." % name,self)
271
276
  end
277
+
272
278
  if actual_type.unreachable?
273
279
  actual_type = typer.no_type
274
280
  end
@@ -156,12 +156,12 @@ module Mirah
156
156
  @self_node
157
157
  end
158
158
 
159
- def binding_type(defining_class=nil, duby=nil)
159
+ def binding_type(defining_class=nil, mirah=nil)
160
160
  @binding_type ||= begin
161
161
  if parent
162
- parent.binding_type(defining_class, duby)
162
+ parent.binding_type(defining_class, mirah)
163
163
  else
164
- name = "#{defining_class.name}$#{duby.tmp}"
164
+ name = "#{defining_class.name}$#{mirah.tmp}"
165
165
  factory = Mirah::AST.type_factory
166
166
  if factory
167
167
  factory.declare_type(@scope_node, name)
@@ -26,14 +26,14 @@ module Mirah::AST
26
26
  unless @inferred_type
27
27
  @typer ||= typer
28
28
  @self_type ||= typer.self_type
29
- if children.size == 0
29
+
30
+ if children.empty?
30
31
  @inferred_type = typer.no_type
31
32
  else
32
- last = children.size - 1
33
- children.each_with_index do |child, i|
34
- child_is_expression = (i == last && expression)
35
- @inferred_type = typer.infer(child, child_is_expression)
33
+ children[0..-2].each do |child|
34
+ typer.infer(child, false)
36
35
  end
36
+ @inferred_type = typer.infer(children.last, expression)
37
37
  end
38
38
 
39
39
  if @inferred_type
@@ -175,16 +175,19 @@ module Mirah::AST
175
175
  end
176
176
 
177
177
  def add_methods(klass, binding, typer)
178
- found_def = false
179
- body.each do |node|
180
- if node.kind_of?(MethodDefinition)
181
- found_def = true
178
+ method_definitions = body.select{ |node| node.kind_of? MethodDefinition }
179
+
180
+ if method_definitions.empty?
181
+ build_method(klass, binding, typer)
182
+ else
183
+ # TODO warn if there are non method definition nodes
184
+ # they won't be used at all currently--so it'd be nice to note that.
185
+ method_definitions.each do |node|
182
186
  node.static_scope = static_scope
183
187
  node.binding_type = binding
184
188
  klass.append_node(node)
185
189
  end
186
190
  end
187
- build_method(klass, binding, typer) unless found_def
188
191
  end
189
192
 
190
193
  def build_method(klass, binding, typer)
@@ -338,13 +341,13 @@ module Mirah::AST
338
341
  case node
339
342
  when String
340
343
  java.lang.String.new(node.literal)
344
+ when Fixnum
345
+ java.lang.Integer.new(node.literal)
341
346
  when Array
342
347
  node.children.map {|node| annotation_value(node, typer)}
343
348
  else
344
349
  # TODO Support other types
345
- ref = value.type_refence(typer)
346
- desc = BiteScript::Signature.class_id(ref)
347
- BiteScript::ASM::Type.getType(desc)
350
+ raise "Unsupported Annotation Value Type"
348
351
  end
349
352
  end
350
353
  end
@@ -34,8 +34,8 @@ module Mirah
34
34
  def execute_base
35
35
  # because MirahCommand is a JRuby Java class, SystemExit bubbles through and makes noise
36
36
  # so we use a catch/throw to early exit instead
37
- # see process_errors.rb
38
- catch(:exit) do
37
+ # see util/process_errors.rb
38
+ status = catch(:exit) do
39
39
  begin
40
40
  argument_processor.process
41
41
  yield
@@ -46,8 +46,12 @@ module Mirah
46
46
  rescue Mirah::MirahError => ex
47
47
  Mirah.print_error(ex.message, ex.position)
48
48
  puts ex.backtrace if state.verbose
49
+ throw :exit, 1
49
50
  end
51
+ 0
50
52
  end
53
+ exit status if status > 0
54
+ true
51
55
  end
52
56
  end
53
57
  end
@@ -75,7 +75,7 @@ module Mirah
75
75
 
76
76
  prepare_binding(node) do
77
77
  declare_locals(node.static_scope)
78
- unless @method.type.nil? || @method.type.void?
78
+ unless method.returns_void?
79
79
  self.return(ImplicitReturn.new(node.body))
80
80
  else
81
81
  node.body.compile(self, false) if node.body
@@ -87,7 +87,7 @@ module Mirah
87
87
  end
88
88
  end
89
89
  end
90
-
90
+
91
91
  def annotate(node, annotations)
92
92
  node.annotate(annotations)
93
93
  end
@@ -95,7 +95,7 @@ module Mirah
95
95
  def define_optarg_chain(name, arg, return_type,
96
96
  args_for_opt, arg_types_for_opt)
97
97
  # declare all args so they get their values
98
- @method.print "return " unless @method.type.nil? || @method.type.void?
98
+ @method.print "return " unless method.returns_void?
99
99
  @method.print "this." unless @static
100
100
  @method.print "#{name}("
101
101
  @method.print args_for_opt.map(&:name).join(', ')
@@ -164,7 +164,7 @@ module Mirah
164
164
  end
165
165
 
166
166
  def return(node)
167
- if @method.type.nil? || @method.type.void?
167
+ if method.returns_void?
168
168
  @method.puts 'return;'
169
169
  return
170
170
  end
@@ -157,6 +157,8 @@ module Mirah
157
157
 
158
158
  def annotation_value(value)
159
159
  case value
160
+ when Java::JavaLang::Integer
161
+ value.to_s
160
162
  when Java::JavaLang::String, String
161
163
  value.to_s.inspect
162
164
  when Array
@@ -394,6 +396,10 @@ module Mirah
394
396
  dedent
395
397
  puts "}"
396
398
  end
399
+
400
+ def returns_void?
401
+ type.nil? || type.void?
402
+ end
397
403
 
398
404
  def declare_local(type, name, initialize=true)
399
405
  unless @locals[name]