[Yhc] make_tuple for arbitrary number of elements

Tom Shackell shackell at cs.york.ac.uk
Tue Jan 16 13:11:51 EST 2007


Hi,

> Hi YHC,
> 
> I'm trying to do a make_tuple of 11 elements.
> 
> Is the correct structure to do:
> 
> MAKE_NODE(ret, G_infoTuple, N_NORMAL);
> 
> ...
> 
> node->args[0] = thing0
> node->args[1] = thing1
> node->args[2] = thing2
> node->args[3] = thing3
> ...
> node->args[10] = thing10
> 
> Then, how does the garbage collector know the number of elements?
> 
> I would have thought that it would basically have been make_array, but 
> make array uses data, not args; how does data help the situation?

My first question is to ask why you need to make an 11 tuple from the C 
code. I guess you must be adding support for some library, but the 
normal way to do that is using the FFI. Only one or two specialised 
things in the prelude are coded directly using the C interface.

In any case I've just pushed a patch that makes it much easier to make 
tuples from the C code. You can now use

      Node* make_nTuple(int num, ...);

To make a tuple of any size (including 0). So now you can do

    return make_nTuple(3, a, b, c);

> Finally, I would think that I would nead to heap_pushGlobal any time I 
> call anything that calls heap_alloc, but not all functions do this:
> 
> Node* _primIntegerQuotRem(Node* node){
>   Node* quot = _primIntegerQuot(node);
>   Node* rem  = _primIntegerRem(node);
>   return make_tuple(quot, rem);
> }
> 
> Could the GC not be called during _primIntegerRem, and collect quot?

Oops, yes that's a bug. This is partly why we've moved to using the FFI 
for primitives where possible. It's so easy to make mistakes.

Thanks

Tom


More information about the Yhc mailing list