boot2

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

124-scratch-record-type.scm (735B)


      1 ; define-record-type installs process-global metadata. Defining a type
      2 ; while scratch is current must not leave its TD / generated PRIMs /
      3 ; field-name list in scratch.
      4 
      5 (use-scratch-heap!)
      6 (define-record-type dyn
      7   (mk-dyn x y)
      8   dyn?
      9   (x dyn-x)
     10   (y dyn-y dyn-y-set!))
     11 (reset-scratch-heap!)
     12 (use-main-heap!)
     13 
     14 (define d (mk-dyn 7 8))
     15 (if (dyn? d) 0 (sys-exit 1))
     16 (if (= 7 (dyn-x d)) 0 (sys-exit 2))
     17 (if (= 8 (dyn-y d)) 0 (sys-exit 3))
     18 (dyn-y-set! d 9)
     19 (if (= 9 (dyn-y d)) 0 (sys-exit 4))
     20 
     21 ;; pmatch uses the TD.fields list, so this also checks that the field-name
     22 ;; metadata survived the scratch reset.
     23 (if (= 16
     24        (pmatch d
     25          (($ dyn? (x ,a) (y ,b)) (+ a b))
     26          (else 0)))
     27     0
     28     (sys-exit 5))
     29 
     30 (sys-exit 42)