Exemple #1
0
        private void PrintFunctionCall(FunctionCallNode p_node)
        {
            Console.Write("[FUNCTION CALL ");
            Print(p_node.Variable);

            int counter = 0;

            foreach (CallInfo call in p_node.Calls)
            {
                Console.Write("(");
                bool is_first = true;
                foreach (Node n in call.Arguments)
                {
                    if (is_first)
                    {
                        Print(n);
                        is_first = false;
                    }
                    else
                    {
                        Print(n);
                        Console.Write(", ");
                    }
                }
                Console.Write(")");
                if (call.Indexes != null)
                {
                    foreach (Node n in call.Indexes)
                    {
                        Print(n);
                    }
                }
                counter++;
            }
            Console.Write("]");
        }
Exemple #2
0
        private void ChunkFunctionCall(FunctionCallNode p_node)
        {
            //push parameters on stack
            for (int i = p_node.Calls[0].Arguments.Count - 1; i >= 0; i--)
            {
                ChunkIt(p_node.Calls[0].Arguments[i]);
            }

            // the first call, we need to decode the function name, or object
            Variable this_called;

            if (p_node.Variable.IsAnonymous)
            {
                this_called = new Variable(p_node.Variable.Expression);
            }
            else
            {
                Nullable <Variable> maybe_call = GetVar(p_node.Variable.Name, p_node.PositionData);
                if (maybe_call.HasValue)
                {
                    this_called = maybe_call.Value;
                }
                else
                {
                    return;
                }
            }

            if (p_node.Variable.Indexes.Count == 0)
            {
                LoadVariable(this_called, p_node.PositionData);
            }
            else // it is a compoundCall/method/IndexedAccess!
            {
                if (p_node.Variable.Indexes[p_node.Variable.Indexes.Count - 1].AccessType == VarAccessType.COLON)
                {                                         // is it a method!
                    LoadVariable(this_called, p_node.PositionData);
                    Add(OpCode.DUP, p_node.PositionData); // it is a method so we push the table again, to be used as parameter!
                    Add(OpCode.PUSH_STASH, p_node.PositionData);

                    for (int i = 0; i < p_node.Variable.Indexes.Count - 1; i++)
                    {
                        LoadIndex(p_node.Variable.Indexes[i]);
                    }

                    Add(OpCode.GET, (Operand)(p_node.Variable.Indexes.Count - 1), p_node.PositionData);
                    Add(OpCode.POP_STASH, p_node.PositionData);
                }
                else
                {
                    LoadVariable(this_called, p_node.PositionData);
                }

                LoadIndexes(p_node.Variable.Indexes);
                Add(OpCode.GET, (Operand)p_node.Variable.Indexes.Count, p_node.PositionData);
            }

            // Call
            Add(OpCode.CALL, p_node.PositionData);
            // Does it have IndexedAccess?
            if (p_node.Calls[0].Indexes != null)
            {
                LoadIndexes(p_node.Calls[0].Indexes);
                Add(OpCode.GET, (Operand)p_node.Calls[0].Indexes.Count, p_node.PositionData);
            }

            // Is it a compound call?
            for (int i = 1; i < p_node.Calls.Count; i++)
            {
                Add(OpCode.PUSH_STASH, p_node.PositionData);

                for (int j = p_node.Calls[i].Arguments.Count - 1; j >= 0; j--)
                {
                    ChunkIt(p_node.Calls[i].Arguments[j]);
                }

                Add(OpCode.POP_STASH, p_node.PositionData);
                Add(OpCode.CALL, p_node.PositionData);

                if (p_node.Calls[i].Indexes != null)
                {
                    LoadIndexes(p_node.Calls[i].Indexes);
                    Add(OpCode.GET, (Operand)p_node.Calls[i].Indexes.Count, p_node.PositionData);
                }
            }
        }