예제 #1
0
        private void PrintFunctionDeclaration(FunctionDeclarationNode p_node)
        {
            Console.Write(identString + "[FUNCTION DECLARATION ");
            Print(p_node.Variable);
            Console.Write(" (");
            bool is_first = true;

            if (p_node.Parameters != null)
            {
                foreach (string n in p_node.Parameters)
                {
                    if (is_first)
                    {
                        Console.Write(n);
                        is_first = false;
                    }
                    else
                    {
                        Console.Write(", " + n);
                    }
                }
            }
            Console.WriteLine(")");
            IdentPlus();
            foreach (Node n in p_node.Body)
            {
                Print(n);
            }
            IdentMinus();
            Console.WriteLine(identString + "]");
        }
예제 #2
0
        private void ChunkFunctionDeclaration(FunctionDeclarationNode p_node)
        {
            //register name
            if (p_node.Variable.Indexes.Count == 0) // it is a regular function
            {
                if (globals.Contains(p_node.Variable.Name))
                {
                    Error("Local functions can not override global ones.", p_node.PositionData);
                }

                Nullable <Variable> maybe_name = SetVar(p_node.Variable.Name);

                if (maybe_name.HasValue)
                {
                    Variable this_function = maybe_name.Value;
                    if (this_function.type == ValueType.Global)
                    {
                        CompileFunction(this_function.name, p_node, true);
                    }
                    else
                    {
                        CompileFunction(this_function.name, p_node, false);
                    }
                }
                else
                {
                    Error("Function name has already been used!", p_node.PositionData);
                }
            }
            else
            {// it is a member function
                // assemble a name for it
                string name = p_node.Variable.Name;
                for (int i = 0; i < p_node.Variable.Indexes.Count; i++)
                {
                    if (p_node.Variable.Indexes[i].Type == NodeType.VARIABLE)
                    {
                        IndexNode this_index = p_node.Variable.Indexes[i];
                        if (this_index.AccessType == VarAccessType.COLON)
                        {
                            Error("Method Declaration is not supported yet!", p_node.PositionData);
                        }
                        if (this_index.IsAnonymous)
                        {
                            name += GetLambdaName(p_node);
                        }
                        else
                        {
                            name += "." + this_index.Name;
                        }
                    }
                }
                // Break it down
                MemberFunctionDeclarationNode extracted_function = new MemberFunctionDeclarationNode(name, p_node.Parameters, p_node.Body, p_node.PositionData);
                AssignmentNode new_assigment = new AssignmentNode(p_node.Variable, extracted_function, AssignmentOperatorType.ASSIGN, p_node.PositionData);
                StmtExprNode   new_stmt_expr = new StmtExprNode(new_assigment, p_node.PositionData);
                ChunkIt(new_stmt_expr);
            }
        }