RealExceptionsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) May 22, 1985 12:54:15 pm PDT
DIRECTORY
Basics USING [LongNumber],
PrincOps USING [PsbIndex],
PrincOpsUtils USING [ProcessToPsbIndex],
Process USING [GetCurrent],
Real USING [Exception, ExceptionFlags, Extended, NoExceptions, RealException],
RealExceptions USING [CombinedFlags, FlagsArray];
RealExceptionsImpl: CEDAR PROGRAM
IMPORTS PrincOpsUtils, Process, Real
EXPORTS RealExceptions
= BEGIN
FlagsArray: TYPE = RealExceptions.FlagsArray;
combined: LONG POINTER TO FlagsArray ← NIL;
empty: RealExceptions.CombinedFlags = [Real.NoExceptions, Real.NoExceptions];
Init: PUBLIC UNSAFE PROC [lp: LONG POINTER TO FlagsArray] = TRUSTED {
Must be called to enable multi-process REAL exception handling.
IF lp # NIL THEN {
lp^ ← ALL[empty];
combined ← lp;
};
};
ClearExceptions: PUBLIC PROC = {
Clear the exceptions for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
combined[psbi].exceptions ← Real.NoExceptions;
};
};
ClearSticky: PUBLIC PROC = {
Clear the sticky bits for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
combined[psbi].sticky ← Real.NoExceptions;
};
};
ClearCombined: PUBLIC PROC = {
Clear the sticky bits for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
combined[psbi] ← empty;
};
};
SetCombined: PUBLIC PROC [flags: RealExceptions.CombinedFlags] = {
Sets the exception bits & sticky bits for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
combined[psbi] ← flags;
};
};
SetException: PUBLIC PROC [which: Real.Exception] = {
Sets a given exception for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
combined[psbi].exceptions[which] ← TRUE;
};
};
SetSticky: PUBLIC PROC [which: Real.Exception] = {
Sets a given sticky bit for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
combined[psbi].sticky[which] ← TRUE;
};
};
TestException: PUBLIC PROC [which: Real.Exception] RETURNS [BOOL] = {
Tests a particular exception for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
IF combined[psbi].exceptions[which] THEN RETURN [TRUE];
};
RETURN [FALSE];
};
TestSticky: PUBLIC PROC [which: Real.Exception] RETURNS [BOOL] = {
Tests a particular sticky bit for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
IF combined[psbi].sticky[which] THEN RETURN [TRUE];
};
RETURN [FALSE];
};
GetExceptions: PUBLIC PROC RETURNS [Real.ExceptionFlags] = {
Samples the combined for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
RETURN [combined[psbi].exceptions];
};
RETURN [Real.NoExceptions];
};
GetSticky: PUBLIC PROC RETURNS [Real.ExceptionFlags] = {
Samples the sticky bits for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
RETURN [combined[psbi].sticky];
};
RETURN [Real.NoExceptions];
};
GetCombined: PUBLIC PROC RETURNS [RealExceptions.CombinedFlags] = {
Samples the sticky bits for the current process
IF combined # NIL THEN TRUSTED {
psbi: PrincOps.PsbIndex ← PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]];
RETURN [combined[psbi]];
};
RETURN [empty];
};
RaiseException: PUBLIC PROC [ext: Real.Extended] RETURNS [clientFixup: BOOL, fraction: Basics.LongNumber] = {
Raises Real.RealException with the current exception flags and the given extended number. Returns whatever the client directed if the client RESUMEs the signal.
p: REF Real.Extended ← NEW[Real.Extended ← ext];
clientFixup ← SIGNAL Real.RealException[GetExceptions[], p];
fraction.li ← LOOPHOLE[p^.frac, INT];
};
END.