I would like to get rid of lvalues, because they pollute the system
severely. It isn't just the type system .. the problem is that 
you cannot write *Felix* functions that operate on lvalues, only 
define C primitives which do so.

A proposed solution to this is rather interesting: change 
the meaning of

        var x : int;

so that x is a POINTER to an int (i.e. a reference, as in ML).

Already we can use pointers to X in some places where X is needed,
for example

        a . b

works for struct A where a is an A or an &A: the pointer is deref
automatically (since pointers can't have components, this is safe).

For a function

        f (x:int)=> x + x;

it isn't quite so clear if we can do this hack. I'm not sure how
overload resolution would cope (matching parameter 'int' with 
argument '&int') .. given that some functions will actually
operate on pointers.

However the lvalue->value decay already being done already
has to cope with this kind of crap.. so maybe it will work.

Clearly

        x + 1

is ambiguous .. incrementing the pointer? or the value it points to?

There is another issue:

        proc pre_incr: lvalue[int] = "++$1";

would now become

        proc pre_incr: &int = "++*$1";

which means all functions -- both Felix and C primitives -- would use
pass by value. This will work fine.. but it is potentially inefficient
because it hides the variable being incremented, introducing an
aliasing problem.. it isn't clear C++ compilers such as gcc can
unravel this.. 

        var x = 1;
        ++x;       // generates ++*&x

but it has to unravel immediately to

        ++x

to allow some optimisations to work.




-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to