def convert_const(self, dictobj): if dictobj is None: return self.DICT._defl() if not isinstance(dictobj, dict) and not isinstance( dictobj, objectmodel.r_dict): raise TyperError("expected a dict: %r" % (dictobj, )) try: key = Constant(dictobj) return self.dict_cache[key] except KeyError: self.setup() l_dict = ll_newdict(self.DICT) if self.custom_eq_hash: interp = llinterp.LLInterpreter(self.rtyper) EQ_FUNC = ootype.StaticMethod( [self.DICT._KEYTYPE, self.DICT._KEYTYPE], ootype.Bool) sm_eq = self.__get_func(interp, self.r_rdict_eqfn, dictobj.key_eq, EQ_FUNC) HASH_FUNC = ootype.StaticMethod([self.DICT._KEYTYPE], ootype.Signed) sm_hash = self.__get_func(interp, self.r_rdict_hashfn, dictobj.key_hash, HASH_FUNC) l_dict.ll_set_functions(sm_eq, sm_hash) self.dict_cache[key] = l_dict r_key = self.key_repr r_value = self.value_repr if self.custom_eq_hash: for dictkeycont, dictvalue in dictobj._dict.items(): llkey = r_key.convert_const(dictkeycont.key) llvalue = r_value.convert_const(dictvalue) llhash = dictkeycont.hash l_dictkeycont = objectmodel._r_dictkey_with_hash( l_dict._dict, llkey, llhash) l_dict._dict._dict[l_dictkeycont] = llvalue else: for dictkey, dictvalue in dictobj.items(): llkey = r_key.convert_const(dictkey) llvalue = r_value.convert_const(dictvalue) l_dict.ll_set(llkey, llvalue) return l_dict
def convert_const(self, dictobj): if dictobj is None: return self.DICT._defl() if not isinstance(dictobj, dict) and not isinstance(dictobj, objectmodel.r_dict): raise TyperError("expected a dict: %r" % (dictobj,)) try: key = Constant(dictobj) return self.dict_cache[key] except KeyError: self.setup() l_dict = ll_newdict(self.DICT) if self.custom_eq_hash: interp = llinterp.LLInterpreter(self.rtyper) EQ_FUNC = ootype.StaticMethod([self.DICT._KEYTYPE, self.DICT._KEYTYPE], ootype.Bool) sm_eq = self.__get_func(interp, self.r_rdict_eqfn, dictobj.key_eq, EQ_FUNC) HASH_FUNC = ootype.StaticMethod([self.DICT._KEYTYPE], ootype.Signed) sm_hash = self.__get_func(interp, self.r_rdict_hashfn, dictobj.key_hash, HASH_FUNC) l_dict.ll_set_functions(sm_eq, sm_hash) self.dict_cache[key] = l_dict r_key = self.key_repr r_value = self.value_repr if self.custom_eq_hash: for dictkeycont, dictvalue in dictobj._dict.items(): llkey = r_key.convert_const(dictkeycont.key) llvalue = r_value.convert_const(dictvalue) llhash = dictkeycont.hash l_dictkeycont = objectmodel._r_dictkey_with_hash(l_dict._dict, llkey, llhash) l_dict._dict._dict[l_dictkeycont] = llvalue else: for dictkey, dictvalue in dictobj.items(): llkey = r_key.convert_const(dictkey) llvalue = r_value.convert_const(dictvalue) l_dict.ll_set(llkey, llvalue) return l_dict