-- HeapMemoryImpl.mesa
-- Last changed by Doug Wyatt, September 26, 1980 12:30 AM

DIRECTORY
Memory,
InlineDefs USING [LowHalf],
SystemDefs USING [AllocateHeapNode, FreeHeapNode];

MemoryImpl: PROGRAM
IMPORTS InlineDefs,SystemDefs
EXPORTS Memory = {

UZHandle: TYPE = LONG POINTER TO UZObject;

UZObject: TYPE = MACHINE DEPENDENT RECORD [
procs: LONG POINTER TO UZProcs,
data: LONG POINTER TO UZData
];

UZProcs: TYPE = MACHINE DEPENDENT RECORD [
alloc: PROC[zone: UZHandle, size: CARDINAL] RETURNS[LONG POINTER],
dealloc: PROC[zone: UZHandle, object: LONG POINTER]
];

UZData: TYPE = RECORD[];

nodes: INTEGER←0;

UZAlloc: PROC[zone: UZHandle, size: CARDINAL] RETURNS[LONG POINTER] = {
nodes←nodes+1;
RETURN[SystemDefs.AllocateHeapNode[size]];
};

UZDeAlloc: PROC[zone: UZHandle, object: LONG POINTER] = {
nodes←nodes-1;
SystemDefs.FreeHeapNode[InlineDefs.LowHalf[object]];
};

uzprocs: UZProcs ← [alloc: UZAlloc, dealloc: UZDeAlloc];
uzobject: UZObject ← [procs: @uzprocs, data: NIL];
uzhandle: UZHandle = @uzobject;

MDSHandle: TYPE = POINTER TO MDSObject;

MDSObject: TYPE = MACHINE DEPENDENT RECORD [
procs: POINTER TO MDSProcs,
data: POINTER TO MDSData
];

MDSProcs: TYPE = MACHINE DEPENDENT RECORD [
alloc: PROC[zone: MDSHandle, size: CARDINAL] RETURNS[POINTER],
dealloc: PROC[zone: MDSHandle, object: POINTER]
];

MDSData: TYPE = RECORD[];

MDSAlloc: PROC[zone: MDSHandle, size: CARDINAL] RETURNS[POINTER] = {
RETURN[SystemDefs.AllocateHeapNode[size]];
};

MDSDeAlloc: PROC[zone: MDSHandle, object: POINTER] = {
SystemDefs.FreeHeapNode[object];
};

mdsprocs: MDSProcs ← [alloc: MDSAlloc, dealloc: MDSDeAlloc];
mdsobject: MDSObject ← [procs: @mdsprocs, data: NIL];
mdshandle: MDSHandle = @mdsobject;

zone: UNCOUNTED ZONE ← LOOPHOLE[uzhandle];

NewZone: PUBLIC PROC[STRING] RETURNS[UNCOUNTED ZONE] = { RETURN[zone] };

mds: PUBLIC MDSZone ← LOOPHOLE[mdshandle];

}.