diff --git a/LGPL/chr/chr_translate.pl b/LGPL/chr/chr_translate.pl index 3a9e8e355..307459617 100644 --- a/LGPL/chr/chr_translate.pl +++ b/LGPL/chr/chr_translate.pl @@ -1,6 +1,6 @@ /* Generated by CHR bootstrap compiler - From: ../../../../work/LGPL/chr/chr_translate.chr - Date: [84,104,117,32,79,99,116,32,50,55,32,49,54,58,51,54,58,50,53,32,50,48,48,53,10] + From: chr_translate.chr + Date: [84,104,117,32,83,101,112,32,50,56,32,49,51,58,50,53,58,53,56,32,50,48,48,54,10] DO NOT EDIT. EDIT THE CHR FILE INSTEAD */ @@ -171,9 +171,9 @@ is_declaration(A,B) :- conj2list(D,E), extract_type_mode(E,B). extract_type_mode([],[]). -extract_type_mode([A/B|C],[A/B|D]) :- +extract_type_mode([B/C|A],[B/C|D]) :- !, - extract_type_mode(C,D). + extract_type_mode(A,D). extract_type_mode([A|B],[C|D]) :- functor(A,E,F), C=E/F, @@ -183,15 +183,15 @@ extract_type_mode([A|B],[C|D]) :- constraint_mode(E/F,I), extract_type_mode(B,D). extract_types_and_modes([],[],[]). -extract_types_and_modes([(+A)|B],[A|C],[+|D]) :- +extract_types_and_modes([(+B)|A],[B|C],[+|D]) :- !, - extract_types_and_modes(B,C,D). -extract_types_and_modes([(?A)|B],[A|C],[?|D]) :- + extract_types_and_modes(A,C,D). +extract_types_and_modes([(?B)|A],[B|C],[?|D]) :- !, - extract_types_and_modes(B,C,D). -extract_types_and_modes([(-A)|B],[A|C],[?|D]) :- + extract_types_and_modes(A,C,D). +extract_types_and_modes([(-B)|A],[B|C],[?|D]) :- !, - extract_types_and_modes(B,C,D). + extract_types_and_modes(A,C,D). extract_types_and_modes([A|_],_,_) :- format('CHR compiler ERROR: Illegal mode/type declaration "~w". ',[A]), @@ -221,7 +221,7 @@ tdisj2list(A,B,C) :- !, tdisj2list(D,B,F), tdisj2list(E,F,C). -tdisj2list(A,[A|B],B). +tdisj2list(B,[B|A],A). parse_rule(A,B) :- A=(C@D), !, @@ -595,13 +595,13 @@ generate_attach_detach_a_constraint_all([A|B],C) :- ), generate_attach_detach_a_constraint_all(B,F), append_lists([D,E,F],C). -generate_attach_a_constraint(A,[B,C]) :- - generate_attach_a_constraint_empty_list(A,B), +generate_attach_a_constraint(C,[A,B]) :- + generate_attach_a_constraint_empty_list(C,A), get_max_constraint_index(D), ( D==1 -> - generate_attach_a_constraint_1_1(A,C) + generate_attach_a_constraint_1_1(C,B) ; - generate_attach_a_constraint_t_p(A,C) + generate_attach_a_constraint_t_p(C,B) ). generate_attach_a_constraint_skeleton(A,B,C,D) :- make_name(attach_,A,E), @@ -610,16 +610,16 @@ generate_attach_a_constraint_skeleton(A,B,C,D) :- generate_attach_a_constraint_empty_list(A,B) :- generate_attach_a_constraint_skeleton(A,[[],_],true,B). generate_attach_a_constraint_1_1(A,B) :- - C=[[D|E],F], - generate_attach_a_constraint_skeleton(A,C,G,B), - generate_attach_body_1(A,D,F,H), + F=[[C|D],E], + generate_attach_a_constraint_skeleton(A,F,G,B), + generate_attach_body_1(A,C,E,H), make_name(attach_,A,I), - J=..[I,E,F], + J=..[I,D,E], chr_pp_flag(solver_events,K), ( K\==none -> - C=[[D|_],F], + F=[[C|_],E], get_target_module(L), - M=clp_events:subscribe(D,K,L,chr_runtime:'chr run_suspensions'([F])) + M=clp_events:subscribe(C,K,L,chr_runtime:'chr run_suspensions'([E])) ; M=true ), @@ -628,16 +628,16 @@ generate_attach_body_1(_,A,B,C) :- get_target_module(D), C=(get_attr(A,D,E)->F=[B|E],put_attr(A,D,F);put_attr(A,D,[B])). generate_attach_a_constraint_t_p(A,B) :- - C=[[D|E],F], - generate_attach_a_constraint_skeleton(A,C,G,B), + F=[[C|D],E], + generate_attach_a_constraint_skeleton(A,F,G,B), make_name(attach_,A,H), - I=..[H,E,F], - generate_attach_body_n(A,D,F,J), + I=..[H,D,E], + generate_attach_body_n(A,C,E,J), chr_pp_flag(solver_events,K), ( K\==none -> - C=[[D|_],F], + F=[[C|_],E], get_target_module(L), - M=clp_events:subscribe(D,K,L,chr_runtime:'chr run_suspensions'([F])) + M=clp_events:subscribe(C,K,L,chr_runtime:'chr run_suspensions'([E])) ; M=true ), @@ -659,13 +659,13 @@ generate_attach_body_n(A/B,C,D,E) :- make_attr(H,G,R,T), get_target_module(U), 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)). -generate_detach_a_constraint(A,[B,C]) :- - generate_detach_a_constraint_empty_list(A,B), +generate_detach_a_constraint(C,[A,B]) :- + generate_detach_a_constraint_empty_list(C,A), get_max_constraint_index(D), ( D==1 -> - generate_detach_a_constraint_1_1(A,C) + generate_detach_a_constraint_1_1(C,B) ; - generate_detach_a_constraint_t_p(A,C) + generate_detach_a_constraint_t_p(C,B) ). generate_detach_a_constraint_empty_list(A,B) :- make_name(detach_,A,C), @@ -674,10 +674,10 @@ generate_detach_a_constraint_empty_list(A,B) :- B=(E:-true). generate_detach_a_constraint_1_1(A,B) :- make_name(detach_,A,C), - D=[[E|F],G], - H=..[C|D], - I=..[C,F,G], - generate_detach_body_1(A,E,G,J), + G=[[D|E],F], + H=..[C|G], + I=..[C,E,F], + generate_detach_body_1(A,D,F,J), K=(J,I), B=(H:-K). generate_detach_body_1(_,A,B,C) :- @@ -685,10 +685,10 @@ generate_detach_body_1(_,A,B,C) :- C=(get_attr(A,D,E)->'chr sbag_del_element'(E,B,F),(F==[]->del_attr(A,D);put_attr(A,D,F));true). generate_detach_a_constraint_t_p(A,B) :- make_name(detach_,A,C), - D=[[E|F],G], - H=..[C|D], - I=..[C,F,G], - generate_detach_body_n(A,E,G,J), + G=[[D|E],F], + H=..[C|G], + I=..[C,E,F], + generate_detach_body_n(A,D,F,J), K=(J,I), B=(H:-K). generate_detach_body_n(A/B,C,D,E) :- @@ -779,14 +779,14 @@ global_indexed_variables_clause(A,B,C) :- B=[D|C], ( chr_pp_flag(reduced_indexing,on) -> ( forsome(E,A,chr_translate:may_trigger(E)) -> - F=(G=..[_,_,_,_,_,_,H|_],'$indexed_variables'(H,I)) + I=(G=..[_,_,_,_,_,_,F|_],'$indexed_variables'(F,H)) ; - F=true, - I=[] + I=true, + H=[] ), - D=(chr_indexed_variables(G,I):-F) + D=(chr_indexed_variables(G,H):-I) ; - D=(chr_indexed_variables(G,I):-'chr chr_indexed_variables'(G,I)) + D=(chr_indexed_variables(G,H):-'chr chr_indexed_variables'(G,H)) ) ; B=C @@ -806,21 +806,21 @@ generate_attach_increment(A) :- ). generate_attach_increment_empty((attach_increment([],_):-true)). generate_attach_increment_one(A) :- - B=attach_increment([C|D],E), + E=attach_increment([B|C],D), get_target_module(F), - 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)), - A=(B:-G). + J=('chr not_locked'(B),(get_attr(B,F,G)->sort(G,H),merge(D,H,I),put_attr(B,F,I);put_attr(B,F,D)),attach_increment(C,D)), + A=(E:-J). generate_attach_increment_many(A,B) :- make_attr(A,C,D,E), make_attr(A,F,G,H), - I=attach_increment([J|K],E), - bagof(L,M^N^O^P^(member2(D,G,M-N),L=(sort(N,O),'chr merge_attributes'(M,O,P))),Q), + K=attach_increment([I|J],E), + bagof(P,O^N^M^L^(member2(D,G,O-N),P=(sort(N,M),'chr merge_attributes'(O,M,L))),Q), list2conj(Q,R), - bagof(S,T^U^V^member((T,'chr merge_attributes'(U,V,S)),Q),W), + bagof(V,U^T^S^member((U,'chr merge_attributes'(T,S,V)),Q),W), make_attr(A,X,W,Y), get_target_module(Z), - 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)), - B=(I:-A1). + B1=('chr not_locked'(I),(get_attr(I,Z,A1)->A1=H,R,X is C\/F,put_attr(I,Z,Y);put_attr(I,Z,E)),attach_increment(J,E)), + B=(K:-B1). generate_attr_unify_hook(A) :- get_max_constraint_index(B), ( B==0 -> @@ -834,29 +834,29 @@ generate_attr_unify_hook(A) :- ) ). generate_attr_unify_hook_one(A) :- - B=attr_unify_hook(C,D), + D=attr_unify_hook(B,C), get_target_module(E), make_run_suspensions(F,G), - make_run_suspensions(C,H), - 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)), - A=(B:-I). + make_run_suspensions(B,H), + M=(sort(B,I),(var(C)->(get_attr(C,E,J)->true;J=[]),sort(J,K),'chr merge_attributes'(I,K,F),put_attr(C,E,F),G;(compound(C)->term_variables(C,L),attach_increment(L,I);true),H)), + A=(D:-M). generate_attr_unify_hook_many(A,B) :- make_attr(A,C,D,E), make_attr(A,F,G,H), - bagof(I,J^K^(member(J,D),I=sort(J,K)),L), + bagof(K,J^I^(member(J,D),K=sort(J,I)),L), list2conj(L,M), - bagof(K,J^member(sort(J,K),L),N), - bagof(O,P^Q^R^S^(member2(N,G,P-Q),O=(sort(Q,R),'chr merge_attributes'(P,R,S))),T), - bagof(S,P^R^U^member((U,'chr merge_attributes'(P,R,S)),T),V), + bagof(I,J^member(sort(J,I),L),N), + bagof(S,R^Q^P^O^(member2(N,G,R-Q),S=(sort(Q,P),'chr merge_attributes'(R,P,O))),T), + bagof(O,R^P^U^member((U,'chr merge_attributes'(R,P,O)),T),V), list2conj(T,W), make_attr(A,X,V,Y), make_attr(A,C,N,Z), - A1=attr_unify_hook(E,B1), + B1=attr_unify_hook(E,A1), get_target_module(C1), make_run_suspensions_loop(V,D1), make_run_suspensions_loop(N,E1), - 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)), - B=(A1:-F1). + H1=(M,(var(A1)->(get_attr(A1,C1,F1)->F1=H,W,X is C\/F,put_attr(A1,C1,Y),D1;put_attr(A1,C1,Z),E1);(compound(A1)->term_variables(A1,G1),attach_increment(G1,Z);true),E1)), + B=(B1:-H1). make_run_suspensions(A,B) :- ( chr_pp_flag(debugable,on) -> B='chr run_suspensions_d'(A) @@ -884,14 +884,14 @@ generate_insert_delete_constraint(A,B,C) :- generate_delete_constraint(D,A,C). generate_insert_constraint(A,B,C) :- make_name('$insert_in_store_',B,D), - E=..[D,F], - generate_insert_constraint_body(A,B,F,G), + F=..[D,E], + generate_insert_constraint_body(A,B,E,G), ( chr_pp_flag(store_counter,on) -> H='$insert_counter_inc' ; H=true ), - C=(E:-H,G). + C=(F:-H,G). generate_insert_constraint_body(default,A,B,C) :- get_target_module(_), get_max_constraint_index(D), @@ -910,24 +910,24 @@ generate_insert_constraint_body(global_singleton,A,B,C) :- global_singleton_store_name(A,D), C=b_setval(D,B). generate_insert_constraint_body(multi_store(A),B,C,D) :- - find_with_var_identity(E,[C],(member(F,A),chr_translate:generate_insert_constraint_body(F,B,C,E)),G), + find_with_var_identity(F,[C],(member(E,A),chr_translate:generate_insert_constraint_body(E,B,C,F)),G), list2conj(G,D). generate_multi_hash_insert_constraint_bodies([],_,_,true). -generate_multi_hash_insert_constraint_bodies([A|B],C,D,(E,F)) :- - multi_hash_store_name(C,A,G), - multi_hash_key(C,A,D,H,I), - E=(H,nb_getval(G,J),insert_ht(J,I,D)), - generate_multi_hash_insert_constraint_bodies(B,C,D,F). +generate_multi_hash_insert_constraint_bodies([A|B],E,F,(C,D)) :- + multi_hash_store_name(E,A,G), + multi_hash_key(E,A,F,H,I), + C=(H,nb_getval(G,J),insert_ht(J,I,F)), + generate_multi_hash_insert_constraint_bodies(B,E,F,D). generate_delete_constraint(A,B,C) :- make_name('$delete_from_store_',B,D), - E=..[D,F], - generate_delete_constraint_body(A,B,F,G), + F=..[D,E], + generate_delete_constraint_body(A,B,E,G), ( chr_pp_flag(store_counter,on) -> H='$delete_counter_inc' ; H=true ), - C=(E:-H,G). + C=(F:-H,G). generate_delete_constraint_body(default,A,B,C) :- get_target_module(_), get_max_constraint_index(D), @@ -947,23 +947,23 @@ generate_delete_constraint_body(global_singleton,A,_,B) :- global_singleton_store_name(A,C), B=b_setval(C,[]). generate_delete_constraint_body(multi_store(A),B,C,D) :- - find_with_var_identity(E,[C],(member(F,A),chr_translate:generate_delete_constraint_body(F,B,C,E)),G), + find_with_var_identity(F,[C],(member(E,A),chr_translate:generate_delete_constraint_body(E,B,C,F)),G), list2conj(G,D). generate_multi_hash_delete_constraint_bodies([],_,_,true). -generate_multi_hash_delete_constraint_bodies([A|B],C,D,(E,F)) :- - multi_hash_store_name(C,A,G), - multi_hash_key(C,A,D,H,I), - E=(H,nb_getval(G,J),delete_ht(J,I,D)), - generate_multi_hash_delete_constraint_bodies(B,C,D,F). +generate_multi_hash_delete_constraint_bodies([A|B],E,F,(C,D)) :- + multi_hash_store_name(E,A,G), + multi_hash_key(E,A,F,H,I), + C=(H,nb_getval(G,J),delete_ht(J,I,F)), + generate_multi_hash_delete_constraint_bodies(B,E,F,D). generate_delete_constraint_call(A,B,C) :- make_name('$delete_from_store_',A,D), C=..[D,B]. generate_insert_constraint_call(A,B,C) :- make_name('$insert_in_store_',A,D), C=..[D,B]. -generate_attach_code(A,[B|C]) :- - enumerate_stores_code(A,B), - generate_attach_code(A,C,[]). +generate_attach_code(C,[A|B]) :- + enumerate_stores_code(C,A), + generate_attach_code(C,B,[]). generate_attach_code([],A,A). generate_attach_code([A|B],C,D) :- get_store_type(A,E), @@ -986,8 +986,8 @@ multi_store_generate_attach_code([A|B],C,D,E) :- multi_hash_store_initialisations([],_,A,A). multi_hash_store_initialisations([A|B],C,D,E) :- multi_hash_store_name(C,A,F), - D=[(:-new_ht(G),nb_setval(F,G))|H], - multi_hash_store_initialisations(B,C,H,E). + D=[(:-new_ht(H),nb_setval(F,H))|G], + multi_hash_store_initialisations(B,C,G,E). global_ground_store_initialisation(A,B,C) :- global_ground_store_name(A,D), B=[(:-nb_setval(D,[]))|C]. @@ -997,10 +997,10 @@ global_singleton_store_initialisation(A,B,C) :- multi_hash_via_lookups([],_,A,A). multi_hash_via_lookups([A|B],C,D,E) :- multi_hash_via_lookup_name(C,A,F), - G=..[F,H,I], + I=..[F,G,H], multi_hash_store_name(C,A,J), - K=(nb_getval(J,L),lookup_ht(L,H,I)), - D=[(G:-K)|M], + L=(nb_getval(J,K),lookup_ht(K,G,H)), + D=[(I:-L)|M], multi_hash_via_lookups(B,C,M,E). multi_hash_via_lookup_name(A/B,C,D) :- ( integer(C) -> @@ -1057,10 +1057,10 @@ global_singleton_store_name(A/B,C) :- get_target_module(D), atom_concat_list(['$chr_store_global_singleton_',D,:,A,/,B],C). enumerate_stores_code(A,B) :- - C='$enumerate_suspensions'(D), - enumerate_store_bodies(A,D,E), + D='$enumerate_suspensions'(C), + enumerate_store_bodies(A,C,E), list2disj(E,F), - B=(C:-F). + B=(D:-F). enumerate_store_bodies([],_,[]). enumerate_store_bodies([A|B],C,D) :- ( is_stored(A) -> @@ -1075,14 +1075,14 @@ enumerate_store_body(default,A,B,C) :- get_constraint_index(A,D), get_target_module(E), get_max_constraint_index(F), - G=('chr global_term_ref_1'(H),get_attr(H,E,I)), + I=('chr global_term_ref_1'(G),get_attr(G,E,H)), ( F>1 -> J is D+1, - K=(arg(J,I,L),'chr sbag_member'(B,L)) + L=(arg(J,H,K),'chr sbag_member'(B,K)) ; - K='chr sbag_member'(B,I) + L='chr sbag_member'(B,H) ), - C=(G,K). + C=(I,L). enumerate_store_body(multi_hash([A|_]),B,C,D) :- multi_hash_enumerate_store_body(A,B,C,D). enumerate_store_body(global_ground,A,B,C) :- @@ -1105,24 +1105,24 @@ guard_simplification :- ). add_type_information_(_,[],true) :- !. -add_type_information_(A,[B|C],D) :- +add_type_information_(C,[A|B],D) :- !, - add_type_information(A,B,E), + add_type_information(C,A,E), D=(E,F), - add_type_information_(A,C,F). + add_type_information_(C,B,F). compute_derived_info(_,[],_,_,_,_,_,_,[],[]) :- !. -compute_derived_info(A,[B|C],D,E,F,G,H,I,J,K) :- +compute_derived_info(C,[A|B],D,E,F,G,H,I,J,K) :- !, - copy_term(A-F,L), - variable_replacement(A-F,L,M), - append(B,M,N), - list2conj(A,O), + copy_term(C-F,L), + variable_replacement(C-F,L,M), + append(A,M,N), + list2conj(C,O), negate_b(O,P), make_head_matchings_explicit_not_negated2(E,D,Q), list2conj(Q,R), term_variables(N,S), - term_variables(A-F-Q,T), + term_variables(C-F-Q,T), new_vars(T,S,U), append(N,U,V), negate_b(F,W), @@ -1133,11 +1133,11 @@ compute_derived_info(A,[B|C],D,E,F,G,H,I,J,K) :- ), copy_with_variable_replacement(X,Y,V), copy_with_variable_replacement(F,Z,V), - copy_with_variable_replacement(A,A1,V), + copy_with_variable_replacement(C,A1,V), list2conj(A1,B1), add_guard_to_head(H,Z,C1), add_guard_to_head(C1,B1,D1), - compute_derived_info(A,C,D,E,F,G,H,I,E1,F1), + compute_derived_info(C,B,D,E,F,G,H,I,E1,F1), append([Y],E1,J), append([D1],F1,K). simplify_guard(A,B,C,D,E) :- @@ -1164,16 +1164,16 @@ head_subset([A|B],C,D,E,F) :- head_subset(B,H,I,G,J), D=I, F=J. -head_subset(A,[B|C],D,E,F) :- +head_subset(C,[A|B],D,E,F) :- !, ( - head_subset(A,B,G,E,_), + head_subset(C,A,G,E,_), D=G, - F=C + F=B ; - head_subset(A,C,H,E,I), + head_subset(C,B,H,E,I), D=H, - F=[B|I] + F=[A|I] ). head_subset(A,B,C,D,E) :- variable_replacement(A,B,D,C), @@ -1197,17 +1197,17 @@ extract_variables([A|B],C) :- append(D,E,C). insert_variables([],[],[]) :- !. -insert_variables(A,[B|C],[D|E]) :- - B=..[F|G], +insert_variables(E,[A|B],[C|D]) :- + A=..[F|G], length(G,H), - take_first_N(A,H,I,J), - D=..[F|I], - insert_variables(J,C,E). + take_first_N(E,H,I,J), + C=..[F|I], + insert_variables(J,B,D). take_first_N(A,0,[],A) :- !. -take_first_N([A|B],C,[A|D],E) :- - F is C-1, - take_first_N(B,F,D,E). +take_first_N([A|B],D,[A|C],E) :- + F is D-1, + take_first_N(B,F,C,E). make_matchings_explicit([],[],_,A,A,[]). make_matchings_explicit([A|B],[C|D],E,F,G,H) :- ( var(A) -> @@ -1245,20 +1245,20 @@ make_matchings_explicit_not_negated([A|B],[C|D],E,F) :- H=E, make_matchings_explicit_not_negated(B,D,H,G). add_guard_to_head([],_,[]). -add_guard_to_head([A|B],C,[D|E]) :- +add_guard_to_head([A|B],E,[C|D]) :- ( var(A) -> - find_guard_info_for_var(A,C,D) + find_guard_info_for_var(A,E,C) ; functor(A,F,_), A=..[F|G], - add_guard_to_head(G,C,H), - D=..[F|H] + add_guard_to_head(G,E,H), + C=..[F|H] ), - add_guard_to_head(B,C,E). -find_guard_info_for_var(A,(B,C),D) :- + add_guard_to_head(B,E,D). +find_guard_info_for_var(C,(A,B),D) :- !, - find_guard_info_for_var(A,B,E), - find_guard_info_for_var(E,C,D). + find_guard_info_for_var(C,A,E), + find_guard_info_for_var(E,B,D). find_guard_info_for_var(A,B,C) :- ( B=(D=E), A==D -> @@ -1300,29 +1300,29 @@ replace_some_heads([],[A|B],[C|D],[E|F],[],[G|H],I,J,K) :- G=A, replace_some_heads([],B,D,[E|F],[],H,I,J,K) ). -replace_some_heads([A|B],C,[D|E],[F|G],[H|I],J,K,L,M) :- +replace_some_heads([A|B],I,[C|D],[E|F],[G|H],J,K,L,M) :- !, - ( D==F -> - H=F, - replace_some_heads(B,C,E,G,I,J,K,L,M) + ( C==E -> + G=E, + replace_some_heads(B,I,D,F,H,J,K,L,M) ; - ( F=functor(N,O,P), - D==N -> + ( E=functor(N,O,P), + C==N -> length(Q,P), ( var(A) -> R=[], - H=..[O|Q] + G=..[O|Q] ; A=..[O|S], use_same_args(S,Q,T,K,L,R), - H=..[O|T] + G=..[O|T] ), - replace_some_heads(B,C,E,G,I,J,K,L,U), + replace_some_heads(B,I,D,F,H,J,K,L,U), append(R,U,M) ) ; - H=A, - replace_some_heads(B,C,E,[F|G],I,J,K,L,M) + G=A, + replace_some_heads(B,I,D,[E|F],H,J,K,L,M) ). use_same_args([],[],[],_,_,[]). use_same_args([A|B],[_|C],[D|E],F,G,H) :- @@ -1401,25 +1401,25 @@ flatten_stuff(chr_pp_not_in_store(A),[A]) :- !. flatten_stuff(_,[]). unify_stuff(_,[],[]). -unify_stuff(A,[B|C],[D|E]) :- - B\==D, - term_variables(B,F), - term_variables(D,G), +unify_stuff(E,[A|B],[C|D]) :- + A\==C, + term_variables(A,F), + term_variables(C,G), intersect_eq(F,G,H), - check_safe_unif(B,D,H), - variable_replacement(B,D,I), + check_safe_unif(A,C,H), + variable_replacement(A,C,I), check_replacement(I), term_variables(I,J), list_difference_eq(J,F,K), - intersect_eq(A,K,L), + intersect_eq(E,K,L), L==[], - B=D, - unify_stuff(A,C,E), + A=C, + unify_stuff(E,B,D), !. -unify_stuff(A,B,[_|C]) :- - unify_stuff(A,B,C). -unify_stuff(A,[_|B],C) :- - unify_stuff(A,B,C). +unify_stuff(B,C,[_|A]) :- + unify_stuff(B,C,A). +unify_stuff(B,[_|A],C) :- + unify_stuff(B,A,C). check_safe_unif(A,B,C) :- var(A), !, @@ -1472,20 +1472,20 @@ check_replacement(A) :- !, length(B,D). check_replacement([],[]). -check_replacement([A-_|B],[A|C]) :- - check_replacement(B,C). +check_replacement([B-_|A],[B|C]) :- + check_replacement(A,C). add_failing_occ(A,B,C,D,E,F,_,G,H) :- A=pragma(rule(_,_,I,_),ids(J,K),_,_,_), append(K,J,L), missing_partner_cond(B,C,L,D,M,N,G), - copy_term((N,B,C),(O,P,Q)), - variable_replacement((N,B,C),(O,P,Q),H), + copy_term((N,B,C),(Q,O,P)), + variable_replacement((N,B,C),(Q,O,P),H), copy_with_variable_replacement(I,R,H), extract_explicit_matchings(R,S), negate_b(S,T), copy_with_variable_replacement(M,U,H), - ( check_safe_unif2(F,O), - F=O -> + ( check_safe_unif2(F,Q), + F=Q -> E=[(T;U)] ; E=[chr_pp_void_info] @@ -1494,9 +1494,9 @@ missing_partner_cond([],[],[],_,fail,_,_). missing_partner_cond([A|B],[_|C],[D|E],D,F,A,G) :- !, missing_partner_cond(B,C,E,D,F,A,G). -missing_partner_cond([A|B],[_|C],[_|D],E,F,G,H/I) :- - F=(chr_pp_not_in_store(A);J), - missing_partner_cond(B,C,D,E,J,G,H/I). +missing_partner_cond([A|B],[_|C],[_|D],G,H,I,E/F) :- + H=(chr_pp_not_in_store(A);J), + missing_partner_cond(B,C,D,G,J,I,E/F). extract_explicit_matchings(A=B) :- var(A), var(B), @@ -1698,14 +1698,14 @@ constraint_prelude(A/B,C) :- use_auxiliary_predicate(insert_constraint_internal), generate_insert_constraint_call(A/B,E,K), make_name(attach_,A/B,L), - M=..[L,N,E], - O=(arg(2,E,P),'chr update_mutable'(inactive,P)), - C=(G:-insert_constraint_internal(_,N,E,I:H,J,D),K,M,O,('chr debug_event'(call(E)),H;'chr debug_event'(fail(E)),!,fail),('chr debug_event'(exit(E));'chr debug_event'(redo(E)),fail)) + N=..[L,M,E], + P=(arg(2,E,O),'chr update_mutable'(inactive,O)), + C=(G:-insert_constraint_internal(_,M,E,I:H,J,D),K,N,P,('chr debug_event'(call(E)),H;'chr debug_event'(fail(E)),!,fail),('chr debug_event'(exit(E));'chr debug_event'(redo(E)),fail)) ; ( get_allocation_occurrence(A/B,0) -> gen_insert_constraint_internal_goal(A/B,Q,F,D,E), - O=(arg(2,E,P),'chr update_mutable'(inactive,P)), - C=(G:-Q,O,H) + P=(arg(2,E,O),'chr update_mutable'(inactive,O)), + C=(G:-Q,P,H) ) ; C=(G:-H) @@ -1742,46 +1742,46 @@ gen_cond_attach_goal(A/B,C,D,E,F) :- build_head(A,B,[0],D,G), ( may_trigger(A/B) -> make_name(attach_,A/B,H), - I=..[H,J,F] + J=..[H,I,F] ; - I=true + J=true ), get_target_module(K), L=..[A|E], generate_insert_constraint_call(A/B,F,M), use_auxiliary_predicate(insert_constraint_internal), use_auxiliary_predicate(activate_constraint), - C=((var(F)->insert_constraint_internal(N,J,F,K:G,L,E);activate_constraint(N,J,F,_)),(N==yes->M,I;true)). + C=((var(F)->insert_constraint_internal(N,I,F,K:G,L,E);activate_constraint(N,I,F,_)),(N==yes->M,J;true)). gen_insert_constraint_internal_goal(A/B,C,D,E,F) :- vars_susp(B,E,F,D), ( may_trigger(A/B) -> make_name(attach_,A/B,G), - H=..[G,I,F], + I=..[G,H,F], build_head(A,B,[0],D,J), get_target_module(K), L=K:J ; - H=true, + I=true, L=true ), M=..[A|E], generate_insert_constraint_call(A/B,F,N), use_auxiliary_predicate(insert_constraint_internal), - C=(insert_constraint_internal(_,I,F,L,M,E),N,H). + C=(insert_constraint_internal(_,H,F,L,M,E),N,I). gen_uncond_attach_goal(A,B,C,D) :- ( may_trigger(A) -> make_name(attach_,A,E), - F=..[E,G,B] + G=..[E,F,B] ; - F=true + G=true ), generate_insert_constraint_call(A,B,H), ( chr_pp_flag(late_allocation,on) -> use_auxiliary_predicate(activate_constraint), - C=(activate_constraint(I,G,B,D),(I==yes->H,F;true)) + C=(activate_constraint(I,F,B,D),(I==yes->H,G;true)) ; use_auxiliary_predicate(activate_constraint), - C=activate_constraint(I,G,B,D) + C=activate_constraint(I,F,B,D) ). head1_code(A,B,C,D,E,F,G,H,I) :- D=pragma(J,_,_,_,K), @@ -1812,17 +1812,17 @@ gen_alloc_inc_clause(A/B,C,D,E,F) :- gen_cond_allocation(A,B,C,D,E) :- gen_allocation(A,B,C,D,F), E=(var(B)->F;true). -gen_allocation(A,B,C/D,E,F) :- - ( may_trigger(C/D) -> - build_head(C,D,[0],E,G), +gen_allocation(C,D,A/B,E,F) :- + ( may_trigger(A/B) -> + build_head(A,B,[0],E,G), get_target_module(H), I=H:G ; I=true ), - J=..[C|A], + J=..[A|C], use_auxiliary_predicate(allocate_constraint), - F=allocate_constraint(I,B,J,A). + F=allocate_constraint(I,D,J,C). gen_occ_allocation(A,B,C,D,E,F) :- get_allocation_occurrence(A,G), ( chr_pp_flag(debugable,off), @@ -1848,8 +1848,8 @@ guard_via_reschedule_main(A,B,C,D) :- dependency_reorder(F,G), units2goal(G,D). units2goal([],true). -units2goal([unit(_,A,_,_)|B],(A,C)) :- - units2goal(B,C). +units2goal([unit(_,B,_,_)|A],(B,C)) :- + units2goal(A,C). dependency_reorder(A,B) :- dependency_reorder(A,[],B). dependency_reorder([],A,B) :- @@ -1955,8 +1955,8 @@ functional_dependency_analysis_main([A|B]) :- true ), functional_dependency_analysis_main(B). -discover_unique_pattern(A,B/C,D,E,F) :- - A=pragma(G,_,_,_,D), +discover_unique_pattern(C,A/B,D,E,F) :- + C=pragma(G,_,_,_,D), G=rule(H,I,J,_), ( H=[K], I=[L] -> @@ -1971,7 +1971,7 @@ discover_unique_pattern(A,B/C,D,E,F) :- term_variables(K,N), select_pragma_unique_variables(N,M,O), copy_term_nat(K-O,E-F), - functor(K,B,C). + functor(K,A,B). select_pragma_unique_variables([],_,[]). select_pragma_unique_variables([A|B],C,D) :- ( lookup_eq(C,A,_) -> @@ -2018,8 +2018,8 @@ symmetry_analysis(A) :- ). symmetry_analysis_main([]). symmetry_analysis_main([A|B]) :- - A=pragma(C,ids(D,E),_,_,F), - C=rule(G,H,_,_), + A=pragma(E,ids(C,D),_,_,F), + E=rule(G,H,_,_), ( ( \+chr_pp_flag(check_unnecessary_active,simplification) @@ -2027,8 +2027,8 @@ symmetry_analysis_main([A|B]) :- H==[] ), G\==[] -> - symmetry_analysis_heads(G,D,[],[],C,F), - symmetry_analysis_heads(H,E,[],[],C,F) + symmetry_analysis_heads(G,C,[],[],E,F), + symmetry_analysis_heads(H,D,[],[],E,F) ; true ), @@ -2046,27 +2046,27 @@ symmetry_analysis_heads([A|B],[C|D],E,F,G,H) :- true ), symmetry_analysis_heads(B,D,[A|E],[C|F],G,H). -simplification_code(A,B,C,D,E/F,G,H,I,J) :- - D=pragma(K,_,_,_,_), - head_info(A,F,_,L,M,N), - build_head(E,F,H,M,O), - get_constraint_mode(E/F,P), +simplification_code(C,D,E,F,A/B,G,H,I,J) :- + F=pragma(K,_,_,_,_), + head_info(C,B,_,L,M,N), + build_head(A,B,H,M,O), + get_constraint_mode(A/B,P), head_arg_matches(N,P,[],Q,R,[],S), - rest_heads_retrieval_and_matching(B,C,A,T,U,R,V,[],[],[],S,_), + rest_heads_retrieval_and_matching(D,E,C,T,U,R,V,[],[],[],S,_), guard_body_copies2(K,V,W,X), guard_via_reschedule(T,W,O-Q,Y), - gen_uncond_susps_detachments(U,B,Z), - gen_cond_susp_detachment(H,L,E/F,A1), + gen_uncond_susps_detachments(U,D,Z), + gen_cond_susp_detachment(H,L,A/B,A1), ( chr_pp_flag(debugable,on) -> K=rule(_,_,B1,C1), my_term_copy(B1-C1,V,D1-E1), - F1='chr debug_event'(try([L|G1],[],D1,E1)), - H1='chr debug_event'(apply([L|G1],[],D1,E1)), - instrument_goal(I1,F1,H1,J1) + G1='chr debug_event'(try([L|F1],[],D1,E1)), + H1='chr debug_event'(apply([L|F1],[],D1,E1)), + instrument_goal(I1,G1,H1,J1) ; J1=I1 ), - ( unconditional_occurrence(E/F,G), + ( unconditional_occurrence(A/B,G), chr_pp_flag(late_allocation,on) -> I1=true ; @@ -2080,67 +2080,67 @@ head_arg_matches(A,B,C,D,E,F,G) :- head_arg_matches_(A,B,C,F,H,E,G), list2conj(H,D). head_arg_matches_([],[],A,B,[],A,B). -head_arg_matches_([A-B|C],[D|E],F,G,H,I,J) :- - ( var(A) -> - ( lookup_eq(F,A,K) -> +head_arg_matches_([B-C|A],[D|E],F,G,H,I,J) :- + ( var(B) -> + ( lookup_eq(F,B,K) -> ( D= + -> - ( memberchk_eq(A,G) -> - H=[B=K|L], + ( memberchk_eq(B,G) -> + H=[C=K|L], M=G ; - H=[B==K|L], - M=[A|G] + H=[C==K|L], + M=[B|G] ) ; - H=[B==K|L], + H=[C==K|L], M=G ), N=F ; - N=[A-B|F], + N=[B-C|F], H=L, ( D= + -> - M=[A|G] + M=[B|G] ; M=G ) ), - O=C, + O=A, P=E ; - ( atomic(A) -> + ( atomic(B) -> ( D= + -> - H=[B=A|L] + H=[C=B|L] ; - H=[B==A|L] + H=[C==B|L] ), F=N, M=G, - O=C, + O=A, P=E ) ; ( D== +, - is_ground(G,A) -> - copy_with_variable_replacement(A,Q,F), - H=[B=Q|L], + is_ground(G,B) -> + copy_with_variable_replacement(B,Q,F), + H=[C=Q|L], F=N, M=G, - O=C, + O=A, P=E ) ; - A=..[_|R], - functor(A,S,T), + B=..[_|R], + functor(B,S,T), functor(U,S,T), U=..[_|V], ( D= + -> - H=[B=U|L] + H=[C=U|L] ; - H=[nonvar(B),B=U|L] + H=[nonvar(C),C=U|L] ), pairup(R,V,W), - append(W,C,O), + append(W,A,O), replicate(T,D,X), append(X,E,P), N=F, @@ -2173,12 +2173,12 @@ rest_heads_retrieval_and_matching(A,B,C,D,E,F,G,H,I,J,K,L) :- ). rest_heads_retrieval_and_matching_n([],_,_,_,_,[],[],A,A,B,C,C) :- instantiate_pattern_goals(B). -rest_heads_retrieval_and_matching_n([A|B],[_|C],D,E,F,[G|H],[I|J],K,L,M,N,O) :- +rest_heads_retrieval_and_matching_n([A|B],[_|C],H,I,J,[D|E],[F|G],K,L,M,N,O) :- functor(A,P,Q), head_info(A,Q,R,_,_,S), get_store_type(P/Q,T), ( T==default -> - passive_head_via(A,[F|D],M,K,U,V,W), + passive_head_via(A,[J|H],M,K,U,V,W), get_max_constraint_index(X), ( X==1 -> Y=V @@ -2190,38 +2190,38 @@ rest_heads_retrieval_and_matching_n([A|B],[_|C],D,E,F,[G|H],[I|J],K,L,M,N,O) :- create_get_mutable(active,B1,C1), get_constraint_mode(P/Q,D1), head_arg_matches(S,D1,K,E1,F1,N,G1), - H1=(U,'chr sbag_member'(I,Y),I=I1,C1) + I1=(U,'chr sbag_member'(F,Y),F=H1,C1) ; - existential_lookup(T,A,[F|D],K,I1,B1,H1,I,S,J1), + existential_lookup(T,A,[J|H],K,H1,B1,I1,F,S,J1), get_constraint_mode(P/Q,D1), filter_mode(J1,S,D1,K1), head_arg_matches(J1,K1,K,E1,F1,N,G1), W=M ), - I1=..[suspension,_,B1,_,_,_,_|R], - different_from_other_susps(A,I,D,E,L1), - G=(H1,L1,E1), - rest_heads_retrieval_and_matching_n(B,C,[A|D],[I|E],F,H,J,F1,L,W,G1,O). + H1=..[suspension,_,B1,_,_,_,_|R], + different_from_other_susps(A,F,H,I,L1), + D=(I1,L1,E1), + rest_heads_retrieval_and_matching_n(B,C,[A|H],[F|I],J,E,G,F1,L,W,G1,O). filter_mode([],_,_,[]). -filter_mode([A-B|C],[_-D|E],[F|G],H) :- - ( B==D -> +filter_mode([B-C|A],[_-E|D],[F|G],H) :- + ( C==E -> H=[F|I], - filter_mode(C,E,G,I) + filter_mode(A,D,G,I) ; - filter_mode([A-B|C],E,G,H) + filter_mode([B-C|A],D,G,H) ). instantiate_pattern_goals([]). -instantiate_pattern_goals([_-attr(A,B,C)|D]) :- +instantiate_pattern_goals([_-attr(B,C,D)|A]) :- get_max_constraint_index(E), ( E==1 -> - C=true + D=true ; - make_attr(E,F,_,A), - or_list(B,G), + make_attr(E,F,_,B), + or_list(C,G), !, - C=(F/\G=:=G) + D=(F/\G=:=G) ), - instantiate_pattern_goals(D). + instantiate_pattern_goals(A). check_unique_keys([],_). check_unique_keys([A|B],C) :- lookup_eq(C,A,_), @@ -2268,15 +2268,15 @@ gen_get_mod_constraints(A,B,C) :- B=('chr global_term_ref_1'(E),get_attr(E,D,F),F=C) ; ( A=[G] -> - H='chr via_1'(G,I) + I='chr via_1'(G,H) ; ( A=[G,J] -> - H='chr via_2'(G,J,I) + I='chr via_2'(G,J,H) ) ; - H='chr via'(A,I) + I='chr via'(A,H) ), - B=(H,get_attr(I,D,F),F=C) + B=(I,get_attr(H,D,F),F=C) ). guard_body_copies(A,B,C,D) :- guard_body_copies2(A,B,E,D), @@ -2285,10 +2285,10 @@ guard_body_copies2(A,B,C,D) :- A=rule(_,_,E,F), conj2list(E,G), split_off_simple_guard(G,B,H,I), - my_term_copy(H-I,B,J,K-L), - append(K,[M],C), + my_term_copy(H-I,B,L,J-K), + append(J,[M],C), term_variables(I,N), - term_variables(L,O), + term_variables(K,O), ( chr_pp_flag(guard_locks,on), bagof('chr lock'(P)-(chr_runtime:unlock(P)),Q^(lists:member(Q,N),pairlist:lookup_eq(B,Q,P),memberchk_eq(P,O)),R) -> once(pairup(S,T,R)) @@ -2298,9 +2298,9 @@ guard_body_copies2(A,B,C,D) :- ), list2conj(S,U), list2conj(T,V), - list2conj(L,W), + list2conj(K,W), M=(U,W,V), - my_term_copy(F,J,D). + my_term_copy(F,L,D). split_off_simple_guard([],_,[],[]). split_off_simple_guard([A|B],C,D,E) :- ( simple_guard(A,C) -> @@ -2341,9 +2341,9 @@ gen_uncond_susp_detachment(A,B,C) :- ( is_stored(B) -> ( may_trigger(B) -> make_name(detach_,B,D), - E=..[D,F,A] + F=..[D,E,A] ; - E=true + F=true ), ( chr_pp_flag(debugable,on) -> G='chr debug_event'(remove(A)) @@ -2352,7 +2352,7 @@ gen_uncond_susp_detachment(A,B,C) :- ), generate_delete_constraint_call(B,A,H), use_auxiliary_predicate(remove_constraint_internal), - C=(G,remove_constraint_internal(A,F,I),(I==yes->H,E;true)) + C=(G,remove_constraint_internal(A,E,I),(I==yes->H,F;true)) ; C=true ). @@ -2361,22 +2361,22 @@ gen_uncond_susps_detachments([A|B],[C|D],(E,F)) :- functor(C,G,H), gen_uncond_susp_detachment(A,G/H,E), gen_uncond_susps_detachments(B,D,F). -simpagation_head1_code(A,B,C,D,E/F,G,H,I) :- - D=pragma(J,ids(_,K),_,_,_), - J=rule(_,L,M,N), - head_info(A,F,_,O,P,Q), - get_constraint_mode(E/F,R), +simpagation_head1_code(C,D,E,F,A/B,G,H,I) :- + F=pragma(K,ids(_,J),_,_,_), + K=rule(_,L,M,N), + head_info(C,B,_,O,P,Q), + get_constraint_mode(A/B,R), head_arg_matches(Q,R,[],S,T,[],U), - build_head(E,F,G,P,V), - append(B,L,W), - append(C,K,X), - reorder_heads(_,A,W,X,Y,Z), - rest_heads_retrieval_and_matching(Y,Z,A,A1,B1,T,C1,[],[],[],U,_), - split_by_ids(Z,B1,C,D1,E1), - guard_body_copies2(J,C1,F1,G1), + build_head(A,B,G,P,V), + append(D,L,W), + append(E,J,X), + reorder_heads(_,C,W,X,Y,Z), + rest_heads_retrieval_and_matching(Y,Z,C,A1,B1,T,C1,[],[],[],U,_), + split_by_ids(Z,B1,E,D1,E1), + guard_body_copies2(K,C1,F1,G1), guard_via_reschedule(A1,F1,V-S,H1), - gen_uncond_susps_detachments(D1,B,I1), - gen_cond_susp_detachment(G,O,E/F,J1), + gen_uncond_susps_detachments(D1,D,I1), + gen_cond_susp_detachment(G,O,A/B,J1), ( chr_pp_flag(debugable,on) -> my_term_copy(M-N,C1,K1-L1), M1='chr debug_event'(try([O|D1],E1,K1,L1)), @@ -2398,15 +2398,15 @@ split_by_ids([A|B],[C|D],E,F,G) :- ), split_by_ids(B,D,E,H,I). simpagation_head2_code(A,B,C,D,E,F,G,H,I) :- - D=pragma(J,ids(K,L),_,_,M), - J=rule(N,_,O,P), + D=pragma(L,ids(J,K),_,_,M), + L=rule(N,_,O,P), append(N,B,Q), - append(K,C,R), + append(J,C,R), reorder_heads(M,A,Q,R,[S|T],[U|V]), simpagation_head2_prelude(A,S,[T,O,P],E,F,G,H,W), extend_id(G,X), - ( memberchk_eq(U,L) -> - simpagation_universal_searches(T,V,L,[S,A],J,E,Y,Z,A1,X,B1,W,C1) + ( memberchk_eq(U,K) -> + simpagation_universal_searches(T,V,K,[S,A],L,E,Y,Z,A1,X,B1,W,C1) ; W=C1, X=B1, @@ -2414,34 +2414,34 @@ simpagation_head2_code(A,B,C,D,E,F,G,H,I) :- Z=[S,A], A1=V ), - universal_search_iterator_end(Z,Y,J,E,B1,C1,D1), + universal_search_iterator_end(Z,Y,L,E,B1,C1,D1), simpagation_head2_new_worker(Z,Y,A1,D,E,F,B1,D1,I). simpagation_universal_searches([],[],_,A,_,_,[],A,[],B,B,C,C). -simpagation_universal_searches(A,[B|C],D,E,F,G,H,I,J,K,L,M,N) :- - A=[O|P], +simpagation_universal_searches(C,[A|B],D,E,F,G,H,I,J,K,L,M,N) :- + C=[O|P], inc_id(K,Q), - universal_search_iterator_end(E,A,F,G,K,M,R), - universal_search_iterator(A,E,F,G,K,R,S), - ( memberchk_eq(B,D) -> - simpagation_universal_searches(P,C,D,[O|E],F,G,H,I,J,Q,L,S,N) + universal_search_iterator_end(E,C,F,G,K,M,R), + universal_search_iterator(C,E,F,G,K,R,S), + ( memberchk_eq(A,D) -> + simpagation_universal_searches(P,B,D,[O|E],F,G,H,I,J,Q,L,S,N) ; L=Q, S=N, H=P, I=[O|E], - C=J + B=J ). -simpagation_head2_prelude(A,B,C,D/E,F,G,H,I) :- - head_info(A,E,J,K,L,M), - build_head(D,E,G,L,N), - get_constraint_mode(D/E,O), +simpagation_head2_prelude(C,D,E,A/B,F,G,H,I) :- + head_info(C,B,J,K,L,M), + build_head(A,B,G,L,N), + get_constraint_mode(A/B,O), head_arg_matches(M,O,[],P,Q), - lookup_passive_head(B,[A],Q,R,S), - gen_occ_allocation(D/E,F,J,K,L,T), + lookup_passive_head(D,[C],Q,R,S), + gen_occ_allocation(A/B,F,J,K,L,T), extend_id(G,U), - extra_active_delegate_variables(A,[B|C],Q,V), + extra_active_delegate_variables(C,[D|E],Q,V), append([S|L],V,W), - build_head(D,E,U,W,X), + build_head(A,B,U,W,X), Y=(N:-P,R,!,T,X), H=[Y|I]. extra_active_delegate_variables(A,B,C,D) :- @@ -2456,10 +2456,10 @@ delegate_variables(A,B,C,D,E) :- intersect_eq(F,G,H), list_difference_eq(H,D,I), translate(I,C,E). -simpagation_head2_new_worker([A|B],C,D,E,F/G,H,I,J,K) :- - E=pragma(L,ids(M,_),N,_,_), - L=rule(_,_,O,P), - get_prop_inner_loop_vars(B,[A,C,O,P],Q,R,S,T), +simpagation_head2_new_worker([A|B],E,F,G,C/D,H,I,J,K) :- + G=pragma(M,ids(L,_),N,_,_), + M=rule(_,_,O,P), + get_prop_inner_loop_vars(B,[A,E,O,P],Q,R,S,T), gen_var(U), gen_var(V), functor(A,W,X), @@ -2467,27 +2467,27 @@ simpagation_head2_new_worker([A|B],C,D,E,F/G,H,I,J,K) :- head_info(A,X,Y,U,_,Z), get_constraint_mode(W/X,A1), head_arg_matches(Z,A1,R,B1,C1), - D1=..[suspension,_,E1,_,_,_,_|Y], + E1=..[suspension,_,D1,_,_,_,_|Y], different_from_other_susps(A,U,B,T,F1), - create_get_mutable(active,E1,G1), - H1=(U=D1,G1,F1,B1), + create_get_mutable(active,D1,G1), + H1=(U=E1,G1,F1,B1), I1=[[U|V]|Q], - build_head(F,G,I,I1,J1), - rest_heads_retrieval_and_matching(C,D,[A|B],K1,L1,C1,M1,[A|B],[U|T],[]), - split_by_ids(D,L1,M,N1,O1), - split_by_ids(D,C,M,P1,_), + build_head(C,D,I,I1,J1), + rest_heads_retrieval_and_matching(E,F,[A|B],K1,L1,C1,M1,[A|B],[U|T],[]), + split_by_ids(F,L1,L,N1,O1), + split_by_ids(F,E,L,P1,_), gen_uncond_susps_detachments([U|N1],[A|P1],Q1), R1=[V|Q], - build_head(F,G,I,R1,S1), + build_head(C,D,I,R1,S1), T1=[[]|Q], - build_head(F,G,I,T1,U1), - guard_body_copies2(L,M1,V1,W1), + build_head(C,D,I,T1,U1), + guard_body_copies2(M,M1,V1,W1), guard_via_reschedule(K1,V1,v(J1,H1),X1), ( W1\==true, - is_observed(F/G,H) -> - gen_uncond_attach_goal(F/G,S,Y1,Z1), - gen_state_cond_call(S,G,S1,Z1,A2), - gen_state_cond_call(S,G,U1,Z1,B2) + is_observed(C/D,H) -> + gen_uncond_attach_goal(C/D,S,Y1,Z1), + gen_state_cond_call(S,D,S1,Z1,A2), + gen_state_cond_call(S,D,U1,Z1,B2) ; Y1=true, A2=S1, @@ -2510,42 +2510,42 @@ simpagation_head2_new_worker([A|B],C,D,E,F/G,H,I,J,K) :- J=[H2|K]. gen_state_cond_call(A,B,C,D,E) :- length(F,B), - G=..[suspension,_,H,_,I,_,_|F], - create_get_mutable(active,H,J), - create_get_mutable(D,I,K), - E=(A=G,J,K->'chr update_mutable'(inactive,H),C;true). + I=..[suspension,_,G,_,H,_,_|F], + create_get_mutable(active,G,J), + create_get_mutable(D,H,K), + E=(A=I,J,K->'chr update_mutable'(inactive,G),C;true). propagation_code(A,B,C,D,E,F,G,H,I,J) :- ( B==[] -> propagation_single_headed(A,D,E,F,G,H,I,J) ; propagation_multi_headed(A,B,C,D,E,F,G,H,I,J) ). -propagation_single_headed(A,B,C,D/E,F,G,H,I) :- - head_info(A,E,J,K,L,M), - build_head(D,E,G,L,N), +propagation_single_headed(C,D,E,A/B,F,G,H,I) :- + head_info(C,B,J,K,L,M), + build_head(A,B,G,L,N), inc_id(G,O), - build_head(D,E,O,L,P), - get_constraint_mode(D/E,Q), + build_head(A,B,O,L,P), + get_constraint_mode(A/B,Q), head_arg_matches(M,Q,[],R,S), - guard_body_copies(B,S,T,U), - gen_occ_allocation(D/E,F,J,K,L,V), + guard_body_copies(D,S,T,U), + gen_occ_allocation(A/B,F,J,K,L,V), W=P, ( U\==true, - is_observed(D/E,F) -> - gen_uncond_attach_goal(D/E,K,X,Y), - gen_state_cond_call(K,E,W,Y,Z) + is_observed(A/B,F) -> + gen_uncond_attach_goal(A/B,K,X,Y), + gen_state_cond_call(K,B,W,Y,Z) ; X=true, Z=W ), - ( unconditional_occurrence(D/E,F), + ( unconditional_occurrence(A/B,F), chr_pp_flag(late_allocation,on) -> A1=true ; A1=! ), ( chr_pp_flag(debugable,on) -> - B=rule(_,_,B1,C1), + D=rule(_,_,B1,C1), my_term_copy(B1-C1,S,D1-E1), F1='chr debug_event'(try([],[K],D1,E1)), G1='chr debug_event'(apply([],[K],D1,E1)), @@ -2553,9 +2553,9 @@ propagation_single_headed(A,B,C,D/E,F,G,H,I) :- ; H1=A1 ), - ( may_trigger(D/E) -> - I1='chr novel_production'(K,C), - J1='chr extend_history'(K,C) + ( may_trigger(A/B) -> + I1='chr novel_production'(K,E), + J1='chr extend_history'(K,E) ; I1=true, J1=true @@ -2567,18 +2567,18 @@ propagation_multi_headed(A,B,C,D,E,F,G,H,I,J) :- propagation_prelude(A,B,D,F,G,H,I,M), extend_id(H,N), propagation_nested_code(L,[K,A],C,D,E,F,G,N,M,J). -propagation_prelude(A,[B|C],D,E/F,G,H,I,J) :- - head_info(A,F,K,L,M,N), - build_head(E,F,H,M,O), - get_constraint_mode(E/F,P), +propagation_prelude(E,[A|B],F,C/D,G,H,I,J) :- + head_info(E,D,K,L,M,N), + build_head(C,D,H,M,O), + get_constraint_mode(C/D,P), head_arg_matches(N,P,[],Q,R), - D=rule(_,_,S,T), - extra_active_delegate_variables(A,[B,C,S,T],R,U), - lookup_passive_head(B,[A],R,V,W), - gen_occ_allocation(E/F,G,K,L,M,X), + F=rule(_,_,S,T), + extra_active_delegate_variables(E,[A,B,S,T],R,U), + lookup_passive_head(A,[E],R,V,W), + gen_occ_allocation(C/D,G,K,L,M,X), extend_id(H,Y), append([W|M],U,Z), - build_head(E,F,Y,Z,A1), + build_head(C,D,Y,Z,A1), B1=A1, C1=(O:-Q,V,!,X,B1), I=[C1|J]. @@ -2590,49 +2590,49 @@ propagation_nested_code([A|B],C,D,E,F,G,H,I,J,K) :- universal_search_iterator([A|B],C,E,G,I,L,M), inc_id(I,N), propagation_nested_code(B,[A|C],D,E,F,G,H,N,M,K). -propagation_body(A,B,C,D,E,F/G,H,I,J,K) :- - D=rule(_,_,L,M), - get_prop_inner_loop_vars(B,[A,L,M],N,O,P,Q), +propagation_body(C,D,E,F,G,A/B,H,I,J,K) :- + F=rule(_,_,L,M), + get_prop_inner_loop_vars(D,[C,L,M],N,O,P,Q), gen_var(R), gen_var(S), - functor(A,T,U), + functor(C,T,U), gen_vars(U,V), - W=..[suspension,_,X,_,_,_,_|V], - create_get_mutable(active,X,Y), - Z=(R=W,Y), + X=..[suspension,_,W,_,_,_,_|V], + create_get_mutable(active,W,Y), + Z=(R=X,Y), A1=[[R|S]|N], - build_head(F,G,I,A1,B1), + build_head(A,B,I,A1,B1), C1=[S|N], - build_head(F,G,I,C1,D1), + build_head(A,B,I,C1,D1), E1=D1, - A=..[_|F1], + C=..[_|F1], pairup(F1,V,G1), get_constraint_mode(T/U,H1), head_arg_matches(G1,H1,O,I1,J1), - different_from_other_susps(A,R,B,Q,K1), - guard_body_copies(D,J1,L1,M1), + different_from_other_susps(C,R,D,Q,K1), + guard_body_copies(F,J1,L1,M1), ( M1\==true, - is_observed(F/G,H) -> - gen_uncond_attach_goal(F/G,P,N1,O1), - gen_state_cond_call(P,G,E1,O1,P1) + is_observed(A/B,H) -> + gen_uncond_attach_goal(A/B,P,N1,O1), + gen_state_cond_call(P,B,E1,O1,P1) ; N1=true, P1=E1 ), - ( is_least_occurrence(E) -> + ( is_least_occurrence(G) -> Q1=true, R1=true ; - get_occurrence(F/G,H,_,S1), - history_susps(C,[R|Q],P,S1,T1), - U1=..[t,E|T1], + get_occurrence(A/B,H,_,S1), + history_susps(E,[R|Q],P,S1,T1), + U1=..[t,G|T1], bagof('chr novel_production'(V1,W1),(lists:member(V1,T1),W1=X1),Y1), list2conj(Y1,Z1), Q1=(X1=U1,Z1), R1='chr extend_history'(P,X1) ), ( chr_pp_flag(debugable,on) -> - D=rule(_,_,L,M), + F=rule(_,_,L,M), my_term_copy(L-M,J1,A2-B2), C2='chr debug_event'(try([],[P,R|Q],A2,B2)), D2='chr debug_event'(apply([],[P,R|Q],A2,B2)) @@ -2655,15 +2655,15 @@ get_prop_inner_loop_vars([A],B,C,D,E,[]) :- head_arg_matches(I,J,[],_,D), extra_active_delegate_variables(A,B,D,K), append(H,K,C). -get_prop_inner_loop_vars([A|B],C,D,E,F,[G|H]) :- - get_prop_inner_loop_vars(B,[A|C],I,J,F,H), +get_prop_inner_loop_vars([A|B],E,F,G,H,[C|D]) :- + get_prop_inner_loop_vars(B,[A|E],I,J,H,D), functor(A,K,L), gen_var(M), - head_info(A,L,_,G,_,N), + head_info(A,L,_,C,_,N), get_constraint_mode(K/L,O), - head_arg_matches(N,O,J,_,E), - passive_delegate_variables(A,B,C,E,P), - append(P,[G,M|I],D). + head_arg_matches(N,O,J,_,G), + passive_delegate_variables(A,B,E,G,P), + append(P,[C,M|I],F). gen_var_susp_list_for([A],B,C,D,E,F) :- !, functor(A,G,H), @@ -2689,15 +2689,15 @@ pre_vars_and_susps([A],B,C,D,[]) :- head_arg_matches(H,I,[],_,D), extra_active_delegate_variables(A,B,D,J), append(G,J,C). -pre_vars_and_susps([A|B],C,D,E,[F|G]) :- - pre_vars_and_susps(B,[A|C],H,I,G), +pre_vars_and_susps([A|B],E,F,G,[C|D]) :- + pre_vars_and_susps(B,[A|E],H,I,D), functor(A,J,K), gen_var(L), - head_info(A,K,_,F,_,M), + head_info(A,K,_,C,_,M), get_constraint_mode(J/K,N), - head_arg_matches(M,N,I,_,E), - passive_delegate_variables(A,B,C,E,O), - append(O,[F,L|H],D). + head_arg_matches(M,N,I,_,G), + passive_delegate_variables(A,B,E,G,O), + append(O,[C,L|H],F). reorder_heads(A,B,C,D,E,F) :- ( chr_pp_flag(reorder_heads,on) -> reorder_heads_main(A,B,C,D,E,F) @@ -2709,7 +2709,7 @@ reorder_heads_main(A,B,C,D,E,F) :- term_variables(B,G), H=entry([],[],G,C,D,A), copy_term_nat(H,I), - a_star(I,J^(chr_translate:final_data(J)),K^L^M^(chr_translate:expand_data(K,L,M)),N), + a_star(I,J^(chr_translate:final_data(J)),M^L^K^(chr_translate:expand_data(M,L,K)),N), I=H, N=entry(O,P,_,_,_,_), reverse(O,E), @@ -2748,7 +2748,7 @@ order_score(global_ground,A,_,_,_,_,B) :- order_score(global_singleton,_,_,_,_,_,A) :- A=1. order_score(multi_store(A),B,C,D,E,F,G) :- - find_with_var_identity(H,t(B,D,E),(lists:member(I,A),chr_translate:order_score(I,B,C,D,E,F,H)),J), + find_with_var_identity(I,t(B,D,E),(lists:member(H,A),chr_translate:order_score(H,B,C,D,E,F,I)),J), min_list(J,G). order_score_indexes([],_,_,A,B) :- A>0, @@ -2777,22 +2777,22 @@ order_score_vars(A,B,C,D) :- D is max(10-G,1)*100 ). order_score_count_vars([],_,_,0-0-0). -order_score_count_vars([A|B],C,D,E-F-G) :- - order_score_count_vars(B,C,D,H-I-J), - ( memberchk_eq(A,C) -> - E is H+1, - F=I, - G=J +order_score_count_vars([A|B],F,G,C-D-E) :- + order_score_count_vars(B,F,G,H-I-J), + ( memberchk_eq(A,F) -> + C is H+1, + D=I, + E=J ; - ( memberchk_eq(A,D) -> - F is I+1, - E=H, - G=J + ( memberchk_eq(A,G) -> + D is I+1, + C=H, + E=J ) ; - G is J+1, - E=H, - F=I + E is J+1, + C=H, + D=I ). create_get_mutable(A,B,C) :- B=mutable(A), @@ -2863,8 +2863,8 @@ and_pattern(A,B) :- C is A-1, D is 1< next_id(G,Q), R=M @@ -3013,11 +3013,11 @@ universal_search_iterator_end([A|B],C,D,E/F,G,H,I) :- dec_id(G,Q), R=[N|M] ), - build_head(E,F,Q,R,S), + build_head(C,D,Q,R,S), T=(P:-S), H=[T|I]. -universal_search_iterator([A|B],[C|D],E,F/G,H,I,J) :- - E=rule(_,_,K,L), +universal_search_iterator([A|B],[C|D],G,E/F,H,I,J) :- + G=rule(_,_,K,L), pre_vars_and_susps(D,[C,A,B,K,L],M,N,O), gen_var(P), functor(C,Q,R), @@ -3025,19 +3025,19 @@ universal_search_iterator([A|B],[C|D],E,F/G,H,I,J) :- head_info(C,R,S,T,_,U), get_constraint_mode(Q/R,V), head_arg_matches(U,V,N,W,X), - Y=..[suspension,_,Z,_,_,_,_|S], + Z=..[suspension,_,Y,_,_,_,_|S], different_from_other_susps(C,T,D,O,A1), - create_get_mutable(active,Z,B1), - C1=(T=Y,B1,A1,W), + create_get_mutable(active,Y,B1), + C1=(T=Z,B1,A1,W), lookup_passive_head(A,[C|D],X,D1,E1), inc_id(H,F1), G1=[[T|P]|M], - build_head(F,G,H,G1,H1), + build_head(E,F,H,G1,H1), passive_delegate_variables(C,D,[A,B,K,L],X,I1), append([E1|I1],[T,P|M],J1), - build_head(F,G,F1,J1,K1), + build_head(E,F,F1,J1,K1), L1=[P|M], - build_head(F,G,H,L1,M1), + build_head(E,F,H,L1,M1), N1=(H1:-C1,D1->K1;M1), I=[N1|J]. ai_observation_analysis(A) :- @@ -3062,21 +3062,21 @@ ai_observation_schedule_new_calls([A|B],C) :- ai_observation_schedule_new_calls(B,C). ai_observation_lub(odom(A,B),odom(A,C),odom(A,D)) :- ord_intersect(B,C,D). -ai_observation_top(A,odom(A,B)) :- - ord_empty(B). +ai_observation_top(B,odom(B,A)) :- + ord_empty(A). ai_observation_leq(odom(A,B),odom(A,C)) :- ord_subset(C,B). -ai_observation_observe(odom(A,B),C,odom(A,D)) :- - ord_del_element(B,C,D). -ai_observation_observe_list(odom(A,B),C,odom(A,D)) :- - list_to_ord_set(C,E), - ord_subtract(B,E,D). +ai_observation_observe(odom(A,B),D,odom(A,C)) :- + ord_del_element(B,D,C). +ai_observation_observe_list(odom(A,B),D,odom(A,C)) :- + list_to_ord_set(D,E), + ord_subtract(B,E,C). ai_observation_abstract_constraint(A,B,C) :- functor(A,D,E), C=D/E, member(C,B). ai_observation_abstract_constraints(A,B,C) :- - findall(D,(member(E,A),ai_observation_abstract_constraint(E,B,D)),C). + findall(E,(member(D,A),ai_observation_abstract_constraint(D,B,E)),C). ai_observation_abstract_goal(A,B,C) :- ai_observation_abstract_goal(A,B,C,[]). ai_observation_abstract_goal((A,B),C,D,E) :- @@ -3091,8 +3091,8 @@ ai_observation_abstract_goal((A->B),C,D,E) :- !, ai_observation_abstract_goal(A,C,D,F), ai_observation_abstract_goal(B,C,F,E). -ai_observation_abstract_goal(A,B,[C|D],D) :- - ai_observation_abstract_constraint(A,B,C), +ai_observation_abstract_goal(C,D,[A|B],B) :- + ai_observation_abstract_constraint(C,D,A), !. ai_observation_abstract_goal(true,_,A,A) :- !. @@ -3129,11 +3129,11 @@ generate_show_constraint(A,B,C,D) :- D=C ). generate_show_rules([],A,A). -generate_show_rules([A/B|C],[D|E],F) :- - functor(G,A,B), +generate_show_rules([B/C|A],[D|E],F) :- + functor(G,B,C), inc_rule_count(H), D=pragma(rule([],['$show',G],true,writeln(G)),ids([],[0,1]),[passive(1)],no,H), - generate_show_rules(C,E,F). + generate_show_rules(A,E,F). :-use_module(chr(chr_runtime)). :-use_module(chr(chr_hashtable_store)). :-use_module(library('clp/clp_events')). diff --git a/LGPL/chr/guard_entailment.pl b/LGPL/chr/guard_entailment.pl index 0830917c4..76981c217 100644 --- a/LGPL/chr/guard_entailment.pl +++ b/LGPL/chr/guard_entailment.pl @@ -1,6 +1,6 @@ /* Generated by CHR bootstrap compiler From: guard_entailment.chr - Date: [84,104,117,32,79,99,116,32,50,55,32,49,54,58,51,54,58,49,52,32,50,48,48,53,10] + Date: [84,104,117,32,83,101,112,32,50,56,32,49,51,58,50,53,58,53,50,32,50,48,48,54,10] DO NOT EDIT. EDIT THE CHR FILE INSTEAD */ diff --git a/library/system.yap b/library/system.yap index c7dc62224..851c91ed6 100644 --- a/library/system.yap +++ b/library/system.yap @@ -217,15 +217,15 @@ make_directory(Dir) :- var(Dir), !, throw(error(instantiation_error,mkdir(Dir))). make_directory(IDir) :- - atom(Dir), !, + atom(IDir), !, true_file_name(IDir, Dir), mkdir(Dir,Error), - handle_system_error(Error, off, mkdir(Dir)). + handle_system_error(Error, off, mkdir(IDir)). make_directory(Dir) :- throw(error(type_error(atom,Dir),make_directory(Dir))). rename_file(IOld, New) :- - atom(Old), atom(New), !, + atom(IOld), atom(New), !, true_file_name(IOld,Old), rename_file(Old, New, Error), handle_system_error(Error, off, rename_file(Old, New)).