;ELC ;;; Compiled ;;; in Emacs version 26.3 ;;; with all optimizations. ;;; This file uses dynamic docstrings, first added in Emacs 19.29. ;;; This file does not contain utf-8 non-ASCII characters, ;;; and so can be loaded in Emacs versions earlier than 23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (byte-code "\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307!\210\310\311\312\313#\210\310\311\314\315#\210\306\316!\210\310\317\312\320#\210\310\317\314\321#\210\306\322!\210\310\323\312\324#\210\310\323\314\325#\210\306\326!\210\310\327\312\330#\210\310\327\314\331#\210\332\333\334\335!\"\210\332\336\337\335!\"\210\332\340\336\"\210\341\340\342\343#\210\344\335\345\336#\346\335\347\211\350$\207" [require cl-lib cl-generic eieio rudel-errors rudel-util intern "rudel-state-error" put rudel-state-error error-conditions (error rudel-error rudel-state-error) error-message "Invalid state or state transition" "rudel-invalid-successor-state" rudel-invalid-successor-state (error rudel-error rudel-state-error rudel-invalid-successor-state) "Invalid successor state in state transition" "rudel-entered-error-state" rudel-entered-error-state (error rudel-error rudel-state-error rudel-entered-error-state) "Transition to error state" "rudel-no-start-state" rudel-no-start-state (error rudel-error rudel-state-error rudel-no-start-state) "No start state specified for state machine" defalias rudel-state-p eieio-make-class-predicate rudel-state rudel-state--eieio-childp eieio-make-child-predicate rudel-state-child-p make-obsolete "use (cl-typep ... \\='rudel-state) instead" "25.1" define-symbol-prop cl-deftype-satisfies eieio-defclass-internal nil (:documentation "A state that can be used in state machines." :abstract t)] 6) #@69 You cannot create a new object of type `rudel-state'. (fn &rest _) (defalias 'rudel-state #[128 "\300\301!\207" [error "Class rudel-state is abstract"] 3 (#$ . 1863)]) (byte-code "\300\301\302\301\303\304#\305#\210\300\306\302\306\307\304#\310#\210\300\311\302\311\312\304#\313#\210\300\314\315\316!\"\210\300\317\320\316!\"\210\300\321\317\"\210\322\321\323\324#\210\325\316\326\317#\327\316\304\330\331$\210\332\333\304\334\304\335%\207" [defalias rudel-accept cl-generic-define ((this rudel-state) &rest arguments) nil "Executed when the machine receives an event while in state THIS.\n\n(fn (this rudel-state) &rest ARGUMENTS)" rudel-enter ((this rudel-state) &rest arguments) "Executed when the machine switches to state THIS.\n\n(fn (this rudel-state) &rest ARGUMENTS)" rudel-leave ((this rudel-state)) "Executed when the machine leaves state THIS.\n\n(fn (this rudel-state))" rudel-state-machine-p eieio-make-class-predicate rudel-state-machine rudel-state-machine--eieio-childp eieio-make-child-predicate rudel-state-machine-child-p make-obsolete "use (cl-typep ... \\='rudel-state-machine) instead" "25.1" define-symbol-prop cl-deftype-satisfies eieio-defclass-internal ((states :initarg :states :type list :initform nil :documentation "A list (NAME . STATE) conses where NAME is a symbol\nand STATE is an object of a class derived from rudel-state.") (state :initarg :state :type rudel-state-child :writer rudel-set-state :documentation "The current state of the machine.")) (:documentation "A finite state machine.") cl-generic-define-method rudel-set-state ((this rudel-state-machine) value) #[514 "\300\301#\207" [eieio-oset state] 7 "Set the slot `state' of an object of class `rudel-state-machine'.\n\n(fn THIS VALUE)"]] 7) #@76 Create a new object of class type `rudel-state-machine'. (fn &rest SLOTS) (defalias 'rudel-state-machine #[128 "\300\301\302#\207" [apply make-instance rudel-state-machine] 5 (#$ . 3612)]) (byte-code "\300\301\302\303#\300\207" [function-put rudel-state-machine compiler-macro rudel-state-machine--anon-cmacro] 4) #@26 (fn WHOLE &rest SLOTS) (defalias 'rudel-state-machine--anon-cmacro #[385 "\211@;\204\207\300\301\302@@#@\303@DABB\"\207" [macroexp--warn-and-return format "Obsolete name arg %S to constructor %S" identity] 7 (#$ . 3934)]) (byte-code "\300\301\302\303\304\305%\210\300\301\306\307\302\310%\210\300\311\302\312\302\313%\210\300\314\302\315\302\316%\210\300\317\302\320\302\321%\210\300\322\302\323\302\324%\210\300\325\302\326\302\327%\210\300\330\302\331\302\332%\210\300\333\302\334\302\335%\210\300\336\302\337\304\340%\210\341\342\343\344!\"\210\341\345\346\344!\"\210\341\347\345\"\210\350\347\351\352#\210\353\344\354\345#\355\344\356\357\360$\207" [cl-generic-define-method initialize-instance nil ((this rudel-state-machine) slots) t #[771 "\300!\"\207" [rudel-state-machine-strip-initargs] 7 "Initialize slots of THIS skipping :start initarg.\n\n(fn CL--CNM THIS SLOTS)"] (:after) ((this rudel-state-machine) slots) #[514 "\300\301\"\211<\205\f\211A\302!\203\202,9\203\"\303\"\202,<\203/\303@\"\206R\304\305\306\307\"\"A\206R\304\310\306\307\"\"A\206R\306\307\"\205R\306\307\"@A\211\204[\311\312\313\"\210\314\"\210\315\316\317##\266\203\207" [plist-get :start rudel-state-child-p rudel-find-state assoc start slot-value states new signal rudel-no-start-state nil rudel-set-state rudel--switch-to-return-value apply rudel-enter] 13 "Set current state of THIS to a proper initial value.\nIf a start state is specified using the :start init argument to\nthe constructor, that state is used. If there is no such state,\nthe list of states is search for a state named 'start or 'new. If\nthat fails as well, the first state in the state list is used.\n\n(fn THIS SLOTS)"] rudel-find-state ((this rudel-state-machine) name) #[514 "\300\301\302\"\"A\207" [assoc slot-value states] 8 "Return state object for symbol NAME.\n\n(fn THIS NAME)"] rudel-register-state ((this rudel-state-machine) name state) #[771 "\300\301B\302$\207" [object-add-to-list :states t] 8 "Register STATE and its NAME with THIS state machine.\n\n(fn THIS NAME STATE)"] rudel-register-states ((this rudel-state-machine) states) #[514 "\211\211\205\"\211@\211@A\211\300\301\302!\"#\266A\266\202\202\207" [rudel-register-state make-instance symbol-name] 15 "Register STATES with THIS state machine.\nSTATES is a list of cons cells whose car is a symbol - the name\nof the state - and whose cdr is a class.\n\n(fn THIS STATES)"] rudel-current-state ((this rudel-state-machine) &optional object) #[513 "\300\301\302\"\301\303\"\304\305\306\307&@\203\211\301\302\"B\202\211\262\207" [cl-find slot-value state states :key cdr :test eq] 10 "Return name and, optionally, state object of the current state of THIS.\nIf OBJECT is non-nil, (NAME . OBJECT) is returned. Otherwise,\njust NAME.\n\n(fn THIS &optional OBJECT)"] rudel-accept ((this rudel-state-machine) &rest arguments) #[385 "\300\301\302\303\"#\211\203\2119\204\304!\203\305\"\2023\211<\203,\300\305#\2023\306\307\310!C\"\262\207" [apply rudel-accept slot-value state rudel-state-child-p rudel-switch signal wrong-type-argument type-of] 8 "Process an event described by ARGUMENTS.\n\n(fn THIS &rest ARGUMENTS)"] rudel-switch ((this rudel-state-machine) next &rest arguments) #[642 "\300!\204@\204\301\302\"\262\202@9\2038\303\301\304\"\"\211\2040\305\306\307\301\302\"E\"\210\211A\262\210\202@\305\310\311!C\"\210\301\302\"=\203T\204T\301\302\"\202q\312\301\302\"!\210\313\"\210\314\301\302\"\315\316\301\302\"##\207" [rudel-state-child-p slot-value state assoc states signal rudel-invalid-successor-state <- wrong-type-argument type-of rudel-leave rudel-set-state rudel--switch-to-return-value apply rudel-enter] 12 "Leave current state and switch to state NEXT.\nARGUMENTS are passed to the `rudel-enter' method of the successor\nstate.\n\n(fn THIS NEXT &rest ARGUMENTS)"] rudel--switch-to-return-value ((this rudel-state-machine) state next) #[771 "\211\204\207\211<\203\300\301#\207\301\"\207" [apply rudel-switch] 7 "Switch from STATE to the next state indicated by NEXT.\nSTATE is the current state.\nNEXT can nil, a list or a `rudel-state' object.\n\n(fn THIS STATE NEXT)"] object-print ((this rudel-state-machine) &rest strings) #[642 "\300\301\"\203\302\303\304\305\306\301\"!\"$\207\307#\207" [slot-boundp state apply format " state: %s" object-name-string slot-value " state: #start"] 13 "Add current state to the string representation of THIS.\n\n(fn THIS &rest STRINGS)"] defalias rudel-hook-state-machine-p eieio-make-class-predicate rudel-hook-state-machine rudel-hook-state-machine--eieio-childp eieio-make-child-predicate rudel-hook-state-machine-child-p make-obsolete "use (cl-typep ... \\='rudel-hook-state-machine) instead" "25.1" define-symbol-prop cl-deftype-satisfies eieio-defclass-internal (rudel-hook-object rudel-state-machine) ((last-args :initarg :last-args :type list :initform nil :documentation "In this slot `rudel-switch' stores the switch\narguments for processing in the `rudel-set-state' method.") (accept-hook :initarg :accept-hook :type list :initform nil :documentation "This hook is run when the state machine accepts\ninput.") (switch-hook :initarg :switch-hook :type list :initform nil :documentation "This hook is run when the state machine switches\nbetween states.")) (:documentation "State machine objects of this class run hooks when they accept\narguments and when they switch states.")] 6) #@81 Create a new object of class type `rudel-hook-state-machine'. (fn &rest SLOTS) (defalias 'rudel-hook-state-machine #[128 "\300\301\302#\207" [apply make-instance rudel-hook-state-machine] 5 (#$ . 9460)]) (byte-code "\300\301\302\303#\300\207" [function-put rudel-hook-state-machine compiler-macro rudel-hook-state-machine--anon-cmacro] 4) #@26 (fn WHOLE &rest SLOTS) (defalias 'rudel-hook-state-machine--anon-cmacro #[385 "\211@;\204\207\300\301\302@@#@\303@DABB\"\207" [macroexp--warn-and-return format "Obsolete name arg %S to constructor %S" identity] 7 (#$ . 9807)]) (byte-code "\300\301\302\303\304\305%\210\300\306\307\310\304\311%\210\300\312\313\314\304\315%\207" [cl-generic-define-method rudel-accept (:before) ((this rudel-hook-state-machine) &rest arguments) nil #[385 "\300\301\302$\207" [apply object-run-hook-with-args accept-hook] 7 "This method runs 'accept-hook' before ARGUMENTS are processed.\n\n(fn THIS &rest ARGUMENTS)"] rudel-switch (:before) ((this rudel-hook-state-machine) _next &rest arguments) #[642 "\300\301#\207" [eieio-oset :last-args] 7 "This method stores ARGUMENTS for later processing.\n\n(fn THIS NEXT &rest ARGUMENTS)"] rudel-set-state (:before) ((this rudel-hook-state-machine) next &rest _arguments) #[642 "\300\301\302\303\304\"%\207" [apply object-run-hook-with-args switch-hook slot-value last-args] 12 "This method runs 'switch-hook' when switching states.\n\n(fn THIS NEXT &rest ARGUMENTS)"]] 6) #@66 Remove virtual initargs and their values from SLOTS. (fn SLOTS) (defalias 'rudel-state-machine-strip-initargs #[257 "\211\300\203\"@\301=\204@B\262A@B\262AA\262\202\302!\207" [nil :start reverse] 5 (#$ . 10931)]) #@762 Repeatedly call CALLBACK until MACHINE is in a state in SUCCESS-STATES or ERROR-STATES. MACHINE should be of type rudel-state-machine-child or at least have a method `rudel-get-state'. SUCCESS-STATES and ERROR-STATES are lists which contain the names (as symbols) of success and error states respectively. This function does not return when MACHINE enters states not in SUCCESS-STATES or ERROR-STATES. As a result, a deadlock can occur when MACHINE deadlocks or cycles through states not in either list infinitely. When non-nil, CALLBACK has to be a function that accepts one argument of the form (SYMBOL . STATE) where SYMBOL is the name symbol of the current state and STATE is the state object. (fn MACHINE SUCCESS-STATES &optional ERROR-STATES CALLBACK) (defalias 'rudel-state-wait #[1026 "\3002@\301\302\"\211@A\211\211>\203\303\300\304BB\"\210\211>\203.\303\300\305BB\"\210\2038B!\210\306\307!\266\202\203H\302!\210\211@\304=\204U\310\311A\"\210\211A\207" [state-wait rudel-current-state t throw success error sleep-for 0.05 signal rudel-entered-error-state] 14 (#$ . 11168)]) (provide 'rudel-state-machine)