On Fri, 2007-09-07 at 16:41 +0200, Rhythmic Fistman wrote:

> > Here is ackermann's function in the new format:
> >
> > //C PROC <5925>: ack_mkproc
> > void FLX_REGPARM ack_mkproc(
> >   int x_mkproc, int y_mkproc, int* _5943_mkproc)
> > {
> >   int _mkp_5953;
> >     start_5557:;
> >       ifnot(x_mkproc == 0 ==1) goto _5552;
> >       *_5943_mkproc = y_mkproc + 1 ;
> >       return;
> >     _5552:;
> >       ifnot(y_mkproc == 0 ==1) goto _5553;
> >       y_mkproc = 1;
> >       x_mkproc = x_mkproc - 1 ;
> >       goto start_5557;
> >     _5553:;
> >   ack_mkproc(x_mkproc, y_mkproc - 1 , (int*)&_mkp_5953);
> >       y_mkproc = _mkp_5953;
> >       x_mkproc = x_mkproc - 1 ;
> >       goto start_5557;
> > }
> >
> > I have no idea if this is faster or slower than the old version :)
> 
> I definitely reads better than the old one.

Really? You should try to run it before building the new version:

        flx speed/src/felix/ack 10

> Did the old one use the machine stack like that?

No, in the old version ack was a function
returning a value, in this version it is a procedure
storing a value at the place the last argument point to.

However this is a "C" function variant, so it doesn't demonstrate
the real point: in the C++ variant using a class, the calling
protocol uses the call() and resume() methods .. which permit
service calls, in which case the object goes on the heap, and
the return address is stored in the _caller variable. 

Functions don't use the _caller variable for return addresses,
they use the machine stack so they can be nested in C expressions.

They can *still* be nested in procedural form:

        f (g (x))

simply becomes

        type tmp;
        g (x, &tmp);
        f (tmp)

So you could now write a function that reads
from a channel .. because the function becomes a procedure.
But you can't PASS it or store it in a variable (yet) because
calls to functions in variables still look like:

        v (x)

instead of

        type tmp;
        v (x, &tmp);

More precisely at present we have:

        v->clone()->apply(x)

whereas we want:

        type tmp;
        pc = 99;
        return v->clone()->call(this,x,&tmp);
        case 99:

which is of course a yield.

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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to