def __init__(self, rtyper, methdescs): samplemdesc = iter(methdescs).next() concretetable, uniquerows = get_concrete_calltable(rtyper, samplemdesc.funcdesc.getcallfamily()) self.row_mapping = {} for row in uniquerows: sample_as_static_meth = row.itervalues().next() SM = ootype.typeOf(sample_as_static_meth) M = ootype.Meth(SM.ARGS[1:], SM.RESULT) # cut self self.row_mapping[row.attrname] = row, M
def attach_class_attr_accessor(self, mangled, oovalue): def ll_getclassattr(self): return oovalue M = ootype.Meth([], ootype.typeOf(oovalue)) ll_getclassattr = func_with_new_name(ll_getclassattr, 'll_get_' + mangled) graph = self.rtyper.annotate_helper(ll_getclassattr, [self.lowleveltype]) m = ootype.meth(M, _name=mangled, _callable=ll_getclassattr, graph=graph) ootype.addMethods(self.lowleveltype, {mangled: m})
def attach_class_attr_accessor(self, mangled, value, r_value): def ll_getclassattr(self): return oovalue M = ootype.Meth([], r_value.lowleveltype) if value is None: m = ootype.meth(M, _name=mangled, abstract=True) else: oovalue = r_value.convert_desc_or_const(value) ll_getclassattr = func_with_new_name(ll_getclassattr, 'll_get_' + mangled) graph = self.rtyper.annotate_helper(ll_getclassattr, [self.lowleveltype]) m = ootype.meth(M, _name=mangled, _callable=ll_getclassattr, graph=graph) ootype.addMethods(self.lowleveltype, {mangled: m})
def attach_abstract_class_attr_accessor(self, mangled, attrtype): M = ootype.Meth([], attrtype) m = ootype.meth(M, _name=mangled, abstract=True) ootype.addMethods(self.lowleveltype, {mangled: m})
return None this = op.args[1] if isinstance(this.concretetype, type_) and method_name in BUILTIN_METHODS[type_]: return method_name else: return None # explicit is better than implicit :-) def get_method(TYPE, name): try: # special case: when having List of Void, look at the concrete # methods, not the generic ones if isinstance(TYPE, ootype.List) and TYPE._ITEMTYPE is ootype.Void: return TYPE._METHODS[name] else: return TYPE._GENERIC_METHODS[name] except KeyError: t = type(TYPE) return BUILTIN_METHODS[t][name] BUILTIN_TYPES = {'list': ootype.List} BUILTIN_METHODS = { ootype.List: { 'Add': ootype.Meth([ootype.List.ITEMTYPE_T], ootype.Void) } }