1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-19 01:28:26 +03:00
mal/ada.2/types-maps.ads
Nicolas Boulenguez 8185fe141c Clarify and optimize ada.2.
Makefile:
Drop OPT and -gnat2020, not used anymore.
Simplify file list now that each unit has a body.

README:
Remove obsolete items.

Global:
Restrict most pointers to a provable non-null value.

Types: merge intermediate Types.Mal into the Types package.  (the
intermediate package was created in order to prevent a circular
dependency, but is not needed anymore).
Most of the noise in the diff is caused by this change.
This allows to remove most Elaboration pragmas.
Declare most types abstract in the visible part,
enforcing the use of the constructor outside the declaring package.

Envs:
Replace the Get recursion with a more efficient loop.
Use MAL objects as key, string pointers do not change speed.
This delegates some checks from the step files.
Split the constructor and Set_Binds, so that an existing environment
can be reused during TCO.

Err:
Attempt to group the calls.
Avoid computing the message when the assertion holds.

Fns:
Declare and use the eval callback only here.
Separate function and macro interfaces.
Keep a reference to the provided parameter list instead of copying them.

Garbage_Collected:
Make explicit that Keep is not inherited.

Printer:
Remove obsolete inline indications and redundant Print_Function helper.

Maps:
Provide a cleaner interface copied from standard library.

Sequences: stop encapsulating the implementation because of the
performance hit.

Steps:
Move map and vector evaluations into separate functions for readability.
Replace return blocks with normal blocks (MAL values are not finalized
anymore).
Rename standard arrays instead of sequence_ptr when possible.
Remove some duplication and indentation from the apply phase.
Move the frequent special forms in front of the test cascade.
When an environment has been created in the same Eval, reuse it.

Strings:
Use the same garbage-collected storage model for all strings.
This seems faster than the default (mutable) string types.
Hide most of the implementation to avoid leaks.

Symbols: stop ensuring unique allocation of symbols. The reduced
garbage collection and comparison time was compensed by the
maintainance of a global hash.
2019-05-02 21:19:34 +02:00

63 lines
2.3 KiB
Ada

private with Ada.Containers.Hashed_Maps;
with Garbage_Collected;
package Types.Maps is
-- All function receiving a key check that its kind is keyword or
-- string.
type Instance (<>) is abstract new Garbage_Collected.Instance with private;
-- Built-in functions.
function Assoc (Args : in T_Array) return T;
function Contains (Args : in T_Array) return T;
function Dissoc (Args : in T_Array) return T;
function Get (Args : in T_Array) return T;
function Hash_Map (Args : in T_Array) return T;
function Keys (Args : in T_Array) return T;
function Vals (Args : in T_Array) return T;
function "=" (Left, Right : in Instance) return Boolean with Inline;
-- Used to print each element of a map.
type Cursor (<>) is limited private;
function Has_Element (Position : in Cursor) return Boolean with Inline;
function Key (Position : in Cursor) return T with Inline;
function Element (Position : in Cursor) return T with Inline;
function First (Container : in Instance) return Cursor with Inline;
procedure Next (Position : in out Cursor) with Inline;
-- Used to evaluate each element of a map.
function New_Map (Source : in Instance) return T with Inline;
procedure Replace_Element (Container : in out Instance;
Position : in Cursor;
New_Item : in T) with Inline;
function Meta (Container : in Instance) return T with Inline;
function With_Meta (Container : in Instance;
Metadata : in T) return T with Inline;
private
function Hash (Item : in T) return Ada.Containers.Hash_Type with Inline;
-- This function also checks the kind of the key, and raise an
-- error in case of problem.
package HM is new Ada.Containers.Hashed_Maps (Key_Type => T,
Element_Type => T,
Hash => Hash,
Equivalent_Keys => "=",
"=" => "=");
type Instance is new Garbage_Collected.Instance with record
Data : HM.Map;
F_Meta : T;
end record;
overriding procedure Keep_References (Object : in out Instance) with Inline;
type Cursor is new HM.Cursor;
end Types.Maps;