예제 #1
0
 def arithmetic_binary_op(self, op, left, right):
     if op == "ADD":
         return ClassicalAdd(left, right)
     elif op == "SUB":
         return ClassicalSub(left, right)
     elif op == "MUL":
         return ClassicalMul(left, right)
     elif op == "DIV":
         return ClassicalDiv(left, right)
예제 #2
0
파일: gates.py 프로젝트: timasq/pyquil
def SUB(classical_reg, right):
    """
    Produce a SUB instruction.

    :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target.
    :param right: Right operand for the arithmetic operation.
    :return: A ClassicalSub instance.
    """
    left, right = unpack_reg_val_pair(classical_reg, right)
    return ClassicalSub(left, right)
예제 #3
0
def SUB(classical_reg: MemoryReferenceDesignator,
        right: Union[MemoryReferenceDesignator, int, float]) -> ClassicalSub:
    """
    Produce a SUB instruction.

    :param classical_reg: Left operand for the arithmetic operation. Also serves as the store target.
    :param right: Right operand for the arithmetic operation.
    :return: A ClassicalSub instance.
    """
    left, right = unpack_reg_val_pair(classical_reg, right)
    return ClassicalSub(left, right)
예제 #4
0
    def exitArithmeticBinaryOp(self, ctx):
        # type : (QuilParser.ArithmeticBinaryOpContext) -> None
        left = _addr(ctx.addr(0))
        if ctx.number():
            right = _number(ctx.number())
        else:
            right = _addr(ctx.addr(1))

        if ctx.ADD():
            self.result.append(ClassicalAdd(left, right))
        elif ctx.SUB():
            self.result.append(ClassicalSub(left, right))
        elif ctx.MUL():
            self.result.append(ClassicalMul(left, right))
        elif ctx.DIV():
            self.result.append(ClassicalDiv(left, right))