guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bytestructures: a "type system" for bytevectors


From: Taylan Ulrich Bayırlı/Kammer
Subject: Re: Bytestructures: a "type system" for bytevectors
Date: Tue, 08 Sep 2015 09:59:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

address@hidden writes:

> Sorry for not mentioning this before, but have you seen make-c-struct
> and parse-c-struct at
> https://www.gnu.org/software/guile/manual/html_node/Foreign-Structs.html
> ?

Yup.  They're somewhat primitive, not supporting nested structs or
arrays.  Unions aren't supported at all.  Bytestructures imitates C's
type system in full w.r.t. numeric, array (vector), struct, union, and
pointer types.  Though there are two main missing things now: tight
packing and bit fields.

Tight packing should be simple to implement by allowing an integer for
the optional argument to the struct constructor (currently only accepts
#f to mean no alignment-padding whatsoever, and #t (the default) for
conventional packing).

Bit fields would be implemented by allowing an optional third element,
the width, in each field of the fields alist passed to the struct
constructor.  The only problem is how to implement fields smaller than 8
bits when the bytevector API only allows granularity down to 8 bits.  I
guess it would be implemented via bitwise operations or by converting
ints to bit-arrays.  In any case it shouldn't be too hard to abstract it
out entirely for the user.

I'm working in a couple other things in parallel, but I should find time
to implement those some time in the not too distant future.

Taylan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]