Sun May 10 09:04:13 CEST 2009
peephole and stack
The peephole optimizer works well for a stack formulation because of
the way locality is encoded. This is especially so for the PIC18
which tunnels everything through the WREG.
However, for true partial evaluation the program structure needs to be
exposed on a more abstract level. On the other hand, the stack gives
a very natural way to bind static data early: by placing it on top.
So the real question is: how to steer static data towards the top of
the stack? How to keep a simple reduction mechanism, but write logic
on top of them such that this works best?
Examples. With ifte ( cond true false ) arguments, how to specialize
: when-done [ [ ready-flag high? ] i ] dip [ ] ifte ;
This will perform some re-arrangement of the arguments then call
ifte. I don't see any problem. This will just yield 3 [mw .]
arguments to ifte.
Now: ifte needs to know if the condition is available at compile time.
It can do this by forcing the condition macro and checking if it
reduces to a value. If so, one of the branches can be eliminated. If
not, the conditional branch construct needs to be passed to runtime.
This doesn't seem so special.
So where _is_ the problem? I think it's the coupling run time stack
vs. compile time stack. At some point a quotation needs to be
instantiated. At this point one also needs to know the input and
output argument structure.
Somehow it seems to be really natural to do eager optimizations, but
quite a leap of faith to do it lazily. Messing with the run-time
stacks is not trivial..
'dup and specialization. When a quotation that's big enough gets
instantiated more than once, there's an opportunity for sharing. This
needs extra knowledge to be filled in later: what is "big enough"?
But apart from that, it needs its type to be able to use it as a
function call! Inlined macros don't need type: they can just be
executed, but once abstracted the type is neccessary both at the call
site and at the definition site to decouple both.
next: implement run time abstraction from a pure lazy macro definition
of a language.