示例#1
0
        private static OperatorResult SetFunc(OperatorOperands operands, BinaryArithmeticInstructionType operatorType)
        {
            //if(!operands.A.Type.Equals(operands.B.Type))
            //return new OperatorResult(new CompileError(CompileErrorType.IncompatibleTypes, operands.A.Token));

            //if(operands.LineItem.Operand1 == null)
            //    return new OperatorResult(new CompileError(CompileErrorType.WrongAssignmentOperation, operands.A.Token));

            if (operands.A.VariableType != VariableType.Variable && operands.A.VariableType != VariableType.ArrayItem)
            {
                return(new OperatorResult(new CompileError(CompileErrorType.WrongAssignmentOperation, operands.A.Token)));
            }

            if (!Type.CanCastAssignment(operands.A.Type, operands.B.Type))
            {
                return(new OperatorResult(new CompileError(CompileErrorType.IncompatibleTypes, operands.A.Token)));
            }

            var casts = new List <InstructionCast>();

            if (operands.B.Type != operands.A.Type)
            {
                var castedB = new Variable(operands.A.Type, "__castedReg", operands.Function.Scope, operands.B.Token,
                                           -1, VariableType.Variable);
                casts.Add(new InstructionCast(
                              castedB, operands.B, operands.Function, operands.ByteCode, operands.Label
                              ));

                operands.B = castedB;
            }

            return(new OperatorResult(new BinaryArithmeticInstruction(operatorType,
                                                                      null, operands.A, operands.B, operands.Function, operands.ByteCode, operands.Label), operands.A.Type, casts));
        }
示例#2
0
        private static OperatorResult UnaryOperatorFunc(OperatorOperands operands, UnaryArithmeticInstructionType operatorType)
        {
            if (operands.A.Type.ID != TypeID.Float && operands.A.Type.ID != TypeID.Integer && operands.A.Type.ID != TypeID.UInteger)
            {
                return(new OperatorResult(new CompileError(CompileErrorType.ExpectedNumericOperands, operands.A.Token)));
            }

            return(new OperatorResult(new UnaryArithmeticInstruction(operatorType, null, operands.A, operands.Function, operands.ByteCode, operands.Label), operands.A.Type, null));
        }
示例#3
0
        private static OperatorResult OperatorFunc(OperatorOperands operands, BinaryArithmeticInstructionType operatorType)
        {
            CompileError error = null;
            Type         type;

            if ((error = operands.CheckNumericAndGetType(out type)) != null)
            {
                return(new OperatorResult(error));
            }

            var casts = new List <InstructionCast>();

            if (operands.A.Type != type)
            {
                var castedA = new Variable(type, "__castedReg", operands.Function.Scope, operands.A.Token,
                                           -1, VariableType.Variable);
                casts.Add(new InstructionCast(
                              castedA, operands.A, operands.Function, operands.ByteCode, operands.Label
                              ));

                operands.A = castedA;
            }

            if (operands.B.Type != type)
            {
                var castedB = new Variable(type, "__castedReg", operands.Function.Scope, operands.B.Token,
                                           -1, VariableType.Variable);
                casts.Add(new InstructionCast(
                              castedB, operands.B, operands.Function, operands.ByteCode, operands.Label
                              ));

                operands.B = castedB;
            }

            return(new OperatorResult(new BinaryArithmeticInstruction(operatorType,
                                                                      null, operands.A, operands.B, operands.Function, operands.ByteCode, operands.Label), type, casts));
        }