Exemplo n.º 1
0
 public CompoundAssignmentInstruction(OpCode opCode, CompoundAssignmentType compoundAssignmentType, ILInstruction target, ILInstruction value)
     : base(opCode)
 {
     this.CompoundAssignmentType = compoundAssignmentType;
     this.Target = target;
     this.Value  = value;
 }
Exemplo n.º 2
0
        public bool IsLifted => false;         // TODO: implement lifted user-defined compound assignments

        public UserDefinedCompoundAssign(IMethod method, CompoundAssignmentType compoundAssignmentType, ILInstruction target, ILInstruction value)
            : base(OpCode.UserDefinedCompoundAssign, compoundAssignmentType, target, value)
        {
            this.Method = method;
            Debug.Assert(Method.IsOperator || IsStringConcat(method));
            Debug.Assert(compoundAssignmentType == CompoundAssignmentType.EvaluatesToNewValue || (Method.Name == "op_Increment" || Method.Name == "op_Decrement"));
            Debug.Assert(IsValidCompoundAssignmentTarget(Target));
        }
Exemplo n.º 3
0
 public CompoundAssignmentInstruction(BinaryNumericOperator op, ILInstruction target, ILInstruction value, IType type, bool checkForOverflow, Sign sign, CompoundAssignmentType compoundAssigmentType)
     : base(OpCode.CompoundAssignmentInstruction)
 {
     this.CheckForOverflow       = checkForOverflow;
     this.Sign                   = sign;
     this.Operator               = op;
     this.Target                 = target;
     this.type                   = type;
     this.Value                  = value;
     this.CompoundAssignmentType = compoundAssigmentType;
     Debug.Assert(compoundAssigmentType == CompoundAssignmentType.EvaluatesToNewValue || (op == BinaryNumericOperator.Add || op == BinaryNumericOperator.Sub));
     Debug.Assert(IsValidCompoundAssignmentTarget(Target));
 }
 public CompoundAssignmentInstruction(BinaryNumericInstruction binary, ILInstruction target, ILInstruction value, IType type, CompoundAssignmentType compoundAssignmentType)
     : base(OpCode.CompoundAssignmentInstruction)
 {
     Debug.Assert(IsBinaryCompatibleWithType(binary, type));
     this.CheckForOverflow       = binary.CheckForOverflow;
     this.Sign                   = binary.Sign;
     this.LeftInputType          = binary.LeftInputType;
     this.RightInputType         = binary.RightInputType;
     this.UnderlyingResultType   = binary.UnderlyingResultType;
     this.Operator               = binary.Operator;
     this.CompoundAssignmentType = compoundAssignmentType;
     this.IsLifted               = binary.IsLifted;
     this.Target                 = target;
     this.type                   = type;
     this.Value                  = value;
     this.ILRange                = binary.ILRange;
     Debug.Assert(compoundAssignmentType == CompoundAssignmentType.EvaluatesToNewValue || (Operator == BinaryNumericOperator.Add || Operator == BinaryNumericOperator.Sub));
     Debug.Assert(IsValidCompoundAssignmentTarget(Target));
 }
Exemplo n.º 5
0
        private AstNode CompoundAssignment(string identifier, CompoundAssignmentType type)
        {
            var variable = Variable(identifier);

            int line = 0;

            switch (type)
            {
            case CompoundAssignmentType.Add:
                Match(TokenType.CompoundAdd);
                break;

            case CompoundAssignmentType.Subtract:
                Match(TokenType.CompoundSubtract);
                break;

            case CompoundAssignmentType.Multiply:
                Match(TokenType.CompoundMultiply);
                break;

            case CompoundAssignmentType.Divide:
                Match(TokenType.CompoundDivide);
                break;

            case CompoundAssignmentType.Modulo:
                Match(TokenType.CompoundModulo);
                break;

            default:
                throw new ParserException("Unexpected compound assignment type enum value??");
            }

            var right = Comparison();

            return(new CompoundAssignmentNode(variable, right, type)
            {
                Line = line
            });
        }
        private DynValue HandleCompoundOperation(DynValue variable, DynValue operand, CompoundAssignmentType type)
        {
            switch (type)
            {
            case CompoundAssignmentType.Add:
                return(new DynValue(variable.Number + operand.Number));

            case CompoundAssignmentType.Subtract:
                return(new DynValue(variable.Number - operand.Number));

            case CompoundAssignmentType.Multiply:
                return(new DynValue(variable.Number * operand.Number));

            case CompoundAssignmentType.Divide:
                if (operand.Number == 0)
                {
                    throw new RuntimeException("Cannot divide by zero.", null);
                }

                return(new DynValue(variable.Number / operand.Number));

            case CompoundAssignmentType.Modulo:
                return(new DynValue(variable.Number % operand.Number));

            default:
                throw new RuntimeException("Unexpected compound assignment type??", null);
            }
        }
 public CompoundAssignmentNode(VariableNode variable, AstNode right, CompoundAssignmentType operation)
 {
     Variable  = variable;
     Right     = right;
     Operation = operation;
 }