-- FuglemanImpl.mesa
-- Last changed by Doug Wyatt, September 6, 1980 11:38 AM

DIRECTORY
Fugleman,
Memory USING [Zone];

FuglemanImpl: PROGRAM
IMPORTS Memory
EXPORTS Fugleman SHARES Fugleman = {
OPEN Fugleman;

zone: UNCOUNTED ZONE = Memory.Zone[];

Data: PUBLIC TYPE = RECORD [
foo: INTEGER,
count: CARDINAL,
flag: BOOLEAN
];
DataRef: TYPE = LONG POINTER TO Data;

procs: LONG POINTER TO READONLY Procs = zone.NEW[Procs = [
Mumble: CMumble,
Copy: CCopy,
Free: CFree
]];

-- Procedure for creating a Fugleman object

New: PUBLIC PROC[foo: INTEGER] RETURNS[Handle] = {
d: DataRef = zone.NEW[Data ← [
foo: foo, count: 0, flag: TRUE
]];
RETURN[zone.NEW[Object ← [procs: procs, data: d]]];
};

-- Operations on a Fugleman

CMumble: PROC[self: Handle] = {
d: DataRef=self.data;
-- refer to instance data as d.foo, d.count, etc.
};

CCopy: PROC[self: Handle] RETURNS[Handle] = {
d: DataRef=self.data;
dd: DataRef = zone.NEW[Data ← d↑]; -- *** copy any referents of d
RETURN[zone.NEW[Object ← [procs: self.procs, data: dd]]];
};

CFree: PROC[selfPtr: LONG POINTER TO Handle] = {
self: Handle←selfPtr↑;
d: DataRef←self.data;
selfPtr↑←NIL;
-- *** free any referents of d
zone.FREE[@d];
zone.FREE[@self];
};

}.