main
Matthew Butterick 8 years ago
parent 2a15a3f371
commit 8cb718427f

@ -29,4 +29,27 @@
(define-macro (test-module . EXPRS)
#`(module+ test
(require #,(datum->syntax caller-stx 'rackunit))
. EXPRS))
. EXPRS))
(define-macro (define-stub-stop ID)
(with-pattern ([ERROR-ID (suffix-id (prefix-id (syntax-source #'this) ":" #'ID) ":not-implemented")])
#'(define (ID . args)
(error 'ERROR-ID))))
(provide (rename-out [define-stub-stop define-stub]))
(define-macro (define-stub-go ID)
(with-pattern ([ERROR-ID (suffix-id (prefix-id (syntax-source #'this) ":" #'ID) ":not-implemented")])
#'(define (ID . args)
(displayln 'ERROR-ID))))
(define-macro (define-unfinished (ID . ARGS) . BODY)
(with-pattern ([ID-UNFINISHED (suffix-id (prefix-id (syntax-source #'this) ":" #'ID) ":unfinished")])
#'(define (ID . ARGS)
(begin . BODY)
(error 'ID-UNFINISHED))))
(define-macro (unfinished)
(with-pattern ([ID-UNFINISHED (prefix-id (syntax-source caller-stx) ":" (syntax-line caller-stx) ":" #'unfinished)])
#'(error 'ID-UNFINISHED)))

@ -14,20 +14,26 @@
(check-true (unsigned-type? 'UInt16))
(check-false (unsigned-type? 'Int16)))
(define-subclass BinaryIO% (NumberT type [endian (if (system-big-endian?) 'BE 'LE)])
(define-subclass object% (NumberT type [endian (if (system-big-endian?) 'BE 'LE)])
(getter-field [fn (string->symbol (format "~a~a" type (if (ends-with-8? type) "" endian)))])
(unless (hash-has-key? type-sizes fn)
(raise-argument-error 'NumberT "valid type and endian" (format "~v ~v" type endian)))
(define/override (decode stream)
(define bstr (read-bytes-exact (size) stream))
(if (= 1 (size))
(getter-field [size (hash-ref type-sizes fn)])
(define/public (decode stream)
(unless (input-port? stream)
(raise-argument-error 'decode "input port" stream))
(define bstr (read-bytes-exact size stream))
(if (= 1 size)
(bytes-ref bstr 0)
(integer-bytes->integer bstr (unsigned-type? type) (eq? endian 'BE))))
(define/override (encode op val) 'foo)
(define/override (size) (hash-ref type-sizes fn)))
(define/public (encode stream val)
(unless (output-port? stream)
(raise-argument-error 'encode "output port" stream))
(unfinished)))
(test-module

Loading…
Cancel
Save