Next: , Up: Optimizer Idiom Language   [Index]


C.1 OIL Basics

The structure of an OIL file consists of a sequence of idioms. An optimizer idiom looks for a certain pattern in an expression (which could be an INTERCAL expression, or an expression that has already been partly optimized and therefore contains some non-INTERCAL operators), and replaces it with a replacement that’s ‘simpler’ in some sense (in the case of C-INTERCAL, ‘simpler’ is interpreted to mean ‘compiles into a faster or smaller executable when run through a C compiler’). When an OIL program acts on an input INTERCAL file, it keeps on matching idioms to simplify expressions, until none of the idioms act any more (and if a situation occurs where idioms can keep matching indefinitely, the compiler goes into an infinite loop; so don’t allow that to happen); at present, the idioms are tried from left to right, from the leaves of an expression to its root, and from the start of the OIL file to the end; but don’t rely on that, because it’s subject to change (and gets confusing when you think about what happens when the program actually does a replacement). Anyway, the point is that if an idiom can match an expression, and another idiom doesn’t change it first, then the idiom will be matched against that part of the expression eventually, and the program won’t end until there are no idioms that match the optimized expression.

At present, the only place that OIL is used in the C-INTERCAL compiler is when the -O option (see -O) is used in base 2. (Syntax is planned to extend OIL to higher bases, and some of this is documented and even implemented, but there’s no way to use it.) The idioms are read from the file src/idiotism.oil during the compilation of the C-INTERCAL from sources; you can change the idioms, but you will then have to recompile the distribution (and if you are using the config.sh method, also reinstall, but that will be pretty fast.)


Next: , Up: Optimizer Idiom Language   [Index]