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