(in-package #:user-side-compiler)

(defun test-sweep ()
  (let* ((line-routine (make-label :name "line" :address 0))
         (var+=-routine (make-label :name "var+=" :address 0))
         (var-=-routine (make-label :name "var-=" :address 0))
         (calls (list (make-call line-routine '((t 0) (t 120) (nil 0) (nil 1)))
                      (make-call line-routine '((t 255) (t 120) (nil 2) (nil 3)))
                      (make-call var+=-routine '((nil 0) (t 1)))
                      (make-call var+=-routine '((nil 1) (t 1)))
                      (make-call var-=-routine '((nil 2) (t 1)))
                      (make-call var-=-routine '((nil 3) (t 1))))))
    (loop :with prev := nil
          :for call :in calls
          :unless (null prev)
            :do (setf (next prev) call)
          :do (setf prev call))
    (let ((insts
            (compile-starting-at
             (make-instance 'node-dotimes :loopee-node (first calls) :stop-ref (make-instance 'reference-constant :value 240)))))
      (fix-label-addresses-in-instruction-list insts #xc000)
      (bytesquash-instruction-list insts #xc000))))