diff options
author | David Thompson <dthompson2@worcester.edu> | 2024-11-18 21:12:09 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2024-11-18 21:12:09 -0500 |
commit | b882724e502c07c7e4e475d266dbb5175c661b48 (patch) | |
tree | e5c6790f65593419cd9d1b8459b1628eca083a21 /bstruct.scm | |
parent | 1f4778a74416b51fbeaed9ea78ecd5adf7f384a2 (diff) |
Remove opaque type; s/alignment/align
Diffstat (limited to 'bstruct.scm')
-rw-r--r-- | bstruct.scm | 94 |
1 files changed, 38 insertions, 56 deletions
diff --git a/bstruct.scm b/bstruct.scm index 9edb5ce..2755303 100644 --- a/bstruct.scm +++ b/bstruct.scm @@ -76,10 +76,10 @@ define-bstruct)) (define-record-type <scalar> - (make-scalar size alignment native? type) + (make-scalar size align native? type) scalar? (size scalar-size) - (alignment scalar-alignment) + (align scalar-align) (native? scalar-native?) ; native endianness? (type scalar-type)) @@ -91,10 +91,10 @@ (type struct-field-type)) (define-record-type <struct> - (make-struct size alignment fields) + (make-struct size align fields) %struct? (size struct-size) - (alignment struct-alignment) + (align struct-align) (fields struct-fields)) (define-record-type <union-field> @@ -104,33 +104,28 @@ (type union-field-type)) (define-record-type <union> - (make-union size alignment fields) + (make-union size align fields) union? (size union-size) - (alignment union-alignment) + (align union-align) (fields union-fields)) (define-record-type <array> - (make-array size alignment length type) + (make-array size align length type) array? (size array-size) - (alignment array-alignment) + (align array-align) (length array-length) (type array-type)) (define-record-type <pointer> - (make-pointer size alignment type) + (make-pointer size align type) pointer? (size pointer-size) - (alignment pointer-alignment) - ;; Mutable for recursive types. + (align pointer-align) + ;; Mutable for setting up recursive types. (type pointer-type set-pointer-type!)) -(define-record-type <opaque> - (make-opaque) - opaque?) - -;; TODO: functions ;; TODO: bitfields (define (struct-field-ref struct name) @@ -152,8 +147,7 @@ (%struct? obj) (union? obj) (array? obj) - (pointer? obj) - (opaque? obj))) + (pointer? obj))) (define (sizeof type) (match type @@ -162,28 +156,16 @@ ($ <union> size) ($ <array> size) ($ <pointer> size)) - size) - (($ <opaque>) - (raise-exception - (make-exception (make-exception-with-message - "cannot get size of opaque type") - (make-exception-with-origin 'sizeof) - (make-exception-with-irritants (list type))))))) + size))) (define (alignof type) (match type - ((or ($ <scalar> _ alignment) - ($ <struct> _ alignment) - ($ <union> _ alignment) - ($ <array> _ alignment) - ($ <pointer> _ alignment)) - alignment) - (($ <opaque>) - (raise-exception - (make-exception (make-exception-with-message - "cannot get alignment of opaque type") - (make-exception-with-origin 'sizeof) - (make-exception-with-irritants (list type))))))) + ((or ($ <scalar> _ align) + ($ <struct> _ align) + ($ <union> _ align) + ($ <array> _ align) + ($ <pointer> _ align)) + align))) (define-syntax-rule (assert expr who) (unless expr @@ -413,9 +395,9 @@ (let-values (((_ transformer) (syntax-local-binding id))) (procedure-property transformer 'bstruct-size))) -(define (bstruct-descriptor-identifier-alignment id) +(define (bstruct-descriptor-identifier-align id) (let-values (((_ transformer) (syntax-local-binding id))) - (procedure-property transformer 'bstruct-alignment))) + (procedure-property transformer 'bstruct-align))) ;; A predicate that can answer the questions: ;; 1) Is this *any kind* of bstruct? @@ -526,7 +508,7 @@ (syntax-case stx () ((_ <type>) (non-opaque-bstruct-descriptor-identifier? #'<type>) - (bstruct-descriptor-identifier-alignment #'<type>))))) + (bstruct-descriptor-identifier-align #'<type>))))) ;; 'bstruct-pack!' and 'bstruct-unpack' allow for directly ;; interpreting bytevector contents as structured data. @@ -648,29 +630,29 @@ (id (identifier? #'id) desc) - ((scalar size alignment native? type) + ((scalar size align native? type) (symbolic-match? scalar) - #'(make-scalar size alignment native? 'type)) - ((struct size alignment (field ...)) + #'(make-scalar size align native? 'type)) + ((struct size align (field ...)) (symbolic-match? struct) (with-syntax (((field ...) (map build-struct-field #'(field ...)))) - #'(make-struct size alignment (list field ...)))) - ((union size alignment (field ...)) + #'(make-struct size align (list field ...)))) + ((union size align (field ...)) (symbolic-match? union) (with-syntax (((field ...) (map build-union-field #'(field ...)))) - #'(make-union size alignment (list field ...)))) - ((array size alignment length desc) + #'(make-union size align (list field ...)))) + ((array size align length desc) (symbolic-match? array) - #`(make-array size alignment length #,(build-type #'desc))) - ((pointer size alignment (recur _)) + #`(make-array size align length #,(build-type #'desc))) + ((pointer size align (recur _)) (and (symbolic-match? pointer) (symbolic-match? recur)) - #'(make-pointer size alignment #f)) - ((pointer size alignment void) + #'(make-pointer size align #f)) + ((pointer size align void) (and (symbolic-match? pointer) (symbolic-match? void)) - #'(make-pointer size alignment #f)) - ((pointer size alignment desc) + #'(make-pointer size align #f)) + ((pointer size align desc) (symbolic-match? pointer) - #`(make-pointer size alignment #,(build-type #'desc))))) + #`(make-pointer size align #,(build-type #'desc))))) (syntax-case stx () ((_ id name layout . kwargs) (with-syntax ((type (build-type #'layout))) @@ -721,7 +703,7 @@ 0) (_ (bstruct-descriptor-identifier? type) - (bstruct-descriptor-identifier-alignment type)))) + (bstruct-descriptor-identifier-align type)))) (define (expand-accessor proc stx id op type) (syntax-case stx () (() (proc id 0)) ; self reference @@ -1026,7 +1008,7 @@ #((bstruct? . #t) (bstruct-opaque? . #f) (bstruct-size . size) - (bstruct-alignment . align)) + (bstruct-align . align)) (let ((type #'desc)) (syntax-case stx () (self |