2015-04-02 01:36:29 +03:00
|
|
|
with Ada.Containers.Hashed_Maps;
|
2015-04-26 22:09:18 +03:00
|
|
|
with Ada.Strings.Unbounded.Hash;
|
2015-04-02 01:36:29 +03:00
|
|
|
with Smart_Pointers;
|
2015-04-19 20:08:51 +03:00
|
|
|
limited with Types;
|
2015-04-02 01:36:29 +03:00
|
|
|
|
|
|
|
package Envs is
|
|
|
|
|
2015-04-19 20:08:51 +03:00
|
|
|
type Env_Handle is private;
|
|
|
|
|
|
|
|
function New_Env (Outer : Env_Handle) return Env_Handle;
|
|
|
|
|
|
|
|
-- Set adds an element to the environment E.
|
|
|
|
procedure Set
|
|
|
|
(E : Env_Handle;
|
|
|
|
Key : String;
|
|
|
|
Elem : Smart_Pointers.Smart_Pointer);
|
|
|
|
|
|
|
|
-- Get finds a key in the E env. If it can't be found it looks
|
|
|
|
-- in an outer env. If it runs out of envs, Not Found is raised.
|
|
|
|
function Get (E : Env_Handle; Key : String)
|
|
|
|
return Smart_Pointers.Smart_Pointer;
|
2015-04-02 01:36:29 +03:00
|
|
|
|
2015-04-22 23:27:43 +03:00
|
|
|
procedure Set_Outer
|
|
|
|
(E : Env_Handle; Outer_Env : Env_Handle);
|
|
|
|
|
|
|
|
function To_String (E : Env_Handle) return String;
|
|
|
|
|
2015-04-03 00:34:55 +03:00
|
|
|
Not_Found : exception;
|
|
|
|
|
2015-04-19 20:08:51 +03:00
|
|
|
-- Sym and Exprs are lists. Bind Sets Keys in Syms to the corresponding
|
2015-06-09 22:59:05 +03:00
|
|
|
-- expression in Exprs. Returns true if all the parameters were bound.
|
|
|
|
function Bind (E : Env_Handle; Syms, Exprs : Types.List_Mal_Type)
|
|
|
|
return Boolean;
|
2015-04-19 20:08:51 +03:00
|
|
|
|
|
|
|
-- Create a New_Env. The previous one is pushed to the stack and the
|
2015-04-02 01:36:29 +03:00
|
|
|
-- 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;
|
|
|
|
|
2015-04-19 20:08:51 +03:00
|
|
|
function Get_Current return Env_Handle;
|
|
|
|
|
|
|
|
Debug : Boolean := False;
|
|
|
|
|
2015-04-02 01:36:29 +03:00
|
|
|
private
|
|
|
|
|
2015-04-19 20:08:51 +03:00
|
|
|
type Env_Handle is new Smart_Pointers.Smart_Pointer;
|
|
|
|
|
|
|
|
function Is_Null (E : Env_Handle) return Boolean;
|
|
|
|
|
2015-04-02 01:36:29 +03:00
|
|
|
package String_Mal_Hash is new Ada.Containers.Hashed_Maps
|
|
|
|
(Key_Type => Ada.Strings.Unbounded.Unbounded_String,
|
|
|
|
Element_Type => Smart_Pointers.Smart_Pointer,
|
2015-04-26 22:09:18 +03:00
|
|
|
Hash => Ada.Strings.Unbounded.Hash,
|
2015-04-02 01:36:29 +03:00
|
|
|
Equivalent_Keys => Ada.Strings.Unbounded."=",
|
|
|
|
"=" => Smart_Pointers."=");
|
|
|
|
|
2015-04-19 20:08:51 +03:00
|
|
|
type Env is new Smart_Pointers.Base_Class with record
|
2015-04-02 01:36:29 +03:00
|
|
|
The_Map : String_Mal_Hash.Map;
|
2015-04-19 20:08:51 +03:00
|
|
|
Outer_Env : Env_Handle;
|
2015-04-22 23:27:43 +03:00
|
|
|
Level: Natural;
|
2015-04-02 01:36:29 +03:00
|
|
|
end record;
|
|
|
|
|
2015-04-19 20:08:51 +03:00
|
|
|
Current : Env_Handle;
|
|
|
|
|
|
|
|
type Env_Ptr is access all Env;
|
|
|
|
|
|
|
|
function Deref (SP : Env_Handle) return Env_Ptr;
|
2015-04-02 01:36:29 +03:00
|
|
|
|
|
|
|
end Envs;
|