1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/ada.2/types-atoms.ads
Nicolas Boulenguez 5a07bb5331 ada.2: fix memory leaks with garbage collection. Various simplifications.
Cyclic references were never deallocated by reference conuting.
Symbols cannot create cyclic structures and are less frequent (one
allocation per symbol), keep reference counting for them.

This slightly improves performances even though many previous
optimizations are removed (environment stack, reuse of memory).

Step caching hash of symbols. This does not seem to improve
performances. Hashing them instead of ordering them does.

Define Repl in the step file instead of globally. Move the eval
built-in function from core into the step file.

When possible, pass Ada records instead of explicit pointers.

In the reader, construct more objects directly as described in the MAL
process, reserve the buffer for sequences and maps

In eval, iterate on vectors without delegation. The increased
complexity was not improving performances.  Keep demonstrating Ada
type-safe genericity for maps, where iterating outside Types.Maps
would be less easy and/or efficient.

In quasiquote_list, concatenate in one buffer instead of allocating a
list for each element. The buffer may be reallocated behind the
curtain, but not once per element anymore.

In environments, illustrate tail call optimization when recursion is
more readable than a loop.
2019-03-31 19:06:00 +02:00

25 lines
684 B
Ada

with Garbage_Collected;
with Types.Mal;
package Types.Atoms is
type Instance (<>) is new Garbage_Collected.Instance with private;
-- Built-in functions.
function Atom (Args : in Mal.T_Array) return Mal.T;
function Deref (Args : in Mal.T_Array) return Mal.T;
function Reset (Args : in Mal.T_Array) return Mal.T;
function Swap (Args : in Mal.T_Array) return Mal.T;
-- Helper for print.
function Deref (Item : in Instance) return Mal.T with Inline;
private
type Instance is new Garbage_Collected.Instance with record
Data : Mal.T;
end record;
overriding procedure Keep_References (Object : in out Instance) with Inline;
end Types.Atoms;