-- CedarMemoryImpl.mesa
-- Last changed by Doug Wyatt, September 26, 1980 12:33 AM
DIRECTORY
Memory,
CedarStorage USING [Zone, CreateZone],
CedarStorageOps USING [NewQuantumNode, FreeQuantumNode],
SystemDefs USING [AllocateHeapNode, FreeHeapNode];
MemoryImpl: PROGRAM
IMPORTS CedarStorage,CedarStorageOps,SystemDefs
EXPORTS Memory = {
nodes: INTEGER←0; -- for debugging
UZHandle: TYPE = LONG POINTER TO UZObject;
UZObject: TYPE = MACHINE DEPENDENT RECORD [
procs(0:0..31): LONG POINTER TO UZProcs,
data(2:0..31): CedarStorage.Zone
];
UZProcs: TYPE = MACHINE DEPENDENT RECORD [
alloc(0): PROC[self: UZHandle, size: CARDINAL] RETURNS[LONG POINTER],
dealloc(1): PROC[self: UZHandle, object: LONG POINTER]
];
UZAlloc: PROC[self: UZHandle, size: CARDINAL] RETURNS[LONG POINTER] = {
nodes←nodes+1;
RETURN[CedarStorageOps.NewQuantumNode[size: size, zone: self.data]];
};
UZDeAlloc: PROC[self: UZHandle, object: LONG POINTER] = {
nodes←nodes-1;
CedarStorageOps.FreeQuantumNode[ptr: object];
};
czone: CedarStorage.Zone ← CedarStorage.CreateZone[
dm: heap, tr: quantized, initialSize: 20000];
uzprocs: UZProcs ← [alloc: UZAlloc, dealloc: UZDeAlloc];
uzobject: UZObject ← [procs: @uzprocs, data: czone];
uzhandle: UZHandle = @uzobject;
zone: UNCOUNTED ZONE ← LOOPHOLE[uzhandle];
NewZone: PUBLIC PROC[STRING] RETURNS[UNCOUNTED ZONE] = { RETURN[zone] };
MDSHandle: TYPE = POINTER TO MDSObject;
MDSObject: TYPE = MACHINE DEPENDENT RECORD [
procs(0:0..15): POINTER TO MDSProcs,
data(1:0..15): POINTER TO MDSData
];
MDSProcs: TYPE = MACHINE DEPENDENT RECORD [
alloc(0): PROC[self: MDSHandle, size: CARDINAL] RETURNS[POINTER],
dealloc(1): PROC[self: MDSHandle, object: POINTER]
];
MDSData: TYPE = RECORD[];
MDSAlloc: PROC[self: MDSHandle, size: CARDINAL] RETURNS[POINTER] = {
RETURN[SystemDefs.AllocateHeapNode[size]];
};
MDSDeAlloc: PROC[self: MDSHandle, object: POINTER] = {
SystemDefs.FreeHeapNode[object];
};
mdsprocs: MDSProcs ← [alloc: MDSAlloc, dealloc: MDSDeAlloc];
mdsobject: MDSObject ← [procs: @mdsprocs, data: NIL];
mdshandle: MDSHandle = @mdsobject;
mds: PUBLIC MDSZone ← LOOPHOLE[mdshandle];
}.