summaryrefslogtreecommitdiff
path: root/src/kompsos.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/kompsos.adb')
-rw-r--r--src/kompsos.adb77
1 files changed, 62 insertions, 15 deletions
diff --git a/src/kompsos.adb b/src/kompsos.adb
index 0ac59ee..d531f25 100644
--- a/src/kompsos.adb
+++ b/src/kompsos.adb
@@ -6,9 +6,53 @@
-- See license.txt for further details
+with
+
+ Ada.Unchecked_Deallocation;
+
+
package body Kompsos is
+ -------------------------
+ -- Memory Management --
+ -------------------------
+
+ -- Terms --
+
+ procedure Free is new Ada.Unchecked_Deallocation (Term_Component, Term_Component_Access);
+
+
+ procedure Initialize
+ (This : in out Term) is
+ begin
+ This.Actual := null;
+ end Initialize;
+
+
+ procedure Adjust
+ (This : in out Term) is
+ begin
+ if This.Kind /= Null_Term then
+ This.Actual.Counter := This.Actual.Counter + 1;
+ end if;
+ end Adjust;
+
+
+ procedure Finalize
+ (This : in out Term) is
+ begin
+ if This.Kind /= Null_Term then
+ This.Actual.Counter := This.Actual.Counter - 1;
+ if This.Actual.Counter = 0 then
+ Free (This.Actual);
+ end if;
+ end if;
+ end Finalize;
+
+
+
+
-----------------
-- Datatypes --
-----------------
@@ -19,7 +63,7 @@ package body Kompsos is
(This : in Term)
return Term_Kind is
begin
- return Term_Component (This.Actual.Constant_Reference.Element.all).Kind;
+ return (if This.Actual = null then Null_Term else This.Actual.Kind);
end Kind;
@@ -27,9 +71,10 @@ package body Kompsos is
(Item : in Element_Type)
return Term is
begin
- return (Actual => Term_Holders.To_Holder (Term_Component'(
- Kind => Atom_Term,
- Value => Item)));
+ return (Ada.Finalization.Controlled with Actual => new Term_Component'(
+ Kind => Atom_Term,
+ Counter => 1,
+ Value => Item));
end T;
@@ -37,9 +82,10 @@ package body Kompsos is
(Item : in Variable)
return Term'Class is
begin
- return Term'(Actual => Term_Holders.To_Holder (Term_Component'(
- Kind => Var_Term,
- Refer => Item)));
+ return Term'(Ada.Finalization.Controlled with Actual => new Term_Component'(
+ Kind => Var_Term,
+ Counter => 1,
+ Refer => Item));
end T;
@@ -47,10 +93,11 @@ package body Kompsos is
(Item1, Item2 : in Term'Class)
return Term is
begin
- return (Actual => Term_Holders.To_Holder (Term_Component'(
- Kind => Pair_Term,
- Left => Term (Item1),
- Right => Term (Item2))));
+ return (Ada.Finalization.Controlled with Actual => new Term_Component'(
+ Kind => Pair_Term,
+ Counter => 1,
+ Left => Term (Item1),
+ Right => Term (Item2)));
end T;
@@ -70,7 +117,7 @@ package body Kompsos is
(This : in Term)
return Element_Type is
begin
- return Term_Component (This.Actual.Constant_Reference.Element.all).Value;
+ return This.Actual.Value;
end Atom;
@@ -78,7 +125,7 @@ package body Kompsos is
(This : in Term'Class)
return Variable is
begin
- return Term_Component (This.Actual.Constant_Reference.Element.all).Refer;
+ return This.Actual.Refer;
end Var;
@@ -94,7 +141,7 @@ package body Kompsos is
(This : in Term)
return Term is
begin
- return Term_Component (This.Actual.Constant_Reference.Element.all).Left;
+ return This.Actual.Left;
end Left;
@@ -102,7 +149,7 @@ package body Kompsos is
(This : in Term)
return Term is
begin
- return Term_Component (This.Actual.Constant_Reference.Element.all).Right;
+ return This.Actual.Right;
end Right;