Skip to content

Commit

Permalink
micros/walker: for-as-on-list
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Nov 12, 2023
1 parent 7d0fb09 commit 671aa67
Show file tree
Hide file tree
Showing 4 changed files with 2,049 additions and 1,952 deletions.
10 changes: 10 additions & 0 deletions contrib/walker/example.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,13 @@
:for x :in '(1 2 3) :do (print x))
(loop :with foo := nil
:for x :in '(1 2 3) :do (print x))
(loop :with fn := #'cddr :and a
:for x :in (list a) :by fn :do (print x))

(loop :for x :on '(1 2 3) :do (print x))
(loop :with foo
:for x :on '(1 2 3) :do (print x))
(loop :with foo := nil
:for x :on '(1 2 3) :do (print x))
(loop :with fn := #'cddr :and a
:for x :on (list a) :by fn :do (print x))
29 changes: 17 additions & 12 deletions contrib/walker/loop-form.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@
(defclass it-form (ast)
())

(defclass for-as-in-list-clause (ast <with-binding-form>)
(defclass <for-as-in-on-list-clause> (ast <with-binding-form>)
((binding :initarg :binding
:reader ast-binding)
(in :initarg :in
:reader ast-in)
(in-on :initarg :in-on
:reader ast-in-on)
(by :initarg :by
:reader ast-by)))

(defclass for-as-in-list-clause (<for-as-in-on-list-clause>) ())
(defclass for-as-on-list-clause (<for-as-in-on-list-clause>) ())

(defun walk-d-var-spec (walker d-var-spec env path)
(cond ((null d-var-spec)
'())
Expand Down Expand Up @@ -194,7 +197,7 @@
(cond ((accept :in)
(for-as-in-list binding))
((accept :on)
(for-as-on-list))
(for-as-on-list binding))
((accept :=)
(for-as-equals-then))
((accept :across)
Expand All @@ -206,21 +209,23 @@
;; TODO: error
;; TODO: from, to, downfrom, downto, above, by
)))))
(for-as-in-list (binding)

(for-as-in-on-list (ast-class binding)
(let* ((for-pos (- pos 2))
(in (walk walker (next) env (cons (+ for-pos 3) path)))
(by (when (accept :by)
(walk walker (next) env (cons (+ for-pos 5) path)))))
(push (make-instance 'for-as-in-list-clause
(push (make-instance ast-class
:path (cons (+ for-pos 1) path)
:binding binding
:in in
:in-on in
:by by)
for-as-clauses)
(setf env (extend-env env binding))))
(for-as-on-list ()
;; TODO
)
(for-as-in-list (binding)
(for-as-in-on-list 'for-as-in-list-clause binding))
(for-as-on-list (binding)
(for-as-in-on-list 'for-as-on-list-clause binding))
(for-as-equals-then ()
;; TODO
)
Expand Down Expand Up @@ -290,8 +295,8 @@
(defmethod visit (visitor (ast it-form))
nil)

(defmethod visit (visitor (ast for-as-in-list-clause))
(visit visitor (ast-in ast))
(defmethod visit (visitor (ast <for-as-in-on-list-clause>))
(visit visitor (ast-in-on ast))
(when (ast-by ast) (visit visitor (ast-by ast))))

(defmethod visit (visitor (ast simple-loop-form))
Expand Down
Loading

0 comments on commit 671aa67

Please sign in to comment.