I ran across an interesting optimizer for FORTH stack words in java by Ram
Janovski, and Vassilii Khachaturov, dated 2004, here:
http://black.cs.bgu.ac.il/forth-opt
Depending on which FORTH stack words you select, it'll attempt to generate
a
optimized definition using the input set of words.
i.e., if you input ab -- ba, for SWAP, and select DROP,DUP,TUCK it'll
output:
Transforming ab ==> ba
TUCK ( ab -- bab )
DROP ( bab -- ba )
i.e., if you input ab -- ba, for SWAP, and select DROP,DUP,ROT it'll
output:
Transforming ab ==> ba
DUP ( ab -- abb )
ROT ( abb -- bba )
ROT ( bba -- bab )
DROP ( bab -- ba )
Anyone aware of other FORTH stack optimizers? This one seemed pretty
good,
but has some limitations.
e.g., single FORTH and 2 FORTH words aren't symmetric - missing 2NIP,
2TUCK, -2ROT
e.g., has PICK but not the opposite, i.e., a "PLACE" - for x86 assembly
conversion
e.g., doesn't have Koopman's OVER_+, PICK_2, TUCK_2, UNDER, UNDER_+,
etc.
from here:
http://www.ece.cmu.edu/~koopman/stack_compiler/stack_co.html
e.g., doesn't generate sequences with "0 PICK", "1 PICK", "0 ROLL", "1
ROLL"
i.e., won't generate ab -- ba, for SWAP as 1 ROLL, but as:
Transforming ab ==> ba
DUP ( ab -- abb )
DUP ( abb -- abbb )
3 ROLL ( abbb -- bbba )
3 ROLL ( bbba -- bbab )
3 ROLL ( bbab -- babb )
DROP ( babb -- bab )
DROP ( bab -- ba )
Anyone know of an improved version, or some other one that's a bit more
advanced? The sourcecode is available, but it's in java...
Rod Pemberton


|