summaryrefslogtreecommitdiff
path: root/src/kompsos.ads
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-11-13 12:12:27 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2025-11-13 12:12:27 +1300
commit25164ac09136d378d21411b9e47fededa4352594 (patch)
treed0bb486d0b42c610be42b6ee280043d152063b7e /src/kompsos.ads
parent60cdfe48b2f861e67e1ee8ca115aed8755e486f1 (diff)
Improved memory management for world gen
Diffstat (limited to 'src/kompsos.ads')
-rw-r--r--src/kompsos.ads46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/kompsos.ads b/src/kompsos.ads
index d2b6fe5..f3f8470 100644
--- a/src/kompsos.ads
+++ b/src/kompsos.ads
@@ -233,6 +233,26 @@ private
type World_Access is access Mu_World'Class;
+ type World_Holder is new Ada.Finalization.Controlled with record
+ Ptr : World_Access;
+ end record;
+
+ overriding procedure Initialize
+ (This : in out World_Holder);
+
+ overriding procedure Adjust
+ (This : in out World_Holder);
+
+ overriding procedure Finalize
+ (This : in out World_Holder);
+
+ function Hold
+ (This : in Mu_World'Class)
+ return World_Holder;
+
+ procedure Swap
+ (Left, Right : in out World_Holder);
+
type Generator_Kind is
(No_Gen,
Fresh_Gen,
@@ -246,20 +266,20 @@ private
when No_Gen =>
null;
when Fresh_Gen =>
- Frs_World : World_Access;
+ Frs_World : World_Holder;
Frs_Name : SU.Unbounded_String;
when Unify_Gen =>
- Uni_World : World_Access;
+ Uni_World : World_Holder;
Uni_Term1 : Term;
Uni_Term2 : Term;
when Buffer_Gen =>
- Buff_World : World_Access;
+ Buff_World : World_Holder;
when Disjunct_Gen =>
- Dis_World1 : World_Access;
- Dis_World2 : World_Access;
+ Dis_World1 : World_Holder;
+ Dis_World2 : World_Holder;
when Recurse_Gen =>
- Rec_World : World_Access;
- Rec_Index : Positive;
+ Rec_World : World_Holder;
+ Rec_Index : Positive;
end case;
end record;
@@ -267,18 +287,12 @@ private
(Index_Type => Positive,
Element_Type => State);
- type Mu_World is new Ada.Finalization.Controlled with record
+ type Mu_World is tagged record
Possibles : State_Vectors.Vector;
Next_Ident : ID_Number;
Engine : Generator;
end record;
- overriding procedure Adjust
- (This : in out Mu_World);
-
- overriding procedure Finalize
- (This : in out Mu_World);
-
function Has_State
(This : in out Mu_World;
Index : in Positive)
@@ -293,8 +307,8 @@ private
use type State_Vectors.Vector;
- Empty_Mu_World : constant Mu_World := (Ada.Finalization.Controlled with
- Possibles => State_Vectors.Empty_Vector & Empty_State,
+ Empty_Mu_World : constant Mu_World :=
+ (Possibles => State_Vectors.Empty_Vector & Empty_State,
Next_Ident => 0,
Engine => (Kind => No_Gen));