<ulclass="crumbs"><li><ahref="../index.html">Home</a></li><li><ahref="../intern.html">Inter Modules</a></li><li><ahref="index.html">pipeline</a></li><li><ahref="index.html#P">Preliminaries</a></li><li><b>What This Module Does</b></li></ul></div>
<pclass="commentary firstcommentary"><aid="SP1"class="paragraph-anchor"></a><b>§1. Prerequisites. </b>The pipeline module is a part of the Inform compiler toolset. It is
presented as a literate program or "web". Before diving in:
full details, but essentially: it's C without predeclarations or header files,
and where functions have names like <spanclass="extract"><spanclass="extract-syntax">Tags::add_by_name</span></span> rather than just <spanclass="extract"><spanclass="extract-syntax">add_by_name</span></span>.
<pclass="commentary firstcommentary"><aid="SP2"class="paragraph-anchor"></a><b>§2. Pipelines. </b>This module manages the process of working on trees of Inter code by running
them through a "pipeline" of "steps", each performed in turn. Each step makes
use of an algorithm called a "stage" which transforms the tree in some way:
perhaps adding, removing or rearranging material, or perhaps just looking for
problems with it. <ahref="../inter/index.html"class="internal">inter</a> currently has about 20 different stages, though
no single pipeline is ever likely to need all 20.
</p>
<pclass="commentary firstcommentary"><aid="SP3"class="paragraph-anchor"></a><b>§3. </b>Command-line users of the Inform tool chain are free to define their
own pipelines, perhaps to experiment with adding new optimisation stages, or
to do other things with Inter code. To help with this, pipelines are specified
as text files, written in their own definition language. A brief guide to this
language can be found in <ahref="../inter/M-pas.html"class="internal">Pipelines and Stages (in inter)</a>.
</p>
<pclass="commentary">See <ahref="2-pp.html"class="internal">Parsing Pipelines</a> for how such files are turned into <ahref="2-pp.html#SP1"class="internal">inter_pipeline</a>
objects, each made up of <ahref="2-pp.html#SP2"class="internal">pipeline_step</a> objects.
</p>
<pclass="commentary">The mechanics of running through a pipeline can be found in <ahref="2-rp.html"class="internal">Running Pipelines</a>.
</p>
<pclass="commentary">Pipelines can go wrong in two different ways: either by failing to be properly
defined because of syntax errors in their definitions, or by failing to run
properly. For example, if we compile this Basic Inform project:
<pclass="commentary">...then the <ahref="../inform7/index.html"class="internal">inform7</a> compiler happily makes an Inter tree, on the
assumption that an Inter function called <spanclass="extract"><spanclass="extract-syntax">Cryptid</span></span> will be defined in one
of the kits to be loaded in later. But when later comes, the <spanclass="extract"><spanclass="extract-syntax">compile</span></span> pipeline
has to halt when it fails to find <spanclass="extract"><spanclass="extract-syntax">Cryptid</span></span> anywhere. The process has to halt
with error messages at the command line, or a legible problem message for users
of the GUI application.
</p>
<pclass="commentary">Both sorts of pipeline error are dealt with by <ahref="2-pe.html"class="internal">Pipeline Errors</a>.
</p>
<pclass="commentary firstcommentary"><aid="SP4"class="paragraph-anchor"></a><b>§4. </b>For purposes of Inform, two pipelines are important:
</p>
<ulclass="items"><li>●<spanclass="extract"><spanclass="extract-syntax">build-kit</span></span> reads in the source code for a kit written in Inform 6
(broadly C-like) syntax, compiles that to Inter code, and then saves this
as a binary Inter file.
</li><li>●<spanclass="extract"><spanclass="extract-syntax">compile</span></span> works on an Inter tree produced by <ahref="../inform7/index.html"class="internal">inform7</a> from natural
language source text, links in one or more binary Inter files from kits,
optimises the result, and then generates final code.
</li></ul>
<pclass="commentary">The <ahref="../supervisor-module/index.html"class="internal">supervisor</a> module decides when these are to be "run", and sets them
up with configuration details — what Inter architecture to use, where to
put the resultant files, when a kit needs to be rebuilt, and so on. None of
that is our problem here. Roughly speaking, though, <spanclass="extract"><spanclass="extract-syntax">build-kit</span></span> is run only
occasionally, when the source code for a kit is modified — for most Inform
users, that will be never — whereas <spanclass="extract"><spanclass="extract-syntax">compile</span></span> is run every time the user of
an Inform GUI app clicks the "Go" button.
</p>
<pclass="commentary">Speed is therefore unimportant for stages used in <spanclass="extract"><spanclass="extract-syntax">build-kit</span></span>, but very
important for stages used in <spanclass="extract"><spanclass="extract-syntax">compile</span></span>. As a rule of thumb, if the user waits
10 seconds for the result after clicking "Go" then the first 6 seconds are spent
in <ahref="../inform7/index.html"class="internal">inform7</a>, the next 3 seconds running the <spanclass="extract"><spanclass="extract-syntax">compile</span></span> pipeline, and the final
second in whatever compiler turns the final code into an executable — usually
Inform 6.
</p>
<pclass="commentary firstcommentary"><aid="SP5"class="paragraph-anchor"></a><b>§5. </b>The <spanclass="extract"><spanclass="extract-syntax">compile</span></span> pipeline is as follows. Here the <ahref="../supervisor-module/index.html"class="internal">supervisor</a> module has
already set the variables <spanclass="extract"><spanclass="extract-syntax">*in</span></span> and <spanclass="extract"><spanclass="extract-syntax">*out</span></span> respectively to the source of
Inter (in fact, it will be in memory, not in a file), and to the filename
for where the final code is to be written. By default <spanclass="extract"><spanclass="extract-syntax">*tout</span></span> is not set
when the Inform 7 GUI app is being used, but it's sometimes set when testing
at the command line. If it is set, then the final state of the Inter tree
<spanclass="comment-syntax">The following does nothing if the variable *tout does not exist and it</span>
<spanclass="comment-syntax">will exist only when debugging:</span>
<spanclass="plain-syntax">optionally-generate text </span><spanclass="reserved-syntax">-></span><spanclass="plain-syntax"></span><spanclass="identifier-syntax">*tout</span>
<pclass="commentary firstcommentary"><aid="SP6"class="paragraph-anchor"></a><b>§6. </b>These of course use three subsidiary pipelines. The <spanclass="extract"><spanclass="extract-syntax">assimilate</span></span> pipeline
turns raw Inform 6-syntax source code into Inter material: so it does a great
deal of work when <spanclass="extract"><spanclass="extract-syntax">build-kit</span></span> is running, but only a very little for <spanclass="extract"><spanclass="extract-syntax">compile</span></span>,
when all it needs to worry about will be a few scraps of I6 code compiled
by <ahref="../inform7/index.html"class="internal">inform7</a> from uses of the low-level <spanclass="extract"><spanclass="extract-syntax">Include (-</span></span> ... <spanclass="extract"><spanclass="extract-syntax">-)</span></span> feature.
<pclass="commentary">The <spanclass="extract"><spanclass="extract-syntax">link</span></span> pipeline sorts out cross-references between Inter code made by
<ahref="../inform7/index.html"class="internal">inform7</a>, and Inter code loaded in from kits. Each side may need to call
functions or access variables in the other. This process is more active
and less symmetrical than linking would be for a C-like language, but "linking"
<pclass="commentary">Finally, the <spanclass="extract"><spanclass="extract-syntax">optimisation</span></span> pipeline is a chance to simplify the Inter tree
without changing its meaning, so that equivalent but faster or smaller final
code is generated. At present this does relatively little, but it's a start.
<pclass="commentary firstcommentary"><aid="SP7"class="paragraph-anchor"></a><b>§7. </b>To create a new stage, you may want to copy a simple existing one — say,
the <ahref="6-erls.html"class="internal">Eliminate Redundant Labels Stage</a>— as a model. Note that a stage
must be "created", and your function to create it should be called from the
function <ahref="2-pp.html#SP10"class="internal">ParsingPipelines::parse_stage</a>.