* Deleted copy_term_nat/2 definition
[chr.git] / chr_translate_bootstrap2.pl
blob2a9d5fbcd489e33c43bdcae17e99af5214913379
1 /* Generated by CHR bootstrap compiler
2 From: chr_translate_bootstrap2.chr
3 Date: Wed Jan 19 10:16:37 2005
5 DO NOT EDIT. EDIT THE CHR FILE INSTEAD
6 */
8 :-module(chr_translate, [chr_translate/2]).
9 :-use_module(chr_runtime).
10 :-style_check(-singleton).
11 :-style_check(- (discontiguous)).
12 :-use_module(chr_runtime).
13 :-use_module(chr_hashtable_store).
14 :-style_check(-singleton).
15 :-style_check(- (discontiguous)).
16 :-use_module(library(lists)).
17 :-use_module(hprolog).
18 :-use_module(library(assoc)).
19 :-use_module(pairlist).
20 :-use_module(library(ordsets)).
21 :-use_module(a_star).
22 :-use_module(clean_code).
23 :-use_module(builtins).
24 :-use_module(find).
25 :-include(chr_op2).
26 chr_translate(A, B) :-
27 init_chr_pp_flags,
28 partition_clauses(A, C, D, E),
29 ( C==[]
30 -> insert_declarations(E, B)
31 ; add_rules(D),
32 check_rules(D, C),
33 add_occurrences(D),
34 late_allocation(C),
35 unique_analyse_optimise(D, F),
36 check_attachments(C),
37 assume_constraint_stores(C),
38 set_constraint_indices(C, 1),
39 constraints_code(C, F, G),
40 validate_store_type_assumptions(C),
41 store_management_preds(C, H),
42 insert_declarations(E, I),
43 chr_module_declaration(J),
44 append_lists([I, H, G, J], B)
46 store_management_preds(A, B) :-
47 generate_attach_detach_a_constraint_all(A, C),
48 generate_indexed_variables_clauses(A, D),
49 generate_attach_increment(E),
50 generate_attr_unify_hook(F),
51 generate_extra_clauses(A, G),
52 generate_insert_delete_constraints(A, H),
53 generate_store_code(A, I),
54 append_lists([C, D, E, F, G, H, I], B).
55 insert_declarations(A, B) :-
56 ( A=[ (:-module(C, D))|E]
57 -> B=[ (:-module(C, D)), (:-use_module(chr_runtime)), (:-use_module(chr_hashtable_store)), (:-style_check(-singleton)), (:-style_check(- (discontiguous)))|E]
58 ; B=[ (:-use_module(chr_runtime)), (:-use_module(chr_hashtable_store)), (:-style_check(-singleton)), (:-style_check(- (discontiguous)))|A]
60 chr_module_declaration(A) :-
61 get_target_module(B),
62 ( B\==chr_translate
63 -> A=[ (:-multifile chr:'$chr_module'/1), chr:'$chr_module'(B)]
64 ; A=[]
66 partition_clauses([], [], [], []).
67 partition_clauses([A|B], C, D, E) :-
68 ( parse_rule(A, F)
69 -> C=G,
70 D=[F|H],
71 E=I
72 ; is_declaration(A, J)
73 -> append(J, G, C),
74 D=H,
75 E=I
76 ; is_module_declaration(A, K)
77 -> target_module(K),
78 C=G,
79 D=H,
80 E=[A|I]
81 ; A=handler(L)
82 -> format('CHR compiler WARNING: ~w.\n', [A]),
83 format(' `--> SICStus compatibility: ignoring handler/1 declaration.\n', []),
84 C=G,
85 D=H,
86 E=I
87 ; A=rules(M)
88 -> format('CHR compiler WARNING: ~w.\n', [A]),
89 format(' `--> SICStus compatibility: ignoring rules/1 declaration.\n', []),
90 C=G,
91 D=H,
92 E=I
93 ; A=option(N, O)
94 -> handle_option(N, O),
95 C=G,
96 D=H,
97 E=I
98 ; C=G,
99 D=H,
100 E=[A|I]
102 partition_clauses(B, G, H, I).
103 is_declaration(A, B) :-
104 ( A= (:-C)
105 -> true
106 ; A=C
108 C=..[constraints, D],
109 conj2list(D, B).
110 parse_rule(A, B) :-
111 A= @(C, D), !,
112 rule(D, yes(C), B).
113 parse_rule(A, B) :-
114 rule(A, no, B).
115 rule(A, B, C) :-
116 A=pragma(D, E), !,
117 is_rule(D, F, G),
118 conj2list(E, H),
119 inc_rule_count(I),
120 C=pragma(F, G, H, B, I).
121 rule(A, B, C) :-
122 is_rule(A, D, E),
123 inc_rule_count(F),
124 C=pragma(D, E, [], B, F).
125 is_rule(A, B, C) :-
126 A= ==>(D, E), !,
127 conj2list(D, F),
128 get_ids(F, G, H),
129 C=ids([], G),
130 ( E= (I|J)
131 -> B=rule([], H, I, J)
132 ; B=rule([], H, true, E)
134 is_rule(A, B, C) :-
135 A= <=>(D, E), !,
136 ( E= (F|G)
137 -> H=F,
139 ; H=true,
142 ( D= \(J, K)
143 -> conj2list(J, L),
144 conj2list(K, M),
145 get_ids(L, N, O, 0, P),
146 get_ids(M, Q, R, P, S),
147 C=ids(Q, N)
148 ; conj2list(D, M),
149 O=[],
150 get_ids(M, Q, R),
151 C=ids(Q, [])
153 B=rule(R, O, H, I).
154 get_ids(A, B, C) :-
155 get_ids(A, B, C, 0, D).
156 get_ids([], [], [], A, A).
157 get_ids([A|B], [C|D], [E|F], C, G) :-
158 ( A= #(E, C)
159 -> true
160 ; E=A
162 H is C+1,
163 get_ids(B, D, F, H, G).
164 is_module_declaration((:-module(A)), A).
165 is_module_declaration((:-module(A, B)), A).
166 add_rules([]).
167 add_rules([A|B]) :-
168 A=pragma(C, D, E, F, G),
169 rule(G, A),
170 add_rules(B).
171 check_rules([], A).
172 check_rules([A|B], C) :-
173 check_rule(A, C),
174 check_rules(B, C).
175 check_rule(A, B) :-
176 check_rule_indexing(A),
177 A=pragma(C, D, E, F, G),
178 C=rule(H, I, J, K),
179 append(H, I, L),
180 check_head_constraints(L, B, A),
181 check_pragmas(E, A).
182 check_head_constraints([], A, B).
183 check_head_constraints([A|B], C, D) :-
184 functor(A, E, F),
185 ( member(E/F, C)
186 -> check_head_constraints(B, C, D)
187 ; format('CHR compiler ERROR: Undeclared constraint ~w in head of ~@.\n', [E/F, format_rule(D)]),
188 format(' `--> Constraint should be one of ~w.\n', [C]),
189 fail
191 check_pragmas([], A).
192 check_pragmas([A|B], C) :-
193 check_pragma(A, C),
194 check_pragmas(B, C).
195 check_pragma(A, B) :-
196 var(A), !,
197 format('CHR compiler ERROR: invalid pragma ~w in ~@.\n', [A, format_rule(B)]),
198 format(' `--> Pragma should not be a variable!\n', []),
199 fail.
200 check_pragma(passive(A), B) :- !,
201 B=pragma(C, ids(D, E), F, G, H),
202 ( memberchk_eq(A, D)
203 -> true
204 ; memberchk_eq(A, E)
205 -> true
206 ; format('CHR compiler ERROR: invalid identifier ~w in pragma passive in ~@.\n', [A, format_rule(B)]),
207 fail
209 passive(H, A).
210 check_pragma(A, B) :-
211 A=unique(C, D), !,
212 B=pragma(E, F, G, H, I),
213 pragma_unique(I, C, D),
214 format('CHR compiler WARNING: undocument pragma ~w in ~@.\n', [A, format_rule(B)]),
215 format(' `--> Only use this pragma if you know what you are doing.\n', []).
216 check_pragma(A, B) :-
217 A=already_in_heads, !,
218 format('CHR compiler WARNING: currently unsupported pragma ~w in ~@.\n', [A, format_rule(B)]),
219 format(' `--> Pragma is ignored. Termination and correctness may be affected \n', []).
220 check_pragma(A, B) :-
221 A=already_in_head(C), !,
222 format('CHR compiler WARNING: currently unsupported pragma ~w in ~@.\n', [A, format_rule(B)]),
223 format(' `--> Pragma is ignored. Termination and correctness may be affected \n', []).
224 check_pragma(A, B) :-
225 format('CHR compiler ERROR: invalid pragma ~w in ~@.\n', [A, format_rule(B)]),
226 format(' `--> Pragma should be one of passive/1!\n', []),
227 fail.
228 format_rule(A) :-
229 A=pragma(B, C, D, E, F),
230 ( E=yes(G)
231 -> write('rule '),
232 write(G)
233 ; write('rule number '),
234 write(F)
236 check_rule_indexing(A) :-
237 A=pragma(B, C, D, E, F),
238 B=rule(G, H, I, J),
239 term_variables(G-H, K),
240 remove_anti_monotonic_guards(I, K, L),
241 check_indexing(G, L-H),
242 check_indexing(H, L-G).
243 remove_anti_monotonic_guards(A, B, C) :-
244 conj2list(A, D),
245 remove_anti_monotonic_guard_list(D, B, E),
246 list2conj(E, C).
247 remove_anti_monotonic_guard_list([], A, []).
248 remove_anti_monotonic_guard_list([A|B], C, D) :-
249 ( A=var(E),
250 memberchk_eq(E, C)
251 -> D=F
252 ; D=[A|F]
254 remove_anti_monotonic_guard_list(B, C, F).
255 check_indexing([], A).
256 check_indexing([A|B], C) :-
257 functor(A, D, E),
258 A=..[F|G],
259 term_variables(B-C, H),
260 check_indexing(G, 1, D/E, H),
261 check_indexing(B, [A|C]).
262 check_indexing([], A, B, C).
263 check_indexing([A|B], C, D, E) :-
264 ( is_indexed_argument(D, C)
265 -> true
266 ; nonvar(A)
267 -> indexed_argument(D, C)
268 ; term_variables(B, F),
269 append(F, E, G),
270 ( memberchk_eq(A, G)
271 -> indexed_argument(D, C)
272 ; true
275 H is C+1,
276 term_variables(A, I),
277 append(I, E, J),
278 check_indexing(B, H, D, J).
279 add_occurrences([]).
280 add_occurrences([A|B]) :-
281 A=pragma(rule(C, D, E, F), ids(G, H), I, J, K),
282 add_occurrences(C, G, K),
283 add_occurrences(D, H, K),
284 add_occurrences(B).
285 add_occurrences([], [], A).
286 add_occurrences([A|B], [C|D], E) :-
287 functor(A, F, G),
288 H=F/G,
289 get_max_occurrence(H, I),
290 J is I+1,
291 occurrence(H, J, E, C),
292 add_occurrences(B, D, E).
293 late_allocation([]).
294 late_allocation([A|B]) :-
295 allocation_occurrence(A, 1),
296 late_allocation(B).
297 handle_option(A, B) :-
298 var(A), !,
299 format('CHR compiler ERROR: ~w.\n', [option(A, B)]),
300 format(' `--> First argument should be an atom, not a variable.\n', []),
301 fail.
302 handle_option(A, B) :-
303 var(B), !,
304 format('CHR compiler ERROR: ~w.\n', [option(A, B)]),
305 format(' `--> Second argument should be a nonvariable.\n', []),
306 fail.
307 handle_option(A, B) :-
308 option_definition(A, B, C), !,
309 set_chr_pp_flags(C).
310 handle_option(A, B) :-
311 \+option_definition(A, C, D), !,
312 format('CHR compiler WARNING: ~w.\n', [option(A, B)]),
313 format(' `--> Invalid option name \n', []).
314 handle_option(A, B) :-
315 findall(C, option_definition(A, C, D), E),
316 format('CHR compiler ERROR: ~w.\n', [option(A, B)]),
317 format(' `--> Invalid value ~w: should be one of ~w.\n', [B, E]),
318 fail.
319 option_definition(optimize, experimental, A) :-
320 A=[unique_analyse_optimise-on, check_unnecessary_active-full, reorder_heads-on, set_semantics_rule-on, check_attachments-on, guard_via_reschedule-on].
321 option_definition(optimize, full, A) :-
322 A=[unique_analyse_optimise-on, check_unnecessary_active-full, reorder_heads-on, set_semantics_rule-on, check_attachments-on, guard_via_reschedule-on].
323 option_definition(optimize, sicstus, A) :-
324 A=[unique_analyse_optimise-off, check_unnecessary_active-simplification, reorder_heads-off, set_semantics_rule-off, check_attachments-off, guard_via_reschedule-off].
325 option_definition(optimize, off, A) :-
326 A=[unique_analyse_optimise-off, check_unnecessary_active-off, reorder_heads-off, set_semantics_rule-off, check_attachments-off, guard_via_reschedule-off].
327 option_definition(check_guard_bindings, on, A) :-
328 A=[guard_locks-on].
329 option_definition(check_guard_bindings, off, A) :-
330 A=[guard_locks-off].
331 option_definition(reduced_indexing, on, A) :-
332 A=[reduced_indexing-on].
333 option_definition(reduced_indexing, off, A) :-
334 A=[reduced_indexing-off].
335 option_definition(mode, A, []) :-
336 ( nonvar(A)
337 -> functor(A, B, C),
338 A=..[D|E],
339 constraint_mode(B/C, E)
340 ; true
342 option_definition(store, A-B, []) :-
343 store_type(A, B).
344 option_definition(debug, on, A) :-
345 A=[debugable-on].
346 option_definition(debug, off, A) :-
347 A=[debugable-off].
348 init_chr_pp_flags :-
349 chr_pp_flag_definition(A, [B|C]),
350 set_chr_pp_flag(A, B),
351 fail.
352 init_chr_pp_flags.
353 set_chr_pp_flags([]).
354 set_chr_pp_flags([A-B|C]) :-
355 set_chr_pp_flag(A, B),
356 set_chr_pp_flags(C).
357 set_chr_pp_flag(A, B) :-
358 atom_concat('$chr_pp_', A, C),
359 nb_setval(C, B).
360 chr_pp_flag_definition(unique_analyse_optimise, [on, off]).
361 chr_pp_flag_definition(check_unnecessary_active, [full, simplification, off]).
362 chr_pp_flag_definition(reorder_heads, [on, off]).
363 chr_pp_flag_definition(set_semantics_rule, [on, off]).
364 chr_pp_flag_definition(guard_via_reschedule, [on, off]).
365 chr_pp_flag_definition(guard_locks, [on, off]).
366 chr_pp_flag_definition(check_attachments, [on, off]).
367 chr_pp_flag_definition(debugable, [off, on]).
368 chr_pp_flag_definition(reduced_indexing, [on, off]).
369 chr_pp_flag(A, B) :-
370 atom_concat('$chr_pp_', A, C),
371 nb_getval(C, D),
372 ( D==[]
373 -> chr_pp_flag_definition(A, [B|E])
374 ; D=B
376 generate_attach_detach_a_constraint_all([], []).
377 generate_attach_detach_a_constraint_all([A|B], C) :-
378 ( may_trigger(A)
379 -> generate_attach_a_constraint(A, D),
380 generate_detach_a_constraint(A, E)
381 ; D=[],
382 E=[]
384 generate_attach_detach_a_constraint_all(B, F),
385 append_lists([D, E, F], C).
386 generate_attach_a_constraint(A, [B, C]) :-
387 generate_attach_a_constraint_empty_list(A, B),
388 get_max_constraint_index(D),
389 ( D==1
390 -> generate_attach_a_constraint_1_1(A, C)
391 ; generate_attach_a_constraint_t_p(A, C)
393 generate_attach_a_constraint_skeleton(A, B, C, D) :-
394 make_name(attach_, A, E),
395 F=..[E|B],
396 D= (F:-C).
397 generate_attach_a_constraint_empty_list(A, B) :-
398 generate_attach_a_constraint_skeleton(A, [[], C], true, B).
399 generate_attach_a_constraint_1_1(A, B) :-
400 C=[[D|E], F],
401 generate_attach_a_constraint_skeleton(A, C, G, B),
402 generate_attach_body_1(A, D, F, H),
403 make_name(attach_, A, I),
404 J=..[I, E, F],
405 G= (H, J).
406 generate_attach_body_1(A, B, C, D) :-
407 get_target_module(E),
408 D= (get_attr(B, E, F)->G=[C|F], put_attr(B, E, G);put_attr(B, E, [C])).
409 generate_attach_a_constraint_t_p(A, B) :-
410 C=[[D|E], F],
411 generate_attach_a_constraint_skeleton(A, C, G, B),
412 make_name(attach_, A, H),
413 I=..[H, E, F],
414 generate_attach_body_n(A, D, F, J),
415 G= (J, I).
416 generate_attach_body_n(A/B, C, D, E) :-
417 get_constraint_index(A/B, F),
418 or_pattern(F, G),
419 get_max_constraint_index(H),
420 make_attr(H, I, J, K),
421 nth(F, J, L),
422 substitute(L, J, [D|L], M),
423 make_attr(H, I, M, N),
424 substitute(L, J, [D], O),
425 make_attr(H, P, O, Q),
426 copy_term(J, R),
427 nth(F, R, [D]),
428 delete(R, [D], S),
429 set_elems(S, []),
430 make_attr(H, G, R, T),
431 get_target_module(U),
432 E= (get_attr(C, U, V)->V=K, (I/\G=:=G->put_attr(C, U, N);P is I\/G, put_attr(C, U, Q));put_attr(C, U, T)).
433 generate_detach_a_constraint(A, [B, C]) :-
434 generate_detach_a_constraint_empty_list(A, B),
435 get_max_constraint_index(D),
436 ( D==1
437 -> generate_detach_a_constraint_1_1(A, C)
438 ; generate_detach_a_constraint_t_p(A, C)
440 generate_detach_a_constraint_empty_list(A, B) :-
441 make_name(detach_, A, C),
442 D=[[], E],
443 F=..[C|D],
444 B= (F:-true).
445 generate_detach_a_constraint_1_1(A, B) :-
446 make_name(detach_, A, C),
447 D=[[E|F], G],
448 H=..[C|D],
449 I=..[C, F, G],
450 generate_detach_body_1(A, E, G, J),
451 K= (J, I),
452 B= (H:-K).
453 generate_detach_body_1(A, B, C, D) :-
454 get_target_module(E),
455 D= (get_attr(B, E, F)->'chr sbag_del_element'(F, C, G), (G==[]->del_attr(B, E);put_attr(B, E, G));true).
456 generate_detach_a_constraint_t_p(A, B) :-
457 make_name(detach_, A, C),
458 D=[[E|F], G],
459 H=..[C|D],
460 I=..[C, F, G],
461 generate_detach_body_n(A, E, G, J),
462 K= (J, I),
463 B= (H:-K).
464 generate_detach_body_n(A/B, C, D, E) :-
465 get_constraint_index(A/B, F),
466 or_pattern(F, G),
467 and_pattern(F, H),
468 get_max_constraint_index(I),
469 make_attr(I, J, K, L),
470 nth(F, K, M),
471 substitute(M, K, [], N),
472 make_attr(I, O, N, P),
473 substitute(M, K, Q, R),
474 make_attr(I, J, R, S),
475 get_target_module(T),
476 E= (get_attr(C, T, U)->U=L, (J/\G=:=G->'chr sbag_del_element'(M, D, Q), (Q==[]->O is J/\H, (O==0->del_attr(C, T);put_attr(C, T, P));put_attr(C, T, S));true);true).
477 generate_indexed_variables_clauses(A, B) :-
478 ( forsome(C, A, chr_translate:may_trigger(C))
479 -> generate_indexed_variables_clauses_(A, B)
480 ; B=[]
482 generate_indexed_variables_clauses_([], []).
483 generate_indexed_variables_clauses_([A|B], C) :-
484 ( ( is_attached(A)
485 ; chr_pp_flag(debugable, on)
487 -> C=[D|E],
488 generate_indexed_variables_clause(A, D)
489 ; C=E
491 generate_indexed_variables_clauses_(B, E).
492 generate_indexed_variables_clause(A/B, C) :-
493 functor(D, A, B),
494 get_constraint_mode(A/B, E),
495 D=..[F|G],
496 create_indexed_variables_body(G, E, H, 1, A/B, I, J),
497 ( I==empty
498 -> K= (H=[])
499 ; J==0
500 -> K=term_variables(L, H)
501 ; I=K
503 C= ('$indexed_variables'(L, H):-L=D, K).
504 create_indexed_variables_body([], [], A, B, C, empty, 0).
505 create_indexed_variables_body([A|B], [C|D], E, F, G, H, I) :-
506 J is F+1,
507 create_indexed_variables_body(B, D, K, J, G, L, M),
508 ( C\== +,
509 is_indexed_argument(G, F)
510 -> ( L==empty
511 -> H=term_variables(A, E)
512 ; H= (term_variables(A, E, K), L)
515 ; E=K,
516 H=L,
517 I is M+1
519 generate_extra_clauses(A, [B, C, D, E, F]) :-
520 ( chr_pp_flag(reduced_indexing, on)
521 -> global_indexed_variables_clause(A, E)
522 ; E= (chr_indexed_variables(G, H):-'chr chr_indexed_variables'(G, H))
524 generate_remove_clause(B),
525 generate_activate_clause(C),
526 generate_allocate_clause(D),
527 generate_insert_constraint_internal(F).
528 generate_remove_clause(A) :-
529 A= (remove_constraint_internal(B, C, D):-arg(2, B, E), E=mutable(F), 'chr update_mutable'(removed, E), (compound(F)->C=[], D=no;F==removed->C=[], D=no;D=yes, chr_indexed_variables(B, C))).
530 generate_activate_clause(A) :-
531 A= (activate_constraint(B, C, D, E):-arg(2, D, F), F=mutable(G), 'chr update_mutable'(active, F), (nonvar(E)->true;arg(4, D, H), H=mutable(I), E is I+1, 'chr update_mutable'(E, H)), (compound(G)->term_variables(G, C), 'chr none_locked'(C), B=yes;G==removed->chr_indexed_variables(D, C), B=yes;C=[], B=no)).
532 generate_allocate_clause(A) :-
533 A= (allocate_constraint(B, C, D, E):-C=..[suspension, F, G, B, H, I, D|E], H=mutable(0), 'chr empty_history'(J), I=mutable(J), chr_indexed_variables(C, K), G=mutable(passive(K)), 'chr gen_id'(F)).
534 generate_insert_constraint_internal(A) :-
535 A= (insert_constraint_internal(yes, B, C, D, E, F):-C=..[suspension, G, H, D, I, J, E|F], chr_indexed_variables(C, B), 'chr none_locked'(B), H=mutable(active), I=mutable(0), J=mutable(K), 'chr empty_history'(K), 'chr gen_id'(G)).
536 global_indexed_variables_clause(A, B) :-
537 ( forsome(C, A, chr_translate:may_trigger(C))
538 -> D= (E=..[F, G, H, I, J, K, L|M], '$indexed_variables'(L, N))
539 ; D=true,
540 N=[]
542 B= (chr_indexed_variables(E, N):-D).
543 generate_attach_increment(A) :-
544 get_max_constraint_index(B),
545 ( B>0
546 -> A=[C, D],
547 generate_attach_increment_empty(C),
548 ( B==1
549 -> generate_attach_increment_one(D)
550 ; generate_attach_increment_many(B, D)
552 ; A=[]
554 generate_attach_increment_empty((attach_increment([], A):-true)).
555 generate_attach_increment_one(A) :-
556 B=attach_increment([C|D], E),
557 get_target_module(F),
558 G= ('chr not_locked'(C), (get_attr(C, F, H)->sort(H, I), merge(E, I, J), put_attr(C, F, J);put_attr(C, F, E)), attach_increment(D, E)),
559 A= (B:-G).
560 generate_attach_increment_many(A, B) :-
561 make_attr(A, C, D, E),
562 make_attr(A, F, G, H),
563 I=attach_increment([J|K], E),
564 bagof(L, M^N^O^P^ (member2(D, G, M-N), L= (sort(N, O), 'chr merge_attributes'(M, O, P))), Q),
565 list2conj(Q, R),
566 bagof(S, T^U^V^member((T, 'chr merge_attributes'(U, V, S)), Q), W),
567 make_attr(A, X, W, Y),
568 get_target_module(Z),
569 A1= ('chr not_locked'(J), (get_attr(J, Z, B1)->B1=H, R, X is C\/F, put_attr(J, Z, Y);put_attr(J, Z, E)), attach_increment(K, E)),
570 B= (I:-A1).
571 generate_attr_unify_hook([A]) :-
572 get_max_constraint_index(B),
573 ( B==0
574 -> get_target_module(C),
575 A= (attr_unify_hook(D, E):-write('ERROR: Unexpected triggering of attr_unify_hook/2 in module '), writeln(C))
576 ; B==1
577 -> generate_attr_unify_hook_one(A)
578 ; generate_attr_unify_hook_many(B, A)
580 generate_attr_unify_hook_one(A) :-
581 B=attr_unify_hook(C, D),
582 get_target_module(E),
583 make_run_suspensions(F, G),
584 make_run_suspensions(C, H),
585 I= (sort(C, J), (var(D)-> (get_attr(D, E, K)->true;K=[]), sort(K, L), 'chr merge_attributes'(J, L, F), put_attr(D, E, F), G; (compound(D)->term_variables(D, M), attach_increment(M, J);true), H)),
586 A= (B:-I).
587 generate_attr_unify_hook_many(A, B) :-
588 make_attr(A, C, D, E),
589 make_attr(A, F, G, H),
590 bagof(I, J^K^ (member(J, D), I=sort(J, K)), L),
591 list2conj(L, M),
592 bagof(K, J^member(sort(J, K), L), N),
593 bagof(O, P^Q^R^S^ (member2(N, G, P-Q), O= (sort(Q, R), 'chr merge_attributes'(P, R, S))), T),
594 bagof(S, P^R^U^member((U, 'chr merge_attributes'(P, R, S)), T), V),
595 list2conj(T, W),
596 make_attr(A, X, V, Y),
597 make_attr(A, C, N, Z),
598 A1=attr_unify_hook(E, B1),
599 get_target_module(C1),
600 make_run_suspensions_loop(V, D1),
601 make_run_suspensions_loop(N, E1),
602 F1= (M, (var(B1)-> (get_attr(B1, C1, G1)->G1=H, W, X is C\/F, put_attr(B1, C1, Y), D1;put_attr(B1, C1, Z), E1); (compound(B1)->term_variables(B1, H1), attach_increment(H1, Z);true), E1)),
603 B= (A1:-F1).
604 make_run_suspensions(A, B) :-
605 ( chr_pp_flag(debugable, on)
606 -> B='chr run_suspensions_d'(A)
607 ; B='chr run_suspensions'(A)
609 make_run_suspensions_loop(A, B) :-
610 ( chr_pp_flag(debugable, on)
611 -> B='chr run_suspensions_loop_d'(A)
612 ; B='chr run_suspensions_loop'(A)
614 generate_insert_delete_constraints([], []).
615 generate_insert_delete_constraints([A|B], C) :-
616 ( is_attached(A)
617 -> C=[D, E|F],
618 generate_insert_delete_constraint(A, D, E)
619 ; C=F
621 generate_insert_delete_constraints(B, F).
622 generate_insert_delete_constraint(A, B, C) :-
623 get_store_type(A, D),
624 generate_insert_constraint(D, A, B),
625 generate_delete_constraint(D, A, C).
626 generate_insert_constraint(A, B, C) :-
627 make_name('$insert_in_store_', B, D),
628 E=..[D, F],
629 generate_insert_constraint_body(A, B, F, G),
630 C= (E:-G).
631 generate_insert_constraint_body(default, A, B, C) :-
632 get_target_module(D),
633 get_max_constraint_index(E),
634 ( E==1
635 -> generate_attach_body_1(A, F, B, G)
636 ; generate_attach_body_n(A, F, B, G)
638 C= ('chr global_term_ref_1'(F), G).
639 generate_insert_constraint_body(multi_hash(A), B, C, D) :-
640 generate_multi_hash_insert_constraint_bodies(A, B, C, D).
641 generate_insert_constraint_body(global_ground, A, B, C) :-
642 global_ground_store_name(A, D),
643 C= (nb_getval(D, E), b_setval(D, [B|E])).
644 generate_insert_constraint_body(multi_store(A), B, C, D) :-
645 find_with_var_identity(E, [C], (member(F, A), chr_translate:generate_insert_constraint_body(F, B, C, E)), G),
646 list2conj(G, D).
647 generate_multi_hash_insert_constraint_bodies([], A, B, true).
648 generate_multi_hash_insert_constraint_bodies([A|B], C, D, (E, F)) :-
649 multi_hash_store_name(C, A, G),
650 multi_hash_key(C, A, D, H, I),
651 E= (H, nb_getval(G, J), insert_ht(J, I, D)),
652 generate_multi_hash_insert_constraint_bodies(B, C, D, F).
653 generate_delete_constraint(A, B, C) :-
654 make_name('$delete_from_store_', B, D),
655 E=..[D, F],
656 generate_delete_constraint_body(A, B, F, G),
657 C= (E:-G).
658 generate_delete_constraint_body(default, A, B, C) :-
659 get_target_module(D),
660 get_max_constraint_index(E),
661 ( E==1
662 -> generate_detach_body_1(A, F, B, G),
663 C= ('chr global_term_ref_1'(F), G)
664 ; generate_detach_body_n(A, F, B, G),
665 C= ('chr global_term_ref_1'(F), G)
667 generate_delete_constraint_body(multi_hash(A), B, C, D) :-
668 generate_multi_hash_delete_constraint_bodies(A, B, C, D).
669 generate_delete_constraint_body(global_ground, A, B, C) :-
670 global_ground_store_name(A, D),
671 C= (nb_getval(D, E), 'chr sbag_del_element'(E, B, F), b_setval(D, F)).
672 generate_delete_constraint_body(multi_store(A), B, C, D) :-
673 find_with_var_identity(E, [C], (member(F, A), chr_translate:generate_delete_constraint_body(F, B, C, E)), G),
674 list2conj(G, D).
675 generate_multi_hash_delete_constraint_bodies([], A, B, true).
676 generate_multi_hash_delete_constraint_bodies([A|B], C, D, (E, F)) :-
677 multi_hash_store_name(C, A, G),
678 multi_hash_key(C, A, D, H, I),
679 E= (H, nb_getval(G, J), delete_ht(J, I, D)),
680 generate_multi_hash_delete_constraint_bodies(B, C, D, F).
681 generate_delete_constraint_call(A, B, C) :-
682 make_name('$delete_from_store_', A, D),
683 C=..[D, B].
684 generate_insert_constraint_call(A, B, C) :-
685 make_name('$insert_in_store_', A, D),
686 C=..[D, B].
687 generate_store_code(A, [B|C]) :-
688 enumerate_stores_code(A, B),
689 generate_store_code(A, C, []).
690 generate_store_code([], A, A).
691 generate_store_code([A|B], C, D) :-
692 get_store_type(A, E),
693 generate_store_code(E, A, C, F),
694 generate_store_code(B, F, D).
695 generate_store_code(default, A, B, B).
696 generate_store_code(multi_hash(A), B, C, D) :-
697 multi_hash_store_initialisations(A, B, C, E),
698 multi_hash_via_lookups(A, B, E, D).
699 generate_store_code(global_ground, A, B, C) :-
700 global_ground_store_initialisation(A, B, C).
701 generate_store_code(multi_store(A), B, C, D) :-
702 multi_store_generate_store_code(A, B, C, D).
703 multi_store_generate_store_code([], A, B, B).
704 multi_store_generate_store_code([A|B], C, D, E) :-
705 generate_store_code(A, C, D, F),
706 multi_store_generate_store_code(B, C, F, E).
707 multi_hash_store_initialisations([], A, B, B).
708 multi_hash_store_initialisations([A|B], C, D, E) :-
709 multi_hash_store_name(C, A, F),
710 D=[ (:-new_ht(G), nb_setval(F, G))|H],
711 multi_hash_store_initialisations(B, C, H, E).
712 global_ground_store_initialisation(A, B, C) :-
713 global_ground_store_name(A, D),
714 B=[ (:-nb_setval(D, []))|C].
715 multi_hash_via_lookups([], A, B, B).
716 multi_hash_via_lookups([A|B], C, D, E) :-
717 multi_hash_via_lookup_name(C, A, F),
718 G=..[F, H, I],
719 multi_hash_store_name(C, A, J),
720 K= (nb_getval(J, L), lookup_ht(L, H, I)),
721 D=[ (G:-K)|M],
722 multi_hash_via_lookups(B, C, M, E).
723 multi_hash_via_lookup_name(A/B, C, D) :-
724 ( integer(C)
725 -> E=C
726 ; is_list(C)
727 -> atom_concat_list(C, E)
729 atom_concat_list(['$via1_multi_hash_', A, /, B, -, E], D).
730 multi_hash_store_name(A/B, C, D) :-
731 get_target_module(E),
732 ( integer(C)
733 -> F=C
734 ; is_list(C)
735 -> atom_concat_list(C, F)
737 atom_concat_list(['$chr_store_multi_hash_', E, :, A, /, B, -, F], D).
738 multi_hash_key(A/B, C, D, E, F) :-
739 ( ( integer(C)
740 -> G=C
741 ; C=[G]
743 -> H is G+6,
744 E=arg(H, D, F)
745 ; is_list(C)
746 -> sort(C, I),
747 find_with_var_identity(arg(J, D, K)-K, [D], (member(G, I), J is G+6), L),
748 pairup(M, N, L),
749 F=..[k|N],
750 list2conj(M, E)
752 multi_hash_key_args(A, B, C) :-
753 ( integer(A)
754 -> arg(A, B, D),
755 C=[D]
756 ; is_list(A)
757 -> sort(A, E),
758 term_variables(B, F),
759 find_with_var_identity(D, F, (member(G, E), arg(G, B, D)), C)
761 global_ground_store_name(A/B, C) :-
762 get_target_module(D),
763 atom_concat_list(['$chr_store_global_ground_', D, :, A, /, B], C).
764 enumerate_stores_code(A, B) :-
765 C='$enumerate_suspensions'(D),
766 enumerate_store_bodies(A, D, E),
767 list2disj(E, F),
768 B= (C:-F).
769 enumerate_store_bodies([], A, []).
770 enumerate_store_bodies([A|B], C, D) :-
771 ( is_attached(A)
772 -> get_store_type(A, E),
773 enumerate_store_body(E, A, C, F),
774 D=[F|G]
775 ; D=G
777 enumerate_store_bodies(B, C, G).
778 enumerate_store_body(default, A, B, C) :-
779 get_constraint_index(A, D),
780 get_target_module(E),
781 get_max_constraint_index(F),
782 G= ('chr global_term_ref_1'(H), get_attr(H, E, I)),
783 ( F>1
784 -> J is D+1,
785 K= (arg(J, I, L), 'chr sbag_member'(B, L))
786 ; K='chr sbag_member'(B, I)
788 C= (G, K).
789 enumerate_store_body(multi_hash([A|B]), C, D, E) :-
790 multi_hash_enumerate_store_body(A, C, D, E).
791 enumerate_store_body(global_ground, A, B, C) :-
792 global_ground_store_name(A, D),
793 C= (nb_getval(D, E), 'chr sbag_member'(B, E)).
794 enumerate_store_body(multi_store(A), B, C, D) :-
795 once((
796 member(E, A),
797 enumerate_store_body(E, B, C, D)
799 multi_hash_enumerate_store_body(A, B, C, D) :-
800 multi_hash_store_name(B, A, E),
801 D= (nb_getval(E, F), value_ht(F, C)).
802 check_attachments(A) :-
803 ( chr_pp_flag(check_attachments, on)
804 -> check_constraint_attachments(A)
805 ; true
807 check_constraint_attachments([]).
808 check_constraint_attachments([A|B]) :-
809 check_constraint_attachment(A),
810 check_constraint_attachments(B).
811 check_constraint_attachment(A) :-
812 get_max_occurrence(A, B),
813 check_occurrences_attachment(A, 1, B).
814 check_occurrences_attachment(A, B, C) :-
815 ( B>C
816 -> true
817 ; check_occurrence_attachment(A, B),
818 D is B+1,
819 check_occurrences_attachment(A, D, C)
821 check_occurrence_attachment(A, B) :-
822 get_occurrence(A, B, C, D),
823 get_rule(C, E),
824 E=pragma(rule(F, G, H, I), ids(J, K), L, M, N),
825 ( select2(D, O, J, F, P, Q)
826 -> check_attachment_head1(O, D, C, F, G, H)
827 ; select2(D, R, K, G, S, T)
828 -> check_attachment_head2(R, D, C, F, I)
830 check_attachment_head1(A, B, C, D, E, F) :-
831 functor(A, G, H),
832 ( D==[A],
833 E==[],
834 F==true,
835 A=..[I|J],
836 no_matching(J, []),
837 \+is_passive(C, B)
838 -> attached(G/H, no)
839 ; attached(G/H, maybe)
841 no_matching([], A).
842 no_matching([A|B], C) :-
843 var(A),
844 \+memberchk_eq(A, C),
845 no_matching(B, [A|C]).
846 check_attachment_head2(A, B, C, D, E) :-
847 functor(A, F, G),
848 ( is_passive(C, B)
849 -> attached(F/G, maybe)
850 ; D\==[],
851 E==true
852 -> attached(F/G, maybe)
853 ; attached(F/G, yes)
855 all_attached([]).
856 all_attached([A|B]) :-
857 functor(A, C, D),
858 is_attached(C/D),
859 all_attached(B).
860 set_constraint_indices([], A) :-
861 B is A-1,
862 max_constraint_index(B).
863 set_constraint_indices([A|B], C) :-
864 ( ( may_trigger(A)
865 ; is_attached(A),
866 get_store_type(A, default)
868 -> constraint_index(A, C),
869 D is C+1,
870 set_constraint_indices(B, D)
871 ; set_constraint_indices(B, C)
873 constraints_code(A, B, C) :-
874 post_constraints(A, 1),
875 constraints_code1(1, B, D, []),
876 clean_clauses(D, C).
877 post_constraints([], A) :-
878 B is A-1,
879 constraint_count(B).
880 post_constraints([A/B|C], D) :-
881 constraint(A/B, D),
882 E is D+1,
883 post_constraints(C, E).
884 constraints_code1(A, B, C, D) :-
885 get_constraint_count(E),
886 ( A>E
887 -> D=C
888 ; constraint_code(A, B, C, F),
889 G is A+1,
890 constraints_code1(G, B, F, D)
892 constraint_code(A, B, C, D) :-
893 get_constraint(E, A),
894 constraint_prelude(E, F),
895 C=[F|G],
896 H=[0],
897 rules_code(B, A, H, I, G, J),
898 gen_cond_attach_clause(E, I, J, D).
899 constraint_prelude(A/B, C) :-
900 vars_susp(B, D, E, F),
901 G=..[A|D],
902 build_head(A, B, [0], F, H),
903 get_target_module(I),
904 J=..[A|D],
905 ( chr_pp_flag(debugable, on)
906 -> C= (G:-allocate_constraint(I:H, E, J, D), ('chr debug_event'(call(E)), H;'chr debug_event'(fail(E)), !, fail), ('chr debug_event'(exit(E));'chr debug_event'(redo(E)), fail))
907 ; C= (G:-H)
909 gen_cond_attach_clause(A/B, C, D, E) :-
910 ( is_attached(A/B)
911 -> ( C==[0]
912 -> ( may_trigger(A/B)
913 -> gen_cond_attach_goal(A/B, F, G, H, I)
914 ; gen_insert_constraint_internal_goal(A/B, F, G, H, I)
916 ; vars_susp(B, H, I, G),
917 gen_uncond_attach_goal(A/B, I, F, J)
919 ( chr_pp_flag(debugable, on)
920 -> K=..[A|H],
921 L='chr debug_event'(insert(#(K, I)))
922 ; L=true
924 build_head(A, B, C, G, M),
925 N= (M:-L, F),
926 D=[N|E]
927 ; D=E
929 gen_cond_attach_goal(A/B, C, D, E, F) :-
930 vars_susp(B, E, F, D),
931 build_head(A, B, [0], D, G),
932 ( may_trigger(A/B)
933 -> make_name(attach_, A/B, H),
934 I=..[H, J, F]
935 ; I=true
937 get_target_module(K),
938 L=..[A|E],
939 generate_insert_constraint_call(A/B, F, M),
940 C= ((var(F)->insert_constraint_internal(N, J, F, K:G, L, E);activate_constraint(N, J, F, O)), (N==yes->M, I;true)).
941 gen_insert_constraint_internal_goal(A/B, C, D, E, F) :-
942 vars_susp(B, E, F, D),
943 build_head(A, B, [0], D, G),
944 ( may_trigger(A/B)
945 -> make_name(attach_, A/B, H),
946 I=..[H, J, F]
947 ; I=true
949 get_target_module(K),
950 L=..[A|E],
951 generate_insert_constraint_call(A/B, F, M),
952 C= (insert_constraint_internal(N, J, F, K:G, L, E), M, I).
953 gen_uncond_attach_goal(A, B, C, D) :-
954 ( may_trigger(A)
955 -> make_name(attach_, A, E),
956 F=..[E, G, B]
957 ; F=true
959 generate_insert_constraint_call(A, B, H),
960 C= (activate_constraint(I, G, B, D), (I==yes->H, F;true)).
961 occurrences_code(A, B, C, D, E, F, G) :-
962 ( A>B
963 -> E=D,
965 ; occurrence_code(A, C, D, H, F, I),
966 J is A+1,
967 occurrences_code(J, B, C, H, E, I, G)
969 occurrences_code(A, B, C, D, E, F) :-
970 get_occurrence(B, A, G, H),
971 ( is_passive(G, H)
972 -> D=C,
974 ; get_rule(G, I),
975 I=pragma(rule(J, K, L, M), ids(N, O), P, Q, R),
976 ( select2(N, J, H, S, T, U)
977 -> D=C,
978 head1_code(S, U, T, I, B, C, E, F)
979 ; select2(O, K, H, V, W, X)
980 -> length(X, Y),
981 head2_code(V, X, W, I, Y, B, C, E, Z),
982 inc_id(C, D),
983 gen_alloc_inc_clause(B, C, Z, F)
986 rules_code([], A, B, B, C, C).
987 rules_code([A|B], C, D, E, F, G) :-
988 rule_code(A, C, D, H, F, I),
989 rules_code(B, C, H, E, I, G).
990 rule_code(A, B, C, D, E, F) :-
991 A=pragma(G, H, I, J, K),
992 H=ids(L, M),
993 G=rule(N, O, P, Q),
994 heads1_code(N, [], L, [], A, B, C, E, R),
995 heads2_code(O, [], M, [], A, B, C, D, R, F).
996 heads1_code([], A, B, C, D, E, F, G, G).
997 heads1_code([A|B], C, [D|E], F, G, H, I, J, K) :-
998 G=pragma(L, M, N, O, P),
999 get_constraint(Q/R, H),
1000 ( functor(A, Q, R),
1001 \+is_passive(P, D),
1002 \+check_unnecessary_active(A, C, L),
1003 all_attached(B),
1004 all_attached(C),
1005 L=rule(S, T, U, V),
1006 all_attached(T)
1007 -> append(B, C, W),
1008 append(E, F, X),
1009 head1_code(A, W, X, G, Q/R, H, I, J, Y)
1010 ; J=Y
1012 heads1_code(B, [A|C], E, [D|F], G, H, I, Y, K).
1013 head1_code(A, B, C, D, E, F, G, H, I) :-
1014 D=pragma(J, K, L, M, N),
1015 J=rule(O, P, Q, R),
1016 ( P==[]
1017 -> reorder_heads(N, A, B, C, S, T),
1018 simplification_code(A, S, T, D, E, G, H, I)
1019 ; simpagation_head1_code(A, B, C, D, E, G, H, I)
1021 heads2_code([], A, B, C, D, E, F, F, G, G).
1022 heads2_code([A|B], C, [D|E], F, G, H, I, J, K, L) :-
1023 G=pragma(M, N, O, P, Q),
1024 get_constraint(R/S, H),
1025 ( functor(A, R, S),
1026 \+is_passive(Q, D),
1027 \+check_unnecessary_active(A, C, M),
1028 \+set_semantics_rule(G),
1029 all_attached(B),
1030 all_attached(C),
1031 M=rule(T, U, V, W),
1032 all_attached(T)
1033 -> append(B, C, X),
1034 append(E, F, Y),
1035 length(B, Z),
1036 head2_code(A, X, Y, G, Z, R/S, I, K, A1),
1037 inc_id(I, B1),
1038 gen_alloc_inc_clause(R/S, I, A1, C1)
1039 ; K=C1,
1040 B1=I
1042 heads2_code(B, [A|C], E, [D|F], G, H, B1, J, C1, L).
1043 head2_code(A, B, C, D, E, F, G, H, I) :-
1044 D=pragma(J, K, L, M, N),
1045 J=rule(O, P, Q, R),
1046 ( O==[]
1047 -> reorder_heads(N, A, B, C, S, T),
1048 propagation_code(A, S, J, N, E, F, G, H, I)
1049 ; simpagation_head2_code(A, B, C, D, F, G, H, I)
1051 gen_alloc_inc_clause(A/B, C, D, E) :-
1052 vars_susp(B, F, G, H),
1053 build_head(A, B, C, H, I),
1054 inc_id(C, J),
1055 build_head(A, B, J, H, K),
1056 gen_allocation(C, F, G, A/B, H, L),
1057 M= (I:-L, K),
1058 D=[M|E].
1059 gen_cond_allocation(A, B, C, D, E) :-
1060 gen_allocation(A, B, C, D, F),
1061 E= (var(B)->F;true).
1062 gen_allocation(A, B, C/D, E, F) :-
1063 build_head(C, D, [0], E, G),
1064 get_target_module(H),
1065 I=..[C|A],
1066 F=allocate_constraint(H:G, B, I, A).
1067 gen_allocation(A, B, C, D, E, F) :-
1068 ( A==[0]
1069 -> ( is_attached(D)
1070 -> ( may_trigger(D)
1071 -> gen_cond_allocation(B, C, D, E, F)
1072 ; gen_allocation(B, C, D, E, F)
1074 ; F=true
1076 ; F=true
1078 guard_via_reschedule(A, B, C, D) :-
1079 ( chr_pp_flag(guard_via_reschedule, on)
1080 -> guard_via_reschedule_main(A, B, C, D)
1081 ; append(A, B, E),
1082 list2conj(E, D)
1084 guard_via_reschedule_main(A, B, C, D) :-
1085 initialize_unit_dictionary(C, E),
1086 build_units(A, B, E, F),
1087 dependency_reorder(F, G),
1088 units2goal(G, D).
1089 units2goal([], true).
1090 units2goal([unit(A, B, C, D)|E], (B, F)) :-
1091 units2goal(E, F).
1092 dependency_reorder(A, B) :-
1093 dependency_reorder(A, [], B).
1094 dependency_reorder([], A, B) :-
1095 reverse(A, B).
1096 dependency_reorder([A|B], C, D) :-
1097 A=unit(E, F, G, H),
1098 ( G==fixed
1099 -> I=[A|C]
1100 ; dependency_insert(C, A, H, I)
1102 dependency_reorder(B, I, D).
1103 dependency_insert([], A, B, [A]).
1104 dependency_insert([A|B], C, D, E) :-
1105 A=unit(F, G, H, I),
1106 ( memberchk(F, D)
1107 -> E=[C, A|B]
1108 ; E=[A|J],
1109 dependency_insert(B, C, D, J)
1111 build_units(A, B, C, D) :-
1112 build_retrieval_units(A, 1, E, C, F, D, G),
1113 build_guard_units(B, E, F, G).
1114 build_retrieval_units([], A, A, B, B, C, C).
1115 build_retrieval_units([A|B], C, D, E, F, G, H) :-
1116 term_variables(A, I),
1117 update_unit_dictionary(I, C, E, J, [], K),
1118 G=[unit(C, A, movable, K)|L],
1119 M is C+1,
1120 build_retrieval_units2(B, M, D, J, F, L, H).
1121 build_retrieval_units2([], A, A, B, B, C, C).
1122 build_retrieval_units2([A|B], C, D, E, F, G, H) :-
1123 term_variables(A, I),
1124 update_unit_dictionary(I, C, E, J, [], K),
1125 G=[unit(C, A, fixed, K)|L],
1126 M is C+1,
1127 build_retrieval_units(B, M, D, J, F, L, H).
1128 initialize_unit_dictionary(A, B) :-
1129 term_variables(A, C),
1130 pair_all_with(C, 0, B).
1131 update_unit_dictionary([], A, B, B, C, C).
1132 update_unit_dictionary([A|B], C, D, E, F, G) :-
1133 ( lookup_eq(D, A, H)
1134 -> ( ( H==C
1135 ; memberchk(H, F)
1137 -> I=F
1138 ; I=[H|F]
1141 ; J=[A-C|D],
1144 update_unit_dictionary(B, C, J, E, I, G).
1145 build_guard_units(A, B, C, D) :-
1146 ( A=[E]
1147 -> D=[unit(B, E, fixed, [])]
1148 ; A=[E|F]
1149 -> term_variables(E, G),
1150 update_unit_dictionary2(G, B, C, H, [], I),
1151 D=[unit(B, E, movable, I)|J],
1152 K is B+1,
1153 build_guard_units(F, K, H, J)
1155 update_unit_dictionary2([], A, B, B, C, C).
1156 update_unit_dictionary2([A|B], C, D, E, F, G) :-
1157 ( lookup_eq(D, A, H)
1158 -> ( ( H==C
1159 ; memberchk(H, F)
1161 -> I=F
1162 ; I=[H|F]
1164 J=[A-C|D]
1165 ; J=[A-C|D],
1168 update_unit_dictionary2(B, C, J, E, I, G).
1169 unique_analyse_optimise(A, B) :-
1170 ( chr_pp_flag(unique_analyse_optimise, on)
1171 -> unique_analyse_optimise_main(A, 1, [], B)
1172 ; B=A
1174 unique_analyse_optimise_main([], A, B, []).
1175 unique_analyse_optimise_main([A|B], C, D, [E|F]) :-
1176 ( discover_unique_pattern(A, C, G)
1177 -> H=[G|D]
1178 ; H=D
1180 A=pragma(I, J, K, L, M),
1181 I=rule(N, O, P, Q),
1182 J=ids(R, S),
1183 apply_unique_patterns_to_constraints(N, R, H, T),
1184 apply_unique_patterns_to_constraints(O, S, H, U),
1185 globalize_unique_pragmas(T, M),
1186 globalize_unique_pragmas(U, M),
1187 append_lists([T, U, K], V),
1188 E=pragma(I, J, V, L, M),
1189 W is C+1,
1190 unique_analyse_optimise_main(B, W, H, F).
1191 globalize_unique_pragmas([], A).
1192 globalize_unique_pragmas([unique(A, B)|C], D) :-
1193 pragma_unique(D, A, B),
1194 globalize_unique_pragmas(C, D).
1195 apply_unique_patterns_to_constraints([], A, B, []).
1196 apply_unique_patterns_to_constraints([A|B], [C|D], E, F) :-
1197 ( member(G, E),
1198 apply_unique_pattern(A, C, G, H)
1199 -> F=[H|I]
1200 ; F=I
1202 apply_unique_patterns_to_constraints(B, D, E, I).
1203 apply_unique_pattern(A, B, C, D) :-
1204 C=unique(E, F),
1205 subsumes(A, E, G),
1206 ( setof(H, I^J^K^ (member(I, F), lookup_eq(G, I, J), term_variables(J, K), member(H, K)), L)
1207 -> true
1208 ; L=[]
1210 D=unique(B, L).
1211 subsumes(A, B, C) :-
1212 empty_assoc(D),
1213 subsumes_aux(A, B, D, E),
1214 assoc_to_list(E, F),
1215 build_unifier(F, C).
1216 subsumes_aux(A, B, C, D) :-
1217 ( compound(B),
1218 functor(B, E, F)
1219 -> compound(A),
1220 functor(A, E, F),
1221 subsumes_aux(F, A, B, C, D)
1222 ; A==B
1223 -> D=C
1224 ; var(B),
1225 get_assoc(A, C, G)
1226 -> G==B,
1228 ; var(B),
1229 put_assoc(A, C, B, D)
1231 subsumes_aux(0, A, B, C, C) :- !.
1232 subsumes_aux(A, B, C, D, E) :-
1233 arg(A, B, F),
1234 arg(A, C, G),
1235 subsumes_aux(F, G, D, H),
1236 I is A-1,
1237 subsumes_aux(I, B, C, H, E).
1238 build_unifier([], []).
1239 build_unifier([A-B|C], [B-A|D]) :-
1240 build_unifier(C, D).
1241 discover_unique_pattern(A, B, C) :-
1242 A=pragma(D, E, F, G, B),
1243 D=rule(H, I, J, K),
1244 ( H=[L],
1245 I=[M]
1246 -> true
1247 ; H=[L, M],
1248 I==[]
1249 -> true
1251 check_unique_constraints(L, M, J, B, N),
1252 term_variables(L, O),
1253 select_pragma_unique_variables(N, O, P),
1254 Q=unique(L, P),
1255 copy_term(Q, C),
1256 ( prolog_flag(verbose, R),
1257 R==yes
1258 -> format('Found unique pattern ~w in rule ~d~@\n', [C, B, (G=yes(S)->write([58, 32]), write(S);true)])
1259 ; true
1261 select_pragma_unique_variables([], A, []).
1262 select_pragma_unique_variables([A-B|C], D, E) :-
1263 ( A==B
1264 -> E=[A|F]
1265 ; once((
1266 ( \+memberchk_eq(A, D)
1267 ; \+memberchk_eq(B, D)
1272 select_pragma_unique_variables(C, D, F).
1273 check_unique_constraints(A, B, C, D, E) :-
1274 \+any_passive_head(D),
1275 variable_replacement(A-B, B-A, E),
1276 copy_with_variable_replacement(C, F, E),
1277 negate_b(C, G),
1278 once(entails_b(G, F)).
1279 check_unnecessary_active(A, B, C) :-
1280 ( chr_pp_flag(check_unnecessary_active, full)
1281 -> check_unnecessary_active_main(A, B, C)
1282 ; chr_pp_flag(check_unnecessary_active, simplification),
1283 C=rule(D, [], E, F)
1284 -> check_unnecessary_active_main(A, B, C)
1285 ; fail
1287 check_unnecessary_active_main(A, B, C) :-
1288 member(D, B),
1289 variable_replacement(D, A, E),
1290 copy_with_variable_replacement(C, F, E),
1291 identical_rules(C, F), !.
1292 set_semantics_rule(A) :-
1293 ( chr_pp_flag(set_semantics_rule, on)
1294 -> set_semantics_rule_main(A)
1295 ; fail
1297 set_semantics_rule_main(A) :-
1298 A=pragma(B, C, D, E, F),
1299 B=rule([G], [H], true, I),
1300 C=ids([J], [K]),
1301 once(member(unique(J, L), D)),
1302 once(member(unique(K, M), D)),
1303 L==M,
1304 \+is_passive(F, J).
1305 identical_rules(rule(A, B, C, D), rule(E, F, G, H)) :-
1306 C==G,
1307 identical_bodies(D, H),
1308 permutation(A, I),
1309 I==E,
1310 permutation(B, J),
1311 J==F.
1312 identical_bodies(A, B) :-
1313 ( A= (C=D),
1314 B= (E=F)
1315 -> ( C==E,
1316 D==F
1317 ; C==F,
1318 E==D
1319 ), !
1320 ; A==B
1322 copy_with_variable_replacement(A, B, C) :-
1323 ( var(A)
1324 -> ( lookup_eq(C, A, B)
1325 -> true
1326 ; A=B
1328 ; functor(A, D, E),
1329 functor(B, D, E),
1330 A=..[F|G],
1331 B=..[H|I],
1332 copy_with_variable_replacement_l(G, I, C)
1334 copy_with_variable_replacement_l([], [], A).
1335 copy_with_variable_replacement_l([A|B], [C|D], E) :-
1336 copy_with_variable_replacement(A, C, E),
1337 copy_with_variable_replacement_l(B, D, E).
1338 variable_replacement(A, B, C) :-
1339 variable_replacement(A, B, [], C).
1340 variable_replacement(A, B, C, D) :-
1341 ( var(A)
1342 -> var(B),
1343 ( lookup_eq(C, A, E)
1344 -> E==B,
1346 ; D=[A-B|C]
1348 ; A=..[F|G],
1349 nonvar(B),
1350 B=..[F|H],
1351 variable_replacement_l(G, H, C, D)
1353 variable_replacement_l([], [], A, A).
1354 variable_replacement_l([A|B], [C|D], E, F) :-
1355 variable_replacement(A, C, E, G),
1356 variable_replacement_l(B, D, G, F).
1357 simplification_code(A, B, C, D, E/F, G, H, I) :-
1358 D=pragma(J, K, L, M, N),
1359 head_info(A, F, O, P, Q, R),
1360 build_head(E, F, G, Q, S),
1361 head_arg_matches(R, [], T, U),
1362 ( B==[]
1363 -> V=[],
1364 W=U,
1365 X=[]
1366 ; rest_heads_retrieval_and_matching(B, C, L, A, X, V, U, W)
1368 guard_body_copies2(J, W, Y, Z),
1369 guard_via_reschedule(X, Y, S-T, A1),
1370 gen_uncond_susps_detachments(V, B, B1),
1371 gen_cond_susp_detachment(G, P, E/F, C1),
1372 ( chr_pp_flag(debugable, on)
1373 -> J=rule(D1, E1, F1, G1),
1374 my_term_copy(F1-G1, W, H1, I1-J1),
1375 K1='chr debug_event'(try([P|L1], [], I1, J1)),
1376 M1='chr debug_event'(apply([P|L1], [], I1, J1))
1377 ; K1=true,
1378 M1=true
1380 N1= (S:-T, A1, K1, !, M1, B1, C1, Z),
1381 H=[N1|I].
1382 head_arg_matches(A, B, C, D) :-
1383 head_arg_matches_(A, B, E, D),
1384 list2conj(E, C).
1385 head_arg_matches_([], A, [], A).
1386 head_arg_matches_([A-B|C], D, E, F) :-
1387 ( var(A)
1388 -> ( lookup_eq(D, A, G)
1389 -> E=[B==G|H],
1391 ; I=[A-B|D],
1395 ; atomic(A)
1396 -> E=[B==A|H],
1397 D=I,
1399 ; A=..[K|L],
1400 functor(A, M, N),
1401 functor(O, M, N),
1402 O=..[P|Q],
1403 E=[nonvar(B), B=O|H],
1404 pairup(L, Q, R),
1405 append(R, C, J),
1408 head_arg_matches_(J, I, H, F).
1409 rest_heads_retrieval_and_matching(A, B, C, D, E, F, G, H) :-
1410 rest_heads_retrieval_and_matching(A, B, C, D, E, F, G, H, [], [], []).
1411 rest_heads_retrieval_and_matching(A, B, C, D, E, F, G, H, I, J, K) :-
1412 ( A=[L|M]
1413 -> rest_heads_retrieval_and_matching_n(A, B, C, I, J, D, E, F, G, H, K)
1414 ; E=[],
1415 F=[],
1418 rest_heads_retrieval_and_matching_n([], A, B, C, D, E, [], [], F, F, G) :-
1419 instantiate_pattern_goals(G).
1420 rest_heads_retrieval_and_matching_n([A|B], [C|D], E, F, G, H, [I, J|K], [L|M], N, O, P) :-
1421 functor(A, Q, R),
1422 get_store_type(Q/R, S),
1423 ( S==default
1424 -> passive_head_via(A, [H|F], P, N, I, T, U),
1425 get_max_constraint_index(V),
1426 ( V==1
1427 -> W=T
1428 ; get_constraint_index(Q/R, X),
1429 make_attr(V, Y, Z, T),
1430 nth(X, Z, W)
1432 ; lookup_passive_head(S, A, [H|F], N, I, W),
1435 head_info(A, R, A1, B1, C1, D1),
1436 head_arg_matches(D1, N, E1, F1),
1437 G1=..[suspension, H1, I1, J1, K1, L1, M1|A1],
1438 different_from_other_susps(A, L, F, G, N1),
1439 create_get_mutable(active, I1, O1),
1440 P1= ('chr sbag_member'(L, W), L=G1, O1, N1, E1),
1441 ( member(unique(C, Q1), E),
1442 check_unique_keys(Q1, N)
1443 -> J= (P1->true)
1444 ; J=P1
1446 rest_heads_retrieval_and_matching_n(B, D, E, [A|F], [L|G], H, K, M, F1, O, U).
1447 instantiate_pattern_goals([]).
1448 instantiate_pattern_goals([A-attr(B, C, D)|E]) :-
1449 get_max_constraint_index(F),
1450 ( F==1
1451 -> D=true
1452 ; make_attr(F, G, H, B),
1453 or_list(C, I), !,
1454 D= (G/\I=:=I)
1456 instantiate_pattern_goals(E).
1457 check_unique_keys([], A).
1458 check_unique_keys([A|B], C) :-
1459 lookup_eq(C, A, D),
1460 check_unique_keys(B, C).
1461 different_from_other_susps(A, B, C, D, E) :-
1462 ( bagof(F, G^ (nth(G, C, H), \+A\=H, nth(G, D, I), F= (B\==I)), J)
1463 -> list2conj(J, E)
1464 ; E=true
1466 passive_head_via(A, B, C, D, E, F, G) :-
1467 functor(A, H, I),
1468 get_constraint_index(H/I, J),
1469 common_variables(A, B, K),
1470 translate(K, D, L),
1471 or_pattern(J, M),
1472 ( permutation(L, N),
1473 lookup_eq(C, N, attr(F, O, P))
1474 -> member(M, O), !,
1475 G=C,
1476 E=true
1477 ; E= (Q, R),
1478 gen_get_mod_constraints(L, Q, F),
1479 G=[L-attr(F, [M|S], R)|C]
1481 common_variables(A, B, C) :-
1482 term_variables(A, D),
1483 term_variables(B, E),
1484 intersect_eq(D, E, C).
1485 gen_get_mod_constraints(A, B, C) :-
1486 get_target_module(D),
1487 ( A==[]
1488 -> B= ('chr global_term_ref_1'(E), get_attr(E, D, F), F=C)
1489 ; ( A=[G]
1490 -> H='chr via_1'(G, I)
1491 ; A=[G, J]
1492 -> H='chr via_2'(G, J, I)
1493 ; H='chr via'(A, I)
1495 B= (H, get_attr(I, D, F), F=C)
1497 guard_body_copies(A, B, C, D) :-
1498 guard_body_copies2(A, B, E, D),
1499 list2conj(E, C).
1500 guard_body_copies2(A, B, C, D) :-
1501 A=rule(E, F, G, H),
1502 conj2list(G, I),
1503 split_off_simple_guard(I, B, J, K),
1504 my_term_copy(J-K, B, L, M-N),
1505 append(M, [O], C),
1506 term_variables(K, P),
1507 term_variables(N, Q),
1508 ( chr_pp_flag(guard_locks, on),
1509 bagof('chr lock'(R)-'chr unlock'(R), S^ (member(S, P), lookup_eq(B, S, R), memberchk_eq(R, Q)), T)
1510 -> once(pairup(U, V, T))
1511 ; U=[],
1512 V=[]
1514 list2conj(U, W),
1515 list2conj(V, X),
1516 list2conj(N, Y),
1517 O= (W, Y, X),
1518 my_term_copy(H, L, D).
1519 split_off_simple_guard([], A, [], []).
1520 split_off_simple_guard([A|B], C, D, E) :-
1521 ( simple_guard(A, C)
1522 -> D=[A|F],
1523 split_off_simple_guard(B, C, F, E)
1524 ; D=[],
1525 E=[A|B]
1527 simple_guard(A, B) :-
1528 binds_b(A, C),
1529 \+((
1530 member(D, C),
1531 lookup_eq(B, D, E)
1533 my_term_copy(A, B, C) :-
1534 my_term_copy(A, B, D, C).
1535 my_term_copy(A, B, C, D) :-
1536 ( var(A)
1537 -> ( lookup_eq(B, A, D)
1538 -> C=B
1539 ; C=[A-D|B]
1541 ; functor(A, E, F),
1542 functor(D, E, F),
1543 A=..[G|H],
1544 D=..[I|J],
1545 my_term_copy_list(H, B, C, J)
1547 my_term_copy_list([], A, A, []).
1548 my_term_copy_list([A|B], C, D, [E|F]) :-
1549 my_term_copy(A, C, G, E),
1550 my_term_copy_list(B, G, D, F).
1551 gen_cond_susp_detachment(A, B, C, D) :-
1552 ( is_attached(C)
1553 -> ( A==[0],
1554 \+may_trigger(C)
1555 -> D=true
1556 ; gen_uncond_susp_detachment(B, C, E),
1557 D= (var(B)->true;E)
1559 ; D=true
1561 gen_uncond_susp_detachment(A, B, C) :-
1562 ( is_attached(B)
1563 -> ( may_trigger(B)
1564 -> make_name(detach_, B, D),
1565 E=..[D, F, A]
1566 ; E=true
1568 ( chr_pp_flag(debugable, on)
1569 -> G='chr debug_event'(remove(A))
1570 ; G=true
1572 generate_delete_constraint_call(B, A, H),
1573 C= (G, remove_constraint_internal(A, F, I), (I==yes->H, E;true))
1574 ; C=true
1576 gen_uncond_susps_detachments([], [], true).
1577 gen_uncond_susps_detachments([A|B], [C|D], (E, F)) :-
1578 functor(C, G, H),
1579 gen_uncond_susp_detachment(A, G/H, E),
1580 gen_uncond_susps_detachments(B, D, F).
1581 simpagation_head1_code(A, B, C, D, E/F, G, H, I) :-
1582 D=pragma(J, ids(K, L), M, N, O),
1583 J=rule(P, Q, R, S),
1584 head_info(A, F, T, U, V, W),
1585 head_arg_matches(W, [], X, Y),
1586 build_head(E, F, G, V, Z),
1587 append(B, Q, A1),
1588 append(C, L, B1),
1589 reorder_heads(O, A, A1, B1, C1, D1),
1590 rest_heads_retrieval_and_matching(C1, D1, M, A, E1, F1, Y, G1),
1591 split_by_ids(D1, F1, C, H1, I1),
1592 guard_body_copies2(J, G1, J1, K1),
1593 guard_via_reschedule(E1, J1, Z-X, L1),
1594 gen_uncond_susps_detachments(H1, B, M1),
1595 gen_cond_susp_detachment(G, U, E/F, N1),
1596 ( chr_pp_flag(debugable, on)
1597 -> my_term_copy(R-S, G1, O1, P1-Q1),
1598 R1='chr debug_event'(try([U|H1], I1, P1, Q1)),
1599 S1='chr debug_event'(apply([U|H1], I1, P1, Q1))
1600 ; R1=true,
1601 S1=true
1603 T1= (Z:-X, L1, R1, !, S1, M1, N1, K1),
1604 H=[T1|I].
1605 split_by_ids([], [], A, [], []).
1606 split_by_ids([A|B], [C|D], E, F, G) :-
1607 ( memberchk_eq(A, E)
1608 -> F=[C|H],
1610 ; F=H,
1611 G=[C|I]
1613 split_by_ids(B, D, E, H, I).
1614 simpagation_head2_code(A, B, C, D, E, F, G, H) :-
1615 D=pragma(I, ids(J, K), L, M, N),
1616 I=rule(O, P, Q, R),
1617 reorder_heads(N, A, O, J, [S|T], [U|V]),
1618 simpagation_head2_prelude(A, S, [B, O, Q, R], E, F, G, W),
1619 extend_id(F, X),
1620 simpagation_head2_worker(A, S, U, T, V, B, C, D, E, X, W, H).
1621 simpagation_head2_prelude(A, B, C, D/E, F, G, H) :-
1622 head_info(A, E, I, J, K, L),
1623 build_head(D, E, F, K, M),
1624 head_arg_matches(L, [], N, O),
1625 lookup_passive_head(B, [A], O, P, Q),
1626 gen_allocation(F, I, J, D/E, K, R),
1627 extend_id(F, S),
1628 extra_active_delegate_variables(A, C, O, T),
1629 append([Q|K], T, U),
1630 build_head(D, E, S, U, V),
1631 W= (M:-N, P, !, R, V),
1632 G=[W|H].
1633 extra_active_delegate_variables(A, B, C, D) :-
1634 A=..[E|F],
1635 delegate_variables(A, B, C, F, D).
1636 passive_delegate_variables(A, B, C, D, E) :-
1637 term_variables(B, F),
1638 delegate_variables(A, C, D, F, E).
1639 delegate_variables(A, B, C, D, E) :-
1640 term_variables(A, F),
1641 term_variables(B, G),
1642 intersect_eq(F, G, H),
1643 list_difference_eq(H, D, I),
1644 translate(I, C, E).
1645 simpagation_head2_worker(A, B, C, D, E, F, G, H, I, J, K, L) :-
1646 H=pragma(M, N, O, P, Q),
1647 M=rule(R, S, T, U),
1648 simpagation_head2_worker_end(A, [B, D, F, T, U], I, J, K, V),
1649 simpagation_head2_worker_body(A, B, C, D, E, F, G, H, I, J, V, L).
1650 simpagation_head2_worker_body(A, B, C, D, E, F, G, H, I/J, K, L, M) :-
1651 gen_var(N),
1652 gen_var(O),
1653 head_info(A, J, P, Q, R, S),
1654 head_arg_matches(S, [], T, U),
1655 H=pragma(V, W, X, Y, Z),
1656 V=rule(A1, B1, C1, D1),
1657 extra_active_delegate_variables(A, [B, D, F, C1, D1], U, E1),
1658 append([[N|O]|R], E1, F1),
1659 build_head(I, J, K, F1, G1),
1660 functor(B, H1, I1),
1661 head_info(B, I1, J1, K1, L1, M1),
1662 head_arg_matches(M1, U, N1, O1),
1663 P1=..[suspension, Q1, R1, S1, T1, U1, V1|J1],
1664 create_get_mutable(active, R1, W1),
1665 X1= (N=P1, W1),
1666 ( ( D\==[]
1667 ; F\==[]
1669 -> append(D, F, Y1),
1670 append(E, G, Z1),
1671 reorder_heads(Z, B-A, Y1, Z1, A2, B2),
1672 rest_heads_retrieval_and_matching(A2, B2, X, [B, A], C2, D2, O1, E2, [B], [N], []),
1673 split_by_ids(B2, D2, E, F2, G2)
1674 ; C2=[],
1675 F2=[],
1676 G2=[],
1677 E2=O1
1679 gen_uncond_susps_detachments([N|F2], [B|D], H2),
1680 append([O|R], E1, I2),
1681 build_head(I, J, K, I2, J2),
1682 append([[]|R], E1, K2),
1683 build_head(I, J, K, K2, L2),
1684 guard_body_copies2(V, E2, M2, N2),
1685 guard_via_reschedule(C2, M2, v(G1, X1, N1), O2),
1686 ( N2\==true
1687 -> gen_uncond_attach_goal(I/J, Q, P2, Q2),
1688 gen_state_cond_call(Q, J, J2, Q2, R2),
1689 gen_state_cond_call(Q, J, L2, Q2, S2)
1690 ; P2=true,
1691 R2=J2,
1692 S2=L2
1694 ( chr_pp_flag(debugable, on)
1695 -> my_term_copy(C1-D1, E2, T2, U2-V2),
1696 W2='chr debug_event'(try([N|F2], [Q|G2], U2, V2)),
1697 X2='chr debug_event'(apply([N|F2], [Q|G2], U2, V2))
1698 ; W2=true,
1699 X2=true
1701 ( member(unique(C, Y2), X),
1702 check_unique_keys(Y2, U)
1703 -> Z2= (G1:-X1, N1-> (O2, W2->X2, H2, P2, N2, S2;L2);J2)
1704 ; Z2= (G1:-X1, N1, O2, W2->X2, H2, P2, N2, R2;J2)
1706 L=[Z2|M].
1707 gen_state_cond_call(A, B, C, D, E) :-
1708 length(F, B),
1709 G=..[suspension, H, I, J, K, L, M|F],
1710 create_get_mutable(active, I, N),
1711 create_get_mutable(D, K, O),
1712 E= (A=G, N, O->'chr update_mutable'(inactive, I), C;true).
1713 simpagation_head2_worker_end(A, B, C/D, E, F, G) :-
1714 head_info(A, D, H, I, J, K),
1715 head_arg_matches(K, [], L, M),
1716 extra_active_delegate_variables(A, B, M, N),
1717 append([[]|J], N, O),
1718 build_head(C, D, E, O, P),
1719 next_id(E, Q),
1720 build_head(C, D, Q, J, R),
1721 S= (P:-R),
1722 F=[S|G].
1723 propagation_code(A, B, C, D, E, F, G, H, I) :-
1724 ( B==[]
1725 -> propagation_single_headed(A, C, D, F, G, H, I)
1726 ; propagation_multi_headed(A, B, C, D, E, F, G, H, I)
1728 propagation_single_headed(A, B, C, D/E, F, G, H) :-
1729 head_info(A, E, I, J, K, L),
1730 build_head(D, E, F, K, M),
1731 inc_id(F, N),
1732 build_head(D, E, N, K, O),
1733 P=O,
1734 head_arg_matches(L, [], Q, R),
1735 guard_body_copies(B, R, S, T),
1736 gen_allocation(F, I, J, D/E, K, U),
1737 gen_uncond_attach_goal(D/E, J, V, W),
1738 gen_state_cond_call(J, E, P, W, X),
1739 ( chr_pp_flag(debugable, on)
1740 -> B=rule(Y, Z, A1, B1),
1741 my_term_copy(A1-B1, R, C1, D1-E1),
1742 F1='chr debug_event'(try([], [J], D1, E1)),
1743 G1='chr debug_event'(apply([], [J], D1, E1))
1744 ; F1=true,
1745 G1=true
1747 H1= (M:-Q, U, 'chr novel_production'(J, C), S, F1, !, G1, 'chr extend_history'(J, C), V, T, X),
1748 G=[H1|H].
1749 propagation_multi_headed(A, B, C, D, E, F, G, H, I) :-
1750 B=[J|K],
1751 propagation_prelude(A, B, C, F, G, H, L),
1752 extend_id(G, M),
1753 propagation_nested_code(K, [J, A], C, D, E, F, M, L, I).
1754 propagation_prelude(A, [B|C], D, E/F, G, H, I) :-
1755 head_info(A, F, J, K, L, M),
1756 build_head(E, F, G, L, N),
1757 head_arg_matches(M, [], O, P),
1758 D=rule(Q, R, S, T),
1759 extra_active_delegate_variables(A, [B, C, S, T], P, U),
1760 lookup_passive_head(B, [A], P, V, W),
1761 gen_allocation(G, J, K, E/F, L, X),
1762 extend_id(G, Y),
1763 append([W|L], U, Z),
1764 build_head(E, F, Y, Z, A1),
1765 B1=A1,
1766 C1= (N:-O, V, !, X, B1),
1767 H=[C1|I].
1768 propagation_nested_code([], [A|B], C, D, E, F, G, H, I) :-
1769 propagation_end([A|B], [], C, F, G, H, J),
1770 propagation_body(A, B, C, D, E, F, G, J, I).
1771 propagation_nested_code([A|B], C, D, E, F, G, H, I, J) :-
1772 propagation_end(C, [A|B], D, G, H, I, K),
1773 propagation_accumulator([A|B], C, D, G, H, K, L),
1774 inc_id(H, M),
1775 propagation_nested_code(B, [A|C], D, E, F, G, M, L, J).
1776 propagation_body(A, B, C, D, E, F/G, H, I, J) :-
1777 C=rule(K, L, M, N),
1778 get_prop_inner_loop_vars(B, [A, M, N], O, P, Q, R),
1779 gen_var(S),
1780 gen_var(T),
1781 functor(A, U, V),
1782 gen_vars(V, W),
1783 X=..[suspension, Y, Z, A1, B1, C1, D1|W],
1784 create_get_mutable(active, Z, E1),
1785 F1= (S=X, E1),
1786 G1=[[S|T]|O],
1787 build_head(F, G, H, G1, H1),
1788 I1=[T|O],
1789 build_head(F, G, H, I1, J1),
1790 K1=J1,
1791 A=..[L1|M1],
1792 pairup(M1, W, N1),
1793 head_arg_matches(N1, P, O1, P1),
1794 different_from_other_susps(A, S, B, R, Q1),
1795 guard_body_copies(C, P1, R1, S1),
1796 gen_uncond_attach_goal(F/G, Q, T1, U1),
1797 gen_state_cond_call(Q, G, K1, U1, V1),
1798 history_susps(E, [S|R], Q, [], W1),
1799 bagof('chr novel_production'(X1, Y1), (member(X1, W1), Y1=Z1), A2),
1800 list2conj(A2, B2),
1801 C2=..[t, D|W1],
1802 ( chr_pp_flag(debugable, on)
1803 -> C=rule(D2, E2, M, N),
1804 my_term_copy(M-N, P1, F2, G2-H2),
1805 I2='chr debug_event'(try([], [Q, S|R], G2, H2)),
1806 J2='chr debug_event'(apply([], [Q, S|R], G2, H2))
1807 ; I2=true,
1808 J2=true
1810 K2= (H1:-F1, Q1, O1, Z1=C2, B2, R1, I2->J2, 'chr extend_history'(Q, Z1), T1, S1, V1;K1),
1811 I=[K2|J].
1812 history_susps(A, B, C, D, E) :-
1813 ( A==0
1814 -> reverse(B, F),
1815 append(F, [C|D], E)
1816 ; B=[G|H],
1817 I is A-1,
1818 history_susps(I, H, C, [G|D], E)
1820 get_prop_inner_loop_vars([A], B, C, D, E, []) :- !,
1821 functor(A, F, G),
1822 head_info(A, G, H, E, I, J),
1823 head_arg_matches(J, [], K, D),
1824 extra_active_delegate_variables(A, B, D, L),
1825 append(I, L, C).
1826 get_prop_inner_loop_vars([A|B], C, D, E, F, [G|H]) :-
1827 get_prop_inner_loop_vars(B, [A|C], I, J, F, H),
1828 functor(A, K, L),
1829 gen_var(M),
1830 head_info(A, L, N, G, O, P),
1831 head_arg_matches(P, J, Q, E),
1832 passive_delegate_variables(A, B, C, E, R),
1833 append(R, [G, M|I], D).
1834 propagation_end([A|B], C, D, E/F, G, H, I) :-
1835 D=rule(J, K, L, M),
1836 gen_var_susp_list_for(B, [A, C, L, M], N, O, P, Q),
1837 R=[[]|O],
1838 build_head(E, F, G, R, S),
1839 ( G=[0|T]
1840 -> next_id(G, U),
1842 ; dec_id(G, U),
1843 V=[Q|P]
1845 build_head(E, F, U, V, W),
1846 X=W,
1847 Y= (S:-X),
1848 H=[Y|I].
1849 gen_var_susp_list_for([A], B, C, D, E, F) :- !,
1850 functor(A, G, H),
1851 head_info(A, H, I, F, E, J),
1852 head_arg_matches(J, [], K, C),
1853 extra_active_delegate_variables(A, B, C, L),
1854 append(E, L, D).
1855 gen_var_susp_list_for([A|B], C, D, E, F, G) :-
1856 gen_var_susp_list_for(B, [A|C], H, F, I, J),
1857 functor(A, K, L),
1858 gen_var(G),
1859 head_info(A, L, M, N, O, P),
1860 head_arg_matches(P, H, Q, D),
1861 passive_delegate_variables(A, B, C, D, R),
1862 append(R, [N, G|F], E).
1863 propagation_accumulator([A|B], [C|D], E, F/G, H, I, J) :-
1864 E=rule(K, L, M, N),
1865 pre_vars_and_susps(D, [C, A, B, M, N], O, P, Q),
1866 gen_var(R),
1867 functor(C, S, T),
1868 gen_vars(T, U),
1869 head_info(C, T, U, V, W, X),
1870 head_arg_matches(X, P, Y, Z),
1871 A1=..[suspension, B1, C1, D1, E1, F1, G1|U],
1872 different_from_other_susps(C, V, D, Q, H1),
1873 create_get_mutable(active, C1, I1),
1874 J1= (V=A1, I1, H1, Y),
1875 lookup_passive_head(A, [C|D], Z, K1, L1),
1876 inc_id(H, M1),
1877 N1=[[V|R]|O],
1878 build_head(F, G, H, N1, O1),
1879 passive_delegate_variables(C, D, [A, B, M, N], Z, P1),
1880 append([L1|P1], [V, R|O], Q1),
1881 build_head(F, G, M1, Q1, R1),
1882 S1=[R|O],
1883 build_head(F, G, H, S1, T1),
1884 U1= (O1:-J1, K1->R1;T1),
1885 I=[U1|J].
1886 pre_vars_and_susps([A], B, C, D, []) :- !,
1887 functor(A, E, F),
1888 head_info(A, F, G, H, I, J),
1889 head_arg_matches(J, [], K, D),
1890 extra_active_delegate_variables(A, B, D, L),
1891 append(I, L, C).
1892 pre_vars_and_susps([A|B], C, D, E, [F|G]) :-
1893 pre_vars_and_susps(B, [A|C], H, I, G),
1894 functor(A, J, K),
1895 gen_var(L),
1896 head_info(A, K, M, F, N, O),
1897 head_arg_matches(O, I, P, E),
1898 passive_delegate_variables(A, B, C, E, Q),
1899 append(Q, [F, L|H], D).
1900 reorder_heads(A, B, C, D, E, F) :-
1901 ( chr_pp_flag(reorder_heads, on)
1902 -> reorder_heads_main(A, B, C, D, E, F)
1903 ; E=C,
1906 reorder_heads_main(A, B, C, D, E, F) :-
1907 term_variables(B, G),
1908 H=entry([], [], G, C, D, A),
1909 a_star(H, I^ (chr_translate:final_data(I)), J^K^L^ (chr_translate:expand_data(J, K, L)), M),
1910 M=entry(N, O, P, Q, R, S),
1911 reverse(N, E),
1912 reverse(O, F).
1913 final_data(A) :-
1914 A=entry(B, C, D, E, [], F).
1915 expand_data(A, B, C) :-
1916 A=entry(D, E, F, G, H, I),
1917 term_variables(A, J),
1918 B=entry([K|D], [L|E], M, N, O, I),
1919 select2(K, L, G, H, N, O),
1920 order_score(K, L, F, N, I, C),
1921 term_variables([K|F], M).
1922 order_score(A, B, C, D, E, F) :-
1923 functor(A, G, H),
1924 get_store_type(G/H, I),
1925 order_score(I, A, B, C, D, E, F).
1926 order_score(default, A, B, C, D, E, F) :-
1927 term_variables(A, G),
1928 term_variables(D, H),
1929 order_score_vars(G, C, D, 0, F).
1930 order_score(multi_hash(A), B, C, D, E, F, G) :-
1931 order_score_indexes(A, B, D, 0, G).
1932 order_score(global_ground, A, B, C, D, E, F) :-
1933 functor(A, G, H),
1934 ( get_pragma_unique(E, B, I),
1935 I==[]
1936 -> F=1
1937 ; H==0
1938 -> F=10
1939 ; H>0
1940 -> F=100
1942 order_score(multi_store(A), B, C, D, E, F, G) :-
1943 find_with_var_identity(H, t(B, D, E), (member(I, A), chr_translate:order_score(I, B, C, D, E, F, H)), J),
1944 min_list(J, G).
1945 order_score_indexes([], A, B, C, C) :-
1946 C>0.
1947 order_score_indexes([A|B], C, D, E, F) :-
1948 multi_hash_key_args(A, C, G),
1949 ( forall(H, G, hprolog:memberchk_eq(H, D))
1950 -> I is E+10
1951 ; I=E
1953 order_score_indexes(B, C, D, I, F).
1954 order_score_vars([], A, B, C, D) :-
1955 ( C==0
1956 -> D=0
1957 ; D=C
1959 order_score_vars([A|B], C, D, E, F) :-
1960 ( memberchk_eq(A, C)
1961 -> G is E+10
1962 ; memberchk_eq(A, D)
1963 -> G is E+100
1964 ; G=E
1966 order_score_vars(B, C, D, G, F).
1967 create_get_mutable(A, B, C) :-
1968 C= (B=mutable(A)).
1969 gen_var(A).
1970 gen_vars(A, B) :-
1971 length(B, A).
1972 head_info(A, B, C, D, E, F) :-
1973 vars_susp(B, C, D, E),
1974 A=..[G|H],
1975 pairup(H, C, F).
1976 inc_id([A|B], [C|B]) :-
1977 C is A+1.
1978 dec_id([A|B], [C|B]) :-
1979 C is A-1.
1980 extend_id(A, [0|A]).
1981 next_id([A, B|C], [D|C]) :-
1982 D is B+1.
1983 build_head(A, B, C, D, E) :-
1984 buildName(A, B, C, F),
1985 E=..[F|D].
1986 buildName(A, B, C, D) :-
1987 atom_concat(A, /, E),
1988 atom_concat(E, B, F),
1989 buildName_(C, F, D).
1990 buildName_([], A, A).
1991 buildName_([A|B], C, D) :-
1992 buildName_(B, C, E),
1993 atom_concat(E, '__', F),
1994 atom_concat(F, A, D).
1995 vars_susp(A, B, C, D) :-
1996 length(B, A),
1997 append(B, [C], D).
1998 make_attr(A, B, C, D) :-
1999 length(C, A),
2000 D=..[v, B|C].
2001 or_pattern(A, B) :-
2002 C is A-1,
2003 B is 1<<C.
2004 and_pattern(A, B) :-
2005 C is A-1,
2006 D is 1<<C,
2007 B is-1* (D+1).
2008 conj2list(A, B) :-
2009 conj2list(A, B, []).
2010 conj2list(A, B, C) :-
2011 A= (D, E), !,
2012 conj2list(D, B, F),
2013 conj2list(E, F, C).
2014 conj2list(A, [A|B], B).
2015 list2conj([], true).
2016 list2conj([A], B) :- !,
2017 B=A.
2018 list2conj([A|B], C) :-
2019 ( A==true
2020 -> list2conj(B, C)
2021 ; C= (A, D),
2022 list2conj(B, D)
2024 list2disj([], fail).
2025 list2disj([A], B) :- !,
2026 B=A.
2027 list2disj([A|B], C) :-
2028 ( A==fail
2029 -> list2disj(B, C)
2030 ; C= (A;D),
2031 list2disj(B, D)
2033 atom_concat_list([A], A) :- !.
2034 atom_concat_list([A|B], C) :-
2035 atom_concat_list(B, D),
2036 atom_concat(A, D, C).
2037 make_name(A, B/C, D) :-
2038 atom_concat_list([A, B, /, C], D).
2039 set_elems([], A).
2040 set_elems([A|B], A) :-
2041 set_elems(B, A).
2042 member2([A|B], [C|D], A-C).
2043 member2([A|B], [C|D], E) :-
2044 member2(B, D, E).
2045 select2(A, B, [A|C], [B|D], C, D).
2046 select2(A, B, [C|D], [E|F], [C|G], [E|H]) :-
2047 select2(A, B, D, F, G, H).
2048 pair_all_with([], A, []).
2049 pair_all_with([A|B], C, [A-C|D]) :-
2050 pair_all_with(B, C, D).
2051 lookup_passive_head(A, B, C, D, E) :-
2052 functor(A, F, G),
2053 get_store_type(F/G, H),
2054 lookup_passive_head(H, A, B, C, D, E).
2055 lookup_passive_head(default, A, B, C, D, E) :-
2056 passive_head_via(A, B, [], C, D, F, G),
2057 instantiate_pattern_goals(G),
2058 get_max_constraint_index(H),
2059 ( H==1
2060 -> E=F
2061 ; functor(A, I, J),
2062 get_constraint_index(I/J, K),
2063 make_attr(H, L, M, F),
2064 nth(K, M, E)
2066 lookup_passive_head(multi_hash(A), B, C, D, E, F) :-
2067 once((
2068 member(G, A),
2069 multi_hash_key_args(G, B, H),
2070 translate(H, D, I)
2072 ( I=[J]
2073 -> true
2074 ; J=..[k|I]
2076 functor(B, K, L),
2077 multi_hash_via_lookup_name(K/L, G, M),
2078 E=..[M, J, F],
2079 update_store_type(K/L, multi_hash([G])).
2080 lookup_passive_head(global_ground, A, B, C, D, E) :-
2081 functor(A, F, G),
2082 global_ground_store_name(F/G, H),
2083 D=nb_getval(H, E),
2084 update_store_type(F/G, global_ground).
2085 lookup_passive_head(multi_store(A), B, C, D, E, F) :-
2086 once((
2087 member(G, A),
2088 lookup_passive_head(G, B, C, D, E, F)
2090 assume_constraint_stores([]).
2091 assume_constraint_stores([A|B]) :-
2092 ( \+may_trigger(A),
2093 is_attached(A),
2094 get_store_type(A, default)
2095 -> get_indexed_arguments(A, C),
2096 findall(D, (sublist(D, C), D\==[]), E),
2097 assumed_store_type(A, multi_store([multi_hash(E), global_ground]))
2098 ; true
2100 assume_constraint_stores(B).
2101 get_indexed_arguments(A, B) :-
2102 A=C/D,
2103 get_indexed_arguments(1, D, A, B).
2104 get_indexed_arguments(A, B, C, D) :-
2105 ( A>B
2106 -> D=[]
2107 ; ( is_indexed_argument(C, A)
2108 -> D=[A|E]
2109 ; D=E
2111 F is A+1,
2112 get_indexed_arguments(F, B, C, E)
2114 validate_store_type_assumptions([]).
2115 validate_store_type_assumptions([A|B]) :-
2116 validate_store_type_assumption(A),
2117 validate_store_type_assumptions(B).
2118 attr_unify_hook(A, B) :-
2119 write('ERROR: Unexpected triggering of attr_unify_hook/2 in module '),
2120 writeln(chr_translate).
2121 remove_constraint_internal(A, B, C) :-
2122 arg(2, A, D),
2123 D=mutable(E),
2124 'chr update_mutable'(removed, D),
2125 ( compound(E)
2126 -> B=[],
2127 C=no
2128 ; E==removed
2129 -> B=[],
2130 C=no
2131 ; C=yes,
2132 chr_indexed_variables(A, B)
2134 activate_constraint(A, B, C, D) :-
2135 arg(2, C, E),
2136 E=mutable(F),
2137 'chr update_mutable'(active, E),
2138 ( nonvar(D)
2139 -> true
2140 ; arg(4, C, G),
2141 G=mutable(H),
2142 D is H+1,
2143 'chr update_mutable'(D, G)
2145 ( compound(F)
2146 -> term_variables(F, B),
2147 'chr none_locked'(B),
2148 A=yes
2149 ; F==removed
2150 -> chr_indexed_variables(C, B),
2151 A=yes
2152 ; B=[],
2153 A=no
2155 allocate_constraint(A, B, C, D) :-
2156 B=..[suspension, E, F, A, G, H, C|D],
2157 G=mutable(0),
2158 'chr empty_history'(I),
2159 H=mutable(I),
2160 chr_indexed_variables(B, J),
2161 F=mutable(passive(J)),
2162 'chr gen_id'(E).
2163 chr_indexed_variables(A, []).
2164 insert_constraint_internal(yes, A, B, C, D, E) :-
2165 B=..[suspension, F, G, C, H, I, D|E],
2166 chr_indexed_variables(B, A),
2167 'chr none_locked'(A),
2168 G=mutable(active),
2169 H=mutable(0),
2170 I=mutable(J),
2171 'chr empty_history'(J),
2172 'chr gen_id'(F).
2173 '$insert_in_store_constraint/2'(A) :-
2174 arg(8, A, B),
2175 nb_getval('$chr_store_multi_hash_chr_translate:constraint/2-2', C),
2176 insert_ht(C, B, A),
2177 true.
2178 '$delete_from_store_constraint/2'(A) :-
2179 arg(8, A, B),
2180 nb_getval('$chr_store_multi_hash_chr_translate:constraint/2-2', C),
2181 delete_ht(C, B, A),
2182 true.
2183 '$insert_in_store_constraint_count/1'(A) :-
2184 nb_getval('$chr_store_global_ground_chr_translate:constraint_count/1', B),
2185 b_setval('$chr_store_global_ground_chr_translate:constraint_count/1', [A|B]).
2186 '$delete_from_store_constraint_count/1'(A) :-
2187 nb_getval('$chr_store_global_ground_chr_translate:constraint_count/1', B),
2188 'chr sbag_del_element'(B, A, C),
2189 b_setval('$chr_store_global_ground_chr_translate:constraint_count/1', C).
2190 '$insert_in_store_constraint_index/2'(A) :-
2191 arg(7, A, B),
2192 nb_getval('$chr_store_multi_hash_chr_translate:constraint_index/2-1', C),
2193 insert_ht(C, B, A),
2194 true.
2195 '$delete_from_store_constraint_index/2'(A) :-
2196 arg(7, A, B),
2197 nb_getval('$chr_store_multi_hash_chr_translate:constraint_index/2-1', C),
2198 delete_ht(C, B, A),
2199 true.
2200 '$insert_in_store_max_constraint_index/1'(A) :-
2201 nb_getval('$chr_store_global_ground_chr_translate:max_constraint_index/1', B),
2202 b_setval('$chr_store_global_ground_chr_translate:max_constraint_index/1', [A|B]).
2203 '$delete_from_store_max_constraint_index/1'(A) :-
2204 nb_getval('$chr_store_global_ground_chr_translate:max_constraint_index/1', B),
2205 'chr sbag_del_element'(B, A, C),
2206 b_setval('$chr_store_global_ground_chr_translate:max_constraint_index/1', C).
2207 '$insert_in_store_target_module/1'(A) :-
2208 nb_getval('$chr_store_global_ground_chr_translate:target_module/1', B),
2209 b_setval('$chr_store_global_ground_chr_translate:target_module/1', [A|B]).
2210 '$delete_from_store_target_module/1'(A) :-
2211 nb_getval('$chr_store_global_ground_chr_translate:target_module/1', B),
2212 'chr sbag_del_element'(B, A, C),
2213 b_setval('$chr_store_global_ground_chr_translate:target_module/1', C).
2214 '$insert_in_store_attached/2'(A) :-
2215 arg(7, A, B),
2216 nb_getval('$chr_store_multi_hash_chr_translate:attached/2-1', C),
2217 insert_ht(C, B, A),
2218 true.
2219 '$delete_from_store_attached/2'(A) :-
2220 arg(7, A, B),
2221 nb_getval('$chr_store_multi_hash_chr_translate:attached/2-1', C),
2222 delete_ht(C, B, A),
2223 true.
2224 '$insert_in_store_indexed_argument/2'(A) :-
2225 arg(7, A, B),
2226 arg(8, A, C),
2227 nb_getval('$chr_store_multi_hash_chr_translate:indexed_argument/2-12', D),
2228 insert_ht(D, k(B, C), A),
2229 true.
2230 '$delete_from_store_indexed_argument/2'(A) :-
2231 arg(7, A, B),
2232 arg(8, A, C),
2233 nb_getval('$chr_store_multi_hash_chr_translate:indexed_argument/2-12', D),
2234 delete_ht(D, k(B, C), A),
2235 true.
2236 '$insert_in_store_constraint_mode/2'(A) :-
2237 arg(7, A, B),
2238 nb_getval('$chr_store_multi_hash_chr_translate:constraint_mode/2-1', C),
2239 insert_ht(C, B, A),
2240 true.
2241 '$delete_from_store_constraint_mode/2'(A) :-
2242 arg(7, A, B),
2243 nb_getval('$chr_store_multi_hash_chr_translate:constraint_mode/2-1', C),
2244 delete_ht(C, B, A),
2245 true.
2246 '$insert_in_store_store_type/2'(A) :-
2247 arg(7, A, B),
2248 nb_getval('$chr_store_multi_hash_chr_translate:store_type/2-1', C),
2249 insert_ht(C, B, A),
2250 true.
2251 '$delete_from_store_store_type/2'(A) :-
2252 arg(7, A, B),
2253 nb_getval('$chr_store_multi_hash_chr_translate:store_type/2-1', C),
2254 delete_ht(C, B, A),
2255 true.
2256 '$insert_in_store_actual_store_types/2'(A) :-
2257 arg(7, A, B),
2258 nb_getval('$chr_store_multi_hash_chr_translate:actual_store_types/2-1', C),
2259 insert_ht(C, B, A),
2260 true.
2261 '$delete_from_store_actual_store_types/2'(A) :-
2262 arg(7, A, B),
2263 nb_getval('$chr_store_multi_hash_chr_translate:actual_store_types/2-1', C),
2264 delete_ht(C, B, A),
2265 true.
2266 '$insert_in_store_assumed_store_type/2'(A) :-
2267 arg(7, A, B),
2268 nb_getval('$chr_store_multi_hash_chr_translate:assumed_store_type/2-1', C),
2269 insert_ht(C, B, A),
2270 true.
2271 '$delete_from_store_assumed_store_type/2'(A) :-
2272 arg(7, A, B),
2273 nb_getval('$chr_store_multi_hash_chr_translate:assumed_store_type/2-1', C),
2274 delete_ht(C, B, A),
2275 true.
2276 '$insert_in_store_rule_count/1'(A) :-
2277 nb_getval('$chr_store_global_ground_chr_translate:rule_count/1', B),
2278 b_setval('$chr_store_global_ground_chr_translate:rule_count/1', [A|B]).
2279 '$delete_from_store_rule_count/1'(A) :-
2280 nb_getval('$chr_store_global_ground_chr_translate:rule_count/1', B),
2281 'chr sbag_del_element'(B, A, C),
2282 b_setval('$chr_store_global_ground_chr_translate:rule_count/1', C).
2283 '$insert_in_store_passive/2'(A) :-
2284 arg(7, A, B),
2285 nb_getval('$chr_store_multi_hash_chr_translate:passive/2-1', C),
2286 insert_ht(C, B, A),
2287 true,
2288 arg(7, A, D),
2289 arg(8, A, E),
2290 nb_getval('$chr_store_multi_hash_chr_translate:passive/2-12', F),
2291 insert_ht(F, k(D, E), A),
2292 true.
2293 '$delete_from_store_passive/2'(A) :-
2294 arg(7, A, B),
2295 nb_getval('$chr_store_multi_hash_chr_translate:passive/2-1', C),
2296 delete_ht(C, B, A),
2297 true,
2298 arg(7, A, D),
2299 arg(8, A, E),
2300 nb_getval('$chr_store_multi_hash_chr_translate:passive/2-12', F),
2301 delete_ht(F, k(D, E), A),
2302 true.
2303 '$insert_in_store_pragma_unique/3'(A) :-
2304 arg(7, A, B),
2305 arg(8, A, C),
2306 nb_getval('$chr_store_multi_hash_chr_translate:pragma_unique/3-12', D),
2307 insert_ht(D, k(B, C), A),
2308 true.
2309 '$delete_from_store_pragma_unique/3'(A) :-
2310 arg(7, A, B),
2311 arg(8, A, C),
2312 nb_getval('$chr_store_multi_hash_chr_translate:pragma_unique/3-12', D),
2313 delete_ht(D, k(B, C), A),
2314 true.
2315 '$insert_in_store_occurrence/4'(A) :-
2316 arg(9, A, B),
2317 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-3', C),
2318 insert_ht(C, B, A),
2319 true,
2320 arg(8, A, D),
2321 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-2', E),
2322 insert_ht(E, D, A),
2323 true,
2324 arg(7, A, F),
2325 arg(8, A, G),
2326 arg(9, A, H),
2327 arg(10, A, I),
2328 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-1234', J),
2329 insert_ht(J, k(F, G, H, I), A),
2330 true.
2331 '$delete_from_store_occurrence/4'(A) :-
2332 arg(9, A, B),
2333 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-3', C),
2334 delete_ht(C, B, A),
2335 true,
2336 arg(8, A, D),
2337 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-2', E),
2338 delete_ht(E, D, A),
2339 true,
2340 arg(7, A, F),
2341 arg(8, A, G),
2342 arg(9, A, H),
2343 arg(10, A, I),
2344 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-1234', J),
2345 delete_ht(J, k(F, G, H, I), A),
2346 true.
2347 '$insert_in_store_max_occurrence/2'(A) :-
2348 arg(7, A, B),
2349 nb_getval('$chr_store_multi_hash_chr_translate:max_occurrence/2-1', C),
2350 insert_ht(C, B, A),
2351 true.
2352 '$delete_from_store_max_occurrence/2'(A) :-
2353 arg(7, A, B),
2354 nb_getval('$chr_store_multi_hash_chr_translate:max_occurrence/2-1', C),
2355 delete_ht(C, B, A),
2356 true.
2357 '$insert_in_store_allocation_occurrence/2'(A) :-
2358 arg(7, A, B),
2359 nb_getval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-1', C),
2360 insert_ht(C, B, A),
2361 true,
2362 arg(7, A, D),
2363 arg(8, A, E),
2364 nb_getval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-12', F),
2365 insert_ht(F, k(D, E), A),
2366 true,
2367 nb_getval('$chr_store_global_ground_chr_translate:allocation_occurrence/2', G),
2368 b_setval('$chr_store_global_ground_chr_translate:allocation_occurrence/2', [A|G]).
2369 '$delete_from_store_allocation_occurrence/2'(A) :-
2370 arg(7, A, B),
2371 nb_getval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-1', C),
2372 delete_ht(C, B, A),
2373 true,
2374 arg(7, A, D),
2375 arg(8, A, E),
2376 nb_getval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-12', F),
2377 delete_ht(F, k(D, E), A),
2378 true,
2379 nb_getval('$chr_store_global_ground_chr_translate:allocation_occurrence/2', G),
2380 'chr sbag_del_element'(G, A, H),
2381 b_setval('$chr_store_global_ground_chr_translate:allocation_occurrence/2', H).
2382 '$insert_in_store_rule/2'(A) :-
2383 arg(7, A, B),
2384 nb_getval('$chr_store_multi_hash_chr_translate:rule/2-1', C),
2385 insert_ht(C, B, A),
2386 true.
2387 '$delete_from_store_rule/2'(A) :-
2388 arg(7, A, B),
2389 nb_getval('$chr_store_multi_hash_chr_translate:rule/2-1', C),
2390 delete_ht(C, B, A),
2391 true.
2392 '$enumerate_suspensions'(A) :-
2393 ( nb_getval('$chr_store_multi_hash_chr_translate:constraint/2-2', B),
2394 value_ht(B, A)
2395 ; nb_getval('$chr_store_global_ground_chr_translate:constraint_count/1', C),
2396 'chr sbag_member'(A, C)
2397 ; nb_getval('$chr_store_multi_hash_chr_translate:constraint_index/2-1', D),
2398 value_ht(D, A)
2399 ; nb_getval('$chr_store_global_ground_chr_translate:max_constraint_index/1', E),
2400 'chr sbag_member'(A, E)
2401 ; nb_getval('$chr_store_global_ground_chr_translate:target_module/1', F),
2402 'chr sbag_member'(A, F)
2403 ; nb_getval('$chr_store_multi_hash_chr_translate:attached/2-1', G),
2404 value_ht(G, A)
2405 ; nb_getval('$chr_store_multi_hash_chr_translate:indexed_argument/2-12', H),
2406 value_ht(H, A)
2407 ; nb_getval('$chr_store_multi_hash_chr_translate:constraint_mode/2-1', I),
2408 value_ht(I, A)
2409 ; nb_getval('$chr_store_multi_hash_chr_translate:store_type/2-1', J),
2410 value_ht(J, A)
2411 ; nb_getval('$chr_store_multi_hash_chr_translate:actual_store_types/2-1', K),
2412 value_ht(K, A)
2413 ; nb_getval('$chr_store_multi_hash_chr_translate:assumed_store_type/2-1', L),
2414 value_ht(L, A)
2415 ; nb_getval('$chr_store_global_ground_chr_translate:rule_count/1', M),
2416 'chr sbag_member'(A, M)
2417 ; nb_getval('$chr_store_multi_hash_chr_translate:passive/2-1', N),
2418 value_ht(N, A)
2419 ; nb_getval('$chr_store_multi_hash_chr_translate:pragma_unique/3-12', O),
2420 value_ht(O, A)
2421 ; nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-3', P),
2422 value_ht(P, A)
2423 ; nb_getval('$chr_store_multi_hash_chr_translate:max_occurrence/2-1', Q),
2424 value_ht(Q, A)
2425 ; nb_getval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-1', R),
2426 value_ht(R, A)
2427 ; nb_getval('$chr_store_multi_hash_chr_translate:rule/2-1', S),
2428 value_ht(S, A)
2430 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:constraint/2-2', A).
2431 '$via1_multi_hash_constraint/2-2'(A, B) :-
2432 nb_getval('$chr_store_multi_hash_chr_translate:constraint/2-2', C),
2433 lookup_ht(C, A, B).
2434 :-nb_setval('$chr_store_global_ground_chr_translate:constraint_count/1', []).
2435 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:constraint_index/2-1', A).
2436 '$via1_multi_hash_constraint_index/2-1'(A, B) :-
2437 nb_getval('$chr_store_multi_hash_chr_translate:constraint_index/2-1', C),
2438 lookup_ht(C, A, B).
2439 :-nb_setval('$chr_store_global_ground_chr_translate:max_constraint_index/1', []).
2440 :-nb_setval('$chr_store_global_ground_chr_translate:target_module/1', []).
2441 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:attached/2-1', A).
2442 '$via1_multi_hash_attached/2-1'(A, B) :-
2443 nb_getval('$chr_store_multi_hash_chr_translate:attached/2-1', C),
2444 lookup_ht(C, A, B).
2445 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:indexed_argument/2-12', A).
2446 '$via1_multi_hash_indexed_argument/2-12'(A, B) :-
2447 nb_getval('$chr_store_multi_hash_chr_translate:indexed_argument/2-12', C),
2448 lookup_ht(C, A, B).
2449 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:constraint_mode/2-1', A).
2450 '$via1_multi_hash_constraint_mode/2-1'(A, B) :-
2451 nb_getval('$chr_store_multi_hash_chr_translate:constraint_mode/2-1', C),
2452 lookup_ht(C, A, B).
2453 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:store_type/2-1', A).
2454 '$via1_multi_hash_store_type/2-1'(A, B) :-
2455 nb_getval('$chr_store_multi_hash_chr_translate:store_type/2-1', C),
2456 lookup_ht(C, A, B).
2457 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:actual_store_types/2-1', A).
2458 '$via1_multi_hash_actual_store_types/2-1'(A, B) :-
2459 nb_getval('$chr_store_multi_hash_chr_translate:actual_store_types/2-1', C),
2460 lookup_ht(C, A, B).
2461 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:assumed_store_type/2-1', A).
2462 '$via1_multi_hash_assumed_store_type/2-1'(A, B) :-
2463 nb_getval('$chr_store_multi_hash_chr_translate:assumed_store_type/2-1', C),
2464 lookup_ht(C, A, B).
2465 :-nb_setval('$chr_store_global_ground_chr_translate:rule_count/1', []).
2466 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:passive/2-1', A).
2467 '$via1_multi_hash_passive/2-1'(A, B) :-
2468 nb_getval('$chr_store_multi_hash_chr_translate:passive/2-1', C),
2469 lookup_ht(C, A, B).
2470 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:passive/2-12', A).
2471 '$via1_multi_hash_passive/2-12'(A, B) :-
2472 nb_getval('$chr_store_multi_hash_chr_translate:passive/2-12', C),
2473 lookup_ht(C, A, B).
2474 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:pragma_unique/3-12', A).
2475 '$via1_multi_hash_pragma_unique/3-12'(A, B) :-
2476 nb_getval('$chr_store_multi_hash_chr_translate:pragma_unique/3-12', C),
2477 lookup_ht(C, A, B).
2478 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:occurrence/4-3', A).
2479 '$via1_multi_hash_occurrence/4-3'(A, B) :-
2480 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-3', C),
2481 lookup_ht(C, A, B).
2482 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:occurrence/4-2', A).
2483 '$via1_multi_hash_occurrence/4-2'(A, B) :-
2484 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-2', C),
2485 lookup_ht(C, A, B).
2486 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:occurrence/4-1234', A).
2487 '$via1_multi_hash_occurrence/4-1234'(A, B) :-
2488 nb_getval('$chr_store_multi_hash_chr_translate:occurrence/4-1234', C),
2489 lookup_ht(C, A, B).
2490 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:max_occurrence/2-1', A).
2491 '$via1_multi_hash_max_occurrence/2-1'(A, B) :-
2492 nb_getval('$chr_store_multi_hash_chr_translate:max_occurrence/2-1', C),
2493 lookup_ht(C, A, B).
2494 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-1', A).
2495 '$via1_multi_hash_allocation_occurrence/2-1'(A, B) :-
2496 nb_getval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-1', C),
2497 lookup_ht(C, A, B).
2498 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-12', A).
2499 '$via1_multi_hash_allocation_occurrence/2-12'(A, B) :-
2500 nb_getval('$chr_store_multi_hash_chr_translate:allocation_occurrence/2-12', C),
2501 lookup_ht(C, A, B).
2502 :-nb_setval('$chr_store_global_ground_chr_translate:allocation_occurrence/2', []).
2503 :-new_ht(A), nb_setval('$chr_store_multi_hash_chr_translate:rule/2-1', A).
2504 '$via1_multi_hash_rule/2-1'(A, B) :-
2505 nb_getval('$chr_store_multi_hash_chr_translate:rule/2-1', C),
2506 lookup_ht(C, A, B).
2507 constraint(A, B) :-
2508 'constraint/2__0'(A, B, C).
2509 'constraint/2__0'(A, B, C) :-
2510 insert_constraint_internal(D, E, C, chr_translate:'constraint/2__0'(A, B, C), constraint(A, B), [A, B]),
2511 '$insert_in_store_constraint/2'(C).
2512 get_constraint(A, B) :-
2513 'get_constraint/2__0'(A, B, C).
2514 'get_constraint/2__0'(A, B, C) :-
2515 '$via1_multi_hash_constraint/2-2'(B, D),
2516 'chr sbag_member'(E, D),
2517 E=suspension(F, G, H, I, J, K, L, M),
2518 G=mutable(active),
2519 M==B, !,
2520 A=L.
2521 'get_constraint/2__0'(A, B, C) :- !,
2522 fail.
2523 constraint_count(A) :-
2524 'constraint_count/1__0'(A, B).
2525 'constraint_count/1__0'(A, B) :-
2526 insert_constraint_internal(C, D, B, chr_translate:'constraint_count/1__0'(A, B), constraint_count(A), [A]),
2527 '$insert_in_store_constraint_count/1'(B).
2528 get_constraint_count(A) :-
2529 'get_constraint_count/1__0'(A, B).
2530 'get_constraint_count/1__0'(A, B) :-
2531 nb_getval('$chr_store_global_ground_chr_translate:constraint_count/1', C),
2532 'chr sbag_member'(D, C),
2533 D=suspension(E, F, G, H, I, J, K),
2534 F=mutable(active), !,
2535 A=K.
2536 'get_constraint_count/1__0'(A, B) :- !,
2537 A=0.
2538 constraint_index(A, B) :-
2539 'constraint_index/2__0'(A, B, C).
2540 'constraint_index/2__0'(A, B, C) :-
2541 insert_constraint_internal(D, E, C, chr_translate:'constraint_index/2__0'(A, B, C), constraint_index(A, B), [A, B]),
2542 '$insert_in_store_constraint_index/2'(C).
2543 get_constraint_index(A, B) :-
2544 'get_constraint_index/2__0'(A, B, C).
2545 'get_constraint_index/2__0'(A, B, C) :-
2546 '$via1_multi_hash_constraint_index/2-1'(A, D),
2547 'chr sbag_member'(E, D),
2548 E=suspension(F, G, H, I, J, K, L, M),
2549 G=mutable(active),
2550 L==A, !,
2551 B=M.
2552 'get_constraint_index/2__0'(A, B, C) :- !,
2553 fail.
2554 max_constraint_index(A) :-
2555 'max_constraint_index/1__0'(A, B).
2556 'max_constraint_index/1__0'(A, B) :-
2557 insert_constraint_internal(C, D, B, chr_translate:'max_constraint_index/1__0'(A, B), max_constraint_index(A), [A]),
2558 '$insert_in_store_max_constraint_index/1'(B).
2559 get_max_constraint_index(A) :-
2560 'get_max_constraint_index/1__0'(A, B).
2561 'get_max_constraint_index/1__0'(A, B) :-
2562 nb_getval('$chr_store_global_ground_chr_translate:max_constraint_index/1', C),
2563 'chr sbag_member'(D, C),
2564 D=suspension(E, F, G, H, I, J, K),
2565 F=mutable(active), !,
2566 A=K.
2567 'get_max_constraint_index/1__0'(A, B) :- !,
2568 A=0.
2569 target_module(A) :-
2570 'target_module/1__0'(A, B).
2571 'target_module/1__0'(A, B) :-
2572 insert_constraint_internal(C, D, B, chr_translate:'target_module/1__0'(A, B), target_module(A), [A]),
2573 '$insert_in_store_target_module/1'(B).
2574 get_target_module(A) :-
2575 'get_target_module/1__0'(A, B).
2576 'get_target_module/1__0'(A, B) :-
2577 nb_getval('$chr_store_global_ground_chr_translate:target_module/1', C),
2578 'chr sbag_member'(D, C),
2579 D=suspension(E, F, G, H, I, J, K),
2580 F=mutable(active), !,
2581 A=K.
2582 'get_target_module/1__0'(A, B) :- !,
2583 A=user.
2584 attached(A, B) :-
2585 'attached/2__0'(A, B, C).
2586 'attached/2__0'(A, B, C) :-
2587 '$via1_multi_hash_attached/2-1'(A, D),
2588 'chr sbag_member'(E, D),
2589 E=suspension(F, G, H, I, J, K, L, M),
2590 G=mutable(active),
2591 L==A,
2592 M==yes, !.
2593 'attached/2__0'(A, B, C) :-
2594 B==yes,
2595 '$via1_multi_hash_attached/2-1'(A, D), !,
2596 allocate_constraint(chr_translate:'attached/2__0'(A, B, C), C, attached(A, B), [A, B]),
2597 'attached/2__0__0'(D, A, B, C).
2598 'attached/2__0__0'([], A, B, C) :-
2599 'attached/2__1'(A, B, C).
2600 'attached/2__0__0'([A|B], C, D, E) :-
2601 ( A=suspension(F, G, H, I, J, K, L, M),
2602 G=mutable(active),
2603 L==C
2604 -> remove_constraint_internal(A, N, O),
2605 ( O==yes
2606 -> '$delete_from_store_attached/2'(A)
2607 ; true
2609 'attached/2__0__0'(B, C, D, E)
2610 ; 'attached/2__0__0'(B, C, D, E)
2612 'attached/2__0'(A, B, C) :-
2613 allocate_constraint(chr_translate:'attached/2__0'(A, B, C), C, attached(A, B), [A, B]),
2614 'attached/2__1'(A, B, C).
2615 'attached/2__1'(A, B, C) :-
2616 '$via1_multi_hash_attached/2-1'(A, D),
2617 'chr sbag_member'(E, D),
2618 E=suspension(F, G, H, I, J, K, L, M),
2619 G=mutable(active),
2620 L==A,
2621 M==no, !,
2622 ( var(C)
2623 -> true
2624 ; remove_constraint_internal(C, N, O),
2625 ( O==yes
2626 -> '$delete_from_store_attached/2'(C)
2627 ; true
2630 'attached/2__1'(A, B, C) :-
2631 B==no,
2632 '$via1_multi_hash_attached/2-1'(A, D), !,
2633 'attached/2__1__0'(D, A, B, C).
2634 'attached/2__1__0'([], A, B, C) :-
2635 'attached/2__2'(A, B, C).
2636 'attached/2__1__0'([A|B], C, D, E) :-
2637 ( A=suspension(F, G, H, I, J, K, L, M),
2638 G=mutable(active),
2639 L==C
2640 -> remove_constraint_internal(A, N, O),
2641 ( O==yes
2642 -> '$delete_from_store_attached/2'(A)
2643 ; true
2645 'attached/2__1__0'(B, C, D, E)
2646 ; 'attached/2__1__0'(B, C, D, E)
2648 'attached/2__1'(A, B, C) :-
2649 'attached/2__2'(A, B, C).
2650 'attached/2__2'(A, B, C) :-
2651 B==maybe,
2652 '$via1_multi_hash_attached/2-1'(A, D),
2653 ( 'chr sbag_member'(E, D),
2654 E=suspension(F, G, H, I, J, K, L, M),
2655 G=mutable(active),
2656 L==A,
2657 M==maybe
2658 -> true
2659 ), !,
2660 ( var(C)
2661 -> true
2662 ; remove_constraint_internal(C, N, O),
2663 ( O==yes
2664 -> '$delete_from_store_attached/2'(C)
2665 ; true
2668 'attached/2__2'(A, B, C) :-
2669 activate_constraint(D, E, C, F),
2670 ( D==yes
2671 -> '$insert_in_store_attached/2'(C)
2672 ; true
2674 is_attached(A) :-
2675 'is_attached/1__0'(A, B).
2676 'is_attached/1__0'(A, B) :-
2677 '$via1_multi_hash_attached/2-1'(A, C),
2678 'chr sbag_member'(D, C),
2679 D=suspension(E, F, G, H, I, J, K, L),
2680 F=mutable(active),
2681 K==A, !,
2682 L\==no.
2683 'is_attached/1__0'(A, B) :- !.
2684 indexed_argument(A, B) :-
2685 'indexed_argument/2__0'(A, B, C).
2686 'indexed_argument/2__0'(A, B, C) :-
2687 '$via1_multi_hash_indexed_argument/2-12'(k(A, B), D),
2688 ( 'chr sbag_member'(E, D),
2689 E=suspension(F, G, H, I, J, K, L, M),
2690 G=mutable(active),
2691 L==A,
2692 M==B
2693 -> true
2694 ), !.
2695 'indexed_argument/2__0'(A, B, C) :-
2696 insert_constraint_internal(D, E, C, chr_translate:'indexed_argument/2__0'(A, B, C), indexed_argument(A, B), [A, B]),
2697 '$insert_in_store_indexed_argument/2'(C).
2698 is_indexed_argument(A, B) :-
2699 'is_indexed_argument/2__0'(A, B, C).
2700 'is_indexed_argument/2__0'(A, B, C) :-
2701 '$via1_multi_hash_indexed_argument/2-12'(k(A, B), D),
2702 ( 'chr sbag_member'(E, D),
2703 E=suspension(F, G, H, I, J, K, L, M),
2704 G=mutable(active),
2705 L==A,
2706 M==B
2707 -> true
2708 ), !.
2709 'is_indexed_argument/2__0'(A, B, C) :- !,
2710 fail.
2711 constraint_mode(A, B) :-
2712 'constraint_mode/2__0'(A, B, C).
2713 'constraint_mode/2__0'(A, B, C) :-
2714 insert_constraint_internal(D, E, C, chr_translate:'constraint_mode/2__0'(A, B, C), constraint_mode(A, B), [A, B]),
2715 '$insert_in_store_constraint_mode/2'(C).
2716 get_constraint_mode(A, B) :-
2717 'get_constraint_mode/2__0'(A, B, C).
2718 'get_constraint_mode/2__0'(A, B, C) :-
2719 '$via1_multi_hash_constraint_mode/2-1'(A, D),
2720 'chr sbag_member'(E, D),
2721 E=suspension(F, G, H, I, J, K, L, M),
2722 G=mutable(active),
2723 L==A, !,
2724 B=M.
2725 'get_constraint_mode/2__0'(A, B, C) :- !,
2726 A=D/E,
2727 length(B, E),
2728 set_elems(B, ?).
2729 may_trigger(A) :-
2730 'may_trigger/1__0'(A, B).
2731 'may_trigger/1__0'(A, B) :- !,
2732 is_attached(A),
2733 get_constraint_mode(A, C),
2734 has_nonground_indexed_argument(A, 1, C).
2735 has_nonground_indexed_argument(A, B, C) :-
2736 'has_nonground_indexed_argument/3__0'(A, B, C, D).
2737 'has_nonground_indexed_argument/3__0'(A, B, C, D) :-
2738 nonvar(C),
2739 C=[E|F], !,
2740 ( is_indexed_argument(A, B),
2741 E\== +
2742 -> true
2743 ; G is B+1,
2744 has_nonground_indexed_argument(A, G, F)
2746 'has_nonground_indexed_argument/3__0'(A, B, C, D) :- !,
2747 fail.
2748 store_type(A, B) :-
2749 'store_type/2__0'(A, B, C).
2750 'store_type/2__0'(A, B, C) :-
2751 nonvar(B),
2752 B=atom_hash(D), !,
2753 store_type(A, multi_hash([D])).
2754 'store_type/2__0'(A, B, C) :-
2755 insert_constraint_internal(D, E, C, chr_translate:'store_type/2__0'(A, B, C), store_type(A, B), [A, B]),
2756 '$insert_in_store_store_type/2'(C).
2757 get_store_type(A, B) :-
2758 'get_store_type/2__0'(A, B, C).
2759 'get_store_type/2__0'(A, B, C) :-
2760 '$via1_multi_hash_store_type/2-1'(A, D),
2761 'chr sbag_member'(E, D),
2762 E=suspension(F, G, H, I, J, K, L, M),
2763 G=mutable(active),
2764 L==A, !,
2765 B=M.
2766 'get_store_type/2__0'(A, B, C) :-
2767 '$via1_multi_hash_assumed_store_type/2-1'(A, D),
2768 'chr sbag_member'(E, D),
2769 E=suspension(F, G, H, I, J, K, L, M),
2770 G=mutable(active),
2771 L==A, !,
2772 B=M.
2773 'get_store_type/2__0'(A, B, C) :- !,
2774 B=default.
2775 update_store_type(A, B) :-
2776 'update_store_type/2__0'(A, B, C).
2777 'update_store_type/2__0'(A, B, C) :-
2778 '$via1_multi_hash_actual_store_types/2-1'(A, D),
2779 'chr sbag_member'(E, D),
2780 E=suspension(F, G, H, I, J, K, L, M),
2781 G=mutable(active),
2782 L==A,
2783 'chr lock'(B),
2784 member(B, M),
2785 'chr unlock'(B), !.
2786 'update_store_type/2__0'(A, B, C) :-
2787 '$via1_multi_hash_actual_store_types/2-1'(A, D),
2788 'chr sbag_member'(E, D),
2789 E=suspension(F, G, H, I, J, K, L, M),
2790 G=mutable(active),
2791 L==A, !,
2792 remove_constraint_internal(E, N, O),
2793 ( O==yes
2794 -> '$delete_from_store_actual_store_types/2'(E)
2795 ; true
2797 actual_store_types(A, [B|M]).
2798 'update_store_type/2__0'(A, B, C) :- !,
2799 actual_store_types(A, [B]).
2800 actual_store_types(A, B) :-
2801 'actual_store_types/2__0'(A, B, C).
2802 'actual_store_types/2__0'(A, B, C) :-
2803 insert_constraint_internal(D, E, C, chr_translate:'actual_store_types/2__0'(A, B, C), actual_store_types(A, B), [A, B]),
2804 '$insert_in_store_actual_store_types/2'(C).
2805 assumed_store_type(A, B) :-
2806 'assumed_store_type/2__0'(A, B, C).
2807 'assumed_store_type/2__0'(A, B, C) :-
2808 insert_constraint_internal(D, E, C, chr_translate:'assumed_store_type/2__0'(A, B, C), assumed_store_type(A, B), [A, B]),
2809 '$insert_in_store_assumed_store_type/2'(C).
2810 validate_store_type_assumption(A) :-
2811 'validate_store_type_assumption/1__0'(A, B).
2812 'validate_store_type_assumption/1__0'(A, B) :-
2813 '$via1_multi_hash_assumed_store_type/2-1'(A, C),
2814 '$via1_multi_hash_actual_store_types/2-1'(A, D),
2815 'chr sbag_member'(E, D),
2816 E=suspension(F, G, H, I, J, K, L, M),
2817 G=mutable(active),
2818 L==A,
2819 'chr sbag_member'(N, C),
2820 N=suspension(O, P, Q, R, S, T, U, V),
2821 P=mutable(active),
2822 U==A, !,
2823 remove_constraint_internal(E, W, X),
2824 ( X==yes
2825 -> '$delete_from_store_actual_store_types/2'(E)
2826 ; true
2828 remove_constraint_internal(N, Y, Z),
2829 ( Z==yes
2830 -> '$delete_from_store_assumed_store_type/2'(N)
2831 ; true
2833 store_type(A, multi_store(M)).
2834 'validate_store_type_assumption/1__0'(A, B) :-
2835 '$via1_multi_hash_store_type/2-1'(A, C),
2836 '$via1_multi_hash_actual_store_types/2-1'(A, D),
2837 'chr sbag_member'(E, D),
2838 E=suspension(F, G, H, I, J, K, L, M),
2839 G=mutable(active),
2840 L==A,
2841 'chr sbag_member'(N, C),
2842 N=suspension(O, P, Q, R, S, T, U, V),
2843 P=mutable(active),
2844 U==A, !,
2845 remove_constraint_internal(E, W, X),
2846 ( X==yes
2847 -> '$delete_from_store_actual_store_types/2'(E)
2848 ; true
2850 remove_constraint_internal(N, Y, Z),
2851 ( Z==yes
2852 -> '$delete_from_store_store_type/2'(N)
2853 ; true
2855 store_type(A, multi_store(M)).
2856 'validate_store_type_assumption/1__0'(A, B) :- !.
2857 rule_count(A) :-
2858 'rule_count/1__0'(A, B).
2859 'rule_count/1__0'(A, B) :-
2860 insert_constraint_internal(C, D, B, chr_translate:'rule_count/1__0'(A, B), rule_count(A), [A]),
2861 '$insert_in_store_rule_count/1'(B).
2862 inc_rule_count(A) :-
2863 'inc_rule_count/1__0'(A, B).
2864 'inc_rule_count/1__0'(A, B) :-
2865 nb_getval('$chr_store_global_ground_chr_translate:rule_count/1', C),
2866 'chr sbag_member'(D, C),
2867 D=suspension(E, F, G, H, I, J, K),
2868 F=mutable(active), !,
2869 remove_constraint_internal(D, L, M),
2870 ( M==yes
2871 -> '$delete_from_store_rule_count/1'(D)
2872 ; true
2874 A is K+1,
2875 rule_count(A).
2876 'inc_rule_count/1__0'(A, B) :- !,
2877 A=1,
2878 rule_count(A).
2879 get_rule_count(A) :-
2880 'get_rule_count/1__0'(A, B).
2881 'get_rule_count/1__0'(A, B) :-
2882 nb_getval('$chr_store_global_ground_chr_translate:rule_count/1', C),
2883 'chr sbag_member'(D, C),
2884 D=suspension(E, F, G, H, I, J, K),
2885 F=mutable(active), !,
2886 A=K.
2887 'get_rule_count/1__0'(A, B) :- !,
2888 A=0.
2889 passive(A, B) :-
2890 'passive/2__0'(A, B, C).
2891 'passive/2__0'(A, B, C) :-
2892 nb_getval('$chr_store_global_ground_chr_translate:allocation_occurrence/2', D), !,
2893 allocate_constraint(chr_translate:'passive/2__0'(A, B, C), C, passive(A, B), [A, B]),
2894 'passive/2__0__0'(D, A, B, C).
2895 'passive/2__0__0'([], A, B, C) :-
2896 'passive/2__1'(A, B, C).
2897 'passive/2__0__0'([A|B], C, D, E) :-
2898 ( A=suspension(F, G, H, I, J, K, L, M),
2899 G=mutable(active),
2900 '$via1_multi_hash_occurrence/4-1234'(k(L, M, C, D), N),
2901 'chr sbag_member'(O, N),
2902 O=suspension(P, Q, R, S, T, U, V, W, X, Y),
2903 Q=mutable(active),
2904 V==L,
2905 W==M,
2906 X==C,
2907 Y==D
2908 -> remove_constraint_internal(A, Z, A1),
2909 ( A1==yes
2910 -> '$delete_from_store_allocation_occurrence/2'(A)
2911 ; true
2913 activate_constraint(B1, C1, E, D1),
2914 ( B1==yes
2915 -> '$insert_in_store_passive/2'(E)
2916 ; true
2918 E1 is M+1,
2919 allocation_occurrence(L, E1),
2920 ( E=suspension(F1, G1, H1, I1, J1, K1, L1, M1),
2921 G1=mutable(active),
2922 I1=mutable(D1)
2923 -> 'chr update_mutable'(inactive, G1),
2924 'passive/2__0__0'(B, C, D, E)
2925 ; true
2927 ; 'passive/2__0__0'(B, C, D, E)
2929 'passive/2__0'(A, B, C) :-
2930 allocate_constraint(chr_translate:'passive/2__0'(A, B, C), C, passive(A, B), [A, B]),
2931 'passive/2__1'(A, B, C).
2932 'passive/2__1'(A, B, C) :-
2933 activate_constraint(D, E, C, F),
2934 ( D==yes
2935 -> '$insert_in_store_passive/2'(C)
2936 ; true
2938 is_passive(A, B) :-
2939 'is_passive/2__0'(A, B, C).
2940 'is_passive/2__0'(A, B, C) :-
2941 '$via1_multi_hash_passive/2-12'(k(A, B), D),
2942 'chr sbag_member'(E, D),
2943 E=suspension(F, G, H, I, J, K, L, M),
2944 G=mutable(active),
2945 L==A,
2946 M==B, !.
2947 'is_passive/2__0'(A, B, C) :- !,
2948 fail.
2949 any_passive_head(A) :-
2950 'any_passive_head/1__0'(A, B).
2951 'any_passive_head/1__0'(A, B) :-
2952 '$via1_multi_hash_passive/2-1'(A, C),
2953 'chr sbag_member'(D, C),
2954 D=suspension(E, F, G, H, I, J, K, L),
2955 F=mutable(active),
2956 K==A, !.
2957 'any_passive_head/1__0'(A, B) :- !,
2958 fail.
2959 pragma_unique(A, B, C) :-
2960 'pragma_unique/3__0'(A, B, C, D).
2961 'pragma_unique/3__0'(A, B, C, D) :-
2962 insert_constraint_internal(E, F, D, chr_translate:'pragma_unique/3__0'(A, B, C, D), pragma_unique(A, B, C), [A, B, C]),
2963 '$insert_in_store_pragma_unique/3'(D).
2964 get_pragma_unique(A, B, C) :-
2965 'get_pragma_unique/3__0'(A, B, C, D).
2966 'get_pragma_unique/3__0'(A, B, C, D) :-
2967 '$via1_multi_hash_pragma_unique/3-12'(k(A, B), E),
2968 'chr sbag_member'(F, E),
2969 F=suspension(G, H, I, J, K, L, M, N, O),
2970 H=mutable(active),
2971 M==A,
2972 N==B, !,
2973 C=O.
2974 'get_pragma_unique/3__0'(A, B, C, D) :- !.
2975 occurrence(A, B, C, D) :-
2976 'occurrence/4__0'(A, B, C, D, E).
2977 'occurrence/4__0'(A, B, C, D, E) :-
2978 allocate_constraint(chr_translate:'occurrence/4__0'(A, B, C, D, E), E, occurrence(A, B, C, D), [A, B, C, D]),
2979 'chr novel_production'(E, 46), !,
2980 'chr extend_history'(E, 46),
2981 activate_constraint(F, G, E, H),
2982 ( F==yes
2983 -> '$insert_in_store_occurrence/4'(E)
2984 ; true
2986 max_occurrence(A, B),
2987 ( E=suspension(I, J, K, L, M, N, O, P, Q, R),
2988 J=mutable(active),
2989 L=mutable(H)
2990 -> 'chr update_mutable'(inactive, J),
2991 'occurrence/4__1'(A, B, C, D, E)
2992 ; true
2994 'occurrence/4__0'(A, B, C, D, E) :-
2995 allocate_constraint(chr_translate:'occurrence/4__0'(A, B, C, D, E), E, occurrence(A, B, C, D), [A, B, C, D]),
2996 'occurrence/4__1'(A, B, C, D, E).
2997 'occurrence/4__1'(A, B, C, D, E) :-
2998 '$via1_multi_hash_allocation_occurrence/2-12'(k(A, B), F), !,
2999 'occurrence/4__1__0'(F, A, B, C, D, E).
3000 'occurrence/4__1__0'([], A, B, C, D, E) :-
3001 'occurrence/4__2'(A, B, C, D, E).
3002 'occurrence/4__1__0'([A|B], C, D, E, F, G) :-
3003 ( A=suspension(H, I, J, K, L, M, N, O),
3004 I=mutable(active),
3005 N==C,
3006 O==D,
3007 '$via1_multi_hash_rule/2-1'(E, P),
3008 'chr sbag_member'(Q, P),
3009 Q=suspension(R, S, T, U, V, W, X, Y),
3010 S=mutable(active),
3011 X==E,
3012 'chr lock'(Y),
3013 Y=pragma(Z, ids(A1, B1), C1, D1, E1),
3014 member(F, F1),
3015 'chr unlock'(Y)
3016 -> remove_constraint_internal(A, G1, H1),
3017 ( H1==yes
3018 -> '$delete_from_store_allocation_occurrence/2'(A)
3019 ; true
3021 activate_constraint(I1, J1, G, K1),
3022 ( I1==yes
3023 -> '$insert_in_store_occurrence/4'(G)
3024 ; true
3026 L1 is D+1,
3027 allocation_occurrence(C, L1),
3028 ( G=suspension(M1, N1, O1, P1, Q1, R1, S1, T1, U1, V1),
3029 N1=mutable(active),
3030 P1=mutable(K1)
3031 -> 'chr update_mutable'(inactive, N1),
3032 'occurrence/4__1__0'(B, C, D, E, F, G)
3033 ; true
3035 ; 'occurrence/4__1__0'(B, C, D, E, F, G)
3037 'occurrence/4__1'(A, B, C, D, E) :-
3038 'occurrence/4__2'(A, B, C, D, E).
3039 'occurrence/4__2'(A, B, C, D, E) :-
3040 '$via1_multi_hash_allocation_occurrence/2-12'(k(A, B), F), !,
3041 'occurrence/4__2__0'(F, A, B, C, D, E).
3042 'occurrence/4__2__0'([], A, B, C, D, E) :-
3043 'occurrence/4__3'(A, B, C, D, E).
3044 'occurrence/4__2__0'([A|B], C, D, E, F, G) :-
3045 ( A=suspension(H, I, J, K, L, M, N, O),
3046 I=mutable(active),
3047 N==C,
3048 O==D,
3049 '$via1_multi_hash_rule/2-1'(E, P),
3050 'chr sbag_member'(Q, P),
3051 Q=suspension(R, S, T, U, V, W, X, Y),
3052 S=mutable(active),
3053 X==E,
3054 'chr lock'(Y),
3055 Y=pragma(rule(Z, A1, B1, true), C1, D1, E1, F1),
3056 'chr unlock'(Y)
3057 -> remove_constraint_internal(A, G1, H1),
3058 ( H1==yes
3059 -> '$delete_from_store_allocation_occurrence/2'(A)
3060 ; true
3062 activate_constraint(I1, J1, G, K1),
3063 ( I1==yes
3064 -> '$insert_in_store_occurrence/4'(G)
3065 ; true
3067 L1 is D+1,
3068 allocation_occurrence(C, L1),
3069 ( G=suspension(M1, N1, O1, P1, Q1, R1, S1, T1, U1, V1),
3070 N1=mutable(active),
3071 P1=mutable(K1)
3072 -> 'chr update_mutable'(inactive, N1),
3073 'occurrence/4__2__0'(B, C, D, E, F, G)
3074 ; true
3076 ; 'occurrence/4__2__0'(B, C, D, E, F, G)
3078 'occurrence/4__2'(A, B, C, D, E) :-
3079 'occurrence/4__3'(A, B, C, D, E).
3080 'occurrence/4__3'(A, B, C, D, E) :-
3081 '$via1_multi_hash_allocation_occurrence/2-12'(k(A, B), F), !,
3082 'occurrence/4__3__0'(F, A, B, C, D, E).
3083 'occurrence/4__3__0'([], A, B, C, D, E) :-
3084 'occurrence/4__4'(A, B, C, D, E).
3085 'occurrence/4__3__0'([A|B], C, D, E, F, G) :-
3086 ( A=suspension(H, I, J, K, L, M, N, O),
3087 I=mutable(active),
3088 N==C,
3089 O==D,
3090 '$via1_multi_hash_passive/2-12'(k(E, F), P),
3091 'chr sbag_member'(Q, P),
3092 Q=suspension(R, S, T, U, V, W, X, Y),
3093 S=mutable(active),
3094 X==E,
3095 Y==F
3096 -> remove_constraint_internal(A, Z, A1),
3097 ( A1==yes
3098 -> '$delete_from_store_allocation_occurrence/2'(A)
3099 ; true
3101 activate_constraint(B1, C1, G, D1),
3102 ( B1==yes
3103 -> '$insert_in_store_occurrence/4'(G)
3104 ; true
3106 E1 is D+1,
3107 allocation_occurrence(C, E1),
3108 ( G=suspension(F1, G1, H1, I1, J1, K1, L1, M1, N1, O1),
3109 G1=mutable(active),
3110 I1=mutable(D1)
3111 -> 'chr update_mutable'(inactive, G1),
3112 'occurrence/4__3__0'(B, C, D, E, F, G)
3113 ; true
3115 ; 'occurrence/4__3__0'(B, C, D, E, F, G)
3117 'occurrence/4__3'(A, B, C, D, E) :-
3118 'occurrence/4__4'(A, B, C, D, E).
3119 'occurrence/4__4'(A, B, C, D, E) :-
3120 activate_constraint(F, G, E, H),
3121 ( F==yes
3122 -> '$insert_in_store_occurrence/4'(E)
3123 ; true
3125 get_occurrence(A, B, C, D) :-
3126 'get_occurrence/4__0'(A, B, C, D, E).
3127 'get_occurrence/4__0'(A, B, C, D, E) :-
3128 '$via1_multi_hash_occurrence/4-2'(B, F),
3129 'chr sbag_member'(G, F),
3130 G=suspension(H, I, J, K, L, M, N, O, P, Q),
3131 I=mutable(active),
3132 N==A,
3133 O==B, !,
3134 P=C,
3135 Q=D.
3136 'get_occurrence/4__0'(A, B, C, D, E) :- !,
3137 fail.
3138 max_occurrence(A, B) :-
3139 'max_occurrence/2__0'(A, B, C).
3140 'max_occurrence/2__0'(A, B, C) :-
3141 '$via1_multi_hash_max_occurrence/2-1'(A, D),
3142 ( 'chr sbag_member'(E, D),
3143 E=suspension(F, G, H, I, J, K, L, M),
3144 G=mutable(active),
3145 L==A
3146 -> true
3148 M>=B, !.
3149 'max_occurrence/2__0'(A, B, C) :-
3150 '$via1_multi_hash_max_occurrence/2-1'(A, D), !,
3151 allocate_constraint(chr_translate:'max_occurrence/2__0'(A, B, C), C, max_occurrence(A, B), [A, B]),
3152 'max_occurrence/2__0__0'(D, A, B, C).
3153 'max_occurrence/2__0__0'([], A, B, C) :-
3154 'max_occurrence/2__1'(A, B, C).
3155 'max_occurrence/2__0__0'([A|B], C, D, E) :-
3156 ( A=suspension(F, G, H, I, J, K, L, M),
3157 G=mutable(active),
3158 L==C
3159 -> ( D>=M
3160 -> remove_constraint_internal(A, N, O),
3161 ( O==yes
3162 -> '$delete_from_store_max_occurrence/2'(A)
3163 ; true
3165 'max_occurrence/2__0__0'([], C, D, E)
3166 ; 'max_occurrence/2__0__0'([], C, D, E)
3168 ; 'max_occurrence/2__0__0'(B, C, D, E)
3170 'max_occurrence/2__0'(A, B, C) :-
3171 allocate_constraint(chr_translate:'max_occurrence/2__0'(A, B, C), C, max_occurrence(A, B), [A, B]),
3172 'max_occurrence/2__1'(A, B, C).
3173 'max_occurrence/2__1'(A, B, C) :-
3174 activate_constraint(D, E, C, F),
3175 ( D==yes
3176 -> '$insert_in_store_max_occurrence/2'(C)
3177 ; true
3179 get_max_occurrence(A, B) :-
3180 'get_max_occurrence/2__0'(A, B, C).
3181 'get_max_occurrence/2__0'(A, B, C) :-
3182 '$via1_multi_hash_max_occurrence/2-1'(A, D),
3183 ( 'chr sbag_member'(E, D),
3184 E=suspension(F, G, H, I, J, K, L, M),
3185 G=mutable(active),
3186 L==A
3187 -> true
3188 ), !,
3189 B=M.
3190 'get_max_occurrence/2__0'(A, B, C) :- !,
3191 B=0.
3192 allocation_occurrence(A, B) :-
3193 'allocation_occurrence/2__0'(A, B, C).
3194 'allocation_occurrence/2__0'(A, B, C) :-
3195 '$via1_multi_hash_occurrence/4-2'(B, D),
3196 'chr sbag_member'(E, D),
3197 E=suspension(F, G, H, I, J, K, L, M, N, O),
3198 G=mutable(active),
3199 L==A,
3200 M==B,
3201 '$via1_multi_hash_rule/2-1'(N, P),
3202 'chr sbag_member'(Q, P),
3203 Q=suspension(R, S, T, U, V, W, X, Y),
3204 S=mutable(active),
3205 X==N,
3206 'chr lock'(Y),
3207 Y=pragma(Z, ids(A1, B1), C1, D1, E1),
3208 member(O, F1),
3209 'chr unlock'(Y), !,
3210 G1 is B+1,
3211 allocation_occurrence(A, G1).
3212 'allocation_occurrence/2__0'(A, B, C) :-
3213 '$via1_multi_hash_occurrence/4-2'(B, D),
3214 'chr sbag_member'(E, D),
3215 E=suspension(F, G, H, I, J, K, L, M, N, O),
3216 G=mutable(active),
3217 L==A,
3218 M==B,
3219 '$via1_multi_hash_rule/2-1'(N, P),
3220 'chr sbag_member'(Q, P),
3221 Q=suspension(R, S, T, U, V, W, X, Y),
3222 S=mutable(active),
3223 X==N,
3224 'chr lock'(Y),
3225 Y=pragma(rule(Z, A1, B1, true), C1, D1, E1, F1),
3226 'chr unlock'(Y), !,
3227 G1 is B+1,
3228 allocation_occurrence(A, G1).
3229 'allocation_occurrence/2__0'(A, B, C) :-
3230 '$via1_multi_hash_occurrence/4-2'(B, D),
3231 'chr sbag_member'(E, D),
3232 E=suspension(F, G, H, I, J, K, L, M, N, O),
3233 G=mutable(active),
3234 L==A,
3235 M==B,
3236 '$via1_multi_hash_passive/2-12'(k(N, O), P),
3237 'chr sbag_member'(Q, P),
3238 Q=suspension(R, S, T, U, V, W, X, Y),
3239 S=mutable(active),
3240 X==N,
3241 Y==O, !,
3242 Z is B+1,
3243 allocation_occurrence(A, Z).
3244 'allocation_occurrence/2__0'(A, B, C) :-
3245 insert_constraint_internal(D, E, C, chr_translate:'allocation_occurrence/2__0'(A, B, C), allocation_occurrence(A, B), [A, B]),
3246 '$insert_in_store_allocation_occurrence/2'(C).
3247 get_allocation_occurrence(A, B) :-
3248 'get_allocation_occurrence/2__0'(A, B, C).
3249 'get_allocation_occurrence/2__0'(A, B, C) :-
3250 '$via1_multi_hash_allocation_occurrence/2-1'(A, D),
3251 'chr sbag_member'(E, D),
3252 E=suspension(F, G, H, I, J, K, L, M),
3253 G=mutable(active),
3254 L==A, !,
3255 B=M.
3256 'get_allocation_occurrence/2__0'(A, B, C) :- !,
3257 fail.
3258 rule(A, B) :-
3259 'rule/2__0'(A, B, C).
3260 'rule/2__0'(A, B, C) :-
3261 nb_getval('$chr_store_global_ground_chr_translate:allocation_occurrence/2', D), !,
3262 allocate_constraint(chr_translate:'rule/2__0'(A, B, C), C, rule(A, B), [A, B]),
3263 'rule/2__0__0'(D, A, B, C).
3264 'rule/2__0__0'([], A, B, C) :-
3265 'rule/2__1'(A, B, C).
3266 'rule/2__0__0'([A|B], C, D, E) :-
3267 ( A=suspension(F, G, H, I, J, K, L, M),
3268 G=mutable(active),
3269 '$via1_multi_hash_occurrence/4-3'(C, N),
3270 'chr sbag_member'(O, N),
3271 O=suspension(P, Q, R, S, T, U, V, W, X, Y),
3272 Q=mutable(active),
3273 V==L,
3274 W==M,
3275 X==C,
3276 'chr lock'(D),
3277 D=pragma(Z, ids(A1, B1), C1, D1, E1),
3278 member(Y, F1),
3279 'chr unlock'(D)
3280 -> remove_constraint_internal(A, G1, H1),
3281 ( H1==yes
3282 -> '$delete_from_store_allocation_occurrence/2'(A)
3283 ; true
3285 activate_constraint(I1, J1, E, K1),
3286 ( I1==yes
3287 -> '$insert_in_store_rule/2'(E)
3288 ; true
3290 L1 is M+1,
3291 allocation_occurrence(L, L1),
3292 ( E=suspension(M1, N1, O1, P1, Q1, R1, S1, T1),
3293 N1=mutable(active),
3294 P1=mutable(K1)
3295 -> 'chr update_mutable'(inactive, N1),
3296 'rule/2__0__0'(B, C, D, E)
3297 ; true
3299 ; 'rule/2__0__0'(B, C, D, E)
3301 'rule/2__0'(A, B, C) :-
3302 allocate_constraint(chr_translate:'rule/2__0'(A, B, C), C, rule(A, B), [A, B]),
3303 'rule/2__1'(A, B, C).
3304 'rule/2__1'(A, B, C) :-
3305 nb_getval('$chr_store_global_ground_chr_translate:allocation_occurrence/2', D), !,
3306 'rule/2__1__0'(D, A, B, C).
3307 'rule/2__1__0'([], A, B, C) :-
3308 'rule/2__2'(A, B, C).
3309 'rule/2__1__0'([A|B], C, D, E) :-
3310 ( A=suspension(F, G, H, I, J, K, L, M),
3311 G=mutable(active),
3312 '$via1_multi_hash_occurrence/4-3'(C, N),
3313 'chr sbag_member'(O, N),
3314 O=suspension(P, Q, R, S, T, U, V, W, X, Y),
3315 Q=mutable(active),
3316 V==L,
3317 W==M,
3318 X==C,
3319 'chr lock'(D),
3320 D=pragma(rule(Z, A1, B1, true), C1, D1, E1, F1),
3321 'chr unlock'(D)
3322 -> remove_constraint_internal(A, G1, H1),
3323 ( H1==yes
3324 -> '$delete_from_store_allocation_occurrence/2'(A)
3325 ; true
3327 activate_constraint(I1, J1, E, K1),
3328 ( I1==yes
3329 -> '$insert_in_store_rule/2'(E)
3330 ; true
3332 L1 is M+1,
3333 allocation_occurrence(L, L1),
3334 ( E=suspension(M1, N1, O1, P1, Q1, R1, S1, T1),
3335 N1=mutable(active),
3336 P1=mutable(K1)
3337 -> 'chr update_mutable'(inactive, N1),
3338 'rule/2__1__0'(B, C, D, E)
3339 ; true
3341 ; 'rule/2__1__0'(B, C, D, E)
3343 'rule/2__1'(A, B, C) :-
3344 'rule/2__2'(A, B, C).
3345 'rule/2__2'(A, B, C) :-
3346 activate_constraint(D, E, C, F),
3347 ( D==yes
3348 -> '$insert_in_store_rule/2'(C)
3349 ; true
3351 get_rule(A, B) :-
3352 'get_rule/2__0'(A, B, C).
3353 'get_rule/2__0'(A, B, C) :-
3354 '$via1_multi_hash_rule/2-1'(A, D),
3355 'chr sbag_member'(E, D),
3356 E=suspension(F, G, H, I, J, K, L, M),
3357 G=mutable(active),
3358 L==A, !,
3359 B=M.
3360 'get_rule/2__0'(A, B, C) :- !,
3361 fail.