Exemplo n.º 1
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

        # 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_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)
        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
Exemplo n.º 2
0
def translate_str_format_percent_sign(builder: IRBuilder, format_expr: StrExpr,
                                      rhs: Expression) -> Value:
    tokens = tokenizer_printf_style(format_expr.value)
    if tokens is not None:
        literals, format_ops = tokens

        exprs = []
        if isinstance(rhs, TupleExpr):
            exprs = rhs.items
        elif isinstance(rhs, Expression):
            exprs.append(rhs)

        substitutions = convert_expr(builder, format_ops, exprs,
                                     format_expr.line)
        if substitutions is not None:
            return join_formatted_strings(builder, literals, substitutions,
                                          format_expr.line)

    call_c_ops_candidates = binary_ops.get('%', [])
    ret = builder.builder.matching_call_c(
        call_c_ops_candidates,
        [builder.accept(format_expr),
         builder.accept(rhs)], format_expr.line)
    assert ret is not None, 'Cannot use binary op % at line {}'.format(
        format_expr.line)
    return ret
Exemplo n.º 3
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

        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