// ContextInit.Bcpl  -- companion is Context.Asm
//	Code can be wiped out after initialization
// Copyright Xerox Corporation 1979

external
[
// outgoing procedures
InitializeContext

// incoming procedures
SysErr
]

// This declaration matches one in Context.Asm
structure CTX:
[
Next word	// Pointer to a list of such CTX's
Stack word	// Current stack pointer
StackMin word	// Lowest stack can go.
]		// After here, extra for user.

manifest ecCtxStackTooSmall = 2700


//-----------------------------------------------------------------
let InitializeContext(region, length, proc, extraSpace;
    numargs na) = valof
//-----------------------------------------------------------------
[
region>>CTX.Next=0		// Not on a list yet
if na ls 4 then extraSpace=0
region>>CTX.StackMin=region+(size CTX/16)+extraSpace
let s=region+length-4		// Spot to start stack.
s!0 = 0				// So you can tell where it starts
s!1=proc			// Address at which to begin.
region>>CTX.Stack=s		// Initial stack value
if s-region>>CTX.StackMin ls 0 then SysErr(nil, ecCtxStackTooSmall)
resultis region
]