/// <summary> /// Creates a new array of references to the variables used as parameters, rather than returning a reference. /// </summary> /// <returns></returns> public List <Variable> GetParameters() { List <Variable> vars = new List <Variable>(ParameterNames.Count); foreach (string name in ParameterNames) { vars.Add(FunctionScope.GetLocalVariable(name, ScopeSearchOption.kThisScope)); } return(vars); }
public override void PerformOperation() { // Set up our parameters if required if (ParameterNames.Count > 0) { Debug.Assert(ChildCount > 0, "Fatal error in function call - no arguments to process"); CompiledStatement thisCallsParams = ChildCompiledStatements[0]; ChildCompiledStatements.RemoveAt(0); // This will run through each stored parameter and add them to the stack thisCallsParams.PerformOperation(); } // Set up our parameters - read them off the stack with the first parameter at the top for (int i = 0; i < ParameterNames.Count; i++) { Debug.Assert(CelesteStack.StackSize > 0, "Insufficient parameters to function"); CelesteObject input = CelesteStack.Pop(); Variable functionParameter = FunctionScope.GetLocalVariable(ParameterNames[i], ScopeSearchOption.kThisScope); if (input.IsReference()) { functionParameter.Value = input.ValueImpl; } else { (functionParameter.Value as Reference).Value = input.Value; } } CelesteStack.CurrentScope = FunctionScope; // Performs all the operators on the children first foreach (CompiledStatement statement in FuncImpl.ChildCompiledStatements) { statement.PerformOperation(); if (statement is ReturnKeyword) { // Stop iterating through if we have hit a ReturnKeyword in our function break; } } CelesteStack.Scopes.Remove(FunctionScope); CelesteStack.CurrentScope = FunctionScope.ParentScope; }