예제 #1
0
        LocalVariableInfo EmitAssignmentOperator(CompilerState state, Node node)
        {
            if (state == null)
            {
                throw new Exception();
            }
            if (node == null)
            {
                throw new Exception();
            }

            Evaluation.Tokenizing.OperatorData data = node.Token.Data as Evaluation.Tokenizing.OperatorData;
            if (data == null || data.Operator != Operator.Assignment)
            {
                throw new Exception();
            }

            if (node.Children.Count != 2)
            {
                throw new Exception();
            }

            Evaluation.Tokenizing.CustomFunctionData vardata = node.Children[0].Token.Data as Evaluation.Tokenizing.CustomFunctionData;
            if (vardata == null)
            {
                throw new Exception();
            }

            if (node.Children[0].Children.Count != 1)
            {
                throw new Exception();
            }

            LocalVariableInfo index = Emit(state, node.Children[0].Children[0]);
            LocalVariableInfo value = Emit(state, node.Children[1]);

            List <LocalVariableInfo> args = new List <LocalVariableInfo>()
            {
                state.FunctionState, index, value
            };

            if (vardata.Type == typeof(Triggers.Var))
            {
                return(EmitMethod(state, typeof(SpecialFunctions).GetMethod("Assignment_Var"), args));
            }

            if (vardata.Type == typeof(Triggers.FVar))
            {
                return(EmitMethod(state, typeof(SpecialFunctions).GetMethod("Assignment_FVar"), args));
            }

            if (vardata.Type == typeof(Triggers.SysVar))
            {
                return(EmitMethod(state, typeof(SpecialFunctions).GetMethod("Assignment_SysVar"), args));
            }

            if (vardata.Type == typeof(Triggers.SysFVar))
            {
                return(EmitMethod(state, typeof(SpecialFunctions).GetMethod("Assignment_SysFVar"), args));
            }

            throw new Exception();
        }
예제 #2
0
        LocalVariableInfo EmitOperator(CompilerState state, Node node)
        {
            if (state == null)
            {
                throw new Exception();
            }
            if (node == null)
            {
                throw new Exception();
            }

            Evaluation.Tokenizing.OperatorData data = node.Token.Data as Evaluation.Tokenizing.OperatorData;
            if (data == null)
            {
                throw new Exception();
            }

            if (node.Children.Count == 1)
            {
                return(EmitUnaryOperator(state, node));
            }

            if (node.Children.Count != 2)
            {
                throw new Exception();
            }

            if (data.Operator == Operator.Assignment)
            {
                return(EmitAssignmentOperator(state, node));
            }

            LocalVariableInfo lhs = Emit(state, node.Children[0]);
            LocalVariableInfo rhs = Emit(state, node.Children[1]);

            switch (data.Operator)
            {
            case Operator.Plus:
                return(EmitArithmeticOperator(state, OpCodes.Add, lhs, rhs));

            case Operator.Minus:
                return(EmitArithmeticOperator(state, OpCodes.Sub, lhs, rhs));

            case Operator.Divide:
                return(EmitArithmeticOperator(state, OpCodes.Div, lhs, rhs));

            case Operator.Multiply:
                return(EmitArithmeticOperator(state, OpCodes.Mul, lhs, rhs));

            case Operator.Modulus:
                return(EmitArithmeticOperator(state, OpCodes.Rem, lhs, rhs));

            case Operator.Equals:
            case Operator.NotEquals:
            case Operator.Greater:
            case Operator.GreaterEquals:
            case Operator.Lesser:
            case Operator.LesserEquals:
                return(EmitComparsionOperator(state, data.Operator, lhs, rhs));

            case Operator.LogicalAnd:
            case Operator.LogicalOr:
            case Operator.LogicalXor:
                return(EmitLogicalOperator(state, data.Operator, lhs, rhs));

            case Operator.Exponent:
                return(EmitMethod(state, typeof(Math).GetMethod("Pow"), new List <LocalVariableInfo>()
                {
                    lhs, rhs
                }));

            default:
                throw new Exception();
            }
        }