Class: Mirah::AST::Rescue
- Defined in:
- lib/mirah/ast/flow.rb,
lib/mirah/compiler/flow.rb,
lib/mirah/jvm/source_generator/precompile.rb
Instance Attribute Summary
Attributes inherited from Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary collapse
- #compile(compiler, expression) ⇒ Object
- #expr?(compiler) ⇒ Boolean
- #infer(typer, expression) ⇒ Object
-
#initialize(parent, position, &block) ⇒ Rescue
constructor
A new instance of Rescue.
Methods inherited from Node
#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children
Constructor Details
#initialize(parent, position, &block) ⇒ Rescue
Returns a new instance of Rescue.
320 321 322 |
# File 'lib/mirah/ast/flow.rb', line 320 def initialize(parent, position, &block) super(parent, position, &block) end |
Instance Method Details
#compile(compiler, expression) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/mirah/compiler/flow.rb', line 92 def compile(compiler, expression) compiler.line(line_number) compiler.rescue(self, expression) rescue Exception => ex raise Mirah::InternalCompilerError.wrap(ex, self) end |
#expr?(compiler) ⇒ Boolean
188 189 190 |
# File 'lib/mirah/jvm/source_generator/precompile.rb', line 188 def expr?(compiler) false end |
#infer(typer, expression) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/mirah/ast/flow.rb', line 324 def infer(typer, expression) unless resolved? types = [] body_type = typer.infer(body, else_node.nil?) if body else_type = typer.infer(else_node, true) if else_node if else_node types << else_type elsif body types << body_type end types += clauses.map {|c| typer.infer(c, true)} if types.any? {|t| t.nil?} typer.defer(self) else # TODO check types for compatibility (maybe only if an expression) resolved! types.each do |type| @inferred_type ||= type unless type.unreachable? end @inferred_type ||= types[0] end end @inferred_type end |