This commit is contained in:
water
2023-09-23 14:26:30 -04:00
parent 69caa163c9
commit 10971703a0
95 changed files with 286 additions and 723 deletions
+25
View File
@@ -464,6 +464,10 @@
(set! *defstate-type-stack* '())
`(none)
)
(seval (define *defstate-current-type* #f))
(seval (define *defstate-current-state-name* #f))
;; *no-state* is just used for the compiler to know whether a handler was actually set or not
(defmacro defstate (state-name parents
&key (virtual #f)
@@ -483,6 +487,10 @@
*defstate-type-stack*)
)
(set! *defstate-type-stack* '())
(when virtual
(set! *defstate-current-type* defstate-type)
(set! *defstate-current-state-name* state-name)
)
;; check for default handlers
(let ((default-handlers (assoc defstate-type *default-state-handlers*)))
(when default-handlers
@@ -545,6 +553,23 @@
)
)
(defmacro find-parent-state ()
(when (or (not *defstate-current-type*)
(not *defstate-current-state-name*))
(error "use of find-parent-state outside of a defstate.")
)
`(cast-to-method-type
,*defstate-current-type*
,*defstate-current-state-name*
(find-parent-method ,*defstate-current-type* (method-id-of-type ,*defstate-current-type* ,*defstate-current-state-name*))
)
)
(defmacro call-parent-method (&rest args)
`((the (current-method-function-type) (find-parent-method (current-method-type) (current-method-id)))
,@args)
)
(defmacro behavior (bindings &rest body)
"Define an anonymous behavior for a process state. This may only be used inside a defstate!"