|
Leonardus
|
B __odo activates optimizing features of bind. A procedure Ax is internally modified in an arbitrary manner by setting true __odo Ax bind.
An initial pass iteratively creates new optimization opportunities, thus:
2 3 5 7 11 mul mul mul mul ==> 2310
(if constant expression evaluation is actvated.)
The iterations runs as long as changes are possible, but as maximum
DET_MAXODO times
PostScript level 3 offers a feature called idiom recognition. ODO establishs
a similar approach of extending the bind operator.
Substitution of elementary sequences to simplify using (unregistered) operators.
1 --sub-- ==> --__isI-- --__dec-- 1 --add-- ==> --__isI-- --__inc-- 0 --add-- ==> 0 --eq-- ==> --__eq0--
This is related to the PostScript idea of "Idiom Recognition". Examples in Forth would be:
2 --copy-- ==> --__2dup-- --exch-- --pop-- ==> --__nip-- 3 2 --roll-- ==> --__rot-- 3 1 --roll-- ==> --__-rot--
bind could be removed, if its found in a procedure currently bound
bind works on procedures and on all procedures which are elements of the
top procedure.
The procedures should be set to read-only / const to mark the applied changes.
The equivalent of constexpr in C++.
The following example evaluations should be converted at the time of __odo:
1 1 --add-- ==> 2 1.2 2.0 --sub-- ==> -0.8 1.0 2.0 --mul-- ==> 2.0
true false or ==> true
bool {x x} {x x} --ifelse-- ==> x x
bool {x x} --if-- ==> x x | {}
literal1 literal2 --exch-- ==> literal2 literal1
{x y z} --exec-- ==> x y z
[ x ] --cvx-- ==> { x }
1 1 --cvq-- ==> Q
(A) (A) ?
As described in the Red Book.
If __odo in a procedure knows which operands will be produced, it can actually drop some of the stack checks.
Replacement by the single operator with the extension of if, ifelse, repeat, etc. to support this as well.