mirror of
https://github.com/kanaka/mal.git
synced 2024-09-21 02:27:10 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
51 lines
1.5 KiB
Ada
51 lines
1.5 KiB
Ada
with Ada.Exceptions;
|
|
with Ada.Strings.Unbounded;
|
|
|
|
with Types;
|
|
-- We declare a variable of type Types.T.
|
|
pragma Elaborate (Types);
|
|
|
|
package Err is
|
|
|
|
-- Error handling.
|
|
|
|
-- Built-in function.
|
|
function Throw (Args : in Types.T_Array) return Types.T;
|
|
|
|
-- Ada exceptions can only carry an immutable String in each
|
|
-- occurence, so we require a global variable to store the last
|
|
-- exception as a Mal object anyway, and may as well use it for
|
|
-- simple string messages.
|
|
|
|
Error : exception;
|
|
Data : Types.T;
|
|
Trace : Ada.Strings.Unbounded.Unbounded_String;
|
|
|
|
-- Convenient shortcuts.
|
|
|
|
procedure Raise_With (Message : in String) with No_Return;
|
|
-- Similar to a "raise with Message" Ada statement.
|
|
-- Store the message into Data,
|
|
-- store the message and "Uncaught exception: " into Trace,
|
|
-- then raise Error.
|
|
|
|
procedure Raise_In_Mal (E : in Ada.Exceptions.Exception_Occurrence)
|
|
with No_Return;
|
|
-- Raise_With (Ada.Exceptions.Exception_Information (E))
|
|
|
|
procedure Add_Trace_Line (Action : in String;
|
|
Ast : in Types.T);
|
|
-- Appends a line like "Action: Ast" to Trace.
|
|
|
|
procedure Check (Condition : in Boolean;
|
|
Message : in String) with Inline;
|
|
-- Raise_With if Condition fails.
|
|
|
|
-- It is probably more efficient to construct a boolean and call
|
|
-- this procedure once, as "inline" is only a recommendation.
|
|
|
|
-- Beware of the classical performance issue that the Message is
|
|
-- formatted even if the Condition does not hold.
|
|
|
|
end Err;
|