1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/ada/types.ads

84 lines
2.6 KiB
Ada
Raw Normal View History

2015-03-15 22:56:09 +03:00
with Ada.Containers.Doubly_Linked_Lists;
2015-03-23 01:37:42 +03:00
with Ada.Finalization;
2015-03-15 22:56:09 +03:00
with Ada.Strings.Unbounded;
package Types is
package UBStrings renames Ada.Strings.Unbounded;
2015-03-23 01:37:42 +03:00
-- There's a horrible dependency problem as Smart Pointers are used
-- within Mal_Type. If you start using private types then the compiler
-- complains that its being used in Mal_Type before it's been fully
-- declared. So that's the reason for all the public types below.
-- I'm not intending to play with any of the exposed internals...
-- Alternatively you could use private types and then specify all
-- the operations including those for lists. Good luck with that.
-- Smart Pointers section.
2015-03-15 22:56:09 +03:00
type Mal_Type;
2015-03-23 01:37:42 +03:00
type Mal_Type_Accessor is access Mal_Type;
type Smart_Pointer is new Ada.Finalization.Controlled with record
Pointer : Mal_Type_Accessor;
end record;
overriding procedure Adjust (Object : in out Smart_Pointer);
overriding procedure Finalize (Object : in out Smart_Pointer);
function New_Ptr (Mal_Type : Mal_Type_Accessor) return Smart_Pointer;
function Deref (Ptr : Smart_Pointer) return Mal_Type_Accessor;
Null_Smart_Pointer : constant Smart_Pointer :=
(Ada.Finalization.Controlled with Pointer => null);
-- Lists of Smart Pointers.
2015-03-15 22:56:09 +03:00
package Lists is
new Ada.Containers.Doubly_Linked_Lists
2015-03-23 01:37:42 +03:00
(Element_Type => Smart_Pointer,
2015-03-15 22:56:09 +03:00
"=" => "=");
2015-03-23 01:37:42 +03:00
-- Now we get to what the smart pointers are pointing to...
2015-03-19 00:12:54 +03:00
type Sym_Types is (Int, Floating, List, Sym, Str, Atom, Unitary, Error);
2015-03-16 01:00:31 +03:00
2015-03-20 01:19:13 +03:00
type Unitary_Functions is
(Quote, Unquote, Quasiquote, Splice_Unquote, Deref);
2015-03-15 22:56:09 +03:00
2015-03-17 01:48:48 +03:00
type List_Types is (List_List, Vector_List, Hashed_List);
function Opening (LT : List_Types) return Character;
function Closing (LT : List_Types) return Character;
subtype Mal_Float is Float;
subtype Mal_Integer is Integer;
2015-03-15 22:56:09 +03:00
type Mal_Type (Sym_Type : Sym_Types) is record
2015-03-23 01:37:42 +03:00
Ref_Count : Natural := 1;
Meta : Smart_Pointer;
2015-03-15 22:56:09 +03:00
case Sym_Type is
when Int => Int_Val : Mal_Integer;
when Floating => Float_Val : Mal_Float;
2015-03-17 01:48:48 +03:00
when List =>
List_Type : List_Types;
The_List : Lists.List;
2015-03-15 22:56:09 +03:00
when Sym => Symbol : Character;
when Str => The_String : Ada.Strings.Unbounded.Unbounded_String;
when Atom => The_Atom : Ada.Strings.Unbounded.Unbounded_String;
2015-03-16 01:00:31 +03:00
when Unitary =>
The_Function : Unitary_Functions;
2015-03-23 01:37:42 +03:00
The_Operand : Smart_Pointer;
2015-03-19 00:12:54 +03:00
when Error => Error_Msg : Ada.Strings.Unbounded.Unbounded_String;
2015-03-15 22:56:09 +03:00
end case;
end record;
function To_String (T : Mal_Type) return String;
end Types;