Skip to content

Commit

Permalink
Use new macro DRAIN-RESULT-LIST to simplify redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
scymtym committed Jul 27, 2024
1 parent fe61a7c commit 67c5018
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 1 addition & 4 deletions code/analyzer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
(let ((cache (cache analyzer)))
(macrolet ((skip (reader popper)
`(progn
(loop for maybe-wad = (,reader cache)
while (and (not (null maybe-wad))
(position< (first maybe-wad) analyzer))
do (,popper cache))
(drain-result-list analyzer cache ,reader ,popper)
(,reader cache))))
(let ((residue (skip residue pop-from-residue)))
(cond ((null residue)
Expand Down
9 changes: 9 additions & 0 deletions code/cache.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@
(defun push-to-residue (cache wad)
(push wad (residue cache)))

(defmacro drain-result-list (analyzer cache reader popper)
`(loop :for remaining = (,reader ,cache)
:while (and (not (null remaining))
(position< (first remaining) ,analyzer))
;; Detach before popping because detaching may traverse the
;; ancestors of the wad and popping may sever the parent
;; link.
:do (,popper ,cache)))

(defun finish-scavenge (cache)
;; Move entire worklist to residue
(loop until (null (worklist cache))
Expand Down
12 changes: 3 additions & 9 deletions code/read.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@
;; the cache residue and cache suffix that are now before
;; the current stream position.
unless (eq kind :whitespace)
do (macrolet ((clear (reader popper)
`(loop :for remaining = (,reader cache)
:while (and (not (null remaining))
(position< (first remaining)
analyzer))
:do (,popper cache))))
(clear residue pop-from-residue)
(when (null (residue cache))
(clear suffix pop-from-suffix))))))
do (drain-result-list analyzer cache residue pop-from-residue)
(when (null (residue cache))
(drain-result-list analyzer cache suffix pop-from-suffix)))))

0 comments on commit 67c5018

Please sign in to comment.