BrineIO.mesa
Copyright Ó 1988 by Xerox Corporation. All rights reversed.
Created by Bertrand Serlet May 4, 1988 11:15:43 pm PDT
Bertrand Serlet May 5, 1988 10:29:07 pm PDT
DIRECTORY BasicTime, IO, RefTab, Rope;
BrineIO: CEDAR DEFINITIONS = BEGIN
Types
ReadRefProc: TYPE = PROC [IO.STREAM] RETURNS [REF];
WriteRefProc: TYPE = PROC [IO.STREAM, REF];
Basic Read/Write Functions
It is the responsability of the caller to know the type of the data being read or written. In other terms, the type of the data is NOT written by the following functions.
ReadInt: PROC [stream: IO.STREAM] RETURNS [int: INT];
WriteInt: PROC [stream: IO.STREAM, int: INT];
ReadBool: PROC [stream: IO.STREAM] RETURNS [bool: BOOL];
WriteBool: PROC [stream: IO.STREAM, bool: BOOL];
ReadReal: PROC [stream: IO.STREAM] RETURNS [real: REAL];
WriteReal: PROC [stream: IO.STREAM, real: REAL];
ReadGMT: PROC [stream: IO.STREAM] RETURNS [gmt: BasicTime.GMT];
WriteGMT: PROC [stream: IO.STREAM, gmt: BasicTime.GMT];
ReadAtom: PROC [stream: IO.STREAM] RETURNS [atom: ATOM];
WriteAtom: PROC [stream: IO.STREAM, atom: ATOM];
Uses a cache to avoid written litterals twicce.
ReadID: PROC [stream: IO.STREAM] RETURNS [id: Rope.ROPE];
WriteID: PROC [stream: IO.STREAM, id: Rope.ROPE];
Just uses a standard IO.PutRope
ReadRope: PROC [stream: IO.STREAM] RETURNS [rope: Rope.ROPE];
WriteRope: PROC [stream: IO.STREAM, rope: Rope.ROPE];
Uses a cache to share ropes. Ropes should not contain control characters not parsed by IO.GetRopeLiteral, but " are ok.
Composite Read/Write Functions
ReadAtomRef: ReadRefProc;
WriteAtomRef: WriteRefProc;
ReadIDRef: ReadRefProc;
WriteIDRef: WriteRefProc;
ReadRopeRef: ReadRefProc;
WriteRopeRef: WriteRefProc;
Those functions are similar to the ones of the previous section, but have the right type for composite readers or writers.
ReadRopes: PROC [stream: IO.STREAM] RETURNS [ropes: LIST OF Rope.ROPE];
WriteRopes: PROC [stream: IO.STREAM, ropes: LIST OF Rope.ROPE];
Same restrictions as for ReadRope and WriteRope.
ReadRefTab: PROC [stream: IO.STREAM, readKey, readVal: ReadRefProc, equal: RefTab.EqualProc ← NIL, hash: RefTab.HashProc ← NIL] RETURNS [table: RefTab.Ref];
WriteRefTab: PROC [stream: IO.STREAM, table: RefTab.Ref, writeKey, writeVal: WriteRefProc];
Utilities
In order to save DAGs, it is common to store a RefTab mapping objects to IDs on the output stream, and a SymTab mapping IDs to objects on the input stream.
The following functions search the property list of the stream for a given key. To avoid collisions, it is good practise to prefix keys by the name of the module using them. For instance, the implementation uses the 2 keys $BrineIOAtomTable and $BrineIORopeTable.
GetRefTab: PROC [stream: IO.STREAM, key: ATOM, equal: RefTab.EqualProc ← NIL, hash: RefTab.HashProc ← NIL] RETURNS [table: RefTab.Ref];
Creates the table if necessary.
MakeID: PROC [prefix: Rope.ROPE, int: INT] RETURNS [Rope.ROPE];
Generates a new ID for int.
END.