1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/ada.2/types.adb
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

62 lines
1.9 KiB
Ada

pragma Warnings (Off, "no entities of ""Types.*"" are referenced");
with Types.Atoms;
with Types.Builtins;
with Types.Fns;
with Types.Macros;
with Types.Maps;
with Types.Sequences;
pragma Warnings (On, "no entities of ""Types.*"" are referenced");
with Types.Strings;
package body Types is
function "=" (Left, Right : in T) return Boolean
is (case Left.Kind is
when Kind_Nil =>
Right.Kind = Kind_Nil,
when Kind_Boolean =>
Right.Kind = Kind_Boolean
and then Left.Ada_Boolean = Right.Ada_Boolean,
when Kind_Number =>
Right.Kind = Kind_Number and then Left.Number = Right.Number,
-- Here comes the part that differs from the predefined equality.
when Kind_Key | Kind_Symbol =>
Right.Kind = Left.Kind
and then Strings.Same_Contents (Left.Str, Right.Str),
when Kind_Sequence =>
Right.Kind in Kind_Sequence
and then (Left.Sequence = Right.Sequence
or else Sequences."=" (Left.Sequence.all, Right.Sequence.all)),
when Kind_Map =>
Right.Kind = Kind_Map
and then (Left.Map = Right.Map
or else Maps."=" (Left.Map.all, Right.Map.all)),
-- Also, comparing functions is an interesting problem.
when others =>
False);
procedure Keep (Object : in T) is
-- No dynamic dispatching happens here.
begin
case Object.Kind is
when Kind_Nil | Kind_Boolean | Kind_Number | Kind_Builtin =>
null;
when Kind_Key | Kind_Symbol =>
Object.Str.all.Keep;
when Kind_Atom =>
Object.Atom.all.Keep;
when Kind_Sequence =>
Object.Sequence.all.Keep;
when Kind_Map =>
Object.Map.all.Keep;
when Kind_Builtin_With_Meta =>
Object.Builtin_With_Meta.all.Keep;
when Kind_Fn =>
Object.Fn.all.Keep;
when Kind_Macro =>
Object.Macro.all.Keep;
end case;
end Keep;
end Types;