1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-19 17:47:53 +03:00
mal/ada.2/step4_if_fn_do.adb

264 lines
8.6 KiB
Ada
Raw Normal View History

ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
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;
2016-10-10 20:08:59 +03:00
with Core;
with Envs;
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
with Err;
with Garbage_Collected;
2016-10-10 20:08:59 +03:00
with Printer;
with Reader;
with Readline;
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
with Types.Fns;
with Types.Maps;
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
with Types.Sequences;
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 22:19:34 +03:00
with Types.Strings;
2016-10-10 20:08:59 +03:00
procedure Step4_If_Fn_Do is
Dbgeval : constant Boolean := Ada.Environment_Variables.Exists ("dbgeval");
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
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 22:19:34 +03:00
use type Types.T;
use all type Types.Kind_Type;
use type Types.Strings.Instance;
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 22:19:34 +03:00
function Read return Types.T_Array with Inline;
2016-10-10 20:08:59 +03:00
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 22:19:34 +03:00
function Eval (Ast : in Types.T;
Env : in Envs.Ptr) return Types.T;
2016-10-10 20:08:59 +03:00
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 22:19:34 +03:00
procedure Print (Ast : in Types.T) with Inline;
2016-10-10 20:08:59 +03:00
procedure Rep (Env : in Envs.Ptr) with Inline;
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 22:19:34 +03:00
function Eval_Map (Source : in Types.Maps.Instance;
Env : in Envs.Ptr) return Types.T;
function Eval_Vector (Source : in Types.Sequences.Instance;
Env : in Envs.Ptr) return Types.T;
-- Helpers for the Eval function.
2016-10-10 20:08:59 +03:00
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
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
----------------------------------------------------------------------
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 22:19:34 +03:00
function Eval (Ast : in Types.T;
Env : in Envs.Ptr) return Types.T
is
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 22:19:34 +03:00
First : Types.T;
2016-10-10 20:08:59 +03:00
begin
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
if Dbgeval then
Ada.Text_IO.New_Line;
Ada.Text_IO.Put ("EVAL: ");
Print (Ast);
Envs.Dump_Stack (Env.all);
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
end if;
2016-10-10 20:08:59 +03:00
case Ast.Kind is
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 22:19:34 +03:00
when Kind_Nil | Kind_Atom | Kind_Boolean | Kind_Number | Types.Kind_Key
| Kind_Macro | Types.Kind_Function =>
return Ast;
2016-10-10 20:08:59 +03:00
when Kind_Symbol =>
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 22:19:34 +03:00
return Env.all.Get (Ast.Str);
2016-10-10 20:08:59 +03:00
when Kind_Map =>
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 22:19:34 +03:00
return Eval_Map (Ast.Map.all, Env);
2016-10-10 20:08:59 +03:00
when Kind_Vector =>
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 22:19:34 +03:00
return Eval_Vector (Ast.Sequence.all, Env);
2016-10-10 20:08:59 +03:00
when Kind_List =>
null;
end case;
-- Ast is a list.
if Ast.Sequence.all.Length = 0 then
return Ast;
end if;
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 22:19:34 +03:00
First := Ast.Sequence.all.Data (1);
-- Special forms
-- Ast is a non-empty list, First is its first element.
case First.Kind is
when Kind_Symbol =>
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 22:19:34 +03:00
if First.Str.all = "if" then
Err.Check (Ast.Sequence.all.Length in 3 .. 4,
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
"expected 2 or 3 parameters");
declare
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 22:19:34 +03:00
Tst : constant Types.T := Eval (Ast.Sequence.all.Data (2), Env);
begin
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 22:19:34 +03:00
if Tst /= Types.Nil and Tst /= (Kind_Boolean, False) then
return Eval (Ast.Sequence.all.Data (3), Env);
elsif Ast.Sequence.all.Length = 3 then
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 22:19:34 +03:00
return Types.Nil;
else
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 22:19:34 +03:00
return Eval (Ast.Sequence.all.Data (4), Env);
end if;
end;
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 22:19:34 +03:00
elsif First.Str.all = "let*" then
Err.Check (Ast.Sequence.all.Length = 3
and then Ast.Sequence.all.Data (2).Kind in Types.Kind_Sequence,
"expected a sequence then a value");
declare
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 22:19:34 +03:00
Bindings : Types.T_Array
renames Ast.Sequence.all.Data (2).Sequence.all.Data;
New_Env : constant Envs.Ptr := Envs.New_Env (Outer => Env);
begin
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 22:19:34 +03:00
Err.Check (Bindings'Length mod 2 = 0, "expected even binds");
for I in 0 .. Bindings'Length / 2 - 1 loop
New_Env.all.Set (Bindings (Bindings'First + 2 * I),
Eval (Bindings (Bindings'First + 2 * I + 1), New_Env));
-- This call checks key kind.
end loop;
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 22:19:34 +03:00
return Eval (Ast.Sequence.all.Data (3), New_Env);
end;
elsif First.Str.all = "def!" then
Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
declare
Key : Types.T renames Ast.Sequence.all.Data (2);
Val : constant Types.T := Eval (Ast.Sequence.all.Data (3), Env);
begin
Env.all.Set (Key, Val); -- Check key kind.
return Val;
end;
elsif First.Str.all = "do" then
Err.Check (1 < Ast.Sequence.all.Length, "do expects arguments");
declare
Result : Types.T;
begin
for I in 2 .. Ast.Sequence.all.Length loop
Result := Eval (Ast.Sequence.all.Data (I), Env);
end loop;
return Result;
end;
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 22:19:34 +03:00
elsif First.Str.all = "fn*" then
Err.Check (Ast.Sequence.all.Length = 3, "expected 2 parameters");
declare
Params : Types.T renames Ast.Sequence.all.Data (2);
begin
Err.Check (Params.Kind in Types.Kind_Sequence,
"first argument of fn* must be a sequence");
return (Kind_Fn, Types.Fns.New_Function
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 22:19:34 +03:00
(Params => Params.Sequence,
Ast => Ast.Sequence.all.Data (3),
Env => Env));
end;
else
First := Eval (First, Env);
end if;
when others =>
First := Eval (First, Env);
end case;
-- Apply phase.
-- Ast is a non-empty list,
-- First is its non-special evaluated first element.
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 22:19:34 +03:00
Err.Check (First.Kind in Types.Kind_Function,
"first element must be a function");
-- We are applying a function. Evaluate its arguments.
declare
Args : Types.T_Array (2 .. Ast.Sequence.all.Length);
begin
for I in Args'Range loop
Args (I) := Eval (Ast.Sequence.all.Data (I), Env);
end loop;
if First.Kind = Kind_Builtin then
return First.Builtin.all (Args);
end if;
return First.Fn.all.Apply (Args);
end;
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
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;
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 22:19:34 +03:00
function Eval_Map (Source : in Types.Maps.Instance;
Env : in Envs.Ptr) return Types.T
is
use all type Types.Maps.Cursor;
-- Copy the whole map so that keys are not hashed again.
Result : constant Types.T := Types.Maps.New_Map (Source);
Position : Types.Maps.Cursor := Result.Map.all.First;
begin
while Has_Element (Position) loop
Result.Map.all.Replace_Element (Position,
Eval (Element (Position), Env));
Next (Position);
end loop;
return Result;
end Eval_Map;
function Eval_Vector (Source : in Types.Sequences.Instance;
Env : in Envs.Ptr) return Types.T
is
Ref : constant Types.Sequence_Ptr
:= Types.Sequences.Constructor (Source.Length);
begin
for I in Source.Data'Range loop
Ref.all.Data (I) := Eval (Source.Data (I), Env);
end loop;
return (Kind_Vector, Ref);
end Eval_Vector;
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
procedure Exec (Script : in String;
Env : in Envs.Ptr)
is
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 22:19:34 +03:00
Result : Types.T;
2016-10-10 20:08:59 +03:00
begin
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
for Expression of Reader.Read_Str (Script) loop
Result := Eval (Expression, Env);
end loop;
pragma Unreferenced (Result);
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
end Exec;
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 22:19:34 +03:00
procedure Print (Ast : in Types.T) is
begin
Ada.Text_IO.Unbounded_IO.Put_Line (Printer.Pr_Str (Ast));
end Print;
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 22:19:34 +03:00
function Read return Types.T_Array
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
is (Reader.Read_Str (Readline.Input ("user> ")));
procedure Rep (Env : in Envs.Ptr) is
begin
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
for Expression of Read loop
Print (Eval (Expression, Env));
end loop;
end Rep;
2016-10-10 20:08:59 +03:00
----------------------------------------------------------------------
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
Startup : constant String
:= "(def! not (fn* (a) (if a false true)))";
Repl : constant Envs.Ptr := Envs.New_Env;
2016-10-10 20:08:59 +03:00
begin
-- Show the Eval function to other packages.
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 22:19:34 +03:00
Types.Fns.Eval_Cb := Eval'Unrestricted_Access;
-- Add Core functions into the top environment.
Core.NS_Add_To_Repl (Repl);
-- Native startup procedure.
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
Exec (Startup, Repl);
-- Execute user commands.
loop
begin
Rep (Repl);
exception
when Readline.End_Of_File =>
exit;
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
when Err.Error =>
Ada.Text_IO.Unbounded_IO.Put (Err.Trace);
end;
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
-- Other exceptions are really unexpected.
-- Collect garbage.
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 22:19:34 +03:00
Err.Data := Types.Nil;
Repl.all.Keep;
Garbage_Collected.Clean;
end loop;
Ada.Text_IO.New_Line;
ada.2: spring cleaning before final pull request. Two changes require approval. * The 'do' special becomes a built-in function similar to first. This small change reduces the complexity of eval. The last evaluation cannot benefit from TCO, but the performance change seems invisible. * read/eval/print acts on each item found in the input string, as if they were enclosed with (do ..). The guide does not specify what should happen to text following the first AST, and this change actually simplifies some things (like dealing with zero AST). The read-string built-in function only returns the first AST, as changing this would be much more intrusive. Other changes seem straightforward. Global: * Ada 2020 target assignments (like +=, but more general). * Use Constant_Indexing aspect for sequences, so that they can be indexed in source code like native arrays. * consistency renamings. 'fn' does not include built-in functions, 'function' does. 'list' does not include vectors, 'sequence' does. Move error handling to a separate package. * This simplifies code everywhere else. * Uncaught expressions now report a stack trace. Types: * Count allocations and deallocations, check that counts match. * Share more code between functions and macros. Core: * Replace the Core.Ns function returning an array with a procedure (The intermediate object was preventing the reference counting code from deallocating some unused objects). * Implement Prn with Pr_Str. Printer: * Change the profile so that the caller spares some allocations. Reader: * Share a single buffer of mal values between all recursions. This significantly reduces the stack footprint. Steps: * Fix implementation name (ada.2) in the startup script. * Let environment variables trigger debugging information.
2019-03-17 13:24:03 +03:00
-- If assertions are enabled, check deallocations.
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 22:19:34 +03:00
-- Normal runs do not need to deallocate before termination.
-- Beware that all pointers are now dangling.
pragma Debug (Garbage_Collected.Clean);
Garbage_Collected.Check_Allocations;
2016-10-10 20:08:59 +03:00
end Step4_If_Fn_Do;