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 | ||
b5bad5ea CM |
10 | Null_Env_Handle : constant Env_Handle; |
11 | ||
12 | function New_Env (Outer : Env_Handle := Null_Env_Handle) return Env_Handle; | |
13ce1681 CM |
13 | |
14 | -- Set adds an element to the environment E. | |
15 | procedure Set | |
16 | (E : Env_Handle; | |
17 | Key : String; | |
18 | Elem : Smart_Pointers.Smart_Pointer); | |
19 | ||
20 | -- Get finds a key in the E env. If it can't be found it looks | |
21 | -- in an outer env. If it runs out of envs, Not Found is raised. | |
b5bad5ea CM |
22 | function Get (E : Env_Handle; Key : String) return Smart_Pointers.Smart_Pointer; |
23 | ||
24 | Not_Found : exception; | |
9a6f4925 | 25 | |
efaad1ce CM |
26 | procedure Set_Outer |
27 | (E : Env_Handle; Outer_Env : Env_Handle); | |
28 | ||
13ce1681 | 29 | -- Sym and Exprs are lists. Bind Sets Keys in Syms to the corresponding |
c3244bcf | 30 | -- expression in Exprs. Returns true if all the parameters were bound. |
b5bad5ea | 31 | function Bind (Env : Env_Handle; Syms, Exprs : Types.List_Mal_Type) |
c3244bcf | 32 | return Boolean; |
13ce1681 | 33 | |
b5bad5ea | 34 | function To_String (E : Env_Handle) return String; |
13ce1681 CM |
35 | |
36 | Debug : Boolean := False; | |
37 | ||
9a6f4925 CM |
38 | private |
39 | ||
13ce1681 CM |
40 | type Env_Handle is new Smart_Pointers.Smart_Pointer; |
41 | ||
b5bad5ea CM |
42 | Null_Env_Handle : constant Env_Handle := |
43 | Env_Handle (Smart_Pointers.Null_Smart_Pointer); | |
44 | ||
13ce1681 CM |
45 | function Is_Null (E : Env_Handle) return Boolean; |
46 | ||
9a6f4925 CM |
47 | package String_Mal_Hash is new Ada.Containers.Hashed_Maps |
48 | (Key_Type => Ada.Strings.Unbounded.Unbounded_String, | |
49 | Element_Type => Smart_Pointers.Smart_Pointer, | |
795c5e1a | 50 | Hash => Ada.Strings.Unbounded.Hash, |
9a6f4925 CM |
51 | Equivalent_Keys => Ada.Strings.Unbounded."=", |
52 | "=" => Smart_Pointers."="); | |
53 | ||
13ce1681 | 54 | type Env is new Smart_Pointers.Base_Class with record |
9a6f4925 | 55 | The_Map : String_Mal_Hash.Map; |
13ce1681 | 56 | Outer_Env : Env_Handle; |
efaad1ce | 57 | Level: Natural; |
9a6f4925 CM |
58 | end record; |
59 | ||
13ce1681 CM |
60 | type Env_Ptr is access all Env; |
61 | ||
62 | function Deref (SP : Env_Handle) return Env_Ptr; | |
9a6f4925 CM |
63 | |
64 | end Envs; |