User guide

54 CHAPTER 3. THE LIBRARY
cptr := initco(fn, size,a,b,c,d,e,f,g,h,i,j,k) CIN:y, POS:y, NAT:y
This function provides a convenient method of creating and initialising coroutines.
It definition is as follows:
LET initco(fn, size, a, b, c, d, e, f, g, h, i, j, k) = VALOF
{ LET cptr = createco(fn, size)
result2 := 0
IF cptr DO result2 := callco(cptr, @a)
RESULTIS cptr
}
A coroutine with main funct i on fn and given size is created and, if s ucc e ssf ul , it is
initialised by callco(cptr, @a). Thus, fn should expect a vector containing up to 11
elements. Once the newly created coroutine has initialised itself, it returns control to
initco by means a call of cowait. The result of initco is the newly created coroutine
pointer , or zero on failure. The second result (in result2) is the value returned by the
first call of cowait in the newly cr e at ed coroutine.
scb := input() CIN:y, POS:y, NAT:y
This function returns cis, the SCB of the currently selected input stream.
count := instrcount(fn,a,b,c,d,e,f,g,h,i,j,k) CIN:y, POS:y, NAT:n
This function retur ns the number of Cintco de instructions executed when eval u ati ng
the call: fn(a,b,c,d,e,f,g,h,i,j,k).
Counting starts from the first instruction of the body of fn and ends when i ts
final RTN instruction is executed. Thus when f was defined by LET f(x) = 2*x+1,
the call instrcount(f, 10) returns 4 since its body executes the four instructions:
L2; MUL; A1; RTN. The value returned by fn(a,b,c,d,e,f,g,h,i,j,k) is saved by
instrcount in t he global variable result2.
flag := intflag() CIN:y, POS:y, NAT:n
This function provides a machine dependent test to determine whether the user is
asking to interrupt t he normal execution of a program. On the Apple Macintosh flag
will be set to TRUE only if the COMMAND, OPTION and SHIFT keys are simu l tane -
ously pressed.
p := level() CIN:y, POS:y, NAT:y
This call returns the current st ack frame pointer for use in a l ate r call of longjump.
segl := loadseg(name) CIN:y, POS:y, NAT:n
This function calls sys(Sys
loadseg, name) to loads the specified compiled pro-
gram into memory. Se e Sys
loadseg on page 68 for details.
longjump(P , L) CIN:y, POS:y, NAT:y
This call causes execution to resume at labe l L in the body of a function or routine
that owns the stack frame given by P that must have been obtained by a previous call of
level. Jumps may only be used to points within the current coroutine. Jumps to labels