Class: Duby::AST::Body

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

Direct Known Subclasses

ScopedBody

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

Returns a new instance of Body.



3
4
5
# File 'lib/duby/ast/structure.rb', line 3

def initialize(parent, line_number, &block)
  super(parent, line_number, &block)
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



69
70
71
72
# File 'lib/duby/compiler.rb', line 69

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

#expr?(compiler) ⇒ Boolean

Returns:



44
45
46
# File 'lib/duby/jvm/source_generator/precompile.rb', line 44

def expr?(compiler)
  false
end

#infer(typer) ⇒ Object

Type of a block is the type of its final element



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/duby/ast/structure.rb', line 8

def infer(typer)
  unless @inferred_type
    if children.size == 0
      @inferred_type = typer.no_type
    else
      children.each {|child| @inferred_type = typer.infer(child)}
    end

    if @inferred_type
      resolved!
    else
      typer.defer(self)
    end
  end

  @inferred_type
end