GCRootsImpl.mesa
Copyright Ó 1993 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, April 13, 1993 11:12 am PDT
DIRECTORY GCRoots, RefTab;
GCRootsImpl: CEDAR MONITOR
IMPORTS RefTab
EXPORTS GCRoots ~
BEGIN
cacheMax: INT = 8;
CacheArray: TYPE = ARRAY [0..cacheMax] OF REF INT;
cache: REF CacheArray ~ NEW[CacheArray]; --cacheing counts to reduce allocations
tab: RefTab.Ref ~ RefTab.Create[];
ExternalNames: PROC [] = TRUSTED MACHINE CODE {
Make this package available to C programs also
"^ExternalNames\n";
"Include XR←GCRoots←Include\n";
"Forget XR←GCRoots𡤏orget\n";
"Number XR←GCRoots←Number\n";
};
New: PROC [i: INT] RETURNS [REF INT] = {
IF i>cacheMax THEN RETURN [NEW[INT ¬ i]] ELSE RETURN [cache[i]]
};
Include: PUBLIC PROC [x: REF ANY] = {
Action: RefTab.UpdateAction = {
IF found
THEN new ¬ New[NARROW[val, REF INT]­+1]
ELSE new ¬ New[1];
op ¬ store;
};
RefTab.Update[tab, x, Action]
};
Forget: PUBLIC PROC [x: REF ANY] = {
Action: RefTab.UpdateAction = {
IF found THEN {
i: INT ~ NARROW[val, REF INT]­;
IF i<=1
THEN op ¬ delete
ELSE {new ¬ New[i-1]; op ¬ store};
}
};
RefTab.Update[tab, x, Action]
};
Number: PUBLIC PROC [] RETURNS [INT] = {
RETURN [RefTab.GetSize[tab]]
};
ExternalNames[];
FOR i: INT IN [1..cacheMax] DO
cache[i] ¬ NEW[INT ¬ i];
ENDLOOP;
END.