skaller wrote:
>> I really think that something like this would be the simplest solution.
>
> Err.. which of the 100 different ways to do it are you suggesting
> is the simplest?
I meant the whole proc returning stuff form. I thought that would have
been clear by what I quoted :)
>
> [about the optimization of composed functions] I don't think it will at the
> moment, but if we can formalise
> the pattern, I can probably make it.
I got one idea, but I'm not sure if it's firm enough, and the felix
optimizer may already do this. Basically, we exploit the fact that a val
is constant, and input and output values being of the same type. So when
we have this:
-----------------------
proc f(val x:int): int { return x + 1; }
-----------------------
which converts to:
-----------------------
proc f'(val x:int) (val px:&int) { *px = x + 1; }
-----------------------
We know that x won't be modified by the function. Assuming that the
optimizer can tell if a function argument is a val, we can convert this:
-----------------------
val x = 2;
val y = f(x);
-----------------------
Into this:
-----------------------
val x = 2;
var tmp2;
f' tmp1 &tmp2;
val y = tmp2;
-----------------------
Since tmp2 is only used once, then assigned to y, the optimizer should
be able to just inline y for tmp2. This principle should still work for
composed functions, with just some recursive applications of this
optimization. If we have the already desugared:
-----------------------
proc g'(val y:int) (val py:&int) { *py = y + 2; }
proc h'(val z:int) (val pz:&int) { *pz = z + 2; }
-----------------------
This:
-----------------------
val x = 2;
val y = h(g(f x));
-----------------------
Will desugar into this:
-----------------------
val x = 2;
var tmp1: int;
f' tmp1 &tmp1;
var tmp2 = tmp1;
g' tmp2 &tmp2;
var tmp3 = tmp2;
g' tmp3 &tmp3;
val y = tmp2;
-----------------------
Then, we just recursely apply the optimization to eliminate tmp1, tmp2,
and tmp3. I think it should work for vars as well, but it wouldn't be
that optimal as I think you have an implied copy inside the function.
Not sure what we'd do with refs though.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language