|
|
|
@ -1,36 +1,17 @@
|
|
|
|
|
#lang racket/base
|
|
|
|
|
#lang debug racket/base
|
|
|
|
|
(require racket/class
|
|
|
|
|
"helper.rkt" "util.rkt" "number.rkt" "array.rkt" racket/stream racket/dict sugar/unstable/dict)
|
|
|
|
|
"helper.rkt" "util.rkt" "number.rkt" "array.rkt" racket/stream sugar/unstable/dict)
|
|
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
|
|
#|
|
|
|
|
|
approximates
|
|
|
|
|
https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
|
|
|
|
|
|#
|
|
|
|
|
|
|
|
|
|
#;(define (xlazy-array-decode xla [port-arg (current-input-port)] #:parent [parent #f])
|
|
|
|
|
(define port (->input-port port-arg))
|
|
|
|
|
(parameterize ([current-input-port port])
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
#;(define (xlazy-array-encode xla val [port-arg (current-output-port)] #:parent [parent #f])
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
#;(define (xlazy-array-size xla [val #f] #:parent [parent #f]))
|
|
|
|
|
|
|
|
|
|
;; xarray-base holds type and len fields
|
|
|
|
|
#;(struct xlazy-array xarray-base () #:transparent
|
|
|
|
|
#:methods gen:xenomorphic
|
|
|
|
|
[(define decode xlazy-array-decode)
|
|
|
|
|
(define xdecode xlazy-array-decode)
|
|
|
|
|
(define encode xlazy-array-encode)
|
|
|
|
|
(define size xlazy-array-size)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define xlazy-array%
|
|
|
|
|
(class xarray-base%
|
|
|
|
|
(class xarray%
|
|
|
|
|
(super-new)
|
|
|
|
|
(init-field lazy-type values)
|
|
|
|
|
(inherit-field len)
|
|
|
|
|
(inherit-field type len)
|
|
|
|
|
|
|
|
|
|
(define/override (xxdecode port parent)
|
|
|
|
|
(define starting-pos (pos port)) ; ! placement matters. `resolve-length` will change `pos`
|
|
|
|
@ -42,14 +23,12 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
|
|
|
|
|
'_length len)
|
|
|
|
|
parent)])
|
|
|
|
|
(define starting-pos (pos port))
|
|
|
|
|
(define type type)
|
|
|
|
|
(begin0
|
|
|
|
|
(for/stream ([index (in-range decoded-len)])
|
|
|
|
|
(define orig-pos (pos port))
|
|
|
|
|
(pos port (+ starting-pos (* (send type xxsize #f parent) index)))
|
|
|
|
|
;; use explicit `port` arg below because this evaluation is delayed
|
|
|
|
|
(begin0
|
|
|
|
|
(send this post-decode (send type xxdecode port parent))
|
|
|
|
|
(send type xxdecode port parent)
|
|
|
|
|
(pos port orig-pos)))
|
|
|
|
|
(pos port (+ (pos port) (* decoded-len (send type xxsize #f parent)))))))
|
|
|
|
|
|
|
|
|
@ -57,7 +36,7 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
|
|
|
|
|
(super xxencode (if (stream? val) (stream->list val) val) port parent))
|
|
|
|
|
|
|
|
|
|
(define/override (xxsize [val #f] [parent #f])
|
|
|
|
|
(super xxsize (if (stream? val) (stream->list val) val) parent))))
|
|
|
|
|
(super xxsize (if (stream? val) (stream->list val) val) parent))))
|
|
|
|
|
|
|
|
|
|
(define (+xlazy-array [type-arg #f] [len-arg #f]
|
|
|
|
|
#:type [type-kwarg #f]
|
|
|
|
@ -65,11 +44,9 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
|
|
|
|
|
#:subclass [class xlazy-array%])
|
|
|
|
|
(define type (or type-arg type-kwarg))
|
|
|
|
|
(define len (or len-arg len-kwarg))
|
|
|
|
|
(unless (xenomorphic-type? type)
|
|
|
|
|
(raise-argument-error '+xarray "xenomorphic type" type))
|
|
|
|
|
(unless (length-resolvable? len)
|
|
|
|
|
(raise-argument-error '+xarray "length-resolvable?" len))
|
|
|
|
|
(new class [type type] [len len]))
|
|
|
|
|
(new class [type type]
|
|
|
|
|
[len len]
|
|
|
|
|
[length-type 'count]))
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
|
(require rackunit "number.rkt" "generic.rkt")
|
|
|
|
|