1 /* Generated by CHR bootstrap compiler
2 From
: chr_translate_bootstrap1
.chr
3 Date
: Fri Feb
18 13:54:42 2005
5 DO NOT EDIT
. EDIT THE CHR FILE INSTEAD
8 :-module
(chr_translate_bootstrap1
, [chr_translate
/2]).
9 :-use_module
(chr_runtime
).
10 :-style_check
(-singleton
).
11 :-style_check
(- (discontiguous
)).
12 :-use_module
(library
(lists
)).
13 :-use_module
(hprolog
).
14 :-use_module
(library
(assoc
)).
15 :-use_module
(pairlist
).
16 :-use_module
(library
(ordsets
)).
18 chr_translate
(A
, B
) :-
20 partition_clauses
(A
, C
, D
, E
),
24 unique_analyse_optimise
(D
, F
),
26 set_constraint_indices
(C
, 1),
27 store_management_preds
(C
, G
),
28 constraints_code
(C
, F
, H
),
29 append_lists
([E
, G
, H
], B
)
32 store_management_preds
(A
, B
) :-
33 generate_attach_detach_a_constraint_all
(A
, C
),
34 generate_attach_increment
(D
),
35 generate_attr_unify_hook
(E
),
36 append_lists
([C
, D
, E
], B
).
37 partition_clauses
([], [], [], []).
38 partition_clauses
([A
|B
], C
, D
, E
) :-
43 ; is_declaration
(A
, J
)
47 ; is_module_declaration
(A
, K
)
53 -> format
('CHR compiler WARNING: ~w.\n', [A
]),
54 format
(' `--> SICStus compatibility: ignoring handler/1 declaration.\n', []),
59 -> format
('CHR compiler WARNING: ~w.\n', [A
]),
60 format
(' `--> SICStus compatibility: ignoring rules/1 declaration.\n', []),
65 -> handle_option
(N
, O
),
73 partition_clauses
(B
, G
, H
, I
).
74 is_declaration
(A
, B
) :-
93 C
=pragma
(D
, E
, [], B
).
100 -> B
=rule
([], H
, I
, J
)
101 ; B
=rule
([], H
, true
, E
)
114 get_ids
(L
, N
, O
, 0, P
),
115 get_ids
(M
, Q
, R
, P
, S
),
124 get_ids
(A
, B
, C
, 0, D
).
125 get_ids
([], [], [], A
, A
).
126 get_ids
([A
|B
], [C
|D
], [E
|F
], C
, G
) :-
132 get_ids
(B
, D
, F
, H
, G
).
133 is_module_declaration
((:-module
(A
)), A
).
134 is_module_declaration
((:-module
(A
, B
)), A
).
136 check_rules
(A
, B
, 1).
137 check_rules
([], A
, B
).
138 check_rules
([A
|B
], C
, D
) :-
141 check_rules
(B
, C
, E
).
142 check_rule
(A
, B
, C
) :-
143 A
=pragma
(D
, E
, F
, G
),
146 check_head_constraints
(L
, B
, A
, C
),
147 check_pragmas
(F
, A
, C
).
148 check_head_constraints
([], A
, B
, C
).
149 check_head_constraints
([A
|B
], C
, D
, E
) :-
152 -> check_head_constraints
(B
, C
, D
, E
)
153 ; format
('CHR compiler ERROR: Undeclared constraint ~w in head of ~@.\n', [F
/G
, format_rule
(D
, E
)]),
154 format
(' `--> Constraint should be on of ~w.\n', [C
]),
157 check_pragmas
([], A
, B
).
158 check_pragmas
([A
|B
], C
, D
) :-
159 check_pragma
(A
, C
, D
),
160 check_pragmas
(B
, C
, D
).
161 check_pragma
(A
, B
, C
) :-
163 format
('CHR compiler ERROR: invalid pragma ~w in ~@.\n', [A
, format_rule
(B
, C
)]),
164 format
(' `--> Pragma should not be a variable!\n', []),
166 check_pragma
(passive
(A
), B
, C
) :- !,
167 B
=pragma
(D
, ids
(E
, F
), G
, H
),
172 ; format
('CHR compiler ERROR: invalid identifier ~w in pragma passive in ~@.\n', [A
, format_rule
(B
, C
)]),
175 check_pragma
(A
, B
, C
) :-
177 format
('CHR compiler WARNING: undocument pragma ~w in ~@.\n', [A
, format_rule
(B
, C
)]),
178 format
(' `--> Only use this pragma if you know what you are doing.\n', []).
179 check_pragma
(A
, B
, C
) :-
180 A
=already_in_heads
, !,
181 format
('CHR compiler WARNING: currently unsupported pragma ~w in ~@.\n', [A
, format_rule
(B
, C
)]),
182 format
(' `--> Pragma is ignored. Termination and correctness may be affected \n', []).
183 check_pragma
(A
, B
, C
) :-
184 A
=already_in_head
(D
), !,
185 format
('CHR compiler WARNING: currently unsupported pragma ~w in ~@.\n', [A
, format_rule
(B
, C
)]),
186 format
(' `--> Pragma is ignored. Termination and correctness may be affected \n', []).
187 check_pragma
(A
, B
, C
) :-
188 format
('CHR compiler ERROR: invalid pragma ~w in ~@.\n', [A
, format_rule
(B
, C
)]),
189 format
(' `--> Pragma should be one of passive/1!\n', []),
192 A
=pragma
(C
, D
, E
, F
),
196 ; write('rule number '),
199 handle_option
(A
, B
) :-
201 format
('CHR compiler ERROR: ~w.\n', [option
(A
, B
)]),
202 format
(' `--> First argument should be an atom, not a variable.\n', []),
204 handle_option
(A
, B
) :-
206 format
('CHR compiler ERROR: ~w.\n', [option
(A
, B
)]),
207 format
(' `--> Second argument should be a nonvariable.\n', []),
209 handle_option
(A
, B
) :-
210 option_definition
(A
, B
, C
), !,
212 handle_option
(A
, B
) :-
213 \
+option_definition
(A
, C
, D
), !.
214 handle_option
(A
, B
) :-
215 findall
(C
, option_definition
(A
, C
, D
), E
),
216 format
('CHR compiler ERROR: ~w.\n', [option
(A
, B
)]),
217 format
(' `--> Invalid value ~w: should be one of ~w.\n', [B
, E
]),
219 option_definition
(optimize
, experimental
, A
) :-
220 A
=[unique_analyse_optimise
-on
, check_unnecessary_active
-full
, reorder_heads
-on
, set_semantics_rule
-on
, check_attachments
-on
, guard_via_reschedule
-on
].
221 option_definition
(optimize
, full
, A
) :-
222 A
=[unique_analyse_optimise
-on
, check_unnecessary_active
-full
, reorder_heads
-on
, set_semantics_rule
-on
, check_attachments
-on
, guard_via_reschedule
-on
].
223 option_definition
(optimize
, sicstus
, A
) :-
224 A
=[unique_analyse_optimise
-off
, check_unnecessary_active
-simplification
, reorder_heads
-off
, set_semantics_rule
-off
, check_attachments
-off
, guard_via_reschedule
-off
].
225 option_definition
(optimize
, off
, A
) :-
226 A
=[unique_analyse_optimise
-off
, check_unnecessary_active
-off
, reorder_heads
-off
, set_semantics_rule
-off
, check_attachments
-off
, guard_via_reschedule
-off
].
227 option_definition
(debug
, off
, A
) :-
229 option_definition
(debug
, on
, A
) :-
231 option_definition
(check_guard_bindings
, on
, A
) :-
233 option_definition
(check_guard_bindings
, off
, A
) :-
236 chr_pp_flag_definition
(A
, [B
|C
]),
237 set_chr_pp_flag
(A
, B
),
240 set_chr_pp_flags
([]).
241 set_chr_pp_flags
([A
-B
|C
]) :-
242 set_chr_pp_flag
(A
, B
),
244 set_chr_pp_flag
(A
, B
) :-
245 atom_concat
('$chr_pp_', A
, C
),
247 chr_pp_flag_definition
(unique_analyse_optimise
, [on
, off
]).
248 chr_pp_flag_definition
(check_unnecessary_active
, [full
, simplification
, off
]).
249 chr_pp_flag_definition
(reorder_heads
, [on
, off
]).
250 chr_pp_flag_definition
(set_semantics_rule
, [on
, off
]).
251 chr_pp_flag_definition
(guard_via_reschedule
, [on
, off
]).
252 chr_pp_flag_definition
(guard_locks
, [on
, off
]).
253 chr_pp_flag_definition
(check_attachments
, [on
, off
]).
254 chr_pp_flag_definition
(debugable
, [off
, on
]).
256 atom_concat
('$chr_pp_', A
, C
),
259 -> chr_pp_flag_definition
(A
, [B
|E
])
262 generate_attach_detach_a_constraint_all
([], []).
263 generate_attach_detach_a_constraint_all
([A
|B
], C
) :-
265 -> generate_attach_a_constraint
(A
, D
),
266 generate_detach_a_constraint
(A
, E
)
270 generate_attach_detach_a_constraint_all
(B
, F
),
271 append_lists
([D
, E
, F
], C
).
272 generate_attach_a_constraint
(A
, [B
, C
]) :-
273 generate_attach_a_constraint_empty_list
(A
, B
),
274 get_max_constraint_index
(D
),
276 -> generate_attach_a_constraint_1_1
(A
, C
)
277 ; generate_attach_a_constraint_t_p
(A
, C
)
279 generate_attach_a_constraint_empty_list
(A
/B
, C
) :-
280 atom_concat_list
([attach_
, A
, /, B
], D
),
284 generate_attach_a_constraint_1_1
(A
/B
, C
) :-
285 atom_concat_list
([attach_
, A
, /, B
], D
),
289 get_target_module
(K
),
290 L
= ((get_attr
(F
, K
, M
)->N=[H
|M
], put_attr
(F
, K
, N
);put_attr
(F
, K
, [H
])), J
),
292 generate_attach_a_constraint_t_p
(A
/B
, C
) :-
293 atom_concat_list
([attach_
, A
, /, B
], D
),
297 get_constraint_index
(A
/B
, K
),
299 get_max_constraint_index
(M
),
300 make_attr
(M
, N
, O
, P
),
302 substitute
(Q
, O
, [H
|Q
], R
),
303 make_attr
(M
, N
, R
, S
),
304 substitute
(Q
, O
, [H
], T
),
305 make_attr
(M
, U
, T
, V
),
308 chr_delete
(W
, [H
], X
),
310 make_attr
(M
, L
, W
, Y
),
311 get_target_module
(Z
),
312 A1
= ((get_attr
(F
, Z
, B1
)->B1=P
, (N
/\L=:=L->put_attr(F, Z, S);U is N\/L
, put_attr
(F
, Z
, V
));put_attr
(F
, Z
, Y
)), J
),
314 generate_detach_a_constraint
(A
, [B
, C
]) :-
315 generate_detach_a_constraint_empty_list
(A
, B
),
316 get_max_constraint_index
(D
),
318 -> generate_detach_a_constraint_1_1
(A
, C
)
319 ; generate_detach_a_constraint_t_p
(A
, C
)
321 generate_detach_a_constraint_empty_list
(A
/B
, C
) :-
322 atom_concat_list
([detach_
, A
, /, B
], D
),
326 generate_detach_a_constraint_1_1
(A
/B
, C
) :-
327 atom_concat_list
([detach_
, A
, /, B
], D
),
331 get_target_module
(K
),
332 L
= ((get_attr
(F
, K
, M
)->'chr sbag_del_element'(M
, H
, N
), (N
==[]->del_attr(F
, K
);put_attr
(F
, K
, N
));true
), J
),
334 generate_detach_a_constraint_t_p
(A
/B
, C
) :-
335 atom_concat_list
([detach_
, A
, /, B
], D
),
339 get_constraint_index
(A
/B
, K
),
342 get_max_constraint_index
(N
),
343 make_attr
(N
, O
, P
, Q
),
345 substitute
(R
, P
, [], S
),
346 make_attr
(N
, T
, S
, U
),
347 substitute
(R
, P
, V
, W
),
348 make_attr
(N
, O
, W
, X
),
349 get_target_module
(Y
),
350 Z
= ((get_attr
(F
, Y
, A1
)->A1=Q
, (O
/\L=:=L->'chr sbag_del_element'(R, H, V), (V==[]->T is O/\M
, (T
==0->del_attr(F
, Y
);put_attr
(F
, Y
, U
));put_attr
(F
, Y
, X
));true
);true
), J
),
352 generate_attach_increment
([A
, B
]) :-
353 generate_attach_increment_empty
(A
),
354 get_max_constraint_index
(C
),
356 -> generate_attach_increment_one
(B
)
357 ; generate_attach_increment_many
(C
, B
)
359 generate_attach_increment_empty
((attach_increment
([], A
):-true
)).
360 generate_attach_increment_one
(A
) :-
361 B
=attach_increment
([C
|D
], E
),
362 get_target_module
(F
),
363 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
)),
365 generate_attach_increment_many
(A
, B
) :-
366 make_attr
(A
, C
, D
, E
),
367 make_attr
(A
, F
, G
, H
),
368 I
=attach_increment
([J
|K
], E
),
369 bagof
(L
, M
^N
^O
^P
^ (member2
(D
, G
, M
-N
), L
= (sort(N
, O
), 'chr merge_attributes'(M
, O
, P
))), Q
),
371 bagof
(S
, T
^U
^V
^member
((T
, 'chr merge_attributes'(U
, V
, S
)), Q
), W
),
372 make_attr
(A
, X
, W
, Y
),
373 get_target_module
(Z
),
374 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
)),
376 generate_attr_unify_hook
([A
]) :-
377 get_max_constraint_index
(B
),
379 -> generate_attr_unify_hook_one
(A
)
380 ; generate_attr_unify_hook_many
(B
, A
)
382 generate_attr_unify_hook_one
(A
) :-
383 B
=C
:attr_unify_hook
(D
, E
),
384 get_target_module
(C
),
385 make_run_suspensions
(F
, G
),
386 make_run_suspensions
(D
, H
),
387 I
= (sort(D
, J
), (var
(E
)-> (get_attr
(E
, C
, K
)->true;K
=[]), sort(K
, L
), 'chr merge_attributes'(J
, L
, F
), put_attr
(E
, C
, F
), G
; (compound
(E
)->term_variables(E
, M
), attach_increment
(M
, J
);true
), H
)),
389 generate_attr_unify_hook_many
(A
, B
) :-
390 make_attr
(A
, C
, D
, E
),
391 make_attr
(A
, F
, G
, H
),
392 bagof
(I
, J
^K
^ (member
(J
, D
), I
=sort(J
, K
)), L
),
394 bagof
(K
, J
^member
(sort(J
, K
), L
), N
),
395 bagof
(O
, P
^Q
^R
^S
^ (member2
(N
, G
, P
-Q
), O
= (sort(Q
, R
), 'chr merge_attributes'(P
, R
, S
))), T
),
396 bagof
(S
, P
^R
^U
^member
((U
, 'chr merge_attributes'(P
, R
, S
)), T
), V
),
398 make_attr
(A
, X
, V
, Y
),
399 make_attr
(A
, C
, N
, Z
),
400 A1
=B1
:attr_unify_hook
(E
, C1
),
401 get_target_module
(B1
),
402 make_run_suspensions_loop
(V
, D1
),
403 make_run_suspensions_loop
(N
, E1
),
404 F1
= (M
, (var
(C1
)-> (get_attr
(C1
, B1
, G1
)->G1=H
, W
, X is C\
/F
, put_attr
(C1
, B1
, Y
), D1
;put_attr
(C1
, B1
, Z
), E1
); (compound
(C1
)->term_variables(C1
, H1
), attach_increment
(H1
, Z
);true
), E1
)),
406 make_run_suspensions
(A
, B
) :-
407 ( chr_pp_flag
(debugable
, on
)
408 -> B
='chr run_suspensions_d'(A
)
409 ; B
='chr run_suspensions'(A
)
411 make_run_suspensions_loop
(A
, B
) :-
412 ( chr_pp_flag
(debugable
, on
)
413 -> B
='chr run_suspensions_loop_d'(A
)
414 ; B
='chr run_suspensions_loop'(A
)
416 check_attachments
(A
) :-
417 ( chr_pp_flag
(check_attachments
, on
)
418 -> check_attachments_
(A
)
421 check_attachments_
([]).
422 check_attachments_
([A
|B
]) :-
424 check_attachments_
(B
).
425 check_attachment
(A
) :-
426 A
=pragma
(B
, C
, D
, E
),
428 check_attachment_heads1
(F
, F
, G
, H
),
429 check_attachment_heads2
(G
, F
, I
).
430 check_attachment_heads1
([], A
, B
, C
).
431 check_attachment_heads1
([A
|B
], C
, D
, E
) :-
439 ; attached
(F
/G
, maybe
)
441 check_attachment_heads1
(B
, C
, D
, E
).
443 no_matching
([A
|B
], C
) :-
445 \
+memberchk_eq
(A
, C
),
446 no_matching
(B
, [A
|C
]).
447 check_attachment_heads2
([], A
, B
).
448 check_attachment_heads2
([A
|B
], C
, D
) :-
452 -> attached
(E
/F
, maybe
)
455 check_attachment_heads2
(B
, C
, D
).
457 all_attached
([A
|B
]) :-
461 set_constraint_indices
([], A
) :-
463 max_constraint_index
(B
).
464 set_constraint_indices
([A
|B
], C
) :-
466 -> constraint_index
(A
, C
),
468 set_constraint_indices
(B
, D
)
469 ; set_constraint_indices
(B
, C
)
471 constraints_code
(A
, B
, C
) :-
472 post_constraints
(A
, 1),
473 constraints_code1
(1, B
, D
, []),
475 post_constraints
([], A
) :-
478 post_constraints
([A
/B
|C
], D
) :-
481 post_constraints
(C
, E
).
482 constraints_code1
(A
, B
, C
, D
) :-
486 ; constraint_code
(A
, B
, C
, F
),
488 constraints_code1
(G
, B
, F
, D
)
490 constraint_code
(A
, B
, C
, D
) :-
492 constraint_prelude
(E
, F
),
495 rules_code
(B
, 1, A
, H
, I
, G
, J
),
496 gen_cond_attach_clause
(E
, I
, J
, D
).
497 constraint_prelude
(A
/B
, C
) :-
498 vars_susp
(B
, D
, E
, F
),
500 build_head
(A
, B
, [0], F
, H
),
501 get_target_module
(I
),
502 ( chr_pp_flag
(debugable
, on
)
503 -> C
= (G
:-'chr allocate_constraint'(I
:H
, E
, A
, D
), ('chr debug_event'(call
(E
)), H
;'chr debug_event'(fail
(E
)), !, fail
), ('chr debug_event'(exit(E
));'chr debug_event'(redo(E
)), fail
))
506 gen_cond_attach_clause
(A
/B
, C
, D
, E
) :-
509 -> gen_cond_attach_goal
(A
/B
, F
, G
, H
, I
)
510 ; vars_susp
(B
, H
, I
, G
),
511 gen_uncond_attach_goal
(A
/B
, I
, F
, J
)
513 ( chr_pp_flag
(debugable
, on
)
515 L
='chr debug_event'(insert
(#(K, I)))
518 build_head
(A
, B
, C
, G
, M
),
523 gen_cond_attach_goal
(A
/B
, C
, D
, E
, F
) :-
524 vars_susp
(B
, E
, F
, D
),
525 build_head
(A
, B
, [0], D
, G
),
526 atom_concat_list
([attach_
, A
, /, B
], H
),
528 get_target_module
(K
),
529 C
= ((var
(F
)->'chr insert_constraint_internal'(J
, F
, K
:G
, A
, E
);'chr activate_constraint'(J
, F
, L
)), I
).
530 gen_uncond_attach_goal
(A
/B
, C
, D
, E
) :-
531 atom_concat_list
([attach_
, A
, /, B
], F
),
533 D
= ('chr activate_constraint'(H
, C
, E
), G
).
534 rules_code
([], A
, B
, C
, C
, D
, D
).
535 rules_code
([A
|B
], C
, D
, E
, F
, G
, H
) :-
536 rule_code
(A
, C
, D
, E
, I
, G
, J
),
538 rules_code
(B
, K
, D
, I
, F
, J
, H
).
539 rule_code
(A
, B
, C
, D
, E
, F
, G
) :-
540 A
=pragma
(H
, I
, J
, K
),
543 heads1_code
(N
, [], L
, [], A
, C
, D
, F
, R
),
544 heads2_code
(O
, [], M
, [], A
, B
, C
, D
, E
, R
, G
).
545 heads1_code
([], A
, B
, C
, D
, E
, F
, G
, G
).
546 heads1_code
([A
|B
], C
, [D
|E
], F
, G
, H
, I
, J
, K
) :-
547 G
=pragma
(L
, M
, N
, O
),
550 \
+check_unnecessary_active
(A
, C
, L
),
551 \
+memberchk_eq
(passive
(D
), N
),
558 head1_code
(A
, V
, W
, G
, P
/Q
, H
, I
, J
, X
)
561 heads1_code
(B
, [A
|C
], E
, [D
|F
], G
, H
, I
, X
, K
).
562 head1_code
(A
, B
, C
, D
, E
, F
, G
, H
, I
) :-
563 D
=pragma
(J
, K
, L
, M
),
566 -> reorder_heads
(A
, B
, C
, R
, S
),
567 simplification_code
(A
, R
, S
, D
, E
, G
, H
, I
)
568 ; simpagation_head1_code
(A
, B
, C
, D
, E
, G
, H
, I
)
570 heads2_code
([], A
, B
, C
, D
, E
, F
, G
, G
, H
, H
).
571 heads2_code
([A
|B
], C
, [D
|E
], F
, G
, H
, I
, J
, K
, L
, M
) :-
572 G
=pragma
(N
, O
, P
, Q
),
575 \
+check_unnecessary_active
(A
, C
, N
),
576 \
+memberchk_eq
(passive
(D
), P
),
577 \
+set_semantics_rule
(G
),
585 head2_code
(A
, X
, Y
, G
, H
, Z
, R
/S
, J
, L
, A1
),
587 gen_alloc_inc_clause
(R
/S
, J
, A1
, C1
)
591 heads2_code
(B
, [A
|C
], E
, [D
|F
], G
, H
, I
, B1
, K
, C1
, M
).
592 head2_code
(A
, B
, C
, D
, E
, F
, G
, H
, I
, J
) :-
593 D
=pragma
(K
, L
, M
, N
),
596 -> reorder_heads
(A
, B
, S
),
597 propagation_code
(A
, S
, K
, E
, F
, G
, H
, I
, J
)
598 ; simpagation_head2_code
(A
, B
, C
, D
, G
, H
, I
, J
)
600 gen_alloc_inc_clause
(A
/B
, C
, D
, E
) :-
601 vars_susp
(B
, F
, G
, H
),
602 build_head
(A
, B
, C
, H
, I
),
604 build_head
(A
, B
, J
, H
, K
),
606 -> gen_cond_allocation
(F
, G
, A
/B
, H
, L
)
611 gen_cond_allocation
(A
, B
, C
/D
, E
, F
) :-
612 build_head
(C
, D
, [0], E
, G
),
613 get_target_module
(H
),
614 F
= (var
(B
)->'chr allocate_constraint'(H
:G
, B
, C
, A
);true
).
615 guard_via_reschedule
(A
, B
, C
, D
) :-
616 ( chr_pp_flag
(guard_via_reschedule
, on
)
617 -> guard_via_reschedule_main
(A
, B
, C
, D
)
621 guard_via_reschedule_main
(A
, B
, C
, D
) :-
622 initialize_unit_dictionary
(C
, E
),
623 build_units
(A
, B
, E
, F
),
624 dependency_reorder
(F
, G
),
626 units2goal
([], true
).
627 units2goal
([unit
(A
, B
, C
, D
)|E
], (B
, F
)) :-
629 dependency_reorder
(A
, B
) :-
630 dependency_reorder
(A
, [], B
).
631 dependency_reorder
([], A
, B
) :-
633 dependency_reorder
([A
|B
], C
, D
) :-
637 ; dependency_insert
(C
, A
, H
, I
)
639 dependency_reorder
(B
, I
, D
).
640 dependency_insert
([], A
, B
, [A
]).
641 dependency_insert
([A
|B
], C
, D
, E
) :-
646 dependency_insert
(B
, C
, D
, J
)
648 build_units
(A
, B
, C
, D
) :-
649 build_retrieval_units
(A
, 1, E
, C
, F
, D
, G
),
650 build_guard_units
(B
, E
, F
, G
).
651 build_retrieval_units
([], A
, A
, B
, B
, C
, C
).
652 build_retrieval_units
([A
|B
], C
, D
, E
, F
, G
, H
) :-
653 term_variables
(A
, I
),
654 update_unit_dictionary
(I
, C
, E
, J
, [], K
),
655 G
=[unit
(C
, A
, movable
, K
)|L
],
657 build_retrieval_units2
(B
, M
, D
, J
, F
, L
, H
).
658 build_retrieval_units2
([], A
, A
, B
, B
, C
, C
).
659 build_retrieval_units2
([A
|B
], C
, D
, E
, F
, G
, H
) :-
660 term_variables
(A
, I
),
661 update_unit_dictionary
(I
, C
, E
, J
, [], K
),
662 G
=[unit
(C
, A
, fixed
, K
)|L
],
664 build_retrieval_units
(B
, M
, D
, J
, F
, L
, H
).
665 initialize_unit_dictionary
(A
, B
) :-
666 term_variables
(A
, C
),
667 pair_all_with
(C
, 0, B
).
668 update_unit_dictionary
([], A
, B
, B
, C
, C
).
669 update_unit_dictionary
([A
|B
], C
, D
, E
, F
, G
) :-
681 update_unit_dictionary
(B
, C
, J
, E
, I
, G
).
682 build_guard_units
(A
, B
, C
, D
) :-
684 -> D
=[unit
(B
, E
, fixed
, [])]
686 -> term_variables
(E
, G
),
687 update_unit_dictionary2
(G
, B
, C
, H
, [], I
),
688 D
=[unit
(B
, E
, movable
, I
)|J
],
690 build_guard_units
(F
, K
, H
, J
)
692 update_unit_dictionary2
([], A
, B
, B
, C
, C
).
693 update_unit_dictionary2
([A
|B
], C
, D
, E
, F
, G
) :-
705 update_unit_dictionary2
(B
, C
, J
, E
, I
, G
).
706 unique_analyse_optimise
(A
, B
) :-
707 ( chr_pp_flag
(unique_analyse_optimise
, on
)
708 -> unique_analyse_optimise_main
(A
, 1, [], B
)
711 unique_analyse_optimise_main
([], A
, B
, []).
712 unique_analyse_optimise_main
([A
|B
], C
, D
, [E
|F
]) :-
713 ( discover_unique_pattern
(A
, C
, G
)
717 A
=pragma
(I
, J
, K
, L
),
720 apply_unique_patterns_to_constraints
(M
, Q
, H
, S
),
721 apply_unique_patterns_to_constraints
(N
, R
, H
, T
),
722 append_lists
([S
, T
, K
], U
),
723 E
=pragma
(I
, J
, U
, L
),
725 unique_analyse_optimise_main
(B
, V
, H
, F
).
726 apply_unique_patterns_to_constraints
([], A
, B
, []).
727 apply_unique_patterns_to_constraints
([A
|B
], [C
|D
], E
, F
) :-
729 apply_unique_pattern
(A
, C
, G
, H
)
733 apply_unique_patterns_to_constraints
(B
, D
, E
, I
).
734 apply_unique_pattern
(A
, B
, C
, D
) :-
737 ( setof
(H
, I
^J
^K
^ (member
(I
, F
), lookup_eq
(G
, I
, J
), term_variables
(J
, K
), member
(H
, K
)), L
)
744 subsumes_aux
(A
, B
, D
, E
),
747 subsumes_aux
(A
, B
, C
, D
) :-
752 subsumes_aux
(F
, A
, B
, C
, D
)
760 put_assoc
(A
, C
, B
, D
)
762 subsumes_aux
(0, A
, B
, C
, C
) :- !.
763 subsumes_aux
(A
, B
, C
, D
, E
) :-
766 subsumes_aux
(F
, G
, D
, H
),
768 subsumes_aux
(I
, B
, C
, H
, E
).
769 build_unifier
([], []).
770 build_unifier
([A
-B
|C
], [B
-A
|D
]) :-
772 discover_unique_pattern
(A
, B
, C
) :-
773 A
=pragma
(D
, E
, F
, G
),
774 ( D
=rule
([H
], [I
], J
, K
)
776 ; D
=rule
([H
, I
], [], J
, K
)
778 check_unique_constraints
(H
, I
, J
, K
, F
, L
),
779 term_variables
(H
, M
),
780 select_pragma_unique_variables
(L
, M
, N
),
783 ( prolog_flag
(verbose
, P
),
785 -> format
('Found unique pattern ~w in rule ~d~@\n', [C
, B
, (G
=yes
(Q
)->write([58, 32]), write(Q
);true
)])
788 select_pragma_unique_variables
([], A
, []).
789 select_pragma_unique_variables
([A
-B
|C
], D
, E
) :-
793 ( \
+memberchk_eq
(A
, D
)
794 ; \
+memberchk_eq
(B
, D
)
799 select_pragma_unique_variables
(C
, D
, F
).
800 check_unique_constraints
(A
, B
, C
, D
, E
, F
) :-
801 \
+member
(passive
(G
), E
),
802 variable_replacement
(A
-B
, B
-A
, F
),
803 copy_with_variable_replacement
(C
, H
, F
),
812 negate
(var
(A
), nonvar
(A
)).
813 negate
(nonvar
(A
), var
(A
)).
817 entails
(A
>B
, C
>=D
) :-
820 entails
(A
<B
, C
=<D
) :-
823 entails
(ground
(A
), nonvar
(B
)) :-
825 entails
(compound
(A
), nonvar
(B
)) :-
827 entails
(atomic
(A
), nonvar
(B
)) :-
829 entails
(number
(A
), nonvar
(B
)) :-
831 entails
(atom
(A
), nonvar
(B
)) :-
833 check_unnecessary_active
(A
, B
, C
) :-
834 ( chr_pp_flag
(check_unnecessary_active
, full
)
835 -> check_unnecessary_active_main
(A
, B
, C
)
836 ; chr_pp_flag
(check_unnecessary_active
, simplification
),
838 -> check_unnecessary_active_main
(A
, B
, C
)
841 check_unnecessary_active_main
(A
, B
, C
) :-
843 variable_replacement
(D
, A
, E
),
844 copy_with_variable_replacement
(C
, F
, E
),
845 identical_rules
(C
, F
), !.
846 set_semantics_rule
(A
) :-
847 ( chr_pp_flag
(set_semantics_rule
, on
)
848 -> set_semantics_rule_main
(A
)
851 set_semantics_rule_main
(A
) :-
852 A
=pragma
(B
, C
, D
, E
),
853 B
=rule
([F
], [G
], true
, H
),
855 once
(member
(unique
(I
, K
), D
)),
856 once
(member
(unique
(J
, L
), D
)),
858 \
+memberchk_eq
(passive
(I
), D
).
859 identical_rules
(rule
(A
, B
, C
, D
), rule
(E
, F
, G
, H
)) :-
861 identical_bodies
(D
, H
),
866 identical_bodies
(A
, B
) :-
876 copy_with_variable_replacement
(A
, B
, C
) :-
878 -> ( lookup_eq
(C
, A
, B
)
886 copy_with_variable_replacement_l
(G
, I
, C
)
888 copy_with_variable_replacement_l
([], [], A
).
889 copy_with_variable_replacement_l
([A
|B
], [C
|D
], E
) :-
890 copy_with_variable_replacement
(A
, C
, E
),
891 copy_with_variable_replacement_l
(B
, D
, E
).
892 variable_replacement
(A
, B
, C
) :-
893 variable_replacement
(A
, B
, [], C
).
894 variable_replacement
(A
, B
, C
, D
) :-
905 variable_replacement_l
(G
, H
, C
, D
)
907 variable_replacement_l
([], [], A
, A
).
908 variable_replacement_l
([A
|B
], [C
|D
], E
, F
) :-
909 variable_replacement
(A
, C
, E
, G
),
910 variable_replacement_l
(B
, D
, G
, F
).
911 simplification_code
(A
, B
, C
, D
, E
/F
, G
, H
, I
) :-
912 D
=pragma
(J
, K
, L
, M
),
913 head_info
(A
, F
, N
, O
, P
, Q
),
914 build_head
(E
, F
, G
, P
, R
),
915 head_arg_matches
(Q
, [], S
, T
),
920 ; rest_heads_retrieval_and_matching
(B
, C
, L
, A
, W
, U
, T
, V
)
922 guard_body_copies2
(J
, V
, X
, Y
),
923 guard_via_reschedule
(W
, X
, R
-S
, Z
),
924 gen_uncond_susps_detachments
(U
, B
, A1
),
925 gen_cond_susp_detachment
(O
, E
/F
, B1
),
926 ( chr_pp_flag
(debugable
, on
)
927 -> J
=rule
(C1
, D1
, E1
, F1
),
928 my_term_copy
(E1
-F1
, V
, G1
, H1
-I1
),
929 J1
='chr debug_event'(try
([O
|K1
], [], H1
, I1
)),
930 L1
='chr debug_event'(apply
([O
|K1
], [], H1
, I1
))
934 M1
= (R
:-S
, Z
, J1
, !, L1
, A1
, B1
, Y
),
936 head_arg_matches
(A
, B
, C
, D
) :-
937 head_arg_matches_
(A
, B
, E
, D
),
939 head_arg_matches_
([], A
, [], A
).
940 head_arg_matches_
([A
-B
|C
], D
, E
, F
) :-
942 -> ( lookup_eq
(D
, A
, G
)
957 E
=[nonvar
(B
), B
=O
|H
],
962 head_arg_matches_
(J
, I
, H
, F
).
963 rest_heads_retrieval_and_matching
(A
, B
, C
, D
, E
, F
, G
, H
) :-
964 rest_heads_retrieval_and_matching
(A
, B
, C
, D
, E
, F
, G
, H
, [], [], []).
965 rest_heads_retrieval_and_matching
(A
, B
, C
, D
, E
, F
, G
, H
, I
, J
, K
) :-
967 -> rest_heads_retrieval_and_matching_n
(A
, B
, C
, I
, J
, D
, E
, F
, G
, H
, K
)
972 rest_heads_retrieval_and_matching_n
([], A
, B
, C
, D
, E
, [], [], F
, F
, G
) :-
973 instantiate_pattern_goals
(G
).
974 rest_heads_retrieval_and_matching_n
([A
|B
], [C
|D
], E
, F
, G
, H
, [I
, J
|K
], [L
|M
], N
, O
, P
) :-
975 passive_head_via
(A
, [H
|F
], P
, N
, I
, Q
, R
),
977 head_info
(A
, T
, U
, V
, W
, X
),
978 head_arg_matches
(X
, N
, Y
, Z
),
979 A1
=..[suspension
, B1
, C1
, D1
, E1
, F1
, G1
|U
],
980 get_max_constraint_index
(H1
),
983 ; get_constraint_index
(S
/T
, J1
),
984 make_attr
(H1
, K1
, L1
, Q
),
987 different_from_other_susps
(A
, L
, F
, G
, M1
),
988 create_get_mutable
(active
, C1
, N1
),
989 O1
= ('chr sbag_member'(L
, I1
), L
=A1
, N1
, M1
, Y
),
990 ( member
(unique
(C
, P1
), E
),
991 check_unique_keys
(P1
, N
)
995 rest_heads_retrieval_and_matching_n
(B
, D
, E
, [A
|F
], [L
|G
], H
, K
, M
, Z
, O
, R
).
996 instantiate_pattern_goals
([]).
997 instantiate_pattern_goals
([A
-attr
(B
, C
, D
)|E
]) :-
998 get_max_constraint_index
(F
),
1001 ; make_attr
(F
, G
, H
, B
),
1005 instantiate_pattern_goals
(E
).
1006 check_unique_keys
([], A
).
1007 check_unique_keys
([A
|B
], C
) :-
1009 check_unique_keys
(B
, C
).
1010 different_from_other_susps
(A
, B
, C
, D
, E
) :-
1011 ( bagof
(F
, G
^ (nth
(G
, C
, H
), \
+A\
=H
, nth
(G
, D
, I
), F
= (B\
==I
)), J
)
1015 passive_head_via
(A
, B
, C
, D
, E
, F
, G
) :-
1017 get_constraint_index
(H
/I
, J
),
1018 common_variables
(A
, B
, K
),
1021 ( permutation
(L
, N
),
1022 lookup_eq
(C
, N
, attr
(F
, O
, P
))
1027 gen_get_mod_constraints
(L
, Q
, F
),
1028 G
=[L
-attr
(F
, [M
|S
], R
)|C
]
1030 common_variables
(A
, B
, C
) :-
1031 term_variables
(A
, D
),
1032 term_variables
(B
, E
),
1033 intersect_eq
(D
, E
, C
).
1034 gen_get_mod_constraints
(A
, B
, C
) :-
1035 get_target_module
(D
),
1037 -> B
= ('chr global_term_ref_1'(E
), get_attr
(E
, D
, F
), F
=C
)
1039 -> H
='chr via_1'(G
, I
)
1041 -> H
='chr via_2'(G
, J
, I
)
1044 B
= (H
, get_attr
(I
, D
, F
), F
=C
)
1046 guard_body_copies
(A
, B
, C
, D
) :-
1047 guard_body_copies2
(A
, B
, E
, D
),
1049 guard_body_copies2
(A
, B
, C
, D
) :-
1052 split_off_simple_guard
(I
, B
, J
, K
),
1053 my_term_copy
(J
-K
, B
, L
, M
-N
),
1055 term_variables
(K
, P
),
1056 term_variables
(N
, Q
),
1057 ( chr_pp_flag
(guard_locks
, on
),
1058 bagof
('chr lock'(R
)-'chr unlock'(R
), S
^ (member
(S
, P
), lookup_eq
(B
, S
, R
), memberchk_eq
(R
, Q
)), T
)
1059 -> once
(pairup
(U
, V
, T
))
1067 my_term_copy
(H
, L
, D
).
1068 split_off_simple_guard
([], A
, [], []).
1069 split_off_simple_guard
([A
|B
], C
, D
, E
) :-
1070 ( simple_guard
(A
, C
)
1072 split_off_simple_guard
(B
, C
, F
, E
)
1076 simple_guard
(var
(A
), B
).
1077 simple_guard
(nonvar
(A
), B
).
1078 simple_guard
(ground
(A
), B
).
1079 simple_guard
(number
(A
), B
).
1080 simple_guard
(atom
(A
), B
).
1081 simple_guard
(integer
(A
), B
).
1082 simple_guard
(float
(A
), B
).
1083 simple_guard
(A
>B
, C
).
1084 simple_guard
(A
<B
, C
).
1085 simple_guard
(A
=<B
, C
).
1086 simple_guard
(A
>=B
, C
).
1087 simple_guard
(A
=:=B
, C
).
1088 simple_guard
(A
==B
, C
).
1089 simple_guard
(A is B
, C
) :-
1090 \
+lookup_eq
(C
, A
, D
).
1091 simple_guard
((A
, B
), C
) :-
1094 simple_guard
(\
+A
, B
) :-
1096 my_term_copy
(A
, B
, C
) :-
1097 my_term_copy
(A
, B
, D
, C
).
1098 my_term_copy
(A
, B
, C
, D
) :-
1100 -> ( lookup_eq
(B
, A
, D
)
1108 my_term_copy_list
(H
, B
, C
, J
)
1110 my_term_copy_list
([], A
, A
, []).
1111 my_term_copy_list
([A
|B
], C
, D
, [E
|F
]) :-
1112 my_term_copy
(A
, C
, G
, E
),
1113 my_term_copy_list
(B
, G
, D
, F
).
1114 gen_cond_susp_detachment
(A
, B
, C
) :-
1116 -> gen_uncond_susp_detachment
(A
, B
, D
),
1120 gen_uncond_susp_detachment
(A
, B
/C
, D
) :-
1122 -> atom_concat_list
([detach_
, B
, /, C
], E
),
1124 ( chr_pp_flag
(debugable
, on
)
1125 -> H
='chr debug_event'(remove
(A
))
1128 D
= (H
, 'chr remove_constraint_internal'(A
, G
), F
)
1131 gen_uncond_susps_detachments
([], [], true
).
1132 gen_uncond_susps_detachments
([A
|B
], [C
|D
], (E
, F
)) :-
1134 gen_uncond_susp_detachment
(A
, G
/H
, E
),
1135 gen_uncond_susps_detachments
(B
, D
, F
).
1136 simpagation_head1_code
(A
, B
, C
, D
, E
/F
, G
, H
, I
) :-
1137 D
=pragma
(J
, ids
(K
, L
), M
, N
),
1139 head_info
(A
, F
, S
, T
, U
, V
),
1140 head_arg_matches
(V
, [], W
, X
),
1141 build_head
(E
, F
, G
, U
, Y
),
1144 reorder_heads
(A
, Z
, A1
, B1
, C1
),
1145 rest_heads_retrieval_and_matching
(B1
, C1
, M
, A
, D1
, E1
, X
, F1
),
1146 split_by_ids
(C1
, E1
, C
, G1
, H1
),
1147 guard_body_copies2
(J
, F1
, I1
, J1
),
1148 guard_via_reschedule
(D1
, I1
, Y
-W
, K1
),
1149 gen_uncond_susps_detachments
(G1
, B
, L1
),
1150 gen_cond_susp_detachment
(T
, E
/F
, M1
),
1151 ( chr_pp_flag
(debugable
, on
)
1152 -> my_term_copy
(Q
-R
, F1
, N1
, O1
-P1
),
1153 Q1
='chr debug_event'(try
([T
|G1
], H1
, O1
, P1
)),
1154 R1
='chr debug_event'(apply
([T
|G1
], H1
, O1
, P1
))
1158 S1
= (Y
:-W
, K1
, Q1
, !, R1
, L1
, M1
, J1
),
1160 split_by_ids
([], [], A
, [], []).
1161 split_by_ids
([A
|B
], [C
|D
], E
, F
, G
) :-
1162 ( memberchk_eq
(A
, E
)
1168 split_by_ids
(B
, D
, E
, H
, I
).
1169 simpagation_head2_code
(A
, B
, C
, D
, E
, F
, G
, H
) :-
1170 D
=pragma
(I
, ids
(J
, K
), L
, M
),
1172 reorder_heads
(A
, N
, J
, [R
|S
], [T
|U
]),
1173 simpagation_head2_prelude
(A
, R
, [B
, N
, P
, Q
], E
, F
, G
, V
),
1175 simpagation_head2_worker
(A
, R
, T
, S
, U
, B
, C
, I
, L
, E
, W
, V
, H
).
1176 simpagation_head2_prelude
(A
, B
, C
, D
/E
, F
, G
, H
) :-
1177 head_info
(A
, E
, I
, J
, K
, L
),
1178 build_head
(D
, E
, F
, K
, M
),
1179 head_arg_matches
(L
, [], N
, O
),
1180 passive_head_via
(B
, [A
], [], O
, P
, Q
, R
),
1181 instantiate_pattern_goals
(R
),
1182 get_max_constraint_index
(S
),
1186 get_constraint_index
(U
/V
, W
),
1187 make_attr
(S
, X
, Y
, Q
),
1191 -> gen_cond_allocation
(I
, J
, D
/E
, K
, Z
)
1195 extra_active_delegate_variables
(A
, C
, O
, B1
),
1196 append
([T
|K
], B1
, C1
),
1197 build_head
(D
, E
, A1
, C1
, D1
),
1198 E1
= (M
:-N
, P
, !, Z
, D1
),
1200 extra_active_delegate_variables
(A
, B
, C
, D
) :-
1202 delegate_variables
(A
, B
, C
, F
, D
).
1203 passive_delegate_variables
(A
, B
, C
, D
, E
) :-
1204 term_variables
(B
, F
),
1205 delegate_variables
(A
, C
, D
, F
, E
).
1206 delegate_variables
(A
, B
, C
, D
, E
) :-
1207 term_variables
(A
, F
),
1208 term_variables
(B
, G
),
1209 intersect_eq
(F
, G
, H
),
1210 list_difference_eq
(H
, D
, I
),
1212 simpagation_head2_worker
(A
, B
, C
, D
, E
, F
, G
, H
, I
, J
, K
, L
, M
) :-
1214 simpagation_head2_worker_end
(A
, [B
, D
, F
, P
, Q
], J
, K
, L
, R
),
1215 simpagation_head2_worker_body
(A
, B
, C
, D
, E
, F
, G
, H
, I
, J
, K
, R
, M
).
1216 simpagation_head2_worker_body
(A
, B
, C
, D
, E
, F
, G
, H
, I
, J
/K
, L
, M
, N
) :-
1219 head_info
(A
, K
, Q
, R
, S
, T
),
1220 head_arg_matches
(T
, [], U
, V
),
1222 extra_active_delegate_variables
(A
, [B
, D
, F
, Y
, Z
], V
, A1
),
1223 append
([[O
|P
]|S
], A1
, B1
),
1224 build_head
(J
, K
, L
, B1
, C1
),
1226 head_info
(B
, E1
, F1
, G1
, H1
, I1
),
1227 head_arg_matches
(I1
, V
, J1
, K1
),
1228 L1
=..[suspension
, M1
, N1
, O1
, P1
, Q1
, R1
|F1
],
1229 create_get_mutable
(active
, N1
, S1
),
1234 -> append
(D
, F
, U1
),
1236 reorder_heads
(B
-A
, U1
, V1
, W1
, X1
),
1237 rest_heads_retrieval_and_matching
(W1
, X1
, I
, [B
, A
], Y1
, Z1
, K1
, A2
, [B
], [O
], []),
1238 split_by_ids
(X1
, Z1
, E
, B2
, C2
)
1244 gen_uncond_susps_detachments
([O
|B2
], [B
|D
], D2
),
1245 append
([P
|S
], A1
, E2
),
1246 build_head
(J
, K
, L
, E2
, F2
),
1247 append
([[]|S
], A1
, G2
),
1248 build_head
(J
, K
, L
, G2
, H2
),
1249 guard_body_copies2
(H
, A2
, I2
, J2
),
1250 guard_via_reschedule
(Y1
, I2
, v
(C1
, T1
, J1
), K2
),
1252 -> gen_uncond_attach_goal
(J
/K
, R
, L2
, M2
),
1253 gen_state_cond_call
(R
, K
, F2
, M2
, N2
),
1254 gen_state_cond_call
(R
, K
, H2
, M2
, O2
)
1259 ( chr_pp_flag
(debugable
, on
)
1260 -> my_term_copy
(Y
-Z
, A2
, P2
, Q2
-R2
),
1261 S2
='chr debug_event'(try
([O
|B2
], [R
|C2
], Q2
, R2
)),
1262 T2
='chr debug_event'(apply
([O
|B2
], [R
|C2
], Q2
, R2
))
1266 ( member
(unique
(C
, U2
), I
),
1267 check_unique_keys
(U2
, V
)
1268 -> V2
= (C1
:-T1
, J1
-> (K2
, S2
->T2, D2
, L2
, J2
, O2
;H2
);F2
)
1269 ; V2
= (C1
:-T1
, J1
, K2
, S2
->T2, D2
, L2
, J2
, N2
;F2
)
1272 gen_state_cond_call
(A
, B
, C
, D
, E
) :-
1274 G
=..[suspension
, H
, I
, J
, K
, L
, M
|F
],
1275 create_get_mutable
(active
, I
, N
),
1276 create_get_mutable
(D
, K
, O
),
1277 E
= (A
=G
, N
, O
->'chr update_mutable'(inactive
, I
), C
;true
).
1278 simpagation_head2_worker_end
(A
, B
, C
/D
, E
, F
, G
) :-
1279 head_info
(A
, D
, H
, I
, J
, K
),
1280 head_arg_matches
(K
, [], L
, M
),
1281 extra_active_delegate_variables
(A
, B
, M
, N
),
1282 append
([[]|J
], N
, O
),
1283 build_head
(C
, D
, E
, O
, P
),
1285 build_head
(C
, D
, Q
, J
, R
),
1288 propagation_code
(A
, B
, C
, D
, E
, F
, G
, H
, I
) :-
1290 -> propagation_single_headed
(A
, C
, D
, F
, G
, H
, I
)
1291 ; propagation_multi_headed
(A
, B
, C
, D
, E
, F
, G
, H
, I
)
1293 propagation_single_headed
(A
, B
, C
, D
/E
, F
, G
, H
) :-
1294 head_info
(A
, E
, I
, J
, K
, L
),
1295 build_head
(D
, E
, F
, K
, M
),
1297 build_head
(D
, E
, N
, K
, O
),
1299 head_arg_matches
(L
, [], Q
, R
),
1300 guard_body_copies
(B
, R
, S
, T
),
1302 -> gen_cond_allocation
(I
, J
, D
/E
, K
, U
),
1306 gen_uncond_attach_goal
(D
/E
, J
, W
, X
),
1307 gen_state_cond_call
(J
, E
, P
, X
, Y
),
1308 ( chr_pp_flag
(debugable
, on
)
1309 -> B
=rule
(Z
, A1
, B1
, C1
),
1310 my_term_copy
(B1
-C1
, R
, D1
, E1
-F1
),
1311 G1
='chr debug_event'(try
([], [J
], E1
, F1
)),
1312 H1
='chr debug_event'(apply
([], [J
], E1
, F1
))
1316 I1
= (M
:-Q
, V
, 'chr novel_production'(J
, C
), S
, G1
, !, H1
, 'chr extend_history'(J
, C
), W
, T
, Y
),
1318 propagation_multi_headed
(A
, B
, C
, D
, E
, F
, G
, H
, I
) :-
1320 propagation_prelude
(A
, B
, C
, F
, G
, H
, L
),
1322 propagation_nested_code
(K
, [J
, A
], C
, D
, E
, F
, M
, L
, I
).
1323 propagation_prelude
(A
, [B
|C
], D
, E
/F
, G
, H
, I
) :-
1324 head_info
(A
, F
, J
, K
, L
, M
),
1325 build_head
(E
, F
, G
, L
, N
),
1326 head_arg_matches
(M
, [], O
, P
),
1328 extra_active_delegate_variables
(A
, [B
, C
, S
, T
], P
, U
),
1329 passive_head_via
(B
, [A
], [], P
, V
, W
, X
),
1330 instantiate_pattern_goals
(X
),
1331 get_max_constraint_index
(Y
),
1334 ; functor
(B
, A1
, B1
),
1335 make_attr
(Y
, C1
, D1
, W
),
1336 get_constraint_index
(A1
/B1
, E1
),
1340 -> gen_cond_allocation
(J
, K
, E
/F
, L
, F1
)
1344 append
([Z
|L
], U
, H1
),
1345 build_head
(E
, F
, G1
, H1
, I1
),
1347 K1
= (N
:-O
, V
, !, F1
, J1
),
1349 propagation_nested_code
([], [A
|B
], C
, D
, E
, F
, G
, H
, I
) :-
1350 propagation_end
([A
|B
], [], C
, F
, G
, H
, J
),
1351 propagation_body
(A
, B
, C
, D
, E
, F
, G
, J
, I
).
1352 propagation_nested_code
([A
|B
], C
, D
, E
, F
, G
, H
, I
, J
) :-
1353 propagation_end
(C
, [A
|B
], D
, G
, H
, I
, K
),
1354 propagation_accumulator
([A
|B
], C
, D
, G
, H
, K
, L
),
1356 propagation_nested_code
(B
, [A
|C
], D
, E
, F
, G
, M
, L
, J
).
1357 propagation_body
(A
, B
, C
, D
, E
, F
/G
, H
, I
, J
) :-
1359 get_prop_inner_loop_vars
(B
, [A
, M
, N
], O
, P
, Q
, R
),
1364 X
=..[suspension
, Y
, Z
, A1
, B1
, C1
, D1
|W
],
1365 create_get_mutable
(active
, Z
, E1
),
1368 build_head
(F
, G
, H
, G1
, H1
),
1370 build_head
(F
, G
, H
, I1
, J1
),
1374 head_arg_matches
(N1
, P
, O1
, P1
),
1375 different_from_other_susps
(A
, S
, B
, R
, Q1
),
1376 guard_body_copies
(C
, P1
, R1
, S1
),
1377 gen_uncond_attach_goal
(F
/G
, Q
, T1
, U1
),
1378 gen_state_cond_call
(Q
, G
, K1
, U1
, V1
),
1379 history_susps
(E
, [S
|R
], Q
, [], W1
),
1380 bagof
('chr novel_production'(X1
, Y1
), (member
(X1
, W1
), Y1
=Z1
), A2
),
1383 ( chr_pp_flag
(debugable
, on
)
1384 -> C
=rule
(D2
, E2
, M
, N
),
1385 my_term_copy
(M
-N
, P1
, F2
, G2
-H2
),
1386 I2
='chr debug_event'(try
([], [Q
, S
|R
], G2
, H2
)),
1387 J2
='chr debug_event'(apply
([], [Q
, S
|R
], G2
, H2
))
1391 K2
= (H1
:-F1
, Q1
, O1
, Z1
=C2
, B2
, R1
, I2
->J2, 'chr extend_history'(Q
, Z1
), T1
, S1
, V1
;K1
),
1393 history_susps
(A
, B
, C
, D
, E
) :-
1399 history_susps
(I
, H
, C
, [G
|D
], E
)
1401 get_prop_inner_loop_vars
([A
], B
, C
, D
, E
, []) :- !,
1403 head_info
(A
, G
, H
, E
, I
, J
),
1404 head_arg_matches
(J
, [], K
, D
),
1405 extra_active_delegate_variables
(A
, B
, D
, L
),
1407 get_prop_inner_loop_vars
([A
|B
], C
, D
, E
, F
, [G
|H
]) :-
1408 get_prop_inner_loop_vars
(B
, [A
|C
], I
, J
, F
, H
),
1411 head_info
(A
, L
, N
, G
, O
, P
),
1412 head_arg_matches
(P
, J
, Q
, E
),
1413 passive_delegate_variables
(A
, B
, C
, E
, R
),
1414 append
(R
, [G
, M
|I
], D
).
1415 propagation_end
([A
|B
], C
, D
, E
/F
, G
, H
, I
) :-
1417 gen_var_susp_list_for
(B
, [A
, C
, L
, M
], N
, O
, P
, Q
),
1419 build_head
(E
, F
, G
, R
, S
),
1426 build_head
(E
, F
, U
, V
, W
),
1430 gen_var_susp_list_for
([A
], B
, C
, D
, E
, F
) :- !,
1432 head_info
(A
, H
, I
, F
, E
, J
),
1433 head_arg_matches
(J
, [], K
, C
),
1434 extra_active_delegate_variables
(A
, B
, C
, L
),
1436 gen_var_susp_list_for
([A
|B
], C
, D
, E
, F
, G
) :-
1437 gen_var_susp_list_for
(B
, [A
|C
], H
, F
, I
, J
),
1440 head_info
(A
, L
, M
, N
, O
, P
),
1441 head_arg_matches
(P
, H
, Q
, D
),
1442 passive_delegate_variables
(A
, B
, C
, D
, R
),
1443 append
(R
, [N
, G
|F
], E
).
1444 propagation_accumulator
([A
|B
], [C
|D
], E
, F
/G
, H
, I
, J
) :-
1446 pre_vars_and_susps
(D
, [C
, A
, B
, M
, N
], O
, P
, Q
),
1450 head_info
(C
, T
, U
, V
, W
, X
),
1451 head_arg_matches
(X
, P
, Y
, Z
),
1452 A1
=..[suspension
, B1
, C1
, D1
, E1
, F1
, G1
|U
],
1453 different_from_other_susps
(C
, V
, D
, Q
, H1
),
1454 create_get_mutable
(active
, C1
, I1
),
1455 J1
= (V
=A1
, I1
, H1
, Y
),
1457 passive_head_via
(A
, [C
|D
], [], Z
, M1
, N1
, O1
),
1458 instantiate_pattern_goals
(O1
),
1459 get_max_constraint_index
(P1
),
1462 ; get_constraint_index
(K1
/L1
, R1
),
1463 make_attr
(P1
, S1
, T1
, N1
),
1468 build_head
(F
, G
, H
, V1
, W1
),
1469 passive_delegate_variables
(C
, D
, [A
, B
, M
, N
], Z
, X1
),
1470 append
([Q1
|X1
], [V
, R
|O
], Y1
),
1471 build_head
(F
, G
, U1
, Y1
, Z1
),
1473 build_head
(F
, G
, H
, A2
, B2
),
1474 C2
= (W1
:-J1
, M1
->Z1;B2
),
1476 pre_vars_and_susps
([A
], B
, C
, D
, []) :- !,
1478 head_info
(A
, F
, G
, H
, I
, J
),
1479 head_arg_matches
(J
, [], K
, D
),
1480 extra_active_delegate_variables
(A
, B
, D
, L
),
1482 pre_vars_and_susps
([A
|B
], C
, D
, E
, [F
|G
]) :-
1483 pre_vars_and_susps
(B
, [A
|C
], H
, I
, G
),
1486 head_info
(A
, K
, M
, F
, N
, O
),
1487 head_arg_matches
(O
, I
, P
, E
),
1488 passive_delegate_variables
(A
, B
, C
, E
, Q
),
1489 append
(Q
, [F
, L
|H
], D
).
1490 reorder_heads
(A
, B
, C
, D
, E
) :-
1491 ( chr_pp_flag
(reorder_heads
, on
)
1492 -> reorder_heads_main
(A
, B
, C
, D
, E
)
1496 reorder_heads_main
(A
, B
, C
, D
, E
) :-
1497 term_variables
(A
, F
),
1498 reorder_heads1
(B
, C
, F
, D
, E
).
1499 reorder_heads1
(A
, B
, C
, D
, E
) :-
1505 select_best_head
(A
, B
, C
, F
, H
, J
, K
, L
),
1506 reorder_heads1
(J
, K
, L
, G
, I
)
1508 select_best_head
(A
, B
, C
, D
, E
, F
, G
, H
) :-
1509 ( bagof
(tuple
(I
, J
, K
, L
, M
), (select2
(J
, K
, A
, B
, L
, M
), order_score
(J
, C
, L
, I
)), N
)
1513 max_go_list
(N
, tuple
(O
, D
, E
, F
, G
)),
1514 term_variables
(D
, P
),
1515 ( setof
(Q
, (member
(Q
, P
), \
+memberchk_eq
(Q
, C
)), R
)
1520 reorder_heads
(A
, B
, C
) :-
1521 term_variables
(A
, D
),
1522 reorder_heads1
(B
, D
, C
).
1523 reorder_heads1
(A
, B
, C
) :-
1527 select_best_head
(A
, B
, D
, F
, G
),
1528 reorder_heads1
(F
, G
, E
)
1530 select_best_head
(A
, B
, C
, D
, E
) :-
1531 ( bagof
(tuple
(F
, G
, H
), (select(G
, A
, H
), order_score
(G
, B
, H
, F
)), I
)
1535 max_go_list
(I
, tuple
(J
, C
, D
)),
1536 term_variables
(C
, K
),
1537 ( setof
(L
, (member
(L
, K
), \
+memberchk_eq
(L
, B
)), M
)
1542 order_score
(A
, B
, C
, D
) :-
1543 term_variables
(A
, E
),
1544 term_variables
(C
, F
),
1545 order_score_vars
(E
, B
, F
, 0, D
).
1546 order_score_vars
([], A
, B
, C
, D
) :-
1551 order_score_vars
([A
|B
], C
, D
, E
, F
) :-
1552 ( memberchk_eq
(A
, C
)
1554 ; memberchk_eq
(A
, D
)
1558 order_score_vars
(B
, C
, D
, G
, F
).
1559 create_get_mutable
(A
, B
, C
) :-
1561 clean_clauses
([], []).
1562 clean_clauses
([A
|B
], [C
|D
]) :-
1564 clean_clauses
(B
, D
).
1565 clean_clause
(A
, B
) :-
1567 -> clean_goal
(D
, E
),
1577 clean_goal
((A
, B
), C
) :- !,
1586 clean_goal
((A
->B;C
), D
) :- !,
1589 -> clean_goal
(B
, F
),
1592 -> clean_goal
(C
, G
),
1598 clean_goal
((A
;B
), C
) :- !,
1607 clean_goal
(once
(A
), B
) :- !,
1615 clean_goal
((A
->B), C
) :- !,
1628 head_info
(A
, B
, C
, D
, E
, F
) :-
1629 vars_susp
(B
, C
, D
, E
),
1632 inc_id
([A
|B
], [C
|B
]) :-
1634 dec_id
([A
|B
], [C
|B
]) :-
1636 extend_id
(A
, [0|A
]).
1637 next_id
([A
, B
|C
], [D
|C
]) :-
1639 build_head
(A
, B
, C
, D
, E
) :-
1640 buildName
(A
, B
, C
, F
),
1642 buildName
(A
, B
, C
, D
) :-
1643 atom_concat
(A
, /, E
),
1644 atom_concat
(E
, B
, F
),
1645 buildName_
(C
, F
, D
).
1646 buildName_
([], A
, A
).
1647 buildName_
([A
|B
], C
, D
) :-
1648 buildName_
(B
, C
, E
),
1649 atom_concat
(E
, '__', F
),
1650 atom_concat
(F
, A
, D
).
1651 vars_susp
(A
, B
, C
, D
) :-
1654 make_attr
(A
, B
, C
, D
) :-
1660 and_pattern(A, B) :-
1665 conj2list(A, B, []).
1666 conj2list(A, B, C) :-
1670 conj2list
(A
, [A
|B
], B
).
1671 list2conj
([], true
).
1672 list2conj
([A
], B
) :- !,
1674 list2conj
([A
|B
], C
) :-
1680 atom_concat_list
([A
], A
) :- !.
1681 atom_concat_list
([A
|B
], C
) :-
1682 atom_concat_list
(B
, D
),
1683 atom_concat
(A
, D
, C
).
1685 set_elems
([A
|B
], A
) :-
1687 member2
([A
|B
], [C
|D
], A
-C
).
1688 member2
([A
|B
], [C
|D
], E
) :-
1690 select2
(A
, B
, [A
|C
], [B
|D
], C
, D
).
1691 select2
(A
, B
, [C
|D
], [E
|F
], [C
|G
], [E
|H
]) :-
1692 select2
(A
, B
, D
, F
, G
, H
).
1693 pair_all_with
([], A
, []).
1694 pair_all_with
([A
|B
], C
, [A
-C
|D
]) :-
1695 pair_all_with
(B
, C
, D
).
1696 'attach_constraint/2'([], A
).
1697 'attach_constraint/2'([A
|B
], C
) :-
1698 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1699 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1701 -> put_attr
(A
, chr_translate_bootstrap1
, v
(E
, [C
|F
], G
, H
, I
, J
, K
))
1703 put_attr
(A
, chr_translate_bootstrap1
, v
(L
, [C
], G
, H
, I
, J
, K
))
1705 ; put_attr
(A
, chr_translate_bootstrap1
, v
(1, [C
], [], [], [], [], []))
1707 'attach_constraint/2'(B
, C
).
1708 'detach_constraint/2'([], A
).
1709 'detach_constraint/2'([A
|B
], C
) :-
1710 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1711 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1713 -> 'chr sbag_del_element'(F
, C
, L
),
1717 -> del_attr
(A
, chr_translate_bootstrap1
)
1718 ; put_attr
(A
, chr_translate_bootstrap1
, v
(M
, [], G
, H
, I
, J
, K
))
1720 ; put_attr
(A
, chr_translate_bootstrap1
, v
(E
, L
, G
, H
, I
, J
, K
))
1726 'detach_constraint/2'(B
, C
).
1727 'attach_constraint_count/1'([], A
).
1728 'attach_constraint_count/1'([A
|B
], C
) :-
1729 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1730 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1732 -> put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, [C
|G
], H
, I
, J
, K
))
1734 put_attr
(A
, chr_translate_bootstrap1
, v
(L
, F
, [C
], H
, I
, J
, K
))
1736 ; put_attr
(A
, chr_translate_bootstrap1
, v
(2, [], [C
], [], [], [], []))
1738 'attach_constraint_count/1'(B
, C
).
1739 'detach_constraint_count/1'([], A
).
1740 'detach_constraint_count/1'([A
|B
], C
) :-
1741 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1742 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1744 -> 'chr sbag_del_element'(G
, C
, L
),
1748 -> del_attr
(A
, chr_translate_bootstrap1
)
1749 ; put_attr
(A
, chr_translate_bootstrap1
, v
(M
, F
, [], H
, I
, J
, K
))
1751 ; put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, L
, H
, I
, J
, K
))
1757 'detach_constraint_count/1'(B
, C
).
1758 'attach_constraint_index/2'([], A
).
1759 'attach_constraint_index/2'([A
|B
], C
) :-
1760 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1761 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1763 -> put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, G
, [C
|H
], I
, J
, K
))
1765 put_attr
(A
, chr_translate_bootstrap1
, v
(L
, F
, G
, [C
], I
, J
, K
))
1767 ; put_attr
(A
, chr_translate_bootstrap1
, v
(4, [], [], [C
], [], [], []))
1769 'attach_constraint_index/2'(B
, C
).
1770 'detach_constraint_index/2'([], A
).
1771 'detach_constraint_index/2'([A
|B
], C
) :-
1772 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1773 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1775 -> 'chr sbag_del_element'(H
, C
, L
),
1779 -> del_attr
(A
, chr_translate_bootstrap1
)
1780 ; put_attr
(A
, chr_translate_bootstrap1
, v
(M
, F
, G
, [], I
, J
, K
))
1782 ; put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, G
, L
, I
, J
, K
))
1788 'detach_constraint_index/2'(B
, C
).
1789 'attach_max_constraint_index/1'([], A
).
1790 'attach_max_constraint_index/1'([A
|B
], C
) :-
1791 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1792 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1794 -> put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, G
, H
, [C
|I
], J
, K
))
1796 put_attr
(A
, chr_translate_bootstrap1
, v
(L
, F
, G
, H
, [C
], J
, K
))
1798 ; put_attr
(A
, chr_translate_bootstrap1
, v
(8, [], [], [], [C
], [], []))
1800 'attach_max_constraint_index/1'(B
, C
).
1801 'detach_max_constraint_index/1'([], A
).
1802 'detach_max_constraint_index/1'([A
|B
], C
) :-
1803 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1804 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1806 -> 'chr sbag_del_element'(I
, C
, L
),
1810 -> del_attr
(A
, chr_translate_bootstrap1
)
1811 ; put_attr
(A
, chr_translate_bootstrap1
, v
(M
, F
, G
, H
, [], J
, K
))
1813 ; put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, G
, H
, L
, J
, K
))
1819 'detach_max_constraint_index/1'(B
, C
).
1820 'attach_target_module/1'([], A
).
1821 'attach_target_module/1'([A
|B
], C
) :-
1822 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1823 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1825 -> put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, G
, H
, I
, [C
|J
], K
))
1827 put_attr
(A
, chr_translate_bootstrap1
, v
(L
, F
, G
, H
, I
, [C
], K
))
1829 ; put_attr
(A
, chr_translate_bootstrap1
, v
(16, [], [], [], [], [C
], []))
1831 'attach_target_module/1'(B
, C
).
1832 'detach_target_module/1'([], A
).
1833 'detach_target_module/1'([A
|B
], C
) :-
1834 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1835 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1837 -> 'chr sbag_del_element'(J
, C
, L
),
1841 -> del_attr
(A
, chr_translate_bootstrap1
)
1842 ; put_attr
(A
, chr_translate_bootstrap1
, v
(M
, F
, G
, H
, I
, [], K
))
1844 ; put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, G
, H
, I
, L
, K
))
1850 'detach_target_module/1'(B
, C
).
1851 'attach_attached/2'([], A
).
1852 'attach_attached/2'([A
|B
], C
) :-
1853 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1854 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1856 -> put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, G
, H
, I
, J
, [C
|K
]))
1858 put_attr
(A
, chr_translate_bootstrap1
, v
(L
, F
, G
, H
, I
, J
, [C
]))
1860 ; put_attr
(A
, chr_translate_bootstrap1
, v
(32, [], [], [], [], [], [C
]))
1862 'attach_attached/2'(B
, C
).
1863 'detach_attached/2'([], A
).
1864 'detach_attached/2'([A
|B
], C
) :-
1865 ( get_attr
(A
, chr_translate_bootstrap1
, D
)
1866 -> D
=v
(E
, F
, G
, H
, I
, J
, K
),
1868 -> 'chr sbag_del_element'(K
, C
, L
),
1872 -> del_attr
(A
, chr_translate_bootstrap1
)
1873 ; put_attr
(A
, chr_translate_bootstrap1
, v
(M
, F
, G
, H
, I
, J
, []))
1875 ; put_attr
(A
, chr_translate_bootstrap1
, v
(E
, F
, G
, H
, I
, J
, L
))
1881 'detach_attached/2'(B
, C
).
1882 attach_increment
([], A
).
1883 attach_increment
([A
|B
], v
(C
, D
, E
, F
, G
, H
, I
)) :-
1884 'chr not_locked'(A
),
1885 ( get_attr
(A
, chr_translate_bootstrap1
, J
)
1886 -> J
=v
(K
, L
, M
, N
, O
, P
, Q
),
1888 'chr merge_attributes'(D
, R
, S
),
1890 'chr merge_attributes'(E
, T
, U
),
1892 'chr merge_attributes'(F
, V
, W
),
1894 'chr merge_attributes'(G
, X
, Y
),
1896 'chr merge_attributes'(H
, Z
, A1
),
1898 'chr merge_attributes'(I
, B1
, C1
),
1900 put_attr
(A
, chr_translate_bootstrap1
, v
(D1
, S
, U
, W
, Y
, A1
, C1
))
1901 ; put_attr
(A
, chr_translate_bootstrap1
, v
(C
, D
, E
, F
, G
, H
, I
))
1903 attach_increment
(B
, v
(C
, D
, E
, F
, G
, H
, I
)).
1904 chr_translate_bootstrap1
:attr_unify_hook
(v
(A
, B
, C
, D
, E
, F
, G
), H
) :-
1912 -> ( get_attr
(H
, chr_translate_bootstrap1
, O
)
1913 -> O
=v
(P
, Q
, R
, S
, T
, U
, V
),
1915 'chr merge_attributes'(I
, W
, X
),
1917 'chr merge_attributes'(J
, Y
, Z
),
1919 'chr merge_attributes'(K
, A1
, B1
),
1921 'chr merge_attributes'(L
, C1
, D1
),
1923 'chr merge_attributes'(M
, E1
, F1
),
1925 'chr merge_attributes'(N
, G1
, H1
),
1927 put_attr
(H
, chr_translate_bootstrap1
, v
(I1
, X
, Z
, B1
, D1
, F1
, H1
)),
1928 'chr run_suspensions_loop'([X
, Z
, B1
, D1
, F1
, H1
])
1929 ; put_attr
(H
, chr_translate_bootstrap1
, v
(A
, I
, J
, K
, L
, M
, N
)),
1930 'chr run_suspensions_loop'([I
, J
, K
, L
, M
, N
])
1933 -> term_variables
(H
, J1
),
1934 attach_increment
(J1
, v
(A
, I
, J
, K
, L
, M
, N
))
1937 'chr run_suspensions_loop'([I
, J
, K
, L
, M
, N
])
1940 'constraint/2__0'(A
, B
, C
).
1941 'constraint/2__0'(A
, B
, C
) :-
1943 get_attr
(D
, chr_translate_bootstrap1
, E
),
1944 E
=v
(F
, G
, H
, I
, J
, K
, L
),
1946 ( 'chr sbag_member'(M
, G
),
1947 M
=suspension
(N
, O
, P
, Q
, R
, S
, T
, U
),
1954 ; 'chr remove_constraint_internal'(C
, V
),
1955 'detach_constraint/2'(V
, C
)
1958 'constraint/2__0'(A
, B
, C
) :-
1960 get_attr
(D
, chr_translate_bootstrap1
, E
),
1961 E
=v
(F
, G
, H
, I
, J
, K
, L
),
1963 'chr sbag_member'(M
, G
),
1964 M
=suspension
(N
, O
, P
, Q
, R
, S
, T
, U
),
1969 ; 'chr remove_constraint_internal'(C
, V
),
1970 'detach_constraint/2'(V
, C
)
1973 'constraint/2__0'(A
, B
, C
) :-
1975 -> 'chr insert_constraint_internal'(D
, C
, chr_translate_bootstrap1
:'constraint/2__0'(A
, B
, C
), constraint
, [A
, B
])
1976 ; 'chr activate_constraint'(D
, C
, E
)
1978 'attach_constraint/2'(D
, C
).
1979 constraint_count
(A
) :-
1980 'constraint_count/1__0'(A
, B
).
1981 'constraint_count/1__0'(A
, B
) :-
1982 'chr global_term_ref_1'(C
),
1983 get_attr
(C
, chr_translate_bootstrap1
, D
),
1984 D
=v
(E
, F
, G
, H
, I
, J
, K
),
1986 'chr sbag_member'(L
, G
),
1987 L
=suspension
(M
, N
, O
, P
, Q
, R
, S
),
1988 N
=mutable
(active
), !,
1991 ; 'chr remove_constraint_internal'(B
, T
),
1992 'detach_constraint_count/1'(T
, B
)
1995 'constraint_count/1__0'(A
, B
) :-
1997 -> 'chr insert_constraint_internal'(C
, B
, chr_translate_bootstrap1
:'constraint_count/1__0'(A
, B
), constraint_count
, [A
])
1998 ; 'chr activate_constraint'(C
, B
, D
)
2000 'attach_constraint_count/1'(C
, B
).
2001 constraint_index
(A
, B
) :-
2002 'constraint_index/2__0'(A
, B
, C
).
2003 'constraint_index/2__0'(A
, B
, C
) :-
2005 -> 'chr insert_constraint_internal'(D
, C
, chr_translate_bootstrap1
:'constraint_index/2__0'(A
, B
, C
), constraint_index
, [A
, B
])
2006 ; 'chr activate_constraint'(D
, C
, E
)
2008 'attach_constraint_index/2'(D
, C
).
2009 get_constraint_index
(A
, B
) :-
2010 'get_constraint_index/2__0'(A
, B
, C
).
2011 'get_constraint_index/2__0'(A
, B
, C
) :-
2013 get_attr
(D
, chr_translate_bootstrap1
, E
),
2014 E
=v
(F
, G
, H
, I
, J
, K
, L
),
2016 'chr sbag_member'(M
, I
),
2017 M
=suspension
(N
, O
, P
, Q
, R
, S
, T
, U
),
2021 'get_constraint_index/2__0'(A
, B
, C
) :- !,
2023 max_constraint_index
(A
) :-
2024 'max_constraint_index/1__0'(A
, B
).
2025 'max_constraint_index/1__0'(A
, B
) :-
2027 -> 'chr insert_constraint_internal'(C
, B
, chr_translate_bootstrap1
:'max_constraint_index/1__0'(A
, B
), max_constraint_index
, [A
])
2028 ; 'chr activate_constraint'(C
, B
, D
)
2030 'attach_max_constraint_index/1'(C
, B
).
2031 get_max_constraint_index
(A
) :-
2032 'get_max_constraint_index/1__0'(A
, B
).
2033 'get_max_constraint_index/1__0'(A
, B
) :-
2034 'chr global_term_ref_1'(C
),
2035 get_attr
(C
, chr_translate_bootstrap1
, D
),
2036 D
=v
(E
, F
, G
, H
, I
, J
, K
),
2038 'chr sbag_member'(L
, I
),
2039 L
=suspension
(M
, N
, O
, P
, Q
, R
, S
),
2040 N
=mutable
(active
), !,
2042 'get_max_constraint_index/1__0'(A
, B
) :- !,
2045 'target_module/1__0'(A
, B
).
2046 'target_module/1__0'(A
, B
) :-
2048 -> 'chr insert_constraint_internal'(C
, B
, chr_translate_bootstrap1
:'target_module/1__0'(A
, B
), target_module
, [A
])
2049 ; 'chr activate_constraint'(C
, B
, D
)
2051 'attach_target_module/1'(C
, B
).
2052 get_target_module
(A
) :-
2053 'get_target_module/1__0'(A
, B
).
2054 'get_target_module/1__0'(A
, B
) :-
2055 'chr global_term_ref_1'(C
),
2056 get_attr
(C
, chr_translate_bootstrap1
, D
),
2057 D
=v
(E
, F
, G
, H
, I
, J
, K
),
2059 'chr sbag_member'(L
, J
),
2060 L
=suspension
(M
, N
, O
, P
, Q
, R
, S
),
2061 N
=mutable
(active
), !,
2063 'get_target_module/1__0'(A
, B
) :- !,
2066 'attached/2__0'(A
, B
, C
).
2067 'attached/2__0'(A
, B
, C
) :-
2069 get_attr
(D
, chr_translate_bootstrap1
, E
),
2070 E
=v
(F
, G
, H
, I
, J
, K
, L
),
2072 'chr sbag_member'(M
, L
),
2073 M
=suspension
(N
, O
, P
, Q
, R
, S
, T
, U
),
2079 ; 'chr remove_constraint_internal'(C
, V
),
2080 'detach_attached/2'(V
, C
)
2082 'attached/2__0'(A
, B
, C
) :-
2085 get_attr
(D
, chr_translate_bootstrap1
, E
),
2086 E
=v
(F
, G
, H
, I
, J
, K
, L
),
2089 -> 'chr allocate_constraint'(chr_translate_bootstrap1
:'attached/2__0'(A
, B
, C
), C
, attached
, [A
, B
])
2092 'attached/2__0__0'(L
, A
, B
, C
).
2093 'attached/2__0__0'([], A
, B
, C
) :-
2094 'attached/2__1'(A
, B
, C
).
2095 'attached/2__0__0'([A
|B
], C
, D
, E
) :-
2096 ( A
=suspension
(F
, G
, H
, I
, J
, K
, L
, M
),
2099 -> 'chr remove_constraint_internal'(A
, N
),
2100 'detach_attached/2'(N
, A
),
2101 'attached/2__0__0'(B
, C
, D
, E
)
2102 ; 'attached/2__0__0'(B
, C
, D
, E
)
2104 'attached/2__0'(A
, B
, C
) :-
2106 -> 'chr allocate_constraint'(chr_translate_bootstrap1
:'attached/2__0'(A
, B
, C
), C
, attached
, [A
, B
])
2109 'attached/2__1'(A
, B
, C
).
2110 'attached/2__1'(A
, B
, C
) :-
2112 get_attr
(D
, chr_translate_bootstrap1
, E
),
2113 E
=v
(F
, G
, H
, I
, J
, K
, L
),
2115 'chr sbag_member'(M
, L
),
2116 M
=suspension
(N
, O
, P
, Q
, R
, S
, T
, U
),
2122 ; 'chr remove_constraint_internal'(C
, V
),
2123 'detach_attached/2'(V
, C
)
2125 'attached/2__1'(A
, B
, C
) :-
2128 get_attr
(D
, chr_translate_bootstrap1
, E
),
2129 E
=v
(F
, G
, H
, I
, J
, K
, L
),
2131 'attached/2__1__0'(L
, A
, B
, C
).
2132 'attached/2__1__0'([], A
, B
, C
) :-
2133 'attached/2__2'(A
, B
, C
).
2134 'attached/2__1__0'([A
|B
], C
, D
, E
) :-
2135 ( A
=suspension
(F
, G
, H
, I
, J
, K
, L
, M
),
2138 -> 'chr remove_constraint_internal'(A
, N
),
2139 'detach_attached/2'(N
, A
),
2140 'attached/2__1__0'(B
, C
, D
, E
)
2141 ; 'attached/2__1__0'(B
, C
, D
, E
)
2143 'attached/2__1'(A
, B
, C
) :-
2144 'attached/2__2'(A
, B
, C
).
2145 'attached/2__2'(A
, B
, C
) :-
2148 get_attr
(D
, chr_translate_bootstrap1
, E
),
2149 E
=v
(F
, G
, H
, I
, J
, K
, L
),
2151 ( 'chr sbag_member'(M
, L
),
2152 M
=suspension
(N
, O
, P
, Q
, R
, S
, T
, U
),
2160 ; 'chr remove_constraint_internal'(C
, V
),
2161 'detach_attached/2'(V
, C
)
2163 'attached/2__2'(A
, B
, C
) :-
2164 'chr activate_constraint'(D
, C
, E
),
2165 'attach_attached/2'(D
, C
).
2167 'is_attached/1__0'(A
, B
).
2168 'is_attached/1__0'(A
, B
) :-
2170 get_attr
(C
, chr_translate_bootstrap1
, D
),
2171 D
=v
(E
, F
, G
, H
, I
, J
, K
),
2173 'chr sbag_member'(L
, K
),
2174 L
=suspension
(M
, N
, O
, P
, Q
, R
, S
, T
),
2181 'is_attached/1__0'(A
, B
) :- !.
2183 'chr_clear/0__0'(A
).
2184 'chr_clear/0__0'(A
) :-
2185 'chr global_term_ref_1'(B
),
2186 get_attr
(B
, chr_translate_bootstrap1
, C
),
2187 C
=v
(D
, E
, F
, G
, H
, I
, J
),
2190 -> 'chr allocate_constraint'(chr_translate_bootstrap1
:'chr_clear/0__0'(A
), A
, chr_clear
, [])
2193 'chr_clear/0__0__0'(E
, A
).
2194 'chr_clear/0__0__0'([], A
) :-
2195 'chr_clear/0__1'(A
).
2196 'chr_clear/0__0__0'([A
|B
], C
) :-
2197 ( A
=suspension
(D
, E
, F
, G
, H
, I
, J
, K
),
2199 -> 'chr remove_constraint_internal'(A
, L
),
2200 'detach_constraint/2'(L
, A
),
2201 'chr_clear/0__0__0'(B
, C
)
2202 ; 'chr_clear/0__0__0'(B
, C
)
2204 'chr_clear/0__0'(A
) :-
2206 -> 'chr allocate_constraint'(chr_translate_bootstrap1
:'chr_clear/0__0'(A
), A
, chr_clear
, [])
2209 'chr_clear/0__1'(A
).
2210 'chr_clear/0__1'(A
) :-
2211 'chr global_term_ref_1'(B
),
2212 get_attr
(B
, chr_translate_bootstrap1
, C
),
2213 C
=v
(D
, E
, F
, G
, H
, I
, J
),
2215 'chr_clear/0__1__0'(F
, A
).
2216 'chr_clear/0__1__0'([], A
) :-
2217 'chr_clear/0__2'(A
).
2218 'chr_clear/0__1__0'([A
|B
], C
) :-
2219 ( A
=suspension
(D
, E
, F
, G
, H
, I
, J
),
2221 -> 'chr remove_constraint_internal'(A
, K
),
2222 'detach_constraint_count/1'(K
, A
),
2223 'chr_clear/0__1__0'(B
, C
)
2224 ; 'chr_clear/0__1__0'(B
, C
)
2226 'chr_clear/0__1'(A
) :-
2227 'chr_clear/0__2'(A
).
2228 'chr_clear/0__2'(A
) :-
2229 'chr global_term_ref_1'(B
),
2230 get_attr
(B
, chr_translate_bootstrap1
, C
),
2231 C
=v
(D
, E
, F
, G
, H
, I
, J
),
2233 'chr_clear/0__2__0'(G
, A
).
2234 'chr_clear/0__2__0'([], A
) :-
2235 'chr_clear/0__3'(A
).
2236 'chr_clear/0__2__0'([A
|B
], C
) :-
2237 ( A
=suspension
(D
, E
, F
, G
, H
, I
, J
, K
),
2239 -> 'chr remove_constraint_internal'(A
, L
),
2240 'detach_constraint_index/2'(L
, A
),
2241 'chr_clear/0__2__0'(B
, C
)
2242 ; 'chr_clear/0__2__0'(B
, C
)
2244 'chr_clear/0__2'(A
) :-
2245 'chr_clear/0__3'(A
).
2246 'chr_clear/0__3'(A
) :-
2247 'chr global_term_ref_1'(B
),
2248 get_attr
(B
, chr_translate_bootstrap1
, C
),
2249 C
=v
(D
, E
, F
, G
, H
, I
, J
),
2251 'chr_clear/0__3__0'(H
, A
).
2252 'chr_clear/0__3__0'([], A
) :-
2253 'chr_clear/0__4'(A
).
2254 'chr_clear/0__3__0'([A
|B
], C
) :-
2255 ( A
=suspension
(D
, E
, F
, G
, H
, I
, J
),
2257 -> 'chr remove_constraint_internal'(A
, K
),
2258 'detach_max_constraint_index/1'(K
, A
),
2259 'chr_clear/0__3__0'(B
, C
)
2260 ; 'chr_clear/0__3__0'(B
, C
)
2262 'chr_clear/0__3'(A
) :-
2263 'chr_clear/0__4'(A
).
2264 'chr_clear/0__4'(A
) :-
2265 'chr global_term_ref_1'(B
),
2266 get_attr
(B
, chr_translate_bootstrap1
, C
),
2267 C
=v
(D
, E
, F
, G
, H
, I
, J
),
2269 'chr_clear/0__4__0'(I
, A
).
2270 'chr_clear/0__4__0'([], A
) :-
2271 'chr_clear/0__5'(A
).
2272 'chr_clear/0__4__0'([A
|B
], C
) :-
2273 ( A
=suspension
(D
, E
, F
, G
, H
, I
, J
),
2275 -> 'chr remove_constraint_internal'(A
, K
),
2276 'detach_target_module/1'(K
, A
),
2277 'chr_clear/0__4__0'(B
, C
)
2278 ; 'chr_clear/0__4__0'(B
, C
)
2280 'chr_clear/0__4'(A
) :-
2281 'chr_clear/0__5'(A
).
2282 'chr_clear/0__5'(A
) :-
2283 'chr global_term_ref_1'(B
),
2284 get_attr
(B
, chr_translate_bootstrap1
, C
),
2285 C
=v
(D
, E
, F
, G
, H
, I
, J
),
2287 'chr_clear/0__5__0'(J
, A
).
2288 'chr_clear/0__5__0'([], A
) :-
2289 'chr_clear/0__6'(A
).
2290 'chr_clear/0__5__0'([A
|B
], C
) :-
2291 ( A
=suspension
(D
, E
, F
, G
, H
, I
, J
, K
),
2293 -> 'chr remove_constraint_internal'(A
, L
),
2294 'detach_attached/2'(L
, A
),
2295 'chr_clear/0__5__0'(B
, C
)
2296 ; 'chr_clear/0__5__0'(B
, C
)
2298 'chr_clear/0__5'(A
) :-
2299 'chr_clear/0__6'(A
).
2300 'chr_clear/0__6'(A
) :- !.