switch to tail -f circular pipes
[jackhill/mal.git] / ada.2 / err.ads
1 with Ada.Exceptions;
2 with Ada.Strings.Unbounded;
3
4 with Types;
5 -- We declare a variable of type Types.T.
6 pragma Elaborate (Types);
7
8 package Err is
9
10 -- Error handling.
11
12 -- Built-in function.
13 function Throw (Args : in Types.T_Array) return Types.T;
14
15 -- Ada exceptions can only carry an immutable String in each
16 -- occurence, so we require a global variable to store the last
17 -- exception as a Mal object anyway, and may as well use it for
18 -- simple string messages.
19
20 Error : exception;
21 Data : Types.T;
22 Trace : Ada.Strings.Unbounded.Unbounded_String;
23
24 -- Convenient shortcuts.
25
26 procedure Raise_With (Message : in String) with No_Return;
27 -- Similar to a "raise with Message" Ada statement.
28 -- Store the message into Data,
29 -- store the message and "Uncaught exception: " into Trace,
30 -- then raise Error.
31
32 procedure Raise_In_Mal (E : in Ada.Exceptions.Exception_Occurrence)
33 with No_Return;
34 -- Raise_With (Ada.Exceptions.Exception_Information (E))
35
36 procedure Add_Trace_Line (Action : in String;
37 Ast : in Types.T);
38 -- Appends a line like "Action: Ast" to Trace.
39
40 procedure Check (Condition : in Boolean;
41 Message : in String) with Inline;
42 -- Raise_With if Condition fails.
43
44 -- It is probably more efficient to construct a boolean and call
45 -- this procedure once, as "inline" is only a recommendation.
46
47 -- Beware of the classical performance issue that the Message is
48 -- formatted even if the Condition does not hold.
49
50 end Err;