Skip to content

Commit

Permalink
micros/walker: add named-lambda support
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Dec 23, 2023
1 parent 3952cfd commit 23f52d5
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions contrib/walker/walker.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
(lambda-list :initarg :lambda-list :reader ast-lambda-list)
(body :initarg :body :reader ast-body)))

(defclass named-lambda-form (ast)
((name :initarg :name :reader ast-name)
(documentation :initarg :documentation :reader ast-documentation)
(lambda-list :initarg :lambda-list :reader ast-lambda-list)
(body :initarg :body :reader ast-body)))

(defclass multiple-value-call-form (ast)
((function :initarg :function
:reader ast-function)
Expand Down Expand Up @@ -529,7 +535,7 @@
:path path)
env)))

(defun walk-lambda-list-and-body (walker lambda-list body env path)
(defun walk-lambda-list-and-body (walker lambda-list body env path &optional name)
(multiple-value-bind (body declare-forms documentation)
(parse-body body :documentation t)
(let ((declaration-spec (parse-declaration-specifiers declare-forms)))
Expand All @@ -539,11 +545,25 @@
env
(cons 1 path)
:declaration-spec declaration-spec)
(make-instance 'lambda-form
:documentation documentation
:lambda-list lambda-list
:body (walk-forms walker body env path (+ 2 (length declare-forms)))
:path (cons 0 path))))))
(cond (name
(make-instance
'named-lambda-form
:name name
:documentation documentation
:lambda-list lambda-list
:body (walk-forms walker
body
(extend-env env (make-instance 'block-binding :name name))
path
(+ 2 (length declare-forms)))
:path (cons 0 path)))
(t
(make-instance
'lambda-form
:documentation documentation
:lambda-list lambda-list
:body (walk-forms walker body env path (+ 2 (length declare-forms)))
:path (cons 0 path))))))))

(defmethod walk-lambda-form ((walker walker) form env path)
(assert-type (first form) '(member lambda #+sbcl sb-int:named-lambda))
Expand All @@ -553,8 +573,7 @@
(walk-lambda-list-and-body walker lambda-list body env path)))
((sb-int:named-lambda)
(with-walker-bindings (name lambda-list &body body) (rest form)
(declare (ignore name)) ; TODO
(walk-lambda-list-and-body walker lambda-list body env path)))))
(walk-lambda-list-and-body walker lambda-list body env path name)))))

(defmethod walk-form ((walker walker) (name (eql 'function)) form env path)
(with-walker-bindings (thing) (rest form)
Expand Down

0 comments on commit 23f52d5

Please sign in to comment.