C.7 OIL Tips
Here are some tips for the best use of OIL:
-
The
OIL compiler has a few deficiencies, such as error
messages that don’t give you much of an idea of what you did
wrong (to compensate for this, it does give a reasonably accurate
line and character number where the error happened), limits on things
like how deep expressions can be nested and how many idioms are
allowed (if you hit the first, you should really break it up into
smaller idioms if possible, and if you hit the second, increase
MAXTOFREE
in oil.y; this isn’t a limit on the
number of idioms but on the number of strings that are allocated
internally to process the idioms), and lack of error checking
(invalid OIL may produce errors in the
OIL compiler, or cause the output C code to
contain errors or warnings, or may even appear to work).
- When you have symmetrical operators in an idiom (like C binary
logical operators), you need to write the idiom both ways round (in the
same group of idioms, preferably), or write another idiom to
standardise the format first; the first method can get very tedious
when there are many symmetrical operators in an idiom, and the second
is prone to optimizer loops and subtle errors (both methods have been
used in the provided idiotism.oil file).
- Idioms should preferably be as general as possible, broken down
into many separate idioms rather than all as one big idiom, and match
the smallest part of the expression being optimized that is necessary
for the idiom to be correct in all circumstances; all of these help to
improve the performance of the optimizer in terms of what it can
optimize.
- If a program’s optimizing incorrectly, or you just want to
see how the optimizer deals with a particular program, it’s
possible to debug the optimizer by giving the -h,
-H, or -hH (see -h) switch to the C-INTERCAL
compiler, which will cause debug information to be output on stderr.
-h will show the initial and final expressions for each
expression that was given as input to the optimizer, as well as a list
of all optimizations used, in a language that’s a sort of mix of
C, INTERCAL, and OIL;
-H will do the same, and also show the intermediate stages
in the optimization. -hH is like -H, but
produces its output entirely in C, so that the various intermediate
stages can be tried with a C compiler, or for people who are fed up of
reading INTERCAL. -H can be a useful
learning resource for people who want to understand how a particular
INTERCAL expression works.
- Make sure that the optimizer doesn’t change a statement from
a run-time error into something that silently succeeds! Checking which
bits can and can’t be 1 is one good way to avoid this, especially
with mingles. Likewise, don’t optimise a run-time error into a
compile-time error (although creating a compile-time warning in this
situation is fine).
- You can help! If you find an idiom that the optimizer isn’t
optimizing correctly, feel free to add it, or multiple idioms that come
to the same thing, to idiotism.oil. In such a case, it
would help other users if you would submit your new optimizer idiom to
the project (see Reporting
Bugs); this will help other users and future releases of
INTERCAL, and also has a chance of allowing other users to
check your new idioms to see if they cause problems or could be
written better.