delete extraneous key

main
Matthew Butterick 6 years ago
parent 5fced8eda0
commit 3e8fa7fcc8

@ -1,7 +1,5 @@
#lang racket/base
(require racket/dict
racket/class
racket/sequence
(require racket/class
"helper.rkt"
"number.rkt"
"util.rkt"
@ -64,7 +62,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Array.coffee
(cond
[(x:int? @len)
(define new-parent (mhash x:pointers-key null
x:alt-start-offset-key (pos port)
x:start-offset-key (pos port)
x:parent-key parent))
(hash-set! new-parent x:pointer-offset-key (+ (pos port) (x:size array new-parent)))
(send @len x:encode (length array) port) ; encode length at front

@ -1,7 +1,5 @@
#lang racket/base
(require racket/private/generic-methods
racket/dict
racket/port
racket/class
"generic.rkt")
(provide (all-defined-out))
@ -15,10 +13,9 @@
(define x:pointers-key 'x:pointers)
(define x:pointer-offset-key 'x:pointer-offset)
(define x:val-key 'x:val)
(define x:alt-start-offset-key 'x:alt-start-offset)
(define private-keys (list x:parent-key x:start-offset-key x:current-offset-key x:length-key x:pointer-size-key
x:pointers-key x:pointer-offset-key x:alt-start-offset-key))
x:pointers-key x:pointer-offset-key))
(define (hash-ref* d . keys)
(for/fold ([d d])

@ -66,7 +66,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
[(global) (find-top-parent parent)]
[else (error 'unknown-pointer-style)]))
(define relative (+ (case @pointer-relative-to
[(local parent) (hash-ref new-parent x:alt-start-offset-key)]
[(local parent) (hash-ref new-parent x:start-offset-key)]
[(immediate) (+ (pos port) (send @offset-type x:size val-in parent))]
[(global) 0])))
(send @offset-type x:encode (- (hash-ref new-parent x:pointer-offset-key) relative) port)

@ -71,7 +71,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
(format "dict that contains superset of xstruct keys: ~a"
(dict-keys @fields)) (dict-keys val)))
(define parent (mhash x:pointers-key empty
x:alt-start-offset-key (pos port)
x:start-offset-key (pos port)
x:parent-key parent-arg
x:val-key val
x:pointer-size-key 0))

@ -98,7 +98,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
"pointer: encode should handle null pointers"
(parameterize ([current-output-port (open-output-bytes)])
(define parent (mhash x:pointer-size-key 0
x:alt-start-offset-key 0
x:start-offset-key 0
x:pointer-offset-key 0
x:pointers-key null))
(encode (x:pointer) #f #:parent parent)
@ -109,7 +109,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
"pointer: encode should handle local offsets"
(parameterize ([current-output-port (open-output-bytes)])
(define parent (mhash x:pointer-size-key 0
x:alt-start-offset-key 0
x:start-offset-key 0
x:pointer-offset-key 1
x:pointers-key null))
(encode (x:pointer) 10 #:parent parent)
@ -123,7 +123,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
"pointer: encode should handle immediate offsets"
(parameterize ([current-output-port (open-output-bytes)])
(define parent (mhash x:pointer-size-key 0
x:alt-start-offset-key 0
x:start-offset-key 0
x:pointer-offset-key 1
x:pointers-key null))
(encode (x:pointer #:relative-to 'immediate) 10 #:parent parent)
@ -137,7 +137,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
"pointer: encode should handle offsets relative to parent"
(parameterize ([current-output-port (open-output-bytes)])
(define parent (mhash x:parent-key (mhash x:pointer-size-key 0
x:alt-start-offset-key 3
x:start-offset-key 3
x:pointer-offset-key 5
x:pointers-key null)))
(encode (x:pointer #:relative-to 'parent) 10 #:parent parent)
@ -153,7 +153,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
(define parent (mhash x:parent-key
(mhash x:parent-key
(mhash x:parent-key (mhash x:pointer-size-key 0
x:alt-start-offset-key 3
x:start-offset-key 3
x:pointer-offset-key 5
x:pointers-key null)))))
(encode (x:pointer #:relative-to 'global) 10 #:parent parent)
@ -168,7 +168,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
"pointer: encode should support void pointers"
(parameterize ([current-output-port (open-output-bytes)])
(define parent (mhash x:pointer-size-key 0
x:alt-start-offset-key 0
x:start-offset-key 0
x:pointer-offset-key 1
x:pointers-key null))
(encode (x:pointer uint8 'void) (x:void-pointer uint8 55) #:parent parent)
@ -180,7 +180,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
"pointer: encode should throw if not a void pointer instance"
(parameterize ([current-output-port (open-output-bytes)])
(define parent (mhash x:pointer-size-key 0
x:alt-start-offset-key 0
x:start-offset-key 0
x:pointer-offset-key 1
x:pointers-key null))
(check-exn exn:fail:contract? (λ () (encode (x:pointer uint8 'void) 44 #:parent parent)))))

@ -1,4 +1,4 @@
#lang debug racket/base
#lang racket/base
(require "helper.rkt" "struct.rkt"
racket/dict
racket/class
@ -65,7 +65,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(unless (dict? encode-me)
(raise-argument-error 'xversioned-struct-encode "dict" encode-me))
(define parent (mhash x:pointers-key null
x:alt-start-offset-key (pos port)
x:start-offset-key (pos port)
x:parent-key parent-arg
x:val-key encode-me
x:pointer-size-key 0))

Loading…
Cancel
Save