(export (make-record-type record-constructor record-predicate record-accessor record-updater)
;;; Bootstrapping descriptors
(make-record-type 'descriptor '(
name ; first arg to make-record-type for this descriptor
size ; how many slots in the whole record, with cookies?
field-map ; a-list mapping field names to slot indices (in order)
all-field-map ; same, but including ancestor fields (parent first)
indices ; (map cdr all-field-map)
cookie-map ; list of pairs: (cookie index); gives cookie locations
; in decreasing order of index (i.e., child first)
print-proc ; client-defined print proc or #f
))
(define descriptor-cookie #f)
(define (make-descriptor name size field-map all-field-map
indices cookie-map print-proc)
(let ((record (%make-record 8)))
(%record-set! record 0 descriptor-cookie)
(%record-set! record 1 name)
(%record-set! record 2 size)
(%record-set! record 3 field-map)
(%record-set! record 4 all-field-map)
(%record-set! record 5 indices)
(%record-set! record 6 cookie-map)
(%record-set! record 7 print-proc)
record))
(define (descriptor? value)
(and (%record? value)
(= 8 (%record-length value))
(eq? (%record-ref value 0) descriptor-cookie)))
(define ((make-descriptor-accessor name index) record)
(if (descriptor? record)
(%record-ref record index)
(error (format #f "~S accessor for record-type descriptors" name)
record
"not a record-type descriptor")))
(define descriptor-name #f)
(define descriptor-size #f)
(define descriptor-field-map #f)
(define descriptor-all-field-map #f)
(define descriptor-indices #f)
(define descriptor-cookie-map #f)
(define descriptor-print-proc #f)
(define (print-descriptor port descriptor display?)
(format port "#<Record-type descriptor: ~S>"
(descriptor-name descriptor)))
(set! descriptor-cookie (cons print-descriptor 8))
(set! descriptor-name (make-descriptor-accessor 'name 1))
(set! descriptor-size (make-descriptor-accessor 'size 2))
(set! descriptor-field-map (make-descriptor-accessor 'field-map 3))
(set! descriptor-all-field-map
(make-descriptor-accessor 'all-field-map 4))
(set! descriptor-indices (make-descriptor-accessor 'indices 5))
(set! descriptor-cookie-map (make-descriptor-accessor 'cookie-map 6))
(set! descriptor-print-proc (make-descriptor-accessor 'print-proc 7))