Class: CallNode
- Inherits:
-
Struct
- Object
- Struct
- CallNode
- Defined in:
- lib/toylang/ast/nodes.rb,
lib/toylang/interpreter/evaluation.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#call_method ⇒ Object
Returns the value of attribute call_method.
-
#receiver ⇒ Object
Returns the value of attribute receiver.
Instance Method Summary collapse
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments
33 34 35 |
# File 'lib/toylang/ast/nodes.rb', line 33 def arguments @arguments end |
#call_method ⇒ Object
Returns the value of attribute call_method
33 34 35 |
# File 'lib/toylang/ast/nodes.rb', line 33 def call_method @call_method end |
#receiver ⇒ Object
Returns the value of attribute 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 |