mirror of
https://github.com/kanaka/mal.git
synced 2024-11-11 00:52:44 +03:00
5a07bb5331
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.
29 lines
1.0 KiB
Ada
29 lines
1.0 KiB
Ada
with Garbage_Collected;
|
|
with Types.Mal;
|
|
|
|
package Types.Builtins is
|
|
|
|
-- Types.Mal.Builtin_Ptr is efficient and sufficient for most
|
|
-- purposes, as counting references is a waste of time for native
|
|
-- functions. The controlled type below is only useful when one
|
|
-- has the silly idea to add metadata to a built-in.
|
|
|
|
type Instance is new Garbage_Collected.Instance with private;
|
|
|
|
function With_Meta (Builtin : in Mal.Builtin_Ptr;
|
|
Metadata : in Mal.T) return Mal.T with Inline;
|
|
function With_Meta (Item : in Instance;
|
|
Metadata : in Mal.T) return Mal.T with Inline;
|
|
function Meta (Item : in Instance) return Mal.T with Inline;
|
|
function Builtin (Item : in Instance) return Mal.Builtin_Ptr with Inline;
|
|
|
|
private
|
|
|
|
type Instance is new Garbage_Collected.Instance with record
|
|
F_Builtin : Mal.Builtin_Ptr;
|
|
F_Meta : Mal.T;
|
|
end record;
|
|
overriding procedure Keep_References (Object : in out Instance) with Inline;
|
|
|
|
end Types.Builtins;
|