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)
def ADD(classical_reg, right): """ Produce an ADD 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 ClassicalAdd instance. """ left, right = unpack_reg_val_pair(classical_reg, right) return ClassicalAdd(left, right)
def ADD(classical_reg: MemoryReferenceDesignator, right: Union[MemoryReferenceDesignator, int, float]) -> ClassicalAdd: """ Produce an ADD 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 ClassicalAdd instance. """ left, right = unpack_reg_val_pair(classical_reg, right) return ClassicalAdd(left, right)
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))