Ejemplo n.º 1
0
def is_const_slice(typemap, func_ir, var, accept_stride=False):
    """ return True if var can be determined to be a constant size slice """
    require(typemap[var.name] == types.slice2_type
            or (accept_stride and typemap[var.name] == types.slice3_type))
    call_expr = get_definition(func_ir, var)
    require(isinstance(call_expr, ir.Expr) and call_expr.op == 'call')
    assert (len(call_expr.args) == 2
            or (accept_stride and len(call_expr.args) == 3))
    assert find_callname(func_ir, call_expr) == ('slice', 'builtins')
    arg0_def = get_definition(func_ir, call_expr.args[0])
    require(isinstance(arg0_def, ir.Const) and arg0_def.value is None)
    size_const = find_const(func_ir, call_expr.args[1])
    require(isinstance(size_const, int))
    return True
Ejemplo n.º 2
0
    def test_obj_func_match(self):
        """Test matching of an object method (other than Array see #3449)"""
        def test_func():
            d = Dummy([1])
            d.val.append(2)

        test_ir = compiler.run_frontend(test_func)
        typingctx = cpu_target.typing_context
        typemap, _, _ = type_inference_stage(typingctx, test_ir, (), None)
        matched_call = ir_utils.find_callname(test_ir,
                                              test_ir.blocks[0].body[8].value,
                                              typemap)
        self.assertTrue(
            isinstance(matched_call, tuple) and len(matched_call) == 2
            and matched_call[0] == "append")