Class: Duby::AST::Return

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

Instance Attribute Summary

Attributes included from Valued

#value

Attributes included from Typed

#type

Attributes inherited from JumpNode

#ensures

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, line_number, ensures, &block) ⇒ Return

Returns a new instance of Return.



174
175
176
177
# File 'lib/duby/ast/flow.rb', line 174

def initialize(parent, line_number, ensures, &block)
  super(parent, line_number, ensures, &block)
  @value = children[0]
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



195
196
197
198
# File 'lib/duby/compiler.rb', line 195

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

#expr?(compiler) ⇒ Boolean

Returns:



120
121
122
# File 'lib/duby/jvm/source_generator/precompile.rb', line 120

def expr?(compiler)
  false
end

#infer(typer) ⇒ Object



179
180
181
182
183
184
185
186
187
# File 'lib/duby/ast/flow.rb', line 179

def infer(typer)
  unless resolved?
    @inferred_type = typer.infer(value)

    (@inferred_type && value.resolved?) ? resolved! : typer.defer(self)
  end

  @inferred_type
end