This repository was archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
FIP: A better Storable type class #111
Labels
C - design
design stuff
C - system
system stuff
WIP
Work In Progress (e.g. don't merge)
X - FIP
Foundation improvement proposal
Comments
Great idea to do some work on this area. A few notes:
I'm looking forward to this work. |
I agree |
What about |
I think you are right that We could also remove |
I think For |
NicolasDP
added a commit
that referenced
this issue
Sep 9, 2016
NicolasDP
added a commit
that referenced
this issue
Sep 11, 2016
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
C - design
design stuff
C - system
system stuff
WIP
Work In Progress (e.g. don't merge)
X - FIP
Foundation improvement proposal
Overview
Foundation aims to bring better typed object representation in order to help users to quickly understand a given API, but also to gives better type checking and therefor semantic validation at compile time.
This is a draft proposal on what could look like a new interface for Foreign Storable.
Foreign interface: The state of the art
Storable object (object which can be marshalled to/from foreign interfaces, but not only) are originally defined as follow:
This type class seems to provide what one would need to safely marshall objects to/from a given address.
Limitations of the current state
sizeOf
,alignment
andp***ElemOff
), this is not the culture of theFoundation
to leave such non labeled size and offsets;peekElemOff
ispeekByteOff ptr (off * sizeOf undef)
);p***ElemOff
may not apply for certain types).New storable type classes
Storable type class
Without having any information about the size of a given type, we want to be able to peek or poke an object from a given pointer. In this case, the
sizeOf
information is not relevant. A given object can have a variable size and yet bepeeked
orpoked
at a given address.Some primitives already interface this
Storable
:Word8
,Int
... PrimType type classAn example of object that can be shared with foreign libraries is a CString. It is litterally an array of
Word8
terminated by a zero.There are also C Structure of variable size which can be defined:
In this case, the structure will have a dynamically known size that
peek
orpoke
can easily implements:StorableFixed type class
A
SizedStorable
is aStorable
element which can be peeked/poked from/to an offset and an address in memory and to do so, the only information we need is its size and its alignment.And now it is very simple to define generic function using the 2 given interfaces.
Compatibility with prim types
The text was updated successfully, but these errors were encountered: