示例#1
0
    def apply_renaming(self, s_out, renaming):
        if hasattr(s_out, 'is_type_of'):
            renamed_is_type_of = []
            for v in s_out.is_type_of:
                renamed_is_type_of += renaming[v]
            assert s_out.knowntype is type
            newcell = typeof(renamed_is_type_of)
            if s_out.is_constant():
                newcell.const = s_out.const
            s_out = newcell

        if hasattr(s_out, 'knowntypedata'):
            renamed_knowntypedata = {}
            for value, constraints in s_out.knowntypedata.items():
                renamed_knowntypedata[value] = {}
                for v, s in constraints.items():
                    new_vs = renaming.get(v, [])
                    for new_v in new_vs:
                        renamed_knowntypedata[value][new_v] = s
            assert isinstance(s_out, annmodel.SomeBool)
            newcell = annmodel.SomeBool()
            if s_out.is_constant():
                newcell.const = s_out.const
            s_out = newcell
            s_out.set_knowntypedata(renamed_knowntypedata)
        return s_out
示例#2
0
def test_runtime_type_info():
    S = lltype.GcStruct('s', ('x', lltype.Signed), rtti=True)

    def ll_example(p):
        return (lltype.runtime_type_info(p),
                lltype.runtime_type_info(p) == lltype.getRuntimeTypeInfo(S))

    assert ll_example(lltype.malloc(S)) == (lltype.getRuntimeTypeInfo(S), True)
    s, t = ll_rtype(ll_example, [SomePtr(lltype.Ptr(S))])
    assert s == annmodel.SomeTuple(
        [SomePtr(lltype.Ptr(lltype.RuntimeTypeInfo)),
         annmodel.SomeBool()])
示例#3
0
def test_subclassof():
    I = Instance("test", ROOT, {'a': Signed})
    I1 = Instance("test1", I)

    def oof():
        i = new(I)
        i1 = new(I1)
        return subclassof(classof(i1), classof(i))

    a = RPythonAnnotator()
    s = a.build_types(oof, [])
    #a.translator.view()

    assert s == annmodel.SomeBool()
示例#4
0
 def compute_result_annotation(self, s_x):
     from rpython.annotator import model as annmodel
     return annmodel.SomeBool()
示例#5
0
 def compute_result_annotation(self, s_arg):
     from rpython.annotator import model
     r = model.SomeBool()
     r.const = s_arg.is_constant()
     return r
示例#6
0
文件: jit_hooks.py 项目: xen0n/pypy
@register_helper(SomePtr(llmemory.GCREF))
def box_clone(llbox):
    return _cast_to_gcref(_cast_to_box(llbox).clonebox())


@register_helper(SomePtr(llmemory.GCREF))
def box_constbox(llbox):
    return _cast_to_gcref(_cast_to_box(llbox).constbox())


@register_helper(SomePtr(llmemory.GCREF))
def box_nonconstbox(llbox):
    return _cast_to_gcref(_cast_to_box(llbox).nonconstbox())


@register_helper(annmodel.SomeBool())
def box_isconst(llbox):
    from rpython.jit.metainterp.history import Const
    return isinstance(_cast_to_box(llbox), Const)


@register_helper(annmodel.SomeBool())
def box_isint(llbox):
    from rpython.jit.metainterp.history import INT
    return _cast_to_box(llbox).type == INT


# ------------------------- stats interface ---------------------------


@register_helper(annmodel.SomeBool())
示例#7
0
def bool():
    return model.SomeBool()
示例#8
0
    def follow_link(self, graph, link, knowntypedata):
        in_except_block = False
        v_last_exc_type = link.last_exception  # may be None for non-exception link
        v_last_exc_value = link.last_exc_value  # may be None for non-exception link

        if (isinstance(link.exitcase, (types.ClassType, type))
                and issubclass(link.exitcase, BaseException)):
            assert v_last_exc_type and v_last_exc_value
            s_last_exc_value = self.bookkeeper.valueoftype(link.exitcase)
            s_last_exc_type = annmodel.SomeType()
            if isinstance(v_last_exc_type, Constant):
                s_last_exc_type.const = v_last_exc_type.value
            s_last_exc_type.is_type_of = [v_last_exc_value]

            if isinstance(v_last_exc_type, Variable):
                self.setbinding(v_last_exc_type, s_last_exc_type)
            if isinstance(v_last_exc_value, Variable):
                self.setbinding(v_last_exc_value, s_last_exc_value)

            s_last_exc_type = annmodel.SomeType()
            if isinstance(v_last_exc_type, Constant):
                s_last_exc_type.const = v_last_exc_type.value
            last_exc_value_vars = []
            in_except_block = True

        ignore_link = False
        inputs_s = []
        renaming = {}
        for v_out, v_input in zip(link.args, link.target.inputargs):
            renaming.setdefault(v_out, []).append(v_input)
        for v_out, v_input in zip(link.args, link.target.inputargs):
            if v_out == v_last_exc_type:
                assert in_except_block
                inputs_s.append(s_last_exc_type)
            elif v_out == v_last_exc_value:
                assert in_except_block
                inputs_s.append(s_last_exc_value)
                last_exc_value_vars.append(v_input)
            else:
                s_out = self.annotation(v_out)
                if (link.exitcase, v_out) in knowntypedata:
                    knownvarvalue = knowntypedata[(link.exitcase, v_out)]
                    s_out = pair(s_out, knownvarvalue).improve()
                    # ignore links that try to pass impossible values
                    if s_out == annmodel.s_ImpossibleValue:
                        ignore_link = True

                if hasattr(s_out, 'is_type_of'):
                    renamed_is_type_of = []
                    for v in s_out.is_type_of:
                        new_vs = renaming.get(v, [])
                        renamed_is_type_of += new_vs
                    assert s_out.knowntype is type
                    newcell = annmodel.SomeType()
                    if s_out.is_constant():
                        newcell.const = s_out.const
                    s_out = newcell
                    s_out.is_type_of = renamed_is_type_of

                if hasattr(s_out, 'knowntypedata'):
                    renamed_knowntypedata = {}
                    for (value, v), s in s_out.knowntypedata.items():
                        new_vs = renaming.get(v, [])
                        for new_v in new_vs:
                            renamed_knowntypedata[value, new_v] = s
                    assert isinstance(s_out, annmodel.SomeBool)
                    newcell = annmodel.SomeBool()
                    if s_out.is_constant():
                        newcell.const = s_out.const
                    s_out = newcell
                    s_out.set_knowntypedata(renamed_knowntypedata)

                inputs_s.append(s_out)
        if ignore_link:
            return

        if in_except_block:
            s_last_exc_type.is_type_of = last_exc_value_vars
        self.links_followed[link] = True
        self.addpendingblock(graph, link.target, inputs_s)