Skip to content

Commit

Permalink
micros/walker: add defun-form
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Nov 6, 2023
1 parent 36e5723 commit 3288348
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions contrib/walker/walker.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@
:type implict-progn-form
:reader ast-body)))

(defclass defun-form (ast)
((name :initarg :name
:type variable-symbol
:reader ast-name)
(lambda-list :initarg :lambda-list
:reader ast-lambda-list)
(body :initarg :body
:type implict-progn-form
:reader ast-body)))

;; walker
(defclass walker () ())

Expand Down Expand Up @@ -730,6 +740,20 @@
(walk-form walker (first form) form env path))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod walk-form ((walker walker) (name (eql 'defun)) form env path)
(with-walker-bindings (name lambda-list &body body) (rest form)
(multiple-value-bind (lambda-list env)
(walk-lambda-list walker lambda-list env (cons 2 path))
(make-instance 'defun-form
:name name
:lambda-list lambda-list
:body (make-instance 'implict-progn-form
:path (cons 3 path)
:forms (walk-forms walker body env path 3))
:path (cons 0 path)))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgeneric visit (visitor ast))
Expand Down Expand Up @@ -853,6 +877,11 @@
(defmethod visit (visitor (ast macrolet-form))
(visit visitor (ast-body ast)))

(defmethod visit (visitor (ast defun-form))
(visit visitor (ast-lambda-list ast))
(visit visitor (ast-body ast)))

;;
(define-condition exit-visitor ()
((value :initarg :value
:reader exit-visitor-value)))
Expand Down

0 comments on commit 3288348

Please sign in to comment.