User guide
3.3. GLOBAL FUNCTIONS 47
Decimal range GB2312 bytes
0 < dd < 127 <dd>
128 < xxyy < 9494 <xx+160> <yy+160>
res := compch(ch1, ch2) CIN:y, POS:y, NAT:y
This function compares two characters ignoring case. It yields -1 (+1) if ch1 is
earlier (later) in the collating sequence than ch2, and 0 if they are equal.
res := compstring(s1, s2) CIN:y, POS:y, NAT:y
This function compares two strings ignoring case. It yields -1 (+1) if s1 is earlier
(later) in the collating sequence than s2, and 0 if the strings are equal.
res := cowait(arg) CIN:y, POS:y, NAT:y
This call suspends the current coroutine and returns control to its parent by re-
suming execution of the function that cause d its suspension, yielding arg as result.
When cowait(arg) next receives control it yields the result it is given. The definition
of cowait is in blib.b and is as follows.
LET cowait(a) = VALOF
{ LET parent = currco!co_parent
currco!co_parent := 0
RESULTIS changeco(a, parent)
}
cptr := createco(fn, size) CIN:y, POS:y, NAT:y
BCPL uses a stack to hold function arguments, local variables and anonymous
results, and it uses the global vector and static variables to hold non-local quanitities.
It is somet i me s convenient to have separate runtime stacks so that different parts of
the program can run in pseudo parallel i sm. The coroutine mechanism provides this
facility.
Coroutines have distinct stacks but share the same global vector, and it is natural
to rep r es ent them by pointers to their stacks. At the base of each stack there are six
words of system information as shown in figure 3.1.
sz c P1 L1fn
suspended
stack frame
resumption point
coroutine chain
parent link
cptr
Figure 3.1: A coroutine stack
The resumption point is P poi nter belonging to the function that caused the sus-
pension of the coroutine. It becomes the value of the P pointer when the coroutine