Class: FuncCallNode
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from Node
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(name, args) ⇒ FuncCallNode
constructor
A new instance of FuncCallNode.
Methods inherited from Node
Constructor Details
#initialize(name, args) ⇒ FuncCallNode
Returns a new instance of FuncCallNode.
65 66 67 68 |
# File 'lib/nodes/stmtnodes.rb', line 65 def initialize(name, args) @name = name @args = args end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
63 64 65 |
# File 'lib/nodes/stmtnodes.rb', line 63 def args @args end |
#name ⇒ Object
Returns the value of attribute name.
63 64 65 |
# File 'lib/nodes/stmtnodes.rb', line 63 def name @name end |
Instance Method Details
#evaluate ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/nodes/stmtnodes.rb', line 70 def evaluate func = ScopeManager.lookup_func(@name) function_body = func[0] function_param = func[1] ScopeManager.increment_scope_level if function_param.is_a?(ArrayNode) function_param.each do |val, index| function_param[index] = VariableDecNode.new(function_param[index].name, @args[index]) function_param[index].evaluate end end func_return_value = function_body.evaluate ScopeManager.decrement_scope_level # If function return value is an "Assign" then we declare that variable in the global scope. # This should be a ScopeManager method, add_variable_to_global_scope is missing. old_scope_lvl = ScopeManager.scope_lvl if func_return_value.is_a?(VariableDecNode) ScopeManager.scope_lvl = 0 func_return_value.evaluate ScopeManager.scope_lvl = old_scope_lvl end return func_return_value end |