1
1
mirror of https://github.com/kanaka/mal.git synced 2024-10-06 10:27:34 +03:00
mal/ada/envs.ads

48 lines
1.3 KiB
Ada
Raw Normal View History

2015-04-02 01:36:29 +03:00
with Ada.Containers.Hashed_Maps;
with Ada.Strings.Unbounded;
with Smart_Pointers;
package Envs is
-- Set adds an element to the current environment
2015-04-02 23:40:22 +03:00
procedure Set (Key : String; SP : Smart_Pointers.Smart_Pointer);
2015-04-02 01:36:29 +03:00
-- Get finds a key in the current env. If it can't be found it looks
-- in a previous env. If it runs out of envs, Not Found is raised.
2015-04-02 23:40:22 +03:00
function Get (Key : String) return Smart_Pointers.Smart_Pointer;
2015-04-02 01:36:29 +03:00
Not_Found : exception;
2015-04-02 01:36:29 +03:00
-- Create a New_Env. THe previous one is pushed to the stack and the
-- new one becomes the current one.
procedure New_Env;
-- Destroys the top-most env and replaces it with the previous one
-- in the stack.
procedure Delete_Env;
private
function String_Hash (Key : Ada.Strings.Unbounded.Unbounded_String)
return Ada.Containers.Hash_Type;
package String_Mal_Hash is new Ada.Containers.Hashed_Maps
(Key_Type => Ada.Strings.Unbounded.Unbounded_String,
Element_Type => Smart_Pointers.Smart_Pointer,
Hash => String_Hash,
Equivalent_Keys => Ada.Strings.Unbounded."=",
"=" => Smart_Pointers."=");
2015-04-05 22:27:47 +03:00
type Environment;
type Env_Ptr is access Environment;
2015-04-02 01:36:29 +03:00
type Environment is record
The_Map : String_Mal_Hash.Map;
2015-04-05 22:27:47 +03:00
Prev_Env : Env_Ptr;
2015-04-02 01:36:29 +03:00
end record;
Current : Env_Ptr;
end Envs;