User guide

2.5. SEPARATE COMPILATION 31
restriction is exemplified below.
GLOBAL { var:200 }
LET f1(...) BE
{ LET oldvar = var // Save the current value of var
var := ... // Use var during the call of f1
...
f2(...) // var may be used in f2
...
IF ... DO f1(...) // f1 may be called recursively
var := oldvar // restore the original value of var
}
AND f2(...) BE // f2 uses var as a free variable
{ ... var ... }
2.5 Separate Compilation
Large BCPL programs can be split up into sections that can be compiled sepa-
rately. When loaded into memory they can communicate with each other using
a special area of store called the Global Vector. This mechanism is simple and
machine independent and was put into the languag e since linkage editors at the
time were so primit ive and machine dependent.
Variables residing in the global vector are declared by GLOBAL declarations
(see section 2.4.3). Su ch variables can be shared between separately compiled
sections. This mechanism is simila r to the u sed of BLANK COMMO N in Fortran,
however there is an additional sim p l e rule to permit access to funct i on s and
routines declar ed in different sections.
If the definition of a function or routine occurs within the scope of a global
declaration for the same name, it provides the initial value for the corresponding
global variable. Initialization of such global var i ables takes place at load time.
The three files shown in Table 2.1 form a simp le example of how separate
compilation c an be organised.
File demohdr File demolib.b File demomain.b
GET "libhdr" GET "demohdr" GET "demohdr"
GLOBAL { f:200 } LET f(...) = VALOF LET start() BE
{ ... { ...
} f(...)
}
Table 2.1 - Separate com p i l at i on example