예제 #1
0
    def binary_op(self, lreg: Value, rreg: Value, expr_op: str,
                  line: int) -> Value:
        # special case tuple comparison here so that nested tuples can be supported
        if (isinstance(lreg.type, RTuple) and isinstance(rreg.type, RTuple)
                and expr_op in ('==', '!=')):
            return self.compare_tuples(lreg, rreg, expr_op, line)
        # Special case == and != when we can resolve the method call statically.
        value = None
        if expr_op in ('==', '!='):
            value = self.translate_eq_cmp(lreg, rreg, expr_op, line)
        if value is not None:
            return value

        # Special case 'is' and 'is not'
        if expr_op in ('is', 'is not'):
            return self.translate_is_op(lreg, rreg, expr_op, line)

        if (is_str_rprimitive(lreg.type) and is_str_rprimitive(rreg.type)
                and expr_op in ('==', '!=')):
            return self.compare_strings(lreg, rreg, expr_op, line)

        if is_tagged(lreg.type) and is_tagged(
                rreg.type) and expr_op in int_comparison_op_mapping:
            return self.compare_tagged(lreg, rreg, expr_op, line)

        call_c_ops_candidates = c_binary_ops.get(expr_op, [])
        target = self.matching_call_c(call_c_ops_candidates, [lreg, rreg],
                                      line)
        assert target, 'Unsupported binary operation: %s' % expr_op
        return target
예제 #2
0
    def binary_op(self,
                  lreg: Value,
                  rreg: Value,
                  expr_op: str,
                  line: int) -> Value:
        # Special case == and != when we can resolve the method call statically.
        value = None
        if expr_op in ('==', '!='):
            value = self.translate_eq_cmp(lreg, rreg, expr_op, line)
        if value is not None:
            return value

        # generate fast binary logic ops on short ints
        if (is_short_int_rprimitive(lreg.type) and is_short_int_rprimitive(rreg.type)
                and expr_op in int_logical_op_mapping.keys()):
            return self.binary_int_op(bool_rprimitive, lreg, rreg,
                                      int_logical_op_mapping[expr_op][0], line)

        call_c_ops_candidates = c_binary_ops.get(expr_op, [])
        target = self.matching_call_c(call_c_ops_candidates, [lreg, rreg], line)
        if target:
            return target
        ops = binary_ops.get(expr_op, [])
        target = self.matching_primitive_op(ops, [lreg, rreg], line)
        assert target, 'Unsupported binary operation: %s' % expr_op
        return target
예제 #3
0
파일: ll_builder.py 프로젝트: jmetz/mypy
    def binary_op(self, lreg: Value, rreg: Value, expr_op: str,
                  line: int) -> Value:
        # Special case == and != when we can resolve the method call statically.
        value = None
        if expr_op in ('==', '!='):
            value = self.translate_eq_cmp(lreg, rreg, expr_op, line)
        if value is not None:
            return value

        call_c_ops_candidates = c_binary_ops.get(expr_op, [])
        target = self.matching_call_c(call_c_ops_candidates, [lreg, rreg],
                                      line)
        if target:
            return target
        ops = binary_ops.get(expr_op, [])
        target = self.matching_primitive_op(ops, [lreg, rreg], line)
        assert target, 'Unsupported binary operation: %s' % expr_op
        return target