Class: CallNode

Inherits:
Struct
  • Object
show all
Defined in:
lib/toylang/ast/nodes.rb,
lib/toylang/interpreter/evaluation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments

Returns:

  • (Object)

    the current value of arguments



33
34
35
# File 'lib/toylang/ast/nodes.rb', line 33

def arguments
  @arguments
end

#call_methodObject

Returns the value of attribute call_method

Returns:

  • (Object)

    the current value of call_method



33
34
35
# File 'lib/toylang/ast/nodes.rb', line 33

def call_method
  @call_method
end

#receiverObject

Returns the value of attribute receiver

Returns:

  • (Object)

    the current value of receiver



33
34
35
# File 'lib/toylang/ast/nodes.rb', line 33

def receiver
  @receiver
end

Instance Method Details

#eval(context) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/toylang/interpreter/evaluation.rb', line 77

def eval(context)
  if receiver.nil? && context.locals[call_method] && arguments.empty?
    context.locals[call_method]
  else
    value = if receiver
              receiver.eval(context)
            else
              context.current_self
            end
    eval_arguments = arguments.map { |arg| arg.eval(context) }
    value.call(call_method, eval_arguments)
  end
end