15 BOp(enter_lu_pred, Illss);
23 if (ap->LastCallOfPred != LUCALL_EXEC) {
28 if (ap->TimeStampOfPred >= TIMESTAMP_RESET)
29 Yap_UpdateTimestamps(ap);
30 ap->TimeStampOfPred++;
31 ap->LastCallOfPred = LUCALL_EXEC;
34 *--YREG = MkIntegerTerm(ap->TimeStampOfPred);
36 PREG = PREG->y_u.Illss.l1;
43 if (!(cl->ClFlags & InUseMask)) {
44 cl->ClFlags |= InUseMask;
52 BOp(profiled_retry_logical, OtaLl);
58#if defined(YAPOR) || defined(THREADS)
59 if (PP != PREG->y_u.OtaLl.d->ClPred) {
60 if (PP) UNLOCKPE(15,PP);
61 PP = PREG->y_u.OtaLl.d->ClPred;
65 timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[PREG->y_u.OtaLl.s]);
66 if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) {
68 PREG=PREG->y_u.OtaLl.n;
71 restore_yaam_regs(PREG->y_u.OtaLl.n);
72 restore_args(PREG->y_u.OtaLl.s);
73 LOCK(PREG->y_u.OtaLl.d->ClPred->StatisticsForPred->lock);
74 PREG->y_u.OtaLl.d->ClPred->StatisticsForPred->NOfRetries++;
75 UNLOCK(PREG->y_u.OtaLl.d->ClPred->StatisticsForPred->lock);
77 PP = PREG->y_u.OtaLl.d->ClPred;
79 PREG = PREG->y_u.OtaLl.d->ClCode;
81 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
82 set_cut(S_YREG, B->cp_b);
84 set_cut(S_YREG, B_YREG->cp_b);
92 BOp(profiled_trust_logical, OtILl);
98 UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]);
100#if defined(YAPOR) || defined(THREADS)
102 if (PP) UNLOCKPE(16,PP);
107 if (!VALID_TIMESTAMP(timestamp, lcl)) {
111 LOCK(ap->StatisticsForPred->lock);
112 ap->StatisticsForPred->NOfRetries++;
113 UNLOCK(ap->StatisticsForPred->lock);
124 if (cl->ClRefCount == 0 && (cl->ClFlags & (ErasedMask|DirtyMask))) {
125 if (PREG != FAILCODE) {
129 if (lcl->ClRefCount == 1) {
132 INC_CLREF_COUNT(lcl);
136 if (cl->ClFlags & ErasedMask) {
138 Yap_ErLogUpdIndex(cl);
142 Yap_CleanUpIndex(cl);
148 if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) &&
149 B->cp_tr != B->cp_b->cp_tr) {
150 cl->ClFlags &= ~InUseMask;
153 if (B->cp_tr > TR_FZ)
159 if (cl->ClFlags & (ErasedMask|DirtyMask)) {
160 if (PREG != FAILCODE) {
163 if (!(lcl->ClFlags & InUseMask)) {
164 lcl->ClFlags |= InUseMask;
168 if (cl->ClFlags & ErasedMask) {
170 Yap_ErLogUpdIndex(cl);
174 Yap_CleanUpIndex(cl);
182 if (SCH_top_shared_cp(B)) {
183 SCH_last_alternative(PREG, B_YREG);
184 restore_args(ap->ArityOfPE);
186 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
190 set_cut(S_YREG, B->cp_b);
195 pop_args(ap->ArityOfPE);
198 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
208 BOp(try_logical, OtaLl);
214 timestamp = IntegerOfTerm(S_YREG[0]);
218 store_args(PREG->y_u.OtaLl.s);
219 store_yaam_regs(PREG->y_u.OtaLl.n, 0);
223 SCH_set_load(B_YREG);
226 PP = PREG->y_u.OtaLl.d->ClPred;
228 if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) {
230 PREG=PREG->y_u.OtaLl.n;
232 PREG = PREG->y_u.OtaLl.d->ClCode;
240 BOp(count_retry_logical, OtaLl);
246#if defined(YAPOR) || defined(THREADS)
247 if (PP != PREG->y_u.OtaLl.d->ClPred) {
248 if (PP) UNLOCKPE(15,PP);
249 PP = PREG->y_u.OtaLl.d->ClPred;
253 timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[PREG->y_u.OtaLl.s]);
254 if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) {
256 PREG=PREG->y_u.OtaLl.n;
259 restore_yaam_regs(PREG->y_u.OtaLl.n);
260 restore_args(PREG->y_u.OtaLl.s);
261 LOCAL_RetriesCounter--;
262 if (LOCAL_RetriesCounter == 0) {
264 Yap_NilError(RETRY_COUNTER_UNDERFLOW_EVENT,
"");
268 LOCAL_PredEntriesCounter--;
269 if (LOCAL_PredEntriesCounter == 0) {
271 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT,
"");
275 LOCK(PREG->y_u.OtaLl.d->ClPred->StatisticsForPred->lock);
276 PREG->y_u.OtaLl.d->ClPred->StatisticsForPred->NOfRetries++;
277 UNLOCK(PREG->y_u.OtaLl.d->ClPred->StatisticsForPred->lock);
279 PP = PREG->y_u.OtaLl.d->ClPred;
281 PREG = PREG->y_u.OtaLl.d->ClCode;
283 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
284 set_cut(S_YREG, B->cp_b);
286 set_cut(S_YREG, B_YREG->cp_b);
294 BOp(count_trust_logical, OtILl);
300 UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]);
302#if defined(YAPOR) || defined(THREADS)
304 if (PP) UNLOCKPE(16,PP);
309 if (!VALID_TIMESTAMP(timestamp, lcl)) {
313 LOCAL_RetriesCounter--;
314 if (LOCAL_RetriesCounter == 0) {
316 Yap_NilError(RETRY_COUNTER_UNDERFLOW_EVENT,
"");
320 LOCAL_PredEntriesCounter--;
321 if (LOCAL_PredEntriesCounter == 0) {
323 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT,
"");
327 LOCK(ap->StatisticsForPred->lock);
328 ap->StatisticsForPred->NOfRetries++;
329 UNLOCK(ap->StatisticsForPred->lock);
342 if (cl->ClRefCount == 0 && (cl->ClFlags & (ErasedMask|DirtyMask))) {
343 if (PREG != FAILCODE) {
347 if (lcl->ClRefCount == 1) {
350 INC_CLREF_COUNT(lcl);
354 if (cl->ClFlags & ErasedMask) {
356 Yap_ErLogUpdIndex(cl);
360 Yap_CleanUpIndex(cl);
366 if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) &&
367 B->cp_tr != B->cp_b->cp_tr) {
368 cl->ClFlags &= ~InUseMask;
371 if (B->cp_tr > TR_FZ)
377 if (cl->ClFlags & (ErasedMask|DirtyMask)) {
378 if (PREG != FAILCODE) {
380 if (!(lcl->ClFlags & InUseMask)) {
381 lcl->ClFlags |= InUseMask;
385 if (cl->ClFlags & ErasedMask) {
387 Yap_ErLogUpdIndex(cl);
391 Yap_CleanUpIndex(cl);
399 if (SCH_top_shared_cp(B)) {
400 SCH_last_alternative(PREG, B_YREG);
401 restore_args(ap->ArityOfPE);
403 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
407 set_cut(S_YREG, B->cp_b);
412 pop_args(ap->ArityOfPE);
415 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
427 BOp(retry_logical, OtaLl);
433#if defined(YAPOR) || defined(THREADS)
434 if (PP != PREG->y_u.OtaLl.d->ClPred) {
435 if (PP) UNLOCKPE(15,PP);
436 PP = PREG->y_u.OtaLl.d->ClPred;
440 timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[PREG->y_u.OtaLl.s]);
442 if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) {
444 PREG=PREG->y_u.OtaLl.n;
447 restore_yaam_regs(PREG->y_u.OtaLl.n);
448 restore_at_least_one_arg(PREG->y_u.OtaLl.s);
450 PP = PREG->y_u.OtaLl.d->ClPred;
452 PREG = PREG->y_u.OtaLl.d->ClCode;
454 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
455 set_cut(S_YREG, B->cp_b);
457 set_cut(S_YREG, B_YREG->cp_b);
465 BOp(trust_logical, OtILl);
471 UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]);
474#if defined(YAPOR) || defined(THREADS)
476 if (PP) UNLOCKPE(16,PP);
481 if (!VALID_TIMESTAMP(timestamp, lcl)) {
495 if (cl->ClRefCount == 0 && (cl->ClFlags & (ErasedMask|DirtyMask))) {
496 if (PREG != FAILCODE) {
497 if (lcl->ClRefCount == 1) {
500 INC_CLREF_COUNT(lcl);
505 if (cl->ClFlags & ErasedMask) {
507 Yap_ErLogUpdIndex(cl);
511 Yap_CleanUpIndex(cl);
517 if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) &&
518 B->cp_tr != B->cp_b->cp_tr) {
519 cl->ClFlags &= ~InUseMask;
522 if (B->cp_tr > TR_FZ)
528 if (cl->ClFlags & (ErasedMask|DirtyMask)) {
529 if (PREG != FAILCODE) {
531 if (!(lcl->ClFlags & InUseMask)) {
532 lcl->ClFlags |= InUseMask;
537 if (cl->ClFlags & ErasedMask) {
539 Yap_ErLogUpdIndex(cl);
543 Yap_CleanUpIndex(cl);
550 if (SCH_top_shared_cp(B)) {
551 SCH_last_alternative(PREG, B_YREG);
552 restore_args(ap->ArityOfPE);
554 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
558 set_cut(S_YREG, B->cp_b);
563 pop_args(ap->ArityOfPE);
566 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
572#if defined(YAPOR) || defined(THREADS)
573 if (PREG == FAILCODE) {
598 PREG = NEXTOP(PREG, p);
605#if defined(YAPOR) || defined(THREADS)
611 PREG = NEXTOP(PREG, e);
617 BOp(alloc_for_logical_pred, L);
637 if (!(cl->ClFlags & InUseMask)) {
638 cl->ClFlags |= InUseMask;
643 PREG = NEXTOP(PREG, L);
648 BOp(copy_idb_term, e);
655 while ((t = Yap_FetchTermFromDB(cl->lusl.ClSource)) == 0L) {
656 if (PP) UNLOCKPE(3,PP);
657#if defined(YAPOR) || defined(THREADS)
660 if (LOCAL_Error_TYPE == RESOURCE_ERROR_ATTRIBUTED_VARIABLES) {
661 LOCAL_Error_TYPE = YAP_NO_ERROR;
662 if (!Yap_growglobal(NULL)) {
663 Yap_NilError(RESOURCE_ERROR_ATTRIBUTED_VARIABLES, LOCAL_ErrorMessage);
667 LOCAL_Error_TYPE = YAP_NO_ERROR;
669 Yap_track_cpred(_copy_idb_term, P, 0, &info);
670 if (!Yap_gc(&info)) {
671 Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
675#if defined(YAPOR) || defined(THREADS)
676 PELOCK(5,ClauseCodeToLogUpdClause(PREG)->ClPred);
677 PP = ClauseCodeToLogUpdClause(PREG)->ClPred;
680 if (!Yap_IUnify(ARG2, t)) {
682#if defined(YAPOR) || defined(THREADS)
683 if (PP) UNLOCKPE(6,PP);
688 if (!Yap_IUnify(ARG3, MkDBRefTerm((
DBRef)cl))) {
690#if defined(YAPOR) || defined(THREADS)
691 if (PP) UNLOCKPE(5,PP);
702 if (PP) UNLOCKPE(7,PP);
705 if (!(cl->ClFlags & InUseMask)) {
710 cl->ClFlags |= InUseMask;
718 DEPTH = YREG[E_DEPTH];
725 BOp(unify_idb_term, e);
730 if (!Yap_IUnify(ARG2, cl->lusl.ClSource->Entry)) {
733#if defined(YAPOR) || defined(THREADS)
738 if (!Yap_IUnify(ARG3, MkDBRefTerm((
DBRef)cl))) {
741#if defined(YAPOR) || defined(THREADS)
757 if (!(cl->ClFlags & InUseMask)) {
762 cl->ClFlags |= InUseMask;
770 DEPTH = YREG[E_DEPTH];