boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

115-gc-live-identity.scm (693B)


      1 ; Live pairs, cycles, closures, and bytevector RAW storage retain identity
      2 ; and mutations across repeated collections.
      3 
      4 (define p (cons 1 2))
      5 (set-cdr! p p)
      6 (define same p)
      7 (define bv (bytevector 1 2 3 4 5))
      8 (define make-adder (lambda (x) (lambda (y) (+ x y))))
      9 (define add7 (make-adder 7))
     10 
     11 (define (garbage n)
     12   (if (= n 0) #f (begin (cons n (make-bytevector 24 n)) (garbage (- n 1)))))
     13 
     14 (garbage 120)
     15 (collect-garbage)
     16 (set-car! p 9)
     17 (bytevector-u8-set! bv 2 99)
     18 (collect-garbage)
     19 
     20 (if (eq? p same) 0 (sys-exit 1))
     21 (if (= (car p) 9) 0 (sys-exit 2))
     22 (if (eq? p (cdr p)) 0 (sys-exit 3))
     23 (if (= (bytevector-u8-ref bv 2) 99) 0 (sys-exit 4))
     24 (if (= (add7 35) 42) 0 (sys-exit 5))
     25 
     26 (sys-exit 42)