On 04/11/2011, at 11:17 PM, john skaller wrote:

> Another day another bug .. :)
> 
> generated code giving error:
> //-----------------------------------------
> //EMIT USER BODY CODE
> 
>    void _rev(_poly_5493t_29757* plt)
>    void _rev(_poly_5493t_29764* plt)
>    { // in place reversal
>      struct node_t { _a4974t_29738* elt; void *tail; };
>      void *nutail = 0;
>      void *cur = *plt;
>      while(cur)
>      {
>        void *oldtail = ((node_t*)FLX_VP(cur))->tail;   // save old tail in 
> temp
>        ((node_t*)FLX_VP(cur))->tail = nutail;          // overwrite current 
> node tail
>        nutail = cur;                                   // set new tail to 
> current
>        cur = oldtail;                                  // set current to 
> saved old tail
>      }
>      *plt = nutail;                                    // overwrite
>    }



Solution 1, a temporary hack: change the list definition from

  union list[T] = | Empty | Cons of T * list[T];

to

  union list[T] = | Empty | Cons of list[T] * T;

This puts the pointer first in the node_t struct. Since we now know the offset,
the list reversal code becomes non-polymorphic.

Solution 2: maybe (not sure) we can make the body code in question 
non-polymorphic
to Felix but C++ polymorphic: use a template. C++ will figure out that the two 
typedefs
map to the same type and only generate one instance.

Solution 3: The real solution perhaps: get rid of emitted typedefs. That's 
easy, but
everywhere they're used in the code they have to be replaced by what they're 
defined to.

Solution 4: Just admit polymorphic body insertions don't work. Actually that's
already specified (in my head anyhow).

Solution 5: make 'em distinct types, eg: struct name { void *data; }.


Since I'm chasing a run time bug at the moment, solution (1) has some appeal :)

--
john skaller
skal...@users.sourceforge.net





------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to