IPErrorImpl.mesa
Copyright © 1984 Xerox Corporation. All rights reserved.
Doug Wyatt, November 13, 1984 2:22:35 pm PST
Errors and Signals known throughout the Interpress interpreter
DIRECTORY
IO USING [atom, PutF, rope, STREAM],
IPInterpreter USING [ErrorClass, Get, Integer, IntegerFromAny, MasterErrorType, MasterWarningType, Shape, State, Vector, VectorShape],
List USING [AList, Assoc, PutAssoc],
ProcessProps USING [AddPropList, GetPropList],
Rope USING [FromProc, ROPE];
IPErrorImpl: CEDAR PROGRAM
IMPORTS IO, IPInterpreter, List, ProcessProps, Rope
EXPORTS IPInterpreter
~ BEGIN OPEN IPInterpreter;
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Error: PUBLIC ERROR ~ CODE;
stateKey: ATOM ~ $InterpressState;
AddState:
PUBLIC
PROC[state: State, inner:
PROC] ~ {
aList: List.AList ← NIL;
aList ← List.PutAssoc[key: stateKey, val: state, aList: aList];
ProcessProps.AddPropList[aList, inner];
};
GetState:
PUBLIC
PROC
RETURNS[State] ~ {
aList: List.AList ~ ProcessProps.GetPropList[];
value: REF ~ List.Assoc[key: stateKey, aList: aList];
WITH value SELECT FROM state: State => RETURN[state]; ENDCASE;
RETURN[NIL];
};
RopeFromClass:
PROC[class: ErrorClass]
RETURNS[
ROPE] ~ {
RETURN[
SELECT class
FROM
masterError => "Master Error",
masterWarning => "Master Warning",
appearanceError => "Appearance Error",
appearanceWarning => "Appearance Warning",
comment => "Comment",
ENDCASE => NIL];
};
ReportError:
PUBLIC
PROC[class: ErrorClass, code:
ATOM, explanation:
ROPE] ~ {
self: State ~ GetState[];
IF self#
NIL
THEN {
log: STREAM ~ self.log;
IF log=NIL THEN RETURN;
log.PutF["%g (%g):\n", IO.rope[RopeFromClass[class]], IO.atom[code]];
log.PutF[" %g\n", IO.rope[explanation]];
};
};
NonDefaultingATOM: TYPE ~ ATOM ←
MasterErrorCodeTable: TYPE ~ ARRAY MasterErrorType OF NonDefaultingATOM;
MasterWarningCodeTable: TYPE ~ ARRAY MasterWarningType OF NonDefaultingATOM;
masterErrorCode: REF MasterErrorCodeTable ~ NEW[MasterErrorCodeTable ← [bug: $bug, unimplemented: $unimplemented, boundsFault: $boundsFault, nilFault: $nilFault, invalidArgs: $invalidArgs, limitExceeded: $limitExceeded, markMismatch: $markMismatch, missingBody: $missingBody, notInteger: $notInteger, stackOverflow: $stackOverflow, stackUnderflow: $stackUnderflow, undefinedOperation: $undefinedOperation, undefinedProperty: $undefinedProperty, unmarkFailed: $unmarkFailed, wrongType: $wrongType]];
masterWarningCode: REF MasterWarningCodeTable ~ NEW[MasterWarningCodeTable ← [bug: $bug, unimplemented: $unimplemented, nullValue: $nullValue, illegalIdentifier: $illegalIdentifier, illegalString: $illegalString, unknownToken: $unknownToken]];
MasterError:
PUBLIC
PROC[type: MasterErrorType, explanation:
ROPE ←] ~ {
ReportError[$masterError, masterErrorCode[type], explanation];
};
MasterWarning:
PUBLIC
PROC[type: MasterWarningType, explanation:
ROPE ←] ~ {
ReportError[$masterWarning, masterWarningCode[type], explanation];
};
AppearanceError:
PUBLIC
PROC[code:
ATOM, explanation:
ROPE ←] ~ {
ReportError[$appearanceError, code, explanation];
};
AppearanceWarning:
PUBLIC
PROC[code:
ATOM, explanation:
ROPE ←] ~ {
ReportError[$appearanceWarning, code, explanation];
};
RopeFromVector:
PUBLIC
PROC[v: Vector]
RETURNS[
ROPE] ~ {
shape: VectorShape ~ Shape[v];
i: Integer ← shape.l;
p:
PROC
RETURNS[
CHAR] ~ {
n: Integer ~ IntegerFromAny[Get[v, i]]; i ← i+1;
IF n IN[0..255] THEN RETURN[0C+n]
ELSE { MasterError[$boundsFault, "Ascii character not in [0..255]."]; RETURN['-] };
};
RETURN[Rope.FromProc[len: shape.n, p: p]];
};
END.