summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-01-02 09:30:43 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-01-02 09:43:28 -0800
commit6b06553049d438a52127fa722cbd8717d2a13680 (patch)
tree756fec86b34bfc56234301a2808e60240338df62 /tests
parent77340129486f06498bca2d536ec0406e02ca6d76 (diff)
downloadtxr-6b06553049d438a52127fa722cbd8717d2a13680.tar.gz
txr-6b06553049d438a52127fa722cbd8717d2a13680.tar.bz2
txr-6b06553049d438a52127fa722cbd8717d2a13680.zip
ffi: allow enumed bitfield.
* ffi.c (ffi_type_copy): Function moved earlier in file without change. (ffi_type_copy_new_ops): New stati function. (make_ffi_type_enum): Do not create a new type object using cobj; copy the existing base_type, and then tweak its properties, just like what is done with bool. Thus if base_type is a bitfield, the enum will be a bitfield. Add check against doign this to anything but an FFI_KIND_NUM, with the awareness that this does include floating-point types. Since tft is now a copy, we no longer have to copy a number of things from btft. We do set he kind field to FFI_KIND_ENUM. (ffi_type_compile): In the two bitfield cases, we now calculate the mask field for the bitfield type (leaving the shift at zero). The struct or union type into which the bitfield is embedded will still re-calculate this. The reason is that when an (enumed (bit ...) ...) type is defined, it constructs hash tables for converting between the symbolic and numeric values. It calls the put function of the underlying type to test whether each enumeration value can be converted (i.e. is in range). So the bitfield type must have a valid mask at that time, or else it will reject every nonzero value as being out of range for the bitfield. I'm also replacing the max_int variable with bits_int. Since bitfields are restricted to no wider than int, why pretend? * tests/017/ffi-misc.tl: New test cases. * txr.1: Documented.
Diffstat (limited to 'tests')
-rw-r--r--tests/017/ffi-misc.tl13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/017/ffi-misc.tl b/tests/017/ffi-misc.tl
index 3b3c4438..377d7572 100644
--- a/tests/017/ffi-misc.tl
+++ b/tests/017/ffi-misc.tl
@@ -70,3 +70,16 @@
(typeof (ffi (enumed int64 e (x 0) (y #x7fffffffffffffff)))) ffi-type
(typeof (ffi (enumed int64 e (x #x-8000000000000001)))) :error
(typeof (ffi (enumed int64 e (x #x8000000000000000)))) :error)
+
+(typedef abc (struct abc
+ (a (enumed (bit 1 uint8) bit fals true))
+ (b (enumed (bit 1 uint8) bit fals true))
+ (c (enumed (bit 1 uint8) bit fals true))))
+
+(mtest
+ (sizeof abc) 1
+ (znew abc) #S(abc a fals b fals c fals))
+
+(each-match ((a b c) (rperm '(fals true) 3))
+ (let ((s (new abc a a b b c c)))
+ (test (ffi-get (ffi-put s (ffi abc)) (ffi-abc)) s)))