JaMStorageImpl.mesa
Doug Wyatt, 13-Oct-81 17:33:49
Bill Paxton, March 18, 1982 12:13 pm
Russ Atkinson, July 22, 1983 7:29 pm
Paul Rovner, August 18, 1983 4:02 pm
DIRECTORY
JaMStorage USING [TextObject],
PrincOpsUtils USING [LongCOPY],
UnsafeStorage USING [GetSystemUZone];
JaMStorageImpl:
PROGRAM
IMPORTS PrincOpsUtils, UnsafeStorage
EXPORTS JaMStorage
SHARES JaMStorage = {
zone: UNCOUNTED ZONE = UnsafeStorage.GetSystemUZone[];
Zone: PUBLIC PROC RETURNS[UNCOUNTED ZONE] = { RETURN[zone] };
pruning: BOOLEAN ← FALSE; -- can turn this on someday
Prune: PUBLIC PROC = { IF pruning THEN NULL--UnsafeStorage.TrimUZone[zone]-- };
Text allocation
TextObject: TYPE = JaMStorage.TextObject;
PrivateTextPut:
PUBLIC
PROC[t:
POINTER
TO TextObject, c:
CHARACTER] = {
old: LONG STRING ← t.text;
new: LONG STRING ← NIL;
length: CARDINAL ← t.len;
oldmax: CARDINAL ← t.max;
maxmax: CARDINAL = t.lim;
newmax: CARDINAL ← oldmax + MIN[oldmax/2,maxmax-oldmax];
IF NOT length<newmax THEN RETURN;
new ← zone.NEW[StringBody[newmax]];
PrincOpsUtils.LongCOPY[from: @old.text, to: @new.text, nwords: (oldmax+1)/2];
IF old#t.cache THEN zone.FREE[@old];
t.text ← new; t.max ← new.maxlength;
new[length] ← c; t.len ← length + 1;
};
PrivateTextFree:
PUBLIC
PROC[t:
POINTER
TO TextObject] = {
IF t.text#t.cache THEN zone.FREE[@t.text];
};
}.