On 29/01/2014, at 1:43 PM, srean wrote:

> Few days ago I was thinking of the other way round. As long as compiling the 
> generator can be deferred, one could push/ inline the body of the loop inside 
> the generator. The generator takes the "body" as an argument, but I dont mean 
> a closure which is a runtime construct. Was thinking if its possible to do 
> this in compile time using Felix's laziness.
> 
> I was assuming that the "body of the loop" refers to variables in a call 
> stack, but the Felix way i guess is to hold them in the heap.


Well you can already do this, its basic functional programming stuff, eg

        List::iter (proc (v:T) { body; }) somelist;

Of course, you're passing in a closure, so now you have the problem of
"inlining" the closure in that. Same problem in some sense.

Now, if you have some definition of List::iter that has some loop,
and the "closure" argument is say just a function name, and it is lazily
bound like this:

        proc iter[T] (val body: T -> 0) { .... body(); ... }

then hopefully a call like:

        proc f (x:int) => println$ x;
        iter f (list (1,2,3));

will reduce to

        .... f(value); ....

and then f can be inlined .. of course certain ppl convinced me that
procedure arguments should default to eager evaluation which
would prevent this .. should I revert?

The idea with the coroutine model is you inline BOTH the loop body
and the generator, and then just zig-zag between them.

First things first. I have implemented 

        BEXE_cgoto (expr)

where expr has to be a label variable. But now, I have to have some way to
make a label variable and put labels in it :)

Incidentally this will make finite state machines nice (if unsafe!):

        var state = &start;

        machine:>>
                goto *state;

        start:>>
                dostuff;
                state = &next_label;
                goto machine;

        next_label:>>
                do stuff ...

etc. This is faster (a LOT faster) than doing a match on an integer:

        match state with
        | 1 => ...
        | 2 => ....

because matches are sequential. So the last case won't be found until
after all the others are checked. Of course you can do this with an array
of procedures and that's O(1) to find the handler instead of O(N) but now
your pay the overhead of closures.



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




------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&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