예제 #1
0
파일: parser.py 프로젝트: mazispider/pyquil
 def logical_binary_op(self, op, left, right):
     if op == "AND":
         return ClassicalAnd(left, right)
     elif op == "OR":
         return ClassicalOr(left, right)
     elif op == "IOR":
         return ClassicalInclusiveOr(left, right)
     elif op == "XOR":
         return ClassicalExclusiveOr(left, right)
예제 #2
0
 def exitClassicalBinary(self, ctx):
     # type: (QuilParser.ClassicalBinaryContext) -> None
     if ctx.AND():
         self.result.append(ClassicalAnd(_addr(ctx.addr(0)), _addr(ctx.addr(1))))
     elif ctx.OR():
         self.result.append(ClassicalOr(_addr(ctx.addr(0)), _addr(ctx.addr(1))))
     elif ctx.MOVE():
         self.result.append(ClassicalMove(_addr(ctx.addr(0)), _addr(ctx.addr(1))))
     elif ctx.EXCHANGE():
         self.result.append(ClassicalExchange(_addr(ctx.addr(0)), _addr(ctx.addr(1))))
예제 #3
0
def OR(classical_reg1, classical_reg2):
    """
    Produce an OR instruction.

    :param classical_reg1: The first classical register.
    :param classical_reg2: The second classical register, which gets modified.
    :return: A ClassicalOr instance.
    """
    left = unpack_classical_reg(classical_reg1)
    right = unpack_classical_reg(classical_reg2)
    return ClassicalOr(left, right)
예제 #4
0
    def exitLogicalBinaryOp(self, ctx):
        # type: (QuilParser.LogicalBinaryOpContext) -> None
        left = _addr(ctx.addr(0))
        if ctx.INT():
            right = int(ctx.INT().getText())
        else:
            right = _addr(ctx.addr(1))

        if ctx.AND():
            self.result.append(ClassicalAnd(left, right))
        elif ctx.OR():
            self.result.append(ClassicalOr(left, right))
        elif ctx.IOR():
            self.result.append(ClassicalInclusiveOr(left, right))
        elif ctx.XOR():
            self.result.append(ClassicalExclusiveOr(left, right))
예제 #5
0
    def exitLogicalBinaryOp(self, ctx):
        # type: (QuilParser.LogicalBinaryOpContext) -> None
        left = _addr(ctx.addr(0))
        right: Union[int, MemoryReference]
        if ctx.INT():
            right = int(ctx.INT().getText())
        else:
            right = _addr(ctx.addr(1))

        if ctx.AND():
            self.result.append(ClassicalAnd(left, right))
        elif ctx.OR():
            if isinstance(right, MemoryReference):
                self.result.append(ClassicalOr(left, right))
            else:
                raise RuntimeError(
                    "Right operand of deprecated OR instruction must be a"
                    f" MemoryReference, but found '{right}'")
        elif ctx.IOR():
            self.result.append(ClassicalInclusiveOr(left, right))
        elif ctx.XOR():
            self.result.append(ClassicalExclusiveOr(left, right))