diff options
author | David Thompson <dthompson2@worcester.edu> | 2024-11-25 08:48:56 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2024-11-26 09:07:12 -0500 |
commit | c5ece84da180b29a60d881008881ccfb29e7486c (patch) | |
tree | d7681339625b76f544462a4e75343abb4fb5b81e /tests | |
parent | f6596f32468ed21ea539fc2943210f559668d958 (diff) |
First-class primitives, type aliasing, and better cross-compilation.main
I haven't actually tested cross-compilation, but we should be making
fewer assumptions about the target ABI now.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-bstruct.scm | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/tests/test-bstruct.scm b/tests/test-bstruct.scm index 18cb13a..6970f4e 100644 --- a/tests/test-bstruct.scm +++ b/tests/test-bstruct.scm @@ -20,6 +20,9 @@ #:use-module (system foreign) #:use-module (tests utils)) +;; For testing primitive type aliases. +(define-bstruct f32 float) + ;; For testing basic structs. (define-bstruct <vec2> (struct (x f32) (y f32))) @@ -27,6 +30,9 @@ (define-bstruct <vertex> (struct (xy <vec2>) (uv <vec2>))) +;; For testing compound type aliases. +(define-bstruct <vert> <vertex>) + ;; For testing bit fields. (define-bstruct <date> (bits @@ -36,21 +42,21 @@ ;; For testing arrays. (define-bstruct <matrix4> - (array 16 f32)) + (array 16 float)) ;; For testing variable length arrays. (define-bstruct <floats> - (struct (items (* f32)))) + (struct (items (* float)))) ;; For testing unions. (define-bstruct <mouse-move-event> - (struct (type u8) (x s32) (y s32))) + (struct (type uint8) (x int32) (y int32))) (define-bstruct <mouse-button-event> - (struct (type u8) (button u8) (state u8) (x s32) (y s32))) + (struct (type uint8) (button uint8) (state uint8) (x int32) (y int32))) (define-bstruct <event> - (union (type u8) + (union (type uint8) (mouse-move <mouse-move-event>) (mouse-button <mouse-button-event>))) @@ -61,10 +67,10 @@ ;; For testing proper sizing. (define-bstruct <right-sized> (struct - (a u64) - (b u32) - (c u64) - (d u32))) + (a uint64) + (b uint32) + (c uint64) + (d uint32))) ;; For testing opaque types. (define-bstruct <opaque>) @@ -85,6 +91,7 @@ (bstruct-alloc <vec2> (x 77) (y 89)))))) (test-group "bstruct->sexp" + ;; (test-equal 42.0 (bstruct->sexp (bstruct-alloc float 42.0))) (test-equal '(struct (x 42.0) (y 69.0)) (bstruct->sexp (bstruct-alloc <vec2> (x 42) (y 69)))) (test-equal '(struct (xy (struct (x 42.0) (y 69.0))) @@ -143,6 +150,8 @@ (test-equal (alignof (list float float)) (bstruct-alignof <vec2>)) (test-equal (alignof (list (list float float) (list float float))) (bstruct-alignof <vertex>)) + (test-equal (alignof (list (list float float) (list float float))) + (bstruct-alignof <vert>)) (test-equal (alignof (make-list 16 float)) (bstruct-alignof <matrix4>)) (test-equal (alignof (list uint8 int32 int32)) (bstruct-alignof <mouse-move-event>)) @@ -158,6 +167,8 @@ (test-equal (sizeof (list float float)) (bstruct-sizeof <vec2>)) (test-equal (sizeof (list (list float float) (list float float))) (bstruct-sizeof <vertex>)) + (test-equal (sizeof (list (list float float) (list float float))) + (bstruct-sizeof <vert>)) (test-equal (sizeof (make-list 16 float)) (bstruct-sizeof <matrix4>)) (test-equal (sizeof (list uint8 int32 int32)) (bstruct-sizeof <mouse-move-event>)) @@ -176,6 +187,8 @@ (bstruct-ref <vec2> (bstruct-alloc <vec2> (x 42) (y 69)) y)) (test-equal 42.0 (bstruct-ref <vertex> (bstruct-alloc <vertex> ((uv x) 42)) (uv x))) + (test-equal 42.0 + (bstruct-ref <vertex> (bstruct-alloc <vert> ((uv x) 42)) (uv x))) (test-equal 4.0 (let ((bv (f32vector 1 2 3 4))) (bstruct-ref <floats> |