1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-19 09:38:28 +03:00
mal/impls/ada/envs.ads
Joel Martin 8a19f60386 Move implementations into impls/ dir
- Reorder README to have implementation list after "learning tool"
  bullet.

- This also moves tests/ and libs/ into impls. It would be preferrable
  to have these directories at the top level.  However, this causes
  difficulties with the wasm implementations which need pre-open
  directories and have trouble with paths starting with "../../". So
  in lieu of that, symlink those directories to the top-level.

- Move the run_argv_test.sh script into the tests directory for
  general hygiene.
2020-02-10 23:50:16 -06:00

65 lines
1.8 KiB
Ada

with Ada.Containers.Hashed_Maps;
with Ada.Strings.Unbounded.Hash;
with Smart_Pointers;
limited with Types;
package Envs is
type Env_Handle is private;
Null_Env_Handle : constant Env_Handle;
function New_Env (Outer : Env_Handle := Null_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;
Not_Found : exception;
procedure Set_Outer
(E : Env_Handle; Outer_Env : Env_Handle);
-- Sym and Exprs are lists. Bind Sets Keys in Syms to the corresponding
-- expression in Exprs. Returns true if all the parameters were bound.
function Bind (Env : Env_Handle; Syms, Exprs : Types.List_Mal_Type)
return Boolean;
function To_String (E : Env_Handle) return String;
Debug : Boolean := False;
private
type Env_Handle is new Smart_Pointers.Smart_Pointer;
Null_Env_Handle : constant Env_Handle :=
Env_Handle (Smart_Pointers.Null_Smart_Pointer);
function Is_Null (E : Env_Handle) return Boolean;
package String_Mal_Hash is new Ada.Containers.Hashed_Maps
(Key_Type => Ada.Strings.Unbounded.Unbounded_String,
Element_Type => Smart_Pointers.Smart_Pointer,
Hash => Ada.Strings.Unbounded.Hash,
Equivalent_Keys => Ada.Strings.Unbounded."=",
"=" => Smart_Pointers."=");
type Env is new Smart_Pointers.Base_Class with record
The_Map : String_Mal_Hash.Map;
Outer_Env : Env_Handle;
Level: Natural;
end record;
type Env_Ptr is access all Env;
function Deref (SP : Env_Handle) return Env_Ptr;
end Envs;