Class: Duby::AST::Rescue

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

Instance Attribute Summary collapse

Attributes inherited from Node

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

Instance Method Summary collapse

Methods inherited from Node

#[], #each, #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.



287
288
289
290
# File 'lib/duby/ast/flow.rb', line 287

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

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



286
287
288
# File 'lib/duby/ast/flow.rb', line 286

def body
  @body
end

#clausesObject

Returns the value of attribute clauses.



286
287
288
# File 'lib/duby/ast/flow.rb', line 286

def clauses
  @clauses
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



248
249
250
251
# File 'lib/duby/compiler.rb', line 248

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

#expr?(compiler) ⇒ Boolean

Returns:



132
133
134
# File 'lib/duby/jvm/source_generator/precompile.rb', line 132

def expr?(compiler)
  false
end

#infer(typer) ⇒ Object



292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/duby/ast/flow.rb', line 292

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