From c5ece84da180b29a60d881008881ccfb29e7486c Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 25 Nov 2024 08:48:56 -0500 Subject: First-class primitives, type aliasing, and better cross-compilation. I haven't actually tested cross-compilation, but we should be making fewer assumptions about the target ABI now. --- tests/test-bstruct.scm | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'tests/test-bstruct.scm') 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 (struct (x f32) (y f32))) @@ -27,6 +30,9 @@ (define-bstruct (struct (xy ) (uv ))) +;; For testing compound type aliases. +(define-bstruct ) + ;; For testing bit fields. (define-bstruct (bits @@ -36,21 +42,21 @@ ;; For testing arrays. (define-bstruct - (array 16 f32)) + (array 16 float)) ;; For testing variable length arrays. (define-bstruct - (struct (items (* f32)))) + (struct (items (* float)))) ;; For testing unions. (define-bstruct - (struct (type u8) (x s32) (y s32))) + (struct (type uint8) (x int32) (y int32))) (define-bstruct - (struct (type u8) (button u8) (state u8) (x s32) (y s32))) + (struct (type uint8) (button uint8) (state uint8) (x int32) (y int32))) (define-bstruct - (union (type u8) + (union (type uint8) (mouse-move ) (mouse-button ))) @@ -61,10 +67,10 @@ ;; For testing proper sizing. (define-bstruct (struct - (a u64) - (b u32) - (c u64) - (d u32))) + (a uint64) + (b uint32) + (c uint64) + (d uint32))) ;; For testing opaque types. (define-bstruct ) @@ -85,6 +91,7 @@ (bstruct-alloc (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 (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 )) (test-equal (alignof (list (list float float) (list float float))) (bstruct-alignof )) + (test-equal (alignof (list (list float float) (list float float))) + (bstruct-alignof )) (test-equal (alignof (make-list 16 float)) (bstruct-alignof )) (test-equal (alignof (list uint8 int32 int32)) (bstruct-alignof )) @@ -158,6 +167,8 @@ (test-equal (sizeof (list float float)) (bstruct-sizeof )) (test-equal (sizeof (list (list float float) (list float float))) (bstruct-sizeof )) + (test-equal (sizeof (list (list float float) (list float float))) + (bstruct-sizeof )) (test-equal (sizeof (make-list 16 float)) (bstruct-sizeof )) (test-equal (sizeof (list uint8 int32 int32)) (bstruct-sizeof )) @@ -176,6 +187,8 @@ (bstruct-ref (bstruct-alloc (x 42) (y 69)) y)) (test-equal 42.0 (bstruct-ref (bstruct-alloc ((uv x) 42)) (uv x))) + (test-equal 42.0 + (bstruct-ref (bstruct-alloc ((uv x) 42)) (uv x))) (test-equal 4.0 (let ((bv (f32vector 1 2 3 4))) (bstruct-ref -- cgit v1.2.3