main
Matthew Butterick 6 years ago
parent f8909041f0
commit 9640111ffc

@ -117,7 +117,7 @@ This allows the pointer to be calculated relative to a property on the parent. I
(define/contract (x:pointer
[offset-arg #f]
[type-arg #f]
#:offset-type [offset-kwarg #f]
#:offset-type [offset-kwarg uint8]
#:type [type-kwarg uint32]
#:relative-to [pointer-relative-to 'local]
#:lazy [pointer-lazy? #f]
@ -128,9 +128,13 @@ This allows the pointer to be calculated relative to a property on the parent. I
#:base-class [base-class x:pointer%])
(()
((or/c xenomorphic? #false)
(or/c x:int? #false)
(or/c x:int? 'void #false)
#:offset-type (or/c xenomorphic? #false)
#:type (or/c x:int? #false)
#:type (or/c x:int? 'void #false)
#:relative-to pointer-relative-value?
#:lazy boolean?
#:allow-null boolean?
#:null any/c
#:pre-encode (or/c (any/c . -> . any/c) #false)
#:post-decode (or/c (any/c . -> . any/c) #false)
#:base-class (λ (c) (subclass? c x:pointer%)))
@ -138,9 +142,9 @@ This allows the pointer to be calculated relative to a property on the parent. I
x:pointer?)
(unless (pointer-relative-value? pointer-relative-to)
(raise-argument-error 'x:pointer (format "~v" valid-pointer-relatives) pointer-relative-to))
(define type-in (or type-arg type-kwarg uint8))
(define type-in (or type-arg type-kwarg))
(new (generate-subclass base-class pre-proc post-proc)
[offset-type (or offset-arg offset-kwarg uint8)]
[offset-type (or offset-arg offset-kwarg)]
[type (case type-in [(void) #f][else type-in])]
[pointer-relative-to pointer-relative-to]
[pointer-lazy? pointer-lazy?]

@ -1051,9 +1051,9 @@ Whether @racket[x] is an object of type @racket[x:pointer%].
@defproc[
(x:pointer
[offset-arg (or/c xenomorphic? #false) #false]
[type-arg (or/c x:int? #false) #false]
[type-arg (or/c x:int? 'void #false) #false]
[#:offset-type offset-kw (or/c xenomorphic? #false) uint8]
[#:type type-kw (or/c xenomorphic? #false) uint32]
[#:type type-kw (or/c x:int? 'void #false) uint32]
[#:relative-to pointer-relative-to pointer-relative-value? 'local]
[#:allow-null allow-null? boolean? #true]
[#:null null-value any/c 0]
@ -1067,7 +1067,7 @@ Generate an instance of @racket[x:pointer%] (or a subclass of @racket[x:pointer%
@racket[offset-arg] or @racket[offset-kw] (whichever is provided, though @racket[offset-arg] takes precedence) controls the type of the thing being pointed at. Default is @racket[uint8].
@racket[type-arg] or @racket[type-kw] (whichever is provided, though @racket[type-arg] takes precedence) controls the type of the pointer value itself (which must be @racket[x:int?]). Default is @racket[uint32].
@racket[type-arg] or @racket[type-kw] (whichever is provided, though @racket[type-arg] takes precedence) controls the type of the pointer value itself, which must be either an @racket[x:int?] or the symbol @racket['void] to indicate a void pointer). Default is @racket[uint32].
@racket[pointer-relative-to] controls the style of pointer, which must be one of @racket['(local immediate parent global)]. Default is @racket['local].

@ -61,25 +61,25 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
(test-case
"pointer: size"
(let ([parent (mhash x:pointer-size-key 0)])
(check-equal? (size (x:pointer) 10 #:parent parent) 1)
(check-equal? (size (x:pointer #:type uint8) 10 #:parent parent) 1)
(check-equal? (hash-ref parent x:pointer-size-key) 1)))
(test-case
"pointer: size should add to immediate pointerSize"
(let ([parent (mhash x:pointer-size-key 0)])
(check-equal? (size (x:pointer #:relative-to 'immediate) 10 #:parent parent) 1)
(check-equal? (size (x:pointer #:relative-to 'immediate #:type uint8) 10 #:parent parent) 1)
(check-equal? (hash-ref parent x:pointer-size-key) 1)))
(test-case
"pointer: size should add to parent pointerSize"
(let ([parent (mhash x:parent-key (mhash x:pointer-size-key 0))])
(check-equal? (size (x:pointer #:relative-to 'parent) 10 #:parent parent) 1)
(check-equal? (size (x:pointer #:relative-to 'parent #:type uint8) 10 #:parent parent) 1)
(check-equal? (hash-ref* parent x:parent-key x:pointer-size-key) 1)))
(test-case
"pointer: size should add to global pointerSize"
(let ([parent (mhash x:parent-key (mhash x:parent-key (mhash x:parent-key (mhash x:pointer-size-key 0))))])
(check-equal? (size (x:pointer #:relative-to 'global) 10 #:parent parent) 1)
(check-equal? (size (x:pointer #:relative-to 'global #:type uint8) 10 #:parent parent) 1)
(check-equal? (hash-ref* parent x:parent-key x:parent-key x:parent-key x:pointer-size-key) 1)))
(test-case
@ -115,7 +115,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
x:start-offset-key 0
x:pointer-offset-key 1
x:pointers-key null))
(encode (x:pointer) 10 #:parent parent)
(encode (x:pointer #:type uint8) 10 #:parent parent)
(check-equal? (hash-ref parent x:pointer-offset-key) 2)
(check-equal? (hash-ref parent x:pointers-key) (list (x:ptr uint8 10 parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 1))))
@ -127,7 +127,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
x:start-offset-key 0
x:pointer-offset-key 1
x:pointers-key null))
(encode (x:pointer #:relative-to 'immediate) 10 #:parent parent)
(encode (x:pointer #:relative-to 'immediate #:type uint8) 10 #:parent parent)
(check-equal? (hash-ref parent x:pointer-offset-key) 2)
(check-equal? (hash-ref parent x:pointers-key) (list (x:ptr uint8 10 parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 0))))
@ -139,7 +139,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
x:start-offset-key 3
x:pointer-offset-key 5
x:pointers-key null)))
(encode (x:pointer #:relative-to 'parent) 10 #:parent parent)
(encode (x:pointer #:relative-to 'parent #:type uint8) 10 #:parent parent)
(check-equal? (hash-ref* parent x:parent-key x:pointer-offset-key) 6)
(check-equal? (hash-ref* parent x:parent-key x:pointers-key) (list (x:ptr uint8 10 parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 2))))
@ -153,7 +153,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
x:start-offset-key 3
x:pointer-offset-key 5
x:pointers-key null)))))
(encode (x:pointer #:relative-to 'global) 10 #:parent parent)
(encode (x:pointer #:relative-to 'global #:type uint8) 10 #:parent parent)
(check-equal? (hash-ref* parent x:parent-key x:parent-key x:parent-key x:pointer-offset-key) 6)
(check-equal? (hash-ref* parent x:parent-key x:parent-key x:parent-key x:pointers-key)
(list (x:ptr uint8 10 parent)))

Loading…
Cancel
Save