Class: Duby::AST::Rescue

Inherits:
Node
  • Object
show all
Defined in:
lib/duby/ast/flow.rb,
lib/duby/compiler.rb,
lib/duby/jvm/source_generator/precompile.rb

Instance Attribute Summary

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods inherited from Node

#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s

Constructor Details

#initialize(parent, position, &block) ⇒ Rescue

Returns a new instance of Rescue.



316
317
318
319
# File 'lib/duby/ast/flow.rb', line 316

def initialize(parent, position, &block)
  super(parent, position, &block)
  @body, @clauses = children
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



306
307
308
309
# File 'lib/duby/compiler.rb', line 306

def compile(compiler, expression)
  compiler.line(line_number)
  compiler.rescue(self, expression)
end

#expr?(compiler) ⇒ Boolean

Returns:



164
165
166
# File 'lib/duby/jvm/source_generator/precompile.rb', line 164

def expr?(compiler)
  false
end

#infer(typer) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/duby/ast/flow.rb', line 321

def infer(typer)
  unless resolved?
    types = [typer.infer(body)] + clauses.map {|c| typer.infer(c)}
    if types.any? {|t| t.nil?}
      typer.defer(self)
    else
      # TODO check types for compatibility (maybe only if an expression)
      resolved!
      @inferred_type = types[0]
    end
  end
  @inferred_type
end