Ada: add symbol and symbol?
[jackhill/mal.git] / ada / envs.ads
1 with Ada.Containers.Hashed_Maps;
2 --with Ada.Strings.Unbounded;
3 with Ada.Strings.Unbounded.Hash;
4 with Smart_Pointers;
5 limited with Types;
6
7 package Envs is
8
9 type Env_Handle is private;
10
11 function New_Env (Outer : Env_Handle) return Env_Handle;
12
13 -- Set adds an element to the environment E.
14 procedure Set
15 (E : Env_Handle;
16 Key : String;
17 Elem : Smart_Pointers.Smart_Pointer);
18
19 -- Get finds a key in the E env. If it can't be found it looks
20 -- in an outer env. If it runs out of envs, Not Found is raised.
21 function Get (E : Env_Handle; Key : String)
22 return Smart_Pointers.Smart_Pointer;
23
24 procedure Set_Outer
25 (E : Env_Handle; Outer_Env : Env_Handle);
26
27 function To_String (E : Env_Handle) return String;
28
29 Not_Found : exception;
30
31 -- Sym and Exprs are lists. Bind Sets Keys in Syms to the corresponding
32 -- expression in Exprs. Returns true if all the parameters were bound.
33 function Bind (E : Env_Handle; Syms, Exprs : Types.List_Mal_Type)
34 return Boolean;
35
36 -- Create a New_Env. The previous one is pushed to the stack and the
37 -- new one becomes the current one.
38 procedure New_Env;
39
40 -- Destroys the top-most env and replaces it with the previous one
41 -- in the stack.
42 procedure Delete_Env;
43
44 function Get_Current return Env_Handle;
45
46 Debug : Boolean := False;
47
48 private
49
50 type Env_Handle is new Smart_Pointers.Smart_Pointer;
51
52 function Is_Null (E : Env_Handle) return Boolean;
53
54 package String_Mal_Hash is new Ada.Containers.Hashed_Maps
55 (Key_Type => Ada.Strings.Unbounded.Unbounded_String,
56 Element_Type => Smart_Pointers.Smart_Pointer,
57 Hash => Ada.Strings.Unbounded.Hash,
58 Equivalent_Keys => Ada.Strings.Unbounded."=",
59 "=" => Smart_Pointers."=");
60
61 type Env is new Smart_Pointers.Base_Class with record
62 The_Map : String_Mal_Hash.Map;
63 Outer_Env : Env_Handle;
64 Level: Natural;
65 end record;
66
67 Current : Env_Handle;
68
69 type Env_Ptr is access all Env;
70
71 function Deref (SP : Env_Handle) return Env_Ptr;
72
73 end Envs;