def fn(n): if n: cls2 = ootype.runtimeClass(A) else: cls2 = ootype.runtimeClass(B) assert (cls1 == cls2) == (not (cls1 != cls2)) return cls1 == cls2
def setup_meta_instance(self, meta_instance, rsubcls): if self.classdef is None: rinstance = getinstancerepr(self.rtyper, rsubcls.classdef) meta_instance.class_ = ootype.runtimeClass(rinstance.lowleveltype) else: # setup class attributes: for each attribute name at the level # of 'self', look up its value in the subclass rsubcls def assign(mangled_name, value): if isinstance(value, flowmodel.Constant) and isinstance( value.value, staticmethod): value = flowmodel.Constant(value.value.__get__( 42)) # staticmethod => bare function llvalue = r.convert_desc_or_const(value) setattr(meta_instance, mangled_name, llvalue) # extra PBC attributes for (access_set, attr), (mangled_name, r) in self.pbcfields.items(): if rsubcls.classdef.classdesc not in access_set.descs: continue # only for the classes in the same pbc access set if r.lowleveltype is ootype.Void: continue attrvalue = rsubcls.classdef.classdesc.read_attribute( attr, None) if attrvalue is not None: assign(mangled_name, attrvalue) # then initialize the 'super' portion of the vtable self.rbase.setup_meta_instance(meta_instance, rsubcls)
def setup_meta_instance(self, meta_instance, rsubcls): if self.classdef is None: rinstance = getinstancerepr(self.rtyper, rsubcls.classdef) meta_instance.class_ = ootype.runtimeClass(rinstance.lowleveltype) else: # setup class attributes: for each attribute name at the level # of 'self', look up its value in the subclass rsubcls def assign(mangled_name, value): if isinstance(value, flowmodel.Constant) and isinstance(value.value, staticmethod): value = flowmodel.Constant(value.value.__get__(42)) # staticmethod => bare function llvalue = r.convert_desc_or_const(value) setattr(meta_instance, mangled_name, llvalue) # extra PBC attributes for (access_set, attr), (mangled_name, r) in self.pbcfields.items(): if rsubcls.classdef.classdesc not in access_set.descs: continue # only for the classes in the same pbc access set if r.lowleveltype is ootype.Void: continue attrvalue = rsubcls.classdef.classdesc.read_attribute(attr, None) if attrvalue is not None: assign(mangled_name, attrvalue) # then initialize the 'super' portion of the vtable self.rbase.setup_meta_instance(meta_instance, rsubcls)
def getruntime(self, expected_type): if expected_type == ootype.Class: rinstance = getinstancerepr(self.rtyper, self.classdef) return ootype.runtimeClass(rinstance.lowleveltype) else: assert ootype.isSubclass(expected_type, META) meta = self.get_meta_instance(cast_to_root_meta=False) return ootype.ooupcast(expected_type, meta)
def classof(cliClass_or_type): if isinstance(cliClass_or_type, ootype.StaticMethod): try: FUNC = cliClass_or_type return known_delegates_class[FUNC] except KeyError: cls = ootype._class(ootype.ROOT) cls._FUNC = FUNC known_delegates_class[FUNC] = cls return cls else: assert isinstance(cliClass_or_type, CliClass) TYPE = cliClass_or_type._INSTANCE return ootype.runtimeClass(TYPE)
def test_compare_classes(): A = ootype.Instance("A", ootype.ROOT) B = ootype.Instance("B", ootype.ROOT) cls1 = ootype.runtimeClass(A) def fn(n): if n: cls2 = ootype.runtimeClass(A) else: cls2 = ootype.runtimeClass(B) assert (cls1 == cls2) == (not (cls1 != cls2)) return cls1 == cls2 res = interpret(fn, [1], type_system='ootype') assert res
def __init__(self, SELFTYPE, methname): from rpython.jit.backend.llgraph.runner import boxresult, make_getargs _, meth = SELFTYPE._lookup(methname) METH = ootype.typeOf(meth) getargs = make_getargs(METH.ARGS) def callmeth(selfbox, argboxes): selfobj = selfbox.getref(SELFTYPE) meth = getattr(selfobj, methname) methargs = getargs(argboxes) res = meth(*methargs) if METH.RESULT is not ootype.Void: return boxresult(METH.RESULT, res) self.callmeth = callmeth self.selfclass = ootype.runtimeClass(SELFTYPE) self.methname = methname self.has_result = (METH.RESULT != ootype.Void) self.key = key_manager.getkey((SELFTYPE, methname))
def get_class_for_type(T): if T is ootype.Void: return ootype.nullruntimeclass elif T is ootype.Signed: return dotnet.classof(System.Int32) elif T is ootype.Unsigned: return dotnet.classof(System.UInt32) elif T is ootype.Bool: return dotnet.classof(System.Boolean) elif T is ootype.Float: return dotnet.classof(System.Double) ## elif T is ootype.String: ## return dotnet.classof(System.String) elif T in (ootype.Char, ootype.UniChar): return dotnet.classof(System.Char) elif isinstance(T, ootype.OOType): return ootype.runtimeClass(T) else: assert False
def __init__(self, TYPE, fieldname): DescrWithKey.__init__(self, (TYPE, fieldname)) from rpython.jit.backend.llgraph.runner import boxresult from rpython.jit.metainterp.warmstate import unwrap _, T = TYPE._lookup_field(fieldname) def getfield(objbox): obj = objbox.getref(TYPE) value = getattr(obj, fieldname) return boxresult(T, value) def setfield(objbox, valuebox): obj = objbox.getref(TYPE) value = unwrap(T, valuebox) setattr(obj, fieldname, value) self.getfield = getfield self.setfield = setfield self.selfclass = ootype.runtimeClass(TYPE) self.fieldname = fieldname self.key = key_manager.getkey((TYPE, fieldname)) self._is_pointer_field = (history.getkind(T) == 'ref') self._is_float_field = (history.getkind(T) == 'float')