diff options
author | David Thompson <dthompson2@worcester.edu> | 2016-02-27 20:40:54 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2016-02-27 20:40:54 -0500 |
commit | a319acd01ac950d479d43d77c07d44a9af3012cd (patch) | |
tree | cf0e89d393f6850eba6ba9bcbd514176e8d58481 | |
parent | d0f26aea4f87391af77f5911c3e2ae19891287c8 (diff) |
Add packed record type hack.
This should work well enough until Guile is able to unbox struct fields.
* sly/records.scm (define-packaged-f64-record-type): New syntax.
-rw-r--r-- | sly/records.scm | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/sly/records.scm b/sly/records.scm index a7e180d..3ac2fda 100644 --- a/sly/records.scm +++ b/sly/records.scm @@ -23,8 +23,12 @@ ;;; Code: (define-module (sly records) + #:use-module (srfi srfi-4) #:use-module (srfi srfi-9) - #:export (define-record-type*)) + #:use-module (srfi srfi-9 gnu) + #:use-module (rnrs bytevectors) + #:export (define-record-type* + define-packed-f64-record-type)) (define-syntax-rule (define-record-type* type constructor keyword-constructor @@ -52,3 +56,38 @@ overridden." (lambda* (#:key (inherit default-record) (field (getter inherit)) ...) (constructor field ...)))))) + +;; A little hack until Guile can unbox fields in record types. ;) +(define-syntax-rule (define-packed-f64-record-type <name> + constructor + box unbox + predicate? + (field index getter setter) ...) + (begin + (define-record-type <name> + (box bv) + predicate? + (bv unbox)) + + (set-record-type-printer! <name> + (lambda (obj port) + (display "<" port) + (display '<name> port) + (begin + (display " " port) + (display 'field port) + (display ": " port) + (display (getter obj) port)) + ... + (display " >" port))) + + (define-inlinable (constructor field ...) + (box (f64vector field ...))) + + (define-inlinable (getter obj) + (f64vector-ref (unbox obj) index)) + ... + + (define-inlinable (setter obj value) + (f64vector-set! (unbox obj) index value)) + ...)) |