Next: OIL Expressions, Previous: OIL Basics, Up: Optimizer Idiom Language [Index]
An OIL file is encoded as an ASCII text file using no codepoints outside the range 0-127; using 10 for newline (as on a UNIX or Linux system) is always acceptable, but using 13 then 10 (as is common on Windows or DOS) for newline is acceptable only if your C compiler recognizes that as a newline. I have no idea what happens if you use just 13 on an Apple computer on which that is the common newline convention.
Comments can be given anywhere in the file by writing lines starting
with semicolons (known as hybrids to INTERCAL
programmers). It’s also possible to write a semicolon after part
of a line to comment out the rest of the line. Inside braced C
expressions, comments can be given anywhere whitespace would be allowed
by placing them between /*
and */
(in such
cases, the comments will be copied verbatim to the C temporary files
used when building the C-INTERCAL compiler, where your C
compiler will ignore them). Whitespace is ignored nearly everywhere;
the only places it isn’t ignored are in the middle of a decimal
constant, inside square brackets, immediately after one of the
characters ‘.:#_}’, and anywhere that C
doesn’t allow it in quoted C code. (This means that you can even
place it inside operators like && if you like, as long as
they’re part of OIL code and not C code, although doing this is
not recommended.) If you use whitespace in a situation where it
isn’t ignored, that’s almost certainly an error.
Idioms are grouped into groups of idioms by placing an identifier in square brackets before the group; this follows the rules for C identifiers, except that there’s a maximum length of 30 characters. This identifier is the ‘name’ of the group, which has no effect except on optimizer debug output; for that matter, the only effect a group has is that all idioms in the group look the same in optimizer debug output, because they have the same name. It’s recommended that idioms only have the same name if they are the same idiom, possibly written in several ways. For example, a shift by 0 has no effect and may as well be removed from the output; the way to express this in OIL is:
[nullshift] (_1 >> #0)->(_1) (_1 << #0)->(_1)
Here, nullshift is the name of the group of idioms, and two idioms are given; one which removes a null rightshift, and one which removes a null leftshift.
As the example above shows, the syntax of an idiom itself is
(pattern)->(replacement)
The parentheses here are actually part of the pattern and/or replacement, and as such sparks (apostrophes) or rabbit-ears (double quotes) can be used instead; they’re shown in the syntax because the outer layer of parenthesising is always required. Both the pattern and replacement are OIL expressions, although they both have their own special syntax elements as well.
Next: OIL Expressions, Previous: OIL Basics, Up: Optimizer Idiom Language [Index]