TANGLE

For our next act, after having studied POOLtype, we shall now study TANGLE. Unlike POOLtype, this is not a trivial program; it is the bedrock on which WEB rests (or rested). It is much longer than POOLtype:

So it’s about 9 times bigger. TeX in turn is about 7 times bigger than TANGLE, so we’re nicely in between.

Comparison of sizes

See List of WEB files.

Program Pages Sections Fraction of TeX
POOLTYPE 7 + 4 20 + 2 ≈ 1.4% to 2%
GLUE 8 + 3 26 + 1 ≈ 1.6% to 2%
DVITYPE 47 + 7 111 + 2 ≈ 8% to 10%
TANGLE 66 + 9 187 + 2 ≈ 13.5% to 14%
WEAVE 98 + 12 263 + 2 ≈ 19% to 20.5%
TEX 478 + 57 1378 + 2 100%

Reasons for studying TANGLE

What TANGLE needs to do

Before we start studying the TANGLE program itself, let’s take a few minutes to think about a few things it needs to do: (These are just haphazard thoughts that occurred to me before reading the program; some of them are wrong and TANGLE works differently. The point of the exercise is to know what sort of things to expect.)

Outline of TANGLE

Based on what I’ve read so far (up to section 11), this is my understnding of how TANGLE works.

Recall that TANGLE needs to turn a WEB source file like (say) pooltype.web into a Pascal file pooltype.p. It has to do this while expanding macros and module (section) references, and also supporting some additional features like treating strings as numbers. To do this, it operates in two phases:

  1. (Compression) First it reads the .web file (and the .ch changefile if any) into a compressed representation in memory, one which is aware of e.g. what the strings and modules are.

  2. (Expansion) Then it writes out this in-memory representation into the output file.

So the program can be thought of as:

    [read] -> [data structures] -> [write]

And we an try to learn each of the three parts separately (starting with the data structures of course).

The data structures: Mainly (see top of /program/tangle/tangle-9 on this site),

The “write” is further decomposed into:

Table of contents

(Note the “section” below is what is known as “module” in the program! I’ll use both names interchangeably.)

Because of its length, let’s study each part separately. The horizontal lines below group the 20 parts into what seemed natural places to me.