예제 #1
0
        /// <summary>
        /// Removes a child from this compile statement's children and returns it for adding somewhere else
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public CompiledStatement RemoveAt(int index)
        {
            Debug.Assert(ChildCompiledStatements.Count > index);
            CompiledStatement child = ChildCompiledStatements[index];

            ChildCompiledStatements.RemoveAt(index);

            return(child);
        }
예제 #2
0
        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;
        }
예제 #3
0
 /// <summary>
 /// A wrapper around the add function for our child list
 /// </summary>
 /// <param name="compiledStatement"></param>
 public void Add(CompiledStatement compiledStatement)
 {
     ChildCompiledStatements.Add(compiledStatement);
 }