Oberon || Library || Module Index || Search Engine || Definition || Module
CONST growsup = 1; growsdown = 2; TYPE Direction = SHORTINT; (* growsup, growsdown *)
TYPE Stack = POINTER TO StackRec; TYPE StackRec = RECORD (Disciplines.ObjectRec) align: Types.Size; END;
PROCEDURE Init(stack: Stack; baseoff, align: Types.Size; dir: Direction);
PROCEDURE Allocate(stack: Stack; size, align: Types.Size; autofree: BOOLEAN) : Types.Size; PROCEDURE Free(stack: Stack; offset: Types.Size);
PROCEDURE Close(stack: Stack); PROCEDURE AllocateClosed(stack: Stack; size: Types.Size) : Types.Size;
PROCEDURE GetSize(stack: Stack) : Types.Size;
Init initializes the stack frame object stack for the direction dir (usually growsdown) with an initial offset of baseoff. The frame pointer and baseoff are considered to be multiplies of align. All alignment parameters given to Allocate must be divisors of this alignment.
Allocate allocates size bytes (must be positive) for the stack frame associated with stack and returns the offset which is a multiply of align. If autofree is set to TRUE, the area remains allocated until Close gets called. Otherwise, the area has to be freed using Free.
Free allows to deallocate the area at offset which was formerly returned by Allocate with autofree set to FALSE.
Close closes the regular allocation phase of the stack. Neither Allocate nor Free may be called for stack afterwards. All offsets returned by Allocate with autofree set to FALSE must have been freed before.
AllocateClosed allows to allocate space (with the alignment given to Init) that is available from begin to end of the procedure. In contrast, areas allocated by Allocate are only available from the point where Allocate was called until the area is either freed using Free or automatically closed by Close. AllocateClosed is useful if we want to save only those registers that are actually used. But this is not known until the code for the whole block is generated. Please note that AllocateClosed must not be called before closing the stack and not after GetSize was called for the stack.
GetSize returns the next aligned offset beyond the allocated area. This is the size of the allocated area if baseoff was 0. This procedure must not be called unless Close has already been called for stack.
Currently, CompilerStackAllocations has no way of generating CompilerErrors events for the current compilation process. Hence, CompilerStackAllocations has to resort to assertions to assure that offsets are kept within the limits of the representation of Types.Size.
Oberon || Library || Module Index || Search Engine || Definition || Module