def _interfere_acceptance(cls, snapshot_set_db, EntryRecipeDb, StateIndex): """If the acceptance scheme differs for only two recipes, then the acceptance must be determined upon entry and stored in the LastAcceptance register. RETURN: [0] Accumulated 'accepter' """ # Interference requires determined entry recipes. assert none_is_None(EntryRecipeDb.itervalues()) # Irrelevant E_R.AcceptanceRegister? Impossible! Acceptance is relevant # for all states! '.accepter is None' is not treated. accepter = UniformObject.from_iterable( recipe.accepter for recipe in EntryRecipeDb.itervalues()).plain_content() if accepter != E_Values.VOID: # Homogeneity pass else: # Inhomogeneity accepter = [ cls.RestoreAcceptance ] snapshot_set_db[E_R.AcceptanceRegister] = set([StateIndex]) assert accepter and accepter[-1].pre_context_id() == E_PreContextIDs.NONE return accepter
def _accumulate_input_pointer_storage(PrevRecipe, CurrSingleEntry): """Storing the current input position into a register overwrites previous storage operations. Previous storage operations that appear 'n' steps before can be compensated by 'input_p -= n'. Thus, at each step '-1' is added to the compensation offset. NOTE: Registers which do not appear in the 'ip_offset_db' are meant to be restored from registers. They cannot be computed by offset addition. """ assert none_is_None(PrevRecipe.ip_offset_db.itervalues()) def new_offset(PrevOffset): if PrevOffset is E_Values.RESTORE: return E_Values.RESTORE assert isinstance(PrevOffset, (int, long)), \ "Expected previous offset as number; found %s" % str(PrevOffset) return PrevOffset - 1 # Storage into a register overwrites previous storages # Previous storages receive '.offset - 1' ip_offset_db = dict( (register_id, new_offset(offset)) for register_id, offset in PrevRecipe.ip_offset_db.iteritems() ) # Storing the input position means, that the stored value differs # from the current value by '0'. ip_offset_db.update( (cmd.position_register_id(), 0) for cmd in CurrSingleEntry.get_iterable(SeStoreInputPosition) ) # Any acceptance that does not restore from a position register # defines the current position as the point where the input pointer # needs to be reset upon acceptance. ip_offset_db.update( (cmd.position_register_id(), 0) for cmd in CurrSingleEntry.get_iterable(SeAccept) if not cmd.restore_position_register_f() ) assert none_is_None(ip_offset_db.itervalues()) return ip_offset_db
def _accumulate_read_pointer_storage(PrevRecipe, CurrSingleEntry): """Storing the current input position into a register overwrites previous storage operations. Previous storage operations that appear 'n' steps before can be compensated by 'input_p -= n'. Thus, at each step '-1' is added to the compensation offset. NOTE: Registers which do not appear in the 'ip_offset_db' are meant to be restored from registers. They cannot be computed by offset addition. """ assert none_is_None(PrevRecipe.ip_offset_db.itervalues()) def new_offset(PrevOffset): if PrevOffset is E_Values.RESTORE: return E_Values.RESTORE assert isinstance(PrevOffset, (int, long)), \ "Expected previous offset as number; found %s" % str(PrevOffset) return PrevOffset - 1 # Storage into a register overwrites previous storages # Previous storages receive '.offset - 1' ip_offset_db = dict( (register_id, new_offset(offset)) for register_id, offset in PrevRecipe.ip_offset_db.iteritems() ) # Storing the input position means, that the stored value differs # from the current value by '0'. ip_offset_db.update( (cmd.position_register_id(), 0) for cmd in CurrSingleEntry.get_iterable(SeStoreInputPosition) ) # Any acceptance that does not restore from a position register # defines the current position as the point where the input pointer # needs to be reset upon acceptance. ip_offset_db.update( (cmd.position_register_id(), 0) for cmd in CurrSingleEntry.get_iterable(SeAccept) if not cmd.restore_position_register_f() ) assert none_is_None(ip_offset_db.itervalues()) return ip_offset_db
def _interfere_input_position_storage(cls, snapshot_set_db, EntryRecipeDb, RequiredVariableSet, StateIndex): """Each position register is considered separately. If for one register the offset differs, then it can only be determined from storing it in this mouth state and restoring it later. """ assert none_is_None( flatten_it_list_of_lists(recipe.ip_offset_db.itervalues() for recipe in EntryRecipeDb.itervalues())) ip_offset_db = {} for variable_id in RequiredVariableSet: if type(variable_id) != tuple: continue register_id = variable_id[1] # Irrelevant position register? Possible! A recipe that considers # a position register irrelevant is 'equal' to any other. Thus, it # can be filtered out. Irrelevant position register is not mentioned # in 'ip_offset_db' => 'offset = None'. offset_list = [ recipe.ip_offset_db.get(register_id) for recipe in EntryRecipeDb.itervalues() ] offset = UniformObject.from_iterable( x for x in offset_list if x is not None).plain_content() if offset != E_Values.VOID: # Homogeneity pass else: # Inhomogeneity offset = E_Values.RESTORE snapshot_set_db[variable_id] = set([StateIndex]) ip_offset_db[register_id] = offset assert none_is_None(ip_offset_db.itervalues()) return ip_offset_db
def _interfere_read_position_storage(cls, snapshot_set_db, EntryRecipeDb, RequiredVariableSet, StateIndex): """Each position register is considered separately. If for one register the offset differs, then it can only be determined from storing it in this mouth state and restoring it later. """ assert none_is_None( flatten_it_list_of_lists(recipe.ip_offset_db.itervalues() for recipe in EntryRecipeDb.itervalues())) ip_offset_db = {} for variable_id in RequiredVariableSet: if type(variable_id) != tuple: continue register_id = variable_id[1] # Irrelevant position register? Possible! A recipe that considers # a position register irrelevant is 'equal' to any other. Thus, it # can be filtered out. Irrelevant position register is not mentioned # in 'ip_offset_db' => 'offset = None'. offset_list = [ recipe.ip_offset_db.get(register_id) for recipe in EntryRecipeDb.itervalues() ] offset = UniformObject.from_iterable( x for x in offset_list if x is not None).plain_content() if offset != E_Values.VOID: # Homogeneity pass else: # Inhomogeneity offset = E_Values.RESTORE snapshot_set_db[variable_id] = set([StateIndex]) ip_offset_db[register_id] = offset assert none_is_None(ip_offset_db.itervalues()) return ip_offset_db
def do(code, TheState, TheAnalyzer): assert isinstance(TheState, AnalyzerState) assert isinstance(TheAnalyzer, Analyzer) # (*) Entry _______________________________________________________________ txt, post_txt = entry.do(TheState) # (*) Transition Map ______________________________________________________ tm = relate_to_TransitionCode(TheState.transition_map) transition_block.do(txt, tm) # (*) Post-state entry to init state (if necessary) txt.extend(post_txt) # (*) Consistency check ___________________________________________________ assert none_isinstance(txt, list) assert none_is_None(txt) code.extend(txt)