Hi,
i'm looking for an easy way to map CType union. By easy way i mean, either a Conversion or a make_union/break_union. Having a look at the source code of CInterface, i see that conversion are managed by a union signature so i guess there's a way. But is there a solution that already exists ?
Regards, Pierre-Alain
Hi, I guess you would want to map between a union in C and a datatype in ML. That would require the union type to contain sufficient information to allow the conversion process to know which variant of the datatype to use, which isn't necessarily true of a C union. You might be able to adapt the list example in polyml/mlsource/extra/CInterface/Examples/ForeignTest.sml. The type in C isn't exactly a union but you could have different STRUCTn for each variant.
I feel sure someone has a better example.
Regards, David
On 20/08/2012 07:51, Pierre-Alain Bourdil wrote:
Hi,
i'm looking for an easy way to map CType union. By easy way i mean, either a Conversion or a make_union/break_union. Having a look at the source code of CInterface, i see that conversion are managed by a union signature so i guess there's a way. But is there a solution that already exists ?
Regards, Pierre-Alain _______________________________________________ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
In ForeignTest, the vol2tree method use fromClong to differentiate between NullTree, or Tree. My union, is made of 2 variants : a struct pointer and a int64_t . I can't figure out how to decide if a given vol is a pointer or an int64_t. is there a solution ? The inverse conversion is pretty forward
Le Lundi 20 Ao?t 2012 10:47 CEST, David Matthews David.Matthews@prolingua.co.uk a ?crit:
Hi, I guess you would want to map between a union in C and a datatype in ML. That would require the union type to contain sufficient information to allow the conversion process to know which variant of the datatype to use, which isn't necessarily true of a C union. You might be able to adapt the list example in polyml/mlsource/extra/CInterface/Examples/ForeignTest.sml. The type in C isn't exactly a union but you could have different STRUCTn for each variant.
I feel sure someone has a better example.
Regards, David
On 20/08/2012 07:51, Pierre-Alain Bourdil wrote:
Hi,
i'm looking for an easy way to map CType union. By easy way i mean, either a Conversion or a make_union/break_union. Having a look at the source code of CInterface, i see that conversion are managed by a union signature so i guess there's a way. But is there a solution that already exists ?
Regards, Pierre-Alain _______________________________________________ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
On 20/08/2012 15:28, Pierre-Alain Bourdil wrote:
In ForeignTest, the vol2tree method use fromClong to differentiate between NullTree, or Tree. My union, is made of 2 variants : a struct pointer and a int64_t . I can't figure out how to decide if a given vol is a pointer or an int64_t. is there a solution ? The inverse conversion is pretty forward
It's difficult to know what to do if you can't tell whether you have a number or the pointer to something. Are you actually returning these sort of values from your C code to ML? If not you can just use a dummy function that raises an exception in the conversion from a vol to the ML datatype.
David
On Mon, Aug 20, 2012 at 10:27 AM, David Matthews David.Matthews@prolingua.co.uk wrote:
On 20/08/2012 15:28, Pierre-Alain Bourdil wrote:
In ForeignTest, the vol2tree method use fromClong to differentiate between NullTree, or Tree. My union, is made of 2 variants : a struct pointer and a int64_t . I can't figure out how to decide if a given vol is a pointer or an int64_t. is there a solution ? The inverse conversion is pretty forward
It's difficult to know what to do if you can't tell whether you have a number or the pointer to something. Are you actually returning these sort of values from your C code to ML? If not you can just use a dummy function that raises an exception in the conversion from a vol to the ML datatype.
David
I suspect Pierre-Alain is implicitly assuming that somehow PolyML uses some form of low bits tag to differentiate whether an integer bit-pattern (e.g. a value of type intptr_t) is either a vol or an int64_t. I suspect the answer is no.
On 20/08/2012 17:04, Gabriel Dos Reis wrote:
On Mon, Aug 20, 2012 at 10:27 AM, David Matthews David.Matthews@prolingua.co.uk wrote:
On 20/08/2012 15:28, Pierre-Alain Bourdil wrote:
In ForeignTest, the vol2tree method use fromClong to differentiate between NullTree, or Tree. My union, is made of 2 variants : a struct pointer and a int64_t . I can't figure out how to decide if a given vol is a pointer or an int64_t. is there a solution ? The inverse conversion is pretty forward
It's difficult to know what to do if you can't tell whether you have a number or the pointer to something. Are you actually returning these sort of values from your C code to ML? If not you can just use a dummy function that raises an exception in the conversion from a vol to the ML datatype.
David
I suspect Pierre-Alain is implicitly assuming that somehow PolyML uses some form of low bits tag to differentiate whether an integer bit-pattern (e.g. a value of type intptr_t) is either a vol or an int64_t. I suspect the answer is no.
Perhaps it would help if we could see the definition of the union type in C.
David
Hi,
the structure is pretty simple :
// This is a STRUCT3 struct A {...}
struct B { enum {E1,E2} kind // ok for mapping enum union { int64_t ref ; // there was a discussion about int64 platform independant conversion. I just defined a Cint64_t as Clong struct A *a; } arg }
As i explained, my problem is to differentiate int64_t from Cpointer Cstruct in my vol2enum function..
Cheers
Le Lundi 20 Ao?t 2012 18:18 CEST, David Matthews David.Matthews@prolingua.co.uk a ?crit:
On 20/08/2012 17:04, Gabriel Dos Reis wrote:
On Mon, Aug 20, 2012 at 10:27 AM, David Matthews David.Matthews@prolingua.co.uk wrote:
On 20/08/2012 15:28, Pierre-Alain Bourdil wrote:
In ForeignTest, the vol2tree method use fromClong to differentiate between NullTree, or Tree. My union, is made of 2 variants : a struct pointer and a int64_t . I can't figure out how to decide if a given vol is a pointer or an int64_t. is there a solution ? The inverse conversion is pretty forward
It's difficult to know what to do if you can't tell whether you have a number or the pointer to something. Are you actually returning these sort of values from your C code to ML? If not you can just use a dummy function that raises an exception in the conversion from a vol to the ML datatype.
David
I suspect Pierre-Alain is implicitly assuming that somehow PolyML uses some form of low bits tag to differentiate whether an integer bit-pattern (e.g. a value of type intptr_t) is either a vol or an int64_t. I suspect the answer is no.
Perhaps it would help if we could see the definition of the union type in C.
David _______________________________________________ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
On 21/08/2012 07:41, Pierre-Alain Bourdil wrote:
Hi,
the structure is pretty simple :
// This is a STRUCT3 struct A {...}
struct B { enum {E1,E2} kind // ok for mapping enum union { int64_t ref ; // there was a discussion about int64 platform independant conversion. I just defined a Cint64_t as Clong struct A *a; } arg }
As i explained, my problem is to differentiate int64_t from Cpointer Cstruct in my vol2enum function..
Presumably at the level of struct B you can distinguish them depending on the value of "kind". Maybe you can represent struct B as an ML value and provide a conversion between those. It would require a bit of care especially as I'm not exactly clear about the alignment requirements for "arg" if you want this to run on both 32-bits and 64-bits.
David