Skip to content

Commit

Permalink
micros/walker: add walking-without-expanding-unknown-macros option
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Dec 17, 2023
1 parent 994d4d6 commit b609fe4
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions contrib/walker/walker.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,13 @@

;; walker
(defclass walker ()
((special-variable-table :initform (make-hash-table :test 'eq)
:reader walker-special-variable-table)))
((special-variable-table
:initform (make-hash-table :test 'eq)
:reader walker-special-variable-table)
(walking-without-expanding-unknown-macros
:initarg :walking-without-expanding-unknown-macros
:initform t
:reader walking-without-expanding-unknown-macros-p)))

(defmethod get-special-variable-binding ((walker walker) symbol)
(or (gethash symbol (walker-special-variable-table walker))
Expand Down Expand Up @@ -738,25 +743,27 @@
(if macrolet-binding
(walk-macro walker form path env (macrolet-binding-lambda-list macrolet-binding))
(multiple-value-bind (expansion expanded) (macroexpand-1 form)
(declare (ignore expansion))
(if expanded
(walk-macro walker form path env (micros/backend:arglist (first form)))
(let ((name (first form)))
(if (consp name)
(walk-lambda-call-form walker form env path)
(let ((binding (lookup-function-binding env name))
(arguments (loop :for arg :in (rest form)
:for n :from 1
:collect (walk walker arg env (cons n path)))))
(if binding
(make-instance 'call-local-function-form
:binding binding
:arguments arguments
:path (cons 0 path))
(make-instance 'call-function-form
:operator name
:arguments arguments
:path (cons 0 path)))))))))))
(cond (expanded
(if (walking-without-expanding-unknown-macros-p walker)
(walk-macro walker form path env (micros/backend:arglist (first form)))
(walk walker expansion env path)))
(t
(let ((name (first form)))
(if (consp name)
(walk-lambda-call-form walker form env path)
(let ((binding (lookup-function-binding env name))
(arguments (loop :for arg :in (rest form)
:for n :from 1
:collect (walk walker arg env (cons n path)))))
(if binding
(make-instance 'call-local-function-form
:binding binding
:arguments arguments
:path (cons 0 path))
(make-instance 'call-function-form
:operator name
:arguments arguments
:path (cons 0 path))))))))))))

(defmethod walk-variable ((walker walker) symbol env path)
;; TODO
Expand Down

0 comments on commit b609fe4

Please sign in to comment.