YAP 7.1.0
lu_absmi_insts.h
1/************************************************************************\
2 * Logical Updates *
3\************************************************************************/
4
5#ifdef INDENT_CODE
6{
7 {
8#endif /* INDENT_CODE */
9
10 /************************************************************************\
11 * Logical Updates *
12\************************************************************************/
13
14 /* enter logical pred */
15 BOp(enter_lu_pred, Illss);
16 check_trail(TR);
17 /* mark the indexing code */
18 {
19 LogUpdIndex *cl = PREG->y_u.Illss.I;
20 PredEntry *ap = cl->ClPred;
21
22 if (!cl) { FAIL(); } /* in case the index is empty */
23 if (ap->LastCallOfPred != LUCALL_EXEC) {
24 /*
25 only increment time stamp if we are working on current time
26 stamp
27 */
28 if (ap->TimeStampOfPred >= TIMESTAMP_RESET)
29 Yap_UpdateTimestamps(ap);
30 ap->TimeStampOfPred++;
31 ap->LastCallOfPred = LUCALL_EXEC;
32 /* fprintf(stderr,"R %x--%d--%ul\n",ap,ap->TimeStampOfPred,ap->ArityOfPE);*/
33 }
34 *--YREG = MkIntegerTerm(ap->TimeStampOfPred);
35 /* fprintf(stderr,"> %p/%p %d %d\n",cl,ap,ap->TimeStampOfPred,PREG->y_u.Illss.s);*/
36 PREG = PREG->y_u.Illss.l1;
37 /* indicate the indexing code is being used */
38#if MULTIPLE_STACKS
39 /* just store a reference */
40 INC_CLREF_COUNT(cl);
41 TRAIL_CLREF(cl);
42#else
43 if (!(cl->ClFlags & InUseMask)) {
44 cl->ClFlags |= InUseMask;
45 TRAIL_CLREF(cl);
46 }
47#endif
48 }
49 JMPNext();
50 ENDBOp();
51
52 BOp(profiled_retry_logical, OtaLl);
53 check_trail(TR);
54 {
55 UInt timestamp;
56 CACHE_Y(B);
57
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;
62 PELOCK(15,PP);
63 }
64#endif
65 timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[PREG->y_u.OtaLl.s]);
66 if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) {
67 /* jump to next instruction */
68 PREG=PREG->y_u.OtaLl.n;
69 JMPNext();
70 }
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);
76#ifdef THREADS
77 PP = PREG->y_u.OtaLl.d->ClPred;
78#endif
79 PREG = PREG->y_u.OtaLl.d->ClCode;
80#ifdef FROZEN_STACKS
81 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
82 set_cut(S_YREG, B->cp_b);
83#else
84 set_cut(S_YREG, B_YREG->cp_b);
85#endif /* FROZEN_STACKS */
86 SET_BB(B_YREG);
87 ENDCACHE_Y();
88 }
89 JMPNext();
90 ENDBOp();
91
92 BOp(profiled_trust_logical, OtILl);
93 CACHE_Y(B);
94 {
95 LogUpdIndex *cl = PREG->y_u.OtILl.block;
96 PredEntry *ap = cl->ClPred;
97 LogUpdClause *lcl = PREG->y_u.OtILl.d;
98 UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]);
99
100#if defined(YAPOR) || defined(THREADS)
101 if (PP != ap) {
102 if (PP) UNLOCKPE(16,PP);
103 PP = ap;
104 PELOCK(16,PP);
105 }
106#endif
107 if (!VALID_TIMESTAMP(timestamp, lcl)) {
108 /* jump to next alternative */
109 PREG = FAILCODE;
110 } else {
111 LOCK(ap->StatisticsForPred->lock);
112 ap->StatisticsForPred->NOfRetries++;
113 UNLOCK(ap->StatisticsForPred->lock);
114 PREG = lcl->ClCode;
115 }
116 /* HEY, leave indexing block alone!! */
117 /* check if we are the ones using this code */
118#if MULTIPLE_STACKS
119 DEC_CLREF_COUNT(cl);
120 /* clear the entry from the trail */
121 B->cp_tr--;
122 TR = B->cp_tr;
123 /* actually get rid of the code */
124 if (cl->ClRefCount == 0 && (cl->ClFlags & (ErasedMask|DirtyMask))) {
125 if (PREG != FAILCODE) {
126 /* I am the last one using this clause, hence I don't need a lock
127 to dispose of it
128 */
129 if (lcl->ClRefCount == 1) {
130 /* make sure the clause isn't destroyed */
131 /* always add an extra reference */
132 INC_CLREF_COUNT(lcl);
133 TRAIL_CLREF(lcl);
134 }
135 }
136 if (cl->ClFlags & ErasedMask) {
137 saveregs();
138 Yap_ErLogUpdIndex(cl);
139 setregs();
140 } else {
141 saveregs();
142 Yap_CleanUpIndex(cl);
143 setregs();
144 }
145 save_pc();
146 }
147#else
148 if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) &&
149 B->cp_tr != B->cp_b->cp_tr) {
150 cl->ClFlags &= ~InUseMask;
151 --B->cp_tr;
152#if FROZEN_STACKS
153 if (B->cp_tr > TR_FZ)
154#endif
155 {
156 TR = B->cp_tr;
157 }
158 /* next, recover space for the indexing code if it was erased */
159 if (cl->ClFlags & (ErasedMask|DirtyMask)) {
160 if (PREG != FAILCODE) {
161 /* make sure we don't erase the clause we are jumping to,
162 notice that we can erase a number of refs in one go. */
163 if (!(lcl->ClFlags & InUseMask)) {
164 lcl->ClFlags |= InUseMask;
165 TRAIL_CLREF(lcl);
166 }
167 }
168 if (cl->ClFlags & ErasedMask) {
169 saveregs();
170 Yap_ErLogUpdIndex(cl);
171 setregs();
172 } else {
173 saveregs();
174 Yap_CleanUpIndex(cl);
175 setregs();
176 }
177 save_pc();
178 }
179 }
180#endif
181#ifdef YAPOR
182 if (SCH_top_shared_cp(B)) {
183 SCH_last_alternative(PREG, B_YREG);
184 restore_args(ap->ArityOfPE);
185#ifdef FROZEN_STACKS
186 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
187#else
188 S_YREG++;
189#endif /* FROZEN_STACKS */
190 set_cut(S_YREG, B->cp_b);
191 } else
192#endif /* YAPOR */
193 {
194 pop_yaam_regs();
195 pop_args(ap->ArityOfPE);
196 S_YREG--;
197#ifdef FROZEN_STACKS
198 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
199#endif /* FROZEN_STACKS */
200 set_cut(S_YREG, B);
201 }
202 SET_BB(B_YREG);
203 ENDCACHE_Y();
204 JMPNext();
205 }
206 ENDBOp();
207
208 BOp(try_logical, OtaLl);
209 check_trail(TR);
210 {
211 UInt timestamp;
212
213 CACHE_Y(YREG);
214 timestamp = IntegerOfTerm(S_YREG[0]);
215 /* fprintf(stderr,"+ %p/%p %d %d %d--%u\n",PREG,PREG->y_u.OtaLl.d->ClPred,timestamp,PREG->y_u.OtaLl.d->ClPred->TimeStampOfPred,PREG->y_u.OtaLl.d->ClTimeStart,PREG->y_u.OtaLl.d->ClTimeEnd);*/
216 /* Point AP to the code that follows this instruction */
217 /* always do this, even if we are not going to use it */
218 store_args(PREG->y_u.OtaLl.s);
219 store_yaam_regs(PREG->y_u.OtaLl.n, 0);
220 set_cut(S_YREG, B);
221 B = B_YREG;
222#ifdef YAPOR
223 SCH_set_load(B_YREG);
224#endif /* YAPOR */
225#ifdef YAPOR
226 PP = PREG->y_u.OtaLl.d->ClPred;
227#endif /* YAPOR */
228 if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) {
229 /* jump to next alternative */
230 PREG=PREG->y_u.OtaLl.n;
231 } else {
232 PREG = PREG->y_u.OtaLl.d->ClCode;
233 }
234 SET_BB(B_YREG);
235 ENDCACHE_Y();
236 }
237 JMPNext();
238 ENDBOp();
239
240 BOp(count_retry_logical, OtaLl);
241 check_trail(TR);
242 {
243 UInt timestamp;
244 CACHE_Y(B);
245
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;
250 PELOCK(15,PP);
251 }
252#endif
253 timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[PREG->y_u.OtaLl.s]);
254 if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) {
255 /* jump to next instruction */
256 PREG=PREG->y_u.OtaLl.n;
257 JMPNext();
258 }
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) {
263 saveregs();
264 Yap_NilError(RETRY_COUNTER_UNDERFLOW_EVENT,"");
265 setregs();
266 JMPNext();
267 }
268 LOCAL_PredEntriesCounter--;
269 if (LOCAL_PredEntriesCounter == 0) {
270 saveregs();
271 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT,"");
272 setregs();
273 JMPNext();
274 }
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);
278#ifdef THREADS
279 PP = PREG->y_u.OtaLl.d->ClPred;
280#endif
281 PREG = PREG->y_u.OtaLl.d->ClCode;
282#ifdef FROZEN_STACKS
283 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
284 set_cut(S_YREG, B->cp_b);
285#else
286 set_cut(S_YREG, B_YREG->cp_b);
287#endif /* FROZEN_STACKS */
288 SET_BB(B_YREG);
289 ENDCACHE_Y();
290 }
291 JMPNext();
292 ENDBOp();
293
294 BOp(count_trust_logical, OtILl);
295 CACHE_Y(B);
296 {
297 LogUpdIndex *cl = PREG->y_u.OtILl.block;
298 PredEntry *ap = cl->ClPred;
299 LogUpdClause *lcl = PREG->y_u.OtILl.d;
300 UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]);
301
302#if defined(YAPOR) || defined(THREADS)
303 if (PP != ap) {
304 if (PP) UNLOCKPE(16,PP);
305 PP = ap;
306 PELOCK(16,PP);
307 }
308#endif
309 if (!VALID_TIMESTAMP(timestamp, lcl)) {
310 /* jump to next alternative */
311 PREG = FAILCODE;
312 } else {
313 LOCAL_RetriesCounter--;
314 if (LOCAL_RetriesCounter == 0) {
315 saveregs();
316 Yap_NilError(RETRY_COUNTER_UNDERFLOW_EVENT,"");
317 setregs();
318 JMPNext();
319 }
320 LOCAL_PredEntriesCounter--;
321 if (LOCAL_PredEntriesCounter == 0) {
322 saveregs();
323 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT,"");
324 setregs();
325 JMPNext();
326 }
327 LOCK(ap->StatisticsForPred->lock);
328 ap->StatisticsForPred->NOfRetries++;
329 UNLOCK(ap->StatisticsForPred->lock);
330 PREG = lcl->ClCode;
331 }
332 /* HEY, leave indexing block alone!! */
333 /* check if we are the ones using this code */
334#if MULTIPLE_STACKS
335 PELOCK(2, ap);
336 PP = ap;
337 DEC_CLREF_COUNT(cl);
338 /* clear the entry from the trail */
339 --B->cp_tr;
340 TR = B->cp_tr;
341 /* actually get rid of the code */
342 if (cl->ClRefCount == 0 && (cl->ClFlags & (ErasedMask|DirtyMask))) {
343 if (PREG != FAILCODE) {
344 /* I am the last one using this clause, hence I don't need a lock
345 to dispose of it
346 */
347 if (lcl->ClRefCount == 1) {
348 /* make sure the clause isn't destroyed */
349 /* always add an extra reference */
350 INC_CLREF_COUNT(lcl);
351 TRAIL_CLREF(lcl);
352 }
353 }
354 if (cl->ClFlags & ErasedMask) {
355 saveregs();
356 Yap_ErLogUpdIndex(cl);
357 setregs();
358 } else {
359 saveregs();
360 Yap_CleanUpIndex(cl);
361 setregs();
362 }
363 save_pc();
364 }
365#else
366 if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) &&
367 B->cp_tr != B->cp_b->cp_tr) {
368 cl->ClFlags &= ~InUseMask;
369 --B->cp_tr;
370#if FROZEN_STACKS
371 if (B->cp_tr > TR_FZ)
372#endif
373 {
374 TR = B->cp_tr;
375 }
376 /* next, recover space for the indexing code if it was erased */
377 if (cl->ClFlags & (ErasedMask|DirtyMask)) {
378 if (PREG != FAILCODE) {
379 /* make sure we don't erase the clause we are jumping too */
380 if (!(lcl->ClFlags & InUseMask)) {
381 lcl->ClFlags |= InUseMask;
382 TRAIL_CLREF(lcl);
383 }
384 }
385 if (cl->ClFlags & ErasedMask) {
386 saveregs();
387 Yap_ErLogUpdIndex(cl);
388 setregs();
389 } else {
390 saveregs();
391 Yap_CleanUpIndex(cl);
392 setregs();
393 }
394 save_pc();
395 }
396 }
397#endif
398#ifdef YAPOR
399 if (SCH_top_shared_cp(B)) {
400 SCH_last_alternative(PREG, B_YREG);
401 restore_args(ap->ArityOfPE);
402#ifdef FROZEN_STACKS
403 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
404#else
405 S_YREG++;
406#endif /* FROZEN_STACKS */
407 set_cut(S_YREG, B->cp_b);
408 } else
409#endif /* YAPOR */
410 {
411 pop_yaam_regs();
412 pop_args(ap->ArityOfPE);
413 S_YREG--;
414#ifdef FROZEN_STACKS
415 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
416#endif /* FROZEN_STACKS */
417 set_cut(S_YREG, B);
418 }
419 SET_BB(B_YREG);
420 ENDCACHE_Y();
421 JMPNext();
422 }
423 ENDBOp();
424
425
426
427 BOp(retry_logical, OtaLl);
428 check_trail(TR);
429 {
430 UInt timestamp;
431 CACHE_Y(B);
432
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;
437 PELOCK(15,PP);
438 }
439#endif
440 timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[PREG->y_u.OtaLl.s]);
441 /* fprintf(stderr,"^ %p/%p %d %d %d--%u\n",PREG,PREG->y_u.OtaLl.d->ClPred,timestamp,PREG->y_u.OtaLl.d->ClPred->TimeStampOfPred,PREG->y_u.OtaLl.d->ClTimeStart,PREG->y_u.OtaLl.d->ClTimeEnd);*/
442 if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) {
443 /* jump to next instruction */
444 PREG=PREG->y_u.OtaLl.n;
445 JMPNext();
446 }
447 restore_yaam_regs(PREG->y_u.OtaLl.n);
448 restore_at_least_one_arg(PREG->y_u.OtaLl.s);
449#ifdef THREADS
450 PP = PREG->y_u.OtaLl.d->ClPred;
451#endif
452 PREG = PREG->y_u.OtaLl.d->ClCode;
453#ifdef FROZEN_STACKS
454 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
455 set_cut(S_YREG, B->cp_b);
456#else
457 set_cut(S_YREG, B_YREG->cp_b);
458#endif /* FROZEN_STACKS */
459 SET_BB(B_YREG);
460 ENDCACHE_Y();
461 }
462 JMPNext();
463 ENDBOp();
464
465 BOp(trust_logical, OtILl);
466 CACHE_Y(B);
467 {
468 LogUpdIndex *cl = PREG->y_u.OtILl.block;
469 PredEntry *ap = cl->ClPred;
470 LogUpdClause *lcl = PREG->y_u.OtILl.d;
471 UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]);
472
473 /* fprintf(stderr,"- %p/%p %d %d %p\n",PREG,ap,timestamp,ap->TimeStampOfPred,PREG->y_u.OtILl.d->ClCode);*/
474#if defined(YAPOR) || defined(THREADS)
475 if (PP != ap) {
476 if (PP) UNLOCKPE(16,PP);
477 PP = ap;
478 PELOCK(16,PP);
479 }
480#endif
481 if (!VALID_TIMESTAMP(timestamp, lcl)) {
482 /* jump to next alternative */
483 PREG = FAILCODE;
484 } else {
485 PREG = lcl->ClCode;
486 }
487 /* HEY, leave indexing block alone!! */
488 /* check if we are the ones using this code */
489#if MULTIPLE_STACKS
490 DEC_CLREF_COUNT(cl);
491 /* clear the entry from the trail */
492 B->cp_tr--;
493 TR = B->cp_tr;
494 /* actually get rid of the code */
495 if (cl->ClRefCount == 0 && (cl->ClFlags & (ErasedMask|DirtyMask))) {
496 if (PREG != FAILCODE) {
497 if (lcl->ClRefCount == 1) {
498 /* make sure the clause isn't destroyed */
499 /* always add an extra reference */
500 INC_CLREF_COUNT(lcl);
501 TRAIL_CLREF(lcl);
502 B->cp_tr = TR;
503 }
504 }
505 if (cl->ClFlags & ErasedMask) {
506 saveregs();
507 Yap_ErLogUpdIndex(cl);
508 setregs();
509 } else {
510 saveregs();
511 Yap_CleanUpIndex(cl);
512 setregs();
513 }
514 save_pc();
515 }
516#else
517 if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) &&
518 B->cp_tr != B->cp_b->cp_tr) {
519 cl->ClFlags &= ~InUseMask;
520 B->cp_tr--;
521#if FROZEN_STACKS
522 if (B->cp_tr > TR_FZ)
523#endif
524 {
525 TR = B->cp_tr;
526 }
527 /* next, recover space for the indexing code if it was erased */
528 if (cl->ClFlags & (ErasedMask|DirtyMask)) {
529 if (PREG != FAILCODE) {
530 /* make sure we don't erase the clause we are jumping too */
531 if (!(lcl->ClFlags & InUseMask)) {
532 lcl->ClFlags |= InUseMask;
533 TRAIL_CLREF(lcl);
534 B->cp_tr = TR;
535 }
536 }
537 if (cl->ClFlags & ErasedMask) {
538 saveregs();
539 Yap_ErLogUpdIndex(cl);
540 setregs();
541 } else {
542 saveregs();
543 Yap_CleanUpIndex(cl);
544 setregs();
545 }
546 }
547 }
548#endif
549#ifdef YAPOR
550 if (SCH_top_shared_cp(B)) {
551 SCH_last_alternative(PREG, B_YREG);
552 restore_args(ap->ArityOfPE);
553#ifdef FROZEN_STACKS
554 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
555#else
556 S_YREG++;
557#endif /* FROZEN_STACKS */
558 set_cut(S_YREG, B->cp_b);
559 } else
560#endif /* YAPOR */
561 {
562 pop_yaam_regs();
563 pop_args(ap->ArityOfPE);
564 S_YREG--;
565#ifdef FROZEN_STACKS
566 S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG);
567#endif /* FROZEN_STACKS */
568 set_cut(S_YREG, B);
569 }
570 SET_BB(B_YREG);
571 ENDCACHE_Y();
572#if defined(YAPOR) || defined(THREADS)
573 if (PREG == FAILCODE) {
574 UNLOCKPE(26,PP);
575 PP = NULL;
576 }
577#endif
578 JMPNext();
579 }
580 ENDBOp();
581
582
583
584 /*****************************************************************
585 * enter a logical semantics dynamic predicate *
586 *****************************************************************/
587
588 /* only meaningful with THREADS on! */
589 /* lock logical updates predicate. */
590 Op(lock_lu, p);
591#if PARALLEL_YAP
592 if (PP) {
593 GONext();
594 }
595 PP = PREG->y_u.p.p;
596 PELOCK(3, PP);
597#endif
598 PREG = NEXTOP(PREG, p);
599 GONext();
600 ENDOp();
601
602 /* only meaningful with THREADS on! */
603 /* lock logical updates predicate. */
604 Op(unlock_lu, e);
605#if defined(YAPOR) || defined(THREADS)
606 if (PP) {
607 UNLOCKPE(1,PP);
608 PP = NULL;
609 }
610#endif
611 PREG = NEXTOP(PREG, e);
612 GONext();
613 ENDOp();
614
615
616 /* enter logical pred */
617 BOp(alloc_for_logical_pred, L);
618 check_trail(TR);
619 /* say that an environment is using this clause */
620 /* we have our own copy for the clause */
621#if MULTIPLE_STACKS
622 {
623 LogUpdClause *cl = PREG->y_u.L.ClBase;
624#if PARALLEL_YAP
625 PredEntry *ap = cl->ClPred;
626#endif
627
628 /* always add an extra reference */
629 INC_CLREF_COUNT(cl);
630 TRAIL_CLREF(cl);
631 UNLOCKPE(2,ap);
632 PP = NULL;
633 }
634#else
635 {
636 LogUpdClause *cl = (LogUpdClause *)PREG->y_u.L.ClBase;
637 if (!(cl->ClFlags & InUseMask)) {
638 cl->ClFlags |= InUseMask;
639 TRAIL_CLREF(cl);
640 }
641 }
642#endif
643 PREG = NEXTOP(PREG, L);
644 JMPNext();
645 ENDBOp();
646
647 /* copy database term */
648 BOp(copy_idb_term, e);
649 {
650 LogUpdClause *cl = ClauseCodeToLogUpdClause(PREG);
651 Term t;
652
653 SET_ASP(YREG, E_CB);
654 saveregs();
655 while ((t = Yap_FetchTermFromDB(cl->lusl.ClSource)) == 0L) {
656 if (PP) UNLOCKPE(3,PP);
657#if defined(YAPOR) || defined(THREADS)
658 PP = NULL;
659#endif
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);
664 FAIL();
665 }
666 } else {
667 LOCAL_Error_TYPE = YAP_NO_ERROR;
668 gc_entry_info_t info;
669 Yap_track_cpred(_copy_idb_term, P, 0, &info);
670 if (!Yap_gc(&info)) {
671 Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
672 FAIL();
673 }
674 }
675#if defined(YAPOR) || defined(THREADS)
676 PELOCK(5,ClauseCodeToLogUpdClause(PREG)->ClPred);
677 PP = ClauseCodeToLogUpdClause(PREG)->ClPred;
678#endif
679 }
680 if (!Yap_IUnify(ARG2, t)) {
681 setregs();
682#if defined(YAPOR) || defined(THREADS)
683 if (PP) UNLOCKPE(6,PP);
684 PP = NULL;
685#endif
686 FAIL();
687 }
688 if (!Yap_IUnify(ARG3, MkDBRefTerm((DBRef)cl))) {
689 setregs();
690#if defined(YAPOR) || defined(THREADS)
691 if (PP) UNLOCKPE(5,PP);
692 PP = NULL;
693#endif
694 FAIL();
695 }
696 setregs();
697
698#if MULTIPLE_STACKS
699 /* always add an extra reference */
700 INC_CLREF_COUNT(cl);
701 TRAIL_CLREF(cl);
702 if (PP) UNLOCKPE(7,PP);
703 PP = NULL;
704#else
705 if (!(cl->ClFlags & InUseMask)) {
706 /* Clause *cl = (Clause *)PREG->y_u.EC.ClBase;
707
708 PREG->y_u.EC.ClTrail = TR-(tr_fr_ptr)LOCAL_TrailBase;
709 PREG->y_u.EC.ClENV = LCL0-YREG;*/
710 cl->ClFlags |= InUseMask;
711 TRAIL_CLREF(cl);
712 }
713#endif
714 }
715 PREG = CPREG;
716 YREG = ENV;
717#ifdef DEPTH_LIMIT
718 DEPTH = YREG[E_DEPTH];
719#endif
720 JMPNext();
721 ENDBOp();
722
723
724 /* unify with database term */
725 BOp(unify_idb_term, e);
726 {
727 LogUpdClause *cl = ClauseCodeToLogUpdClause(PREG);
728
729 saveregs();
730 if (!Yap_IUnify(ARG2, cl->lusl.ClSource->Entry)) {
731 setregs();
732 UNLOCKPE(8,PP);
733#if defined(YAPOR) || defined(THREADS)
734 PP = NULL;
735#endif
736 FAIL();
737 }
738 if (!Yap_IUnify(ARG3, MkDBRefTerm((DBRef)cl))) {
739 setregs();
740 UNLOCKPE(9,PP);
741#if defined(YAPOR) || defined(THREADS)
742 PP = NULL;
743#endif
744 FAIL();
745 }
746 setregs();
747
748 /* say that an environment is using this clause */
749 /* we have our own copy for the clause */
750#if MULTIPLE_STACKS
751 /* always add an extra reference */
752 INC_CLREF_COUNT(cl);
753 TRAIL_CLREF(cl);
754 UNLOCKPE(10,PP);
755 PP = NULL;
756#else
757 if (!(cl->ClFlags & InUseMask)) {
758 /* Clause *cl = (Clause *)PREG->y_u.EC.ClBase;
759
760 PREG->y_u.EC.ClTrail = TR-(tr_fr_ptr)LOCAL_TrailBase;
761 PREG->y_u.EC.ClENV = LCL0-YREG;*/
762 cl->ClFlags |= InUseMask;
763 TRAIL_CLREF(cl);
764 }
765#endif
766 }
767 PREG = CPREG;
768 YREG = ENV;
769#ifdef DEPTH_LIMIT
770 DEPTH = YREG[E_DEPTH];
771#endif
772 JMPNext();
773 ENDBOp();
Definition: heapgc.h:272
Definition: Yatom.h:544