예제 #1
0
파일: core.py 프로젝트: dkopecek/amplify
    def __init__(self, StateIndex, TheTransitionMap, SkiDb):
        # A 'PseudoTemplateState' does not implement a 'MegaState_Entry'.
        assert isinstance(StateIndex, long)

        self.__entry    = MegaState_Entry()
        AnalyzerState.set_index(self, StateIndex)
        # AnalyzerState.__init__(StateIndex, InitStateF, EngineType, TheTransitionMap):

        self.ski_db         = SkiDb
        self.transition_map = TheTransitionMap

        # Maintain a list of states with which the state may not combine well
        self.__bad_company = set()
예제 #2
0
    def __init__(self, StateIndex, TheTransitionMap, SkiDb):
        # A 'PseudoTemplateState' does not implement a 'MegaState_Entry'.
        assert isinstance(StateIndex, long)

        self.__entry    = MegaState_Entry()
        AnalyzerState.set_index(self, StateIndex)
        # AnalyzerState.__init__(StateIndex, InitStateF, EngineType, TheTransitionMap):

        self.ski_db         = SkiDb
        self.transition_map = TheTransitionMap

        # Maintain a list of states with which the state may not combine well
        self.__bad_company = set()
예제 #3
0
파일: core.py 프로젝트: liancheng/rose
    def __init__(self, AbsorbedAnalyzerState, AbsorbingMegaState):
        AnalyzerState.set_index(self, AbsorbedAnalyzerState.index)
        # The absorbing MegaState may, most likely, contain other transitions
        # than the transitions into the AbsorbedAnalyzerState. Those, others
        # do not do any harm, though. Filtering out those out of the hash map
        # does, most likely, not bring any benefit.
        assert AbsorbedAnalyzerState.index in AbsorbingMegaState.implemented_state_index_list()
        #----------------------------------------------------------------------

        self.__entry     = AbsorbedState_Entry(AbsorbedAnalyzerState.index, 
                                               AbsorbingMegaState.entry.transition_db,
                                               AbsorbingMegaState.entry.door_db)
        self.absorbed_by = AbsorbingMegaState
        self.__state     = AbsorbedAnalyzerState
예제 #4
0
    def __init__(self, AbsorbedAnalyzerState, AbsorbingMegaState):
        AnalyzerState.set_index(self, AbsorbedAnalyzerState.index)
        # The absorbing MegaState may, most likely, contain other transitions
        # than the transitions into the AbsorbedAnalyzerState. Those, others
        # do not do any harm, though. Filtering out those out of the hash map
        # does, most likely, not bring any benefit.
        assert AbsorbedAnalyzerState.index in AbsorbingMegaState.implemented_state_index_list(
        )
        #----------------------------------------------------------------------

        self.__entry = AbsorbedState_Entry(
            AbsorbedAnalyzerState.index,
            AbsorbingMegaState.entry.transition_db,
            AbsorbingMegaState.entry.door_db)
        self.absorbed_by = AbsorbingMegaState
        self.__state = AbsorbedAnalyzerState
예제 #5
0
파일: core.py 프로젝트: liancheng/rose
    def __init__(self, TheEntry, TheDropOut, StateIndex):
        # A 'PseudoMegaState' does not implement a 'MegaState_Entry' and 'MegaState_DropOut'.
        # On the long term 'MegaState_DropOut' should be derived from 'DropOut'.
        assert isinstance(TheEntry, Entry), Entry.__class__.__name__
        assert isinstance(TheDropOut, (MegaState_DropOut, DropOut, DropOutBackward, DropOutBackwardInputPositionDetection)) 
        assert isinstance(StateIndex, long)

        self.__entry    = TheEntry
        self.__drop_out = TheDropOut
        AnalyzerState.set_index(self, StateIndex)

        # Maintain a list of states with which the state may not combine well
        self.__bad_company = set()
        
        # State Index Sequence: Implemented States (and may be others) in an 
        # ordered Sequence.
        self.__state_index_sequence = None
예제 #6
0
def get_transition_map(TM, StateIndex, DropOutCatcher=None):
    if DropOutCatcher is None:
        DropOutCatcher = AnalyzerState(sm_index.get(), TransitionMap())

    def get_door_id(Target):
        return DoorID(Target, 0)

    tm = TransitionMap.from_iterable(TM, get_door_id)
    return tm.relate_to_TargetByStateKeys(StateIndex, DropOutCatcher)
예제 #7
0
    def __init__(self, TheEntry, TheDropOut, StateIndex):
        # A 'PseudoMegaState' does not implement a 'MegaState_Entry' and 'MegaState_DropOut'.
        # On the long term 'MegaState_DropOut' should be derived from 'DropOut'.
        assert isinstance(TheEntry, Entry), Entry.__class__.__name__
        assert isinstance(TheDropOut,
                          (MegaState_DropOut, DropOut, DropOutBackward,
                           DropOutBackwardInputPositionDetection))
        assert isinstance(StateIndex, long)

        self.__entry = TheEntry
        self.__drop_out = TheDropOut
        AnalyzerState.set_index(self, StateIndex)

        # Maintain a list of states with which the state may not combine well
        self.__bad_company = set()

        # State Index Sequence: Implemented States (and may be others) in an
        # ordered Sequence.
        self.__state_index_sequence = None
예제 #8
0
파일: core.py 프로젝트: xxyzzzq/quex
    def prepare_state(self, OldState, StateIndex, OnBeforeEntry):
        """REQUIRES: 'self.init_state_forward_f', 'self.engine_type', 'self.__from_db'.
        """
        state = AnalyzerState.from_State(OldState, StateIndex, self.engine_type)

        cmd_list = []
        if self.engine_type.is_BACKWARD_PRE_CONTEXT():
            cmd_list.extend(
                 Op.PreContextOK(cmd.acceptance_id()) 
                 for cmd in OldState.single_entry.get_iterable(SeAccept)
            )

        if state.transition_map is None and False: 
            # NOTE: We need a way to disable this exception for PathWalkerState-s(!)
            #       It's safe, not to allow it, in general.
            #------------------------------------------------------------------------
            # If the state has no further transitions then the input character does 
            # not have to be read. This is so, since without a transition map, the 
            # state immediately drops out. The drop out transits to a terminal. 
            # Then, the next action will happen from the init state where we work
            # on the same position. If required the reload happens at that moment,
            # NOT before the empty transition block.
            #
            # This is not true for Path Walker States, so we offer the option 
            # 'ForceInputDereferencingF'
            assert StateIndex != self.init_state_index # Empty state machine! --> impossible

            if self.engine_type.is_FORWARD(): 
                cmd_ext = [ Op.Increment(E_R.InputP) ]
            else:                             
                cmd_ext = [ Op.Decrement(E_R.InputP) ]
        else:
            if self.engine_type.is_FORWARD(): 
                cmd_ext = [ Op.Increment(E_R.InputP), Op.InputPDereference() ]
            else:                             
                cmd_ext = [ Op.Decrement(E_R.InputP), Op.InputPDereference() ]

        cmd_list.extend(cmd_ext)

        ta = TransitionAction(OpList.from_iterable(cmd_list))

        # NOTE: The 'from reload transition' is implemented by 'prepare_for_reload()'
        for source_state_index in self.__from_db[StateIndex]: 
            assert source_state_index != E_StateIndices.BEFORE_ENTRY
            state.entry.enter(StateIndex, source_state_index, ta.clone())

        if StateIndex == self.init_state_index:
            if self.engine_type.is_FORWARD():
                on_entry_op_list = OnBeforeEntry.clone()
                on_entry_op_list.append(Op.InputPDereference())
                ta = TransitionAction(on_entry_op_list)
            state.entry.enter_state_machine_entry(self.__state_machine_id, 
                                                  StateIndex, ta)

        return state
예제 #9
0
파일: core.py 프로젝트: xxyzzzq/quex
    def prepare_state(self, OldState, StateIndex, OnBeforeEntry):
        """REQUIRES: 'self.init_state_forward_f', 'self.engine_type', 'self.__from_db'.
        """
        state = AnalyzerState.from_State(OldState, StateIndex,
                                         self.engine_type)

        cmd_list = []
        if self.engine_type.is_BACKWARD_PRE_CONTEXT():
            cmd_list.extend(
                Op.PreContextOK(cmd.acceptance_id())
                for cmd in OldState.single_entry.get_iterable(SeAccept))

        if state.transition_map is None and False:
            # NOTE: We need a way to disable this exception for PathWalkerState-s(!)
            #       It's safe, not to allow it, in general.
            #------------------------------------------------------------------------
            # If the state has no further transitions then the input character does
            # not have to be read. This is so, since without a transition map, the
            # state immediately drops out. The drop out transits to a terminal.
            # Then, the next action will happen from the init state where we work
            # on the same position. If required the reload happens at that moment,
            # NOT before the empty transition block.
            #
            # This is not true for Path Walker States, so we offer the option
            # 'ForceInputDereferencingF'
            assert StateIndex != self.init_state_index  # Empty state machine! --> impossible

            if self.engine_type.is_FORWARD():
                cmd_ext = [Op.Increment(E_R.InputP)]
            else:
                cmd_ext = [Op.Decrement(E_R.InputP)]
        else:
            if self.engine_type.is_FORWARD():
                cmd_ext = [Op.Increment(E_R.InputP), Op.InputPDereference()]
            else:
                cmd_ext = [Op.Decrement(E_R.InputP), Op.InputPDereference()]

        cmd_list.extend(cmd_ext)

        ta = TransitionAction(OpList.from_iterable(cmd_list))

        # NOTE: The 'from reload transition' is implemented by 'prepare_for_reload()'
        for source_state_index in self.__from_db[StateIndex]:
            assert source_state_index != E_StateIndices.BEFORE_ENTRY
            state.entry.enter(StateIndex, source_state_index, ta.clone())

        if StateIndex == self.init_state_index:
            if self.engine_type.is_FORWARD():
                on_entry_op_list = OnBeforeEntry.clone()
                on_entry_op_list.append(Op.InputPDereference())
                ta = TransitionAction(on_entry_op_list)
            state.entry.enter_state_machine_entry(self.__state_machine_id,
                                                  StateIndex, ta)

        return state
예제 #10
0
파일: core.py 프로젝트: coderjames/pascal
    def __init__(self, AbsorbedAnalyzerState, AbsorbingMegaState):
        AnalyzerState.set_index(self, AbsorbedAnalyzerState.index)
        # The absorbing MegaState may, most likely, contain other transitions
        # than the transitions into the AbsorbedAnalyzerState. Those, others
        # do not do any harm, though. Filtering out those out of the hash map
        # does, most likely, not bring any benefit.
        assert AbsorbedAnalyzerState.index in AbsorbingMegaState.implemented_state_index_list()
        if False:
            for transition_id in AbsorbedAnalyzerState.entry.door_db.iterkeys():
                if transition_id.state_index != AbsorbedAnalyzerState.index: continue
                assert AbsorbingMegaState.entry.door_db.has_key(transition_id), \
                       "MegaState %i absorbed %s but does not implement transition %s" % \
                       (AbsorbingMegaState.index,                                        \
                        AbsorbingMegaState.implemented_state_index_list(), transition_id)
        #----------------------------------------------------------------------

        self.__entry     = AbsorbedState_Entry(AbsorbedAnalyzerState.index, 
                                               AbsorbingMegaState.entry.transition_db,
                                               AbsorbingMegaState.entry.door_db)
        self.absorbed_by = AbsorbingMegaState
        self.__state     = AbsorbedAnalyzerState
예제 #11
0
파일: core.py 프로젝트: liancheng/rose
    def __init__(self, SM, EngineType):
        assert EngineType in E_EngineTypes
        assert isinstance(SM, StateMachine)


        self.__acceptance_state_index_list = SM.get_acceptance_state_index_list()
        self.__init_state_index = SM.init_state_index
        self.__state_machine_id = SM.get_id()
        self.__engine_type      = EngineType

        # (*) PathTrace database, Successor database
        self.__trace_db, self.__dangerous_positioning_state_set = track_analysis.do(SM)

        # (*) From/To Databases
        #
        #     from_db:  state_index --> states from which it is entered.
        #     to_db:    state_index --> states which it enters
        #
        from_db = defaultdict(set)
        to_db   = defaultdict(set)
        for from_index, state in SM.states.iteritems():
            to_db[from_index] = set(state.transitions().get_map().iterkeys())
            for to_index in state.transitions().get_map().iterkeys():
                from_db[to_index].add(from_index)
        self.__from_db = from_db
        self.__to_db   = to_db

        # (*) Prepare AnalyzerState Objects
        self.__state_db = dict([(state_index, AnalyzerState(SM.states[state_index], state_index, 
                                                            state_index == SM.init_state_index, 
                                                            EngineType, 
                                                            from_db[state_index])) 
                                 for state_index in self.__trace_db.iterkeys()])

        if EngineType != E_EngineTypes.FORWARD:
            # BACKWARD_INPUT_POSITION, BACKWARD_PRE_CONTEXT:
            #
            # DropOut and Entry do not require any construction beyond what is
            # accomplished inside the constructor of 'AnalyzerState'. No positions
            # need to be stored and restored.
            self.__position_register_map = None
            self.__position_info_db      = None
            return

        # (*) Positioning info:
        #
        #     map:  (state_index) --> (pattern_id) --> positioning info
        #
        self.__position_info_db = {}
        for state_index, trace_list in self.__trace_db.iteritems():
            self.__position_info_db[state_index] = self.multi_path_positioning_analysis(trace_list)

        # (*) Drop Out Behavior
        #     The PathTrace objects tell what to do at drop_out. From this, the
        #     required entry actions of states can be derived.
        self.__require_acceptance_storage_list = []
        self.__require_position_storage_list   = []
        for state_index, trace_list in self.__trace_db.iteritems():
            state = self.__state_db[state_index]
            # trace_list: PathTrace objects for each path that guides to state.
            self.configure_drop_out(state, trace_list)

        # (*) Entry Behavior
        #     Implement the required entry actions.
        self.configure_entries()

        # (*) Position Register Map (Used in 'optimizer.py')
        self.__position_register_map = position_register_map.do(self)
예제 #12
0
def get_AnalyzerState(StateIndex, TM):
    return AnalyzerState(StateIndex, TM)