Leonardus
Loading...
Searching...
No Matches
ODO

Activation

B __odo activates optimizing features of bind. A procedure Ax is internally modified in an arbitrary manner by setting true __odo Ax bind.

Iterations

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

Idiom Substitution

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--

Recursive bind Elimination

bind could be removed, if its found in a procedure currently bound

bind Recursion

bind works on procedures and on all procedures which are elements of the
top procedure.


WORK IN PROGRESS

read-only / const procedures

The procedures should be set to read-only / const to mark the applied changes.

Constant Expressions

The equivalent of constexpr in C++.

Numbers

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

Constant Boolean Values

true false or                 ==> true
bool {x x} {x x} --ifelse--   ==>  x x
bool {x x} --if--             ==>  x x | {}

Polymorphic Constants

literal1 literal2 --exch--   ==>  literal2 literal1

exec

{x y z} --exec--   ==> x y z

cvx, cvlit

[ x ] --cvx--   ==> { x }

Constant Conversions

1 1 --cvq-- ==> Q

Constant Strings

(A) (A) ?

Immediately Evaluated Names

As described in the Red Book.

Knowledge of the Stack

If __odo in a procedure knows which operands will be produced, it can actually drop some of the stack checks.

Single-Element Procedures

Replacement by the single operator with the extension of if, ifelse, repeat, etc. to support this as well.