remove #;parent arg, xeno rename

main
Matthew Butterick 6 years ago
parent fc78111cd1
commit a14d4feddb

@ -14,7 +14,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
|#
(define x:array%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@type type)] [(@len len)] [(@length-type length-type)])
@ -32,7 +32,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
'_currentOffset 0
'_length @len)
parent))
(define len (resolve-length @len port #:parent parent))
(define len (resolve-length @len port parent))
(cond
[(or (not len) (eq? @length-type 'bytes))
(define end-pos (cond
@ -84,7 +84,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
(define items-size (for/sum ([item val])
(send @type x:size item new-parent)))
(+ items-size len-size)]
[else (define count (resolve-length @len #f #:parent parent))
[else (define count (resolve-length @len #f parent))
(define size (send @type x:size #f parent))
(* size count)]))))

@ -8,7 +8,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Bitfield.coffee
|#
(define x:bitfield%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@type type)][(@flags flags)])
(unless (andmap (λ (f) (or (symbol? f) (not f))) @flags)

@ -8,14 +8,14 @@ https://github.com/mbutterick/restructure/blob/master/src/Buffer.coffee
|#
(define x:buffer%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@len len)])
(unless (length-resolvable? @len)
(raise-argument-error '+xbuffer "resolvable length" @len))
(define/augment (x:decode port parent)
(define len (resolve-length @len port #:parent parent))
(define len (resolve-length @len port parent))
(read-bytes len))
(define/augment (x:encode buf port [parent #f])
@ -30,7 +30,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Buffer.coffee
(raise-argument-error 'xbuffer-size "bytes" val)))
(if (bytes? val)
(bytes-length val)
(resolve-length @len val #:parent parent)))))
(resolve-length @len val parent)))))
(define (x:buffer [len-arg #f]
#:length [len-kwarg #f]

@ -8,7 +8,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Enum.coffee
|#
(define x:enum%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@type type)] [(@values values)])

@ -38,7 +38,7 @@
(define (size xo [val #f] #:parent [parent #f])
(send xo x:size val parent)))])))
(define (xenomorphic-type? x) (is-a? x x:enobase%))
(define (xenomorphic-type? x) (is-a? x xenobase%))
(define-syntax-rule (generate-subclass CLASS PRE-ENCODE-PROC POST-DECODE-PROC)
(cond
@ -57,7 +57,7 @@
(define/override (post-decode x) (POST-DECODE-PROC (super post-decode x))))]
[else CLASS]))
(define x:enobase%
(define xenobase%
(class* object% (x:enomorphic<%>)
(super-new)

@ -15,7 +15,7 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
(define/override (x:decode port parent)
(define starting-pos (pos port)) ; ! placement matters. `resolve-length` will change `pos`
(define len (resolve-length @len port #:parent parent))
(define len (resolve-length @len port parent))
(define new-parent (if (x:int? @len)
(mhasheq 'parent parent
'_startOffset starting-pos

@ -24,7 +24,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(define system-endian (if (system-big-endian?) 'be 'le))
(define x:number%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@size size)] [(@endian endian)])

@ -8,7 +8,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Optional.coffee
|#
(define x:optional%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@type type)] [(@condition condition)])

@ -24,7 +24,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[else (raise-argument-error 'Pointer:size "VoidPointer" val)]))
(define x:pointer%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@offset-type offset-type)]
[(@type type)]
@ -112,7 +112,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[null-value null-value]))
;; A pointer whose type is determined at decode time
(define x:void-pointer% (class x:enobase%
(define x:void-pointer% (class xenobase%
(super-new)
(init-field type value)))
(define (x:void-pointer . args) (apply make-object x:void-pointer% args))

@ -8,12 +8,12 @@ https://github.com/mbutterick/restructure/blob/master/src/Reserved.coffee
|#
(define x:reserved%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@type type)] [(@count count)])
(unless (xenomorphic-type? @type)
(raise-argument-error '+xoptional"xenomorphic type" @type))
(raise-argument-error '+xoptional "xenomorphic type" @type))
(define/augment (x:decode port parent)
(pos port (+ (pos port) (x:size #f parent)))
@ -23,7 +23,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Reserved.coffee
(make-bytes (x:size val parent) 0))
(define/augment (x:size [val #f] [parent #f])
(* (send @type x:size) (resolve-length @count #f #:parent parent)))))
(* (send @type x:size) (resolve-length @count #f parent)))))
(define (x:reserved [type-arg #f] [count-arg #f]
#:type [type-kwarg #f]

@ -29,7 +29,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
(not (eof-object? (peek-byte port))))
(define x:string%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@len len)] [(@encoding encoding)])
@ -39,7 +39,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
(raise-argument-error 'xstring (format "procedure or member of ~v" supported-encodings) @encoding))
(define/augment (x:decode port parent)
(define len (or (resolve-length @len port #:parent parent) (count-nonzero-chars port)))
(define len (or (resolve-length @len port parent) (count-nonzero-chars port)))
(define encoding (if (procedure? @encoding)
(or (@encoding parent) 'ascii)
@encoding))
@ -77,7 +77,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
[(x:int? @len) (send @len x:size)]
[else 0]))
(+ string-size strlen-size)]
[else (resolve-length @len #f #:parent parent)]))))
[else (resolve-length @len #f parent)]))))
(define supported-encodings '(ascii utf8))
(define (x:string [len-arg #f] [enc-arg #f]

@ -46,7 +46,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
h)
(define x:struct%
(class x:enobase%
(class xenobase%
(super-new)
(init-field [(@fields fields)])

@ -5,7 +5,7 @@
(define (length-resolvable? x)
(or (not x) (symbol? x) (xenomorphic? x) (procedure? x) (exact-nonnegative-integer? x)))
(define (resolve-length x port #:parent [parent #f])
(define (resolve-length x port [parent #f])
(cond
[(not x) #f]
[(exact-nonnegative-integer? x) x]

Loading…
Cancel
Save