[<-] [ ^ ] [->] Previous: Difficulties with WEB Up: Literate Programming and WEB Next: Literate Programming WEB and Design

Independent Compilation

WEB began as a system for PASCAL code for which modularity is not an important issue (it does not really have any). For modular languages like C and C++, it is essential to be able to create multiple output files - headers and bodies, or declarations and implementations, from the WEB source. WEB has facilities for module inclusion and changing the output file, but the mechanisms are not very clean. Yet modularity is an extremely important lesson, which needs reinforcing in every single assignment. There are a number of options which are detailed in the appendix. Here we describe a simple and effective method.

Each independent piece of code, which we shall refer to here as a compilation unit, has its own WEB file which TANGLE converts into the source code. The same WEB file is used to create the .h file using WEB macros[+]. Compilation now proceeds using the source and header files. The WEB include mechanism is not used for headers, meaning that the source code stands alone, independent of WEB, and may be built on some other system where WEB is not present.

weave, however, does not operate upon the WEB files but on .root files which include the WEB source and any relevant common declarations. Thus to produce a listing, we can combine (and hence cross-reference and index) any number of individual compilation units, ranging from just the module upon which we are working to the entire software project (much as Knuth published the [LaTeX] and Metafont programs). This procedure will look familiar to users of SLITEX: slides are kept in a separate file to the root file used by the program.

cwj@cs.anu.edu.au