diff --git a/C/index.c b/C/index.c index 58bafe309..6074664d5 100755 --- a/C/index.c +++ b/C/index.c @@ -11,7 +11,8 @@ * File: index.c * * comments: Indexing a Prolog predicate * * * -* Last rev: $Date: 2008-08-07 20:51:21 $,$Author: vsc $ * +* Last rev: $Date: 2008-08-07 20:51:21 $,$Author: vsc $ +** * $Log: not supported by cvs2svn $ * Revision 1.202 2008/07/11 17:02:07 vsc * fixes by Bart and Tom: mostly libraries but nasty one in indexing @@ -222,7 +223,8 @@ * Yap should respect single argument indexing. * * Revision 1.139 2005/07/06 19:33:53 ricroc -* TABLING: answers for completed calls can now be obtained by loading (new option) or executing (default) them from the trie data structure. +* TABLING: answers for completed calls can now be obtained by loading (new +*option) or executing (default) them from the trie data structure. * * Revision 1.138 2005/07/05 18:32:32 vsc * ifix some wierd cases in indexing code: @@ -246,7 +248,8 @@ * significantly used nowadays. * * Revision 1.132 2005/05/31 20:04:17 vsc -* fix cleanup of expand_clauses: make sure we have everything with NULL afterwards. +* fix cleanup of expand_clauses: make sure we have everything with NULL +*afterwards. * * Revision 1.131 2005/05/31 19:42:27 vsc * insert some more slack for indices in LU @@ -285,10 +288,15 @@ * bug fixes, I hope! * * Revision 1.121 2005/04/07 17:48:54 ricroc -* Adding tabling support for mixed strategy evaluation (batched and local scheduling) -* UPDATE: compilation flags -DTABLING_BATCHED_SCHEDULING and -DTABLING_LOCAL_SCHEDULING removed. To support tabling use -DTABLING in the Makefile or --enable-tabling in configure. -* NEW: yap_flag(tabling_mode,MODE) changes the tabling execution mode of all tabled predicates to MODE (batched, local or default). -* NEW: tabling_mode(PRED,MODE) changes the default tabling execution mode of predicate PRED to MODE (batched or local). +* Adding tabling support for mixed strategy evaluation (batched and local +*scheduling) +* UPDATE: compilation flags -DTABLING_BATCHED_SCHEDULING and +*-DTABLING_LOCAL_SCHEDULING removed. To support tabling use -DTABLING in the +*Makefile or --enable-tabling in configure. +* NEW: yap_flag(tabling_mode,MODE) changes the tabling execution mode of all +*tabled predicates to MODE (batched, local or default). +* NEW: tabling_mode(PRED,MODE) changes the default tabling execution mode of +*predicate PRED to MODE (batched or local). * * Revision 1.120 2005/03/15 18:29:23 vsc * fix GPL @@ -322,7 +330,8 @@ * fix bug in clause emulator * * Revision 1.112 2004/12/28 22:20:35 vsc -* some extra bug fixes for trail overflows: some cannot be recovered that easily, +* some extra bug fixes for trail overflows: some cannot be recovered that +*easily, * some can. * * Revision 1.111 2004/12/21 17:17:15 vsc @@ -338,13 +347,15 @@ * Handle overflows when allocating big clauses properly. * * Revision 1.108 2004/11/19 22:08:42 vsc -* replace SYSTEM_ERROR_INTERNAL by out OUT_OF_WHATEVER_ERROR whenever appropriate. +* replace SYSTEM_ERROR_INTERNAL by out OUT_OF_WHATEVER_ERROR whenever +*appropriate. * * Revision 1.107 2004/11/19 17:14:14 vsc * a few fixes for 64 bit compiling. * * Revision 1.106 2004/11/18 22:32:36 vsc -* fix situation where we might assume nonextsing double initialization of C predicates (use +* fix situation where we might assume nonextsing double initialization of C +*predicates (use * Hidden Pred Flag). * $host_type was double initialized. * @@ -452,10 +463,9 @@ * * *************************************************************************/ #ifdef SCCS -static char SccsId[] = "%W% %G%"; +static char SccsId[] = "%W% %G%"; #endif - /** @file index.c @@ -477,42 +487,42 @@ concatenate([],L,L). concatenate([H|T],A,[H|NT]) :- concatenate(T,A,NT). ~~~~~ -If the first argument for the goal is a list, then only the second clause -is of interest. If the first argument is the nil atom, the system needs to -look only for the first clause. The indexation generates instructions that -test the value of the first argument, and then proceed to a selected clause, +If the first argument for the goal is a list, then only the second clause +is of interest. If the first argument is the nil atom, the system needs to +look only for the first clause. The indexation generates instructions that +test the value of the first argument, and then proceed to a selected clause, or group of clauses. -Note that if the first argument was a free variable, then both clauses -should be tried. In general, indexation will not be useful if the first +Note that if the first argument was a free variable, then both clauses +should be tried. In general, indexation will not be useful if the first argument is a free variable. -When activating a predicate, a Prolog system needs to store state -information. This information, stored in a structure known as choice point -or fail point, is necessary when backtracking to other clauses for the -predicate. The operations of creating and using a choice point are very +When activating a predicate, a Prolog system needs to store state +information. This information, stored in a structure known as choice point +or fail point, is necessary when backtracking to other clauses for the +predicate. The operations of creating and using a choice point are very expensive, both in the terms of space used and time spent. -Creating a choice point is not necessary if there is only a clause for -the predicate as there are no clauses to backtrack to. With indexation, this -situation is extended: in the example, if the first argument was the atom -nil, then only one clause would really be of interest, and it is pointless to -create a choice point. This feature is even more useful if the first argument -is a list: without indexation, execution would try the first clause, creating -a choice point. The clause would fail, the choice point would then be used to -restore the previous state of the computation and the second clause would -be tried. The code generated by the indexation mechanism would behave -much more efficiently: it would test the first argument and see whether it +Creating a choice point is not necessary if there is only a clause for +the predicate as there are no clauses to backtrack to. With indexation, this +situation is extended: in the example, if the first argument was the atom +nil, then only one clause would really be of interest, and it is pointless to +create a choice point. This feature is even more useful if the first argument +is a list: without indexation, execution would try the first clause, creating +a choice point. The clause would fail, the choice point would then be used to +restore the previous state of the computation and the second clause would +be tried. The code generated by the indexation mechanism would behave +much more efficiently: it would test the first argument and see whether it is a list, and then proceed directly to the second clause. -An important side effect concerns the use of "cut". In the above -example, some programmers would use a "cut" in the first clause just to -inform the system that the predicate is not backtrackable and force the -removal the choice point just created. As a result, less space is needed but -with a great loss in expressive power: the "cut" would prevent some uses of -the procedure, like generating lists through backtracking. Of course, with +An important side effect concerns the use of "cut". In the above +example, some programmers would use a "cut" in the first clause just to +inform the system that the predicate is not backtrackable and force the +removal the choice point just created. As a result, less space is needed but +with a great loss in expressive power: the "cut" would prevent some uses of +the procedure, like generating lists through backtracking. Of course, with indexation the "cut" becomes useless: the choice point is not even created. -Indexation is also very important for predicates with a large number +Indexation is also very important for predicates with a large number of clauses that are used like tables: ~~~~~ @@ -553,23 +563,23 @@ rules([n(N)|T],I,O) :- rules_for_noun(N,I,N), rules(T,N,O). rules([v(V)|T],I,O) :- rules_for_verb(V,I,N), rules(T,N,O). rules([q(Q)|T],I,O) :- rules_for_qualifier(Q,I,N), rules(T,N,O). ~~~~~ -if the first argument of the goal is a list, its head will be tested, and only +if the first argument of the goal is a list, its head will be tested, and only the clauses matching it will be tried during execution. Some advice on how to take a good advantage of this mechanism: -+ ++ Try to make the first argument an input argument. -+ -Try to keep together all clauses whose first argument is not a -variable, that will decrease the number of tests since the other clauses are ++ +Try to keep together all clauses whose first argument is not a +variable, that will decrease the number of tests since the other clauses are always tried. -+ -Try to avoid predicates having a lot of clauses with the same key. ++ +Try to avoid predicates having a lot of clauses with the same key. For instance, the procedure: @@ -599,10 +609,10 @@ type_of_verb(rest,passive). */ /* - * This file compiles and removes the indexation code for the prolog compiler + * This file compiles and removes the indexation code for the prolog compiler * * Some remarks: *try_me always point to inside the code; - * try always points to outside + * try always points to outside * Algorithm: @@ -618,17 +628,19 @@ type_of_verb(rest,passive). --> type instructions --> count constants --> switch - for all arguments: - select new argument + for all arguments: + select new argument */ #include "absmi.h" #include "compile.h" -#include "index.h" #if DEBUG #include "yapio.h" #endif + +#include "index.h" + #ifndef NULL #define NULL (void *)0 #endif @@ -643,47 +655,56 @@ type_of_verb(rest,passive). #define SET_JLBL(X) #endif -static UInt do_index(ClauseDef *,ClauseDef *,struct intermediates *,UInt,UInt,int,int,CELL *); -static UInt do_compound_index(ClauseDef *,ClauseDef *,Term *t,struct intermediates *,UInt,UInt,UInt,UInt,int,int,int,CELL *,int); -static UInt do_dbref_index(ClauseDef *,ClauseDef *,Term,struct intermediates *,UInt,UInt,int,int,CELL *); -static UInt do_blob_index(ClauseDef *,ClauseDef *,Term,struct intermediates *,UInt,UInt,int,int,CELL *,int); +static UInt do_index(ClauseDef *, ClauseDef *, struct intermediates *, UInt, + UInt, int, int, CELL *); +static UInt do_compound_index(ClauseDef *, ClauseDef *, Term *t, + struct intermediates *, UInt, UInt, UInt, UInt, + int, int, int, CELL *, int); +static UInt do_dbref_index(ClauseDef *, ClauseDef *, Term, + struct intermediates *, UInt, UInt, int, int, + CELL *); +static UInt do_blob_index(ClauseDef *, ClauseDef *, Term, + struct intermediates *, UInt, UInt, int, int, CELL *, + int); -static UInt -cleanup_sw_on_clauses(CELL larg, UInt sz, OPCODE ecls) -{ +static UInt cleanup_sw_on_clauses(CELL larg, UInt sz, OPCODE ecls) { if (larg & 1) { return sz; } else { yamop *xp = (yamop *)larg; if (xp->opc == ecls) { if (xp->y_u.sssllp.s3 == 1) { - UInt nsz = sz + (UInt)(NEXTOP((yamop *)NULL,sssllp))+xp->y_u.sssllp.s1*sizeof(yamop *); - LOCK(ExpandClausesListLock); - if (ExpandClausesFirst == xp) - ExpandClausesFirst = xp->y_u.sssllp.snext; - if (ExpandClausesLast == xp) { - ExpandClausesLast = xp->y_u.sssllp.sprev; - } - if (xp->y_u.sssllp.sprev) { - xp->y_u.sssllp.sprev->y_u.sssllp.snext = xp->y_u.sssllp.snext; - } - if (xp->y_u.sssllp.snext) { - xp->y_u.sssllp.snext->y_u.sssllp.sprev = xp->y_u.sssllp.sprev; - } - UNLOCK(ExpandClausesListLock); + UInt nsz = sz + (UInt)(NEXTOP((yamop *)NULL, sssllp)) + + xp->y_u.sssllp.s1 * sizeof(yamop *); + LOCK(ExpandClausesListLock); + if (ExpandClausesFirst == xp) + ExpandClausesFirst = xp->y_u.sssllp.snext; + if (ExpandClausesLast == xp) { + ExpandClausesLast = xp->y_u.sssllp.sprev; + } + if (xp->y_u.sssllp.sprev) { + xp->y_u.sssllp.sprev->y_u.sssllp.snext = xp->y_u.sssllp.snext; + } + if (xp->y_u.sssllp.snext) { + xp->y_u.sssllp.snext->y_u.sssllp.sprev = xp->y_u.sssllp.sprev; + } + UNLOCK(ExpandClausesListLock); #if DEBUG - Yap_ExpandClauses--; - Yap_expand_clauses_sz -= (UInt)(NEXTOP((yamop *)NULL,sssllp))+xp->y_u.sssllp.s1*sizeof(yamop *); + Yap_ExpandClauses--; + Yap_expand_clauses_sz -= (UInt)(NEXTOP((yamop *)NULL, sssllp)) + + xp->y_u.sssllp.s1 * sizeof(yamop *); #endif - if (xp->y_u.sssllp.p->PredFlags & LogUpdatePredFlag) { - Yap_LUIndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL,sssllp)+xp->y_u.sssllp.s1*sizeof(yamop *); - } else - Yap_IndexSpace_EXT -= (UInt)(NEXTOP((yamop *)NULL,sssllp))+xp->y_u.sssllp.s1*sizeof(yamop *); - Yap_FreeCodeSpace((char *)xp); - return nsz; + if (xp->y_u.sssllp.p->PredFlags & LogUpdatePredFlag) { + Yap_LUIndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL, sssllp) + + xp->y_u.sssllp.s1 * sizeof(yamop *); + } else + Yap_IndexSpace_EXT -= (UInt)(NEXTOP((yamop *)NULL, sssllp)) + + xp->y_u.sssllp.s1 * sizeof(yamop *); + Yap_FreeCodeSpace((char *)xp); + return nsz; } else { - xp->y_u.sssllp.s3--; - return sz; + xp->y_u.sssllp.s3--; + return sz; } } else { return sz; @@ -691,9 +712,8 @@ cleanup_sw_on_clauses(CELL larg, UInt sz, OPCODE ecls) } } -static UInt -recover_from_failed_susp_on_cls(struct intermediates *cint, UInt sz) -{ +static UInt recover_from_failed_susp_on_cls(struct intermediates *cint, + UInt sz) { /* we have to recover all allocated blocks, just follow the code through. */ struct PSEUDO *cpc = cint->CodeStart; @@ -701,21 +721,21 @@ recover_from_failed_susp_on_cls(struct intermediates *cint, UInt sz) pred_flags_t log_upd_pred = cint->CurrentPred->PredFlags & LogUpdatePredFlag; while (cpc) { - switch(cpc->op) { + switch (cpc->op) { case enter_lu_op: if (cpc->rnd4) { - yamop *code_p = (yamop *)cpc->rnd4; - yamop *first = code_p->y_u.Illss.l1; - yamop *last = code_p->y_u.Illss.l2; - while (first) { - yamop *next = first->y_u.OtaLl.n; - LogUpdClause *cl = first->y_u.OtaLl.d; - cl->ClRefCount--; - Yap_FreeCodeSpace((char *)first); - if (first == last) - break; - first = next; - } + yamop *code_p = (yamop *)cpc->rnd4; + yamop *first = code_p->y_u.Illss.l1; + yamop *last = code_p->y_u.Illss.l2; + while (first) { + yamop *next = first->y_u.OtaLl.n; + LogUpdClause *cl = first->y_u.OtaLl.d; + cl->ClRefCount--; + Yap_FreeCodeSpace((char *)first); + if (first == last) + break; + first = next; + } } cpc->rnd4 = Zero; break; @@ -723,59 +743,55 @@ recover_from_failed_susp_on_cls(struct intermediates *cint, UInt sz) case jump_nv_op: sz = cleanup_sw_on_clauses(cpc->rnd1, sz, ecls); break; - case switch_on_type_op: - { - TypeSwitch *type_sw = (TypeSwitch *)(cpc->arnds); - sz = cleanup_sw_on_clauses(type_sw->PairEntry, sz, ecls); - sz = cleanup_sw_on_clauses(type_sw->ConstEntry, sz, ecls); - sz = cleanup_sw_on_clauses(type_sw->FuncEntry, sz, ecls); - sz = cleanup_sw_on_clauses(type_sw->VarEntry, sz, ecls); - } - break; + case switch_on_type_op: { + TypeSwitch *type_sw = (TypeSwitch *)(cpc->arnds); + sz = cleanup_sw_on_clauses(type_sw->PairEntry, sz, ecls); + sz = cleanup_sw_on_clauses(type_sw->ConstEntry, sz, ecls); + sz = cleanup_sw_on_clauses(type_sw->FuncEntry, sz, ecls); + sz = cleanup_sw_on_clauses(type_sw->VarEntry, sz, ecls); + } break; case switch_c_op: - case if_c_op: - { - AtomSwiEntry *target = (AtomSwiEntry *)(cpc->rnd2); - int cases = cpc->rnd1, i; + case if_c_op: { + AtomSwiEntry *target = (AtomSwiEntry *)(cpc->rnd2); + int cases = cpc->rnd1, i; - for (i = 0; i < cases; i++) { - sz = cleanup_sw_on_clauses(target[i].u_a.Label, sz, ecls); - } - if (log_upd_pred) { - LogUpdIndex *lcl = ClauseCodeToLogUpdIndex(cpc->rnd2); - sz += sizeof(LogUpdIndex)+cases*sizeof(AtomSwiEntry); - Yap_LUIndexSpace_SW -= sizeof(LogUpdIndex)+cases*sizeof(AtomSwiEntry); - Yap_FreeCodeSpace((char *)lcl); - } else { - StaticIndex *scl = ClauseCodeToStaticIndex(cpc->rnd2); - sz += sizeof(StaticIndex)+cases*sizeof(AtomSwiEntry); - Yap_IndexSpace_SW -= sizeof(StaticIndex)+cases*sizeof(AtomSwiEntry); - Yap_FreeCodeSpace((char *)scl); - } + for (i = 0; i < cases; i++) { + sz = cleanup_sw_on_clauses(target[i].u_a.Label, sz, ecls); } - break; + if (log_upd_pred) { + LogUpdIndex *lcl = ClauseCodeToLogUpdIndex(cpc->rnd2); + sz += sizeof(LogUpdIndex) + cases * sizeof(AtomSwiEntry); + Yap_LUIndexSpace_SW -= + sizeof(LogUpdIndex) + cases * sizeof(AtomSwiEntry); + Yap_FreeCodeSpace((char *)lcl); + } else { + StaticIndex *scl = ClauseCodeToStaticIndex(cpc->rnd2); + sz += sizeof(StaticIndex) + cases * sizeof(AtomSwiEntry); + Yap_IndexSpace_SW -= sizeof(StaticIndex) + cases * sizeof(AtomSwiEntry); + Yap_FreeCodeSpace((char *)scl); + } + } break; case switch_f_op: - case if_f_op: - { - FuncSwiEntry *target = (FuncSwiEntry *)(cpc->rnd2); - int cases = cpc->rnd1, i; - - for (i = 0; i < cases; i++) { - sz = cleanup_sw_on_clauses(target[i].u_f.Label, sz, ecls); - } - if (log_upd_pred) { - LogUpdIndex *lcl = ClauseCodeToLogUpdIndex(cpc->rnd2); - sz += sizeof(LogUpdIndex)+cases*sizeof(FuncSwiEntry); - Yap_LUIndexSpace_SW -= sizeof(LogUpdIndex)+cases*sizeof(FuncSwiEntry); - Yap_FreeCodeSpace((char *)lcl); - } else { - StaticIndex *scl = ClauseCodeToStaticIndex(cpc->rnd2); - Yap_IndexSpace_SW -= sizeof(StaticIndex)+cases*sizeof(FuncSwiEntry); - sz += sizeof(StaticIndex)+cases*sizeof(FuncSwiEntry); - Yap_FreeCodeSpace((char *)scl); - } + case if_f_op: { + FuncSwiEntry *target = (FuncSwiEntry *)(cpc->rnd2); + int cases = cpc->rnd1, i; + + for (i = 0; i < cases; i++) { + sz = cleanup_sw_on_clauses(target[i].u_f.Label, sz, ecls); } - break; + if (log_upd_pred) { + LogUpdIndex *lcl = ClauseCodeToLogUpdIndex(cpc->rnd2); + sz += sizeof(LogUpdIndex) + cases * sizeof(FuncSwiEntry); + Yap_LUIndexSpace_SW -= + sizeof(LogUpdIndex) + cases * sizeof(FuncSwiEntry); + Yap_FreeCodeSpace((char *)lcl); + } else { + StaticIndex *scl = ClauseCodeToStaticIndex(cpc->rnd2); + Yap_IndexSpace_SW -= sizeof(StaticIndex) + cases * sizeof(FuncSwiEntry); + sz += sizeof(StaticIndex) + cases * sizeof(FuncSwiEntry); + Yap_FreeCodeSpace((char *)scl); + } + } break; default: break; } @@ -789,10 +805,7 @@ recover_from_failed_susp_on_cls(struct intermediates *cint, UInt sz) return sz; } - -static inline int -smaller(Term t1, Term t2) -{ +static inline int smaller(Term t1, Term t2) { CELL tg1 = LowTagOf(t1), tg2 = LowTagOf(t2); if (tg1 == tg2) { return t1 < t2; @@ -800,9 +813,7 @@ smaller(Term t1, Term t2) return tg1 < tg2; } -static inline int -smaller_or_eq(Term t1, Term t2) -{ +static inline int smaller_or_eq(Term t1, Term t2) { CELL tg1 = LowTagOf(t1), tg2 = LowTagOf(t2); if (tg1 == tg2) { return t1 <= t2; @@ -810,15 +821,11 @@ smaller_or_eq(Term t1, Term t2) return tg1 < tg2; } -static inline void -clcpy(ClauseDef *d, ClauseDef *s) -{ +static inline void clcpy(ClauseDef *d, ClauseDef *s) { memcpy((void *)d, (void *)s, sizeof(ClauseDef)); } -static void -insort(ClauseDef base[], CELL *p, CELL *q, int my_p) -{ +static void insort(ClauseDef base[], CELL *p, CELL *q, int my_p) { CELL *j; if (my_p) { @@ -829,39 +836,36 @@ insort(ClauseDef base[], CELL *p, CELL *q, int my_p) CELL *i; key = base[off].Tag; - i = j+1; - + i = j + 1; + /* we are at offset 1 */ - while (i > p+1 && smaller(key,base[i[-2]].Tag)) { - i[0] = i[-2]; - i -= 2; + while (i > p + 1 && smaller(key, base[i[-2]].Tag)) { + i[0] = i[-2]; + i -= 2; } i[0] = off; } } else { - for (j = p+2; j < q; j += 2) { + for (j = p + 2; j < q; j += 2) { Term key; Int off = *j; CELL *i; key = base[off].Tag; i = j; - + /* we are at offset 1 */ - while (i > p && smaller(key,base[i[-2]].Tag)) { - i[0] = i[-2]; - i -= 2; + while (i > p && smaller(key, base[i[-2]].Tag)) { + i[0] = i[-2]; + i -= 2; } i[0] = off; } } } - /* copy to a new list of terms */ -static -void msort(ClauseDef *base, CELL *pt, Int size, int my_p) -{ +static void msort(ClauseDef *base, CELL *pt, Int size, int my_p) { if (size > 2) { Int half_size = size / 2; @@ -869,22 +873,22 @@ void msort(ClauseDef *base, CELL *pt, Int size, int my_p) int left_p, right_p; if (size < 50) { - insort(base, pt, pt+2*size, my_p); - return; + insort(base, pt, pt + 2 * size, my_p); + return; } - pt_right = pt + half_size*2; - left_p = my_p^1; + pt_right = pt + half_size * 2; + left_p = my_p ^ 1; right_p = my_p; msort(base, pt, half_size, left_p); - msort(base, pt_right, size-half_size, right_p); + msort(base, pt_right, size - half_size, right_p); /* now implement a simple merge routine */ - + /* pointer to after the end of the list */ - end_pt = pt + 2*size; + end_pt = pt + 2 * size; /* pointer to the element after the last element to the left */ - end_pt_left = pt+half_size*2; + end_pt_left = pt + half_size * 2; /* where is left list */ - pt_left = pt+left_p; + pt_left = pt + left_p; /* where is right list */ pt_right += right_p; /* where is new list */ @@ -893,16 +897,16 @@ void msort(ClauseDef *base, CELL *pt, Int size, int my_p) while (pt_left < end_pt_left && pt_right < end_pt) { /* if the element to the left is larger than the one to the right */ if (smaller_or_eq(base[pt_left[0]].Tag, base[pt_right[0]].Tag)) { - /* copy the one to the left */ - pt[0] = pt_left[0]; - /* and avance the two pointers */ - pt += 2; - pt_left += 2; + /* copy the one to the left */ + pt[0] = pt_left[0]; + /* and avance the two pointers */ + pt += 2; + pt_left += 2; } else { - /* otherwise, copy the one to the right */ - pt[0] = pt_right[0]; - pt += 2; - pt_right += 2; + /* otherwise, copy the one to the right */ + pt[0] = pt_right[0]; + pt += 2; + pt_right += 2; } } /* if any elements were left in the left vector just copy them */ @@ -914,31 +918,30 @@ void msort(ClauseDef *base, CELL *pt, Int size, int my_p) /* if any elements were left in the right vector and they are in the wrong place, just copy them */ if (my_p != right_p) { - while(pt_right < end_pt) { - pt[0] = pt_right[0]; - pt += 2; - pt_right += 2; + while (pt_right < end_pt) { + pt[0] = pt_right[0]; + pt += 2; + pt_right += 2; } } } else { - if (size > 1 && smaller(base[pt[2]].Tag,base[pt[0]].Tag)) { + if (size > 1 && smaller(base[pt[2]].Tag, base[pt[0]].Tag)) { CELL t = pt[2]; - pt[2+my_p] = pt[0]; + pt[2 + my_p] = pt[0]; pt[my_p] = t; } else if (my_p) { pt[1] = pt[0]; if (size > 1) - pt[3] = pt[2]; + pt[3] = pt[2]; } } } -static void -copy_back(ClauseDef *dest, CELL *pt, int max) { +static void copy_back(ClauseDef *dest, CELL *pt, int max) { /* first need to say that we had no need to make a copy */ int i; CELL *tmp = pt; - for (i=0; i < max; i++) { + for (i = 0; i < max; i++) { if (*tmp != i) { ClauseDef cl; int j = i; @@ -946,21 +949,21 @@ copy_back(ClauseDef *dest, CELL *pt, int max) { /* found a chain */ /* make a backup copy */ - clcpy(&cl, dest+i); + clcpy(&cl, dest + i); do { - /* follow the chain */ - int k = *pnt; + /* follow the chain */ + int k = *pnt; - *pnt = j; - /* printf("i=%d, k = %d, j = %d\n",i,j,k); */ - if (k == i) { - clcpy(dest+j, &cl); - break; - } else { - clcpy(dest+j, dest+k); - } - pnt = pt+2*k; - j = k; + *pnt = j; + /* printf("i=%d, k = %d, j = %d\n",i,j,k); */ + if (k == i) { + clcpy(dest + j, &cl); + break; + } else { + clcpy(dest + j, dest + k); + } + pnt = pt + 2 * k; + j = k; } while (TRUE); } /* we don't need to do swap */ @@ -969,37 +972,35 @@ copy_back(ClauseDef *dest, CELL *pt, int max) { } /* sort a group of clauses by using their tags */ -static void -sort_group(GroupDef *grp, CELL *top, struct intermediates *cint) -{ - int max = (grp->LastClause-grp->FirstClause)+1, i; +static void sort_group(GroupDef *grp, CELL *top, struct intermediates *cint) { + int max = (grp->LastClause - grp->FirstClause) + 1, i; CELL *pt, *base; #if USE_SYSTEM_MALLOC - if (!(base = (CELL *)Yap_AllocCodeSpace(2*max*sizeof(CELL)))) { + if (!(base = (CELL *)Yap_AllocCodeSpace(2 * max * sizeof(CELL)))) { CACHE_REGS save_machine_regs(); - LOCAL_Error_Size = 2*max*sizeof(CELL); - siglongjmp(cint->CompilerBotch,2); + LOCAL_Error_Size = 2 * max * sizeof(CELL); + siglongjmp(cint->CompilerBotch, 2); } #else base = top; - while (top+2*max > (CELL *)LOCAL_TrailTop) { - if (!Yap_growtrail(2*max*CellSize, TRUE)) { - LOCAL_Error_Size = 2*max*CellSize; + while (top + 2 * max > (CELL *)LOCAL_TrailTop) { + if (!Yap_growtrail(2 * max * CellSize, TRUE)) { + LOCAL_Error_Size = 2 * max * CellSize; save_machine_regs(); - siglongjmp(cint->CompilerBotch,4); + siglongjmp(cint->CompilerBotch, 4); return; } } #endif pt = base; /* initialize vector */ - for (i=0; i < max; i++) { + for (i = 0; i < max; i++) { *pt = i; pt += 2; } -#define M_EVEN 0 +#define M_EVEN 0 msort(grp->FirstClause, base, max, M_EVEN); copy_back(grp->FirstClause, base, max); #if USE_SYSTEM_MALLOC @@ -1008,17 +1009,14 @@ sort_group(GroupDef *grp, CELL *top, struct intermediates *cint) } /* add copy to register stack for original reg */ -static int -init_regcopy(wamreg regs[MAX_REG_COPIES], wamreg copy) -{ +static int init_regcopy(wamreg regs[MAX_REG_COPIES], wamreg copy) { regs[0] = copy; return 1; } /* add copy to register stack for original reg */ -static int -is_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, wamreg copy) -{ +static int is_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, + wamreg copy) { int i = 0; while (i < regs_count) { if (regs[i] == copy) { @@ -1031,15 +1029,14 @@ is_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, wamreg copy) } /* add copy to register stack for original reg */ -static int -delete_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, wamreg copy) -{ +static int delete_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, + wamreg copy) { int i = 0; while (i < regs_count) { if (regs[i] == copy) { /* we found it */ - regs[i] = regs[regs_count-1]; - return regs_count-1; + regs[i] = regs[regs_count - 1]; + return regs_count - 1; } i++; } @@ -1048,18 +1045,17 @@ delete_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, wamreg copy) } /* add copy to register stack for original reg */ -static int -add_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, Int source, Int copy) -{ +static int add_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, Int source, + Int copy) { int i = 0; while (i < regs_count) { if (regs[i] == source) { /* we found it, add new element as last element */ if (regs_count == MAX_REG_COPIES) { - return regs_count; + return regs_count; } regs[regs_count] = copy; - return regs_count+1; + return regs_count + 1; } i++; } @@ -1067,14 +1063,11 @@ add_regcopy(wamreg regs[MAX_REG_COPIES], int regs_count, Int source, Int copy) return delete_regcopy(regs, regs_count, copy); } - - /* add copy to register stack for original reg */ -inline static int -link_regcopies(wamreg regs[MAX_REG_COPIES], int regs_count, Int c1, Int c2) -{ +inline static int link_regcopies(wamreg regs[MAX_REG_COPIES], int regs_count, + Int c1, Int c2) { int i; - for (i=0; iCurrentCode; #include "findclause.h" } -static void -add_head_info(ClauseDef *clause, UInt regno) -{ +static void add_head_info(ClauseDef *clause, UInt regno) { wamreg iarg = Yap_regnotoreg(regno); yamop *cl = clause->CurrentCode; #include "headclause.h" } -static void -move_next(ClauseDef *clause, UInt regno) -{ +static void move_next(ClauseDef *clause, UInt regno) { yamop *cl = clause->CurrentCode; wamreg wreg = Yap_regnotoreg(regno); op_numbers op = Yap_op_from_opcode(cl->opc); @@ -1122,19 +1109,19 @@ move_next(ClauseDef *clause, UInt regno) #endif #if THREADS case _unlock_lu: - clause->CurrentCode = NEXTOP(cl,e); + clause->CurrentCode = NEXTOP(cl, e); return; #endif case _p_db_ref_x: case _p_float_x: if (wreg == cl->y_u.xl.x) { - clause->CurrentCode = NEXTOP(cl,xl); - } + clause->CurrentCode = NEXTOP(cl, xl); + } return; case _get_list: if (wreg == cl->y_u.x.x) { - clause->CurrentCode = NEXTOP(cl,x); - } + clause->CurrentCode = NEXTOP(cl, x); + } return; case _glist_valx: case _gl_void_vary: @@ -1145,8 +1132,8 @@ move_next(ClauseDef *clause, UInt regno) return; case _get_atom: if (wreg == cl->y_u.xc.x) { - clause->CurrentCode = NEXTOP(cl,xc); - } + clause->CurrentCode = NEXTOP(cl, xc); + } return; case _get_2atoms: return; @@ -1158,25 +1145,23 @@ move_next(ClauseDef *clause, UInt regno) return; case _get_6atoms: return; - /* - matching is not guaranteed: - case _get_float: - case _get_longint: - case _get_bigint: - */ + /* + matching is not guaranteed: +case _get_float: +case _get_longint: +case _get_bigint: + */ case _get_struct: if (wreg == cl->y_u.xfa.x) { - clause->CurrentCode = NEXTOP(cl,xfa); - } + clause->CurrentCode = NEXTOP(cl, xfa); + } default: clause->CurrentCode = clause->Code; return; } } -static void -add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) -{ +static void add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) { yamop *cl; if (ap->ModuleOfPred == IDB_MODULE) { cl = clause->Code; @@ -1188,11 +1173,11 @@ add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) switch (op) { case _glist_valx: if (argno == 1) { - clause->Tag = (CELL)NULL; - return; + clause->Tag = (CELL)NULL; + return; } argno--; - cl = NEXTOP(cl,xx); + cl = NEXTOP(cl, xx); break; case _gl_void_vary: case _gl_void_valy: @@ -1202,11 +1187,11 @@ add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) return; case _glist_valy: if (argno == 1) { - clause->Tag = (CELL)NULL; - return; + clause->Tag = (CELL)NULL; + return; } argno = 2; - cl = NEXTOP(cl,yx); + cl = NEXTOP(cl, yx); break; case _unify_l_x_var: case _unify_l_x_val: @@ -1215,8 +1200,8 @@ add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) case _unify_x_val: case _unify_x_loc: if (argno == 1) { - clause->Tag = (CELL)NULL; - return; + clause->Tag = (CELL)NULL; + return; } argno--; case _unify_l_x_var_write: @@ -1225,24 +1210,24 @@ add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) case _unify_x_var_write: case _unify_x_val_write: case _unify_x_loc_write: - cl = NEXTOP(cl,ox); + cl = NEXTOP(cl, ox); break; case _save_pair_x_write: case _save_pair_x: case _save_appl_x_write: case _save_appl_x: - cl = NEXTOP(cl,ox); + cl = NEXTOP(cl, ox); break; case _unify_l_x_var2: case _unify_x_var2: if (argno == 1 || argno == 2) { - clause->Tag = (CELL)NULL; - return; + clause->Tag = (CELL)NULL; + return; } argno -= 2; case _unify_l_x_var2_write: case _unify_x_var2_write: - cl = NEXTOP(cl,oxx); + cl = NEXTOP(cl, oxx); break; case _unify_y_var: case _unify_y_val: @@ -1251,11 +1236,11 @@ add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) case _unify_l_y_val: case _unify_l_y_loc: /* we're just done with the head of a list, but there - is nothing inside. + is nothing inside. */ if (argno == 1) { - clause->Tag = (CELL)NULL; - return; + clause->Tag = (CELL)NULL; + return; } argno--; case _unify_y_var_write: @@ -1264,173 +1249,172 @@ add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) case _unify_l_y_var_write: case _unify_l_y_val_write: case _unify_l_y_loc_write: - cl = NEXTOP(cl,oy); + cl = NEXTOP(cl, oy); break; case _save_pair_y_write: case _save_pair_y: case _save_appl_y_write: case _save_appl_y: - cl = NEXTOP(cl,oy); + cl = NEXTOP(cl, oy); break; case _unify_l_void: case _unify_void: if (argno == 1) { - clause->Tag = (CELL)NULL; - return; + clause->Tag = (CELL)NULL; + return; } argno--; case _unify_l_void_write: case _unify_void_write: - cl = NEXTOP(cl,o); + cl = NEXTOP(cl, o); break; case _unify_list: case _unify_l_list: if (argno == 1) { - clause->Tag = AbsPair(NULL); - clause->ucd.WorkPC = NEXTOP(cl,o); - return; + clause->Tag = AbsPair(NULL); + clause->ucd.WorkPC = NEXTOP(cl, o); + return; } argno += 1; /* 2-1: have two extra arguments to skip */ case _unify_list_write: case _unify_l_list_write: - cl = NEXTOP(cl,o); + cl = NEXTOP(cl, o); break; case _unify_n_voids: case _unify_l_n_voids: if (argno <= cl->y_u.os.s) { - clause->Tag = (CELL)NULL; - return; + clause->Tag = (CELL)NULL; + return; } argno -= cl->y_u.os.s; case _unify_n_voids_write: case _unify_l_n_voids_write: - cl = NEXTOP(cl,os); - break; + cl = NEXTOP(cl, os); + break; case _unify_atom: case _unify_l_atom: if (argno == 1) { - clause->Tag = cl->y_u.oc.c; - return; + clause->Tag = cl->y_u.oc.c; + return; } argno--; case _unify_atom_write: case _unify_l_atom_write: - cl = NEXTOP(cl,oc); - break; + cl = NEXTOP(cl, oc); + break; case _unify_float_write: case _unify_l_float_write: - cl = NEXTOP(cl,od); - break; + cl = NEXTOP(cl, od); + break; case _unify_float: case _unify_l_float: if (argno == 1) { - clause->Tag = AbsAppl((CELL *)FunctorDouble); - clause->ucd.t_ptr = AbsAppl(cl->y_u.od.d); - return; + clause->Tag = AbsAppl((CELL *)FunctorDouble); + clause->ucd.t_ptr = AbsAppl(cl->y_u.od.d); + return; } - cl = NEXTOP(cl,od); + cl = NEXTOP(cl, od); argno--; break; case _unify_longint: case _unify_l_longint: if (argno == 1) { - clause->Tag = AbsAppl((CELL *)FunctorLongInt); - clause->ucd.t_ptr = AbsAppl(cl->y_u.oi.i); - return; + clause->Tag = AbsAppl((CELL *)FunctorLongInt); + clause->ucd.t_ptr = AbsAppl(cl->y_u.oi.i); + return; } argno--; - cl = NEXTOP(cl,oi); + cl = NEXTOP(cl, oi); break; case _unify_bigint: case _unify_l_bigint: if (argno == 1) { - clause->Tag = AbsAppl((CELL *)FunctorBigInt); - clause->ucd.t_ptr = cl->y_u.oc.c; - return; + clause->Tag = AbsAppl((CELL *)FunctorBigInt); + clause->ucd.t_ptr = cl->y_u.oc.c; + return; } - cl = NEXTOP(cl,oc); + cl = NEXTOP(cl, oc); argno--; break; case _unify_string: case _unify_l_string: if (argno == 1) { - clause->Tag = AbsAppl((CELL *)FunctorString); - clause->ucd.t_ptr = cl->y_u.ou.ut; - return; + clause->Tag = AbsAppl((CELL *)FunctorString); + clause->ucd.t_ptr = cl->y_u.ou.ut; + return; } - cl = NEXTOP(cl,ou); + cl = NEXTOP(cl, ou); argno--; break; case _unify_n_atoms: if (argno <= cl->y_u.osc.s) { - clause->Tag = cl->y_u.osc.c; - return; + clause->Tag = cl->y_u.osc.c; + return; } argno -= cl->y_u.osc.s; case _unify_n_atoms_write: - cl = NEXTOP(cl,osc); - break; + cl = NEXTOP(cl, osc); + break; case _unify_struct: case _unify_l_struc: if (argno == 1) { - clause->Tag = AbsAppl((CELL *)cl->y_u.ofa.f); - clause->ucd.WorkPC = NEXTOP(cl,ofa); - return; + clause->Tag = AbsAppl((CELL *)cl->y_u.ofa.f); + clause->ucd.WorkPC = NEXTOP(cl, ofa); + return; } /* must skip next n arguments */ - argno += cl->y_u.ofa.a-1; + argno += cl->y_u.ofa.a - 1; case _unify_l_struc_write: case _unify_struct_write: - cl = NEXTOP(cl,ofa); - break; + cl = NEXTOP(cl, ofa); + break; case _pop: - cl = NEXTOP(cl,e); - break; + cl = NEXTOP(cl, e); + break; case _pop_n: - cl = NEXTOP(cl,s); - break; + cl = NEXTOP(cl, s); + break; #ifdef BEAM case _run_eam: - cl = NEXTOP(cl,os); + cl = NEXTOP(cl, os); break; -#endif +#endif #ifdef THREADS case _unlock_lu: - cl = NEXTOP(cl,e); + cl = NEXTOP(cl, e); break; -#endif +#endif case _get_dbterm: - cl = NEXTOP(cl,xc); - break; + cl = NEXTOP(cl, xc); + break; case _unify_dbterm: case _unify_l_dbterm: - cl = NEXTOP(cl,oc); - break; + cl = NEXTOP(cl, oc); + break; case _unify_idb_term: - case _copy_idb_term: - { - Term t = clause->ucd.c_sreg[argno]; + case _copy_idb_term: { + Term t = clause->ucd.c_sreg[argno]; - if (IsVarTerm(t)) { - clause->Tag = (CELL)NULL; - } else if (IsApplTerm(t)) { - CELL *pt = RepAppl(t); + if (IsVarTerm(t)) { + clause->Tag = (CELL)NULL; + } else if (IsApplTerm(t)) { + CELL *pt = RepAppl(t); - clause->Tag = AbsAppl((CELL *)pt[0]); - if (IsExtensionFunctor(FunctorOfTerm(t))) { - clause->ucd.t_ptr = t; - } else { - clause->ucd.c_sreg = pt; - } - } else if (IsPairTerm(t)) { - CELL *pt = RepPair(t); + clause->Tag = AbsAppl((CELL *)pt[0]); + if (IsExtensionFunctor(FunctorOfTerm(t))) { + clause->ucd.t_ptr = t; + } else { + clause->ucd.c_sreg = pt; + } + } else if (IsPairTerm(t)) { + CELL *pt = RepPair(t); - clause->Tag = AbsPair(NULL); - clause->ucd.c_sreg = pt-1; - } else { - clause->Tag = t; - } + clause->Tag = AbsPair(NULL); + clause->ucd.c_sreg = pt - 1; + } else { + clause->Tag = t; } + } return; default: return; @@ -1438,9 +1422,8 @@ add_arg_info(ClauseDef *clause, PredEntry *ap, UInt argno) } } -static void -skip_to_arg(ClauseDef *clause, PredEntry *ap, UInt argno, int at_point) -{ +static void skip_to_arg(ClauseDef *clause, PredEntry *ap, UInt argno, + int at_point) { yamop *cl; int done = FALSE; if (ap->ModuleOfPred == IDB_MODULE) { @@ -1459,153 +1442,149 @@ skip_to_arg(ClauseDef *clause, PredEntry *ap, UInt argno, int at_point) switch (op) { #ifdef BEAM case _run_eam: - clause->CurrentCode = clause->Code; - return; + clause->CurrentCode = clause->Code; + return; #endif case _unify_void: if (argno == 1) { - clause->CurrentCode = clause->Code; - return; + clause->CurrentCode = clause->Code; + return; } else { - argno--; + argno--; } case _unify_void_write: - cl = NEXTOP(cl,o); + cl = NEXTOP(cl, o); break; case _unify_list: case _unify_l_list: case _unify_atom: case _unify_l_atom: - /* - unification is not guaranteed - case _unify_longint: - case _unify_l_longint: - case _unify_bigint: - case _unify_l_bigint: - case _unify_l_float: - */ + /* + unification is not guaranteed + case _unify_longint: + case _unify_l_longint: + case _unify_bigint: + case _unify_l_bigint: + case _unify_l_float: + */ case _unify_struct: case _unify_l_struc: if (cl == clause->ucd.WorkPC) { - clause->CurrentCode = cl; + clause->CurrentCode = cl; } else { - clause->CurrentCode = clause->Code; + clause->CurrentCode = clause->Code; } return; case _unify_list_write: case _unify_l_list_write: - cl = NEXTOP(cl,o); + cl = NEXTOP(cl, o); break; case _unify_n_voids: case _unify_l_n_voids: if (argno <= cl->y_u.os.s) { - clause->CurrentCode = clause->Code; - return; + clause->CurrentCode = clause->Code; + return; } else { - argno -= cl->y_u.os.s; + argno -= cl->y_u.os.s; } case _unify_n_voids_write: case _unify_l_n_voids_write: - cl = NEXTOP(cl,os); - break; + cl = NEXTOP(cl, os); + break; case _unify_atom_write: case _unify_l_atom_write: - cl = NEXTOP(cl,oc); - break; + cl = NEXTOP(cl, oc); + break; case _unify_float_write: case _unify_l_float_write: - cl = NEXTOP(cl,od); - break; + cl = NEXTOP(cl, od); + break; case _unify_l_struc_write: case _unify_struct_write: - cl = NEXTOP(cl,ofa); - break; + cl = NEXTOP(cl, ofa); + break; #ifdef THREADS case _unlock_lu: #endif case _pop: - cl = NEXTOP(cl,e); - break; + cl = NEXTOP(cl, e); + break; case _pop_n: - cl = NEXTOP(cl,s); - break; + cl = NEXTOP(cl, s); + break; default: clause->CurrentCode = clause->Code; - return; + return; } } } - -static UInt -groups_in(ClauseDef *min, ClauseDef *max, GroupDef *grp, struct intermediates *cint) -{ +static UInt groups_in(ClauseDef *min, ClauseDef *max, GroupDef *grp, + struct intermediates *cint) { CACHE_REGS UInt groups = 0; - while(min <= max) { + while (min <= max) { grp->FirstClause = min; grp->AtomClauses = 0; grp->PairClauses = 0; grp->StructClauses = 0; grp->TestClauses = 0; - if (min->Tag == (_var+1)*sizeof(CELL)) { + if (min->Tag == (_var + 1) * sizeof(CELL)) { min++; continue; } /* only do this for the first clauses in a group */ if (IsVarTerm(min->Tag)) { - ClauseDef *clp = min+1; + ClauseDef *clp = min + 1; grp->VarClauses = 1; do { - if (clp > max || - !IsVarTerm(clp->Tag)) { - grp->LastClause = (min = clp)-1; - break; - } - if (clp->Tag != (_var+1)*sizeof(CELL)) - grp->VarClauses++; - clp++; + if (clp > max || !IsVarTerm(clp->Tag)) { + grp->LastClause = (min = clp) - 1; + break; + } + if (clp->Tag != (_var + 1) * sizeof(CELL)) + grp->VarClauses++; + clp++; } while (TRUE); } else { grp->VarClauses = 0; do { restart_loop: - if (IsAtomTerm(min->Tag) || IsIntTerm(min->Tag)) { - grp->AtomClauses++; - } else if (IsPairTerm(min->Tag)) { - grp->PairClauses++; - } else if (IsApplTerm(min->Tag)) { - grp->StructClauses++; - } else { - grp->TestClauses++; - } - min++; - } while (min <= max && - (!IsVarTerm(min->Tag))); - if (min <= max && min->Tag == (_var+1)*sizeof(CELL)) { - min++; - if (min < max) - goto restart_loop; + if (IsAtomTerm(min->Tag) || IsIntTerm(min->Tag)) { + grp->AtomClauses++; + } else if (IsPairTerm(min->Tag)) { + grp->PairClauses++; + } else if (IsApplTerm(min->Tag)) { + grp->StructClauses++; + } else { + grp->TestClauses++; + } + min++; + } while (min <= max && (!IsVarTerm(min->Tag))); + if (min <= max && min->Tag == (_var + 1) * sizeof(CELL)) { + min++; + if (min < max) + goto restart_loop; } - grp->LastClause = min-1; + grp->LastClause = min - 1; } groups++; grp++; - while (grp+16 > (GroupDef *)LOCAL_TrailTop) { - UInt sz = (groups+16)*sizeof(GroupDef); + while (grp + 16 > (GroupDef *)LOCAL_TrailTop) { + UInt sz = (groups + 16) * sizeof(GroupDef); #if USE_SYSTEM_MALLOC LOCAL_Error_Size = sz; /* grow stack */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,4); + siglongjmp(cint->CompilerBotch, 4); #else if (!Yap_growtrail(sz, TRUE)) { - LOCAL_Error_Size = sz; - save_machine_regs(); - siglongjmp(cint->CompilerBotch,4); - return 0; + LOCAL_Error_Size = sz; + save_machine_regs(); + siglongjmp(cint->CompilerBotch, 4); + return 0; } #endif } @@ -1613,38 +1592,34 @@ groups_in(ClauseDef *min, ClauseDef *max, GroupDef *grp, struct intermediates *c return groups; } -static UInt -new_label(struct intermediates *cint) -{ +static UInt new_label(struct intermediates *cint) { UInt lbl = cint->i_labelno; cint->i_labelno += 2; return lbl; } -static Int has_cut(yamop *pc, PredEntry *ap) -{ +static Int has_cut(yamop *pc, PredEntry *ap) { if (ap->PredFlags & LogUpdatePredFlag) { LogUpdClause *lcl = ClauseCodeToLogUpdClause(pc); - return ( (lcl->ClFlags & HasCutMask) != 0); - } else if (ap->PredFlags & MegaClausePredFlag) { + return ((lcl->ClFlags & HasCutMask) != 0); + } else if (ap->PredFlags & MegaClausePredFlag) { /* must be a fact */ return FALSE; } else { StaticClause *scl; scl = ClauseCodeToStaticClause(pc); - return ( (scl->ClFlags & HasCutMask) != 0); + return ((scl->ClFlags & HasCutMask) != 0); } } -static void -emit_trust(ClauseDef *cl, struct intermediates *cint, UInt nxtlbl, int clauses) -{ +static void emit_trust(ClauseDef *cl, struct intermediates *cint, UInt nxtlbl, + int clauses) { PredEntry *ap = cint->CurrentPred; yamop *clcode = cl->Code; if (ap->PredFlags & TabledPredFlag) - clcode = NEXTOP(clcode,Otapl); + clcode = NEXTOP(clcode, Otapl); if (!(ap->PredFlags & LogUpdatePredFlag)) { /* this should not be generated for logical update predicates!! */ if (ap->PredFlags & ProfiledPredFlag) { @@ -1655,21 +1630,20 @@ emit_trust(ClauseDef *cl, struct intermediates *cint, UInt nxtlbl, int clauses) } } if (clauses == 0) { - Yap_emit(trust_op, (CELL)clcode, has_cut(cl->Code, ap) , cint); + Yap_emit(trust_op, (CELL)clcode, has_cut(cl->Code, ap), cint); } else { - Yap_emit(retry_op, (CELL)clcode, (clauses << 1) | has_cut(cl->Code, ap) , cint); + Yap_emit(retry_op, (CELL)clcode, (clauses << 1) | has_cut(cl->Code, ap), + cint); Yap_emit(jumpi_op, nxtlbl, Zero, cint); } } -static void -emit_retry(ClauseDef *cl, struct intermediates *cint, int clauses) -{ +static void emit_retry(ClauseDef *cl, struct intermediates *cint, int clauses) { PredEntry *ap = cint->CurrentPred; yamop *clcode = cl->Code; if (ap->PredFlags & TabledPredFlag) - clcode = NEXTOP(clcode,Otapl); + clcode = NEXTOP(clcode, Otapl); if (!(ap->PredFlags & LogUpdatePredFlag)) { /* this should not be generated for logical update predicates!! */ if (ap->PredFlags & ProfiledPredFlag) { @@ -1679,17 +1653,17 @@ emit_retry(ClauseDef *cl, struct intermediates *cint, int clauses) Yap_emit(count_retry_op, Unsigned(ap), Zero, cint); } } - Yap_emit(retry_op, (CELL)clcode, (clauses << 1) | has_cut(cl->Code, ap), cint); + Yap_emit(retry_op, (CELL)clcode, (clauses << 1) | has_cut(cl->Code, ap), + cint); } -static compiler_vm_op -emit_optry(int var_group, int first, int clauses, int clleft, PredEntry *ap) -{ +static compiler_vm_op emit_optry(int var_group, int first, int clauses, + int clleft, PredEntry *ap) { /* var group */ if (var_group || clauses == 0) { if (first) { return try_op; - } else if (clleft+clauses) { + } else if (clleft + clauses) { return retry_op; } else { return trust_op; @@ -1711,10 +1685,8 @@ emit_optry(int var_group, int first, int clauses, int clleft, PredEntry *ap) } } - -static void -emit_try(ClauseDef *cl, struct intermediates *cint, int var_group, int first, int clauses, int clleft, UInt nxtlbl) -{ +static void emit_try(ClauseDef *cl, struct intermediates *cint, int var_group, + int first, int clauses, int clleft, UInt nxtlbl) { PredEntry *ap = cint->CurrentPred; yamop *clcode; compiler_vm_op comp_op; @@ -1722,77 +1694,78 @@ emit_try(ClauseDef *cl, struct intermediates *cint, int var_group, int first, in if (ap->PredFlags & LogUpdatePredFlag) { clcode = cl->Code; } else if (ap->PredFlags & TabledPredFlag) { - clcode = NEXTOP(cl->Code,Otapl); + clcode = NEXTOP(cl->Code, Otapl); } else { clcode = cl->CurrentCode; } comp_op = emit_optry(var_group, first, clauses, clleft, cint->CurrentPred); - Yap_emit(comp_op, (CELL)clcode, ((clauses+clleft) << 1) | has_cut(cl->Code, ap), cint); + Yap_emit(comp_op, (CELL)clcode, + ((clauses + clleft) << 1) | has_cut(cl->Code, ap), cint); } -static TypeSwitch * -emit_type_switch(compiler_vm_op op, struct intermediates *cint) -{ - return (TypeSwitch *)Yap_emit_extra_size(op, 0, sizeof(TypeSwitch), cint); +static TypeSwitch *emit_type_switch(compiler_vm_op op, + struct intermediates *cint) { + return (TypeSwitch *)Yap_emit_extra_size(op, 0, sizeof(TypeSwitch), cint); } - -static yamop * -emit_switch_space(UInt n, UInt item_size, struct intermediates *cint, CELL func_mask) -{ +static yamop *emit_switch_space(UInt n, UInt item_size, + struct intermediates *cint, CELL func_mask) { CACHE_REGS PredEntry *ap = cint->CurrentPred; if (ap->PredFlags & LogUpdatePredFlag) { - UInt sz = sizeof(LogUpdIndex)+n*item_size; + UInt sz = sizeof(LogUpdIndex) + n * item_size; LogUpdIndex *cl = (LogUpdIndex *)Yap_AllocCodeSpace(sz); if (cl == NULL) { LOCAL_Error_Size = sz; /* grow stack */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,2); + siglongjmp(cint->CompilerBotch, 2); } Yap_LUIndexSpace_SW += sz; - cl->ClFlags = SwitchTableMask|LogUpdMask|func_mask; + cl->ClFlags = SwitchTableMask | LogUpdMask | func_mask; cl->ClSize = sz; cl->ClPred = cint->CurrentPred; /* insert into code chain */ - Yap_inform_profiler_of_clause(cl, (CODEADDR)cl+sz, ap, GPROF_NEW_LU_SWITCH); + Yap_inform_profiler_of_clause(cl, (CODEADDR)cl + sz, ap, + GPROF_NEW_LU_SWITCH); return cl->ClCode; } else { - UInt sz = sizeof(StaticIndex)+n*item_size; + UInt sz = sizeof(StaticIndex) + n * item_size; StaticIndex *cl = (StaticIndex *)Yap_AllocCodeSpace(sz); if (cl == NULL) { LOCAL_Error_Size = sz; /* grow stack */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,2); + siglongjmp(cint->CompilerBotch, 2); } Yap_IndexSpace_SW += sz; cl->ClFlags = SwitchTableMask; cl->ClSize = sz; cl->ClPred = cint->CurrentPred; - Yap_inform_profiler_of_clause(cl, (CODEADDR)cl+sz, ap, GPROF_NEW_STATIC_SWITCH); + Yap_inform_profiler_of_clause(cl, (CODEADDR)cl + sz, ap, + GPROF_NEW_STATIC_SWITCH); return cl->ClCode; /* insert into code chain */ - } + } } -static AtomSwiEntry * -emit_cswitch(COUNT n, yamop *fail_l, struct intermediates *cint) -{ +static AtomSwiEntry *emit_cswitch(COUNT n, yamop *fail_l, + struct intermediates *cint) { compiler_vm_op op; AtomSwiEntry *target; if (n > MIN_HASH_ENTRIES) { COUNT cases = MIN_HASH_ENTRIES, i; - n += 1+n/4; - while (cases < n) cases *= 2; + n += 1 + n / 4; + while (cases < n) + cases *= 2; n = cases; op = switch_c_op; - target = (AtomSwiEntry *)emit_switch_space(n, sizeof(AtomSwiEntry), cint, 0); - for (i=0; i> HASH_SHIFT) & (entries-1); + hash = (t >> HASH_SHIFT) & (entries - 1); centry = cebase + hash; - d = (entries-1) & (t|1); + d = (entries - 1) & (t | 1); while (centry->Tag != t) { if (centry->Tag == 0L) return centry; - hash = (hash + d) & (entries-1); + hash = (hash + d) & (entries - 1); centry = cebase + hash; } return centry; } -static AtomSwiEntry * -fetch_centry(AtomSwiEntry *cebase, Term wt, int i, int n) -{ +static AtomSwiEntry *fetch_centry(AtomSwiEntry *cebase, Term wt, int i, int n) { if (n > MIN_HASH_ENTRIES) { int cases = MIN_HASH_ENTRIES; - n += 1+n/4; - while (cases < n) cases *= 2; + n += 1 + n / 4; + while (cases < n) + cases *= 2; return lookup_c_hash(wt, (yamop *)cebase, cases); } else { return cebase + i; } } -static FuncSwiEntry * -emit_fswitch(COUNT n, yamop *fail_l, struct intermediates *cint) -{ +static FuncSwiEntry *emit_fswitch(COUNT n, yamop *fail_l, + struct intermediates *cint) { compiler_vm_op op; FuncSwiEntry *target; if (n > MIN_HASH_ENTRIES) { int cases = MIN_HASH_ENTRIES, i; - n += 1+n/4; - while (cases < n) cases *= 2; + n += 1 + n / 4; + while (cases < n) + cases *= 2; n = cases; op = switch_f_op; - target = (FuncSwiEntry *)emit_switch_space(n, sizeof(FuncSwiEntry), cint, FuncSwitchMask); - for (i=0; i> HASH_SHIFT) & (entries-1); + hash = (wt >> HASH_SHIFT) & (entries - 1); fentry = febase + hash; - d = (entries-1) & (wt|1); + d = (entries - 1) & (wt | 1); while (fentry->Tag != f) { if (fentry->Tag == NULL) return fentry; - hash = (hash + d) & (entries-1); + hash = (hash + d) & (entries - 1); fentry = febase + hash; } return fentry; } -static FuncSwiEntry * -fetch_fentry(FuncSwiEntry *febase, Functor ft, int i, int n) -{ +static FuncSwiEntry *fetch_fentry(FuncSwiEntry *febase, Functor ft, int i, + int n) { if (n > MIN_HASH_ENTRIES) { int cases = MIN_HASH_ENTRIES; - n += 1+n/4; - while (cases < n) cases *= 2; + n += 1 + n / 4; + while (cases < n) + cases *= 2; return lookup_f_hash(ft, (yamop *)febase, cases); } else { return febase + i; @@ -1914,8 +1885,9 @@ fetch_fentry(FuncSwiEntry *febase, Functor ft, int i, int n) } /* we assume there is at least one clause, that is, c0 < cf */ -static UInt -do_var_clauses(ClauseDef *c0, ClauseDef *cf, int var_group, struct intermediates *cint, int first, int clleft, UInt nxtlbl, UInt argno0) { +static UInt do_var_clauses(ClauseDef *c0, ClauseDef *cf, int var_group, + struct intermediates *cint, int first, int clleft, + UInt nxtlbl, UInt argno0) { UInt labl; UInt labl_dyn0 = 0, labl_dynf = 0; @@ -1923,10 +1895,9 @@ do_var_clauses(ClauseDef *c0, ClauseDef *cf, int var_group, struct intermediates Yap_emit(label_op, labl, Zero, cint); /* add expand_node if var_group == TRUE (jump on var) || - var_group == FALSE (leaf node) + var_group == FALSE (leaf node) */ - if (first && - cint->CurrentPred->PredFlags & LogUpdatePredFlag) { + if (first && cint->CurrentPred->PredFlags & LogUpdatePredFlag) { UInt ncls; labl_dyn0 = new_label(cint); if (clleft) @@ -1934,49 +1905,47 @@ do_var_clauses(ClauseDef *c0, ClauseDef *cf, int var_group, struct intermediates else labl_dynf = new_label(cint); if (clleft == 0) /* trust*/ - ncls = (cf-c0)+1; + ncls = (cf - c0) + 1; else ncls = 0; Yap_emit_4ops(enter_lu_op, labl_dyn0, labl_dynf, ncls, Zero, cint); - Yap_emit(label_op, labl_dyn0, Zero, cint); + Yap_emit(label_op, labl_dyn0, Zero, cint); } if (c0 == cf) { emit_try(c0, cint, var_group, first, 0, clleft, nxtlbl); } else { if (c0 < cf) { - emit_try(c0, cint, var_group, first, cf-c0, clleft, nxtlbl); + emit_try(c0, cint, var_group, first, cf - c0, clleft, nxtlbl); } c0++; while (c0 < cf) { - emit_retry(c0, cint, clleft+(cf-c0)); + emit_retry(c0, cint, clleft + (cf - c0)); c0++; } if (c0 == cf) { emit_trust(c0, cint, nxtlbl, clleft); - if (!clleft && - cint->CurrentPred->PredFlags & LogUpdatePredFlag) { - Yap_emit(label_op, labl_dynf, Zero, cint); + if (!clleft && cint->CurrentPred->PredFlags & LogUpdatePredFlag) { + Yap_emit(label_op, labl_dynf, Zero, cint); } } } return labl; } -static UInt -do_var_group(GroupDef *grp, struct intermediates *cint, int var_group, int first, int clleft, UInt nxtlbl, UInt argno0) { - return do_var_clauses(grp->FirstClause, grp->LastClause, var_group, cint, first, clleft, nxtlbl, argno0); +static UInt do_var_group(GroupDef *grp, struct intermediates *cint, + int var_group, int first, int clleft, UInt nxtlbl, + UInt argno0) { + return do_var_clauses(grp->FirstClause, grp->LastClause, var_group, cint, + first, clleft, nxtlbl, argno0); } - /* count the number of different constants */ -static UInt -count_consts(GroupDef *grp) -{ +static UInt count_consts(GroupDef *grp) { Term current = MkAtomTerm(AtomFoundVar); UInt i = 0; ClauseDef *cl = grp->FirstClause; - + while (IsAtomTerm(cl->Tag) || IsIntTerm(cl->Tag)) { if (current != cl->Tag) { i++; @@ -1990,13 +1959,11 @@ count_consts(GroupDef *grp) return i; } -static UInt -count_blobs(GroupDef *grp) -{ +static UInt count_blobs(GroupDef *grp) { UInt i = 1; - ClauseDef *cl = grp->FirstClause+1; + ClauseDef *cl = grp->FirstClause + 1; Term current = grp->FirstClause->Tag; - + while (cl <= grp->LastClause) { if (current != cl->Tag) { i++; @@ -2008,13 +1975,11 @@ count_blobs(GroupDef *grp) } /* count the number of different constants */ -static UInt -count_funcs(GroupDef *grp) -{ +static UInt count_funcs(GroupDef *grp) { Term current = MkAtomTerm(AtomFoundVar); UInt i = 0; ClauseDef *cl = grp->FirstClause; - + while (IsApplTerm(cl->Tag)) { if (current != cl->Tag) { i++; @@ -2028,21 +1993,20 @@ count_funcs(GroupDef *grp) return i; } -static UInt -emit_single_switch_case(ClauseDef *min, struct intermediates *cint, int first, int clleft, UInt nxtlbl) -{ +static UInt emit_single_switch_case(ClauseDef *min, struct intermediates *cint, + int first, int clleft, UInt nxtlbl) { if (cint->CurrentPred->PredFlags & TabledPredFlag) { /* with tabling we don't clean trust at the very end of computation. */ if (clleft || !first) { /* - if we still have clauses left, means we already created a CP, - so I should avoid creating again + if we still have clauses left, means we already created a CP, + so I should avoid creating again */ - return (UInt)NEXTOP(min->Code,Otapl); + return (UInt)NEXTOP(min->Code, Otapl); } else { return (UInt)min->Code; - } + } } if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) { return (UInt)(min->Code); @@ -2051,19 +2015,18 @@ emit_single_switch_case(ClauseDef *min, struct intermediates *cint, int first, i } } -static UInt -suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap, struct intermediates *cint) -{ +static UInt suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap, + struct intermediates *cint) { UInt tcls = ap->cs.p_code.NOfClauses; - UInt cls = (max-min)+1; + UInt cls = (max - min) + 1; if (cint->expand_block && cint->expand_block != (yamop *)(&(ap->cs.p_code.ExpandCode)) && - cint->expand_block->y_u.sssllp.s2 < 2*(max-min)) { + cint->expand_block->y_u.sssllp.s2 < 2 * (max - min)) { cint->expand_block->y_u.sssllp.s3++; return (UInt)(cint->expand_block); } - if (cls < tcls/8) { + if (cls < tcls / 8) { yamop *ncode; yamop **st; UInt tels; @@ -2075,7 +2038,7 @@ suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap, struct intermedi } else { tels = cls; } - sz = (UInt)NEXTOP((yamop *)NULL,sssllp)+tels*sizeof(yamop *); + sz = (UInt)NEXTOP((yamop *)NULL, sssllp) + tels * sizeof(yamop *); if ((ncode = (yamop *)Yap_AllocCodeSpace(sz)) == NULL) { save_machine_regs(); siglongjmp(cint->CompilerBotch, 2); @@ -2089,14 +2052,15 @@ suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap, struct intermedi } else { Yap_IndexSpace_EXT += sz; } - Yap_inform_profiler_of_clause(ncode, (CODEADDR)ncode+sz, ap, GPROF_NEW_EXPAND_BLOCK); + Yap_inform_profiler_of_clause(ncode, (CODEADDR)ncode + sz, ap, + GPROF_NEW_EXPAND_BLOCK); /* create an expand_block */ ncode->opc = Yap_opcode(_expand_clauses); ncode->y_u.sssllp.p = ap; ncode->y_u.sssllp.s1 = tels; ncode->y_u.sssllp.s2 = cls; ncode->y_u.sssllp.s3 = 1; - st = (yamop **)NEXTOP(ncode,sssllp); + st = (yamop **)NEXTOP(ncode, sssllp); while (min <= max) { *st++ = min->Code; min++; @@ -2116,12 +2080,10 @@ suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap, struct intermedi UNLOCK(ExpandClausesListLock); return (UInt)ncode; } - return (UInt)&(ap->cs.p_code.ExpandCode); + return (UInt) & (ap->cs.p_code.ExpandCode); } -static void -recover_ecls_block(yamop *ipc) -{ +static void recover_ecls_block(yamop *ipc) { ipc->y_u.sssllp.s3--; if (!ipc->y_u.sssllp.s3) { LOCK(ExpandClausesListLock); @@ -2139,31 +2101,36 @@ recover_ecls_block(yamop *ipc) UNLOCK(ExpandClausesListLock); #if DEBUG Yap_ExpandClauses--; - Yap_expand_clauses_sz -= (UInt)(NEXTOP((yamop *)NULL,sssllp))+ipc->y_u.sssllp.s1*sizeof(yamop *); + Yap_expand_clauses_sz -= (UInt)(NEXTOP((yamop *)NULL, sssllp)) + + ipc->y_u.sssllp.s1 * sizeof(yamop *); #endif /* no dangling pointers for gprof */ Yap_InformOfRemoval(ipc); if (ipc->y_u.sssllp.p->PredFlags & LogUpdatePredFlag) { - Yap_LUIndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL,sssllp)+ipc->y_u.sssllp.s1*sizeof(yamop *); + Yap_LUIndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL, sssllp) + + ipc->y_u.sssllp.s1 * sizeof(yamop *); } else - Yap_IndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL,sssllp)+ipc->y_u.sssllp.s1*sizeof(yamop *); + Yap_IndexSpace_EXT -= (UInt)NEXTOP((yamop *)NULL, sssllp) + + ipc->y_u.sssllp.s1 * sizeof(yamop *); Yap_FreeCodeSpace((char *)ipc); } } -static UInt -do_var_entries(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first, int clleft, UInt nxtlbl){ +static UInt do_var_entries(GroupDef *grp, Term t, struct intermediates *cint, + UInt argno, int first, int clleft, UInt nxtlbl) { PredEntry *ap = cint->CurrentPred; if (!IsVarTerm(t) || t != 0L) { return suspend_indexing(grp->FirstClause, grp->LastClause, ap, cint); } - return do_var_group(grp, cint, FALSE, first, clleft, nxtlbl, ap->ArityOfPE+1); + return do_var_group(grp, cint, FALSE, first, clleft, nxtlbl, + ap->ArityOfPE + 1); } -static UInt -do_consts(GroupDef *grp, Term t, struct intermediates *cint, int compound_term, CELL *sreg, UInt arity, int last_arg, UInt argno, int first, UInt nxtlbl, int clleft, CELL *top) -{ +static UInt do_consts(GroupDef *grp, Term t, struct intermediates *cint, + int compound_term, CELL *sreg, UInt arity, int last_arg, + UInt argno, int first, UInt nxtlbl, int clleft, + CELL *top) { COUNT n; ClauseDef *min = grp->FirstClause; COUNT i; @@ -2186,31 +2153,35 @@ do_consts(GroupDef *grp, Term t, struct intermediates *cint, int compound_term, ics = fetch_centry(cs, min->Tag, i, n); ics->Tag = min->Tag; - while (max != grp->LastClause && (max+1)->Tag == min->Tag) + while (max != grp->LastClause && (max + 1)->Tag == min->Tag) max++; if (min != max) { if (sreg != NULL) { - if (ap->PredFlags & LogUpdatePredFlag && max > min) { - ics->u_a.Label = suspend_indexing(min, max, ap, cint); - } else { - ics->u_a.Label = do_compound_index(min, max, sreg, cint, compound_term, arity, argno, nxtlbl, first, last_arg, clleft, top, TRUE); - } + if (ap->PredFlags & LogUpdatePredFlag && max > min) { + ics->u_a.Label = suspend_indexing(min, max, ap, cint); + } else { + ics->u_a.Label = do_compound_index( + min, max, sreg, cint, compound_term, arity, argno, nxtlbl, first, + last_arg, clleft, top, TRUE); + } } else if (ap->PredFlags & LogUpdatePredFlag) { - ics->u_a.Label = suspend_indexing(min, max, cint->CurrentPred, cint); + ics->u_a.Label = suspend_indexing(min, max, cint->CurrentPred, cint); } else { - ics->u_a.Label = do_index(min, max, cint, argno+1, nxtlbl, first, clleft, top); + ics->u_a.Label = + do_index(min, max, cint, argno + 1, nxtlbl, first, clleft, top); } } else { - ics->u_a.Label = do_index(min, max, cint, argno+1, nxtlbl, first, clleft, top); + ics->u_a.Label = + do_index(min, max, cint, argno + 1, nxtlbl, first, clleft, top); } - grp->FirstClause = min = max+1; + grp->FirstClause = min = max + 1; } return lbl; } -static void -do_blobs(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first, UInt nxtlbl, int clleft, CELL *top) -{ +static void do_blobs(GroupDef *grp, Term t, struct intermediates *cint, + UInt argno, int first, UInt nxtlbl, int clleft, + CELL *top) { COUNT n; ClauseDef *min = grp->FirstClause; COUNT i; @@ -2226,21 +2197,21 @@ do_blobs(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int firs ics = fetch_centry(cs, min->Tag, i, n); ics->Tag = min->Tag; - while (max != grp->LastClause && - (max+1)->Tag == min->Tag) max++; - if (min != max && - (ap->PredFlags & LogUpdatePredFlag)) { + while (max != grp->LastClause && (max + 1)->Tag == min->Tag) + max++; + if (min != max && (ap->PredFlags & LogUpdatePredFlag)) { ics->u_a.Label = suspend_indexing(min, max, ap, cint); } else { - ics->u_a.Label = do_index(min, max, cint, argno+1, nxtlbl, first, clleft, top); + ics->u_a.Label = + do_index(min, max, cint, argno + 1, nxtlbl, first, clleft, top); } - grp->FirstClause = min = max+1; + grp->FirstClause = min = max + 1; } } -static UInt -do_funcs(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first, int last_arg, UInt nxtlbl, int clleft, CELL *top) -{ +static UInt do_funcs(GroupDef *grp, Term t, struct intermediates *cint, + UInt argno, int first, int last_arg, UInt nxtlbl, + int clleft, CELL *top) { COUNT n = count_funcs(grp); ClauseDef *min = grp->FirstClause; COUNT i; @@ -2255,48 +2226,53 @@ do_funcs(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int firs Yap_emit(label_op, lbl, Zero, cint); /* generate a switch */ fs = emit_fswitch(n, FAILCODE, cint); - for (i = 0; i < n ; i++) { + for (i = 0; i < n; i++) { Functor f = (Functor)RepAppl(min->Tag); FuncSwiEntry *ifs; ClauseDef *max = min; ifs = fetch_fentry(fs, f, i, n); ifs->Tag = f; - while (max != grp->LastClause && (max+1)->Tag == min->Tag) - max++; - /* delay non-trivial indexing + while (max != grp->LastClause && (max + 1)->Tag == min->Tag) + max++; + /* delay non-trivial indexing if (min != max && !IsExtensionFunctor(f)) { ifs->y_u.Label = suspend_indexing(min, max, ap, cint); - } else + } else */ if (IsExtensionFunctor(f)) { - if (f == FunctorDBRef) - ifs->u_f.Label = do_dbref_index(min, max, t, cint, argno, nxtlbl, first, clleft, top); - else if (f == FunctorLongInt || f == FunctorBigInt) - ifs->u_f.Label = do_blob_index(min, max, t, cint, argno, nxtlbl, first, clleft, top, FALSE); + if (f == FunctorDBRef) + ifs->u_f.Label = do_dbref_index(min, max, t, cint, argno, nxtlbl, first, + clleft, top); + else if (f == FunctorLongInt || f == FunctorBigInt) + ifs->u_f.Label = do_blob_index(min, max, t, cint, argno, nxtlbl, first, + clleft, top, FALSE); else - ifs->u_f.Label = do_blob_index(min, max, t, cint, argno, nxtlbl, first, clleft, top, TRUE); - + ifs->u_f.Label = do_blob_index(min, max, t, cint, argno, nxtlbl, first, + clleft, top, TRUE); + } else { CELL *sreg; if (!IsVarTerm(t) && IsApplTerm(t) && FunctorOfTerm(t) == f) { - sreg = RepAppl(t)+1; + sreg = RepAppl(t) + 1; } else { - sreg = NULL; + sreg = NULL; } - ifs->u_f.Label = do_compound_index(min, max, sreg, cint, 0, ArityOfFunctor(f), argno, nxtlbl, first, last_arg, clleft, top, TRUE); + ifs->u_f.Label = + do_compound_index(min, max, sreg, cint, 0, ArityOfFunctor(f), argno, + nxtlbl, first, last_arg, clleft, top, TRUE); } - grp->FirstClause = min = max+1; + grp->FirstClause = min = max + 1; } return lbl; } -static UInt -do_pair(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first, int last_arg, UInt nxtlbl, int clleft, CELL *top) -{ +static UInt do_pair(GroupDef *grp, Term t, struct intermediates *cint, + UInt argno, int first, int last_arg, UInt nxtlbl, + int clleft, CELL *top) { ClauseDef *min = grp->FirstClause; ClauseDef *max = grp->FirstClause; @@ -2310,9 +2286,9 @@ do_pair(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first /* no clauses, just skip */ return nxtlbl; } - grp->FirstClause = max+1; + grp->FirstClause = max + 1; if (min == max) { - /* single clause, no need to do indexing, but we do know it is a list */ + /* single clause, no need to do indexing, but we do know it is a list */ if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) { return (UInt)(min->Code); } else { @@ -2322,14 +2298,15 @@ do_pair(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int first if (min != max && !IsPairTerm(t)) { return suspend_indexing(min, max, cint->CurrentPred, cint); } - return do_compound_index(min, max, (IsPairTerm(t) ? RepPair(t) : NULL), cint, 0, 2, argno, nxtlbl, first, last_arg, clleft, top, TRUE); + return do_compound_index(min, max, (IsPairTerm(t) ? RepPair(t) : NULL), cint, + 0, 2, argno, nxtlbl, first, last_arg, clleft, top, + TRUE); } -static void -group_prologue(int compound_term, UInt argno, int first, struct intermediates *cint) -{ +static void group_prologue(int compound_term, UInt argno, int first, + struct intermediates *cint) { if (compound_term) { - Yap_emit(cache_sub_arg_op, compound_term-1, compound_term-1, cint); + Yap_emit(cache_sub_arg_op, compound_term - 1, compound_term - 1, cint); } else { if (!first || argno != 1) { Yap_emit(cache_arg_op, argno, argno, cint); @@ -2338,17 +2315,16 @@ group_prologue(int compound_term, UInt argno, int first, struct intermediates *c } /* make sure that we can handle failure correctly */ -static void -emit_protection_choicepoint(int first, int clleft, UInt nxtlbl, struct intermediates *cint) -{ +static void emit_protection_choicepoint(int first, int clleft, UInt nxtlbl, + struct intermediates *cint) { if (first) { if (clleft) { if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) { - UInt labl = new_label(cint); + UInt labl = new_label(cint); - Yap_emit_4ops(enter_lu_op, labl, labl, 0, Zero, cint); - Yap_emit(label_op, labl, Zero, cint); + Yap_emit_4ops(enter_lu_op, labl, labl, 0, Zero, cint); + Yap_emit(label_op, labl, Zero, cint); } Yap_emit(tryme_op, nxtlbl, (clleft << 1), cint); } @@ -2362,29 +2338,27 @@ emit_protection_choicepoint(int first, int clleft, UInt nxtlbl, struct intermedi } } - -static ClauseDef * -cls_move(ClauseDef *min, PredEntry *ap, ClauseDef *max, int compound_term, UInt argno, int last_arg) -{ - ClauseDef *cl=min; +static ClauseDef *cls_move(ClauseDef *min, PredEntry *ap, ClauseDef *max, + int compound_term, UInt argno, int last_arg) { + ClauseDef *cl = min; cl = min; if (compound_term) { while (cl <= max) { - skip_to_arg(cl, ap, compound_term, last_arg ); + skip_to_arg(cl, ap, compound_term, last_arg); cl++; } } else { while (cl <= max) { - if (cl->Tag == (_var+1)*sizeof(CELL)) { - ClauseDef *cli = cl; - while (cli < max) { - clcpy(cli,cli+1); - cli++; - } - max--; + if (cl->Tag == (_var + 1) * sizeof(CELL)) { + ClauseDef *cli = cl; + while (cli < max) { + clcpy(cli, cli + 1); + cli++; + } + max--; } else { - move_next(cl, argno); + move_next(cl, argno); } cl++; } @@ -2392,17 +2366,16 @@ cls_move(ClauseDef *min, PredEntry *ap, ClauseDef *max, int compound_term, UInt return max; } -static void -purge_pvar(GroupDef *group) { +static void purge_pvar(GroupDef *group) { ClauseDef *max = group->LastClause; ClauseDef *cl = group->FirstClause; while (cl <= max) { - if (cl->Tag == (_var+1)*sizeof(CELL)) { + if (cl->Tag == (_var + 1) * sizeof(CELL)) { ClauseDef *cli = cl; while (cli < max) { - clcpy(cli,cli+1); - cli++; + clcpy(cli, cli + 1); + cli++; } group->VarClauses--; max--; @@ -2412,12 +2385,12 @@ purge_pvar(GroupDef *group) { group->LastClause = max; } - -static UInt * -do_nonvar_group(GroupDef *grp, Term t, UInt compound_term, CELL *sreg, UInt arity, UInt labl, struct intermediates *cint, UInt argno, int first, int last_arg, UInt nxtlbl, int clleft, CELL *top) { +static UInt *do_nonvar_group(GroupDef *grp, Term t, UInt compound_term, + CELL *sreg, UInt arity, UInt labl, + struct intermediates *cint, UInt argno, int first, + int last_arg, UInt nxtlbl, int clleft, CELL *top) { TypeSwitch *type_sw; PredEntry *ap = cint->CurrentPred; - /* move cl pointer */ if (grp->AtomClauses + grp->PairClauses + grp->StructClauses > 1) { @@ -2431,59 +2404,62 @@ do_nonvar_group(GroupDef *grp, Term t, UInt compound_term, CELL *sreg, UInt arit } type_sw = emit_type_switch(switch_on_type_op, cint); /* have these first so that we will have something initialized here */ - type_sw->ConstEntry = - type_sw->FuncEntry = - type_sw->PairEntry = - type_sw->VarEntry = - nxtlbl; - type_sw->VarEntry = do_var_entries(grp, t, cint, argno, first, clleft, nxtlbl); - grp->LastClause = cls_move(grp->FirstClause, ap, grp->LastClause, compound_term, argno, last_arg); - sort_group(grp,top,cint); + type_sw->ConstEntry = type_sw->FuncEntry = type_sw->PairEntry = + type_sw->VarEntry = nxtlbl; + type_sw->VarEntry = + do_var_entries(grp, t, cint, argno, first, clleft, nxtlbl); + grp->LastClause = cls_move(grp->FirstClause, ap, grp->LastClause, + compound_term, argno, last_arg); + sort_group(grp, top, cint); while (grp->FirstClause <= grp->LastClause) { if (IsAtomOrIntTerm(grp->FirstClause->Tag)) { - type_sw->ConstEntry = do_consts(grp, t, cint, compound_term, sreg, arity, last_arg, argno, first, nxtlbl, clleft, top); + type_sw->ConstEntry = + do_consts(grp, t, cint, compound_term, sreg, arity, last_arg, argno, + first, nxtlbl, clleft, top); } else if (IsApplTerm(grp->FirstClause->Tag)) { - type_sw->FuncEntry = do_funcs(grp, t, cint, argno, first, last_arg, nxtlbl, clleft, top); + type_sw->FuncEntry = + do_funcs(grp, t, cint, argno, first, last_arg, nxtlbl, clleft, top); } else { - type_sw->PairEntry = do_pair(grp, t, cint, argno, first, last_arg, nxtlbl, clleft, top); + type_sw->PairEntry = + do_pair(grp, t, cint, argno, first, last_arg, nxtlbl, clleft, top); } } return &(type_sw->VarEntry); } else { - Yap_emit(label_op,labl,Zero, cint); - do_var_group(grp, cint, TRUE, first, clleft, nxtlbl, ap->ArityOfPE+1); + Yap_emit(label_op, labl, Zero, cint); + do_var_group(grp, cint, TRUE, first, clleft, nxtlbl, ap->ArityOfPE + 1); return NULL; } } -static UInt -do_optims(GroupDef *group, int ngroups, UInt fail_l, ClauseDef *min, struct intermediates *cint) -{ - if (ngroups==2 && group[0].FirstClause == group[0].LastClause && +static UInt do_optims(GroupDef *group, int ngroups, UInt fail_l, ClauseDef *min, + struct intermediates *cint) { + if (ngroups == 2 && group[0].FirstClause == group[0].LastClause && group[0].AtomClauses == 1 && group[1].VarClauses == 1) { CELL *sp; UInt labl; labl = new_label(cint); - sp = Yap_emit_extra_size(if_not_op, Zero, 4*CellSize, cint); + sp = Yap_emit_extra_size(if_not_op, Zero, 4 * CellSize, cint); sp[0] = (CELL)(group[0].FirstClause->Tag); sp[1] = (CELL)(group[1].FirstClause->Code); - sp[2] = do_var_clauses(group[0].FirstClause, group[1].LastClause, FALSE, cint, TRUE, 0, (CELL)FAILCODE, cint->CurrentPred->ArityOfPE+1); - sp[3] = do_var_clauses(min, group[1].LastClause, FALSE, cint, TRUE, 0, (CELL)FAILCODE, cint->CurrentPred->ArityOfPE+1); + sp[2] = do_var_clauses(group[0].FirstClause, group[1].LastClause, FALSE, + cint, TRUE, 0, (CELL)FAILCODE, + cint->CurrentPred->ArityOfPE + 1); + sp[3] = do_var_clauses(min, group[1].LastClause, FALSE, cint, TRUE, 0, + (CELL)FAILCODE, cint->CurrentPred->ArityOfPE + 1); return labl; } return fail_l; } -static int -cls_info(ClauseDef *min, ClauseDef *max, UInt argno) -{ - ClauseDef *cl=min; +static int cls_info(ClauseDef *min, ClauseDef *max, UInt argno) { + ClauseDef *cl = min; int found_pvar = FALSE; while (cl <= max) { add_info(cl, argno); - if (cl->Tag == (_var+1)*sizeof(CELL)) { + if (cl->Tag == (_var + 1) * sizeof(CELL)) { found_pvar = TRUE; } /* if (IsVarTerm(cl->Tag)) cl->Tag = (CELL)NULL; */ @@ -2492,57 +2468,56 @@ cls_info(ClauseDef *min, ClauseDef *max, UInt argno) return found_pvar; } -static int -cls_head_info(ClauseDef *min, ClauseDef *max, UInt argno, int in_idb) -{ - ClauseDef *cl=min; +static int cls_head_info(ClauseDef *min, ClauseDef *max, UInt argno, + int in_idb) { + ClauseDef *cl = min; if (in_idb) { if (argno != 2) { while (cl <= max) { - cl->Tag = (CELL)NULL; - cl++; - } + cl->Tag = (CELL)NULL; + cl++; + } } else { while (cl <= max) { - LogUpdClause *lcl = ClauseCodeToLogUpdClause(cl->CurrentCode); - Term t = lcl->lusl.ClSource->Entry; - - if (IsVarTerm(t)) { - cl->Tag = (CELL)NULL; - } else if (IsApplTerm(t)) { - CELL *pt = RepAppl(t); - - cl->Tag = AbsAppl((CELL *)pt[0]); - if (IsExtensionFunctor(FunctorOfTerm(t))) { - cl->ucd.t_ptr = t; - } else { - cl->ucd.c_sreg = pt; - } - } else if (IsPairTerm(t)) { - CELL *pt = RepPair(t); + LogUpdClause *lcl = ClauseCodeToLogUpdClause(cl->CurrentCode); + Term t = lcl->lusl.ClSource->Entry; - cl->Tag = AbsPair(NULL); - cl->ucd.c_sreg = pt-1; - } else { - cl->Tag = t; - } - cl++; + if (IsVarTerm(t)) { + cl->Tag = (CELL)NULL; + } else if (IsApplTerm(t)) { + CELL *pt = RepAppl(t); + + cl->Tag = AbsAppl((CELL *)pt[0]); + if (IsExtensionFunctor(FunctorOfTerm(t))) { + cl->ucd.t_ptr = t; + } else { + cl->ucd.c_sreg = pt; + } + } else if (IsPairTerm(t)) { + CELL *pt = RepPair(t); + + cl->Tag = AbsPair(NULL); + cl->ucd.c_sreg = pt - 1; + } else { + cl->Tag = t; + } + cl++; } } } else { - while (cl <= max) { - add_info(cl, argno); - /* if (IsVarTerm(cl->Tag)) cl->Tag = (CELL)NULL; */ - cl++; - } + while (cl <= max) { + add_info(cl, argno); + /* if (IsVarTerm(cl->Tag)) cl->Tag = (CELL)NULL; */ + cl++; + } } return FALSE; } -static UInt -do_index(ClauseDef *min, ClauseDef* max, struct intermediates *cint, UInt argno, UInt fail_l, int first, int clleft, CELL *top) -{ +static UInt do_index(ClauseDef *min, ClauseDef *max, struct intermediates *cint, + UInt argno, UInt fail_l, int first, int clleft, + CELL *top) { CACHE_REGS UInt ngroups, found_pvar = FALSE; UInt i = 0; @@ -2558,14 +2533,16 @@ do_index(ClauseDef *min, ClauseDef* max, struct intermediates *cint, UInt argno, /* base case, just commit to the current code */ return emit_single_switch_case(min, cint, first, clleft, fail_l); } - if ((argno > 1 && indexingMode() == TermSingle && ap->PredFlags & LogUpdatePredFlag) || - indexingMode() == TermOff || - ap->ArityOfPE < argno) { - return do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, ap->ArityOfPE+1); + if ((argno > 1 && indexingMode() == TermSingle && + ap->PredFlags & LogUpdatePredFlag) || + indexingMode() == TermOff || ap->ArityOfPE < argno) { + return do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, + ap->ArityOfPE + 1); } t = Deref(XREGS[argno]); if (ap->PredFlags & LogUpdatePredFlag) { - found_pvar = cls_head_info(min, max, argno, (ap->ModuleOfPred == IDB_MODULE)); + found_pvar = + cls_head_info(min, max, argno, (ap->ModuleOfPred == IDB_MODULE)); } else { found_pvar = cls_info(min, max, argno); } @@ -2575,85 +2552,85 @@ do_index(ClauseDef *min, ClauseDef* max, struct intermediates *cint, UInt argno, Yap_emit(label_op, lablx, Zero, cint); while (IsVarTerm(t)) { if (ngroups > 1 || !group->VarClauses) { - UInt susp_lab = suspend_indexing(min, max, ap, cint); - if (!cint->expand_block) { - cint->expand_block = (yamop *)susp_lab; - } - Yap_emit(jump_nv_op, susp_lab, argno, cint); + UInt susp_lab = suspend_indexing(min, max, ap, cint); + if (!cint->expand_block) { + cint->expand_block = (yamop *)susp_lab; + } + Yap_emit(jump_nv_op, susp_lab, argno, cint); } if (argno == ap->ArityOfPE || - (indexingMode() == TermSingle && - ap->PredFlags & LogUpdatePredFlag)) { - do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, argno0); - cint->expand_block = eblk; - return lablx; + (indexingMode() == TermSingle && ap->PredFlags & LogUpdatePredFlag)) { + do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, argno0); + cint->expand_block = eblk; + return lablx; } argno++; t = Deref(XREGS[argno]); if (ap->PredFlags & LogUpdatePredFlag) { - found_pvar = cls_head_info(min, max, argno, (ap->ModuleOfPred == IDB_MODULE) ); + found_pvar = + cls_head_info(min, max, argno, (ap->ModuleOfPred == IDB_MODULE)); } else { - found_pvar = cls_info(min, max, argno); + found_pvar = cls_info(min, max, argno); } ngroups = groups_in(min, max, group, cint); - } + } labl0 = labl = new_label(cint); } else { lablx = labl0 = labl = new_label(cint); } cint->expand_block = eblk; - top = (CELL *)(group+ngroups); + top = (CELL *)(group + ngroups); if (argno > 1) { /* don't try being smart for other arguments than the first */ if (ngroups > 1 || group->VarClauses != 0 || found_pvar) { if (ap->ArityOfPE == argno) { - return do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, ap->ArityOfPE+1); + return do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, + ap->ArityOfPE + 1); } else { - return do_index(min, max, cint, argno+1, fail_l, first, clleft, top); + return do_index(min, max, cint, argno + 1, fail_l, first, clleft, top); } } else { ClauseDef *cl = min; /* - need to reset the code pointer, otherwise I could be in - the middle of a compound term. + need to reset the code pointer, otherwise I could be in + the middle of a compound term. */ while (cl <= max) { - cl->CurrentCode = cl->Code; - cl++; - } + cl->CurrentCode = cl->Code; + cl++; + } } } else { UInt special_options; if ((ap->PredFlags & LogUpdatePredFlag) && ngroups > 1) { if (ngroups > 1) { - group[0].VarClauses = ap->cs.p_code.NOfClauses; - group[0].AtomClauses = - group[0].PairClauses = - group[0].StructClauses = - group[0].TestClauses = 0; - group[0].LastClause = group[ngroups-1].LastClause; - ngroups = 1; + group[0].VarClauses = ap->cs.p_code.NOfClauses; + group[0].AtomClauses = group[0].PairClauses = group[0].StructClauses = + group[0].TestClauses = 0; + group[0].LastClause = group[ngroups - 1].LastClause; + ngroups = 1; } - } else if ((special_options = do_optims(group, ngroups, fail_l, min, cint)) != fail_l) { + } else if ((special_options = + do_optims(group, ngroups, fail_l, min, cint)) != fail_l) { return special_options; } if (ngroups == 1 && group->VarClauses && !found_pvar) { - return do_index(min, max, cint, argno+1, fail_l, first, clleft, top); + return do_index(min, max, cint, argno + 1, fail_l, first, clleft, top); } else if (found_pvar || - (ap->PredFlags & LogUpdatePredFlag && group[0].VarClauses)) { + (ap->PredFlags & LogUpdatePredFlag && group[0].VarClauses)) { /* make sure we know where to suspend */ Yap_emit(label_op, labl0, Zero, cint); labl = new_label(cint); - Yap_emit(jump_v_op, suspend_indexing(min, max, ap, cint), Zero, cint); + Yap_emit(jump_v_op, suspend_indexing(min, max, ap, cint), Zero, cint); } } - for (i=0; i < ngroups; i++) { + for (i = 0; i < ngroups; i++) { UInt nextlbl; - int left_clauses = clleft+(max-group->LastClause); + int left_clauses = clleft + (max - group->LastClause); /* a group may end up not having clauses*/ - if (i < ngroups-1) { + if (i < ngroups - 1) { nextlbl = new_label(cint); } else { nextlbl = fail_l; @@ -2661,14 +2638,16 @@ do_index(ClauseDef *min, ClauseDef* max, struct intermediates *cint, UInt argno, if (found_pvar && argno == 1) { purge_pvar(group); } - if (group->FirstClause==group->LastClause && first && left_clauses == 0) { + if (group->FirstClause == group->LastClause && first && left_clauses == 0) { Yap_emit(jumpi_op, (CELL)(group->FirstClause->Code), Zero, cint); } else { if (group->VarClauses) { - Yap_emit(label_op,labl,Zero, cint); - do_var_group(group, cint, argno == 1, first, left_clauses, nextlbl, ap->ArityOfPE+1); + Yap_emit(label_op, labl, Zero, cint); + do_var_group(group, cint, argno == 1, first, left_clauses, nextlbl, + ap->ArityOfPE + 1); } else { - do_nonvar_group(group, t, 0, NULL, 0, labl, cint, argno, first, TRUE, nextlbl, left_clauses, top); + do_nonvar_group(group, t, 0, NULL, 0, labl, cint, argno, first, TRUE, + nextlbl, left_clauses, top); } } first = FALSE; @@ -2678,26 +2657,22 @@ do_index(ClauseDef *min, ClauseDef* max, struct intermediates *cint, UInt argno, return lablx; } -static ClauseDef * -copy_clauses(ClauseDef *max0, ClauseDef *min0, CELL *top, struct intermediates *cint) -{ +static ClauseDef *copy_clauses(ClauseDef *max0, ClauseDef *min0, CELL *top, + struct intermediates *cint) { CACHE_REGS - UInt sz = ((max0+1)-min0)*sizeof(ClauseDef); - if ((char *)top + sz >= LOCAL_TrailTop-4096) { + UInt sz = ((max0 + 1) - min0) * sizeof(ClauseDef); + if ((char *)top + sz >= LOCAL_TrailTop - 4096) { LOCAL_Error_Size = sz; /* grow stack */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,4); + siglongjmp(cint->CompilerBotch, 4); } memcpy((void *)top, (void *)min0, sz); return (ClauseDef *)top; } - /* make sure that it is worth it to generate indexing code at that point */ -static int -several_tags(ClauseDef *min, ClauseDef *max) -{ +static int several_tags(ClauseDef *min, ClauseDef *max) { CELL tag = min->Tag; while (min < max) { min++; @@ -2707,11 +2682,11 @@ several_tags(ClauseDef *min, ClauseDef *max) return FALSE; } - /* execute an index inside a structure */ -static UInt -do_compound_index(ClauseDef *min0, ClauseDef* max0, Term* sreg, struct intermediates *cint, UInt i, UInt arity, UInt argno, UInt fail_l, int first, int last_arg, int clleft, CELL *top, int done_work) -{ +static UInt do_compound_index(ClauseDef *min0, ClauseDef *max0, Term *sreg, + struct intermediates *cint, UInt i, UInt arity, + UInt argno, UInt fail_l, int first, int last_arg, + int clleft, CELL *top, int done_work) { UInt ret_lab = 0, *newlabp; CELL *top0 = top; ClauseDef *min, *max; @@ -2720,16 +2695,17 @@ do_compound_index(ClauseDef *min0, ClauseDef* max0, Term* sreg, struct intermedi pred_flags_t lu_pred = ap->PredFlags & LogUpdatePredFlag; UInt old_last_depth, old_last_depth_size; - newlabp = & ret_lab; + newlabp = &ret_lab; if (min0 == max0) { /* base case, just commit to the current code */ return emit_single_switch_case(min0, cint, first, clleft, fail_l); } if ((indexingMode() == TermSingle && ap->PredFlags & LogUpdatePredFlag) || - (indexingDepth() && cint->term_depth - cint->last_index_new_depth > indexingDepth())) { - *newlabp = - do_var_clauses(min0, max0, FALSE, cint, first, clleft, fail_l, ap->ArityOfPE+1); - return ret_lab; + (indexingDepth() && + cint->term_depth - cint->last_index_new_depth > indexingDepth())) { + *newlabp = do_var_clauses(min0, max0, FALSE, cint, first, clleft, fail_l, + ap->ArityOfPE + 1); + return ret_lab; } if (sreg == NULL) { return suspend_indexing(min0, max0, ap, cint); @@ -2737,37 +2713,41 @@ do_compound_index(ClauseDef *min0, ClauseDef* max0, Term* sreg, struct intermedi cint->term_depth++; old_last_depth = cint->last_index_new_depth; old_last_depth_size = cint->last_depth_size; - if (cint->last_depth_size != max0-min0) { + if (cint->last_depth_size != max0 - min0) { cint->last_index_new_depth = cint->term_depth; - cint->last_depth_size = max0-min0; + cint->last_depth_size = max0 - min0; } - while (i < arity && !found_index) { + while (i < arity && !found_index) { ClauseDef *cl; GroupDef *group; UInt ngroups; int isvt = IsVarTerm(Deref(sreg[i])); min = copy_clauses(max0, min0, top, cint); - max = min+(max0-min0); - top = (CELL *)(max+1); + max = min + (max0 - min0); + top = (CELL *)(max + 1); cl = min; /* search for a subargument */ while (cl <= max) { - add_arg_info(cl, ap, i+1); + add_arg_info(cl, ap, i + 1); cl++; } group = (GroupDef *)top; - ngroups = groups_in(min, max, group, cint); - if (ngroups == 1 && group->VarClauses == 0 && (i < 8 || several_tags(min,max))) { + ngroups = groups_in(min, max, group, cint); + if (ngroups == 1 && group->VarClauses == 0 && + (i < 8 || several_tags(min, max))) { /* ok, we are doing a sub-argument */ /* process group */ found_index = TRUE; ret_lab = new_label(cint); - top = (CELL *)(group+1); - if (do_nonvar_group(group, (sreg == NULL ? 0L : Deref(sreg[i])), i+1, (isvt ? NULL : sreg), arity, *newlabp, cint, argno, first, (last_arg && i+1 == arity), fail_l, clleft, top) == NULL) { - top = top0; - break; + top = (CELL *)(group + 1); + if (do_nonvar_group(group, (sreg == NULL ? 0L : Deref(sreg[i])), i + 1, + (isvt ? NULL : sreg), arity, *newlabp, cint, argno, + first, (last_arg && i + 1 == arity), fail_l, clleft, + top) == NULL) { + top = top0; + break; } } top = top0; @@ -2775,7 +2755,8 @@ do_compound_index(ClauseDef *min0, ClauseDef* max0, Term* sreg, struct intermedi } if (!found_index) { if (!lu_pred || !done_work) - *newlabp = do_index(min0, max0, cint, argno+1, fail_l, first, clleft, top); + *newlabp = + do_index(min0, max0, cint, argno + 1, fail_l, first, clleft, top); else *newlabp = suspend_indexing(min0, max0, ap, cint); } @@ -2785,44 +2766,44 @@ do_compound_index(ClauseDef *min0, ClauseDef* max0, Term* sreg, struct intermedi return ret_lab; } -static UInt -do_dbref_index(ClauseDef *min, ClauseDef* max, Term t, struct intermediates *cint, UInt argno, UInt fail_l, int first, int clleft, CELL *top) -{ +static UInt do_dbref_index(ClauseDef *min, ClauseDef *max, Term t, + struct intermediates *cint, UInt argno, UInt fail_l, + int first, int clleft, CELL *top) { UInt ngroups; GroupDef *group; ClauseDef *cl = min; group = (GroupDef *)top; cl = min; - + while (cl <= max) { cl->Tag = cl->ucd.t_ptr; cl++; } ngroups = groups_in(min, max, group, cint); if (ngroups > 1 || group->VarClauses) { - return do_index(min, max, cint, argno+1, fail_l, first, clleft, top); + return do_index(min, max, cint, argno + 1, fail_l, first, clleft, top); } else { int labl = new_label(cint); Yap_emit(label_op, labl, Zero, cint); Yap_emit(index_dbref_op, Zero, Zero, cint); - sort_group(group,(CELL *)(group+1),cint); - do_blobs(group, t, cint, argno, first, fail_l, clleft, (CELL *)(group+1)); + sort_group(group, (CELL *)(group + 1), cint); + do_blobs(group, t, cint, argno, first, fail_l, clleft, (CELL *)(group + 1)); return labl; } } -static UInt -do_blob_index(ClauseDef *min, ClauseDef* max, Term t, struct intermediates *cint, UInt argno, UInt fail_l, int first, int clleft, CELL *top, int blob) -{ +static UInt do_blob_index(ClauseDef *min, ClauseDef *max, Term t, + struct intermediates *cint, UInt argno, UInt fail_l, + int first, int clleft, CELL *top, int blob) { UInt ngroups; GroupDef *group; ClauseDef *cl = min; group = (GroupDef *)top; cl = min; - + while (cl <= max) { if (cl->ucd.t_ptr == (CELL)NULL) { /* check whether it is a builtin */ cl->Tag = Zero; @@ -2835,7 +2816,7 @@ do_blob_index(ClauseDef *min, ClauseDef* max, Term t, struct intermediates *cint } ngroups = groups_in(min, max, group, cint); if (ngroups > 1 || group->VarClauses) { - return do_index(min, max, cint, argno+1, fail_l, first, clleft, top); + return do_index(min, max, cint, argno + 1, fail_l, first, clleft, top); } else { int labl = new_label(cint); @@ -2844,23 +2825,21 @@ do_blob_index(ClauseDef *min, ClauseDef* max, Term t, struct intermediates *cint Yap_emit(index_blob_op, Zero, Zero, cint); else Yap_emit(index_long_op, Zero, Zero, cint); - sort_group(group,(CELL *)(group+1),cint); - do_blobs(group, t, cint, argno, first, fail_l, clleft, (CELL *)(group+1)); + sort_group(group, (CELL *)(group + 1), cint); + do_blobs(group, t, cint, argno, first, fail_l, clleft, (CELL *)(group + 1)); return labl; } } -static void -init_clauses(ClauseDef *cl, PredEntry *ap) -{ +static void init_clauses(ClauseDef *cl, PredEntry *ap) { if (ap->PredFlags & MegaClausePredFlag) { MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses; - yamop *end = (yamop *)((char *)mcl->ClCode+nclauses*mcl->ClItemSize); + yamop *end = (yamop *)((char *)mcl->ClCode + nclauses * mcl->ClItemSize); yamop *cd = mcl->ClCode; while (cd < end) { cl->Code = cl->CurrentCode = cd; - cd = (yamop *)((char *)cd+mcl->ClItemSize); + cd = (yamop *)((char *)cd + mcl->ClItemSize); cl++; } } else { @@ -2871,15 +2850,13 @@ init_clauses(ClauseDef *cl, PredEntry *ap) cl->Code = cl->CurrentCode = scl->ClCode; cl++; if (scl->ClCode == ap->cs.p_code.LastClause) - return; + return; scl = scl->ClNext; } while (TRUE); } } -static void -init_log_upd_clauses(ClauseDef *cl, PredEntry *ap) -{ +static void init_log_upd_clauses(ClauseDef *cl, PredEntry *ap) { LogUpdClause *lcl = ClauseCodeToLogUpdClause(ap->cs.p_code.FirstClause); do { @@ -2889,13 +2866,11 @@ init_log_upd_clauses(ClauseDef *cl, PredEntry *ap) } while (lcl != NULL); } -static UInt -compile_index(struct intermediates *cint) -{ +static UInt compile_index(struct intermediates *cint) { CACHE_REGS PredEntry *ap = cint->CurrentPred; int NClauses = ap->cs.p_code.NOfClauses; - CELL *top = (CELL *) TR; + CELL *top = (CELL *)TR; UInt res; /* only global variable I use directly */ @@ -2904,47 +2879,47 @@ compile_index(struct intermediates *cint) LOCAL_Error_Size = 0; #if USE_SYSTEM_MALLOC if (!cint->cls) { - cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef)); + cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses * sizeof(ClauseDef)); if (!cint->cls) { /* tell how much space we need */ - LOCAL_Error_Size += NClauses*sizeof(ClauseDef); + LOCAL_Error_Size += NClauses * sizeof(ClauseDef); /* grow stack */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,2); + siglongjmp(cint->CompilerBotch, 2); } } cint->freep = (char *)HR; #else /* reserve double the space for compiler */ cint->cls = (ClauseDef *)HR; - if (cint->cls+2*NClauses > (ClauseDef *)(ASP-4096)) { + if (cint->cls + 2 * NClauses > (ClauseDef *)(ASP - 4096)) { /* tell how much space we need */ - LOCAL_Error_Size += NClauses*sizeof(ClauseDef); + LOCAL_Error_Size += NClauses * sizeof(ClauseDef); /* grow stack */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,3); + siglongjmp(cint->CompilerBotch, 3); } - cint->freep = (char *)(cint->cls+NClauses); + cint->freep = (char *)(cint->cls + NClauses); #endif if (ap->PredFlags & LogUpdatePredFlag) { /* throw away a label */ new_label(cint); - init_log_upd_clauses(cint->cls,ap); + init_log_upd_clauses(cint->cls, ap); } else if (ap->PredFlags & UDIPredFlag) { UInt lbl = new_label(cint); - Yap_emit(user_switch_op, Unsigned(ap), Unsigned(&(ap->cs.p_code.ExpandCode)), cint); + Yap_emit(user_switch_op, Unsigned(ap), + Unsigned(&(ap->cs.p_code.ExpandCode)), cint); return lbl; } else { - /* prepare basic data structures */ - init_clauses(cint->cls,ap); + /* prepare basic data structures */ + init_clauses(cint->cls, ap); } - res = do_index(cint->cls, cint->cls+(NClauses-1), cint, 1, (UInt)FAILCODE, TRUE, 0, top); + res = do_index(cint->cls, cint->cls + (NClauses - 1), cint, 1, (UInt)FAILCODE, + TRUE, 0, top); return res; } -static void -CleanCls(struct intermediates *cint) -{ +static void CleanCls(struct intermediates *cint) { #if USE_SYSTEM_MALLOC if (cint->cls) { Yap_FreeCodeSpace((ADDR)cint->cls); @@ -2953,15 +2928,12 @@ CleanCls(struct intermediates *cint) cint->cls = NULL; } -yamop * -Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) -{ +yamop *Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) { CACHE_REGS yamop *indx_out; int setjres; struct intermediates cint; - cint.CurrentPred = ap; cint.code_addr = NULL; cint.blks = NULL; @@ -2971,7 +2943,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) if ((setjres = sigsetjmp(cint.CompilerBotch, 0)) == 3) { restore_machine_regs(); recover_from_failed_susp_on_cls(&cint, 0); - if (!Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE+NSlots, ENV, next_pc)) { + if (!Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE + NSlots, ENV, next_pc)) { CleanCls(&cint); Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage); return FAILCODE; @@ -3001,7 +2973,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) return FAILCODE; } } - restart_index: +restart_index: Yap_BuildMegaClause(ap); cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NULL; cint.expand_block = NULL; @@ -3021,12 +2993,13 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) /* globals for assembler */ LOCAL_IPredArity = ap->ArityOfPE; if (cint.CodeStart) { - if ((indx_out = Yap_assemble(ASSEMBLING_INDEX, TermNil, ap, FALSE, &cint, cint.i_labelno+1)) == NULL) { + if ((indx_out = Yap_assemble(ASSEMBLING_INDEX, TermNil, ap, FALSE, &cint, + cint.i_labelno + 1)) == NULL) { if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { - Yap_ReleaseCMem(&cint); - CleanCls(&cint); - Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage); - return NULL; + Yap_ReleaseCMem(&cint); + CleanCls(&cint); + Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage); + return NULL; } goto restart_index; } @@ -3041,16 +3014,15 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) LogUpdIndex *cl = ClauseCodeToLogUpdIndex(indx_out); cl->ClFlags |= SwitchRootMask; } - return(indx_out); + return (indx_out); } -static istack_entry * -push_stack(istack_entry *sp, Int arg, Term Tag, Term extra, struct intermediates *cint) -{ +static istack_entry *push_stack(istack_entry *sp, Int arg, Term Tag, Term extra, + struct intermediates *cint) { CACHE_REGS - if (sp+1 > (istack_entry *)LOCAL_TrailTop) { + if (sp + 1 > (istack_entry *)LOCAL_TrailTop) { save_machine_regs(); - siglongjmp(cint->CompilerBotch,4); + siglongjmp(cint->CompilerBotch, 4); } sp->pos = arg; sp->val = Tag; @@ -3060,9 +3032,8 @@ push_stack(istack_entry *sp, Int arg, Term Tag, Term extra, struct intermediates return sp; } -static istack_entry * -install_clause(ClauseDef *cls, PredEntry *ap, istack_entry *stack) -{ +static istack_entry *install_clause(ClauseDef *cls, PredEntry *ap, + istack_entry *stack) { istack_entry *sp = stack; while (sp->pos) { if ((Int)(sp->pos) > 0) { @@ -3074,35 +3045,36 @@ install_clause(ClauseDef *cls, PredEntry *ap, istack_entry *stack) /* if we are not talking about a variable */ if (cls->Tag != sp->val) { if (sp->val == 0L) { - sp++; + sp++; } break; } else { if (IsApplTerm(cls->Tag)) { - Functor f = (Functor)RepAppl(cls->Tag); - if (IsExtensionFunctor(f)) { - if (f == FunctorDBRef) { - if (cls->ucd.t_ptr != sp->extra) break; - } else if (f == FunctorDouble) { - if (cls->ucd.t_ptr && - Yap_Double_key(sp->extra) != Yap_Double_key(cls->ucd.t_ptr)) - break; - } else if (f == FunctorString) { - if (cls->ucd.t_ptr && - Yap_String_key(sp->extra) != Yap_String_key(cls->ucd.t_ptr)) - break; - } else { - if (cls->ucd.t_ptr && - Yap_Int_key(sp->extra) != Yap_Int_key(cls->ucd.t_ptr)) - break; - } - } + Functor f = (Functor)RepAppl(cls->Tag); + if (IsExtensionFunctor(f)) { + if (f == FunctorDBRef) { + if (cls->ucd.t_ptr != sp->extra) + break; + } else if (f == FunctorDouble) { + if (cls->ucd.t_ptr && + Yap_Double_key(sp->extra) != Yap_Double_key(cls->ucd.t_ptr)) + break; + } else if (f == FunctorString) { + if (cls->ucd.t_ptr && + Yap_String_key(sp->extra) != Yap_String_key(cls->ucd.t_ptr)) + break; + } else { + if (cls->ucd.t_ptr && + Yap_Int_key(sp->extra) != Yap_Int_key(cls->ucd.t_ptr)) + break; + } + } } if ((Int)(sp->pos) > 0) { - move_next(cls, sp->pos); + move_next(cls, sp->pos); } else if (sp->pos) { - UInt argno = -sp->pos; - skip_to_arg(cls, ap, argno, FALSE); + UInt argno = -sp->pos; + skip_to_arg(cls, ap, argno, FALSE); } } sp++; @@ -3110,37 +3082,36 @@ install_clause(ClauseDef *cls, PredEntry *ap, istack_entry *stack) return sp; } -static ClauseDef * -install_clauses(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop *beg, yamop *end) -{ +static ClauseDef *install_clauses(ClauseDef *cls, PredEntry *ap, + istack_entry *stack, yamop *beg, yamop *end) { istack_entry *sp = stack; if (ap->PredFlags & MegaClausePredFlag) { MegaClause *mcl = ClauseCodeToMegaClause(beg); UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses; - yamop *end = (yamop *)((char *)mcl->ClCode+nclauses*mcl->ClItemSize); + yamop *end = (yamop *)((char *)mcl->ClCode + nclauses * mcl->ClItemSize); yamop *cd = mcl->ClCode; if (stack[0].pos == 0) { while (TRUE) { - cls->Code = cls->CurrentCode = cd; - cls->Tag = 0; - cls++; - cd = (yamop *)((char *)cd+mcl->ClItemSize); - if (cd == end) { - return cls-1; - } + cls->Code = cls->CurrentCode = cd; + cls->Tag = 0; + cls++; + cd = (yamop *)((char *)cd + mcl->ClItemSize); + if (cd == end) { + return cls - 1; + } } } while (TRUE) { - cls->Code = cls->CurrentCode = cd; + cls->Code = cls->CurrentCode = cd; sp = install_clause(cls, ap, stack); /* we reached a matching clause */ if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { - cls++; + cls++; } - cd = (yamop *)((char *)cd+mcl->ClItemSize); + cd = (yamop *)((char *)cd + mcl->ClItemSize); if (cd == end) { - return cls-1; + return cls - 1; } } } else { @@ -3148,76 +3119,74 @@ install_clauses(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop *beg, if (stack[0].pos == 0) { while (TRUE) { - cls->Code = cls->CurrentCode = cl->ClCode; - cls->Tag = 0; - cls++; - if (cl->ClCode == end) { - return cls-1; - } - cl = cl->ClNext; + cls->Code = cls->CurrentCode = cl->ClCode; + cls->Tag = 0; + cls++; + if (cl->ClCode == end) { + return cls - 1; + } + cl = cl->ClNext; } } while (TRUE) { - cls->Code = cls->CurrentCode = cl->ClCode; + cls->Code = cls->CurrentCode = cl->ClCode; sp = install_clause(cls, ap, stack); /* we reached a matching clause */ if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { - cls++; + cls++; } if (cl->ClCode == end) { - return cls-1; + return cls - 1; } cl = cl->ClNext; } } } -static ClauseDef * -install_clauseseq(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop **beg, yamop **end) -{ +static ClauseDef *install_clauseseq(ClauseDef *cls, PredEntry *ap, + istack_entry *stack, yamop **beg, + yamop **end) { istack_entry *sp = stack; if (stack[0].pos == 0) { while (TRUE) { - if (*beg) { - cls->Code = cls->CurrentCode = *beg; - cls->Tag = 0; - cls++; + if (*beg) { + cls->Code = cls->CurrentCode = *beg; + cls->Tag = 0; + cls++; } beg++; if (beg == end) { - return cls-1; + return cls - 1; } } } while (TRUE) { if (*beg) { - cls->Code = cls->CurrentCode = *beg; + cls->Code = cls->CurrentCode = *beg; sp = install_clause(cls, ap, stack); /* we reached a matching clause */ if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { - cls++; + cls++; } } beg++; if (beg == end) { - return cls-1; + return cls - 1; } } } -static void -reinstall_clauses(ClauseDef *cls, ClauseDef *end, PredEntry *ap, istack_entry *stack) -{ +static void reinstall_clauses(ClauseDef *cls, ClauseDef *end, PredEntry *ap, + istack_entry *stack) { do { cls->CurrentCode = cls->Code; install_clause(cls, ap, stack); } while (cls++ != end); } -static istack_entry * -install_log_upd_clause(ClauseDef *cls, PredEntry *ap, istack_entry *stack) -{ +static istack_entry *install_log_upd_clause(ClauseDef *cls, PredEntry *ap, + istack_entry *stack) { istack_entry *sp = stack; while (sp->pos) { if ((Int)(sp->pos) > 0) { @@ -3229,32 +3198,33 @@ install_log_upd_clause(ClauseDef *cls, PredEntry *ap, istack_entry *stack) /* if we are not talking about a variable */ if (cls->Tag != sp->val) { if (sp->val == 0L) { - sp++; + sp++; } break; } else { if (IsApplTerm(cls->Tag)) { - Functor f = (Functor)RepAppl(cls->Tag); - if (IsExtensionFunctor(f)) { - if (f == FunctorDBRef) { - if (cls->ucd.t_ptr != sp->extra) break; - } else if (f == FunctorDouble) { - if (cls->ucd.t_ptr && - Yap_Double_key(sp->extra) != Yap_Double_key(cls->ucd.t_ptr)) - break; - } else { - if (cls->ucd.t_ptr && - Yap_Int_key(sp->extra) != Yap_Int_key(cls->ucd.t_ptr)) - break; - } - } + Functor f = (Functor)RepAppl(cls->Tag); + if (IsExtensionFunctor(f)) { + if (f == FunctorDBRef) { + if (cls->ucd.t_ptr != sp->extra) + break; + } else if (f == FunctorDouble) { + if (cls->ucd.t_ptr && + Yap_Double_key(sp->extra) != Yap_Double_key(cls->ucd.t_ptr)) + break; + } else { + if (cls->ucd.t_ptr && + Yap_Int_key(sp->extra) != Yap_Int_key(cls->ucd.t_ptr)) + break; + } + } } if ((Int)(sp->pos) > 0) { - move_next(cls, sp->pos); + move_next(cls, sp->pos); } else if (sp->pos) { - UInt argno = -sp->pos; + UInt argno = -sp->pos; - skip_to_arg(cls, ap, argno, FALSE); + skip_to_arg(cls, ap, argno, FALSE); } } sp++; @@ -3262,73 +3232,72 @@ install_log_upd_clause(ClauseDef *cls, PredEntry *ap, istack_entry *stack) return sp; } -static ClauseDef * -install_log_upd_clauses(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop *beg, yamop *end) -{ +static ClauseDef *install_log_upd_clauses(ClauseDef *cls, PredEntry *ap, + istack_entry *stack, yamop *beg, + yamop *end) { istack_entry *sp = stack; if (stack[0].pos == 0) { while (TRUE) { - cls->Code = cls->CurrentCode = beg; - cls->Tag = 0; + cls->Code = cls->CurrentCode = beg; + cls->Tag = 0; cls++; if (beg == end || beg == NULL) { - return cls-1; + return cls - 1; } beg = ClauseCodeToLogUpdClause(beg)->ClNext->ClCode; } } while (TRUE) { - cls->Code = cls->CurrentCode = beg; + cls->Code = cls->CurrentCode = beg; sp = install_log_upd_clause(cls, ap, stack); /* we reached a matching clause */ if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { cls++; } if (beg == end || beg == NULL) { - return cls-1; + return cls - 1; } beg = ClauseCodeToLogUpdClause(beg)->ClNext->ClCode; } } -static ClauseDef * -install_log_upd_clauseseq(ClauseDef *cls, PredEntry *ap, istack_entry *stack, yamop **beg, yamop **end) -{ +static ClauseDef *install_log_upd_clauseseq(ClauseDef *cls, PredEntry *ap, + istack_entry *stack, yamop **beg, + yamop **end) { istack_entry *sp = stack; if (stack[0].pos == 0) { while (TRUE) { if (beg) { - cls->Code = cls->CurrentCode = *beg; - cls->Tag = 0; - cls++; + cls->Code = cls->CurrentCode = *beg; + cls->Tag = 0; + cls++; } beg++; if (beg == end) { - return cls-1; + return cls - 1; } } } while (TRUE) { if (*beg) { - cls->Code = cls->CurrentCode = *beg; + cls->Code = cls->CurrentCode = *beg; sp = install_log_upd_clause(cls, ap, stack); /* we reached a matching clause */ if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) { - cls++; + cls++; } } beg++; if (beg == end) { - return cls-1; + return cls - 1; } } } -static void -reinstall_log_upd_clauses(ClauseDef *cls, ClauseDef *end, PredEntry *ap, istack_entry *stack) -{ +static void reinstall_log_upd_clauses(ClauseDef *cls, ClauseDef *end, + PredEntry *ap, istack_entry *stack) { do { cls->CurrentCode = cls->Code; install_log_upd_clause(cls, ap, stack); @@ -3337,17 +3306,15 @@ reinstall_log_upd_clauses(ClauseDef *cls, ClauseDef *end, PredEntry *ap, istack_ #if PRECOMPUTE_REGADDRESS -#define arg_from_x(I) (((CELL *)(I))-XREGS) +#define arg_from_x(I) (((CELL *)(I)) - XREGS) #else -#define arg_from_x(I) (I) +#define arg_from_x(I) (I) #endif /* ALIGN_LONGS */ -static AtomSwiEntry * -lookup_c(Term t, yamop *tab, COUNT entries) -{ +static AtomSwiEntry *lookup_c(Term t, yamop *tab, COUNT entries) { AtomSwiEntry *cebase = (AtomSwiEntry *)tab; while (cebase->Tag != t) { @@ -3359,11 +3326,9 @@ lookup_c(Term t, yamop *tab, COUNT entries) return cebase; } -static FuncSwiEntry * -lookup_f(Functor f, yamop *tab, COUNT entries) -{ +static FuncSwiEntry *lookup_f(Functor f, yamop *tab, COUNT entries) { FuncSwiEntry *febase = (FuncSwiEntry *)tab; - + while (febase->Tag != f) { entries--; febase++; @@ -3373,13 +3338,11 @@ lookup_f(Functor f, yamop *tab, COUNT entries) return febase; } -static COUNT -count_clauses_left(yamop *cl, PredEntry *ap) -{ +static COUNT count_clauses_left(yamop *cl, PredEntry *ap) { if (ap->PredFlags & LogUpdatePredFlag) { LogUpdClause *c = ClauseCodeToLogUpdClause(cl); COUNT i = 0; - + while (c != NULL) { i++; c = c->ClNext; @@ -3389,7 +3352,7 @@ count_clauses_left(yamop *cl, PredEntry *ap) MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); UInt ncls = mcl->ClPred->cs.p_code.NOfClauses; - return (ncls-1)-((char *)cl-(char *)mcl->ClCode)/mcl->ClItemSize; + return (ncls - 1) - ((char *)cl - (char *)mcl->ClCode) / mcl->ClItemSize; } else { yamop *last = ap->cs.p_code.LastClause; StaticClause *c; @@ -3408,47 +3371,43 @@ count_clauses_left(yamop *cl, PredEntry *ap) We have jumped across indexing code. Check if we jumped within the current indexing block, if we moved back to a parent, or if we jumped to a child. */ -static ClausePointer -index_jmp(ClausePointer cur, ClausePointer parent, yamop *ipc, int is_lu, yamop *e_code) -{ - if (cur.lui == NULL || - ipc == FAILCODE || - ipc == e_code || - ipc->opc == Yap_opcode(_expand_clauses) - ) +static ClausePointer index_jmp(ClausePointer cur, ClausePointer parent, + yamop *ipc, int is_lu, yamop *e_code) { + if (cur.lui == NULL || ipc == FAILCODE || ipc == e_code || + ipc->opc == Yap_opcode(_expand_clauses)) return cur; if (is_lu) { LogUpdIndex *lcur = cur.lui, *ncur; /* check myself */ - if (ipc >= lcur->ClCode && ipc < (yamop *)((CODEADDR)lcur+lcur->ClSize)) + if (ipc >= lcur->ClCode && ipc < (yamop *)((CODEADDR)lcur + lcur->ClSize)) return cur; - /* check if I am returning back to a parent, eg + /* check if I am returning back to a parent, eg switch with intermediate node */ if (lcur->ParentIndex) { LogUpdIndex *pcur = lcur->ParentIndex; - if (ipc >= pcur->ClCode && ipc < (yamop *)((CODEADDR)pcur+pcur->ClSize)) { - cur.lui = pcur; - return cur; + if (ipc >= pcur->ClCode && + ipc < (yamop *)((CODEADDR)pcur + pcur->ClSize)) { + cur.lui = pcur; + return cur; } } /* maybe I am a new group */ ncur = ClauseCodeToLogUpdIndex(ipc); if (ncur->ParentIndex != lcur) { #if DEBUG - fprintf(stderr,"OOPS, bad parent in lu index\n"); + fprintf(stderr, "OOPS, bad parent in lu index\n"); #endif cur.lui = NULL; return cur; } cur.lui = ncur; - return cur; + return cur; } else { StaticIndex *scur = parent.si, *ncur; /* check myself */ if (!scur) return cur; - if (ipc >= scur->ClCode && - ipc < (yamop *)((CODEADDR)scur+scur->ClSize)) + if (ipc >= scur->ClCode && ipc < (yamop *)((CODEADDR)scur + scur->ClSize)) return cur; ncur = ClauseCodeToStaticIndex(ipc); if (ncur->ClPred == scur->ClPred) { @@ -3458,9 +3417,9 @@ index_jmp(ClausePointer cur, ClausePointer parent, yamop *ipc, int is_lu, yamop /* if (parent.si != cur.si) { if (parent.si) { - StaticIndex *pcur = parent.si; - if (ipc >= pcur->ClCode && ipc < (yamop *)((CODEADDR)pcur+pcur->ClSize)) - return parent; + StaticIndex *pcur = parent.si; + if (ipc >= pcur->ClCode && ipc < (yamop *)((CODEADDR)pcur+pcur->ClSize)) + return parent; } } cur.si = ncur; @@ -3471,42 +3430,35 @@ index_jmp(ClausePointer cur, ClausePointer parent, yamop *ipc, int is_lu, yamop } } -static ClausePointer -code_to_indexcl(yamop *ipc, int is_lu) -{ +static ClausePointer code_to_indexcl(yamop *ipc, int is_lu) { ClausePointer ret; if (is_lu) ret.lui = ClauseCodeToLogUpdIndex(ipc); else ret.si = ClauseCodeToStaticIndex(ipc); - return ret; + return ret; } /* CALLED by expand when entering sub_arg */ -static void -increase_expand_depth(yamop *ipc, struct intermediates *cint) -{ +static void increase_expand_depth(yamop *ipc, struct intermediates *cint) { yamop *ncode; cint->term_depth++; - if (ipc->opc == Yap_opcode(_switch_on_sub_arg_type) && + if (ipc->opc == Yap_opcode(_switch_on_sub_arg_type) && (ncode = ipc->y_u.sllll.l4)->opc == Yap_opcode(_expand_clauses)) { if (ncode->y_u.sssllp.s2 != cint->last_depth_size) { cint->last_index_new_depth = cint->term_depth; - cint->last_depth_size = ncode->y_u.sssllp.s2; + cint->last_depth_size = ncode->y_u.sssllp.s2; } } } -static void -zero_expand_depth(PredEntry *ap, struct intermediates *cint) -{ +static void zero_expand_depth(PredEntry *ap, struct intermediates *cint) { cint->term_depth = cint->last_index_new_depth; - cint->last_depth_size = ap->cs.p_code.NOfClauses; + cint->last_depth_size = ap->cs.p_code.NOfClauses; } -static yamop ** -expand_index(struct intermediates *cint) { +static yamop **expand_index(struct intermediates *cint) { CACHE_REGS /* first clause */ PredEntry *ap = cint->CurrentPred; @@ -3524,7 +3476,7 @@ expand_index(struct intermediates *cint) { int argno = 1; int isfirstcl = TRUE; /* this is will be used as a new PC */ - CELL *top = (CELL *) TR; + CELL *top = (CELL *)TR; UInt arity = 0; UInt lab, fail_l, clleft, i = 0; int is_lu = ap->PredFlags & LogUpdatePredFlag; @@ -3539,34 +3491,35 @@ expand_index(struct intermediates *cint) { /* try to refine the interval using the indexing code */ cint->term_depth = cint->last_index_new_depth = cint->last_depth_size = 0L; - parentcl = code_to_indexcl(ipc,is_lu); + parentcl = code_to_indexcl(ipc, is_lu); while (ipc != NULL) { op_numbers op; op = Yap_op_from_opcode(ipc->opc); - switch(op) { + switch (op) { case _try_clause: case _retry: /* this clause had no indexing */ if (ap->PredFlags & LogUpdatePredFlag) { - first = ClauseCodeToLogUpdClause(ipc->y_u.Otapl.d)->ClNext->ClCode; + first = ClauseCodeToLogUpdClause(ipc->y_u.Otapl.d)->ClNext->ClCode; } else if (ap->PredFlags & MegaClausePredFlag) { - MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); - first = (yamop *)((char *)ipc->y_u.Otapl.d)+mcl->ClItemSize; + MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); + first = (yamop *)((char *)ipc->y_u.Otapl.d) + mcl->ClItemSize; } else { - first = ClauseCodeToStaticClause(ipc->y_u.Otapl.d)->ClNext->ClCode; + first = ClauseCodeToStaticClause(ipc->y_u.Otapl.d)->ClNext->ClCode; } isfirstcl = FALSE; - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; #if TABLING case _table_try: case _table_retry: /* this clause had no indexing */ - first = ClauseCodeToStaticClause(PREVOP(ipc->y_u.Otapl.d,Otapl))->ClNext->ClCode; + first = ClauseCodeToStaticClause(PREVOP(ipc->y_u.Otapl.d, Otapl)) + ->ClNext->ClCode; isfirstcl = FALSE; - ipc = NEXTOP(ipc,Otapl); - break; + ipc = NEXTOP(ipc, Otapl); + break; #endif /* TABLING */ case _try_clause2: case _try_clause3: @@ -3576,15 +3529,15 @@ expand_index(struct intermediates *cint) { case _retry4: case _try_in: if (ap->PredFlags & LogUpdatePredFlag) { - first = ClauseCodeToLogUpdClause(ipc->y_u.l.l)->ClNext->ClCode; + first = ClauseCodeToLogUpdClause(ipc->y_u.l.l)->ClNext->ClCode; } else if (ap->PredFlags & MegaClausePredFlag) { - MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); - first = (yamop *)((char *)ipc->y_u.Otapl.d)+mcl->ClItemSize; + MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); + first = (yamop *)((char *)ipc->y_u.Otapl.d) + mcl->ClItemSize; } else { - first = ClauseCodeToStaticClause(ipc->y_u.l.l)->ClNext->ClCode; + first = ClauseCodeToStaticClause(ipc->y_u.l.l)->ClNext->ClCode; } isfirstcl = FALSE; - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); break; case _retry_me: #ifdef TABLING @@ -3596,10 +3549,10 @@ expand_index(struct intermediates *cint) { case _table_try_me: #endif /* ok, we found the start for an indexing block, - but we don't if we are going to operate here or not */ + but we don't if we are going to operate here or not */ /* if we are to commit here, alt will tell us where */ alt = ipc->y_u.Otapl.d; - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); /* start of a group, reset stack */ sp = stack; stack[0].pos = 0; @@ -3611,7 +3564,7 @@ expand_index(struct intermediates *cint) { case _table_trust_me: #endif /* TABLING */ /* we will commit to this group for sure */ - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); alt = NULL; /* start of a group, reset stack */ sp = stack; @@ -3620,10 +3573,10 @@ expand_index(struct intermediates *cint) { case _trust: /* we should never be here */ Yap_Error(SYSTEM_ERROR_COMPILER, TermNil, "found trust in expand_index"); - labp = NULL; + labp = NULL; ipc = NULL; break; - /* should we ever be here ? I think not */ + /* should we ever be here ? I think not */ case _try_logical: case _retry_logical: case _count_retry_logical: @@ -3642,7 +3595,7 @@ expand_index(struct intermediates *cint) { case _retry_profiled: case _count_retry: /* no useful info */ - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); break; case _jump: /* just skip for now, but should worry about memory management */ @@ -3652,18 +3605,18 @@ expand_index(struct intermediates *cint) { break; case _lock_lu: case _procceed: - ipc = NEXTOP(ipc,p); + ipc = NEXTOP(ipc, p); break; case _unlock_lu: - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _jump_if_var: if (IsVarTerm(Deref(ARG1))) { - labp = &(ipc->y_u.l.l); - ipc = ipc->y_u.l.l; - parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); + labp = &(ipc->y_u.l.l); + ipc = ipc->y_u.l.l; + parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); } else { - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); } break; case _jump_if_nonvar: @@ -3672,61 +3625,74 @@ expand_index(struct intermediates *cint) { i = 0; /* expand_index expects to find the new argument */ if (!IsVarTerm(t)) { - argno--; - labp = &(ipc->y_u.xll.l1); - ipc = ipc->y_u.xll.l1; - parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); + argno--; + labp = &(ipc->y_u.xll.l1); + ipc = ipc->y_u.xll.l1; + parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); } else { - ipc = NEXTOP(ipc,xll); + ipc = NEXTOP(ipc, xll); } break; - /* instructions type EC */ - /* instructions type e */ + /* instructions type EC */ + /* instructions type e */ case _index_dbref: - t = AbsAppl(s_reg-1); + if (s_reg[-1] != (CELL)FunctorDBREF) { + ipc = alt; + alt = NULL; + } + t = AbsAppl(s_reg - 1); sp[-1].extra = t; s_reg = NULL; - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _index_blob: + if (s_reg[-1] != (CELL)FunctorBigInt) { + ipc = alt; + alt = NULL; + } t = Yap_DoubleP_key(s_reg); - sp[-1].extra = AbsAppl(s_reg-1); + sp[-1].extra = AbsAppl(s_reg - 1); s_reg = NULL; - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _index_long: + if (s_reg[-1] != (CELL)FunctorLongInt) { + ipc = alt; + alt = NULL; + } t = Yap_IntP_key(s_reg); - sp[-1].extra = AbsAppl(s_reg-1); + sp[-1].extra = AbsAppl(s_reg - 1); s_reg = NULL; - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _user_switch: labp = &(ipc->y_u.lp.l); ipc = ipc->y_u.lp.l; break; - /* instructions type e */ + /* instructions type e */ case _switch_on_type: zero_expand_depth(ap, cint); t = Deref(ARG1); argno = 1; i = 0; if (IsVarTerm(t)) { - labp = &(ipc->y_u.llll.l4); - ipc = ipc->y_u.llll.l4; + labp = &(ipc->y_u.llll.l4); + ipc = ipc->y_u.llll.l4; } else if (IsPairTerm(t)) { - sp = push_stack(sp, 1, AbsPair(NULL), TermNil, cint); - s_reg = RepPair(t); - labp = &(ipc->y_u.llll.l1); - ipc = ipc->y_u.llll.l1; - increase_expand_depth(ipc, cint); + sp = push_stack(sp, 1, AbsPair(NULL), TermNil, cint); + s_reg = RepPair(t); + labp = &(ipc->y_u.llll.l1); + ipc = ipc->y_u.llll.l1; + increase_expand_depth(ipc, cint); } else if (IsApplTerm(t)) { - sp = push_stack(sp, 1, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, cint); - ipc = ipc->y_u.llll.l3; - increase_expand_depth(ipc, cint); + sp = + push_stack(sp, 1, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, cint); + ipc = ipc->y_u.llll.l3; + increase_expand_depth(ipc, cint); } else { - sp = push_stack(sp, argno, t, TermNil, cint); - ipc = ipc->y_u.llll.l2; + sp = push_stack(sp, argno, t, TermNil, cint); + ipc = ipc->y_u.llll.l2; } parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); break; @@ -3735,29 +3701,29 @@ expand_index(struct intermediates *cint) { t = Deref(ARG1); argno = 1; i = 0; - if (IsVarTerm(t)) { - labp = &(ipc->y_u.ollll.l4); - ipc = ipc->y_u.ollll.l4; + if (IsVarTerm(t)) { + labp = &(ipc->y_u.ollll.l4); + ipc = ipc->y_u.ollll.l4; } else if (IsPairTerm(t)) { - s_reg = RepPair(t); - labp = &(ipc->y_u.ollll.l1); - sp = push_stack(sp, 1, AbsPair(NULL), TermNil, cint); - ipc = ipc->y_u.ollll.l1; - increase_expand_depth(ipc, cint); + s_reg = RepPair(t); + labp = &(ipc->y_u.ollll.l1); + sp = push_stack(sp, 1, AbsPair(NULL), TermNil, cint); + ipc = ipc->y_u.ollll.l1; + increase_expand_depth(ipc, cint); } else if (t == TermNil) { - sp = push_stack(sp, 1, t, TermNil, cint); - ipc = ipc->y_u.ollll.l2; - increase_expand_depth(ipc, cint); + sp = push_stack(sp, 1, t, TermNil, cint); + ipc = ipc->y_u.ollll.l2; + increase_expand_depth(ipc, cint); } else { - Term tn; + Term tn; - if (IsApplTerm(t)) { - tn = AbsAppl((CELL *)FunctorOfTerm(t)); - } else { - tn = t; - } - sp = push_stack(sp, argno, tn, TermNil, cint); - ipc = ipc->y_u.ollll.l3; + if (IsApplTerm(t)) { + tn = AbsAppl((CELL *)FunctorOfTerm(t)); + } else { + tn = t; + } + sp = push_stack(sp, argno, tn, TermNil, cint); + ipc = ipc->y_u.ollll.l3; } parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); break; @@ -3767,52 +3733,55 @@ expand_index(struct intermediates *cint) { i = 0; t = Deref(XREGS[argno]); if (IsVarTerm(t)) { - labp = &(ipc->y_u.xllll.l4); - ipc = ipc->y_u.xllll.l4; + labp = &(ipc->y_u.xllll.l4); + ipc = ipc->y_u.xllll.l4; } else if (IsPairTerm(t)) { - s_reg = RepPair(t); - sp = push_stack(sp, argno, AbsPair(NULL), TermNil, cint); - labp = &(ipc->y_u.xllll.l1); - ipc = ipc->y_u.xllll.l1; - increase_expand_depth(ipc, cint); + s_reg = RepPair(t); + sp = push_stack(sp, argno, AbsPair(NULL), TermNil, cint); + labp = &(ipc->y_u.xllll.l1); + ipc = ipc->y_u.xllll.l1; + increase_expand_depth(ipc, cint); } else if (IsApplTerm(t)) { - sp = push_stack(sp, argno, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, cint); - ipc = ipc->y_u.xllll.l3; - increase_expand_depth(ipc, cint); + sp = push_stack(sp, argno, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, + cint); + ipc = ipc->y_u.xllll.l3; + increase_expand_depth(ipc, cint); } else { - sp = push_stack(sp, argno, t, TermNil, cint); - ipc = ipc->y_u.xllll.l2; + sp = push_stack(sp, argno, t, TermNil, cint); + ipc = ipc->y_u.xllll.l2; } parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); break; case _switch_on_sub_arg_type: i = ipc->y_u.sllll.s; t = Deref(s_reg[i]); - if (i != arity-1) is_last_arg = FALSE; + if (i != arity - 1) + is_last_arg = FALSE; t = Deref(s_reg[i]); if (IsVarTerm(t)) { - labp = &(ipc->y_u.sllll.l4); - ipc = ipc->y_u.sllll.l4; - i++; + labp = &(ipc->y_u.sllll.l4); + ipc = ipc->y_u.sllll.l4; + i++; } else if (IsPairTerm(t)) { - s_reg = RepPair(t); - sp = push_stack(sp, -i-1, AbsPair(NULL), TermNil, cint); - labp = &(ipc->y_u.sllll.l1); - ipc = ipc->y_u.sllll.l1; - i = 0; - increase_expand_depth(ipc, cint); + s_reg = RepPair(t); + sp = push_stack(sp, -i - 1, AbsPair(NULL), TermNil, cint); + labp = &(ipc->y_u.sllll.l1); + ipc = ipc->y_u.sllll.l1; + i = 0; + increase_expand_depth(ipc, cint); } else if (IsApplTerm(t)) { - sp = push_stack(sp, -i-1, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, cint); - ipc = ipc->y_u.sllll.l3; - i = 0; - increase_expand_depth(ipc, cint); + sp = push_stack(sp, -i - 1, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, + cint); + ipc = ipc->y_u.sllll.l3; + i = 0; + increase_expand_depth(ipc, cint); } else { - /* We don't push stack here, instead we go over to next argument - sp = push_stack(sp, -i-1, t, cint); - */ - sp = push_stack(sp, -i-1, t, TermNil, cint); - ipc = ipc->y_u.sllll.l2; - i++; + /* We don't push stack here, instead we go over to next argument + sp = push_stack(sp, -i-1, t, cint); + */ + sp = push_stack(sp, -i - 1, t, TermNil, cint); + ipc = ipc->y_u.sllll.l2; + i++; } parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code); break; @@ -3820,66 +3789,62 @@ expand_index(struct intermediates *cint) { labp = NULL; ipc = NULL; break; - /* instructions type ollll */ + /* instructions type ollll */ case _switch_on_func: case _if_func: - case _go_on_func: - { - FuncSwiEntry *fe; - yamop *newpc; - Functor f; + case _go_on_func: { + FuncSwiEntry *fe; + yamop *newpc; + Functor f; - s_reg = RepAppl(t); - f = (Functor)(*s_reg++); - if (op == _switch_on_func) { - fe = lookup_f_hash(f,ipc->y_u.sssl.l,ipc->y_u.sssl.s); - } else { - fe = lookup_f(f,ipc->y_u.sssl.l,ipc->y_u.sssl.s); - } - newpc = fe->u_f.labp; - - labp = &(fe->u_f.labp); - if (newpc == e_code) { - /* we found it */ - parentcl = code_to_indexcl(ipc->y_u.sssl.l,is_lu); - ipc = NULL; - } else { - ClausePointer npar = code_to_indexcl(ipc->y_u.sssl.l,is_lu); - ipc = newpc; - parentcl = index_jmp(npar, parentcl, ipc, is_lu, e_code); - } + s_reg = RepAppl(t); + f = (Functor)(*s_reg++); + if (op == _switch_on_func) { + fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); + } else { + fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); } - break; + newpc = fe->u_f.labp; + + labp = &(fe->u_f.labp); + if (newpc == e_code) { + /* we found it */ + parentcl = code_to_indexcl(ipc->y_u.sssl.l, is_lu); + ipc = NULL; + } else { + ClausePointer npar = code_to_indexcl(ipc->y_u.sssl.l, is_lu); + ipc = newpc; + parentcl = index_jmp(npar, parentcl, ipc, is_lu, e_code); + } + } break; case _switch_on_cons: case _if_cons: - case _go_on_cons: - { - AtomSwiEntry *ae; + case _go_on_cons: { + AtomSwiEntry *ae; - if (op == _switch_on_cons) { - ae = lookup_c_hash(t,ipc->y_u.sssl.l,ipc->y_u.sssl.s); - } else { - ae = lookup_c(t,ipc->y_u.sssl.l,ipc->y_u.sssl.s); - } - - labp = &(ae->u_a.labp); - if (ae->u_a.labp == e_code) { - /* we found it */ - parentcl = code_to_indexcl(ipc->y_u.sssl.l,is_lu); - ipc = NULL; - } else { - ClausePointer npar = code_to_indexcl(ipc->y_u.sssl.l,is_lu); - ipc = ae->u_a.labp; - parentcl = index_jmp(npar, parentcl, ipc, is_lu, e_code); - } + if (op == _switch_on_cons) { + ae = lookup_c_hash(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s); + } else { + ae = lookup_c(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s); } - break; + + labp = &(ae->u_a.labp); + if (ae->u_a.labp == e_code) { + /* we found it */ + parentcl = code_to_indexcl(ipc->y_u.sssl.l, is_lu); + ipc = NULL; + } else { + ClausePointer npar = code_to_indexcl(ipc->y_u.sssl.l, is_lu); + ipc = ae->u_a.labp; + parentcl = index_jmp(npar, parentcl, ipc, is_lu, e_code); + } + } break; case _expand_index: case _expand_clauses: if (alt != NULL && ap->PredFlags & LogUpdatePredFlag) { - op_numbers fop = Yap_op_from_opcode(alt->opc); - if (fop == _enter_lu_pred) - alt = alt->y_u.Illss.l1; + op_numbers fop = Yap_op_from_opcode(alt->opc); + if (fop == _enter_lu_pred) + alt = alt->y_u.Illss.l1; } ipc = NULL; break; @@ -3889,14 +3854,15 @@ expand_index(struct intermediates *cint) { break; default: if (alt == NULL) { - Yap_Error(SYSTEM_ERROR_COMPILER,t,"unexpected instruction %d at expand_index ", op); - labp = NULL; - ipc = NULL; + Yap_Error(SYSTEM_ERROR_COMPILER, t, + "unexpected instruction %d at expand_index ", op); + labp = NULL; + ipc = NULL; } else { - /* backtrack */ - first = alt->y_u.Otapl.d; - ipc = alt; - alt = NULL; + /* backtrack */ + first = alt->y_u.Otapl.d; + ipc = alt; + alt = NULL; } } } @@ -3911,7 +3877,7 @@ expand_index(struct intermediates *cint) { if (s_reg != NULL) S = s_reg; #ifdef TABLING - /* handle tabling hack that insertes a failcode, + /* handle tabling hack that insertes a failcode, this really corresponds to not having any more clauses */ if (alt == TRUSTFAILCODE) alt = NULL; @@ -3925,25 +3891,25 @@ expand_index(struct intermediates *cint) { if (ap->PredFlags & LogUpdatePredFlag) { op_numbers op = Yap_op_from_opcode(alt->opc); /* can we be here */ - if (op >= _retry2 && op <= _retry4) { - last = alt->y_u.l.l; + if (op >= _retry2 && op <= _retry4) { + last = alt->y_u.l.l; } else { - last = alt->y_u.Otapl.d; + last = alt->y_u.Otapl.d; } } else { op_numbers op = Yap_op_from_opcode(alt->opc); if (op == _retry || op == _trust) { - last = alt->y_u.Otapl.d; + last = alt->y_u.Otapl.d; #ifdef TABLING } else if (op == _table_retry || op == _table_trust) { - last = PREVOP(alt->y_u.Otapl.d,Otapl); + last = PREVOP(alt->y_u.Otapl.d, Otapl); #endif /* TABLING */ } else if (op >= _retry2 && op <= _retry4) { - last = alt->y_u.l.l; + last = alt->y_u.l.l; } } fail_l = (UInt)alt; - clleft = count_clauses_left(last,ap); + clleft = count_clauses_left(last, ap); } if (Yap_op_from_opcode((*labp)->opc) == _expand_clauses) { @@ -3951,55 +3917,56 @@ expand_index(struct intermediates *cint) { yamop *ipc = *labp; /* check all slots, not just the ones with values */ COUNT nclauses = ipc->y_u.sssllp.s1; - yamop **clp = (yamop **)NEXTOP(ipc,sssllp); + yamop **clp = (yamop **)NEXTOP(ipc, sssllp); cint->expand_block = ipc; #if USE_SYSTEM_MALLOC if (!cint->cls) { - cint->cls = (ClauseDef *)Yap_AllocCodeSpace(nclauses*sizeof(ClauseDef)); + cint->cls = (ClauseDef *)Yap_AllocCodeSpace(nclauses * sizeof(ClauseDef)); if (!cint->cls) { - /* tell how much space we need */ - LOCAL_Error_Size += NClauses*sizeof(ClauseDef); - /* grow stack */ - save_machine_regs(); - siglongjmp(cint->CompilerBotch,2); + /* tell how much space we need */ + LOCAL_Error_Size += NClauses * sizeof(ClauseDef); + /* grow stack */ + save_machine_regs(); + siglongjmp(cint->CompilerBotch, 2); } } #else cint->cls = (ClauseDef *)HR; - if (cint->cls+2*nclauses > (ClauseDef *)(ASP-4096)) { + if (cint->cls + 2 * nclauses > (ClauseDef *)(ASP - 4096)) { /* tell how much space we need (worst case) */ - LOCAL_Error_Size += 2*NClauses*sizeof(ClauseDef); + LOCAL_Error_Size += 2 * NClauses * sizeof(ClauseDef); /* grow stack */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,3); + siglongjmp(cint->CompilerBotch, 3); } #endif if (ap->PredFlags & LogUpdatePredFlag) { - max = install_log_upd_clauseseq(cint->cls, ap, stack, clp, clp+nclauses); + max = + install_log_upd_clauseseq(cint->cls, ap, stack, clp, clp + nclauses); } else { - max = install_clauseseq(cint->cls, ap, stack, clp, clp+nclauses); - } + max = install_clauseseq(cint->cls, ap, stack, clp, clp + nclauses); + } } else { cint->expand_block = NULL; #if USE_SYSTEM_MALLOC if (!cint->cls) { - cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef)); + cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses * sizeof(ClauseDef)); if (!cint->cls) { - /* tell how much space we need */ - LOCAL_Error_Size += NClauses*sizeof(ClauseDef); - /* grow stack */ - save_machine_regs(); - siglongjmp(cint->CompilerBotch,2); + /* tell how much space we need */ + LOCAL_Error_Size += NClauses * sizeof(ClauseDef); + /* grow stack */ + save_machine_regs(); + siglongjmp(cint->CompilerBotch, 2); } } #else cint->cls = (ClauseDef *)HR; - if (cint->cls+2*NClauses > (ClauseDef *)(ASP-4096)) { + if (cint->cls + 2 * NClauses > (ClauseDef *)(ASP - 4096)) { /* tell how much space we need (worst case) */ - LOCAL_Error_Size += 2*NClauses*sizeof(ClauseDef); + LOCAL_Error_Size += 2 * NClauses * sizeof(ClauseDef); save_machine_regs(); - siglongjmp(cint->CompilerBotch,3); + siglongjmp(cint->CompilerBotch, 3); } #endif if (ap->PredFlags & LogUpdatePredFlag) { @@ -4009,75 +3976,84 @@ expand_index(struct intermediates *cint) { } #if DEBUG_EXPAND if (ap->PredFlags & LogUpdatePredFlag) { - fprintf(stderr,"vsc +"); + fprintf(stderr, "vsc +"); } else { - fprintf(stderr,"vsc "); + fprintf(stderr, "vsc "); } - fprintf(stderr," : expanding %d out of %d\n", (max-cls)+1,NClauses); + fprintf(stderr, " : expanding %d out of %d\n", (max - cls) + 1, NClauses); #endif } /* don't count last clause if you don't have to */ - if (alt && max->Code == last) max--; + if (alt && max->Code == last) + max--; if (max < cint->cls && labp != NULL) { - *labp = FAILCODE; + *labp = FAILCODE; return labp; } #if USE_SYSTEM_MALLOC cint->freep = (char *)HR; #else - cint->freep = (char *)(max+1); + cint->freep = (char *)(max + 1); #endif cint->CodeStart = cint->BlobsStart = cint->cpc = cint->icpc = NULL; - - if (!IsVarTerm(sp[-1].val) && sp > stack) { + + if (!IsVarTerm(sp[-1].val) && sp > stack) { if (IsAtomOrIntTerm(sp[-1].val)) { if (s_reg == NULL) { /* we have not yet looked into terms */ - lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); + lab = do_index(cint->cls, max, cint, argno + 1, fail_l, isfirstcl, + clleft, top); } else { - UInt arity = 0; + UInt arity = 0; - if (ap->PredFlags & LogUpdatePredFlag) { - reinstall_log_upd_clauses(cint->cls, max, ap, stack); - } else { - reinstall_clauses(cint->cls, max, ap, stack); - } - sp--; - while (sp > stack) { - Term t = sp[-1].val; - if (IsApplTerm(t)) { - Functor f = (Functor)RepAppl(t); - if (!IsExtensionFunctor(f)) { - arity = ArityOfFunctor(f); - break; - } else { - sp--; - } - } else if (IsPairTerm(t)) { - arity = 2; - break; - } else { - sp--; - } - } - lab = do_compound_index(cint->cls, max, s_reg, cint, i, arity, argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); + if (ap->PredFlags & LogUpdatePredFlag) { + reinstall_log_upd_clauses(cint->cls, max, ap, stack); + } else { + reinstall_clauses(cint->cls, max, ap, stack); + } + sp--; + while (sp > stack) { + Term t = sp[-1].val; + if (IsApplTerm(t)) { + Functor f = (Functor)RepAppl(t); + if (!IsExtensionFunctor(f)) { + arity = ArityOfFunctor(f); + break; + } else { + sp--; + } + } else if (IsPairTerm(t)) { + arity = 2; + break; + } else { + sp--; + } + } + lab = do_compound_index(cint->cls, max, s_reg, cint, i, arity, argno, + fail_l, isfirstcl, is_last_arg, clleft, top, + FALSE); } } else if (IsPairTerm(sp[-1].val) && sp > stack) { - lab = do_compound_index(cint->cls, max, s_reg, cint, i, 2, argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); + lab = do_compound_index(cint->cls, max, s_reg, cint, i, 2, argno, fail_l, + isfirstcl, is_last_arg, clleft, top, FALSE); } else { Functor f = (Functor)RepAppl(sp[-1].val); /* we are continuing within a compound term */ if (IsExtensionFunctor(f)) { - lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); + lab = do_index(cint->cls, max, cint, argno + 1, fail_l, isfirstcl, + clleft, top); } else { - lab = do_compound_index(cint->cls, max, s_reg, cint, i, ArityOfFunctor(f), argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); + lab = do_compound_index(cint->cls, max, s_reg, cint, i, + ArityOfFunctor(f), argno, fail_l, isfirstcl, + is_last_arg, clleft, top, FALSE); } } } else { if (argno == ap->ArityOfPE) { - lab = - do_var_clauses(cint->cls, max, FALSE, cint, isfirstcl, clleft, fail_l, ap->ArityOfPE+1); + lab = do_var_clauses(cint->cls, max, FALSE, cint, isfirstcl, clleft, + fail_l, ap->ArityOfPE + 1); } else { - lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); + lab = do_index(cint->cls, max, cint, argno + 1, fail_l, isfirstcl, clleft, + top); } } if (labp && !(lab & 1)) { @@ -4086,9 +4062,8 @@ expand_index(struct intermediates *cint) { return labp; } - -static yamop * -ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { +static yamop *ExpandIndex(PredEntry *ap, int ExtraArgs, + yamop *nextop USES_REGS) { yamop *indx_out, *expand_clauses; yamop **labp; int cb; @@ -4103,30 +4078,34 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { restore_machine_regs(); /* grow stack */ recover_from_failed_susp_on_cls(&cint, 0); - Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE+ExtraArgs, ENV, nextop); + Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE + ExtraArgs, ENV, nextop); } else if (cb == 2) { restore_machine_regs(); LOCAL_Error_Size = recover_from_failed_susp_on_cls(&cint, LOCAL_Error_Size); if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { save_machine_regs(); if (ap->PredFlags & LogUpdatePredFlag) { - Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),NULL, ap); + Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex( + ap->cs.p_code.TrueCodeOfPred), + NULL, ap); } else { - StaticIndex *cl; + StaticIndex *cl; - cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); - Yap_kill_iblock((ClauseUnion *)cl,NULL, ap); + cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); + Yap_kill_iblock((ClauseUnion *)cl, NULL, ap); } #if defined(YAPOR) || defined(THREADS) if (ap->PredFlags & LogUpdatePredFlag && - !(ap->PredFlags & ThreadLocalPredFlag) && - ap->ModuleOfPred != IDB_MODULE) { - ap->OpcodeOfPred = LOCKPRED_OPCODE; - ap->cs.p_code.TrueCodeOfPred = ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); + !(ap->PredFlags & ThreadLocalPredFlag) && + ap->ModuleOfPred != IDB_MODULE) { + ap->OpcodeOfPred = LOCKPRED_OPCODE; + ap->cs.p_code.TrueCodeOfPred = ap->CodeOfPred = + (yamop *)(&(ap->OpcodeOfPred)); } else { #endif - ap->OpcodeOfPred = INDEX_OPCODE; - ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); + ap->OpcodeOfPred = INDEX_OPCODE; + ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = + (yamop *)(&(ap->OpcodeOfPred)); #if defined(YAPOR) || defined(THREADS) } #endif @@ -4140,18 +4119,20 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { if (!Yap_growtrail(LOCAL_Error_Size, FALSE)) { save_machine_regs(); if (ap->PredFlags & LogUpdatePredFlag) { - Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),NULL, ap); + Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex( + ap->cs.p_code.TrueCodeOfPred), + NULL, ap); } else { - StaticIndex *cl; + StaticIndex *cl; - cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); - Yap_kill_iblock((ClauseUnion *)cl, NULL, ap); + cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); + Yap_kill_iblock((ClauseUnion *)cl, NULL, ap); } CleanCls(&cint); return FAILCODE; } } - restart_index: +restart_index: cint.CodeStart = cint.cpc = cint.BlobsStart = cint.icpc = NIL; cint.CurrentPred = ap; LOCAL_ErrorMessage = NULL; @@ -4163,8 +4144,8 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { } #if DEBUG if (GLOBAL_Option['i' - 'a' + 1]) { - Yap_DebugWriteIndicator( ap ); - } + Yap_DebugWriteIndicator(ap); + } #endif if ((labp = expand_index(&cint)) == NULL) { if (expand_clauses) { @@ -4192,12 +4173,13 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { /* globals for assembler */ LOCAL_IPredArity = ap->ArityOfPE; if (cint.CodeStart) { - if ((indx_out = Yap_assemble(ASSEMBLING_EINDEX, TermNil, ap, FALSE, &cint, cint.i_labelno+1)) == NULL) { + if ((indx_out = Yap_assemble(ASSEMBLING_EINDEX, TermNil, ap, FALSE, &cint, + cint.i_labelno + 1)) == NULL) { if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { - Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage); - Yap_ReleaseCMem(&cint); - CleanCls(&cint); - return FAILCODE; + Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage); + Yap_ReleaseCMem(&cint); + CleanCls(&cint); + return FAILCODE; } goto restart_index; } @@ -4226,10 +4208,10 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { if (ap->PredFlags & LogUpdatePredFlag) { /* add to head of current code children */ LogUpdIndex *ic = cint.current_cl.lui, - *nic = ClauseCodeToLogUpdIndex(indx_out); + *nic = ClauseCodeToLogUpdIndex(indx_out); if (ic == NULL) ic = (LogUpdIndex *)Yap_find_owner_index((yamop *)labp, ap); - /* insert myself in the indexing code chain */ + /* insert myself in the indexing code chain */ nic->SiblingIndex = ic->ChildIndex; nic->PrevSiblingIndex = NULL; if (ic->ChildIndex) { @@ -4242,10 +4224,10 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { } else { /* add to head of current code children */ StaticIndex *ic = cint.current_cl.si, - *nic = ClauseCodeToStaticIndex(indx_out); + *nic = ClauseCodeToStaticIndex(indx_out); if (ic == NULL) ic = (StaticIndex *)Yap_find_owner_index((yamop *)labp, ap); - /* insert myself in the indexing code chain */ + /* insert myself in the indexing code chain */ nic->SiblingIndex = ic->ChildIndex; ic->ChildIndex = nic; } @@ -4256,19 +4238,17 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop USES_REGS) { return indx_out; } -yamop * -Yap_ExpandIndex(PredEntry *ap, UInt nargs) { +yamop *Yap_ExpandIndex(PredEntry *ap, UInt nargs) { CACHE_REGS return ExpandIndex(ap, nargs, CP PASS_REGS); } -static path_stack_entry * -push_path(path_stack_entry *sp, yamop **pipc, ClauseDef *clp, struct intermediates *cint) -{ +static path_stack_entry *push_path(path_stack_entry *sp, yamop **pipc, + ClauseDef *clp, struct intermediates *cint) { CACHE_REGS - if (sp+1 > (path_stack_entry *)LOCAL_TrailTop) { + if (sp + 1 > (path_stack_entry *)LOCAL_TrailTop) { save_machine_regs(); - siglongjmp(cint->CompilerBotch,4); + siglongjmp(cint->CompilerBotch, 4); } sp->flag = pc_entry; sp->uip.pce.pi_pc = pipc; @@ -4276,16 +4256,16 @@ push_path(path_stack_entry *sp, yamop **pipc, ClauseDef *clp, struct intermediat sp->uip.pce.current_code = clp->CurrentCode; sp->uip.pce.work_pc = clp->ucd.WorkPC; sp->uip.pce.tag = clp->Tag; - return sp+1; + return sp + 1; } - -static path_stack_entry * -fetch_new_block(path_stack_entry *sp, yamop **pipc, PredEntry *ap, struct intermediates *cint) -{ + +static path_stack_entry *fetch_new_block(path_stack_entry *sp, yamop **pipc, + PredEntry *ap, + struct intermediates *cint) { CACHE_REGS - if (sp+1 > (path_stack_entry *)LOCAL_TrailTop) { + if (sp + 1 > (path_stack_entry *)LOCAL_TrailTop) { save_machine_regs(); - siglongjmp(cint->CompilerBotch,4); + siglongjmp(cint->CompilerBotch, 4); } /* add current position */ sp->flag = block_entry; @@ -4295,14 +4275,13 @@ fetch_new_block(path_stack_entry *sp, yamop **pipc, PredEntry *ap, struct interm } else { sp->uip.cle.block = (ClauseUnion *)ClauseCodeToStaticIndex(*pipc); } - return sp+1; + return sp + 1; } - -static path_stack_entry * -init_block_stack(path_stack_entry *sp, yamop *ipc, PredEntry *ap) -{ + +static path_stack_entry *init_block_stack(path_stack_entry *sp, yamop *ipc, + PredEntry *ap) { /* add current position */ - + sp->flag = block_entry; sp->uip.cle.entry_code = NULL; if (ap->PredFlags & LogUpdatePredFlag) { @@ -4310,39 +4289,39 @@ init_block_stack(path_stack_entry *sp, yamop *ipc, PredEntry *ap) } else { sp->uip.cle.block = (ClauseUnion *)ClauseCodeToStaticIndex(ipc); } - return sp+1; + return sp + 1; } -static path_stack_entry * -cross_block(path_stack_entry *sp, yamop **pipc, PredEntry *ap, struct intermediates *cint) -{ +static path_stack_entry *cross_block(path_stack_entry *sp, yamop **pipc, + PredEntry *ap, + struct intermediates *cint) { yamop *ipc = *pipc; path_stack_entry *tsp = sp; ClauseUnion *block; do { UInt bsize; - while ((--tsp)->flag != block_entry); + while ((--tsp)->flag != block_entry) + ; block = tsp->uip.cle.block; if (block->lui.ClFlags & LogUpdMask) bsize = block->lui.ClSize; else bsize = block->si.ClSize; - if (ipc > (yamop *)block && - ipc < (yamop *)((CODEADDR)block + bsize)) { - path_stack_entry *nsp = tsp+1; - for (;tspflag == pc_entry) { - if (nsp != tsp) { - nsp->flag = pc_entry; - nsp->uip.pce.pi_pc = tsp->uip.pce.pi_pc; - nsp->uip.pce.code = tsp->uip.pce.code; - nsp->uip.pce.current_code = tsp->uip.pce.current_code; - nsp->uip.pce.work_pc = tsp->uip.pce.work_pc; - nsp->uip.pce.tag = tsp->uip.pce.tag; - } - nsp++; - } + if (ipc > (yamop *)block && ipc < (yamop *)((CODEADDR)block + bsize)) { + path_stack_entry *nsp = tsp + 1; + for (; tsp < sp; tsp++) { + if (tsp->flag == pc_entry) { + if (nsp != tsp) { + nsp->flag = pc_entry; + nsp->uip.pce.pi_pc = tsp->uip.pce.pi_pc; + nsp->uip.pce.code = tsp->uip.pce.code; + nsp->uip.pce.current_code = tsp->uip.pce.current_code; + nsp->uip.pce.work_pc = tsp->uip.pce.work_pc; + nsp->uip.pce.tag = tsp->uip.pce.tag; + } + nsp++; + } } return nsp; } @@ -4351,14 +4330,13 @@ cross_block(path_stack_entry *sp, yamop **pipc, PredEntry *ap, struct intermedia return fetch_new_block(sp, pipc, ap, cint); } - -static yamop * -pop_path(path_stack_entry **spp, ClauseDef *clp, PredEntry *ap, struct intermediates *cint) -{ +static yamop *pop_path(path_stack_entry **spp, ClauseDef *clp, PredEntry *ap, + struct intermediates *cint) { path_stack_entry *sp = *spp; yamop *nipc; - while ((--sp)->flag != pc_entry); + while ((--sp)->flag != pc_entry) + ; *spp = sp; clp->Code = sp->uip.pce.code; clp->CurrentCode = sp->uip.pce.current_code; @@ -4373,50 +4351,46 @@ pop_path(path_stack_entry **spp, ClauseDef *clp, PredEntry *ap, struct intermedi return nipc; } -static int -table_fe_overflow(yamop *pc, Functor f) -{ +static int table_fe_overflow(yamop *pc, Functor f) { if (pc->y_u.sssl.s <= MIN_HASH_ENTRIES) { /* we cannot expand otherwise */ COUNT i; FuncSwiEntry *csw = (FuncSwiEntry *)pc->y_u.sssl.l; - for (i=0; i < pc->y_u.sssl.s; i++,csw++) { - if (csw->Tag == f) return FALSE; + for (i = 0; i < pc->y_u.sssl.s; i++, csw++) { + if (csw->Tag == f) + return FALSE; } return TRUE; } else { - COUNT free = pc->y_u.sssl.s-pc->y_u.sssl.e; - return (!free || pc->y_u.sssl.s/free > 4); + COUNT free = pc->y_u.sssl.s - pc->y_u.sssl.e; + return (!free || pc->y_u.sssl.s / free > 4); } } -static int -table_ae_overflow(yamop *pc, Term at) -{ +static int table_ae_overflow(yamop *pc, Term at) { if (pc->y_u.sssl.s <= MIN_HASH_ENTRIES) { /* check if we are already there */ COUNT i; AtomSwiEntry *csw = (AtomSwiEntry *)pc->y_u.sssl.l; - for (i=0; i < pc->y_u.sssl.s; i++,csw++) { - if (csw->Tag == at) return FALSE; + for (i = 0; i < pc->y_u.sssl.s; i++, csw++) { + if (csw->Tag == at) + return FALSE; } return TRUE; } else { - COUNT free = pc->y_u.sssl.s-pc->y_u.sssl.e; - return (!free || pc->y_u.sssl.s/free > 4); + COUNT free = pc->y_u.sssl.s - pc->y_u.sssl.e; + return (!free || pc->y_u.sssl.s / free > 4); } } -static void -replace_index_block(ClauseUnion *parent_block, yamop *cod, yamop *ncod, PredEntry *ap) -{ +static void replace_index_block(ClauseUnion *parent_block, yamop *cod, + yamop *ncod, PredEntry *ap) { if (ap->PredFlags & LogUpdatePredFlag) { - LogUpdIndex - *cl = ClauseCodeToLogUpdIndex(cod), - *ncl = ClauseCodeToLogUpdIndex(ncod), - *c = parent_block->lui.ChildIndex; + LogUpdIndex *cl = ClauseCodeToLogUpdIndex(cod), + *ncl = ClauseCodeToLogUpdIndex(ncod), + *c = parent_block->lui.ChildIndex; ncl->SiblingIndex = cl->SiblingIndex; ncl->PrevSiblingIndex = cl->PrevSiblingIndex; ncl->ClRefCount = cl->ClRefCount; @@ -4428,7 +4402,7 @@ replace_index_block(ClauseUnion *parent_block, yamop *cod, yamop *ncod, PredEntr parent_block->lui.ChildIndex = ncl; } else { if (cl->PrevSiblingIndex) - cl->PrevSiblingIndex->SiblingIndex = ncl; + cl->PrevSiblingIndex->SiblingIndex = ncl; } if (cl->SiblingIndex) { cl->SiblingIndex->PrevSiblingIndex = ncl; @@ -4442,17 +4416,16 @@ replace_index_block(ClauseUnion *parent_block, yamop *cod, yamop *ncod, PredEntr Yap_LUIndexSpace_SW -= cl->ClSize; Yap_FreeCodeSpace((char *)cl); } else { - StaticIndex - *cl = ClauseCodeToStaticIndex(cod), - *ncl = ClauseCodeToStaticIndex(ncod), - *c = parent_block->si.ChildIndex; + StaticIndex *cl = ClauseCodeToStaticIndex(cod), + *ncl = ClauseCodeToStaticIndex(ncod), + *c = parent_block->si.ChildIndex; ncl->SiblingIndex = cl->SiblingIndex; ncl->ClPred = cl->ClPred; if (c == cl) { parent_block->si.ChildIndex = ncl; } else { while (c->SiblingIndex != cl) { - c = c->SiblingIndex; + c = c->SiblingIndex; } c->SiblingIndex = ncl; } @@ -4461,10 +4434,9 @@ replace_index_block(ClauseUnion *parent_block, yamop *cod, yamop *ncod, PredEntr Yap_FreeCodeSpace((char *)cl); } } - -static AtomSwiEntry * -expand_ctable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Term at) -{ + +static AtomSwiEntry *expand_ctable(yamop *pc, ClauseUnion *blk, + struct intermediates *cint, Term at) { PredEntry *ap = cint->CurrentPred; int n = pc->y_u.sssl.s, i, i0 = n; UInt fail_l = Zero; @@ -4473,11 +4445,13 @@ expand_ctable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Term at) if (n > MIN_HASH_ENTRIES) { AtomSwiEntry *tmp = old_ae; int i; - + n = 1; - for (i = 0; i < pc->y_u.sssl.s; i++,tmp++) { - if (tmp->Tag != Zero) n++; - else fail_l = tmp->u_a.Label; + for (i = 0; i < pc->y_u.sssl.s; i++, tmp++) { + if (tmp->Tag != Zero) + n++; + else + fail_l = tmp->u_a.Label; } } else { fail_l = old_ae[n].u_a.Label; @@ -4485,27 +4459,30 @@ expand_ctable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Term at) } if (n > MIN_HASH_ENTRIES) { int cases = MIN_HASH_ENTRIES, i, n0; - n0 = n+1+n/4; - while (cases < n0) cases *= 2; + n0 = n + 1 + n / 4; + while (cases < n0) + cases *= 2; if (cases == pc->y_u.sssl.s) { - return fetch_centry(old_ae, at, n-1, n); + return fetch_centry(old_ae, at, n - 1, n); } /* initialize */ - target = (AtomSwiEntry *)emit_switch_space(cases, sizeof(AtomSwiEntry), cint, 0); + target = + (AtomSwiEntry *)emit_switch_space(cases, sizeof(AtomSwiEntry), cint, 0); pc->opc = Yap_opcode(_switch_on_cons); pc->y_u.sssl.s = cases; - for (i=0; iopc = Yap_opcode(_if_cons); pc->y_u.sssl.s = n; - target = (AtomSwiEntry *)emit_switch_space(n+1, sizeof(AtomSwiEntry), cint, 0); + target = + (AtomSwiEntry *)emit_switch_space(n + 1, sizeof(AtomSwiEntry), cint, 0); target[n].Tag = Zero; target[n].u_a.Label = fail_l; } - for (i = 0; i < i0; i++,old_ae++) { + for (i = 0; i < i0; i++, old_ae++) { Term tag = old_ae->Tag; if (tag != Zero) { @@ -4518,25 +4495,26 @@ expand_ctable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Term at) if (blk) replace_index_block(blk, pc->y_u.sssl.l, (yamop *)target, ap); pc->y_u.sssl.l = (yamop *)target; - return fetch_centry(target, at, n-1, n); + return fetch_centry(target, at, n - 1, n); } -static FuncSwiEntry * -expand_ftable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Functor f) -{ +static FuncSwiEntry *expand_ftable(yamop *pc, ClauseUnion *blk, + struct intermediates *cint, Functor f) { PredEntry *ap = cint->CurrentPred; int n = pc->y_u.sssl.s, i, i0 = n; - UInt fail_l = Zero; + UInt fail_l = Zero; FuncSwiEntry *old_fe = (FuncSwiEntry *)(pc->y_u.sssl.l), *target; if (n > MIN_HASH_ENTRIES) { FuncSwiEntry *tmp = old_fe; int i; - + n = 1; - for (i = 0; i < pc->y_u.sssl.s; i++,tmp++) { - if (tmp->Tag != Zero) n++; - else fail_l = tmp->u_f.Label; + for (i = 0; i < pc->y_u.sssl.s; i++, tmp++) { + if (tmp->Tag != Zero) + n++; + else + fail_l = tmp->u_f.Label; } } else { fail_l = old_fe[n].u_f.Label; @@ -4544,19 +4522,21 @@ expand_ftable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Functor f } if (n > MIN_HASH_ENTRIES) { int cases = MIN_HASH_ENTRIES, i, n0; - n0 = n+1+n/4; - while (cases < n0) cases *= 2; + n0 = n + 1 + n / 4; + while (cases < n0) + cases *= 2; if (cases == pc->y_u.sssl.s) { - return fetch_fentry(old_fe, f, n-1, n); + return fetch_fentry(old_fe, f, n - 1, n); } pc->opc = Yap_opcode(_switch_on_func); pc->y_u.sssl.s = cases; pc->y_u.sssl.e = n; pc->y_u.sssl.w = 0; /* initialize */ - target = (FuncSwiEntry *)emit_switch_space(cases, sizeof(FuncSwiEntry), cint, FuncSwitchMask); - for (i=0; iy_u.sssl.s = n; pc->y_u.sssl.e = n; pc->y_u.sssl.w = 0; - target = (FuncSwiEntry *)emit_switch_space(n+1, sizeof(FuncSwiEntry), cint, FuncSwitchMask); + target = (FuncSwiEntry *)emit_switch_space(n + 1, sizeof(FuncSwiEntry), + cint, FuncSwitchMask); target[n].Tag = Zero; target[n].u_f.Label = fail_l; } - for (i = 0; i < i0; i++,old_fe++) { + for (i = 0; i < i0; i++, old_fe++) { Functor f = old_fe->Tag; if (f != NULL) { @@ -4580,57 +4561,48 @@ expand_ftable(yamop *pc, ClauseUnion *blk, struct intermediates *cint, Functor f } replace_index_block(blk, pc->y_u.sssl.l, (yamop *)target, ap); pc->y_u.sssl.l = (yamop *)target; - return fetch_fentry(target, f, n-1, n); + return fetch_fentry(target, f, n - 1, n); } -static void -clean_ref_to_clause(LogUpdClause *tgl) -{ +static void clean_ref_to_clause(LogUpdClause *tgl) { tgl->ClRefCount--; - if ((tgl->ClFlags & ErasedMask) && - !(tgl->ClRefCount) && + if ((tgl->ClFlags & ErasedMask) && !(tgl->ClRefCount) && !(tgl->ClFlags & InUseMask)) { /* last ref to the clause */ Yap_ErLogUpdCl(tgl); } } - -static ClauseUnion * -current_block(path_stack_entry *sp) -{ - while ((--sp)->flag != block_entry); +static ClauseUnion *current_block(path_stack_entry *sp) { + while ((--sp)->flag != block_entry) + ; return sp->uip.cle.block; } -static path_stack_entry * -kill_block(path_stack_entry *sp, PredEntry *ap) -{ - while ((--sp)->flag != block_entry); +static path_stack_entry *kill_block(path_stack_entry *sp, PredEntry *ap) { + while ((--sp)->flag != block_entry) + ; if (sp->uip.cle.entry_code == NULL) { Yap_kill_iblock(sp->uip.cle.block, NULL, ap); } else { path_stack_entry *nsp = sp; - - while ((--nsp)->flag != block_entry); + + while ((--nsp)->flag != block_entry) + ; Yap_kill_iblock(sp->uip.cle.block, nsp->uip.cle.block, ap); *sp->uip.cle.entry_code = (yamop *)&(ap->cs.p_code.ExpandCode); } return sp; } -static LogUpdClause * -find_last_clause(yamop *start) -{ - while (start->y_u.OtaLl.d->ClFlags & ErasedMask) +static LogUpdClause *find_last_clause(yamop *start) { + while (start->y_u.OtaLl.d->ClFlags & ErasedMask) start = start->y_u.OtaLl.n; /* this should be the available clause */ return start->y_u.OtaLl.d; } -static void -remove_clause_from_index(yamop *header, LogUpdClause *cl) -{ +static void remove_clause_from_index(yamop *header, LogUpdClause *cl) { yamop **prevp = &(header->y_u.Illss.l1); yamop *curp = header->y_u.Illss.l1; @@ -4659,17 +4631,15 @@ remove_clause_from_index(yamop *header, LogUpdClause *cl) Yap_FreedCps++; #endif clean_ref_to_clause(cl); - Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop*)NULL,OtILl); + Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop *)NULL, OtILl); Yap_FreeCodeSpace((ADDR)curp); } -static void -remove_dirty_clauses_from_index(yamop *header) -{ +static void remove_dirty_clauses_from_index(yamop *header) { LogUpdClause *cl; yamop *previouscurp; OPCODE endop = Yap_opcode(_trust_logical); - yamop **prevp= &(header->y_u.Illss.l1), *curp = header->y_u.Illss.l1; + yamop **prevp = &(header->y_u.Illss.l1), *curp = header->y_u.Illss.l1; OPCODE startopc = curp->opc; PredEntry *ap = curp->y_u.OtaLl.d->ClPred; @@ -4685,23 +4655,24 @@ remove_dirty_clauses_from_index(yamop *header) Yap_DirtyCps--; Yap_FreedCps++; #endif - //if (ap->ModuleOfPred!=IDB_MODULE && !strcmp(RepAtom(NameOfFunctor(ap->FunctorOfPred))->StrOfAE, "$lgt_send_to_obj_ne_")) - // printf(" L %p %p %d %p\n", curp, curp->y_u.OtaLl.n, header->y_u.Illss.e, curp->opc); + // if (ap->ModuleOfPred!=IDB_MODULE && + // !strcmp(RepAtom(NameOfFunctor(ap->FunctorOfPred))->StrOfAE, + // "$lgt_send_to_obj_ne_")) + // printf(" L %p %p %d %p\n", curp, curp->y_u.OtaLl.n, header->y_u.Illss.e, + // curp->opc); clean_ref_to_clause(cl); curp = curp->y_u.OtaLl.n; - Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop*)NULL,OtaLl); + Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop *)NULL, OtaLl); Yap_FreeCodeSpace((ADDR)ocurp); if (ocurp == header->y_u.Illss.l2) { LogUpdIndex *clau = header->y_u.Illss.I; /* no clauses left */ if (clau->ClFlags & ErasedMask) { - Yap_ErLogUpdIndex(clau); - return; + Yap_ErLogUpdIndex(clau); + return; } - header->y_u.Illss.l1 = - header->y_u.Illss.l2 = NULL; - header->y_u.Illss.s = - header->y_u.Illss.e = 0; + header->y_u.Illss.l1 = header->y_u.Illss.l2 = NULL; + header->y_u.Illss.s = header->y_u.Illss.e = 0; return; } } @@ -4725,40 +4696,40 @@ remove_dirty_clauses_from_index(yamop *header) #endif clean_ref_to_clause(cl); if (curp->opc == endop) { - previouscurp->opc = endop; - previouscurp->y_u.OtILl.block = curp->y_u.OtILl.block; - previouscurp->y_u.OtILl.n = NULL; - header->y_u.Illss.l2 = previouscurp; - Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop*)NULL,OtILl); - Yap_FreeCodeSpace((ADDR)curp); - return; + previouscurp->opc = endop; + previouscurp->y_u.OtILl.block = curp->y_u.OtILl.block; + previouscurp->y_u.OtILl.n = NULL; + header->y_u.Illss.l2 = previouscurp; + Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop *)NULL, OtILl); + Yap_FreeCodeSpace((ADDR)curp); + return; } previouscurp->y_u.OtaLl.n = curp->y_u.OtaLl.n; curp = curp->y_u.OtaLl.n; - Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop*)NULL,OtaLl); + Yap_LUIndexSpace_CP -= (UInt)NEXTOP((yamop *)NULL, OtaLl); Yap_FreeCodeSpace((ADDR)ocurp); if (!header->y_u.Illss.e) - return; + return; } else { previouscurp = curp; if (curp->opc == endop) { - curp->y_u.OtILl.n = NULL; - return; + curp->y_u.OtILl.n = NULL; + return; } curp = curp->y_u.OtaLl.n; } } } -static path_stack_entry * -kill_clause(yamop *ipc, yamop *bg, yamop *lt, path_stack_entry *sp0, PredEntry *ap) -{ +static path_stack_entry *kill_clause(yamop *ipc, yamop *bg, yamop *lt, + path_stack_entry *sp0, PredEntry *ap) { LogUpdIndex *blk; yamop *start; op_numbers op0; path_stack_entry *sp = sp0; - while ((--sp)->flag != block_entry); + while ((--sp)->flag != block_entry) + ; blk = (LogUpdIndex *)(sp->uip.cle.block); start = blk->ClCode; op0 = Yap_op_from_opcode(start->opc); @@ -4772,10 +4743,10 @@ kill_clause(yamop *ipc, yamop *bg, yamop *lt, path_stack_entry *sp0, PredEntry * } if (op0 != _enter_lu_pred) { /* static code */ - return kill_block(sp+1, ap); + return kill_block(sp + 1, ap); } /* weird case ????? */ - if (!start->y_u.Illss.s){ + if (!start->y_u.Illss.s) { /* ERROR */ Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "Illss.s == 0 %p", ipc); return sp; @@ -4783,24 +4754,24 @@ kill_clause(yamop *ipc, yamop *bg, yamop *lt, path_stack_entry *sp0, PredEntry * if (start->y_u.Illss.s == 1) { /* we need to discover which clause is left and then die */ path_stack_entry *nsp; - LogUpdClause *tgl = find_last_clause(start->y_u.Illss.l1); + find_last_clause(start->y_u.Illss.l1); nsp = sp; - while ((--nsp)->flag != block_entry); + while ((--nsp)->flag != block_entry) + ; /* make us point straight at clause */ - *sp->uip.cle.entry_code = tgl->ClCode; + *sp->uip.cle.entry_code = FAILCODE; Yap_kill_iblock(sp->uip.cle.block, nsp->uip.cle.block, ap); return sp; } else { if ( #if MULTIPLE_STACKS - blk->ClRefCount == 0 + blk->ClRefCount == 0 #else - !(blk->ClFlags & InUseMask) + !(blk->ClFlags & InUseMask) #endif -) { - remove_clause_from_index(start, - ClauseCodeToLogUpdClause(bg)); + ) { + remove_clause_from_index(start, ClauseCodeToLogUpdClause(bg)); } else { blk->ClFlags |= DirtyMask; } @@ -4808,25 +4779,25 @@ kill_clause(yamop *ipc, yamop *bg, yamop *lt, path_stack_entry *sp0, PredEntry * } } -static path_stack_entry * -expanda_block(path_stack_entry *sp, PredEntry *ap, ClauseDef *cls, int group1, yamop *alt, struct intermediates *cint) -{ - while ((--sp)->flag != block_entry); +static path_stack_entry *expanda_block(path_stack_entry *sp, PredEntry *ap, + ClauseDef *cls, int group1, yamop *alt, + struct intermediates *cint) { + while ((--sp)->flag != block_entry) + ; Yap_kill_iblock(sp->uip.cle.block, NULL, ap); return sp; } -static path_stack_entry * -expandz_block(path_stack_entry *sp, PredEntry *ap, ClauseDef *cls, int group1, yamop *alt, struct intermediates *cint) -{ - while ((--sp)->flag != block_entry); +static path_stack_entry *expandz_block(path_stack_entry *sp, PredEntry *ap, + ClauseDef *cls, int group1, yamop *alt, + struct intermediates *cint) { + while ((--sp)->flag != block_entry) + ; Yap_kill_iblock(sp->uip.cle.block, NULL, ap); return sp; } -static LogUpdClause * -lu_clause(yamop *ipc, PredEntry *ap) -{ +static LogUpdClause *lu_clause(yamop *ipc, PredEntry *ap) { if (ipc == FAILCODE) return NULL; if (ipc == (yamop *)(&(ap->OpcodeOfPred))) @@ -4834,12 +4805,9 @@ lu_clause(yamop *ipc, PredEntry *ap) return ClauseCodeToLogUpdClause(ipc); } -static StaticClause * -find_static_clause(PredEntry *ap, yamop *ipc) -{ +static StaticClause *find_static_clause(PredEntry *ap, yamop *ipc) { StaticClause *cl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause); - while (ipc < cl->ClCode || - ipc > (yamop *)((char *)cl+ cl->ClSize)) { + while (ipc < cl->ClCode || ipc > (yamop *)((char *)cl + cl->ClSize)) { cl = cl->ClNext; if (!cl) return NULL; @@ -4847,22 +4815,20 @@ find_static_clause(PredEntry *ap, yamop *ipc) return cl; } -static StaticClause * -static_clause(yamop *ipc, PredEntry *ap, int trust) -{ +static StaticClause *static_clause(yamop *ipc, PredEntry *ap, int trust) { CELL *p; if (ipc == FAILCODE) return NULL; - if (ipc == (yamop*)(&(ap->OpcodeOfPred))) + if (ipc == (yamop *)(&(ap->OpcodeOfPred))) return NULL; if (ap->PredFlags & MegaClausePredFlag) return (StaticClause *)ipc; if (ap->PredFlags & TabledPredFlag) - ipc = PREVOP(ipc,Otapl); + ipc = PREVOP(ipc, Otapl); p = (CELL *)ipc; if (trust) { - return ClauseCodeToStaticClause(p); + return ClauseCodeToStaticClause(p); } else { op_numbers op = Yap_op_from_opcode(ipc->opc); UInt j; @@ -4901,10 +4867,8 @@ static_clause(yamop *ipc, PredEntry *ap, int trust) return NULL; } -static StaticClause * -simple_static_clause(yamop *ipc, PredEntry *ap) -{ - if (ipc == (yamop*)(&(ap->OpcodeOfPred))) +static StaticClause *simple_static_clause(yamop *ipc, PredEntry *ap) { + if (ipc == (yamop *)(&(ap->OpcodeOfPred))) return NULL; if (ipc == FAILCODE) return NULL; @@ -4912,11 +4876,12 @@ simple_static_clause(yamop *ipc, PredEntry *ap) } /* this code should be called when we jumped to clauses */ -static path_stack_entry * -kill_unsafe_block(path_stack_entry *sp, op_numbers op, PredEntry *ap, int first, int remove, ClauseDef *cls) -{ +static path_stack_entry *kill_unsafe_block(path_stack_entry *sp, op_numbers op, + PredEntry *ap, int first, int remove, + ClauseDef *cls) { yamop *ipc; - while ((--sp)->flag != block_entry); + while ((--sp)->flag != block_entry) + ; if (sp->uip.cle.entry_code == NULL) { /* we have reached the top */ Yap_RemoveIndexation(ap); @@ -4936,14 +4901,15 @@ kill_unsafe_block(path_stack_entry *sp, op_numbers op, PredEntry *ap, int first, LogUpdClause *lc = lu_clause(ipc, ap); if (first) { - cld[0].Code = cls[0].Code; - cld[1].Code = lc->ClCode; + cld[0].Code = cls[0].Code; + cld[1].Code = lc->ClCode; } else { - cld[0].Code = lc->ClCode; - cld[1].Code = cls[0].Code; + cld[0].Code = lc->ClCode; + cld[1].Code = cls[0].Code; } intrs.expand_block = NULL; - *sp->uip.cle.entry_code = (yamop *)suspend_indexing(cld, cld+1, ap, &intrs); + *sp->uip.cle.entry_code = + (yamop *)suspend_indexing(cld, cld + 1, ap, &intrs); } else { /* static predicate, shouldn't do much, just suspend the code here */ *sp->uip.cle.entry_code = (yamop *)&(ap->cs.p_code.ExpandCode); @@ -4952,22 +4918,21 @@ kill_unsafe_block(path_stack_entry *sp, op_numbers op, PredEntry *ap, int first, return sp; } /* we didn't have protection, should kill now */ - return kill_block(sp+1, ap); + return kill_block(sp + 1, ap); } -static int -compacta_expand_clauses(yamop *ipc) -{ +static int compacta_expand_clauses(yamop *ipc) { /* expand clauses so that you have a hole at the beginning */ /* we know that there is at least one element here */ - yamop **start = (yamop **)(NEXTOP(ipc,sssllp)); + yamop **start = (yamop **)(NEXTOP(ipc, sssllp)); yamop **ptr, **end; - ptr = end = start+ipc->y_u.sssllp.s1; + ptr = end = start + ipc->y_u.sssllp.s1; while (ptr > start) { yamop *next = *--ptr; - if (next) *--end = next; + if (next) + *--end = next; } if (ptr != end) { while (end > start) { @@ -4978,20 +4943,19 @@ compacta_expand_clauses(yamop *ipc) return FALSE; } -static int -compactz_expand_clauses(yamop *ipc) -{ +static int compactz_expand_clauses(yamop *ipc) { /* expand clauses so that you have a hole at the beginning */ /* we know that there is at least one element here */ - yamop **start = (yamop **)(NEXTOP(ipc,sssllp)); + yamop **start = (yamop **)(NEXTOP(ipc, sssllp)); yamop **ptr, **end; - end = start+ipc->y_u.sssllp.s1; + end = start + ipc->y_u.sssllp.s1; ptr = start; while (ptr < end) { yamop *next = *ptr++; - if (next) *start++ = next; + if (next) + *start++ = next; } /* reset empty slots at end */ if (start != end) { @@ -5004,40 +4968,43 @@ compactz_expand_clauses(yamop *ipc) } /* this code should be called when we jumped to clauses */ -static yamop * -add_to_expand_clauses(path_stack_entry **spp, yamop *ipc, ClauseDef *cls, PredEntry *ap, int first, struct intermediates *cint) -{ +static yamop *add_to_expand_clauses(path_stack_entry **spp, yamop *ipc, + ClauseDef *cls, PredEntry *ap, int first, + struct intermediates *cint) { path_stack_entry *sp = *spp; yamop **clar; if (first) { do { - clar = (yamop **)NEXTOP(ipc,sssllp); + clar = (yamop **)NEXTOP(ipc, sssllp); if (*clar == NULL || clar[0] == cls->Code) { - while (*clar == NULL) clar++; - if (clar[0] != cls->Code) { - clar[-1] = cls->Code; - ipc->y_u.sssllp.s2++; - } - return pop_path(spp, cls, ap, cint); + while (*clar == NULL) + clar++; + if (clar[0] != cls->Code) { + clar[-1] = cls->Code; + ipc->y_u.sssllp.s2++; + } + return pop_path(spp, cls, ap, cint); } } while (compacta_expand_clauses(ipc)); } else { do { - clar = (yamop **)NEXTOP(ipc,sssllp) + ipc->y_u.sssllp.s1; - if (clar[-1] == NULL || clar[-1] == cls->Code) { - while (*--clar == NULL); - if (clar[0] != cls->Code) { - clar[1] = cls->Code; - ipc->y_u.sssllp.s2++; - } - return pop_path(spp, cls, ap, cint); + clar = (yamop **)NEXTOP(ipc, sssllp) + ipc->y_u.sssllp.s1; + if (clar[-1] == NULL || clar[-1] == cls->Code) { + while (*--clar == NULL) + ; + if (clar[0] != cls->Code) { + clar[1] = cls->Code; + ipc->y_u.sssllp.s2++; + } + return pop_path(spp, cls, ap, cint); } } while (compactz_expand_clauses(ipc)); } - while ((--sp)->flag != block_entry); + while ((--sp)->flag != block_entry) + ; if (sp->uip.cle.entry_code) { *sp->uip.cle.entry_code = (yamop *)&(ap->cs.p_code.ExpandCode); } @@ -5046,11 +5013,10 @@ add_to_expand_clauses(path_stack_entry **spp, yamop *ipc, ClauseDef *cls, PredEn } /* this code should be called when we jumped to clauses */ -static void -nullify_expand_clause(yamop *ipc, path_stack_entry *sp, ClauseDef *cls) -{ - yamop **st = (yamop **)NEXTOP(ipc,sssllp); - yamop **max = st+ipc->y_u.sssllp.s1; +static void nullify_expand_clause(yamop *ipc, path_stack_entry *sp, + ClauseDef *cls) { + yamop **st = (yamop **)NEXTOP(ipc, sssllp); + yamop **max = st + ipc->y_u.sssllp.s1; /* make sure we get rid of the reference */ while (st < max) { @@ -5063,30 +5029,30 @@ nullify_expand_clause(yamop *ipc, path_stack_entry *sp, ClauseDef *cls) } /* if the block has a single element */ if (ipc->y_u.sssllp.s2 == 1) { - yamop **st = (yamop **)NEXTOP(ipc,sssllp); - while ((--sp)->flag != block_entry); + yamop **st = (yamop **)NEXTOP(ipc, sssllp); + while ((--sp)->flag != block_entry) + ; while (TRUE) { if (*st && *st != cls->Code) { - *sp->uip.cle.entry_code = *st; - recover_ecls_block(ipc); - return; + *sp->uip.cle.entry_code = *st; + recover_ecls_block(ipc); + return; } st++; } } } -static yamop * -add_try(PredEntry *ap, ClauseDef *cls, yamop *next, struct intermediates *cint) -{ +static yamop *add_try(PredEntry *ap, ClauseDef *cls, yamop *next, + struct intermediates *cint) { yamop *newcp; - UInt size = (UInt)NEXTOP((yamop *)NULL,OtaLl); + UInt size = (UInt)NEXTOP((yamop *)NULL, OtaLl); LogUpdClause *lcl = ClauseCodeToLogUpdClause(cls->Code); if ((newcp = (yamop *)Yap_AllocCodeSpace(size)) == NULL) { /* OOOPS, got in trouble, must do a siglongjmp and recover space */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,2); + siglongjmp(cint->CompilerBotch, 2); } Yap_LUIndexSpace_CP += size; #if DEBUG @@ -5101,18 +5067,17 @@ add_try(PredEntry *ap, ClauseDef *cls, yamop *next, struct intermediates *cint) return newcp; } -static yamop * -add_trust(LogUpdIndex *icl, ClauseDef *cls, struct intermediates *cint) -{ +static yamop *add_trust(LogUpdIndex *icl, ClauseDef *cls, + struct intermediates *cint) { yamop *newcp; - UInt size = (UInt)NEXTOP((yamop *)NULL,OtILl); + UInt size = (UInt)NEXTOP((yamop *)NULL, OtILl); LogUpdClause *lcl = ClauseCodeToLogUpdClause(cls->Code); - PredEntry *ap = lcl->ClPred; + PredEntry *ap = lcl->ClPred; if ((newcp = (yamop *)Yap_AllocCodeSpace(size)) == NULL) { /* OOOPS, got in trouble, must do a siglongjmp and recover space */ save_machine_regs(); - siglongjmp(cint->CompilerBotch,2); + siglongjmp(cint->CompilerBotch, 2); } Yap_LUIndexSpace_CP += size; #if DEBUG @@ -5132,8 +5097,8 @@ add_trust(LogUpdIndex *icl, ClauseDef *cls, struct intermediates *cint) return newcp; } -static void -add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, ClauseDef *cls) { +static void add_to_index(struct intermediates *cint, int first, + path_stack_entry *sp, ClauseDef *cls) { /* last clause to experiment with */ PredEntry *ap = cint->CurrentPred; yamop *ipc = ap->cs.p_code.TrueCodeOfPred; @@ -5147,7 +5112,7 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause while (ipc != NULL) { op_numbers op = Yap_op_from_opcode(ipc->opc); - switch(op) { + switch (op) { case _try_logical: case _retry_logical: case _count_retry_logical: @@ -5161,28 +5126,27 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause ipc->y_u.Illss.s++; icl = ipc->y_u.Illss.I; if (first) { - if (ap->PredFlags & CountPredFlag) - ipc->y_u.Illss.l1->opc = Yap_opcode(_count_retry_logical); - else if (ap->PredFlags & ProfiledPredFlag) - ipc->y_u.Illss.l1->opc = Yap_opcode(_profiled_retry_logical); - else - ipc->y_u.Illss.l1->opc = Yap_opcode(_retry_logical); - ipc->y_u.Illss.l1 = add_try(ap, cls, ipc->y_u.Illss.l1, cint); + if (ap->PredFlags & CountPredFlag) + ipc->y_u.Illss.l1->opc = Yap_opcode(_count_retry_logical); + else if (ap->PredFlags & ProfiledPredFlag) + ipc->y_u.Illss.l1->opc = Yap_opcode(_profiled_retry_logical); + else + ipc->y_u.Illss.l1->opc = Yap_opcode(_retry_logical); + ipc->y_u.Illss.l1 = add_try(ap, cls, ipc->y_u.Illss.l1, cint); } else { - /* just go to next instruction */ - yamop *end = add_trust(icl, cls, cint), - *old = ipc->y_u.Illss.l2; - - /* we used to have two clauses */ - if (ap->PredFlags & CountPredFlag) - old->opc = Yap_opcode(_count_retry_logical); - else if (ap->PredFlags & ProfiledPredFlag) - old->opc = Yap_opcode(_profiled_retry_logical); - else - old->opc = Yap_opcode(_retry_logical); - old->y_u.OtaLl.n = end; - old->y_u.OtaLl.s = ap->ArityOfPE; - ipc->y_u.Illss.l2 = end; + /* just go to next instruction */ + yamop *end = add_trust(icl, cls, cint), *old = ipc->y_u.Illss.l2; + + /* we used to have two clauses */ + if (ap->PredFlags & CountPredFlag) + old->opc = Yap_opcode(_count_retry_logical); + else if (ap->PredFlags & ProfiledPredFlag) + old->opc = Yap_opcode(_profiled_retry_logical); + else + old->opc = Yap_opcode(_retry_logical); + old->y_u.OtaLl.n = end; + old->y_u.OtaLl.s = ap->ArityOfPE; + ipc->y_u.Illss.l2 = end; } ipc = pop_path(&sp, cls, ap, cint); break; @@ -5191,11 +5155,11 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause have to expand the index. */ if (first) { - sp = expanda_block(sp, ap, cls, group1, alt, cint); - ipc = pop_path(&sp, cls, ap, cint); + sp = expanda_block(sp, ap, cls, group1, alt, cint); + ipc = pop_path(&sp, cls, ap, cint); } else { - /* just go to next instruction */ - ipc = NEXTOP(ipc,Otapl); + /* just go to next instruction */ + ipc = NEXTOP(ipc, Otapl); } break; case _try_clause2: @@ -5205,24 +5169,24 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause have to expand the index. */ if (first) { - sp = expanda_block(sp, ap, cls, group1, alt, cint); - ipc = pop_path(&sp, cls, ap, cint); + sp = expanda_block(sp, ap, cls, group1, alt, cint); + ipc = pop_path(&sp, cls, ap, cint); } else { - /* just go to next instruction */ - ipc = NEXTOP(ipc,l); + /* just go to next instruction */ + ipc = NEXTOP(ipc, l); } break; case _retry: /* this clause had no indexing */ - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _retry2: case _retry3: case _retry4: /* this clause had no indexing */ - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); break; - /* instructions type l */ + /* instructions type l */ case _retry_me: /* should never be reached both for asserta */ group1 = FALSE; @@ -5230,22 +5194,22 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause break; case _try_me: if (first) { - ipc = NEXTOP(ipc,Otapl); - alt = ipc->y_u.Otapl.d; + ipc = NEXTOP(ipc, Otapl); + alt = ipc->y_u.Otapl.d; } else { - ipc = ipc->y_u.Otapl.d; - group1 = FALSE; + ipc = ipc->y_u.Otapl.d; + group1 = FALSE; } break; case _retry_profiled: case _count_retry: - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _profiled_trust_me: case _trust_me: case _count_trust_me: group1 = FALSE; - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _trust: sp = expandz_block(sp, ap, cls, group1, alt, cint); @@ -5258,79 +5222,79 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause break; case _jump_if_var: sp = push_path(sp, &(ipc->y_u.l.l), cls, cint); - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); break; case _jump_if_nonvar: sp = push_path(sp, &(ipc->y_u.xll.l2), cls, cint); sp = cross_block(sp, &ipc->y_u.xll.l1, ap, cint); ipc = ipc->y_u.xll.l1; break; - /* instructions type EC */ + /* instructions type EC */ case _try_in: /* we are done */ if (first) { - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } else { - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); } break; case _user_switch: ipc = ipc->y_u.lp.l; break; - /* instructions type e */ + /* instructions type e */ case _switch_on_type: sp = push_path(sp, &(ipc->y_u.llll.l4), cls, cint); if (ap->PredFlags & LogUpdatePredFlag) { - add_head_info(cls, 1); + add_head_info(cls, 1); } else { - add_info(cls, 1); + add_info(cls, 1); } if (IsPairTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.llll.l1; + yamop *nipc = ipc->y_u.llll.l1; - current_arity = 2; - move_next(cls, 1); - if (nipc == FAILCODE) { - /* jump straight to clause */ - if (ap->PredFlags & LogUpdatePredFlag) { - ipc->y_u.llll.l1 = cls->Code; - } else { - ipc->y_u.llll.l1 = cls->CurrentCode; - } - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* go on */ - sp = cross_block(sp, &ipc->y_u.llll.l1, ap, cint); - ipc = nipc; - } + current_arity = 2; + move_next(cls, 1); + if (nipc == FAILCODE) { + /* jump straight to clause */ + if (ap->PredFlags & LogUpdatePredFlag) { + ipc->y_u.llll.l1 = cls->Code; + } else { + ipc->y_u.llll.l1 = cls->CurrentCode; + } + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* go on */ + sp = cross_block(sp, &ipc->y_u.llll.l1, ap, cint); + ipc = nipc; + } } else if (IsAtomOrIntTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.llll.l2; - move_next(cls, 1); - if (nipc == FAILCODE) { - /* need to expand the block */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.llll.l2; + move_next(cls, 1); + if (nipc == FAILCODE) { + /* need to expand the block */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else if (IsApplTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.llll.l3; - if (nipc == FAILCODE) { - /* need to expand the block */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.llll.l3; + if (nipc == FAILCODE) { + /* need to expand the block */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else { - /* we can't separate into four groups, - need to restart. - */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + /* we can't separate into four groups, + need to restart. + */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } break; case _switch_list_nl: @@ -5340,214 +5304,210 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause case _switch_on_arg_type: sp = push_path(sp, &(ipc->y_u.xllll.l4), cls, cint); if (ap->PredFlags & LogUpdatePredFlag) { - add_head_info(cls, Yap_regtoregno(ipc->y_u.xllll.x)); + add_head_info(cls, Yap_regtoregno(ipc->y_u.xllll.x)); } else { - add_info(cls, Yap_regtoregno(ipc->y_u.xllll.x)); + add_info(cls, Yap_regtoregno(ipc->y_u.xllll.x)); } if (IsPairTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.xllll.l1; + yamop *nipc = ipc->y_u.xllll.l1; - current_arity = 2; - move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x)); - if (nipc == FAILCODE) { - /* jump straight to clause */ - if (ap->PredFlags & LogUpdatePredFlag) { - ipc->y_u.xllll.l1 = cls->Code; - } else { - ipc->y_u.xllll.l1 = cls->CurrentCode; - } - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* go on */ - sp = cross_block(sp, &ipc->y_u.xllll.l1, ap, cint); - ipc = nipc; - } + current_arity = 2; + move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x)); + if (nipc == FAILCODE) { + /* jump straight to clause */ + if (ap->PredFlags & LogUpdatePredFlag) { + ipc->y_u.xllll.l1 = cls->Code; + } else { + ipc->y_u.xllll.l1 = cls->CurrentCode; + } + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* go on */ + sp = cross_block(sp, &ipc->y_u.xllll.l1, ap, cint); + ipc = nipc; + } } else if (IsAtomOrIntTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.xllll.l2; - move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x)); - if (nipc == FAILCODE) { - /* need to expand the block */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.xllll.l2; + move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x)); + if (nipc == FAILCODE) { + /* need to expand the block */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else if (IsApplTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.xllll.l3; - move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x)); - if (nipc == FAILCODE) { - /* need to expand the block */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.xllll.l3; + move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x)); + if (nipc == FAILCODE) { + /* need to expand the block */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else { - /* we can't separate into four groups, - need to restart. - */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + /* we can't separate into four groups, + need to restart. + */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } break; case _switch_on_sub_arg_type: sp = push_path(sp, &(ipc->y_u.sllll.l4), cls, cint); - add_arg_info(cls, ap, ipc->y_u.sllll.s+1); + add_arg_info(cls, ap, ipc->y_u.sllll.s + 1); if (IsPairTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.sllll.l1; - current_arity = 2; - skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity); - if (nipc == FAILCODE) { - /* jump straight to clause */ - if (ap->PredFlags & LogUpdatePredFlag) { - ipc->y_u.sllll.l1 = cls->Code; - } else { - ipc->y_u.sllll.l1 = cls->CurrentCode; - } - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* go on */ - sp = cross_block(sp, &ipc->y_u.sllll.l1, ap, cint); - ipc = nipc; - } + yamop *nipc = ipc->y_u.sllll.l1; + current_arity = 2; + skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity); + if (nipc == FAILCODE) { + /* jump straight to clause */ + if (ap->PredFlags & LogUpdatePredFlag) { + ipc->y_u.sllll.l1 = cls->Code; + } else { + ipc->y_u.sllll.l1 = cls->CurrentCode; + } + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* go on */ + sp = cross_block(sp, &ipc->y_u.sllll.l1, ap, cint); + ipc = nipc; + } } else if (IsAtomOrIntTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.sllll.l2; - skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity); - if (nipc == FAILCODE) { - /* need to expand the block */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.sllll.l2; + skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity); + if (nipc == FAILCODE) { + /* need to expand the block */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else if (IsApplTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.sllll.l3; - skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity); - if (nipc == FAILCODE) { - /* need to expand the block */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.sllll.l3; + skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity); + if (nipc == FAILCODE) { + /* need to expand the block */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else { - /* we can't separate into four groups, - need to restart. - */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + /* we can't separate into four groups, + need to restart. + */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } break; case _if_not_then: ipc = pop_path(&sp, cls, ap, cint); break; - /* instructions type ollll */ + /* instructions type ollll */ case _switch_on_func: case _if_func: - case _go_on_func: - { - FuncSwiEntry *fe; - yamop *newpc; - Functor f = (Functor)RepAppl(cls->Tag); - - if (op == _switch_on_func) { - fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } else { - fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } - if (!IsExtensionFunctor(f)) { - current_arity = ArityOfFunctor(f); - } - newpc = fe->u_f.labp; - if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { - /* we found it */ - ipc = pop_path(&sp, cls, ap, cint); - } else if (newpc == FAILCODE) { - /* oops, nothing there */ - if (fe->Tag != f) { - if (IsExtensionFunctor(f)) { - sp = kill_unsafe_block(sp, op, ap, first, FALSE, cls); - ipc = pop_path(&sp, cls, ap, cint); - break; - } - if (table_fe_overflow(ipc, f)) { - fe = expand_ftable(ipc, current_block(sp), cint, f); - } - fe->Tag = f; - ipc->y_u.sssl.e++; - } - if (ap->PredFlags & LogUpdatePredFlag) { - fe->u_f.labp = cls->Code; - } else { - fe->u_f.labp = cls->CurrentCode; - } - ipc = pop_path(&sp, cls, ap, cint); - } else { - yamop *newpc = fe->u_f.labp; - sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint); - sp = cross_block(sp, &(fe->u_f.labp), ap, cint); - ipc = newpc; - } + case _go_on_func: { + FuncSwiEntry *fe; + yamop *newpc; + Functor f = (Functor)RepAppl(cls->Tag); + + if (op == _switch_on_func) { + fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); + } else { + fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); } - break; + if (!IsExtensionFunctor(f)) { + current_arity = ArityOfFunctor(f); + } + newpc = fe->u_f.labp; + if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { + /* we found it */ + ipc = pop_path(&sp, cls, ap, cint); + } else if (newpc == FAILCODE) { + /* oops, nothing there */ + if (fe->Tag != f) { + if (IsExtensionFunctor(f)) { + sp = kill_unsafe_block(sp, op, ap, first, FALSE, cls); + ipc = pop_path(&sp, cls, ap, cint); + break; + } + if (table_fe_overflow(ipc, f)) { + fe = expand_ftable(ipc, current_block(sp), cint, f); + } + fe->Tag = f; + ipc->y_u.sssl.e++; + } + if (ap->PredFlags & LogUpdatePredFlag) { + fe->u_f.labp = cls->Code; + } else { + fe->u_f.labp = cls->CurrentCode; + } + ipc = pop_path(&sp, cls, ap, cint); + } else { + yamop *newpc = fe->u_f.labp; + sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint); + sp = cross_block(sp, &(fe->u_f.labp), ap, cint); + ipc = newpc; + } + } break; case _index_dbref: cls->Tag = cls->ucd.t_ptr; - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _index_blob: cls->Tag = Yap_Double_key(cls->ucd.t_ptr); - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _index_long: cls->Tag = Yap_Int_key(cls->ucd.t_ptr); - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _switch_on_cons: case _if_cons: - case _go_on_cons: - { - AtomSwiEntry *ae; - yamop *newpc; - Term at = cls->Tag; - - if (op == _switch_on_cons) { - ae = lookup_c_hash(at,ipc->y_u.sssl.l,ipc->y_u.sssl.s); - } else { - ae = lookup_c(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } - newpc = ae->u_a.labp; + case _go_on_cons: { + AtomSwiEntry *ae; + yamop *newpc; + Term at = cls->Tag; - if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { - /* nothing more to do */ - ipc = pop_path(&sp, cls, ap, cint); - } else if (newpc == FAILCODE) { - /* oops, nothing there */ - if (ae->Tag != at) { - if (table_ae_overflow(ipc, at)) { - ae = expand_ctable(ipc, current_block(sp), cint, at); - } - ae->Tag = at; - ipc->y_u.sssl.e++; - } - if (ap->PredFlags & LogUpdatePredFlag) { - ae->u_a.labp = cls->Code; - } else { - ae->u_a.labp = cls->CurrentCode; - } - ipc = pop_path(&sp, cls, ap, cint); - } else { - yamop *newpc = ae->u_a.labp; - - sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint); - sp = cross_block(sp, &(ae->u_a.labp), ap, cint); - ipc = newpc; - } + if (op == _switch_on_cons) { + ae = lookup_c_hash(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s); + } else { + ae = lookup_c(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s); } - break; + newpc = ae->u_a.labp; + + if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { + /* nothing more to do */ + ipc = pop_path(&sp, cls, ap, cint); + } else if (newpc == FAILCODE) { + /* oops, nothing there */ + if (ae->Tag != at) { + if (table_ae_overflow(ipc, at)) { + ae = expand_ctable(ipc, current_block(sp), cint, at); + } + ae->Tag = at; + ipc->y_u.sssl.e++; + } + if (ap->PredFlags & LogUpdatePredFlag) { + ae->u_a.labp = cls->Code; + } else { + ae->u_a.labp = cls->CurrentCode; + } + ipc = pop_path(&sp, cls, ap, cint); + } else { + yamop *newpc = ae->u_a.labp; + + sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint); + sp = cross_block(sp, &(ae->u_a.labp), ap, cint); + ipc = newpc; + } + } break; case _expand_clauses: ipc = add_to_expand_clauses(&sp, ipc, cls, ap, first, cint); break; @@ -5555,10 +5515,11 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause ipc = pop_path(&sp, cls, ap, cint); break; case _lock_lu: - ipc = NEXTOP(ipc,p); + ipc = NEXTOP(ipc, p); break; case _op_fail: - while ((--sp)->flag != block_entry); + while ((--sp)->flag != block_entry) + ; *sp->uip.cle.entry_code = cls->Code; ipc = pop_path(&sp, cls, ap, cint); break; @@ -5569,9 +5530,7 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause } } - -void -Yap_AddClauseToIndex(PredEntry *ap, yamop *beg, int first) { +void Yap_AddClauseToIndex(PredEntry *ap, yamop *beg, int first) { CACHE_REGS ClauseDef cl; /* first clause */ @@ -5609,19 +5568,18 @@ Yap_AddClauseToIndex(PredEntry *ap, yamop *beg, int first) { LOCAL_ErrorMessage = NULL; #if DEBUG if (GLOBAL_Option['i' - 'a' + 1]) { - Yap_DebugPutc(stderr,'+'); - Yap_DebugWriteIndicator( ap ); - } + Yap_DebugPutc(stderr, '+'); + Yap_DebugWriteIndicator(ap); + } #endif stack = (path_stack_entry *)TR; - cl.Code = cl.CurrentCode = beg; + cl.Code = cl.CurrentCode = beg; sp = push_path(stack, NULL, &cl, &cint); - add_to_index(&cint, first, sp, &cl); + add_to_index(&cint, first, sp, &cl); } - -static void -contract_ftable(yamop *ipc, ClauseUnion *blk, PredEntry *ap, Functor f) { +static void contract_ftable(yamop *ipc, ClauseUnion *blk, PredEntry *ap, + Functor f) { int n = ipc->y_u.sssl.s; FuncSwiEntry *fep; @@ -5629,13 +5587,14 @@ contract_ftable(yamop *ipc, ClauseUnion *blk, PredEntry *ap, Functor f) { fep = lookup_f_hash(f, ipc->y_u.sssl.l, n); } else { fep = (FuncSwiEntry *)(ipc->y_u.sssl.l); - while (fep->Tag != f) fep++; + while (fep->Tag != f) + fep++; } fep->u_f.labp = FAILCODE; } -static void -contract_ctable(yamop *ipc, ClauseUnion *blk, PredEntry *ap, Term at) { +static void contract_ctable(yamop *ipc, ClauseUnion *blk, PredEntry *ap, + Term at) { int n = ipc->y_u.sssl.s; AtomSwiEntry *cep; @@ -5643,13 +5602,15 @@ contract_ctable(yamop *ipc, ClauseUnion *blk, PredEntry *ap, Term at) { cep = lookup_c_hash(at, ipc->y_u.sssl.l, n); } else { cep = (AtomSwiEntry *)(ipc->y_u.sssl.l); - while (cep->Tag != at) cep++; + while (cep->Tag != at) + cep++; } cep->u_a.labp = FAILCODE; } -static void -remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg, yamop *lt, struct intermediates *cint) { +static void remove_from_index(PredEntry *ap, path_stack_entry *sp, + ClauseDef *cls, yamop *bg, yamop *lt, + struct intermediates *cint) { /* last clause to experiment with */ yamop *ipc = ap->cs.p_code.TrueCodeOfPred; @@ -5659,16 +5620,16 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg return; } ap->cs.p_code.TrueCodeOfPred = ap->cs.p_code.FirstClause; - if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { + if (ap->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) { ap->OpcodeOfPred = Yap_opcode(_spy_pred); - ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); + ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); #if defined(YAPOR) || defined(THREADS) } else if (ap->PredFlags & LogUpdatePredFlag && - !(ap->PredFlags & ThreadLocalPredFlag) && - ap->ModuleOfPred != IDB_MODULE) { + !(ap->PredFlags & ThreadLocalPredFlag) && + ap->ModuleOfPred != IDB_MODULE) { ap->cs.p_code.TrueCodeOfPred = FAILCODE; ap->OpcodeOfPred = LOCKPRED_OPCODE; - ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); + ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); #endif } else { ap->OpcodeOfPred = ap->cs.p_code.FirstClause->opc; @@ -5681,7 +5642,7 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg while (ipc != NULL) { op_numbers op = Yap_op_from_opcode(ipc->opc); - switch(op) { + switch (op) { case _retry_profiled: case _count_retry: ipc = NEXTOP(ipc, p); @@ -5690,12 +5651,12 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg /* I cannot expand a predicate that starts on a variable, have to expand the index. */ - if (IN_BETWEEN(bg,ipc->y_u.l.l,lt)) { - sp = kill_clause(ipc, bg, lt, sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + if (IN_BETWEEN(bg, ipc->y_u.l.l, lt)) { + sp = kill_clause(ipc, bg, lt, sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } else { - /* just go to next instruction */ - ipc = NEXTOP(ipc,l); + /* just go to next instruction */ + ipc = NEXTOP(ipc, l); } break; case _try_clause: @@ -5703,12 +5664,12 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg /* I cannot expand a predicate that starts on a variable, have to expand the index. */ - if (IN_BETWEEN(bg,ipc->y_u.Otapl.d,lt)) { - sp = kill_clause(ipc, bg, lt, sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + if (IN_BETWEEN(bg, ipc->y_u.Otapl.d, lt)) { + sp = kill_clause(ipc, bg, lt, sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } else { - /* just go to next instruction */ - ipc = NEXTOP(ipc,Otapl); + /* just go to next instruction */ + ipc = NEXTOP(ipc, Otapl); } break; case _try_clause2: @@ -5720,17 +5681,17 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg /* I cannot expand a predicate that starts on a variable, have to expand the index. */ - if (IN_BETWEEN(bg,ipc->y_u.l.l,lt)) { - sp = kill_clause(ipc, bg, lt, sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + if (IN_BETWEEN(bg, ipc->y_u.l.l, lt)) { + sp = kill_clause(ipc, bg, lt, sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } else { - /* just go to next instruction */ - ipc = NEXTOP(ipc,l); + /* just go to next instruction */ + ipc = NEXTOP(ipc, l); } break; case _trust: - if (IN_BETWEEN(bg,ipc->y_u.Otapl.d,lt)) { - sp = kill_clause(ipc, bg, lt, sp, ap); + if (IN_BETWEEN(bg, ipc->y_u.Otapl.d, lt)) { + sp = kill_clause(ipc, bg, lt, sp, ap); } ipc = pop_path(&sp, cls, ap, cint); break; @@ -5744,16 +5705,16 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg sp = kill_clause(ipc, bg, lt, sp, ap); ipc = pop_path(&sp, cls, ap, cint); break; - /* instructions type l */ + /* instructions type l */ case _try_me: case _retry_me: sp = push_path(sp, &(ipc->y_u.Otapl.d), cls, cint); - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _profiled_trust_me: case _trust_me: case _count_trust_me: - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _jump: sp = cross_block(sp, &ipc->y_u.l.l, ap, cint); @@ -5762,7 +5723,7 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg break; case _jump_if_var: sp = push_path(sp, &(ipc->y_u.l.l), cls, cint); - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); break; case _jump_if_nonvar: sp = push_path(sp, &(ipc->y_u.xll.l2), cls, cint); @@ -5772,51 +5733,51 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg case _user_switch: ipc = ipc->y_u.lp.l; break; - /* instructions type e */ + /* instructions type e */ case _switch_on_type: sp = push_path(sp, &(ipc->y_u.llll.l4), cls, cint); if (ap->PredFlags & LogUpdatePredFlag) { - add_head_info(cls, 1); + add_head_info(cls, 1); } else { - add_info(cls, 1); + add_info(cls, 1); } if (IsPairTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.llll.l1; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.llll.l1 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* go on */ - sp = cross_block(sp, &ipc->y_u.llll.l1, ap, cint); - ipc = nipc; - } + yamop *nipc = ipc->y_u.llll.l1; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.llll.l1 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* go on */ + sp = cross_block(sp, &ipc->y_u.llll.l1, ap, cint); + ipc = nipc; + } } else if (IsAtomOrIntTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.llll.l2; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.llll.l2 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.llll.l2; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.llll.l2 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else if (IsApplTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.llll.l3; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.llll.l3 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.llll.l3; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.llll.l3 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else { - /* we can't separate into four groups, - need to restart. - */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + /* we can't separate into four groups, + need to restart. + */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } break; case _switch_list_nl: @@ -5826,172 +5787,168 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg case _switch_on_arg_type: sp = push_path(sp, &(ipc->y_u.xllll.l4), cls, cint); if (ap->PredFlags & LogUpdatePredFlag) { - add_head_info(cls, Yap_regtoregno(ipc->y_u.xllll.x)); + add_head_info(cls, Yap_regtoregno(ipc->y_u.xllll.x)); } else { - add_info(cls, Yap_regtoregno(ipc->y_u.xllll.x)); + add_info(cls, Yap_regtoregno(ipc->y_u.xllll.x)); } if (IsPairTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.xllll.l1; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.xllll.l1 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* go on */ - sp = cross_block(sp, &ipc->y_u.xllll.l1, ap, cint); - ipc = nipc; - } + yamop *nipc = ipc->y_u.xllll.l1; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.xllll.l1 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* go on */ + sp = cross_block(sp, &ipc->y_u.xllll.l1, ap, cint); + ipc = nipc; + } } else if (IsAtomOrIntTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.xllll.l2; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.xllll.l2 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.xllll.l2; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.xllll.l2 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else if (IsApplTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.xllll.l3; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.xllll.l3 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.xllll.l3; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.xllll.l3 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else { - /* we can't separate into four groups, - need to restart. - */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + /* we can't separate into four groups, + need to restart. + */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } break; case _switch_on_sub_arg_type: sp = push_path(sp, &(ipc->y_u.sllll.l4), cls, cint); - add_arg_info(cls, ap, ipc->y_u.sllll.s+1); + add_arg_info(cls, ap, ipc->y_u.sllll.s + 1); if (IsPairTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.sllll.l1; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.sllll.l1 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* go on */ - sp = cross_block(sp, &ipc->y_u.sllll.l1, ap, cint); - ipc = nipc; - } + yamop *nipc = ipc->y_u.sllll.l1; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.sllll.l1 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* go on */ + sp = cross_block(sp, &ipc->y_u.sllll.l1, ap, cint); + ipc = nipc; + } } else if (IsAtomOrIntTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.sllll.l2; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.sllll.l2 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.sllll.l2; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.sllll.l2 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else if (IsApplTerm(cls->Tag)) { - yamop *nipc = ipc->y_u.sllll.l3; - if (IN_BETWEEN(bg,nipc,lt)) { - /* jump straight to clause */ - ipc->y_u.sllll.l3 = FAILCODE; - ipc = pop_path(&sp, cls, ap, cint); - } else { - /* I do not have to worry about crossing a block here */ - ipc = nipc; - } + yamop *nipc = ipc->y_u.sllll.l3; + if (IN_BETWEEN(bg, nipc, lt)) { + /* jump straight to clause */ + ipc->y_u.sllll.l3 = FAILCODE; + ipc = pop_path(&sp, cls, ap, cint); + } else { + /* I do not have to worry about crossing a block here */ + ipc = nipc; + } } else { - /* we can't separate into four groups, - need to restart. - */ - sp = kill_block(sp, ap); - ipc = pop_path(&sp, cls, ap, cint); + /* we can't separate into four groups, + need to restart. + */ + sp = kill_block(sp, ap); + ipc = pop_path(&sp, cls, ap, cint); } break; case _if_not_then: ipc = pop_path(&sp, cls, ap, cint); break; - /* instructions type ollll */ + /* instructions type ollll */ case _switch_on_func: case _if_func: - case _go_on_func: - { - FuncSwiEntry *fe; - yamop *newpc; - Functor f = (Functor)RepAppl(cls->Tag); - - if (op == _switch_on_func) { - fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } else { - fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } - newpc = fe->u_f.labp; + case _go_on_func: { + FuncSwiEntry *fe; + yamop *newpc; + Functor f = (Functor)RepAppl(cls->Tag); - if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { - /* we found it */ - ipc = pop_path(&sp, cls, ap, cint); - } else if (newpc == FAILCODE) { - ipc = pop_path(&sp, cls, ap, cint); - } else if (IN_BETWEEN(bg,fe->u_f.Label,lt)) { - /* oops, nothing there */ - contract_ftable(ipc, current_block(sp), ap, f); - ipc = pop_path(&sp, cls, ap, cint); - } else { - yamop *newpc = fe->u_f.labp; - sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint); - sp = cross_block(sp, &(fe->u_f.labp), ap, cint); - ipc = newpc; - } + if (op == _switch_on_func) { + fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); + } else { + fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); } - break; + newpc = fe->u_f.labp; + + if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { + /* we found it */ + ipc = pop_path(&sp, cls, ap, cint); + } else if (newpc == FAILCODE) { + ipc = pop_path(&sp, cls, ap, cint); + } else if (IN_BETWEEN(bg, fe->u_f.Label, lt)) { + /* oops, nothing there */ + contract_ftable(ipc, current_block(sp), ap, f); + ipc = pop_path(&sp, cls, ap, cint); + } else { + yamop *newpc = fe->u_f.labp; + sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint); + sp = cross_block(sp, &(fe->u_f.labp), ap, cint); + ipc = newpc; + } + } break; case _index_dbref: cls->Tag = cls->ucd.t_ptr; - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _index_blob: cls->Tag = Yap_Double_key(cls->ucd.t_ptr); - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _index_long: cls->Tag = Yap_Int_key(cls->ucd.t_ptr); - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _switch_on_cons: case _if_cons: - case _go_on_cons: - { - AtomSwiEntry *ae; - yamop *newpc; - Term at = cls->Tag; - - if (op == _switch_on_cons) { - ae = lookup_c_hash(at,ipc->y_u.sssl.l,ipc->y_u.sssl.s); - } else { - ae = lookup_c(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } - newpc = ae->u_a.labp; + case _go_on_cons: { + AtomSwiEntry *ae; + yamop *newpc; + Term at = cls->Tag; - if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { - /* we found it */ - ipc = pop_path(&sp, cls, ap, cint); - } else if (newpc == FAILCODE) { - ipc = pop_path(&sp, cls, ap, cint); - } else if (IN_BETWEEN(bg,ae->u_a.Label,lt)) { - /* oops, nothing there */ - contract_ctable(ipc, current_block(sp), ap, at); - ipc = pop_path(&sp, cls, ap, cint); - } else { - yamop *newpc = ae->u_a.labp; - - sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint); - sp = cross_block(sp, &(ae->u_a.labp), ap, cint); - ipc = newpc; - } + if (op == _switch_on_cons) { + ae = lookup_c_hash(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s); + } else { + ae = lookup_c(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s); } - break; + newpc = ae->u_a.labp; + + if (newpc == (yamop *)&(ap->cs.p_code.ExpandCode)) { + /* we found it */ + ipc = pop_path(&sp, cls, ap, cint); + } else if (newpc == FAILCODE) { + ipc = pop_path(&sp, cls, ap, cint); + } else if (IN_BETWEEN(bg, ae->u_a.Label, lt)) { + /* oops, nothing there */ + contract_ctable(ipc, current_block(sp), ap, at); + ipc = pop_path(&sp, cls, ap, cint); + } else { + yamop *newpc = ae->u_a.labp; + + sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint); + sp = cross_block(sp, &(ae->u_a.labp), ap, cint); + ipc = newpc; + } + } break; case _expand_index: ipc = pop_path(&sp, cls, ap, cint); break; @@ -6000,28 +5957,26 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg ipc = pop_path(&sp, cls, ap, cint); break; case _lock_lu: - ipc = NEXTOP(ipc,p); + ipc = NEXTOP(ipc, p); break; default: - if (IN_BETWEEN(bg,ipc,lt)) { - sp = kill_unsafe_block(sp, op, ap, TRUE, TRUE, cls); + if (IN_BETWEEN(bg, ipc, lt)) { + sp = kill_unsafe_block(sp, op, ap, TRUE, TRUE, cls); } ipc = pop_path(&sp, cls, ap, cint); } } } - /* clause is locked */ -void -Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) { +void Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) { CACHE_REGS ClauseDef cl; /* first clause */ path_stack_entry *stack, *sp; int cb; yamop *last; - struct intermediates cint; + struct intermediates cint; if (ap->PredFlags & MegaClausePredFlag) { return; @@ -6044,74 +5999,78 @@ Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) { LOCAL_Error_Size = 0; LOCAL_ErrorMessage = NULL; cint.term_depth = cint.last_index_new_depth = cint.last_depth_size = 0L; - if (cb) { + if (cb || (ap->cs.p_code.NOfClauses == 2 && + ap->PredFlags & IndexedPredFlag)) { /* cannot rely on the code */ if (ap->PredFlags & LogUpdatePredFlag) { - Yap_kill_iblock((ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),NULL, ap); + Yap_kill_iblock( + (ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred), + NULL, ap); } else { StaticIndex *cl; - + ap->PredFlags &= ~LogUpdatePredFlag; cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); Yap_kill_iblock((ClauseUnion *)cl, NULL, ap); } + ap->PredFlags &= ~IndexedPredFlag; return; } #if DEBUG if (GLOBAL_Option['i' - 'a' + 1]) { Term tmod = ap->ModuleOfPred; - if (!tmod) tmod = TermProlog; - Yap_DebugPutc(stderr,'-'); - Yap_DebugPutc(stderr,'\t'); + if (!tmod) + tmod = TermProlog; + Yap_DebugPutc(stderr, '-'); + Yap_DebugPutc(stderr, '\t'); Yap_DebugPlWrite(tmod); - Yap_DebugPutc(stderr,':'); + Yap_DebugPutc(stderr, ':'); if (ap->ModuleOfPred != IDB_MODULE) { if (ap->ArityOfPE == 0) { - Atom At = (Atom)ap->FunctorOfPred; - Yap_DebugPlWrite(MkAtomTerm(At)); + Atom At = (Atom)ap->FunctorOfPred; + Yap_DebugPlWrite(MkAtomTerm(At)); } else { - Functor f = ap->FunctorOfPred; - Atom At = NameOfFunctor(f); - Yap_DebugPlWrite(MkAtomTerm(At)); - Yap_DebugPutc(stderr,'/'); - Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); + Functor f = ap->FunctorOfPred; + Atom At = NameOfFunctor(f); + Yap_DebugPlWrite(MkAtomTerm(At)); + Yap_DebugPutc(stderr, '/'); + Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); } } else { if (ap->PredFlags & NumberDBPredFlag) { - Int id = ap->src.IndxId; - Yap_DebugPlWrite(MkIntegerTerm(id)); + Int id = ap->src.IndxId; + Yap_DebugPlWrite(MkIntegerTerm(id)); } else if (ap->PredFlags & AtomDBPredFlag) { - Atom At = (Atom)ap->FunctorOfPred; - Yap_DebugPlWrite(MkAtomTerm(At)); + Atom At = (Atom)ap->FunctorOfPred; + Yap_DebugPlWrite(MkAtomTerm(At)); } else { - Functor f = ap->FunctorOfPred; - Atom At = NameOfFunctor(f); - Yap_DebugPlWrite(MkAtomTerm(At)); - Yap_DebugPutc(stderr,'/'); - Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); + Functor f = ap->FunctorOfPred; + Atom At = NameOfFunctor(f); + Yap_DebugPlWrite(MkAtomTerm(At)); + Yap_DebugPutc(stderr, '/'); + Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f))); } } - Yap_DebugPutc(stderr,'\n'); + Yap_DebugPutc(stderr, '\n'); } #endif stack = (path_stack_entry *)TR; if (ap->PredFlags & LogUpdatePredFlag) { LogUpdClause *c = ClauseCodeToLogUpdClause(beg); - cl.Code = cl.CurrentCode = beg; - last = (yamop *)((CODEADDR)c+c->ClSize); + cl.Code = cl.CurrentCode = beg; + last = (yamop *)((CODEADDR)c + c->ClSize); } else { StaticClause *c = ClauseCodeToStaticClause(beg); - cl.Code = cl.CurrentCode = beg; - last = (yamop *)((CODEADDR)c+c->ClSize); + cl.Code = cl.CurrentCode = beg; + last = (yamop *)((CODEADDR)c + c->ClSize); } sp = push_path(stack, NULL, &cl, &cint); if (ap->cs.p_code.NOfClauses == 0) { - /* there was no indexing code */ +/* there was no indexing code */ #if defined(YAPOR) || defined(THREADS) - if (ap->PredFlags & LogUpdatePredFlag && - ap->ModuleOfPred != IDB_MODULE) { + if (ap->PredFlags & LogUpdatePredFlag && ap->ModuleOfPred != IDB_MODULE) { ap->cs.p_code.TrueCodeOfPred = FAILCODE; - ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); + ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); } else { #endif ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = FAILCODE; @@ -6119,22 +6078,21 @@ Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) { } #endif ap->OpcodeOfPred = Yap_opcode(_op_fail); - } else if (ap->PredFlags & IndexedPredFlag) { - remove_from_index(ap, sp, &cl, beg, last, &cint); - } else if (ap->cs.p_code.NOfClauses == 1) { + } else if (ap->PredFlags & IndexedPredFlag) { + remove_from_index(ap, sp, &cl, beg, last, &cint); + } else if (ap->cs.p_code.NOfClauses == 1) { ap->cs.p_code.TrueCodeOfPred = ap->cs.p_code.FirstClause; - ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); + ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); } } - -static void -store_clause_choice_point(Term t1, Term tb, Term tr, yamop *ipc, PredEntry *pe, yamop *ap_pc, yamop *cp_pc USES_REGS) -{ +static void store_clause_choice_point(Term t1, Term tb, Term tr, yamop *ipc, + PredEntry *pe, yamop *ap_pc, + yamop *cp_pc USES_REGS) { Term tpc = MkIntegerTerm((Int)ipc); Term tpe = MkIntegerTerm((Int)pe); - CELL *tsp = ASP-5; - choiceptr bptr = ((choiceptr)tsp)-1; + CELL *tsp = ASP - 5; + choiceptr bptr = ((choiceptr)tsp) - 1; tsp[0] = tpe; tsp[1] = tpc; @@ -6156,22 +6114,18 @@ store_clause_choice_point(Term t1, Term tb, Term tr, yamop *ipc, PredEntry *pe, B = bptr; #ifdef YAPOR SCH_set_load(B); -#endif /* YAPOR */ +#endif /* YAPOR */ SET_BB(bptr); } -static void -update_clause_choice_point(yamop *ipc, yamop *ap_pc USES_REGS) -{ +static void update_clause_choice_point(yamop *ipc, yamop *ap_pc USES_REGS) { Term tpc = MkIntegerTerm((Int)ipc); B->cp_args[1] = tpc; B->cp_h = HR; B->cp_ap = ap_pc; } -static LogUpdClause * -to_clause(yamop *ipc, PredEntry *ap) -{ +static LogUpdClause *to_clause(yamop *ipc, PredEntry *ap) { if (ap->PredFlags & LogUpdatePredFlag) return lu_clause(ipc, ap); else if (ap->PredFlags & MegaClausePredFlag) @@ -6180,9 +6134,8 @@ to_clause(yamop *ipc, PredEntry *ap) return (LogUpdClause *)simple_static_clause(ipc, ap); } -LogUpdClause * -Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, yamop *cp_pc) -{ +LogUpdClause *Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], + yamop *ap_pc, yamop *cp_pc) { CACHE_REGS CELL *s_reg = NULL; Term t = TermNil; @@ -6200,113 +6153,116 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y UInt i; for (i = 1; i <= ap->ArityOfPE; i++) { - XREGS[i] = tar[i]; + XREGS[i] = tar[i]; } } } /* try to refine the interval using the indexing code */ while (ipc != NULL) { op_numbers op = Yap_op_from_opcode(ipc->opc); - switch(op) { + switch (op) { case _try_in: - update_clause_choice_point(NEXTOP(ipc,l), ap_pc PASS_REGS); + update_clause_choice_point(NEXTOP(ipc, l), ap_pc PASS_REGS); if (lu_pred) - return lu_clause(ipc->y_u.l.l, ap); + return lu_clause(ipc->y_u.l.l, ap); else - return (LogUpdClause *)static_clause(ipc->y_u.l.l, ap, unbounded); + return (LogUpdClause *)static_clause(ipc->y_u.l.l, ap, unbounded); break; case _try_clause: #if TABLING case _table_try: #endif if (b0 == NULL) - store_clause_choice_point(Terms[0], Terms[1], Terms[2], NEXTOP(ipc,Otapl), ap, ap_pc, cp_pc PASS_REGS); + store_clause_choice_point(Terms[0], Terms[1], Terms[2], + NEXTOP(ipc, Otapl), ap, ap_pc, + cp_pc PASS_REGS); else { - B = b0; - b0 = NULL; - update_clause_choice_point(NEXTOP(ipc,Otapl), ap_pc PASS_REGS); + B = b0; + b0 = NULL; + update_clause_choice_point(NEXTOP(ipc, Otapl), ap_pc PASS_REGS); } if (lu_pred) - return lu_clause(ipc->y_u.Otapl.d, ap); + return lu_clause(ipc->y_u.Otapl.d, ap); else - return (LogUpdClause *)static_clause(ipc->y_u.Otapl.d, ap, unbounded); + return (LogUpdClause *)static_clause(ipc->y_u.Otapl.d, ap, unbounded); case _try_clause2: case _try_clause3: case _try_clause4: if (b0 == NULL) - store_clause_choice_point(Terms[0], Terms[1], Terms[2], NEXTOP(ipc,l), ap, ap_pc, cp_pc PASS_REGS); + store_clause_choice_point(Terms[0], Terms[1], Terms[2], NEXTOP(ipc, l), + ap, ap_pc, cp_pc PASS_REGS); else { - B = b0; - b0 = NULL; - update_clause_choice_point(NEXTOP(ipc,l), ap_pc PASS_REGS); + B = b0; + b0 = NULL; + update_clause_choice_point(NEXTOP(ipc, l), ap_pc PASS_REGS); } if (lu_pred) - return lu_clause(ipc->y_u.l.l, ap); + return lu_clause(ipc->y_u.l.l, ap); else - return (LogUpdClause *)static_clause(ipc->y_u.l.l, ap, unbounded); + return (LogUpdClause *)static_clause(ipc->y_u.l.l, ap, unbounded); case _try_me: #if TABLING case _table_try_me: #endif if (b0 == NULL) - store_clause_choice_point(Terms[0], Terms[1], Terms[2], ipc->y_u.Otapl.d, ap, ap_pc, cp_pc PASS_REGS); + store_clause_choice_point(Terms[0], Terms[1], Terms[2], + ipc->y_u.Otapl.d, ap, ap_pc, cp_pc PASS_REGS); else { - B = b0; - b0 = NULL; - update_clause_choice_point(ipc->y_u.Otapl.d, ap_pc PASS_REGS); + B = b0; + b0 = NULL; + update_clause_choice_point(ipc->y_u.Otapl.d, ap_pc PASS_REGS); } - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _retry_profiled: case _count_retry: - ipc = NEXTOP(ipc,p); + ipc = NEXTOP(ipc, p); break; case _retry: #if TABLING case _table_retry: #endif - update_clause_choice_point(NEXTOP(ipc,Otapl),ap_pc PASS_REGS); + update_clause_choice_point(NEXTOP(ipc, Otapl), ap_pc PASS_REGS); if (lu_pred) - return lu_clause(ipc->y_u.Otapl.d, ap); + return lu_clause(ipc->y_u.Otapl.d, ap); else - return (LogUpdClause *)static_clause(ipc->y_u.Otapl.d, ap, TRUE); + return (LogUpdClause *)static_clause(ipc->y_u.Otapl.d, ap, TRUE); case _retry2: case _retry3: case _retry4: - update_clause_choice_point(NEXTOP(ipc,l),ap_pc PASS_REGS); + update_clause_choice_point(NEXTOP(ipc, l), ap_pc PASS_REGS); if (lu_pred) - return lu_clause(ipc->y_u.l.l, ap); + return lu_clause(ipc->y_u.l.l, ap); else - return (LogUpdClause *)static_clause(ipc->y_u.l.l, ap, TRUE); + return (LogUpdClause *)static_clause(ipc->y_u.l.l, ap, TRUE); case _retry_me: - update_clause_choice_point(ipc->y_u.Otapl.d,ap_pc PASS_REGS); - ipc = NEXTOP(ipc,Otapl); + update_clause_choice_point(ipc->y_u.Otapl.d, ap_pc PASS_REGS); + ipc = NEXTOP(ipc, Otapl); break; case _trust: #if TABLING case _table_trust: #endif - { - while (POP_CHOICE_POINT(B->cp_b)) - { - POP_EXECUTE(); - } + { + while (POP_CHOICE_POINT(B->cp_b)) { + POP_EXECUTE(); } + } #ifdef YAPOR { - choiceptr cut_pt; - cut_pt = B->cp_b; - CUT_prune_to(cut_pt); - B = cut_pt; + choiceptr cut_pt; + cut_pt = B->cp_b; + CUT_prune_to(cut_pt); + B = cut_pt; } #else B = B->cp_b; #endif /* YAPOR */ b0 = B; if (lu_pred) - return lu_clause(ipc->y_u.Otapl.d, ap); + return lu_clause(ipc->y_u.Otapl.d, ap); else - return (LogUpdClause *)static_clause(ipc->y_u.Otapl.d, ap, TRUE); + return (LogUpdClause *)static_clause(ipc->y_u.Otapl.d, ap, TRUE); case _profiled_trust_me: case _trust_me: case _count_trust_me: @@ -6315,85 +6271,85 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y #endif b0 = B; { - while (POP_CHOICE_POINT(B->cp_b)) - { - POP_EXECUTE(); - } + while (POP_CHOICE_POINT(B->cp_b)) { + POP_EXECUTE(); + } } #ifdef YAPOR { - choiceptr cut_pt; - cut_pt = B->cp_b; - CUT_prune_to(cut_pt); - B = cut_pt; + choiceptr cut_pt; + cut_pt = B->cp_b; + CUT_prune_to(cut_pt); + B = cut_pt; } #else B = B->cp_b; #endif /* YAPOR */ - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; - case _enter_lu_pred: - { - LogUpdIndex *cl = ipc->y_u.Illss.I; - PredEntry *ap = cl->ClPred; + case _enter_lu_pred: { + LogUpdIndex *cl = ipc->y_u.Illss.I; + PredEntry *ap = cl->ClPred; - if (!cl) return NULL; /* in case the index is empty */ - if (ap->LastCallOfPred != LUCALL_EXEC) { - /* - only increment time stamp if we are working on current time - stamp - */ - if (ap->TimeStampOfPred >= TIMESTAMP_RESET) - Yap_UpdateTimestamps(ap); - ap->TimeStampOfPred++; - /* fprintf(stderr,"R %x--%d--%ul\n",ap,ap->TimeStampOfPred,ap->ArityOfPE);*/ - ap->LastCallOfPred = LUCALL_EXEC; - } - *--ASP = MkIntegerTerm(ap->TimeStampOfPred); - /* indicate the indexing code is being used */ -#if MULTIPLE_STACKS - /* just store a reference */ - INC_CLREF_COUNT(cl); - TRAIL_CLREF(cl); -#else - if (!(cl->ClFlags & InUseMask)) { - cl->ClFlags |= InUseMask; - TRAIL_CLREF(cl); - } -#endif + if (!cl) + return NULL; /* in case the index is empty */ + if (ap->LastCallOfPred != LUCALL_EXEC) { + /* + only increment time stamp if we are working on current time + stamp + */ + if (ap->TimeStampOfPred >= TIMESTAMP_RESET) + Yap_UpdateTimestamps(ap); + ap->TimeStampOfPred++; + /* fprintf(stderr,"R + * %x--%d--%ul\n",ap,ap->TimeStampOfPred,ap->ArityOfPE);*/ + ap->LastCallOfPred = LUCALL_EXEC; } + *--ASP = MkIntegerTerm(ap->TimeStampOfPred); +/* indicate the indexing code is being used */ +#if MULTIPLE_STACKS + /* just store a reference */ + INC_CLREF_COUNT(cl); + TRAIL_CLREF(cl); +#else + if (!(cl->ClFlags & InUseMask)) { + cl->ClFlags |= InUseMask; + TRAIL_CLREF(cl); + } +#endif + } ipc = ipc->y_u.Illss.l1; break; case _try_logical: if (b0 == NULL) - store_clause_choice_point(Terms[0], Terms[1], Terms[2], ipc->y_u.OtaLl.n, ap, ap_pc, cp_pc PASS_REGS); + store_clause_choice_point(Terms[0], Terms[1], Terms[2], + ipc->y_u.OtaLl.n, ap, ap_pc, cp_pc PASS_REGS); else { - B = b0; - b0 = NULL; - update_clause_choice_point(ipc->y_u.OtaLl.n, ap_pc PASS_REGS); + B = b0; + b0 = NULL; + update_clause_choice_point(ipc->y_u.OtaLl.n, ap_pc PASS_REGS); } { - UInt timestamp = IntegerOfTerm(((CELL *)(B+1))[5]); - - if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtaLl.d)) { - /* jump to next instruction */ - ipc = ipc->y_u.OtaLl.n; - break; - } + UInt timestamp = IntegerOfTerm(((CELL *)(B + 1))[5]); + + if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtaLl.d)) { + /* jump to next instruction */ + ipc = ipc->y_u.OtaLl.n; + break; + } } return ipc->y_u.OtaLl.d; case _retry_logical: case _profiled_retry_logical: - case _count_retry_logical: - { - UInt timestamp = IntegerOfTerm(((CELL *)(B+1))[5]); - if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtaLl.d)) { - /* jump to next instruction */ - ipc = ipc->y_u.OtaLl.n; - break; - } + case _count_retry_logical: { + UInt timestamp = IntegerOfTerm(((CELL *)(B + 1))[5]); + if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtaLl.d)) { + /* jump to next instruction */ + ipc = ipc->y_u.OtaLl.n; + break; } - update_clause_choice_point(ipc->y_u.OtaLl.n,ap_pc PASS_REGS); + } + update_clause_choice_point(ipc->y_u.OtaLl.n, ap_pc PASS_REGS); return ipc->y_u.OtaLl.d; #if TABLING case _table_try_single: @@ -6401,302 +6357,301 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y #endif case _trust_logical: case _count_trust_logical: - case _profiled_trust_logical: - { - UInt timestamp = IntegerOfTerm(((CELL *)(B+1))[5]); - LogUpdIndex *cl = ipc->y_u.OtILl.block; - LogUpdClause *newpc; + case _profiled_trust_logical: { + UInt timestamp = IntegerOfTerm(((CELL *)(B + 1))[5]); + LogUpdIndex *cl = ipc->y_u.OtILl.block; + LogUpdClause *newpc; - if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtILl.d)) { - /* jump to next instruction */ - newpc = NULL; - } else { - newpc = ipc->y_u.OtILl.d; - } -#if MULTIPLE_STACKS - DEC_CLREF_COUNT(cl); - B->cp_tr--; - TR--; - /* actually get rid of the code */ - if (cl->ClRefCount == 0 && cl->ClFlags & (ErasedMask|DirtyMask)) { - /* I am the last one using this clause, hence I don't need a lock - to dispose of it. But on the other hand I need to make sure - the clause is still there when I am back. - */ - LogUpdClause *lcl = ipc->y_u.OtILl.d; - if (newpc) { - if (lcl->ClRefCount == 1) { - /* make sure the clause isn't destroyed */ - /* always add an extra reference */ - INC_CLREF_COUNT(lcl); - TRAIL_CLREF(lcl); - B->cp_tr = TR; - } - } - if (cl->ClFlags & ErasedMask) { - Yap_ErLogUpdIndex(cl); - } else { - Yap_CleanUpIndex(cl); - } - } -#else - if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) && - B->cp_tr != B->cp_b->cp_tr) { - - B->cp_tr--; - TR--; - cl->ClFlags &= ~InUseMask; - /* next, recover space for the indexing code if it was erased */ - if (cl->ClFlags & (ErasedMask|DirtyMask)) { - LogUpdClause *lcl = ipc->y_u.OtILl.d; - /* make sure we don't erase the clause we are jumping to, notice that - ErLogUpdIndex may remove several references in one go. - Notice we only need to do this if we´ re jumping to the clause. - */ - if (newpc && !(lcl->ClFlags & (DirtyMask|InUseMask))) { - lcl->ClFlags |= InUseMask; - TRAIL_CLREF(lcl); - } - if (cl->ClFlags & ErasedMask) { - Yap_ErLogUpdIndex(cl); - } else { - Yap_CleanUpIndex(cl); - } - } - } -#endif - { - while (POP_CHOICE_POINT(B->cp_b)) - { - POP_EXECUTE(); - } - } -#ifdef YAPOR - { - choiceptr cut_pt; - cut_pt = B->cp_b; - CUT_prune_to(cut_pt); - B = cut_pt; - } -#else - B = B->cp_b; -#endif /* YAPOR */ - b0 = B; - return newpc; + if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtILl.d)) { + /* jump to next instruction */ + newpc = NULL; + } else { + newpc = ipc->y_u.OtILl.d; } +#if MULTIPLE_STACKS + DEC_CLREF_COUNT(cl); + B->cp_tr--; + TR--; + /* actually get rid of the code */ + if (cl->ClRefCount == 0 && cl->ClFlags & (ErasedMask | DirtyMask)) { + /* I am the last one using this clause, hence I don't need a lock + to dispose of it. But on the other hand I need to make sure + the clause is still there when I am back. + */ + LogUpdClause *lcl = ipc->y_u.OtILl.d; + if (newpc) { + if (lcl->ClRefCount == 1) { + /* make sure the clause isn't destroyed */ + /* always add an extra reference */ + INC_CLREF_COUNT(lcl); + TRAIL_CLREF(lcl); + B->cp_tr = TR; + } + } + if (cl->ClFlags & ErasedMask) { + Yap_ErLogUpdIndex(cl); + } else { + Yap_CleanUpIndex(cl); + } + } +#else + if (TrailTerm(B->cp_tr - 1) == CLREF_TO_TRENTRY(cl) && + B->cp_tr != B->cp_b->cp_tr) { + + B->cp_tr--; + TR--; + cl->ClFlags &= ~InUseMask; + /* next, recover space for the indexing code if it was erased */ + if (cl->ClFlags & (ErasedMask | DirtyMask)) { + LogUpdClause *lcl = ipc->y_u.OtILl.d; + /* make sure we don't erase the clause we are jumping to, notice that + ErLogUpdIndex may remove several references in one go. + Notice we only need to do this if we´ re jumping to the clause. + */ + if (newpc && !(lcl->ClFlags & (DirtyMask | InUseMask))) { + lcl->ClFlags |= InUseMask; + TRAIL_CLREF(lcl); + } + if (cl->ClFlags & ErasedMask) { + Yap_ErLogUpdIndex(cl); + } else { + Yap_CleanUpIndex(cl); + } + } + } +#endif + { + while (POP_CHOICE_POINT(B->cp_b)) { + POP_EXECUTE(); + } + } +#ifdef YAPOR + { + choiceptr cut_pt; + cut_pt = B->cp_b; + CUT_prune_to(cut_pt); + B = cut_pt; + } +#else + B = B->cp_b; +#endif /* YAPOR */ + b0 = B; + return newpc; + } case _jump: ipc = ipc->y_u.l.l; break; - case _jump_if_var: - { - Term t = Deref(ARG1); - if (IsVarTerm(t)) { - SET_JLBL(l.l); - ipc = ipc->y_u.l.l; - } else { - ipc = NEXTOP(ipc,l); - } + case _jump_if_var: { + Term t = Deref(ARG1); + if (IsVarTerm(t)) { + SET_JLBL(l.l); + ipc = ipc->y_u.l.l; + } else { + ipc = NEXTOP(ipc, l); } - break; - case _jump_if_nonvar: - { - Term t = Deref(XREGS[arg_from_x(ipc->y_u.xll.x)]); - if (!IsVarTerm(t)) { - SET_JLBL(xll.l1); - ipc = ipc->y_u.xll.l1; - } else { - ipc = NEXTOP(ipc,xll); - } + } break; + case _jump_if_nonvar: { + Term t = Deref(XREGS[arg_from_x(ipc->y_u.xll.x)]); + if (!IsVarTerm(t)) { + SET_JLBL(xll.l1); + ipc = ipc->y_u.xll.l1; + } else { + ipc = NEXTOP(ipc, xll); } - break; + } break; case _user_switch: ipc = ipc->y_u.lp.l; break; - /* instructions type e */ + /* instructions type e */ case _switch_on_type: t = Deref(ARG1); blob_term = FALSE; if (IsVarTerm(t)) { - SET_JLBL(llll.l4); - ipc = ipc->y_u.llll.l4; + SET_JLBL(llll.l4); + ipc = ipc->y_u.llll.l4; } else if (IsPairTerm(t)) { - unbounded = FALSE; - SET_JLBL(llll.l1); - ipc = ipc->y_u.llll.l1; - S = s_reg = RepPair(t); + unbounded = FALSE; + SET_JLBL(llll.l1); + ipc = ipc->y_u.llll.l1; + S = s_reg = RepPair(t); } else if (IsAtomOrIntTerm(t)) { - SET_JLBL(llll.l2); - ipc = ipc->y_u.llll.l2; + SET_JLBL(llll.l2); + ipc = ipc->y_u.llll.l2; } else { - SET_JLBL(llll.l3); - ipc = ipc->y_u.llll.l3; - S = RepAppl(t); + SET_JLBL(llll.l3); + ipc = ipc->y_u.llll.l3; + S = RepAppl(t); } break; case _switch_list_nl: t = Deref(ARG1); blob_term = FALSE; if (IsVarTerm(t)) { - SET_JLBL(ollll.l4); - ipc = ipc->y_u.ollll.l4; + SET_JLBL(ollll.l4); + ipc = ipc->y_u.ollll.l4; } else if (IsPairTerm(t)) { - unbounded = FALSE; - SET_JLBL(ollll.l1); - ipc = ipc->y_u.ollll.l1; - S = s_reg = RepPair(t); + unbounded = FALSE; + SET_JLBL(ollll.l1); + ipc = ipc->y_u.ollll.l1; + S = s_reg = RepPair(t); } else if (t == TermNil) { - unbounded = FALSE; - SET_JLBL(ollll.l2); - ipc = ipc->y_u.ollll.l2; + unbounded = FALSE; + SET_JLBL(ollll.l2); + ipc = ipc->y_u.ollll.l2; } else { - SET_JLBL(ollll.l3); - ipc = ipc->y_u.ollll.l3; - S = RepAppl(t); + SET_JLBL(ollll.l3); + ipc = ipc->y_u.ollll.l3; + S = RepAppl(t); } break; case _switch_on_arg_type: t = Deref(XREGS[arg_from_x(ipc->y_u.xllll.x)]); blob_term = FALSE; if (IsVarTerm(t)) { - SET_JLBL(xllll.l4); - ipc = ipc->y_u.xllll.l4; + SET_JLBL(xllll.l4); + ipc = ipc->y_u.xllll.l4; } else if (IsPairTerm(t)) { - unbounded = FALSE; - SET_JLBL(xllll.l1); - ipc = ipc->y_u.xllll.l1; - S = s_reg = RepPair(t); + unbounded = FALSE; + SET_JLBL(xllll.l1); + ipc = ipc->y_u.xllll.l1; + S = s_reg = RepPair(t); } else if (IsAtomOrIntTerm(t)) { - SET_JLBL(xllll.l2); - ipc = ipc->y_u.xllll.l2; + SET_JLBL(xllll.l2); + ipc = ipc->y_u.xllll.l2; } else { - SET_JLBL(xllll.l3); - ipc = ipc->y_u.xllll.l3; - S = RepAppl(t); + SET_JLBL(xllll.l3); + ipc = ipc->y_u.xllll.l3; + S = RepAppl(t); } break; case _switch_on_sub_arg_type: t = Deref(s_reg[ipc->y_u.sllll.s]); blob_term = FALSE; if (IsVarTerm(t)) { - SET_JLBL(sllll.l4); - ipc = ipc->y_u.sllll.l4; + SET_JLBL(sllll.l4); + ipc = ipc->y_u.sllll.l4; } else if (IsPairTerm(t)) { - unbounded = FALSE; - SET_JLBL(sllll.l1); - S = s_reg = RepPair(t); - ipc = ipc->y_u.sllll.l1; + unbounded = FALSE; + SET_JLBL(sllll.l1); + S = s_reg = RepPair(t); + ipc = ipc->y_u.sllll.l1; } else if (IsAtomOrIntTerm(t)) { - SET_JLBL(sllll.l2); - ipc = ipc->y_u.sllll.l2; + SET_JLBL(sllll.l2); + ipc = ipc->y_u.sllll.l2; } else { - SET_JLBL(sllll.l3); - ipc = ipc->y_u.sllll.l3; - S = RepAppl(t); + SET_JLBL(sllll.l3); + ipc = ipc->y_u.sllll.l3; + S = RepAppl(t); } break; case _if_not_then: t = Deref(ARG1); blob_term = FALSE; if (IsVarTerm(t)) { - SET_JLBL(clll.l3); - ipc = ipc->y_u.clll.l3; + SET_JLBL(clll.l3); + ipc = ipc->y_u.clll.l3; } else if (!IsVarTerm(t) && t != ipc->y_u.clll.c) { - SET_JLBL(clll.l1); - ipc = ipc->y_u.clll.l1; + SET_JLBL(clll.l1); + ipc = ipc->y_u.clll.l1; } else { - SET_JLBL(clll.l2); - ipc = ipc->y_u.clll.l2; + SET_JLBL(clll.l2); + ipc = ipc->y_u.clll.l2; } break; - /* instructions type ollll */ + /* instructions type ollll */ case _switch_on_func: case _if_func: - case _go_on_func: - { - FuncSwiEntry *fe; - Functor f; - - unbounded = FALSE; - s_reg = RepAppl(t); - f = (Functor)s_reg[0]; - s_reg++; - S = s_reg; - if (op == _switch_on_func) { - fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } else { - fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } -#if defined(YAPOR) || defined(THREADS) - jlbl = &(fe->u_f.labp); -#endif - ipc = fe->u_f.labp; + case _go_on_func: { + FuncSwiEntry *fe; + Functor f; + + unbounded = FALSE; + s_reg = RepAppl(t); + f = (Functor)s_reg[0]; + s_reg++; + S = s_reg; + if (op == _switch_on_func) { + fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); + } else { + fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s); } - break; +#if defined(YAPOR) || defined(THREADS) + jlbl = &(fe->u_f.labp); +#endif + ipc = fe->u_f.labp; + } break; case _index_dbref: - t = AbsAppl(s_reg-1); + if (s_reg[-1] != (CELL)FunctorDBREF) { + ipc = FAILCODE; + } + t = AbsAppl(s_reg - 1); blob_term = FALSE; - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _index_blob: + if (s_reg[-1] != (CELL)FunctorBigInt) { + ipc = FAILCODE; + } t = Yap_DoubleP_key(s_reg); blob_term = TRUE; - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _index_long: + if (s_reg[-1] != (CELL)FunctorLongInt) { + ipc = FAILCODE; + } t = Yap_IntP_key(s_reg); blob_term = TRUE; - ipc = NEXTOP(ipc,e); + ipc = NEXTOP(ipc, e); break; case _switch_on_cons: case _if_cons: - case _go_on_cons: - { - AtomSwiEntry *ae; - - unbounded = FALSE; - if (op == _switch_on_cons) { - ae = lookup_c_hash(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } else { - ae = lookup_c(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s); - } -#if defined(YAPOR) || defined(THREADS) - jlbl = &(ae->u_a.labp); -#endif - ipc = ae->u_a.labp; + case _go_on_cons: { + AtomSwiEntry *ae; + + unbounded = FALSE; + if (op == _switch_on_cons) { + ae = lookup_c_hash(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s); + } else { + ae = lookup_c(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s); } - break; +#if defined(YAPOR) || defined(THREADS) + jlbl = &(ae->u_a.labp); +#endif + ipc = ae->u_a.labp; + } break; case _expand_index: case _expand_clauses: if (blob_term) { /* protect garbage collector */ - XREGS[ap->ArityOfPE+1] = (CELL)&XREGS[ap->ArityOfPE+1]; - XREGS[ap->ArityOfPE+2] = TermNil; + XREGS[ap->ArityOfPE + 1] = (CELL)&XREGS[ap->ArityOfPE + 1]; + XREGS[ap->ArityOfPE + 2] = TermNil; } else { - XREGS[ap->ArityOfPE+1] = (CELL)s_reg; - XREGS[ap->ArityOfPE+2] = t; + XREGS[ap->ArityOfPE + 1] = (CELL)s_reg; + XREGS[ap->ArityOfPE + 2] = t; } - XREGS[ap->ArityOfPE+3] = Terms[0]; - XREGS[ap->ArityOfPE+4] = Terms[1]; - XREGS[ap->ArityOfPE+5] = Terms[2]; + XREGS[ap->ArityOfPE + 3] = Terms[0]; + XREGS[ap->ArityOfPE + 4] = Terms[1]; + XREGS[ap->ArityOfPE + 5] = Terms[2]; #if defined(YAPOR) || defined(THREADS) if (!same_lu_block(jlbl, ipc)) { - ipc = *jlbl; - break; + ipc = *jlbl; + break; } #endif ipc = ExpandIndex(ap, 5, cp_pc PASS_REGS); if (!blob_term) { /* protect garbage collector */ - s_reg = (CELL *)XREGS[ap->ArityOfPE+1]; - t = XREGS[ap->ArityOfPE+2]; + s_reg = (CELL *)XREGS[ap->ArityOfPE + 1]; + t = XREGS[ap->ArityOfPE + 2]; } blob_term = FALSE; - Terms[0] = XREGS[ap->ArityOfPE+3]; - Terms[1] = XREGS[ap->ArityOfPE+4]; - Terms[2] = XREGS[ap->ArityOfPE+5]; + Terms[0] = XREGS[ap->ArityOfPE + 3]; + Terms[1] = XREGS[ap->ArityOfPE + 4]; + Terms[2] = XREGS[ap->ArityOfPE + 5]; break; case _undef_p: return NULL; case _lock_lu: - ipc = NEXTOP(ipc,p); + ipc = NEXTOP(ipc, p); break; #if THREADS case _thread_local: @@ -6706,71 +6661,68 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y #endif case _spy_pred: case _lock_pred: - if ((ap->PredFlags & IndexedPredFlag) || - ap->cs.p_code.NOfClauses <= 1) { - ipc = ap->cs.p_code.TrueCodeOfPred; - break; + if ((ap->PredFlags & IndexedPredFlag) || ap->cs.p_code.NOfClauses <= 1) { + ipc = ap->cs.p_code.TrueCodeOfPred; + break; } case _index_pred: if (blob_term) { /* protect garbage collector */ - XREGS[ap->ArityOfPE+1] = (CELL)&XREGS[ap->ArityOfPE+1]; - XREGS[ap->ArityOfPE+2] = TermNil; + XREGS[ap->ArityOfPE + 1] = (CELL)&XREGS[ap->ArityOfPE + 1]; + XREGS[ap->ArityOfPE + 2] = TermNil; } else { - XREGS[ap->ArityOfPE+1] = (CELL)s_reg; - XREGS[ap->ArityOfPE+2] = t; + XREGS[ap->ArityOfPE + 1] = (CELL)s_reg; + XREGS[ap->ArityOfPE + 2] = t; } - XREGS[ap->ArityOfPE+3] = Terms[0]; - XREGS[ap->ArityOfPE+4] = Terms[1]; - XREGS[ap->ArityOfPE+5] = Terms[2]; + XREGS[ap->ArityOfPE + 3] = Terms[0]; + XREGS[ap->ArityOfPE + 4] = Terms[1]; + XREGS[ap->ArityOfPE + 5] = Terms[2]; Yap_IPred(ap, 5, cp_pc); ipc = ap->cs.p_code.TrueCodeOfPred; if (!blob_term) { /* protect garbage collector */ - s_reg = (CELL *)XREGS[ap->ArityOfPE+1]; - t = XREGS[ap->ArityOfPE+2]; + s_reg = (CELL *)XREGS[ap->ArityOfPE + 1]; + t = XREGS[ap->ArityOfPE + 2]; } - Terms[0] = XREGS[ap->ArityOfPE+3]; - Terms[1] = XREGS[ap->ArityOfPE+4]; - Terms[2] = XREGS[ap->ArityOfPE+5]; + Terms[0] = XREGS[ap->ArityOfPE + 3]; + Terms[1] = XREGS[ap->ArityOfPE + 4]; + Terms[2] = XREGS[ap->ArityOfPE + 5]; break; case _op_fail: if (ipc == FAILCODE) - return NULL; + return NULL; default: if (b0) { - { - while (POP_CHOICE_POINT(B->cp_b)) - { - POP_EXECUTE(); - } - } + { + while (POP_CHOICE_POINT(B->cp_b)) { + POP_EXECUTE(); + } + } #ifdef YAPOR - { - choiceptr cut_pt; - cut_pt = B->cp_b; - CUT_prune_to(cut_pt); - B = cut_pt; - } + { + choiceptr cut_pt; + cut_pt = B->cp_b; + CUT_prune_to(cut_pt); + B = cut_pt; + } #else - B = B->cp_b; + B = B->cp_b; #endif /* YAPOR */ - /* I did a trust */ + /* I did a trust */ } if (op == _op_fail) - return NULL; + return NULL; if (lu_pred) - return lu_clause(ipc, ap); + return lu_clause(ipc, ap); else - return (LogUpdClause *)static_clause(ipc, ap, unbounded); + return (LogUpdClause *)static_clause(ipc, ap, unbounded); } } if (b0) { /* I did a trust */ - { - while (POP_CHOICE_POINT(B->cp_b)) - { - POP_EXECUTE(); - } + { + while (POP_CHOICE_POINT(B->cp_b)) { + POP_EXECUTE(); } + } #ifdef YAPOR { choiceptr cut_pt; @@ -6785,13 +6737,9 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y return NULL; } -LogUpdClause * -Yap_NthClause(PredEntry *ap, Int ncls) -{ +LogUpdClause *Yap_NthClause(PredEntry *ap, Int ncls) { CACHE_REGS - yamop - *ipc = ap->cs.p_code.TrueCodeOfPred, - *alt = NULL; + yamop *ipc = ap->cs.p_code.TrueCodeOfPred, *alt = NULL; #if defined(YAPOR) || defined(THREADS) yamop **jlbl = NULL; #endif @@ -6800,22 +6748,22 @@ Yap_NthClause(PredEntry *ap, Int ncls) if (ncls > ap->cs.p_code.NOfClauses) return NULL; else if (ncls == 1) - return to_clause(ap->cs.p_code.FirstClause,ap); + return to_clause(ap->cs.p_code.FirstClause, ap); else if (ap->PredFlags & MegaClausePredFlag) { MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause); /* fast access to nth element, all have same size */ - return (LogUpdClause *)((char *)mcl->ClCode+(ncls-1)*mcl->ClItemSize); + return (LogUpdClause *)((char *)mcl->ClCode + (ncls - 1) * mcl->ClItemSize); } else if (ncls == ap->cs.p_code.NOfClauses) { - return to_clause(ap->cs.p_code.LastClause,ap); + return to_clause(ap->cs.p_code.LastClause, ap); } else if (ncls < 0) return NULL; - + if (ap->ModuleOfPred != IDB_MODULE) { if (ap->ArityOfPE) { UInt i; for (i = 1; i <= ap->ArityOfPE; i++) { - XREGS[i] = MkVarTerm(); + XREGS[i] = MkVarTerm(); } } } else { @@ -6824,39 +6772,46 @@ Yap_NthClause(PredEntry *ap, Int ncls) while (TRUE) { op_numbers op = Yap_op_from_opcode(ipc->opc); - switch(op) { + switch (op) { case _try_in: if (ncls == 1) - return to_clause(ipc->y_u.l.l, ap); + return to_clause(ipc->y_u.l.l, ap); ncls--; - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); break; case _retry_profiled: case _count_retry: - ipc = NEXTOP(ipc,p); + ipc = NEXTOP(ipc, p); case _try_clause: case _retry: if (ncls == 1) - return to_clause(ipc->y_u.Otapl.d, ap); + return to_clause(ipc->y_u.Otapl.d, ap); else if (alt == NULL) { - ncls --; - /* get there in a fell swoop */ - if (ap->PredFlags & ProfiledPredFlag) { - if (ap->PredFlags & CountPredFlag) { - ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP(NEXTOP((yamop *)NULL,Otapl),p),p)); - } else { - ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP((yamop *)NULL,Otapl),p)); - } - } else if (ap->PredFlags & CountPredFlag) { - ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP((yamop *)NULL,Otapl),p)); - } else { - ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP((yamop *)NULL,Otapl)); - } - return to_clause(ipc->y_u.Otapl.d, ap); + ncls--; + /* get there in a fell swoop */ + if (ap->PredFlags & ProfiledPredFlag) { + if (ap->PredFlags & CountPredFlag) { + ipc = (yamop *)((char *)ipc + + ncls * (UInt)NEXTOP( + NEXTOP(NEXTOP((yamop *)NULL, Otapl), p), + p)); + } else { + ipc = + (yamop *)((char *)ipc + + ncls * (UInt)NEXTOP(NEXTOP((yamop *)NULL, Otapl), p)); + } + } else if (ap->PredFlags & CountPredFlag) { + ipc = (yamop *)((char *)ipc + + ncls * (UInt)NEXTOP(NEXTOP((yamop *)NULL, Otapl), p)); + } else { + ipc = (yamop *)((char *)ipc + + ncls * (UInt)NEXTOP((yamop *)NULL, Otapl)); + } + return to_clause(ipc->y_u.Otapl.d, ap); } else { - ncls--; + ncls--; } - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _try_clause2: case _try_clause3: @@ -6865,52 +6820,56 @@ Yap_NthClause(PredEntry *ap, Int ncls) case _retry3: case _retry4: if (ncls == 1) - return to_clause(ipc->y_u.l.l, ap); + return to_clause(ipc->y_u.l.l, ap); else if (alt == NULL) { - ncls --; - /* get there in a fell swoop */ - if (ap->PredFlags & ProfiledPredFlag) { - if (ap->PredFlags & CountPredFlag) { - ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP(NEXTOP((yamop *)NULL,l),p),p)); - } else { - ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP((yamop *)NULL,l),p)); - } - } else if (ap->PredFlags & CountPredFlag) { - ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP(NEXTOP((yamop *)NULL,l),p)); - } else { - ipc = (yamop *)((char *)ipc+ncls*(UInt)NEXTOP((yamop *)NULL,l)); - } - return to_clause(ipc->y_u.l.l, ap); + ncls--; + /* get there in a fell swoop */ + if (ap->PredFlags & ProfiledPredFlag) { + if (ap->PredFlags & CountPredFlag) { + ipc = (yamop *)((char *)ipc + + ncls * (UInt)NEXTOP( + NEXTOP(NEXTOP((yamop *)NULL, l), p), p)); + } else { + ipc = (yamop *)((char *)ipc + + ncls * (UInt)NEXTOP(NEXTOP((yamop *)NULL, l), p)); + } + } else if (ap->PredFlags & CountPredFlag) { + ipc = (yamop *)((char *)ipc + + ncls * (UInt)NEXTOP(NEXTOP((yamop *)NULL, l), p)); + } else { + ipc = (yamop *)((char *)ipc + ncls * (UInt)NEXTOP((yamop *)NULL, l)); + } + return to_clause(ipc->y_u.l.l, ap); } else { - ncls--; + ncls--; } - ipc = NEXTOP(ipc,l); + ipc = NEXTOP(ipc, l); break; case _trust: if (ncls == 1) - return to_clause(ipc->y_u.l.l,ap); + return to_clause(ipc->y_u.l.l, ap); ncls--; ipc = alt; break; case _try_me: case _retry_me: alt = ipc->y_u.Otapl.d; - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _profiled_trust_me: case _trust_me: case _count_trust_me: alt = NULL; - ipc = NEXTOP(ipc,Otapl); + ipc = NEXTOP(ipc, Otapl); break; case _try_logical: case _retry_logical: case _count_retry_logical: case _profiled_retry_logical: if (VALID_TIMESTAMP(ap->TimeStampOfPred, ipc->y_u.OtaLl.d)) { - if (ncls == 1) - return ipc->y_u.OtaLl.d; - ncls--; + if (ncls == 1) + return ipc->y_u.OtaLl.d; + ncls--; } ipc = ipc->y_u.OtaLl.n; break; @@ -6918,8 +6877,8 @@ Yap_NthClause(PredEntry *ap, Int ncls) case _count_trust_logical: case _profiled_trust_logical: if (VALID_TIMESTAMP(ap->TimeStampOfPred, ipc->y_u.OtILl.d)) { - if (ncls == 1) - return ipc->y_u.OtILl.d; + if (ncls == 1) + return ipc->y_u.OtILl.d; } return NULL; case _enter_lu_pred: @@ -6927,7 +6886,7 @@ Yap_NthClause(PredEntry *ap, Int ncls) ipc = ipc->y_u.Illss.l1; break; case _lock_lu: - ipc = NEXTOP(ipc,p); + ipc = NEXTOP(ipc, p); break; case _jump: SET_JLBL(l.l); @@ -6938,13 +6897,13 @@ Yap_NthClause(PredEntry *ap, Int ncls) ipc = ipc->y_u.l.l; break; case _jump_if_nonvar: - ipc = NEXTOP(ipc,xll); + ipc = NEXTOP(ipc, xll); break; case _user_switch: SET_JLBL(l.l); ipc = ipc->y_u.lp.l; break; - /* instructions type e */ + /* instructions type e */ case _switch_on_type: SET_JLBL(llll.l4); ipc = ipc->y_u.llll.l4; @@ -6969,8 +6928,8 @@ Yap_NthClause(PredEntry *ap, Int ncls) case _expand_clauses: #if defined(YAPOR) || defined(THREADS) if (*jlbl != (yamop *)&(ap->cs.p_code.ExpandCode)) { - ipc = *jlbl; - break; + ipc = *jlbl; + break; } #endif ipc = ExpandIndex(ap, 0, CP PASS_REGS); @@ -6992,9 +6951,7 @@ Yap_NthClause(PredEntry *ap, Int ncls) } } -void -Yap_CleanUpIndex(LogUpdIndex *blk) -{ +void Yap_CleanUpIndex(LogUpdIndex *blk) { /* just compact the code */ yamop *start = blk->ClCode; op_numbers op = Yap_op_from_opcode(start->opc); @@ -7010,4 +6967,3 @@ Yap_CleanUpIndex(LogUpdIndex *blk) } remove_dirty_clauses_from_index(start); } -