def add_state(self, StateIndex, OnSuccessDoorId, OnFailureDoorId, BeforeReload=None): """Adds a state from where the reload state is entered. When reload is done it jumps to 'OnFailureDoorId' if the reload failed and to 'OnSuccessDoorId' if the reload succeeded. RETURNS: DoorID into the reload state. Jump to this DoorID in order to trigger the reload for the state given by 'StateIndex'. """ assert BeforeReload is None or isinstance(BeforeReload, OpList) # Before reload: prepare after reload, the jump back to the reloading state. before_cl = OpList(Op.PrepareAfterReload(OnSuccessDoorId, OnFailureDoorId)) if BeforeReload is not None: # May be, add additional commands before_cl = before_cl.concatinate(BeforeReload) # No two transitions into the reload state have the same OpList! # No two transitions can have the same DoorID! # => it is safe to assign a new DoorID withouth .categorize() ta = TransitionAction(before_cl) # Assign a DoorID (without categorization) knowing that no such entry # into this state existed before. ta.door_id = dial_db.new_door_id(self.index) assert not self.entry.has_transition(self.index, StateIndex) # Cannot be in there twice! self.entry.enter(self.index, StateIndex, ta) return ta.door_id
def _prepare_entry_and_reentry(analyzer, OnBegin, OnStep): """Prepare the entry and re-entry doors into the initial state of the loop-implementing initial state. .----------. | on_entry | '----------' | .------------. |<--------| on_reentry |<-----. | '------------' | .----------------. | | +-----> Terminal ----+----> Exit | ... | | +-----> Terminal - - '----------------' RETURNS: DoorID of the re-entry door which is used to iterate in the loop. """ # Entry into state machine entry = analyzer.init_state().entry init_state_index = analyzer.init_state_index # OnEntry ta_on_entry = entry.get_action(init_state_index, E_StateIndices.BEFORE_ENTRY) ta_on_entry.command_list = OpList.concatinate(ta_on_entry.command_list, OnBegin) # OnReEntry tid_reentry = entry.enter_OpList(init_state_index, index.get(), OpList.from_iterable(OnStep)) entry.categorize(init_state_index) return entry.get(tid_reentry).door_id
def _prepare_entry_and_reentry(analyzer, OnBegin, OnStep): """Prepare the entry and re-entry doors into the initial state of the loop-implementing initial state. .----------. | on_entry | '----------' | .------------. |<--------| on_reentry |<-----. | '------------' | .----------------. | | +-----> Terminal ----+----> Exit | ... | | +-----> Terminal - - '----------------' RETURNS: DoorID of the re-entry door which is used to iterate in the loop. """ # Entry into state machine entry = analyzer.init_state().entry init_state_index = analyzer.init_state_index # OnEntry ta_on_entry = entry.get_action(init_state_index, E_StateIndices.BEFORE_ENTRY) ta_on_entry.command_list = OpList.concatinate(ta_on_entry.command_list, OnBegin) # OnReEntry tid_reentry = entry.enter_OpList(init_state_index, index.get(), OpList.from_iterable(OnStep)) entry.categorize(init_state_index) return entry.get(tid_reentry).door_id
def __init__(self, ColumnNPerCodeUnit, UserBeforeEntryOpList, UserOnLoopExitDoorId): # Counting Actions upon: loop entry/exit; before/after reload # on_loop_entry_count, \ on_loop_exit_count, \ on_before_reload_count, \ on_after_reload_count = self.__prepare_count_actions(ColumnNPerCodeUnit) # Input pointer positioning: loop entry/exit; before/after reload # on_loop_entry, \ on_loop_reentry_pos, \ on_loop_exit_pos = self.__prepare_positioning_at_loop_begin_and_exit(ColumnNPerCodeUnit) on_before_reload_pos, \ on_after_reload_pos = self.__prepare_positioning_before_and_after_reload() on_before_reload_pos_apx, \ on_after_reload_pos_apx = self.__prepare_positioning_before_and_after_reload(AppendixSmF=True) # _____________________________________________________________________ # if UserBeforeEntryOpList is None: UserBeforeEntryOpList = [] self.on_loop_entry = OpList.concatinate(on_loop_entry, on_loop_reentry_pos, on_loop_entry_count, UserBeforeEntryOpList) self.on_loop_reentry = OpList.from_iterable(on_loop_reentry_pos) self.on_loop_exit = OpList.concatinate( on_loop_exit_pos, on_loop_exit_count, [Op.GotoDoorId(UserOnLoopExitDoorId)]) self.on_before_reload = OpList.concatinate(on_before_reload_pos, on_before_reload_count) self.on_before_reload_in_appendix = OpList.from_iterable( on_before_reload_pos_apx) self.on_after_reload = OpList.concatinate(on_after_reload_pos, on_after_reload_count) self.on_after_reload_in_appendix = OpList.from_iterable( on_after_reload_pos_apx)
def __init__(self, ColumnNPerCodeUnit, LexemeEndCheckF, MaintainLexemeF, EngineType, ReloadStateExtern, UserOnLoopExit): """ColumnNPerCodeUnit is None => no constant relationship between column number and code unit. """ self.column_number_per_code_unit = ColumnNPerCodeUnit self.lexeme_end_check_f = LexemeEndCheckF self.reload_state_extern = ReloadStateExtern self.engine_type = EngineType # Counting Actions upon: loop entry/exit; before/after reload # on_loop_entry_count, \ on_loop_exit_count, \ on_before_reload_count, \ on_after_reload_count = self.__prepare_count_actions(self.column_number_per_code_unit) # Input pointer positioning: loop entry/exit; before/after reload # on_loop_reentry_pos, \ on_loop_exit_pos = self.__prepare_positioning_at_loop_begin_and_exit() on_before_reload_pos, \ on_after_reload_pos = self.__prepare_positioning_before_and_after_reload(MaintainLexemeF) # _____________________________________________________________________ # self.on_loop_entry = OpList.concatinate(on_loop_reentry_pos, on_loop_entry_count) self.on_loop_reentry = OpList.from_iterable(on_loop_reentry_pos) self.on_loop_exit = OpList.concatinate(on_loop_exit_pos, on_loop_exit_count, UserOnLoopExit) self.on_before_reload = OpList.concatinate(on_before_reload_pos, on_before_reload_count) self.on_after_reload = OpList.concatinate(on_after_reload_pos, on_after_reload_count)
def __init__(self, ColumnNPerCodeUnit, LexemeEndCheckF, MaintainLexemeF, EngineType, ReloadStateExtern, UserOnLoopExit): """ColumnNPerCodeUnit is None => no constant relationship between column number and code unit. """ self.column_number_per_code_unit = ColumnNPerCodeUnit self.lexeme_end_check_f = LexemeEndCheckF self.reload_state_extern = ReloadStateExtern self.engine_type = EngineType # Counting Actions upon: loop entry/exit; before/after reload # on_loop_entry_count, \ on_loop_exit_count, \ on_before_reload_count, \ on_after_reload_count = self.__prepare_count_actions(self.column_number_per_code_unit) # Input pointer positioning: loop entry/exit; before/after reload # on_loop_reentry_pos, \ on_loop_exit_pos = self.__prepare_positioning_at_loop_begin_and_exit() on_before_reload_pos, \ on_after_reload_pos = self.__prepare_positioning_before_and_after_reload(MaintainLexemeF) # _____________________________________________________________________ # self.on_loop_entry = OpList.concatinate(on_loop_reentry_pos, on_loop_entry_count) self.on_loop_reentry = OpList.from_iterable(on_loop_reentry_pos) self.on_loop_exit = OpList.concatinate(on_loop_exit_pos, on_loop_exit_count, UserOnLoopExit) self.on_before_reload = OpList.concatinate(on_before_reload_pos, on_before_reload_count) self.on_after_reload = OpList.concatinate(on_after_reload_pos, on_after_reload_count)