#| -*-Scheme-*-
-$Id: defstr.scm,v 14.50 2003/03/12 20:40:28 cph Exp $
+$Id: defstr.scm,v 14.51 2003/03/13 03:57:42 cph Exp $
Copyright 1987,1988,1989,1990,1991,1992 Massachusetts Institute of Technology
Copyright 1993,1994,1995,1996,1997,2000 Massachusetts Institute of Technology
(initial-offset-option (find-option 'INITIAL-OFFSET options)))
(check-for-duplicate-constructors constructor-options
keyword-constructor-options)
- (if (and type-descriptor-option named-option)
- (error "Conflicting structure options:"
- (option/original type-descriptor-option)
- (option/original named-option)))
(let ((tagged?
(or (not type-option)
- type-descriptor-option
named-option))
(offset
(if initial-offset-option
(if (not tagged?)
(check-for-illegal-untagged predicate-option
print-procedure-option))
+ (if (and type-descriptor-option
+ (not (option/argument type-descriptor-option)))
+ (check-for-illegal-no-descriptor type-descriptor-option
+ tagged?
+ safe-accessors-option
+ keyword-constructor-options))
(do ((slots slots (cdr slots))
(index (if tagged? (+ offset 1) offset) (+ index 1)))
((not (pair? slots)))
(option/argument type-option)
'RECORD)
tagged?
- (and tagged? type-name)
+ type-name
(and tagged? tag-expression)
(and safe-accessors-option
(option/argument safe-accessors-option))
(let ((option (car options))
(options (cdr options)))
(let ((conflict
- (let ((name (car (option/arguments option))))
+ (let ((name (option/argument option)))
(and name
(find-matching-item options
(lambda (option*)
- (eq? (car (option/arguments option*))
- name)))))))
+ (eq? (option/argument option*) name)))))))
(if conflict
(error "Conflicting constructor definitions:"
(option/original option)
(error "Structure option illegal without TYPE option:"
(option/original option)))))
(if (and named-option
- (let ((arguments (option/arguments named-option)))
- (and (pair? arguments)
- (not (car arguments)))))
+ (pair? (option/arguments named-option))
+ (not (option/argument named-option)))
(lose named-option))
(if initial-offset-option
(lose initial-offset-option))))
-
+\f
(define (check-for-illegal-untagged predicate-option print-procedure-option)
(let ((test
(lambda (option)
(test predicate-option)
(test print-procedure-option)))
+(define (check-for-illegal-no-descriptor type-descriptor-option
+ tagged?
+ safe-accessors-option
+ keyword-constructor-options)
+ (if tagged?
+ (error "Structure option illegal for tagged structure:"
+ (option/original type-descriptor-option))
+ (let ((lose
+ (lambda (option)
+ (error "Structure option illegal without type descriptor:"
+ (option/original option)))))
+ (cond ((and safe-accessors-option
+ (option/argument safe-accessors-option))
+ (lose safe-accessors-option))
+ (keyword-constructor-options
+ (lose (car keyword-constructor-options)))))))
+
(define (compute-constructors constructor-options
keyword-constructor-options
context)
(else (list (list (default-constructor-name context)))))))
(define (compute-tagging-info type-descriptor-option named-option context)
- (let ((single (lambda (name) (values name name))))
- (cond (type-descriptor-option
- (single (option/argument type-descriptor-option)))
- (named-option
- (let ((arguments (option/arguments named-option)))
- (if (pair? arguments)
- (values #f (car arguments))
- (single (default-type-name context)))))
- (else
- (single (default-type-name context))))))
+ (let ((type-name
+ (if type-descriptor-option
+ (option/argument type-descriptor-option)
+ (default-type-name context))))
+ (values type-name
+ (or (and named-option
+ (pair? (option/arguments named-option))
+ (option/argument named-option))
+ type-name))))
\f
(define (false-expression? object context)
(or (let loop ((object object))
#F))
(define (default-type-name context)
- (parser-context/name context))
+ (symbol-append 'RTD: (parser-context/name context)))
\f
(define (apply-option-transformers options context)
(let loop ((options options))
context
(one-required-argument option
(lambda (arg)
- (if (identifier? arg)
+ (if (or (identifier? arg) (not arg))
`(TYPE-DESCRIPTOR ,arg)
#f)))))
(define-record-type <structure>
(make-structure context conc-name constructors keyword-constructors copier
- predicate print-procedure 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)
- (type structure/type)
+ (physical-type structure/physical-type)
(named? structure/tagged?)
(type-descriptor structure/type-descriptor)
(tag-expression structure/tag-expression)
name))))
(if (structure/safe-accessors? structure)
`(DEFINE ,accessor-name
- (,(absolute (case (structure/type structure)
+ (,(absolute (case (structure/physical-type structure)
((RECORD) 'RECORD-ACCESSOR)
((VECTOR) 'DEFINE-STRUCTURE/VECTOR-ACCESSOR)
((LIST) 'DEFINE-STRUCTURE/LIST-ACCESSOR))
context)
- ,(let ((tag (structure/tag-expression structure)))
- (if tag
- (close tag context)
- (slot/index slot)))
+ ,(close (structure/type-descriptor structure) context)
',name))
`(DEFINE-INTEGRABLE (,accessor-name STRUCTURE)
- (,(absolute (case (structure/type structure)
+ (,(absolute (case (structure/physical-type structure)
((RECORD) '%RECORD-REF)
((VECTOR) 'VECTOR-REF)
((LIST) 'LIST-REF))
(symbol-append 'SET- name '!)))))
(if (structure/safe-accessors? structure)
`(DEFINE ,modifier-name
- (,(absolute (case (structure/type structure)
+ (,(absolute (case (structure/physical-type structure)
((RECORD) 'RECORD-MODIFIER)
((VECTOR) 'DEFINE-STRUCTURE/VECTOR-MODIFIER)
((LIST) 'DEFINE-STRUCTURE/LIST-MODIFIER))
context)
- ,(let ((tag (structure/tag-expression structure)))
- (if tag
- (close tag context)
- (slot/index slot)))
+ ,(close (structure/type-descriptor structure) context)
',name))
`(DEFINE-INTEGRABLE (,modifier-name STRUCTURE VALUE)
- ,(case (structure/type structure)
+ ,(case (structure/physical-type structure)
((RECORD)
`(,(absolute '%RECORD-SET! context) STRUCTURE
,(slot/index slot)
(let ((slot-names (map slot/name (structure/slots structure))))
(make-constructor structure name slot-names
(lambda (tag-expression)
- `(,(absolute (case (structure/type structure)
+ `(,(absolute (case (structure/physical-type structure)
((RECORD) '%RECORD)
((VECTOR) 'VECTOR)
((LIST) 'LIST))
(define (constructor-definition/keyword structure name)
(let ((context (structure/context structure)))
- (if (eq? (structure/type structure) 'RECORD)
- `(DEFINE ,name
- (,(absolute 'RECORD-KEYWORD-CONSTRUCTOR context)
- ,(close (structure/tag-expression structure) context)))
- (make-constructor structure name 'KEYWORD-LIST
- (lambda (tag-expression)
- (let ((list-cons
- `(,@(constructor-prefix-slots structure tag-expression)
- (,(absolute 'DEFINE-STRUCTURE/KEYWORD-PARSER context)
- ,tag-expression
- KEYWORD-LIST))))
- (case (structure/type structure)
- ((VECTOR)
- `(,(absolute 'APPLY context) ,(absolute 'VECTOR context)
- ,@list-cons))
- ((LIST)
- `(,(absolute 'CONS* context) ,@list-cons)))))))))
+ (let ((type-descriptor
+ (close (structure/type-descriptor structure) context)))
+ (if (eq? (structure/physical-type structure) 'RECORD)
+ `(DEFINE ,name
+ (,(absolute 'RECORD-KEYWORD-CONSTRUCTOR context)
+ ,type-descriptor))
+ (make-constructor structure name 'KEYWORD-LIST
+ (lambda (tag-expression)
+ (let ((list-cons
+ `(,@(constructor-prefix-slots structure tag-expression)
+ (,(absolute 'DEFINE-STRUCTURE/KEYWORD-PARSER context)
+ ,type-descriptor
+ KEYWORD-LIST))))
+ (case (structure/physical-type structure)
+ ((VECTOR)
+ `(,(absolute 'APPLY context) ,(absolute 'VECTOR context)
+ ,@list-cons))
+ ((LIST)
+ `(,(absolute 'CONS* context) ,@list-cons))))))))))
\f
(define (constructor-definition/boa structure name lambda-list)
(make-constructor structure name lambda-list
(lambda (tag-expression)
- (let ((type (structure/type structure))
+ (let ((type (structure/physical-type structure))
(context (structure/context structure)))
`(,(absolute (case type
((RECORD) '%RECORD)
'RECORD-TYPE-DEFAULT-VALUE
context)
,(close
- (structure/tag-expression
+ (structure/type-descriptor
structure)
context)
',name))
(structure/slots structure)))))))))))
(define (make-constructor structure name lambda-list generate-body)
- (let* ((context (structure/context structure))
- (tag-expression (close (structure/tag-expression structure) context)))
- (if (eq? (structure/type structure) 'RECORD)
+ (let ((tag-expression
+ (close (structure/tag-expression structure)
+ (structure/context structure))))
+ (if (eq? (structure/physical-type structure) 'RECORD)
(let ((tag (make-synthetic-identifier 'TAG)))
`(DEFINE ,name
(LET ((,tag (RECORD-TYPE-DISPATCH-TAG ,tag-expression)))
(let ((copier-name (structure/copier structure)))
(if copier-name
`((DEFINE ,copier-name
- ,(absolute (case (structure/type structure)
+ ,(absolute (case (structure/physical-type structure)
((RECORD) 'COPY-RECORD)
((VECTOR) 'VECTOR-COPY)
((LIST) 'LIST-COPY))
(let* ((context (structure/context structure))
(tag-expression
(close (structure/tag-expression structure) context)))
- (case (structure/type structure)
+ (case (structure/physical-type structure)
((RECORD)
`((DEFINE ,predicate-name
(LET ((TAG (RECORD-TYPE-DISPATCH-TAG ,tag-expression)))
'())))
(define (type-definitions structure)
- (if (structure/tagged? structure)
- (let ((type (structure/type structure))
- (type-name (structure/type-descriptor structure))
- (slots (structure/slots structure))
- (context (structure/context structure))
- (print-procedure (structure/print-procedure structure)))
+ (let ((physical-type (structure/physical-type structure))
+ (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)))
+ (if type-name
(let ((name (symbol->string (parser-context/name context)))
(field-names (map slot/name slots))
(inits
(map (lambda (slot)
`(LAMBDA () ,(close (slot/default slot) context)))
slots)))
- (let ((type-expression
- (if (eq? type 'RECORD)
- `(,(absolute 'MAKE-RECORD-TYPE context)
- ',name
- ',field-names
- (LIST ,@inits)
- ,(close print-procedure context))
- `(,(absolute 'MAKE-DEFINE-STRUCTURE-TYPE context)
- ',type
- ',name
- ',field-names
- ',(map slot/index (structure/slots structure))
- (LIST ,@inits)
- ,(close print-procedure context)))))
- (if type-name
- `((DEFINE ,type-name ,type-expression))
- `((,(absolute 'NAMED-STRUCTURE/SET-TAG-DESCRIPTION!
- context)
- ,(close (structure/tag-expression structure) context)
- ,type-expression))))))
- '()))
\ No newline at end of file
+ `((DEFINE ,type-name
+ ,(if (eq? physical-type 'RECORD)
+ `(,(absolute 'MAKE-RECORD-TYPE context)
+ ',name
+ ',field-names
+ (LIST ,@inits)
+ ,(close print-procedure context))
+ `(,(absolute 'MAKE-DEFINE-STRUCTURE-TYPE context)
+ ',physical-type
+ ',name
+ ',field-names
+ ',(map slot/index (structure/slots structure))
+ (LIST ,@inits)
+ ,(if (structure/tagged? structure)
+ (close print-procedure context)
+ '#F)
+ ,(if (and tag-expression
+ (not (eq? tag-expression type-name)))
+ (close tag-expression context)
+ '#F)
+ ',(structure/offset structure))))
+ ,@(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
#| -*-Scheme-*-
-$Id: record.scm,v 1.39 2003/03/12 20:41:42 cph Exp $
+$Id: record.scm,v 1.40 2003/03/13 03:58:18 cph Exp $
Copyright 1989,1990,1991,1993,1994,1996 Massachusetts Institute of Technology
Copyright 1997,2002,2003 Massachusetts Institute of Technology
(define <structure-type>)
(define make-define-structure-type)
(define structure-type?)
-(define structure-type/type)
+(define structure-type/physical-type)
(define structure-type/name)
(define structure-type/field-names)
(define structure-type/field-indexes)
(define structure-type/default-inits)
(define structure-type/unparser-method)
(define set-structure-type/unparser-method!)
+(define structure-type/tag)
+(define structure-type/offset)
(define (initialize-structure-type-type!)
(set! <structure-type>
(make-record-type "structure-type"
- '(TYPE NAME FIELD-NAMES FIELD-INDEXES
- DEFAULT-INITS UNPARSER-METHOD)))
+ '(PHYSICAL-TYPE NAME FIELD-NAMES FIELD-INDEXES
+ DEFAULT-INITS UNPARSER-METHOD TAG
+ OFFSET)))
(set! make-define-structure-type
(let ((constructor (record-constructor <structure-type>)))
- (lambda (type name field-names field-indexes v1 #!optional v2)
- (receive (default-inits unparser-method)
- (if (default-object? v2)
- (values #f v1)
- (values v1 v2))
- (constructor type name
+ (lambda (physical-type name field-names field-indexes . rest)
+ (receive (default-inits unparser-method tag offset)
+ (case (length rest)
+ ((1) (values #f (car rest) physical-type 0))
+ ((2) (values (car rest) (cadr rest) physical-type 0))
+ ((4) (apply values rest))
+ (else
+ (error:wrong-number-of-arguments
+ 'MAKE-DEFINE-STRUCTURE-TYPE
+ 8
+ (cons* physical-type name field-names field-indexes
+ rest))))
+ (constructor physical-type
+ name
(list->vector field-names)
(list->vector field-indexes)
(if default-inits
(list->vector default-inits)
(make-vector (length field-names)
(lambda () #f)))
- unparser-method)))))
+ unparser-method
+ tag
+ offset)))))
(set! structure-type?
(record-predicate <structure-type>))
- (set! structure-type/type
- (record-accessor <structure-type> 'TYPE))
+ (set! structure-type/physical-type
+ (record-accessor <structure-type> 'PHYSICAL-TYPE))
(set! structure-type/name
(record-accessor <structure-type> 'NAME))
(set! structure-type/field-names
(record-accessor <structure-type> 'UNPARSER-METHOD))
(set! set-structure-type/unparser-method!
(record-modifier <structure-type> 'UNPARSER-METHOD))
+ (set! structure-type/tag
+ (record-accessor <structure-type> 'TAG))
+ (set! structure-type/offset
+ (record-accessor <structure-type> 'OFFSET))
unspecific)
\f
(define (structure-tag/unparser-method tag type)
(define (tag->structure-type tag type)
(if (structure-type? tag)
- (and (eq? (structure-type/type tag) type)
+ (and (eq? (structure-type/physical-type tag) type)
tag)
(let ((structure-type (named-structure/get-tag-description tag)))
(and (structure-type? structure-type)
- (eq? (structure-type/type structure-type) type)
+ (eq? (structure-type/physical-type structure-type) type)
structure-type))))
(define (structure-tag/default-value tag type field-name)