refactor record type bootstrap
This commit is contained in:
parent
0eecddb5da
commit
8a5a3e6b97
|
@ -746,32 +746,34 @@
|
||||||
|
|
||||||
;; 5.5 Recored-type definitions
|
;; 5.5 Recored-type definitions
|
||||||
|
|
||||||
(import (picrin record))
|
(import (picrin record)
|
||||||
|
(scheme write))
|
||||||
|
|
||||||
(define <record-type> #t) ; bootstrap
|
(define ((default-record-writer ctor) obj)
|
||||||
|
(let ((port (open-output-string)))
|
||||||
|
(display "#.(" port)
|
||||||
|
(display (car ctor) port)
|
||||||
|
(for-each
|
||||||
|
(lambda (field)
|
||||||
|
(display " " port)
|
||||||
|
(write (record-ref obj field) port))
|
||||||
|
(cdr ctor))
|
||||||
|
(display ")" port)
|
||||||
|
(get-output-string port)))
|
||||||
|
|
||||||
(import (scheme write))
|
(define ((boot-make-record-type <meta-type>) name ctor)
|
||||||
|
(let ((rectype (make-record <meta-type>)))
|
||||||
(define (make-record-type name ctor)
|
|
||||||
(let ((rectype (make-record <record-type>)))
|
|
||||||
(record-set! rectype 'name name)
|
(record-set! rectype 'name name)
|
||||||
(record-set! rectype 'writer (lambda (obj)
|
(record-set! rectype 'writer (default-record-writer ctor))
|
||||||
(let ((port (open-output-string)))
|
|
||||||
(display "#.(" port)
|
|
||||||
(display (car ctor) port)
|
|
||||||
(for-each
|
|
||||||
(lambda (field)
|
|
||||||
(display " " port)
|
|
||||||
(write (record-ref obj field) port))
|
|
||||||
(cdr ctor))
|
|
||||||
(display ")" port)
|
|
||||||
(get-output-string port))))
|
|
||||||
rectype))
|
rectype))
|
||||||
|
|
||||||
(set! <record-type>
|
(define <record-type>
|
||||||
(let ((<record-type> (make-record-type '<record-type> '(name writer))))
|
(let ((<record-type>
|
||||||
(record-set! <record-type> '@@type <record-type>)
|
((boot-make-record-type #t) 'record-type '(record-type name writer))))
|
||||||
<record-type>))
|
(record-set! <record-type> '@@type <record-type>)
|
||||||
|
<record-type>))
|
||||||
|
|
||||||
|
(define make-record-type (boot-make-record-type <record-type>))
|
||||||
|
|
||||||
(define-syntax define-record-constructor
|
(define-syntax define-record-constructor
|
||||||
(ir-macro-transformer
|
(ir-macro-transformer
|
||||||
|
|
Loading…
Reference in New Issue