def _key_for_types(self, TYPES): counts = {} for EXACT_TYPE in TYPES: if EXACT_TYPE is lltype.Void: continue ERASED_TYPE = storage_type(EXACT_TYPE) counts[ERASED_TYPE] = counts.get(ERASED_TYPE, 0) + 1 key = lltype.frozendict(counts) return key
def _make_resume_handling(self, FRAME_TYPE, sorted_vars, v_retval, links_to_resumption): resume_substate = len(self.resume_blocks) erased_types = [] for v in sorted_vars: if v.concretetype != lltype.Void: erased_types.append(storage_type(v.concretetype)) retval_type = v_retval.concretetype erased_retval_type = storage_type(retval_type) retrieve_block, output_args = self._get_resume_retrieval_block(FRAME_TYPE, erased_types) return_block, switch_block = self._get_resume_return_block( erased_types, erased_retval_type, links_to_resumption[1:], sorted_vars) link = model.Link(output_args, return_block, resume_substate) link.llexitcase = link.exitcase retrieve_block.recloseblock(*(tuple(retrieve_block.exits) + (link,))) if erased_retval_type != lltype.Void: erased_types.append(erased_retval_type) cast_block, cast_args = self._get_resume_cast_block( erased_types, [v.concretetype for v in sorted_vars] + [retval_type]) link = model.Link(switch_block.inputargs, cast_block, resume_substate) link.llexitcase = resume_substate switch_block.recloseblock(*(tuple(switch_block.exits) + (link,))) varmap = dict([(v, cast_args[sorted_vars.index(v)]) for v in sorted_vars]) for k, v in varmap.items(): assert k.concretetype == v.concretetype varmap[v_retval] = cast_args[-1] link = copy_link_with_varmap(links_to_resumption[0], varmap) link.exitcase = link.llexitcase = resume_substate cast_block.recloseblock(*(tuple(cast_block.exits) + (link,))) self.resume_blocks.append(retrieve_block)
def op_adr_call(self, TGT, f, *inargs): checkadr(f) obj = self.llinterpreter.typer.type_system.deref(f.ref()) assert hasattr(obj, 'graph') # don't want to think about that graph = obj.graph args = [] for inarg, arg in zip(inargs, obj.graph.startblock.inputargs): args.append(lltype._cast_whatever(arg.concretetype, inarg)) frame = self.__class__(graph, args, self.llinterpreter, self) result = frame.eval() from pypy.translator.stackless.frame import storage_type assert storage_type(lltype.typeOf(result)) == TGT return lltype._cast_whatever(TGT, result)
def op_adr_call(self, TGT, f, *inargs): checkadr(f) obj = self.llinterpreter.typer.type_system.deref(f.ref()) assert hasattr(obj, 'graph') # don't want to think about that graph = obj.graph args = [] for inarg, arg in zip(inargs, obj.graph.startblock.inputargs): args.append(lltype._cast_whatever(arg.concretetype, inarg)) frame = self.__class__(graph, args, self.llinterpreter) result = frame.eval() from pypy.translator.stackless.frame import storage_type assert storage_type(lltype.typeOf(result)) == TGT return lltype._cast_whatever(TGT, result)
def _generate_save_block(self, varsforcall, v_unwind_exception, saver): conc_types = tuple([v.concretetype for v in varsforcall]) if conc_types in self.curr_graph_save_blocks: return self.curr_graph_save_blocks[conc_types] rtyper = self.translator.rtyper edata = rtyper.getexceptiondata() etype = edata.lltype_of_exception_type evalue = edata.lltype_of_exception_value inputargs = [copyvar(v) for v in varsforcall] v_unwind_exception = copyvar(v_unwind_exception) save_state_block = model.Block(inputargs + [v_unwind_exception]) saveops = LowLevelOpList() v_exc = gen_cast(saveops, self.unwind_exception_type, v_unwind_exception) realvarsforcall = [v_exc] for v in inputargs: realvarsforcall.append(gen_cast(saveops, storage_type(v.concretetype), v)) saveops.genop('direct_call', [model.Constant(saver, lltype.typeOf(saver))] + realvarsforcall, resulttype=lltype.Void) save_state_block.operations = saveops type_repr = rclass.get_type_repr(rtyper) c_unwindexception = model.Constant( type_repr.convert_const(code.UnwindException), etype) if not hasattr(self.curr_graph.exceptblock.inputargs[0], 'concretetype'): self.curr_graph.exceptblock.inputargs[0].concretetype = etype if not hasattr(self.curr_graph.exceptblock.inputargs[1], 'concretetype'): self.curr_graph.exceptblock.inputargs[1].concretetype = evalue save_state_block.closeblock(model.Link( [c_unwindexception, v_unwind_exception], self.curr_graph.exceptblock)) self.translator.rtyper._convert_link( save_state_block, save_state_block.exits[0]) if SAVE_STATISTICS: self.stats.saveops += len(save_state_block.operations) self.curr_graph_save_blocks[conc_types] = save_state_block return save_state_block
def key(v): return STORAGE_TYPES.index(storage_type(v.concretetype))