<> <> <> 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 { <> IF lp # NIL THEN { lp^ _ ALL[empty]; combined _ lp; }; }; ClearExceptions: PUBLIC PROC = { <> IF combined # NIL THEN TRUSTED { psbi: PrincOps.PsbIndex _ PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]]; combined[psbi].exceptions _ Real.NoExceptions; }; }; <<>> ClearSticky: PUBLIC PROC = { <> IF combined # NIL THEN TRUSTED { psbi: PrincOps.PsbIndex _ PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]]; combined[psbi].sticky _ Real.NoExceptions; }; }; <<>> ClearCombined: PUBLIC PROC = { <> IF combined # NIL THEN TRUSTED { psbi: PrincOps.PsbIndex _ PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]]; combined[psbi] _ empty; }; }; <<>> SetCombined: PUBLIC PROC [flags: RealExceptions.CombinedFlags] = { <> IF combined # NIL THEN TRUSTED { psbi: PrincOps.PsbIndex _ PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]]; combined[psbi] _ flags; }; }; <<>> SetException: PUBLIC PROC [which: Real.Exception] = { <> IF combined # NIL THEN TRUSTED { psbi: PrincOps.PsbIndex _ PrincOpsUtils.ProcessToPsbIndex[Process.GetCurrent[]]; combined[psbi].exceptions[which] _ TRUE; }; }; <<>> SetSticky: PUBLIC PROC [which: Real.Exception] = { <> 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] = { <> 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] = { <> 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] = { <> 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] = { <> 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] = { <> 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] = { <> p: REF Real.Extended _ NEW[Real.Extended _ ext]; clientFixup _ SIGNAL Real.RealException[GetExceptions[], p]; fraction.li _ LOOPHOLE[p^.frac, INT]; }; END.