[mercury-users] using univ with C

QRL_Charles QRL_Gretton g12.charles.gretton at gmail.com
Thu Jun 5 14:26:05 AEST 2008


I'm not trying to store a list (or array) of words in C. The C macro
that gives me different "pushes" for different types looks as follows
-- i.e., I want the C code to be able to reason about the type of the
contents.


#define __IMPLEMENT__POLYMORPHIC_LIST_IN_C__PUSH(TYPE_NAME,
FUNCTION_NAME) struct polymorphic_list_in_c* \
    FUNCTION_NAME(struct polymorphic_list_in_c* list, \
				     void* _data_element){		\
  TYPE_NAME* data_element = (TYPE_NAME*)_data_element; \
  TYPE_NAME* list_data;	       \
...			


In the end, I expect the code I'm looking for will occure something like:


:- pragma foreign_proc("C",
     push_back_c_vector(Univ::in, Vector_In::in,S0::mdi, S::muo),
     [promise_pure],
"
                     Vector_In->push_back(Vector_In, Univ->the_actual_data);
                     S = S0;
 ").


 - Charles

On Thu, Jun 5, 2008 at 12:33 PM, Julien Fischer
<juliensf at csse.unimelb.edu.au> wrote:
>
> On Thu, 5 Jun 2008, QRL_Charles QRL_Gretton wrote:
>
>> Q: How can I access the data of a Mercury ":-type univ" in C?
>
> Is the question, how do I get the thing inside a univ in C, or
> what is the type of a univ in C?
>
>> If my question doesn't make sense, the following might explain what
>> I'm after a bit better.
>>
>> Imagine if "univ" was a C void pointer. Then, for a Mercury interface
>> to a dynamically polymorphic list in C, I could have:
>>
>> :- pred push_back_c_vector(univ::in, c_vector::in, int_store::mdi,
>> int_store::muo) is det.
>>
>> :- pragma foreign_proc("C",
>>       push_back_c_vector(Univ::in, Vector_In::in,S0::mdi, S::muo),
>>       [promise_pure],
>> "
>>                      Vector_In->push_back(Vector_In, Univ);
>>                      S = S0;
>> ").
>
> The type of univ in C is MR_Word, which is an unsigned integral type
> such that sizeof(MR_Word) == sizeof(void *), so the above code should
> work (assuming the C list is defined as I think it is.)
>
> Julien.
> --------------------------------------------------------------------------
> mercury-users mailing list
> Post messages to:       mercury-users at csse.unimelb.edu.au
> Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
> Subscriptions:          mercury-users-request at csse.unimelb.edu.au
> --------------------------------------------------------------------------
>



-- 
cpu :: Intel(R) Core(TM)2 Duo CPU (x86_64)

mercury :: Mercury Compiler, version rotd-2008-05-07, configured for
x86_64-unknown-linux-gnu

mercury -- configure :: ./configure --prefix=`pwd`
--enable-libgrades=asm_fast.gc,hlc.gc.tr,asm_fast.gc.tr.debug,hlc.gc.tr.prof

gcc :: gcc version 4.1.3

amuse :: Hervé This was what Edward Said John Donne to the Terry Nation

--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list