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)); }
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)); }
public BinaryArithmeticInstruction(BinaryArithmeticInstructionType type, Variable res, Variable a, Variable b, Function func, ByteCode byteCode, int label) : base(res, func, byteCode, label) { AType = type; Operand1 = a; Operand2 = b; }