Exemple #1
0
        private void PrintassignmentOp(AssignmentNode p_node)
        {
            Console.Write("[ASSIGMENT_OP " + p_node.Assigned.Name);
            string op;

            switch (p_node.Op)
            {
            case AssignmentOperatorType.ADDITION_ASSIGN:
                op = " += ";
                break;

            case AssignmentOperatorType.SUBTRACTION_ASSIGN:
                op = " -= ";
                break;

            case AssignmentOperatorType.MULTIPLICATION_ASSIGN:
                op = " *= ";
                break;

            case AssignmentOperatorType.DIVISION_ASSIGN:
                op = " /= ";
                break;

            default:
                op = "";
                break;
            }
            Console.Write(op);
            Print(p_node.Value);
            Console.Write("]");
        }
Exemple #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);
            }
        }
Exemple #3
0
        private void ChunkAssignmentOp(AssignmentNode p_node)
        {
            ChunkIt(p_node.Value);
            Nullable <Variable> maybe_var = GetVar(p_node.Assigned.Name, p_node.PositionData);

            Operand op = (Operand)p_node.Op;

            if (maybe_var.HasValue)
            {
                Variable this_var = maybe_var.Value;
                if (p_node.Assigned.Indexes.Count == 0)
                {
                    switch (this_var.type)
                    {
                    case ValueType.Local:
                        Add(OpCode.ASSIGN_VARIABLE, (Operand)this_var.address, (Operand)this_var.envIndex, op, p_node.PositionData);
                        break;

                    case ValueType.Global:
                        Add(OpCode.ASSIGN_GLOBAL, (Operand)this_var.address, op, p_node.PositionData);
                        break;

                    case ValueType.UpValue:
                        int this_index = upvalueStack.Peek().IndexOf(this_var);
                        Add(OpCode.ASSIGN_UPVALUE, (Operand)this_index, op, p_node.PositionData);
                        break;
                    }
                }
                else  //  it is a compoundVar
                {
                    LoadVariable(this_var, p_node.PositionData);
                    LoadIndexes(p_node.Assigned.Indexes);
                    Add(OpCode.SET, (Operand)p_node.Assigned.Indexes.Count, op, p_node.PositionData);
                }
            }
            else
            {
                Error("assignment to non existing variable!", p_node.PositionData);
            }
        }