def op_oonewcustomdict(self, DICT, eq_func, eq_obj, eq_method_name, hash_func, hash_obj, hash_method_name): eq_name, interp_eq = wrap_callable(self.llinterpreter, eq_func, eq_obj, eq_method_name) EQ_FUNC = ootype.StaticMethod([DICT._KEYTYPE, DICT._KEYTYPE], ootype.Bool) sm_eq = ootype.static_meth(EQ_FUNC, eq_name, _callable=interp_eq) hash_name, interp_hash = wrap_callable(self.llinterpreter, hash_func, hash_obj, hash_method_name) HASH_FUNC = ootype.StaticMethod([DICT._KEYTYPE], ootype.Signed) sm_hash = ootype.static_meth(HASH_FUNC, hash_name, _callable=interp_hash) # XXX: is it fine to have StaticMethod type for bound methods, too? return ootype.oonewcustomdict(DICT, sm_eq, sm_hash)
def __get_func(self, interp, r_func, fn, TYPE): if isinstance(r_func, MethodOfFrozenPBCRepr): obj = r_func.r_im_self.convert_const(fn.im_self) r_func, nimplicitarg = r_func.get_r_implfunc() else: obj = None callable = r_func.get_unique_llfn().value func_name, interp_fn = llinterp.wrap_callable(interp, callable, obj, None) return ootype.static_meth(TYPE, func_name, _callable=interp_fn)
def llhelper(F, f): """Gives a low-level function pointer of type F which, when called, invokes the RPython function f(). """ # Example - the following code can be either run or translated: # # def my_rpython_code(): # g = llhelper(F, my_other_rpython_function) # assert typeOf(g) == F # ... # g() # # however the following doesn't translate (xxx could be fixed with hacks): # # prebuilt_g = llhelper(F, f) # def my_rpython_code(): # prebuilt_g() # the next line is the implementation for the purpose of direct running if isinstance(F, ootype.OOType): return ootype.static_meth(F, f.func_name, _callable=f) else: return lltype.functionptr(F.TO, f.func_name, _callable=f)
def constant_func(self, name, inputtypes, rettype, graph, **kwds): FUNC_TYPE = ootype.StaticMethod(inputtypes, rettype) fn_ptr = ootype.static_meth(FUNC_TYPE, name, graph=graph, **kwds) return Constant(fn_ptr, FUNC_TYPE)