Class: Duby::AST::Call

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

Instance Attribute Summary collapse

Attributes included from Named

#name

Attributes inherited from Node

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

Instance Method Summary collapse

Methods included from Named

#to_s

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, name, &kids) ⇒ Call

Returns a new instance of Call.



48
49
50
51
52
# File 'lib/duby/ast/call.rb', line 48

def initialize(parent, line_number, name, &kids)
  super(parent, line_number, children, &kids)
  @target, @parameters, @block = children
  @name = name
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



46
47
48
# File 'lib/duby/ast/call.rb', line 46

def block
  @block
end

#parametersObject

Returns the value of attribute parameters.



46
47
48
# File 'lib/duby/ast/call.rb', line 46

def parameters
  @parameters
end

#targetObject

Returns the value of attribute target.



46
47
48
# File 'lib/duby/ast/call.rb', line 46

def target
  @target
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



146
147
148
149
# File 'lib/duby/compiler.rb', line 146

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

#expr?(compiler) ⇒ Boolean

Returns:



77
78
79
80
81
# File 'lib/duby/jvm/source_generator/precompile.rb', line 77

def expr?(compiler)
  target.expr?(compiler) &&
      parameters.all? {|p| p.expr?(compiler)} &&
      !method.actual_return_type.void?
end

#infer(typer) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/duby/ast/call.rb', line 54

def infer(typer)
  unless @inferred_type
    receiver_type = typer.infer(target)
    should_defer = false
    parameter_types = parameters.map do |param|
      typer.infer(param) || should_defer = true
    end
    
    unless should_defer
      @inferred_type = typer.method_type(receiver_type, name,
                                         parameter_types)
    end
    
    @inferred_type ? resolved! : typer.defer(self)
  end
    
  @inferred_type
end

#method(compiler = nil) ⇒ Object



70
71
72
73
74
75
# File 'lib/duby/jvm/source_generator/precompile.rb', line 70

def method(compiler=nil)
  @method ||= begin
    arg_types = parameters.map {|p| p.inferred_type}
    target.inferred_type.get_method(name, arg_types)
  end
end