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)
def test_string(): def oof(): return new(String) a = RPythonAnnotator() s = a.build_types(oof, []) assert s == annmodel.SomeOOInstance(String)
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
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)
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)
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)
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)
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)
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
def compute_annotation(self): return annmodel.SomeOOInstance(ootype=ootype.String)
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)
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
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
def annotate_struct(self, S): return annmodel.SomeOOInstance(S)