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, 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_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_force_virtualizable(self, rtyper, graphs): from rpython.annotator import model as annmodel from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator graph = graphs[0] for block, op in graph.iterblockops(): if op.opname == 'jit_force_virtualizable': v_inst_ll_type = op.args[0].concretetype break def mycall(vinst_ll): if vinst_ll.vable_token: raise ValueError 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_force_virtualizable_with_call(graphs, v_inst_ll_type, funcptr) return funcptr
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 compute_annotation(self): return annmodel.SomeOOInstance(ootype=ootype.typeOf(self.instance))
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)