delete generic interface

main
Matthew Butterick 6 years ago
parent 3c23354f10
commit c33e1268c4

@ -99,7 +99,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
(define (x:array? x) (is-a? x x:array%))
(module+ test
(require rackunit "generic.rkt")
(require rackunit "base.rkt")
(check-equal? (decode (x:array uint16be 3) #"ABCDEF") '(16706 17220 17734))
(check-equal? (encode (x:array uint16be 3) '(16706 17220 17734) #f) #"ABCDEF")
(check-equal? (size (x:array uint16be) '(1 2 3)) 6)

@ -1,7 +1,5 @@
#lang racket/base
(require racket/private/generic-methods
racket/class
"generic.rkt")
(require racket/class)
(provide (all-defined-out))
(struct x:ptr (type val parent) #:transparent)
@ -30,29 +28,25 @@
(file-position p new-pos))
(file-position p))
(define xenomorphic<%>
(interface* ()
([(generic-property gen:xenomorphic)
(generic-method-table
gen:xenomorphic
(define (decode xo [port-arg (current-input-port)] #:parent [parent #f])
(define port
(cond
[(input-port? port-arg) port-arg]
[(bytes? port-arg) (open-input-bytes port-arg)]
[else (raise-argument-error 'decode "byte string or input port" port-arg)]))
(send xo decode port parent))
(define (decode xo [port-arg (current-input-port)] #:parent [parent #f])
(define port
(cond
[(input-port? port-arg) port-arg]
[(bytes? port-arg) (open-input-bytes port-arg)]
[else (raise-argument-error 'decode "byte string or input port" port-arg)]))
(send xo decode port parent))
(define (encode xo val [port-arg (current-output-port)]
#:parent [parent #f])
(define port (if (output-port? port-arg) port-arg (open-output-bytes)))
(send xo x:encode val port parent)
(unless port-arg (get-output-bytes port)))
(define (encode xo val [port-arg (current-output-port)]
#:parent [parent #f])
(define port (if (output-port? port-arg) port-arg (open-output-bytes)))
(send xo x:encode val port parent)
(unless port-arg (get-output-bytes port)))
(define (size xo [val #f] #:parent [parent #f])
(send xo x:size val parent)))])))
(define (size xo [val #f] #:parent [parent #f])
(send xo x:size val parent))
(define (xenomorphic-type? x) (is-a? x xenobase%))
(define xenomorphic? xenomorphic-type?)
(define-syntax-rule (generate-subclass CLASS PRE-ENCODE-PROC POST-DECODE-PROC)
(cond
@ -72,7 +66,7 @@
[else CLASS]))
(define xenobase%
(class* object% (xenomorphic<%>)
(class object%
(super-new)
(define/pubment (x:decode input-port [parent #f])

@ -41,7 +41,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Bitfield.coffee
(new (generate-subclass x:bitfield% pre-proc post-proc) [type type] [flags flags]))
(module+ test
(require rackunit "number.rkt" "generic.rkt")
(require rackunit "number.rkt" "base.rkt")
(define bfer (x:bitfield uint16be '(bold italic underline #f shadow condensed extended)))
(define bf (decode bfer #"\0\25"))
(check-equal? (length (hash-keys bf)) 6) ; omits #f flag

@ -1,8 +0,0 @@
#lang racket/base
(require racket/generic)
(provide (all-defined-out))
(define-generics xenomorphic
(encode xenomorphic val [port] #:parent [parent])
(decode xenomorphic [port] #:parent [parent])
(size xenomorphic [item] #:parent [parent]))

@ -50,7 +50,7 @@ https://github.com/mbutterick/restructure/blob/master/src/LazyArray.coffee
[count-bytes? #false]))
(module+ test
(require rackunit "number.rkt" "generic.rkt")
(require rackunit "number.rkt" "base.rkt")
(define bstr #"ABCD1234")
(define ds (open-input-bytes bstr))
(define la (x:lazy-array uint8 4))

@ -8,7 +8,6 @@
"bitfield.rkt"
"buffer.rkt"
"enum.rkt"
"generic.rkt"
"base.rkt"
"lazy-array.rkt"
"number.rkt"

@ -103,7 +103,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(define uint32le (x:int 4 #:signed #f #:endian 'le))
(module+ test
(require rackunit "generic.rkt")
(require rackunit "base.rkt")
(check-exn exn:fail:contract? (λ () (x:int 'not-a-valid-type)))
(check-exn exn:fail:contract? (λ () (encode uint8 256 #f)))
(check-not-exn (λ () (encode uint8 255 #f)))

@ -111,7 +111,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
(new (generate-subclass x:symbol% pre-proc post-proc) [len len] [encoding encoding]))
(module+ test
(require rackunit "generic.rkt")
(require rackunit "base.rkt")
(define S-fixed (x:string 4 'utf8))
(check-equal? (encode S-fixed "Mike" #f) #"Mike")
(check-exn exn:fail? (λ () (encode S-fixed "Mikes" #f))) ; too long for fixed string

@ -102,7 +102,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
(new (generate-subclass x:struct% pre-proc post-proc) [fields fields]))
(module+ test
(require rackunit "number.rkt" "generic.rkt")
(require rackunit "number.rkt" "base.rkt")
(define (random-pick xs) (list-ref xs (random (length xs))))
(check-exn exn:fail:contract? (λ () (x:struct 42)))
(for ([i (in-range 20)])

@ -4,7 +4,6 @@
"../array.rkt"
"../number.rkt"
"../pointer.rkt"
"../generic.rkt"
"../base.rkt"
sugar/unstable/dict)

@ -6,7 +6,7 @@
sugar/unstable/dict
"../number.rkt"
"../bitfield.rkt"
"../generic.rkt")
"../base.rkt")
#|
approximates

@ -3,7 +3,7 @@
racket/class
"../buffer.rkt"
"../number.rkt"
"../generic.rkt")
"../base.rkt")
#|
approximates

@ -3,7 +3,7 @@
racket/class
"../number.rkt"
"../enum.rkt"
"../generic.rkt")
"../base.rkt")
#|
approximates

@ -6,7 +6,7 @@
"../base.rkt"
"../number.rkt"
"../lazy-array.rkt"
"../generic.rkt")
"../base.rkt")
#|
approximates

@ -2,7 +2,7 @@
(require rackunit
racket/class
"../number.rkt"
"../generic.rkt")
"../base.rkt")
#|
approximates

@ -4,7 +4,7 @@
"../base.rkt"
"../number.rkt"
"../optional.rkt"
"../generic.rkt")
"../base.rkt")
#|
approximates

@ -6,7 +6,7 @@
"../pointer.rkt"
"../number.rkt"
"../struct.rkt"
"../generic.rkt"
"../base.rkt"
racket/promise
sugar/unstable/dict)

@ -4,7 +4,7 @@
"../number.rkt"
"../base.rkt"
"../reserved.rkt"
"../generic.rkt")
"../base.rkt")
#|
approximates

@ -4,7 +4,7 @@
"../base.rkt"
"../string.rkt"
"../number.rkt"
"../generic.rkt"
"../base.rkt"
sugar/unstable/dict)
#|

@ -6,7 +6,7 @@
"../string.rkt"
"../pointer.rkt"
"../number.rkt"
"../generic.rkt"
"../base.rkt"
sugar/unstable/dict)
#|

@ -7,7 +7,7 @@
"../string.rkt"
"../pointer.rkt"
"../struct.rkt"
"../generic.rkt"
"../base.rkt"
"../versioned-struct.rkt")
#|

@ -1,5 +1,5 @@
#lang racket/base
(require racket/match racket/dict "number.rkt" "base.rkt" "generic.rkt")
(require racket/match racket/dict "number.rkt" "base.rkt")
(provide (all-defined-out))
(define (length-resolvable? x)

Loading…
Cancel
Save