TokenIO.mesa
Copyright © 1983, 1984 by Xerox Corporation. All rights reserved.
by Christian Jacobi August 24, 1983 3:10 pm
last edited by Christian Jacobi December 12, 1984 10:56:52 am PST
TokenIO: CEDAR DEFINITIONS =
BEGIN
Mark:
TYPE =
REF MarkRep;
MarkRep: TYPE;
WritingStopped: SIGNAL;
StopWriting:
PROC [] =
INLINE {stopWriting←
TRUE};
-- causes next call of Write or Update to signal WritingStopped
-- (inside monitorlock; may be resumed or aborted)
-- AttachWriter invalidates a call of WritingStopped
-- inline for speed reason only
stopWriting: PRIVATE BOOL;
WriteInt: PROC [i: INT];
WriteAtom: PROC [a: ATOM];
WriteRope: PROC [r: Rope.ROPE];
WritePushFlag: PROC [a: ATOM←NIL];
WritePopFlag: PROC [];
MarkAndWriteInt: PROC [value: INT] RETURNS [Mark];
UpdateMark: PROC [mark: Mark, value: INT];
TokenType: TYPE = {atom, int, rope, pushFlag, popFlag, endOfStream, error};
Token:
TYPE =
RECORD [
kind: TokenType,
ref: REF←NIL -- either ATOM, Rope.ROPE, REF INT or NIL (Rope.ROPE or NIL if error)
];
-- kind = atom => ISTYPE[ref, ATOM]
-- kind = int => ISTYPE[ref, REF INT]
-- kind = rope => ISTYPE[ref, Rope.ROPE]
-- kind = pushFlag => ref=NIL or ISTYPE[ref, ATOM]
-- kind = popFlag => ref=NIL
-- kind = endOfStream => ref=NIL
-- kind = error => ref=NIL OR ISTYPE[ref, Rope.ROPE]
ReadToken: PROC [] RETURNS [Token];
ReadAgain:
PROC [];
-- cause next call of ReadToken to get the same value as the last read
-- works only one level deep (reads again only the last value returned by ReadToken)
EncodingError: SIGNAL;
-- all read procedures SIGNAL EncodingError if read token is not as expected;
-- for emergeny error bypassing, the state may be changed in the debugger
-- and the computation continued; however, normal computation considers
-- EncodingError to be an ERROR, not a SIGNAL.
ReadInt: PROC [] RETURNS [INT];
ReadAtom: PROC [] RETURNS [ATOM];
ReadRope: PROC [] RETURNS [Rope.ROPE];
ReadPushFlag: PROC [] RETURNS [ATOM];
ReadPopFlag: PROC [];
-- Attaching TokenIo to STREAMS
-- while TokenIo is attached to a stream no other operations on this
-- stream should occur
Error: ERROR[why: Err, explanation: Rope.ROPE]; -- only on Attach or Release
Err: TYPE = {alreadyAttached, wrongVersion, other};
AttachReader: PROC [stream: IO.STREAM];
ReleaseReader: PROC [];
AttachWriter: PROC [stream: IO.STREAM];
ReleaseWriter:
PROC [];
-- also invalidates marks
-- the routines may generate some standard IO signals and errors, however,
-- as few as possible
-- the Rope NIL and the Rope "" may read back correctly or exchanged
-- the ATOM NIL reads back correctly;
-- the ATOM "$" may be read back correctly or as NIL ATOM
END.