UNB/ CS/ David Bremner/ teaching/ cs4613/ lectures/ lecture20/ mutator1.rkt
#lang plai/gc2/mutator
(allocator-setup "mark-sweep.rkt" 200)

(define (build-one)
  (let* ((x0 0)
         (x1
          (lambda (x)
            (if (= x 0)
              x0
              (if (= x 1) x0 (if (= x 2) x0 (if (= x 3) x0 x0))))))
         (x2 (lambda (x) x0))
         (x3 #t)
         (x4 #t)
         (x5
          (lambda (x)
            (if (= x 0)
              x0
              (if (= x 1)
                x1
                (if (= x 2)
                  x4
                  (if (= x 3)
                    x0
                    (if (= x 4)
                      x4
                      (if (= x 5)
                        x0
                        (if (= x 6)
                          x2
                          (if (= x 7) x2 (if (= x 8) x4 x2)))))))))))
         (x6 (cons #f x1))
         (x7 'y)
         (x8 (cons x2 x3)))
    (set-first! x6 x7)
    x5))

(define (traverse-one x5) (= 0 ((x5 1) 3)))
(define (trigger-gc n)
  (if (zero? n)
      0
      (begin (cons n n) (trigger-gc (- n 1)))))
(define (loop i)
  (if (zero? i)
    'passed
    (let ((obj (build-one)))
      (trigger-gc 200)
      (if (traverse-one obj)
          (loop (- i 1)) 'failed))))
(loop 10)