2019-03-17 13:24:03 +03:00
|
|
|
with Ada.Environment_Variables;
|
2016-10-10 20:08:59 +03:00
|
|
|
with Ada.Text_IO.Unbounded_IO;
|
2019-02-28 00:27:12 +03:00
|
|
|
|
2016-10-10 20:08:59 +03:00
|
|
|
with Core;
|
2019-03-06 21:48:51 +03:00
|
|
|
with Envs;
|
2019-03-17 13:24:03 +03:00
|
|
|
with Err;
|
2019-03-06 21:48:51 +03:00
|
|
|
with Eval_Cb;
|
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 20:06:00 +03:00
|
|
|
with Garbage_Collected;
|
2016-10-10 20:08:59 +03:00
|
|
|
with Printer;
|
|
|
|
with Reader;
|
2019-03-06 21:48:51 +03:00
|
|
|
with Readline;
|
2019-03-17 13:24:03 +03:00
|
|
|
with Types.Fns;
|
2019-02-28 00:27:12 +03:00
|
|
|
with Types.Mal;
|
|
|
|
with Types.Maps;
|
2019-03-17 13:24:03 +03:00
|
|
|
with Types.Sequences;
|
2019-02-28 00:27:12 +03:00
|
|
|
with Types.Symbols.Names;
|
2016-10-10 20:08:59 +03:00
|
|
|
|
|
|
|
procedure Step4_If_Fn_Do is
|
|
|
|
|
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 20:06:00 +03:00
|
|
|
Dbgeval : constant Boolean := Ada.Environment_Variables.Exists ("dbgeval");
|
2019-03-17 13:24:03 +03:00
|
|
|
|
2019-02-28 00:27:12 +03:00
|
|
|
use Types;
|
2019-03-17 13:24:03 +03:00
|
|
|
use type Mal.T;
|
2019-02-28 00:27:12 +03:00
|
|
|
|
2019-03-17 13:24:03 +03:00
|
|
|
function Read return Mal.T_Array with Inline;
|
2016-10-10 20:08:59 +03:00
|
|
|
|
2019-02-28 00:27:12 +03:00
|
|
|
function Eval (Ast : in Mal.T;
|
2019-03-06 21:48:51 +03:00
|
|
|
Env : in Envs.Ptr) return Mal.T;
|
2016-10-10 20:08:59 +03:00
|
|
|
|
2019-03-06 21:48:51 +03:00
|
|
|
procedure Print (Ast : in Mal.T) with Inline;
|
2016-10-10 20:08:59 +03:00
|
|
|
|
2019-03-06 21:48:51 +03:00
|
|
|
procedure Rep (Env : in Envs.Ptr) with Inline;
|
2019-02-28 00:27:12 +03:00
|
|
|
|
2019-03-17 13:24:03 +03:00
|
|
|
function Eval_Map_Elts is new Maps.Generic_Eval (Envs.Ptr, Eval);
|
2016-10-10 20:08:59 +03:00
|
|
|
|
2019-03-17 13:24:03 +03:00
|
|
|
procedure Exec (Script : in String;
|
|
|
|
Env : in Envs.Ptr) with Inline;
|
|
|
|
-- Read the script, eval its elements, but ignore the result.
|
2016-10-10 20:08:59 +03:00
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2019-02-28 00:27:12 +03:00
|
|
|
function Eval (Ast : in Mal.T;
|
2019-03-06 21:48:51 +03:00
|
|
|
Env : in Envs.Ptr) return Mal.T
|
|
|
|
is
|
|
|
|
use type Symbols.Ptr;
|
2019-02-28 00:27:12 +03:00
|
|
|
First : Mal.T;
|
2016-10-10 20:08:59 +03:00
|
|
|
begin
|
2019-03-17 13:24:03 +03:00
|
|
|
if Dbgeval then
|
|
|
|
Ada.Text_IO.New_Line;
|
|
|
|
Ada.Text_IO.Put ("EVAL: ");
|
|
|
|
Print (Ast);
|
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 20:06:00 +03:00
|
|
|
Envs.Dump_Stack (Env.all);
|
2019-03-17 13:24:03 +03:00
|
|
|
end if;
|
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 20:06:00 +03:00
|
|
|
|
2016-10-10 20:08:59 +03:00
|
|
|
case Ast.Kind is
|
2019-03-17 13:24:03 +03:00
|
|
|
when Kind_Nil | Kind_Atom | Kind_Boolean | Kind_Number | Kind_Key
|
|
|
|
| Kind_Macro | Kind_Function =>
|
2019-03-03 20:07:18 +03:00
|
|
|
return Ast;
|
2016-10-10 20:08:59 +03:00
|
|
|
when Kind_Symbol =>
|
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 20:06:00 +03:00
|
|
|
return Env.all.Get (Ast.Symbol);
|
2016-10-10 20:08:59 +03:00
|
|
|
when Kind_Map =>
|
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 20:06:00 +03:00
|
|
|
return Eval_Map_Elts (Ast.Map.all, Env);
|
2016-10-10 20:08:59 +03:00
|
|
|
when Kind_Vector =>
|
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 20:06:00 +03:00
|
|
|
declare
|
|
|
|
Len : constant Natural := Ast.Sequence.all.Length;
|
|
|
|
List : constant Mal.Sequence_Ptr := Sequences.Constructor (Len);
|
|
|
|
begin
|
|
|
|
for I in 1 .. Len loop
|
|
|
|
List.all.Replace_Element (I, Eval (Ast.Sequence.all (I), Env));
|
|
|
|
end loop;
|
|
|
|
return (Kind_Vector, List);
|
|
|
|
end;
|
2016-10-10 20:08:59 +03:00
|
|
|
when Kind_List =>
|
2019-03-10 02:14:59 +03:00
|
|
|
null;
|
|
|
|
end case;
|
|
|
|
|
|
|
|
-- Ast is a list.
|
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 20:06:00 +03:00
|
|
|
if Ast.Sequence.all.Length = 0 then
|
2019-03-10 02:14:59 +03:00
|
|
|
return Ast;
|
|
|
|
end if;
|
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 20:06:00 +03:00
|
|
|
First := Ast.Sequence.all (1);
|
2019-03-10 02:14:59 +03:00
|
|
|
|
|
|
|
-- Special forms
|
|
|
|
-- Ast is a non-empty list, First is its first element.
|
|
|
|
case First.Kind is
|
|
|
|
when Kind_Symbol =>
|
|
|
|
if First.Symbol = Symbols.Names.Def then
|
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 20:06:00 +03:00
|
|
|
Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
|
|
|
|
Err.Check (Ast.Sequence.all (2).Kind = Kind_Symbol,
|
2019-03-17 13:24:03 +03:00
|
|
|
"parameter 1 must be a symbol");
|
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 20:06:00 +03:00
|
|
|
return R : constant Mal.T := Eval (Ast.Sequence.all (3), Env) do
|
|
|
|
Env.all.Set (Ast.Sequence.all (2).Symbol, R);
|
2019-02-28 00:27:12 +03:00
|
|
|
end return;
|
2019-03-17 13:24:03 +03:00
|
|
|
-- do is a built-in function, shortening this test cascade.
|
2019-02-28 00:27:12 +03:00
|
|
|
elsif First.Symbol = Symbols.Names.Fn then
|
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 20:06:00 +03:00
|
|
|
Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
|
|
|
|
Err.Check (Ast.Sequence.all (2).Kind in Kind_Sequence,
|
2019-03-17 13:24:03 +03:00
|
|
|
"parameter 1 must be a sequence");
|
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 20:06:00 +03:00
|
|
|
return Fns.New_Function
|
|
|
|
(Params => Ast.Sequence.all (2).Sequence.all,
|
|
|
|
Ast => Ast.Sequence.all (3),
|
|
|
|
Env => Env);
|
2019-02-28 00:27:12 +03:00
|
|
|
elsif First.Symbol = Symbols.Names.Mal_If then
|
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 20:06:00 +03:00
|
|
|
Err.Check (Ast.Sequence.all.Length in 3 .. 4,
|
2019-03-17 13:24:03 +03:00
|
|
|
"expected 2 or 3 parameters");
|
2019-02-28 00:27:12 +03:00
|
|
|
declare
|
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 20:06:00 +03:00
|
|
|
Test : constant Mal.T := Eval (Ast.Sequence.all (2), Env);
|
2019-02-28 00:27:12 +03:00
|
|
|
begin
|
2019-03-17 13:24:03 +03:00
|
|
|
if Test /= Mal.Nil and Test /= (Kind_Boolean, False) then
|
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 20:06:00 +03:00
|
|
|
return Eval (Ast.Sequence.all (3), Env);
|
|
|
|
elsif Ast.Sequence.all.Length = 3 then
|
2019-02-28 00:27:12 +03:00
|
|
|
return Mal.Nil;
|
|
|
|
else
|
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 20:06:00 +03:00
|
|
|
return Eval (Ast.Sequence.all (4), Env);
|
2019-02-28 00:27:12 +03:00
|
|
|
end if;
|
|
|
|
end;
|
|
|
|
elsif First.Symbol = Symbols.Names.Let then
|
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 20:06:00 +03:00
|
|
|
Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
|
|
|
|
Err.Check (Ast.Sequence.all (2).Kind in Kind_Sequence,
|
2019-03-17 13:24:03 +03:00
|
|
|
"parameter 1 must be a sequence");
|
2019-02-28 00:27:12 +03:00
|
|
|
declare
|
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 20:06:00 +03:00
|
|
|
Bindings : constant Mal.Sequence_Ptr
|
|
|
|
:= Ast.Sequence.all (2).Sequence;
|
|
|
|
New_Env : Envs.Ptr;
|
2019-02-28 00:27:12 +03:00
|
|
|
begin
|
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 20:06:00 +03:00
|
|
|
Err.Check (Bindings.all.Length mod 2 = 0,
|
2019-03-17 13:24:03 +03:00
|
|
|
"parameter 1 must have an even length");
|
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 20:06:00 +03:00
|
|
|
New_Env := Envs.New_Env (Outer => Env);
|
|
|
|
for I in 1 .. Bindings.all.Length / 2 loop
|
|
|
|
Err.Check (Bindings.all (2 * I - 1).Kind = Kind_Symbol,
|
2019-03-17 13:24:03 +03:00
|
|
|
"binding keys must be symbols");
|
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 20:06:00 +03:00
|
|
|
New_Env.all.Set (Bindings.all (2 * I - 1).Symbol,
|
|
|
|
Eval (Bindings.all (2 * I), New_Env));
|
2019-02-28 00:27:12 +03:00
|
|
|
end loop;
|
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 20:06:00 +03:00
|
|
|
return Eval (Ast.Sequence.all (3), New_Env);
|
2019-02-28 00:27:12 +03:00
|
|
|
end;
|
|
|
|
else
|
2019-03-10 02:14:59 +03:00
|
|
|
First := Eval (First, Env);
|
2019-02-28 00:27:12 +03:00
|
|
|
end if;
|
2019-03-10 02:14:59 +03:00
|
|
|
when others =>
|
|
|
|
First := Eval (First, Env);
|
|
|
|
end case;
|
|
|
|
|
|
|
|
-- Apply phase.
|
|
|
|
-- Ast is a non-empty list,
|
|
|
|
-- First is its non-special evaluated first element.
|
|
|
|
case First.Kind is
|
2019-02-28 00:27:12 +03:00
|
|
|
when Kind_Builtin =>
|
|
|
|
declare
|
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 20:06:00 +03:00
|
|
|
Args : Mal.T_Array (2 .. Ast.Sequence.all.Length);
|
2019-02-28 00:27:12 +03:00
|
|
|
begin
|
|
|
|
for I in Args'Range loop
|
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 20:06:00 +03:00
|
|
|
Args (I) := Eval (Ast.Sequence.all (I), Env);
|
2019-02-28 00:27:12 +03:00
|
|
|
end loop;
|
|
|
|
return First.Builtin.all (Args);
|
|
|
|
end;
|
2019-03-17 13:24:03 +03:00
|
|
|
when Kind_Fn =>
|
2019-02-28 00:27:12 +03:00
|
|
|
declare
|
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 20:06:00 +03:00
|
|
|
Args : Mal.T_Array (2 .. Ast.Sequence.all.Length);
|
2019-02-28 00:27:12 +03:00
|
|
|
begin
|
|
|
|
for I in Args'Range loop
|
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 20:06:00 +03:00
|
|
|
Args (I) := Eval (Ast.Sequence.all (I), Env);
|
2019-02-28 00:27:12 +03:00
|
|
|
end loop;
|
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 20:06:00 +03:00
|
|
|
return First.Fn.all.Apply (Args);
|
2019-02-28 00:27:12 +03:00
|
|
|
end;
|
|
|
|
when others =>
|
2019-03-17 13:24:03 +03:00
|
|
|
Err.Raise_With ("first element must be a function");
|
2016-10-10 20:08:59 +03:00
|
|
|
end case;
|
2019-03-17 13:24:03 +03:00
|
|
|
exception
|
|
|
|
when Err.Error =>
|
|
|
|
Err.Add_Trace_Line ("eval", Ast);
|
|
|
|
raise;
|
2016-10-10 20:08:59 +03:00
|
|
|
end Eval;
|
|
|
|
|
2019-03-17 13:24:03 +03:00
|
|
|
procedure Exec (Script : in String;
|
|
|
|
Env : in Envs.Ptr)
|
2019-03-06 21:48:51 +03:00
|
|
|
is
|
2019-03-17 13:24:03 +03:00
|
|
|
Result : Mal.T;
|
2016-10-10 20:08:59 +03:00
|
|
|
begin
|
2019-03-17 13:24:03 +03:00
|
|
|
for Expression of Reader.Read_Str (Script) loop
|
|
|
|
Result := Eval (Expression, Env);
|
|
|
|
end loop;
|
2019-03-06 21:48:51 +03:00
|
|
|
pragma Unreferenced (Result);
|
2019-03-17 13:24:03 +03:00
|
|
|
end Exec;
|
2019-03-06 21:48:51 +03:00
|
|
|
|
|
|
|
procedure Print (Ast : in Mal.T) is
|
|
|
|
begin
|
|
|
|
Ada.Text_IO.Unbounded_IO.Put_Line (Printer.Pr_Str (Ast));
|
|
|
|
end Print;
|
|
|
|
|
2019-03-17 13:24:03 +03:00
|
|
|
function Read return Mal.T_Array
|
|
|
|
is (Reader.Read_Str (Readline.Input ("user> ")));
|
2019-03-06 21:48:51 +03:00
|
|
|
|
|
|
|
procedure Rep (Env : in Envs.Ptr) is
|
|
|
|
begin
|
2019-03-17 13:24:03 +03:00
|
|
|
for Expression of Read loop
|
|
|
|
Print (Eval (Expression, Env));
|
|
|
|
end loop;
|
2019-03-06 21:48:51 +03:00
|
|
|
end Rep;
|
2016-10-10 20:08:59 +03:00
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2019-03-17 13:24:03 +03:00
|
|
|
Startup : constant String
|
|
|
|
:= "(def! not (fn* (a) (if a false true)))";
|
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 20:06:00 +03:00
|
|
|
Repl : constant Envs.Ptr := Envs.New_Env;
|
2016-10-10 20:08:59 +03:00
|
|
|
begin
|
2019-03-06 21:48:51 +03:00
|
|
|
-- Show the Eval function to other packages.
|
|
|
|
Eval_Cb.Cb := Eval'Unrestricted_Access;
|
|
|
|
-- Add Core functions into the top environment.
|
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 20:06:00 +03:00
|
|
|
Core.NS_Add_To_Repl (Repl);
|
2019-03-06 21:48:51 +03:00
|
|
|
-- Native startup procedure.
|
2019-03-17 13:24:03 +03:00
|
|
|
Exec (Startup, Repl);
|
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 20:06:00 +03:00
|
|
|
-- Execute user commands.
|
2019-03-06 21:48:51 +03:00
|
|
|
loop
|
|
|
|
begin
|
|
|
|
Rep (Repl);
|
|
|
|
exception
|
|
|
|
when Readline.End_Of_File =>
|
|
|
|
exit;
|
2019-03-17 13:24:03 +03:00
|
|
|
when Err.Error =>
|
|
|
|
Ada.Text_IO.Unbounded_IO.Put (Err.Trace);
|
2019-03-06 21:48:51 +03:00
|
|
|
end;
|
2019-03-17 13:24:03 +03:00
|
|
|
-- Other exceptions are really unexpected.
|
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 20:06:00 +03:00
|
|
|
|
|
|
|
-- Collect garbage.
|
|
|
|
Err.Data := Mal.Nil;
|
|
|
|
Repl.all.Keep;
|
|
|
|
Garbage_Collected.Clean;
|
2019-03-06 21:48:51 +03:00
|
|
|
end loop;
|
|
|
|
Ada.Text_IO.New_Line;
|
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 20:06:00 +03:00
|
|
|
|
2019-03-17 13:24:03 +03:00
|
|
|
-- If assertions are enabled, check deallocations.
|
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 20:06:00 +03:00
|
|
|
pragma Debug (Garbage_Collected.Clean);
|
|
|
|
Garbage_Collected.Check_Allocations;
|
|
|
|
Symbols.Check_Allocations;
|
2016-10-10 20:08:59 +03:00
|
|
|
end Step4_If_Fn_Do;
|