aboutsummaryrefslogtreecommitdiff
path: root/src/kompsos-collector.ads
blob: c1ea8bc1eb7d1ea91ed91b18604471bc194e59eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146


--  Programmed by Jedidiah Barber
--  Licensed under the Sunset License v1.0

--  See license.txt for further details


private with

    Ada.Containers.Vectors,
    Ada.Finalization;


generic
    Relation : in Goal;
    Within   : in State;
package Kompsos.Collector is


    State_Not_Found_Error : exception;


    function Has_Next
        return Boolean;

    function Next
        return State;

    function Next
           (Default : in State)
        return State;

    procedure Reset;


private


    type Goal_Access is access all Goal;
    type Constant_Goal_Access is access constant Goal;

    type Graph_Access is access all Goal_Graph;
    type Constant_Graph_Access is access constant Goal_Graph;

    type State_Access is access State;



    type Eval_Data (Kind : Node_Kind := Unify_Node) is record
        case Kind is
        when Unify_Node =>
            Uni_Offset : Long_Natural  := 0;
        when Disjunct_Node =>
            Dis_Flag   : Boolean       := True;
            Dis_Next1  : Long_Positive := 1;
            Dis_Next2  : Long_Positive := 1;
            Dis_Gone1  : Boolean       := False;
            Dis_Gone2  : Boolean       := False;
        when Conjunct_Node =>
            Con_From   : Long_Positive := 1;
            Con_Base   : State_Access  := null;
            Con_Part   : Goal_Access   := null;
            Con_Next   : Long_Positive := 1;
            Con_Gone   : Boolean       := False;
        when Recurse_Node =>
            Rec_Next   : Long_Positive := 1;
            Rec_Gone   : Boolean       := False;
            Rec_Cache  : Boolean       := True;
        end case;
    end record;



    type Cached_State is record
        Used : Positive     := 1;
        Data : State_Access := null;
    end record;

    package State_Vectors is new Ada.Containers.Vectors
       (Index_Type   => Long_Positive,
        Element_Type => Cached_State);

    type Cache_Entry is record
        Keep : Boolean              := False;
        Data : State_Vectors.Vector := State_Vectors.Empty_Vector;
    end record;

    type Cache_Entry_Access is access Cache_Entry;



    type Book_Node;

    type Book_Node_Access is access Book_Node;

    type Book_Node is record
        Data  : Eval_Data;
        Cache : Cache_Entry_Access := null;
        Next1 : Book_Node_Access   := null;
        Next2 : Book_Node_Access   := null;
    end record;



    type Loose_Book is record
        Used : Positive               := 1;
        Ptr  : Graph_Component_Access := null;
        Book : Book_Node_Access       := null;
    end record;

    package Loose_Book_Vectors is new Ada.Containers.Vectors
       (Index_Type   => Long_Positive,
        Element_Type => Loose_Book);

    package Book_Node_Vectors is new Ada.Containers.Vectors
       (Index_Type   => Long_Positive,
        Element_Type => Book_Node_Access);



    procedure Reset
           (Ptr  : in     Graph_Component_Access;
            Book : in out Book_Node_Access);

    function Get_Next
           (Ptr    : in     Constant_Graph_Access;
            Book   : in out Book_Node_Access;
            Base   : in     State;
            Index  : in     Long_Positive;
            Result :    out State)
        return Boolean;



    type Collector_Final_Controller is new Ada.Finalization.Limited_Controlled with null record;

    overriding procedure Finalize
           (This : in out Collector_Final_Controller);

    Cleanup : Collector_Final_Controller;


end Kompsos.Collector;