DIRECTORY Rope USING [ROPE]; TargetConversions: CEDAR DEFINITIONS = BEGIN ByteSequence: TYPE = Rope.ROPE; Reader: TYPE = REF ReaderRep; ReaderRep: TYPE; Writer: TYPE = REF WriterRep; WriterRep: TYPE; bitsPerWord: NAT = 32; BitIndex: TYPE = [0..bitsPerWord); BitLength: TYPE = [0..bitsPerWord]; ElemIndex: TYPE = [0..bitsPerWord); ElemLength: TYPE = [0..bitsPerWord]; Bool: TYPE = BOOL; Card1: TYPE = CARDINAL [0..1]; Card2: TYPE = CARDINAL [0..3]; Card4: TYPE = CARDINAL [0..15]; Card8: TYPE = CARDINAL [0..255]; Card16: TYPE = CARDINAL [0..65535]; Card32: TYPE = CARD; Char: TYPE = CHAR; Int32: TYPE = INT; Real: TYPE = RECORD [ SELECT realKind: RealKind FROM real32 => [real32: Real32], real48 => [real48: Real48], real64 => [real64: Real64], real80 => [real80: Real80], ENDCASE ]; RealKind: TYPE = {real32, real48, real64, real80}; Real32: TYPE = REAL; Real48: TYPE = PACKED ARRAY [0..48) OF BOOL; Real64: TYPE = PACKED ARRAY [0..64) OF BOOL; Real80: TYPE = PACKED ARRAY [0..80) OF BOOL; NewWriter: PROC RETURNS [Writer]; ResetWriter: PROC [writer: Writer]; WriterContents: PROC [writer: Writer] RETURNS [ByteSequence]; BitsWritten: PROC [writer: Writer] RETURNS [INT]; PutBool: PROC [writer: Writer, bool: Bool]; PutByteSeq: PROC [writer: Writer, seq: ByteSequence, len: INT]; PutCard: PROC [writer: Writer, card: Card32, bits: BitLength]; PutCard32: PROC [writer: Writer, card: Card32]; PutChar: PROC [writer: Writer, char: Char]; PutInt: PROC [writer: Writer, int: Int32, bits: BitLength]; PutInt32: PROC [writer: Writer, int: Int32]; PutPadBits: PROC [writer: Writer, bits: BitLength]; PutReal: PROC [writer: Writer, real: Real]; SetOutputIndex: PROC [writer: Writer, bits: INT]; GetOutputIndex: PROC [writer: Writer] RETURNS [INT]; NewReader: PROC [seq: ByteSequence, start: INT ¬ 0, len: INT ¬ LAST[INT]] RETURNS [Reader]; InitReader: PROC [reader: Reader, seq: ByteSequence, start: INT ¬ 0, len: INT ¬ LAST[INT]]; RemainingBits: PROC [reader: Reader] RETURNS [INT]; BitsRead: PROC [reader: Reader] RETURNS [INT]; GetBool: PROC [reader: Reader] RETURNS [Bool]; GetByteSequence: PROC [reader: Reader, len: INT] RETURNS [ByteSequence]; GetCard: PROC [reader: Reader, bits: BitLength] RETURNS [Card32]; GetCard32: PROC [reader: Reader] RETURNS [Card32]; GetChar: PROC [reader: Reader] RETURNS [Char]; GetInt: PROC [reader: Reader, bits: BitLength] RETURNS [Int32]; GetInt32: PROC [reader: Reader] RETURNS [Int32]; SkipPadBits: PROC [reader: Reader, bits: BitLength]; GetReal: PROC [reader: Reader, kind: RealKind ¬ real32] RETURNS [Real]; SetInputIndex: PROC [reader: Reader, bits: INT]; InsufficientBits: ERROR; InvalidArgument: ERROR; NotImplemented: ERROR; NotAligned: ERROR; BoolToByteSeq: PROC [bool: Bool] RETURNS [ByteSequence]; CardToByteSeq: PROC [card: Card32, bits: BitLength] RETURNS [ByteSequence]; Card32ToByteSeq: PROC [card: Card32] RETURNS [ByteSequence]; CharToByteSeq: PROC [char: Char] RETURNS [ByteSequence]; IntToByteSeq: PROC [int: Int32, bits: BitLength] RETURNS [ByteSequence]; Int32ToByteSeq: PROC [int: Int32] RETURNS [ByteSequence]; RealToByteSeq: PROC [real: Real] RETURNS [ByteSequence]; ByteSeqToBool: PROC [seq: ByteSequence] RETURNS [Bool]; ByteSeqToCard: PROC [seq: ByteSequence, bits: BitLength] RETURNS [Card32]; ByteSeqToCard32: PROC [seq: ByteSequence] RETURNS [Card32]; ByteSeqToChar: PROC [seq: ByteSequence] RETURNS [Char]; ByteSeqToInt: PROC [seq: ByteSequence, bits: BitLength] RETURNS [Int32]; ByteSeqToInt32: PROC [seq: ByteSequence] RETURNS [Int32]; ByteSeqToReal: PROC [seq: ByteSequence, kind: RealKind ¬ real32] RETURNS [Real]; END. ΰ TargetConversions.mesa Copyright Σ 1986, 1991 by Xerox Corporation. All rights reserved. Russ Atkinson (RRA) July 22, 1986 1:01:56 pm PDT The idea behind this interface is to provide isolation for the host to target and the target to host translation of values necessary in the compiler. The common external representation is a sequence of bytes, but the details of the encoding are up to the implementation. Types Temporary A reader is like an input stream that can yield up basic Mesa values. A writer is like an output stream that can be given basic Mesa values. This length does not necessarily correspond to the bitsPerWord on the target. It is declared here for documentation purposes. a 1-bit boolean value {FALSE, TRUE} an unsigned 1-bit quantity an unsigned 2-bit quantity an unsigned 4-bit quantity an unsigned 8-bit quantity an unsigned 16-bit quantity an unsigned 32-bit quantity an ASCII (more or less) 8-bit character a signed 32-bit quantity For now only the single variant is supported, and the other formats are merely speculative. Bit Stream Writers Returns a new bit stream writer with no bits. Resets the writer to ground zero, but retains intermediate storage for the sake of efficiency. Returns the byte sequence corresponding to the currently written contents of the given writer. NIL will be returned if there are no bits in the stream. Returns the number of bits currently written to the stream. Useful for hairy alignment problems not covered by PutAlignment. Puts out the given 1-bit boolean value. Puts out the first len bytes of the given byte sequence. Requires byte alignment (BitsWritten[writer] MOD 8 = 0). Puts out the given unsigned number using the low-order BitLength bits. Puts out the given 32-bit unsigned number. PutCard32[w, c] is the same as (but faster than) PutCard[w, c, 32]. Requires byte alignment. Puts out the given character. Puts out the given signed number using the low-order bits of int. The given Int32 number must have correct sign extension. Puts out the given 32-bit signed number. PutInt32[w, i] is the same as (but faster than) PutInt[w, i, 32]. Puts out the requested number of padding bits. Puts out the given Real. Sets the bit position in the writer. Returns the bit position in the writer. Bit Stream Readers Returns a new bit stream Reader with initial contents given by the ByteSequence (starting at byte offset start for len bytes). Initializes an existing Reader with contents given by the ByteSequence (starting at byte offset start for len bytes). If len exceeds the amount of bytes remaining in the sequence, len will be reduced to describe the remaining number of bytes. Returns the number of remaining bits in the reader. Returns the number of bits read from the reader. Reads a 1-bit boolean value. Reads a sequence of bytes, len gives the number of bytes. Requires byte alignment (BitsRead[reader] MOD 8 = 0). Reads an unsigned number of bits precision. Reads a 32-bit unsigned number. Reads an 8-bit character. Reads a signed number, precision given by bits, and properly extends the sign (if necessary). Reads a 32-bit signed number. Skips a given number of padding bits. Reads an IEEE floating-point number of the specified kind. Sets the bit position in the reader. Exceptions Raised when a Get& operation is called and not enough bits remain in the reader to deliver the value. Raised when an argument is illegal. Raised when an operation calls for a translation not supported by the implementation (as in use of Real when the kind is not real32). Raised when an operation needs at least byte alignment and the stream is not byte aligned. Simple Types to Byte Sequences These operations are present for efficiency. An operation of the form &ToByteSeq[&&] has the same behavior (more or less) as: {w: Writer _ NewWriter[]; Put&[w, &&]; RESULT[WriterContents[w]]}; Byte Sequences to Simple Types These operations are present for efficiency. An operation of the form val _ ByteSeqTo&[&&] has the same behavior (more or less) as: val _ Get&[NewReader[&&]]; Κ–(cedarcode) style•NewlineDelimiter ™codešœ™Kšœ Οeœ6™BK™0—˜šΟk ˜ Kšœžœžœ˜——K˜šΟnœžœž œž˜,K™K™K˜—head2™šœžœžœ˜Kšœ ™ K˜—šœžœžœ ˜šœ žœ˜Inote™E—K˜—šœžœžœ ˜šœ žœ˜M™F—K˜—šœ žœ˜Kšœ~™~—K˜Kšœ žœ˜"Kšœ žœ˜#K˜Kšœ žœ˜#Kšœ žœ˜$K˜šœžœžœ˜Kšœžœžœ™#—šœžœžœ˜Kšœ™—šœžœžœ˜Kšœ™—šœžœžœ ˜Kšœ™—šœžœžœ ˜ Kšœ™—šœžœžœ ˜#Kšœ™—šœžœžœ˜Kšœ™—šœžœžœ˜Kšœ'™'—šœžœžœ˜Kšœ™—K˜šœžœžœ˜šžœž˜Kšœ˜Kšœ˜Kšœ˜Kšœ˜Kšž˜—Kšœ˜šœ žœ$˜2Kšœžœžœ˜Kš œžœžœžœ žœžœ˜,Kš œžœžœžœ žœžœ˜,Kš œžœžœžœ žœžœ˜,—Kšœ[™[K˜——™šŸ œžœžœ ˜!Kšœ-™-K˜—šŸ œžœ˜#Kšœ^™^K˜—šŸœžœžœ˜=Kšœ`žœ5™˜K˜—šŸ œžœžœžœ˜1Kšœ}™}K˜—šŸœžœ˜+Kšœ'™'K˜—šŸ œžœ*žœ˜?Kšœ_Οzœžœ™rK˜—šŸœžœ1˜>KšœF™FK˜—šŸ œžœ ˜/Kšœ‰™‰K˜—šŸœžœ˜+Kšœ™K˜—šŸœžœ/˜;Kšœ{™{K˜—šŸœžœ˜,Kšœk™kK˜—šŸ œžœ#˜3Kšœ.™.K™—šŸœžœ˜+Kšœ™K˜—šŸœžœžœ˜1Kšœ$™$K˜—šŸœžœžœžœ˜4Kšœ'™'K˜——™šŸ œžœžœ žœžœžœžœ ˜[Kšœi œ œ™~K˜—š Ÿ œžœ,žœ žœžœžœ˜[Kš œ` œ œ  œ8 œ;™σK˜—šŸ œžœžœžœ˜3Kšœ3™3K˜—šŸœžœžœžœ˜.Kšœ0™0K˜—šŸœžœžœ˜.K™K˜—šŸœžœžœžœ˜HKšœ] œžœ™pK˜—šŸœžœ#žœ ˜AKšœ œ ™+K˜—šŸ œžœžœ ˜2K™K˜—šŸœžœžœ˜.K™K˜—šŸœžœ#žœ ˜?Kšœ* œ/™]K˜—šŸœžœžœ ˜0K™K˜—šŸ œžœ#˜4K™%K˜—šŸœžœ+žœ˜GKšœ žœ-™:K˜—šŸ œžœžœ˜0K™$K˜——™ šŸœžœ˜K™eK™—šŸœžœ˜K™#K™—šŸœžœ˜K™…K™—šŸ œžœ˜K™ZK™——šœ™šœ~™~Kšœ'žœ™BK™—KšŸ œžœžœ˜8K˜šŸ œžœ!žœ˜KK˜—šŸœžœžœ˜