MicroUtilsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Willie-sue, July 29, 1987 4:24:29 pm PDT
taken from --.bcpl
DIRECTORY
Atom USING [MakeAtomFromRefText],
Basics USING [ShortNumber, LowByte],
RefText USING [line, AppendChar],
Rope USING [ROPE, FromRefText],
MicroDefs,
MicroOps USING [GetSymbol],
MicroUtils USING [];
MicroUtilsImpl: CEDAR PROGRAM
IMPORTS
Atom, Basics, RefText, Rope,
MicroOps
EXPORTS
MicroUtils
= BEGIN
OPEN MicroDefs;
pnameBuf: REF TEXTNEW[TEXT[RefText.line]];
GetCharAtPointer: PUBLIC PROC[aPtr: LONG POINTER TO WORD]
  RETURNS[ch: CHAR] = TRUSTED {
byte: BYTE ← Basics.LowByte[aPtr^];
RETURN[LOOPHOLE[byte, CHAR] ];
};
PutCharAtPointer: PUBLIC PROC[aPtr: LONG POINTER TO WORD, ch: CHAR] = TRUSTED {
sn: Basics.ShortNumber;
sn.hi ← 0;
sn.lo ← LOOPHOLE[ch, BYTE];
aPtr^ ← LOOPHOLE[sn, INTEGER];
};
ValNotChar: SIGNAL[val: WORD] = CODE;
AtomAtPointer: PUBLIC PROC[ePtr: LONG POINTER TO WORD, len: INTEGER]
RETURNS[symb: ATOM] = {
pnameBuf.length ← 0;
IF len = 0 THEN RETURN[NIL];
IF len > 64 THEN ERROR;
FOR i: INTEGER IN [0..len) DO
val: WORD;
TRUSTED { val ← (ePtr+i)^ };
IF val < 40B OR val > 377B THEN SIGNAL ValNotChar[val];
TRUSTED { [] ← RefText.AppendChar[pnameBuf, GetCharAtPointer[ePtr+i]] };
ENDLOOP;
RETURN[Atom.MakeAtomFromRefText[pnameBuf]];
};
RopeAtPointer: PUBLIC PROC[aPtr: LONG POINTER TO WORD, lx: INTEGER]
RETURNS[name: Rope.ROPE] = {
pnameBuf.length ← 0;
IF lx = 0 THEN RETURN[NIL];
IF lx > 100 THEN ERROR;
FOR i: INTEGER IN [0..lx) DO
TRUSTED { [] ← RefText.AppendChar[pnameBuf, GetCharAtPointer[aPtr+i]] };
ENDLOOP;
RETURN[Rope.FromRefText[pnameBuf]];
};
MoveBlock: PUBLIC PROC[to, from: LONG POINTER TO WORD, num: INTEGER] = TRUSTED {
moves num words from from to to
FOR i: INTEGER IN [0..num) DO
to^ ← from^;
to ← to + 1;
from ← from + 1;
ENDLOOP;
};
GetSymbolMemSink: PUBLIC PROC[symIndex: INTEGER] RETURNS[INTEGER] = {
sObj: SymbolObj = MicroOps.GetSymbol[symIndex];
mObj: SymbolObj = MicroOps.GetSymbol[sObj.sMisc];
mem: Memory = NARROW[mObj.sData];
RETURN[mem.sinkIndex];
};
GetSymbolMemSource: PUBLIC PROC[symIndex: INTEGER] RETURNS[INTEGER] = {
sObj: SymbolObj = MicroOps.GetSymbol[symIndex];
mObj: SymbolObj = MicroOps.GetSymbol[sObj.sMisc];
mem: Memory = NARROW[mObj.sData];
RETURN[mem.sourceIndex];
};
END.