On Sat, 2007-12-01 at 18:09 -0800, Erick Tryzelaar wrote:
> On Dec 1, 2007 5:00 PM, skaller <[EMAIL PROTECTED]> wrote:
> > Clearly
> >
> >         x + 1
> >
> > is ambiguous .. incrementing the pointer? or the value it points to?
> 
> What if we made incrementing the pointer a separate felix function?
> It'd be clearer, and I doubt it'd be needed much.

Yes but the question is how to do overloading given:

        fun inc: int -> int = "$1+1"
        fun inc: &int -> &int = "$1+1"

        var x = 1;
        x = inc x; // x = 2?

If x is a &int, the wrong increment function would be called. Elide it
and allow argument of type &int to be use where int is specified,
in the same way that right now lval int can be used where int is 
specified, and there's no problem.

to put this another way, there's no problem if there are
no ambiguous operations on pointers, but + IS an ambiguous
operation. * is not: *px is a deref, there is no meaning
for *42. Similarly -px is unambiguously negating the value
pointed at, since you can't negate a pointer.

So you're right: if we disallow + and - on pointers, it would
work, and + and - are unsafe anyhow.

> > 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.
> 
> Could we do that in the c++ codegen, or would that need dataflow analysis?

You're missing the point: in the specification:

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

the C++ encoding is invisible to Felix .. there's nothing to analyse.
Felix just thinks this is a bunch of text. It DOES process it,
looking for $1 etc, but it doesn't really examine the C++ code.

We could certainly POST PROCESS the result of substituting the $1
out by the argument .. however this is very hard because it
needs parsing of C/C++ text, which is very hard, and impossible
without a table of which names are types.


-- 
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