Esempio n. 1
0
 def compute_result_annotation(self, obj_s, base_s):
     assert isinstance(
         obj_s,
         (annmodel.SomeInteger, annmodel.SomeChar, annmodel.SomeFloat,
          annmodel.SomeOOInstance, annmodel.SomeString))
     assert isinstance(base_s, annmodel.SomeInteger)
     return annmodel.SomeOOInstance(ootype.String)
Esempio n. 2
0
def test_string():
    def oof():
        return new(String)

    a = RPythonAnnotator()
    s = a.build_types(oof, [])
    assert s == annmodel.SomeOOInstance(String)
Esempio n. 3
0
 def compute_result_annotation(self, s_PTR, s_object):
     assert s_PTR.is_constant()
     if isinstance(s_PTR.const, lltype.Ptr):
         return annmodel.SomePtr(s_PTR.const)
     elif isinstance(s_PTR.const, ootype.Instance):
         return annmodel.SomeOOInstance(s_PTR.const)
     else:
         assert False
Esempio n. 4
0
def test_simple_null():
    I = Instance("test", ROOT, {'a': Signed})

    def oof():
        i = null(I)
        return i

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

    assert s == annmodel.SomeOOInstance(I)
Esempio n. 5
0
def test_list():
    L = List(Signed)
    def oof():
        l = new(L)
        l._ll_resize(42)
        return l

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

    assert s == annmodel.SomeOOInstance(L)
Esempio n. 6
0
def test_simple_runtimenew():
    I = Instance("test", ROOT, {'a': Signed})

    def oof():
        i = new(I)
        c = classof(i)
        i2 = runtimenew(c)
        return i2

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

    assert s == annmodel.SomeOOInstance(I)
Esempio n. 7
0
def test_unionof():
    C1 = Instance("C1", ROOT)
    C2 = Instance("C2", C1)
    C3 = Instance("C3", C1)

    def oof(f):
        if f:
            c = new(C2)
        else:
            c = new(C3)
        return c

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

    assert s == annmodel.SomeOOInstance(C1)
Esempio n. 8
0
def test_complex_runtimenew():
    I = Instance("test", ROOT, {'a': Signed})
    J = Instance("test2", I, {'b': Signed})
    K = Instance("test2", I, {'b': Signed})

    def oof(x):
        k = new(K)
        j = new(J)
        if x:
            c = classof(k)
        else:
            c = classof(j)
        i = runtimenew(c)
        return i

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

    assert s == annmodel.SomeOOInstance(I)
Esempio n. 9
0
    def replace_promote_virtualizable(self, rtyper, graphs):
        from pypy.annotation import model as annmodel
        from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
        graph = graphs[0]

        for block, op in graph.iterblockops():
            if op.opname == 'promote_virtualizable':
                v_inst_ll_type = op.args[0].concretetype
                break

        def mycall(vinst_ll):
            pass

        annhelper = MixLevelHelperAnnotator(rtyper)
        if self.type_system == 'lltype':
            s_vinst = annmodel.SomePtr(v_inst_ll_type)
        else:
            s_vinst = annmodel.SomeOOInstance(v_inst_ll_type)
        funcptr = annhelper.delayedfunction(mycall, [s_vinst], annmodel.s_None)
        annhelper.finish()
        replace_promote_virtualizable_with_call(graphs, v_inst_ll_type,
                                                funcptr)
        return funcptr
Esempio n. 10
0
 def compute_annotation(self):
     return annmodel.SomeOOInstance(ootype=ootype.String)
Esempio n. 11
0
 def compute_result_annotation(self, obj_s, base_s):
     assert isinstance(obj_s, annmodel.SomeUnicodeCodePoint) or \
            (isinstance(obj_s, annmodel.SomeOOInstance)
             and obj_s.ootype in (ootype.String, ootype.Unicode))
     assert isinstance(base_s, annmodel.SomeInteger)
     return annmodel.SomeOOInstance(ootype.Unicode)
Esempio n. 12
0
 def make_type_of_exc_inst(self, rtyper):
     # ll_type_of_exc_inst(exception_instance) -> exception_vtable
     s_excinst = annmodel.SomeOOInstance(self.lltype_of_exception_value)
     helper_fn = rtyper.annotate_helper_fn(rclass.ll_inst_type, [s_excinst])
     return helper_fn
Esempio n. 13
0
 def make_exception_matcher(self, rtyper):
     # ll_exception_matcher(real_exception_meta, match_exception_meta)
     s_classtype = annmodel.SomeOOInstance(self.lltype_of_exception_type)
     helper_fn = rtyper.annotate_helper_fn(rclass.ll_issubclass,
                                           [s_classtype, s_classtype])
     return helper_fn
Esempio n. 14
0
 def annotate_struct(self, S):
     return annmodel.SomeOOInstance(S)