00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include "soarkernel.h"
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 slot *find_slot(Symbol * id, Symbol * attr)
00073 {
00074 slot *s;
00075
00076 if (!id)
00077 return NIL;
00078 for (s = id->id.slots; s != NIL; s = s->next)
00079 if (s->attr == attr)
00080 return s;
00081 return NIL;
00082 }
00083
00084 wme *find_impasse_wme(Symbol * id, Symbol * attr)
00085 {
00086 wme *s;
00087
00088 if (!id)
00089 return NIL;
00090
00091 #ifdef DEBUG_FIND_SLOT
00092
00093 print_with_symbols("\nFind Slot '%y' in %y", attr, id);
00094
00095 print("\nChecking the impasse_wmes");
00096 if (id->id.impasse_wmes) {
00097 for (s = id->id.impasse_wmes; s != NIL; s = s->next) {
00098 print_with_symbols("\n Found %y", s->attr);
00099 if (s->attr == attr) {
00100 print("\nFound it\n");
00101 #else
00102
00103 if (id->id.impasse_wmes) {
00104 for (s = id->id.impasse_wmes; s != NIL; s = s->next) {
00105
00106 if (s->attr == attr) {
00107 #endif
00108
00109 return s;
00110 }
00111 }
00112 }
00113 return NULL;
00114 }
00115
00116 slot *make_slot(Symbol * id, Symbol * attr)
00117 {
00118 slot *s;
00119 int i;
00120
00121 for (s = id->id.slots; s != NIL; s = s->next)
00122 if (s->attr == attr)
00123 return s;
00124 allocate_with_pool(¤t_agent(slot_pool), &s);
00125 insert_at_head_of_dll(id->id.slots, s, next, prev);
00126 if ((id->id.isa_goal) && (attr == current_agent(operator_symbol)))
00127 s->isa_context_slot = TRUE;
00128 else
00129 s->isa_context_slot = FALSE;
00130 s->changed = NIL;
00131 s->acceptable_preference_changed = NIL;
00132 s->id = id;
00133 s->attr = attr;
00134 symbol_add_ref(id);
00135 symbol_add_ref(attr);
00136 s->wmes = NIL;
00137 s->all_preferences = NIL;
00138 for (i = 0; i < NUM_PREFERENCE_TYPES; i++)
00139 s->preferences[i] = NIL;
00140 s->impasse_type = NONE_IMPASSE_TYPE;
00141 s->impasse_id = NIL;
00142 s->acceptable_preference_wmes = NIL;
00143 s->marked_for_possible_removal = FALSE;
00144 return s;
00145 }
00146
00147 void mark_slot_as_changed(slot * s)
00148 {
00149 dl_cons *dc;
00150
00151 if (s->isa_context_slot) {
00152 if (current_agent(highest_goal_whose_context_changed)) {
00153 if (s->id->id.level < current_agent(highest_goal_whose_context_changed)->id.level)
00154 current_agent(highest_goal_whose_context_changed) = s->id;
00155 } else {
00156 current_agent(highest_goal_whose_context_changed) = s->id;
00157 }
00158 s->changed = (dl_cons *) s;
00159 } else {
00160 if (!s->changed) {
00161 allocate_with_pool(¤t_agent(dl_cons_pool), &dc);
00162 dc->item = s;
00163 s->changed = dc;
00164 insert_at_head_of_dll(current_agent(changed_slots), dc, next, prev);
00165 }
00166 }
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 void mark_slot_for_possible_removal(slot * s)
00185 {
00186 if (s->marked_for_possible_removal)
00187 return;
00188 s->marked_for_possible_removal = TRUE;
00189 push(s, current_agent(slots_for_possible_removal));
00190 }
00191
00192 void remove_garbage_slots(void)
00193 {
00194 cons *c;
00195 slot *s;
00196
00197 while (current_agent(slots_for_possible_removal)) {
00198 c = current_agent(slots_for_possible_removal);
00199 current_agent(slots_for_possible_removal) = current_agent(slots_for_possible_removal)->rest;
00200 s = c->first;
00201 free_cons(c);
00202
00203 if (s->wmes || s->all_preferences) {
00204
00205 s->marked_for_possible_removal = FALSE;
00206 continue;
00207 }
00208
00209
00210 #ifdef DEBUG_SLOTS
00211 print_with_symbols("\nDeallocate slot %y ^%y", s->id, s->attr);
00212 #endif
00213
00214 if (s->changed && (!s->isa_context_slot)) {
00215 remove_from_dll(current_agent(changed_slots), s->changed, next, prev);
00216 free_with_pool(¤t_agent(dl_cons_pool), s->changed);
00217 }
00218 remove_from_dll(s->id->id.slots, s, next, prev);
00219 if (s->id == NULL)
00220 print("ERROR!!!! in Garbage collection");
00221 else
00222 symbol_remove_ref(s->id);
00223 symbol_remove_ref(s->attr);
00224 free_with_pool(¤t_agent(slot_pool), s);
00225 }
00226 }