In future just use define-unparser-method.
a procedure of two arguments (the unparser state and the structure
instance) rather than three as in Common Lisp.
-* There is an additional option PRINT-ENTITY-PROCEDURE, used to print
- an entity whose extra object is a structure instance.
-
* By default, named structures are tagged with a unique object of some
kind. In Common Lisp, the structures are tagged with symbols, but
that depends on the Common Lisp package system to help generate
,@(accessor-definitions structure)
,@(modifier-definitions structure)
,@(predicate-definitions structure)
- ,@(copier-definitions structure))))))))
+ ,@(copier-definitions structure)
+ ,@(printer-definitions structure))))))))
\f
;;;; Parse options
(copier-option (find-option 'COPIER options))
(predicate-option (find-option 'PREDICATE options))
(print-procedure-option (find-option 'PRINT-PROCEDURE options))
- (print-entity-procedure-option
- (find-option 'PRINT-ENTITY-PROCEDURE options))
(type-option (find-option 'TYPE options))
(type-descriptor-option (find-option 'TYPE-DESCRIPTOR options))
(named-option (find-option 'NAMED options))
(check-for-illegal-untyped named-option initial-offset-option))
(if (not tagged?)
(check-for-illegal-untagged predicate-option
- print-procedure-option
- print-entity-procedure-option))
+ print-procedure-option))
(do ((slots slots (cdr slots))
(index (if tagged? (+ offset 1) offset) (+ index 1)))
((not (pair? slots)))
(option/argument print-procedure-option)
(and type-option
(default-unparser-text context)))
- (if print-entity-procedure-option
- (option/argument print-entity-procedure-option)
- #f)
(if type-option
(option/argument type-option)
'RECORD)
(lose initial-offset-option))))
(define (check-for-illegal-untagged predicate-option
- print-procedure-option
- print-entity-procedure-option)
+ print-procedure-option)
(let ((test
(lambda (option)
(if (and option
(error "Structure option illegal for unnamed structure:"
(option/original option))))))
(test predicate-option)
- (test print-procedure-option)
- (test print-entity-procedure-option)))
+ (test print-procedure-option)))
(define (compute-constructors constructor-options
keyword-constructor-options
(lambda (arg)
`(PRINT-PROCEDURE ,(if (false-expression? arg context) #f arg))))))
-(define-option 'PRINT-ENTITY-PROCEDURE #f
- (lambda (option context)
- (one-required-argument option
- (lambda (arg)
- `(PRINT-ENTITY-PROCEDURE
- ,(if (false-expression? arg context) #f arg))))))
-
(define-option 'TYPE #f
(lambda (option context)
context
(define-record-type <structure>
(make-structure context conc-name constructors keyword-constructors copier
- predicate print-procedure print-entity-procedure
- physical-type named? type-descriptor tag-expression
- safe-accessors? offset slots)
+ predicate print-procedure physical-type named?
+ type-descriptor tag-expression safe-accessors? offset slots)
structure?
(context structure/context)
(conc-name structure/conc-name)
(copier structure/copier)
(predicate structure/predicate)
(print-procedure structure/print-procedure)
- (print-entity-procedure structure/print-entity-procedure)
(physical-type structure/physical-type)
(named? structure/tagged?)
(type-descriptor structure/type-descriptor)
(let ((type-name (structure/type-descriptor structure))
(tag-expression (structure/tag-expression structure))
(slots (structure/slots structure))
- (context (structure/context structure))
- (print-procedure (structure/print-procedure structure))
- (print-entity-procedure (structure/print-entity-procedure structure)))
+ (context (structure/context structure)))
(let ((name (symbol->string (parser-context/name context)))
(field-names (map slot/name slots))
(inits
`(,(absolute 'MAKE-RECORD-TYPE context)
',name
',field-names
- (LIST ,@inits)
- ,(close print-procedure context)
- ,@(if print-entity-procedure
- (list (close print-entity-procedure context))
- '()))
+ (LIST ,@inits))
`(,(absolute 'MAKE-DEFINE-STRUCTURE-TYPE context)
',(structure/physical-type structure)
',name
'#(,@field-names)
'#(,@(map slot/index slots))
(VECTOR ,@inits)
- ,(if (structure/tagged? structure)
- (close print-procedure context)
- '#F)
+ ;; This field was the print-procedure, no longer used.
+ ;; It should be removed after 9.3 is released.
+ #f
,(if (and tag-expression
(not (eq? tag-expression type-name)))
(close tag-expression context)
'#F)
',(+ (if (structure/tagged? structure) 1 0)
(structure/offset structure)
- (length slots))
- ,@(if (and (structure/tagged? structure)
- print-entity-procedure)
- (list (close print-entity-procedure context))
- '()))))
+ (length slots)))))
,@(if (and tag-expression
(not (eq? tag-expression type-name)))
`((,(absolute 'NAMED-STRUCTURE/SET-TAG-DESCRIPTION! context)
,(close tag-expression context)
,type-name))
- '())))))
\ No newline at end of file
+ '())))))
+
+(define (printer-definitions structure)
+ (if (and (structure/predicate structure)
+ (or (structure/record-type? structure)
+ (structure/tagged? structure)))
+ (let ((context (structure/context structure)))
+ `((define-unparser-method
+ ,(close (structure/predicate structure) context)
+ ,(close (structure/print-procedure structure) context))))
+ '()))
\ No newline at end of file
(make-prefix-node prefix
(numerical-walk (cadr object)
list-depth))
- (let ((unparser (unparse-list/unparser object)))
- (if unparser
- (walk-custom unparser object list-depth)
- (walk-pair object list-depth))))))
+ (walk-pair object list-depth))))
((symbol? object)
(if (or (get-param:pp-uninterned-symbols-by-name?)
(interned-symbol? object))
((vector? object)
(if (zero? (vector-length object))
(walk-custom unparse-object object list-depth)
- (let ((unparser (unparse-vector/unparser object)))
- (if unparser
- (walk-custom unparser object list-depth)
- (make-prefix-node "#"
- (walk-pair (vector->list object)
- list-depth))))))
+ (make-prefix-node "#"
+ (walk-pair (vector->list object)
+ list-depth))))
((primitive-procedure? object)
(if (get-param:pp-primitives-by-name?)
(primitive-procedure-name object)
(make-list-node
(numerical-walk (car pair) list-depth)
(let ((list-breadth (+ list-breadth 1)))
- (if (and (pair? (cdr pair))
- (not (unparse-list/unparser (cdr pair))))
+ (if (pair? (cdr pair))
(loop (cdr pair) list-breadth)
(make-list-node
"."
(cadr object)
(advance half-pointer (update-queue queue '(CDR CAR)))
list-depth))
- (let ((unparser (unparse-list/unparser object)))
- (if unparser
- (walk-custom unparser object list-depth)
- (walk-pair-terminating object half-pointer/queue
- list-depth))))))
+ (walk-pair-terminating object half-pointer/queue
+ list-depth))))
((symbol? object)
(if (or (get-param:pp-uninterned-symbols-by-name?)
(interned-symbol? object))
((vector? object)
(if (zero? (vector-length object))
(walk-custom unparse-object object list-depth)
- (let ((unparser (unparse-vector/unparser object)))
- (if unparser
- (walk-custom unparser object list-depth)
- (make-prefix-node
- "#"
- (walk-vector-terminating
- (vector->list object)
- half-pointer/queue list-depth))))))
+ (make-prefix-node
+ "#"
+ (walk-vector-terminating
+ (vector->list object)
+ half-pointer/queue list-depth))))
((primitive-procedure? object)
(if (get-param:pp-primitives-by-name?)
(primitive-procedure-name object)
(car pair) half-pointer/queue list-depth)))
(let ((list-breadth (+ list-breadth 1)))
(if
- (and (pair? (cdr pair))
- (not (unparse-list/unparser (cdr pair))))
+ (pair? (cdr pair))
(let ((half-pointer/queue
(advance
(car half-pointer/queue)
(circularity-string (cdr half-pointer/queue))
(numerical-walk-terminating
(car pair) half-pointer/queue list-depth)))
- (let ((list-breadth (+ list-breadth 1)))
- (if (not (unparse-list/unparser (cdr pair)))
- (loop (cdr pair) list-breadth)
- (make-list-node
- "."
- (make-singleton-list-node
- (if (let ((limit
- (get-param:unparser-list-breadth-limit)))
- (and limit
- (>= list-breadth limit)
- (no-highlights? pair)))
- "..."
- (numerical-walk-terminating
- (cdr pair)
- half-pointer/queue list-depth)))))))))))))
+ (loop (cdr pair) (+ list-breadth 1)))))))))
\f
;;;; These procedures allow the walkers to interact with the queue.
(define (make-record-type type-name field-names
#!optional
default-inits unparser-method entity-unparser-method)
+ ;; The unparser-method and entity-unparser-method arguments should be removed
+ ;; after the 9.3 release.
(let ((caller 'MAKE-RECORD-TYPE))
(if (not (list-of-unique-symbols? field-names))
(error:not-a list-of-unique-symbols? field-names caller))
(%record-set! record-type 1 tag)
(if (not (default-object? default-inits))
(%set-record-type-default-inits! record-type default-inits caller))
- (%set-record-type-predicate! record-type
- (lambda (object)
- (%tagged-record? tag object)))
- (%set-record-type-entity-predicate! record-type
- (lambda (object)
- (%tagged-record-entity? tag object)))
- (if (and unparser-method
- (not (default-object? unparser-method)))
- (set-record-type-unparser-method! record-type unparser-method))
- (if (and entity-unparser-method
- (not (default-object? entity-unparser-method)))
- (set-record-type-entity-unparser-method! record-type
- entity-unparser-method))
+ (let ((predicate
+ (lambda (object)
+ (%tagged-record? tag object)))
+ (entity-predicate
+ (lambda (object)
+ (%tagged-record-entity? tag object))))
+ (%set-record-type-predicate! record-type predicate)
+ (%set-record-type-entity-predicate! record-type entity-predicate)
+ (if (and unparser-method
+ (not (default-object? unparser-method)))
+ (define-unparser-method predicate unparser-method))
+ (if (and entity-unparser-method
+ (not (default-object? entity-unparser-method)))
+ (define-unparser-method entity-predicate entity-unparser-method)))
record-type)))
(define (record-type? object)
(define (set-record-type-describer! record-type describer)
(define-pp-describer (record-predicate record-type)
describer))
-
+\f
(define (set-record-type-entity-unparser-method! record-type method)
(define-unparser-method (record-entity-predicate record-type)
method))
(set! rtd:structure-type
(make-record-type "structure-type"
'(PHYSICAL-TYPE NAME FIELD-NAMES FIELD-INDEXES
- DEFAULT-INITS UNPARSER-METHOD TAG
- LENGTH ENTITY-UNPARSER-METHOD)))
+ DEFAULT-INITS TAG LENGTH)))
(set! make-define-structure-type
(let ((constructor (record-constructor rtd:structure-type)))
(lambda (physical-type name field-names field-indexes default-inits
- unparser-method tag length
- #!optional entity-unparser-method)
+ unparser-method tag length)
+ ;; unparser-method arg should be removed after 9.3 is released.
+ (declare (ignore unparser-method))
(constructor physical-type
name
field-names
field-indexes
default-inits
- unparser-method
tag
- length
- (if (default-object? entity-unparser-method)
- #f
- entity-unparser-method)))))
+ length))))
(set! structure-type?
(record-predicate rtd:structure-type))
(set! structure-type/physical-type
(record-accessor rtd:structure-type 'FIELD-INDEXES))
(set! structure-type/default-inits
(record-accessor rtd:structure-type 'DEFAULT-INITS))
- (set! structure-type/unparser-method
- (record-accessor rtd:structure-type 'UNPARSER-METHOD))
- (set! set-structure-type/unparser-method!
- (record-modifier rtd:structure-type 'UNPARSER-METHOD))
(set! structure-type/tag
(record-accessor rtd:structure-type 'TAG))
(set! structure-type/length
(record-accessor rtd:structure-type 'LENGTH))
- (set! structure-type/entity-unparser-method
- (record-accessor rtd:structure-type 'ENTITY-UNPARSER-METHOD))
- (set! set-structure-type/entity-unparser-method!
- (record-modifier rtd:structure-type 'ENTITY-UNPARSER-METHOD))
unspecific)
\f
(define rtd:structure-type)
(define set-structure-type/unparser-method!)
(define structure-type/tag)
(define structure-type/length)
-(define structure-type/entity-unparser-method)
-(define set-structure-type/entity-unparser-method!)
(define-integrable (structure-type/field-index type field-name)
(vector-ref (structure-type/field-indexes type)
i
(loop (fix:+ i 1)))))))
\f
-(define (structure-tag/unparser-method tag physical-type)
- (and (structure-type-tag? tag physical-type)
- (structure-type/unparser-method (tag->structure-type tag))))
-
-(define (structure-tag/entity-unparser-method tag physical-type)
- (and (structure-type-tag? tag physical-type)
- (structure-type/entity-unparser-method (tag->structure-type tag))))
-
(define (named-structure? object)
(or (named-list? object)
(named-vector? object)
error:no-such-slot
error:uninitialized-slot
record-type-field-index)
- (export (runtime unparser)
- structure-tag/entity-unparser-method
- structure-tag/unparser-method)
(export (runtime predicate-metadata)
cleanup-boot-time-record-predicates!)
(export (runtime predicate-tagging)
get-param:unparser-list-breadth-limit
get-param:unparser-list-depth-limit
make-unparser-state
- unparse-list/prefix-pair?
- unparse-list/unparser
- unparse-vector/unparser)
+ unparse-list/prefix-pair?)
(export (runtime record)
(rtd:unparser-state <context>)))
(loop (fix:- index 1))))))
\f
(define (unparse/vector vector context)
- (let ((method (unparse-vector/unparser vector)))
- (if method
- (invoke-user-method method vector context)
- (unparse-vector/normal vector context))))
-
-(define (unparse-vector/unparser vector)
- (and (fix:> (vector-length vector) 0)
- (let ((tag (safe-vector-ref vector 0)))
- (or (structure-tag/unparser-method tag 'VECTOR)
- ;; Check the global tagging table too.
- (unparser/tagged-vector-method tag)))))
-
-(define (unparse-vector/entity-unparser vector)
- (and (fix:> (vector-length vector) 0)
- (structure-tag/entity-unparser-method (safe-vector-ref vector 0)
- 'VECTOR)))
-
-(define (unparse-vector/normal vector context)
(limit-unparse-depth context
(lambda (context*)
(let ((end (vector-length vector)))
(define (unparse/pair pair context)
(cond ((unparse-list/prefix-pair? pair)
=> (lambda (prefix) (unparse-list/prefix-pair prefix pair context)))
- ((unparse-list/unparser pair)
- => (lambda (method) (invoke-user-method method pair context)))
((and (get-param:unparse-streams?) (stream-pair? pair))
(unparse-list/stream-pair pair context))
(else
(define (unparse-tail l n context)
(cond ((pair? l)
- (let ((method (unparse-list/unparser l)))
- (if method
- (begin
- (*unparse-string " . " context)
- (invoke-user-method method l context))
- (begin
- (*unparse-char #\space context)
- (*unparse-object (safe-car l) context)
- (if (let ((limit (context-list-breadth-limit context)))
- (and limit
- (>= n limit)
- (pair? (safe-cdr l))))
- (*unparse-string " ..." context)
- (unparse-tail (safe-cdr l) (+ n 1) context))))))
+ (*unparse-char #\space context)
+ (*unparse-object (safe-car l) context)
+ (if (let ((limit (context-list-breadth-limit context)))
+ (and limit
+ (>= n limit)
+ (pair? (safe-cdr l))))
+ (*unparse-string " ..." context)
+ (unparse-tail (safe-cdr l) (+ n 1) context)))
((not (null? l))
(*unparse-string " . " context)
(*unparse-object l context))))
-
-(define (unparse-list/unparser pair)
- (let ((tag (safe-car pair)))
- (or (structure-tag/unparser-method tag 'LIST)
- ;; Check the global tagging table too.
- (unparser/tagged-pair-method tag))))
\f
-(define (unparse-list/entity-unparser pair)
- (structure-tag/entity-unparser-method (safe-car pair) 'LIST))
-
(define (unparse-list/prefix-pair prefix pair context)
(*unparse-string prefix context)
(*unparse-object (safe-car (safe-cdr pair)) context))
(else (plain 'ARITY-DISPATCHED-PROCEDURE)))))
((get-param:unparse-with-maximum-readability?)
(*unparse-readable-hash entity context))
- ((or (and (vector? (%entity-extra entity))
- (unparse-vector/entity-unparser (%entity-extra entity)))
- (and (pair? (%entity-extra entity))
- (unparse-list/entity-unparser (%entity-extra entity))))
- => (lambda (method)
- (invoke-user-method method entity context)))
(else (plain 'ENTITY))))
(define (unparse/promise promise context)