diff --git a/contrib/walker/data-and-control-flow.lisp b/contrib/walker/data-and-control-flow.lisp index c2bd636..27f4f22 100644 --- a/contrib/walker/data-and-control-flow.lisp +++ b/contrib/walker/data-and-control-flow.lisp @@ -65,3 +65,44 @@ (defmethod visit (visitor (ast check-type-form)) (visit visitor (ast-place ast)) (visit visitor (ast-type-string ast))) + +;; setf +(defclass setf-form (ast) + ()) + +(defclass setf-symbol-form (ast) + ((symbol :initarg :symbol + :type variable-symbol + :reader ast-symbol) + (value :initarg :value + :reader ast-value))) + +(defclass setf-complex-form (ast) + ((operator :initarg :operator + :type variable-symbol + :reader ast-operator) + (value :initarg :value + :reader ast-value))) + +;; TODO +(defmethod walk-form ((walker walker) (name (eql 'setf)) form env path) + (loop :for (place value) :on (rest form) + :for n :from 1 :by 2 + :for walked-value := (walk walker + value + env + (cons (1+ n) path)) + :collect (if (symbolp place) + (make-instance 'setf-symbol-form + :symbol place + :value walked-value) + (make-instance + 'setf-complex-form + :operator (first place) + :arguments (loop :for m :from 1 + :for arg :in (rest place) + :collect (walk walker + arg + env + (list* m n path))) + :value walked-value)))) diff --git a/contrib/walker/example.lisp b/contrib/walker/example.lisp index 93db367..a7281ed 100644 --- a/contrib/walker/example.lisp +++ b/contrib/walker/example.lisp @@ -260,3 +260,10 @@ b) a b) + +;; TOOD +(let (storage) + (flet (((setf storage) (value) + (setf storage value))) + (setf (storage) 100)) + storage)