So the following no longer works: for a record or struct in a variable:

        struct X { x:int; };
        var v = X(1);

        v.x += 1;

What happens is the parser translates this to:

        incr (& (v.x) , 1 );

however, v.x is not considered addressable despite the fact that you can write

        v .  x = 1;

Assignment to a projection involves builtin functionality. The += operator
is defined in the library.

You should note that now v. x means

        x v

To make it work, you have to use a pointer projection:

        v (&x)

is a pointer to int. So you have to write this:

        *&v.x += 1;


by a happy quirk of precedence, & binds to the v only,
whereas * binds more weakly so this is equivalent to

        *((&v) . x))

or 

        *(x (&v))

Now, the parser translates that to:

        incr (&*(&v.x), 1 )

which then reduces to

        incr ( &v . x, 1 )


So to summarise: a projection of an lvalue isn't an lvalue. To get one you have 
to
to take the address of the lvalue, apply what becomes a pointer projection and
returns a pointer,  then dereference it to convert the pointer to an lvalue.

Then the parse magic can address the lvalue, not because addressing lvalues
is allowed (there's no such thing), but because of the reduction

        &* expr --> expr

i.e. because you're allowed to address a pointer dereference to get back
the pointer.

So, I know this looks messy. But the good news is that now the technology is
universal. There are no special cases. It always works.

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to