lisp/flow.lisp

40 lines
600 B
Common Lisp
Raw Normal View History

2024-12-16 14:34:52 -05:00
(load "utils.lisp")
(defclass node ()
((next :initarg :next :initform nil :accessor node-next)))
(defclass if-node (node)
((expr :initarg :expr)
(else :initarg :else :initform nil)))
(defclass output-node (node)
)
(defgeneric run (node))
(defmethod run ((node node))
(node-next node))
(defmethod run ((node if-node))
(with-slots (expr next else) node
(if (eval expr)
next
else)))
;; start
;; |
;; v
;; x = 10
;; |
;; v
;; if x = 0 -Y> end
;; | ^
;; N |<-------
;; v ^
;; output x |
;; | |
;; v |
;; x = x - 1 ->|