2002-06-04 19:21:55 +01:00
|
|
|
/*************************************************************************
|
2017-11-11 02:15:59 +00:00
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: rheap.h *
|
|
|
|
* comments: walk through heap code *
|
|
|
|
* *
|
|
|
|
* Last rev: $Date: 2008-08-07 20:51:23 $,$Author: vsc $
|
|
|
|
**
|
|
|
|
* $Log: not supported by cvs2svn $
|
|
|
|
* Revision 1.99 2008/07/22 23:34:49 vsc
|
|
|
|
* SWI and module fixes
|
|
|
|
*
|
|
|
|
* Revision 1.98 2008/05/12 22:31:37 vsc
|
|
|
|
* fix previous fixes
|
|
|
|
*
|
|
|
|
* Revision 1.97 2008/05/12 14:04:23 vsc
|
|
|
|
* updates to restore
|
|
|
|
*
|
|
|
|
* Revision 1.96 2008/04/11 16:58:17 ricroc
|
|
|
|
* yapor: seq_def initialization
|
|
|
|
*
|
|
|
|
* Revision 1.95 2008/04/06 12:06:48 vsc
|
|
|
|
* more small fixes
|
|
|
|
*
|
|
|
|
* Revision 1.94 2008/04/06 11:53:02 vsc
|
|
|
|
* fix some restore bugs
|
|
|
|
*
|
|
|
|
* Revision 1.93 2008/04/04 09:10:02 vsc
|
|
|
|
* restore was restoring twice
|
|
|
|
*
|
|
|
|
* Revision 1.92 2008/04/03 11:34:47 vsc
|
|
|
|
* fix restorebb in cases entry key is not an atom (obs from Nicos
|
|
|
|
* Angelopoulos)
|
|
|
|
*
|
|
|
|
* Revision 1.91 2008/04/01 15:31:43 vsc
|
|
|
|
* more saved state fixes
|
|
|
|
*
|
|
|
|
* Revision 1.90 2008/04/01 14:09:43 vsc
|
|
|
|
* improve restore
|
|
|
|
*
|
|
|
|
* Revision 1.89 2008/04/01 09:41:05 vsc
|
|
|
|
* more fixes to restore
|
|
|
|
*
|
|
|
|
* Revision 1.88 2008/04/01 08:42:46 vsc
|
|
|
|
* fix restore and small VISTA thingies
|
|
|
|
*
|
|
|
|
* Revision 1.87 2008/03/25 22:03:14 vsc
|
|
|
|
* fix some icc warnings
|
|
|
|
*
|
|
|
|
* Revision 1.86 2008/03/25 16:45:53 vsc
|
|
|
|
* make or-parallelism compile again
|
|
|
|
*
|
|
|
|
* Revision 1.85 2008/02/12 17:03:52 vsc
|
|
|
|
* SWI-portability changes
|
|
|
|
*
|
|
|
|
* Revision 1.84 2008/02/07 21:39:51 vsc
|
|
|
|
* fix case where predicate is for an integer (DBEntry).
|
|
|
|
*
|
|
|
|
* Revision 1.83 2008/01/23 17:57:55 vsc
|
|
|
|
* valgrind it!
|
|
|
|
* enable atom garbage collection.
|
|
|
|
*
|
|
|
|
* Revision 1.82 2007/12/05 12:17:23 vsc
|
|
|
|
* improve JT
|
|
|
|
* fix graph compatibility with SICStus
|
|
|
|
* re-export declaration.
|
|
|
|
*
|
|
|
|
* Revision 1.81 2007/11/26 23:43:09 vsc
|
|
|
|
* fixes to support threads and assert correctly, even if inefficiently.
|
|
|
|
*
|
|
|
|
* Revision 1.80 2007/11/07 09:35:53 vsc
|
|
|
|
* small fix
|
|
|
|
*
|
|
|
|
* Revision 1.79 2007/11/07 09:25:27 vsc
|
|
|
|
* speedup meta-calls
|
|
|
|
*
|
|
|
|
* Revision 1.78 2007/11/06 17:02:12 vsc
|
|
|
|
* compile ground terms away.
|
|
|
|
*
|
|
|
|
* Revision 1.77 2007/10/10 09:44:24 vsc
|
|
|
|
* some more fixes to make YAP swi compatible
|
|
|
|
* fix absolute_file_name (again)
|
|
|
|
* fix setarg
|
|
|
|
*
|
|
|
|
* Revision 1.76 2007/09/28 23:18:17 vsc
|
|
|
|
* handle learning from interpretations.
|
|
|
|
*
|
|
|
|
* Revision 1.75 2007/04/10 22:13:21 vsc
|
|
|
|
* fix max modules limitation
|
|
|
|
*
|
|
|
|
* Revision 1.74 2007/03/22 11:12:21 vsc
|
|
|
|
* make sure that YAP_Restart does not restart a failed goal.
|
|
|
|
*
|
|
|
|
* Revision 1.73 2007/02/18 00:26:36 vsc
|
|
|
|
* fix atom garbage collector (although it is still off by default)
|
|
|
|
* make valgrind feel better
|
|
|
|
*
|
|
|
|
* Revision 1.72 2007/01/08 08:27:19 vsc
|
|
|
|
* fix restore (Trevor)
|
|
|
|
* make indexing a bit faster on IDB
|
|
|
|
*
|
|
|
|
* Revision 1.71 2006/11/27 17:42:03 vsc
|
|
|
|
* support for UNICODE, and other bug fixes.
|
|
|
|
*
|
|
|
|
* Revision 1.70 2006/08/25 19:50:35 vsc
|
|
|
|
* global data structures
|
|
|
|
*
|
|
|
|
* Revision 1.69 2006/08/22 16:12:46 vsc
|
|
|
|
* global variables
|
|
|
|
*
|
|
|
|
* Revision 1.68 2006/08/02 18:18:30 vsc
|
|
|
|
* preliminary support for readutil library (SWI compatible).
|
|
|
|
*
|
|
|
|
* Revision 1.67 2006/05/17 18:38:11 vsc
|
|
|
|
* make system library use true file name
|
|
|
|
*
|
|
|
|
* Revision 1.66 2006/04/28 15:48:33 vsc
|
|
|
|
* do locking on streams
|
|
|
|
*
|
|
|
|
* Revision 1.65 2006/04/28 13:23:23 vsc
|
|
|
|
* fix number of overflow bugs affecting threaded version
|
|
|
|
* make current_op faster.
|
|
|
|
*
|
|
|
|
* Revision 1.64 2006/03/22 20:07:28 vsc
|
|
|
|
* take better care of zombies
|
|
|
|
*
|
|
|
|
* Revision 1.63 2006/03/06 14:04:56 vsc
|
|
|
|
* fixes to garbage collector
|
|
|
|
* fixes to debugger
|
|
|
|
*
|
|
|
|
* Revision 1.62 2006/02/24 14:03:42 vsc
|
|
|
|
* fix refs to old LogUpd implementation (pre 5).
|
|
|
|
*
|
|
|
|
* Revision 1.61 2006/01/02 02:16:18 vsc
|
|
|
|
* support new interface between YAP and GMP, so that we don't rely on our own
|
|
|
|
* allocation routines.
|
|
|
|
* Several big fixes.
|
|
|
|
*
|
|
|
|
* Revision 1.60 2005/12/17 03:25:39 vsc
|
|
|
|
* major changes to support online event-based profiling
|
|
|
|
* improve error discovery and restart on scanner.
|
|
|
|
*
|
|
|
|
* Revision 1.59 2005/12/05 17:16:11 vsc
|
|
|
|
* write_depth/3
|
|
|
|
* overflow handlings and garbage collection
|
|
|
|
* Several ipdates to CLPBN
|
|
|
|
* dif/2 could be broken in the presence of attributed variables.
|
|
|
|
*
|
|
|
|
* Revision 1.58 2005/11/23 03:01:33 vsc
|
|
|
|
* fix several bugs in save/restore.b
|
|
|
|
*
|
|
|
|
* Revision 1.57 2005/10/28 17:38:50 vsc
|
|
|
|
* sveral updates
|
|
|
|
*
|
|
|
|
* Revision 1.56 2005/10/21 16:09:03 vsc
|
|
|
|
* SWI compatible module only operators
|
|
|
|
*
|
|
|
|
* Revision 1.55 2005/10/19 19:00:48 vsc
|
|
|
|
* extend arrays with nb_terms so that we can implement nb_ builtins
|
|
|
|
* correctly.
|
|
|
|
*
|
|
|
|
* Revision 1.54 2005/09/09 17:24:39 vsc
|
|
|
|
* a new and hopefully much better implementation of atts.
|
|
|
|
*
|
|
|
|
* Revision 1.53 2005/08/01 15:40:38 ricroc
|
|
|
|
* TABLING NEW: better support for incomplete tabling
|
|
|
|
*
|
|
|
|
* Revision 1.52 2005/07/06 19:34:11 ricroc
|
|
|
|
* TABLING: answers for completed calls can now be obtained by loading (new
|
|
|
|
*option) or executing (default) them from the trie data structure.
|
|
|
|
*
|
|
|
|
* Revision 1.51 2005/07/06 15:10:15 vsc
|
|
|
|
* improvements to compiler: merged instructions and fixes for ->
|
|
|
|
*
|
|
|
|
* Revision 1.50 2005/06/01 13:53:46 vsc
|
|
|
|
* improve bb routines to use the DB efficiently
|
|
|
|
* change interface between DB and BB.
|
|
|
|
*
|
|
|
|
* Revision 1.49 2005/05/30 03:26:37 vsc
|
|
|
|
* add some atom gc fixes
|
|
|
|
*
|
|
|
|
* Revision 1.48 2005/01/04 02:50:21 vsc
|
|
|
|
* - allow MegaClauses with blobs
|
|
|
|
* - change Diffs to be thread specific
|
|
|
|
* - include Christian's updates
|
|
|
|
*
|
|
|
|
* Revision 1.47 2004/12/02 06:06:47 vsc
|
|
|
|
* fix threads so that they at least start
|
|
|
|
* allow error handling to work with threads
|
|
|
|
* replace heap_base by Yap_heap_base, according to Yap's convention for
|
|
|
|
*globals.
|
|
|
|
*
|
|
|
|
* Revision 1.46 2004/11/23 21:16:21 vsc
|
|
|
|
* A few extra fixes for saved states.
|
|
|
|
*
|
|
|
|
* Revision 1.45 2004/10/26 20:16:18 vsc
|
|
|
|
* More bug fixes for overflow handling
|
|
|
|
*
|
|
|
|
* Revision 1.44 2004/10/06 16:55:47 vsc
|
|
|
|
* change configure to support big mem configs
|
|
|
|
* get rid of extra globals
|
|
|
|
* fix trouble with multifile preds
|
|
|
|
*
|
|
|
|
* Revision 1.43 2004/09/27 20:45:04 vsc
|
|
|
|
* Mega clauses
|
|
|
|
* Fixes to sizeof(expand_clauses) which was being overestimated
|
|
|
|
* Fixes to profiling+indexing
|
|
|
|
* Fixes to reallocation of memory after restoring
|
|
|
|
* Make sure all clauses, even for C, end in _Ystop
|
|
|
|
* Don't reuse space for Streams
|
|
|
|
* Fix Stream_F on StreaNo+1
|
|
|
|
*
|
|
|
|
* Revision 1.42 2004/06/05 03:37:00 vsc
|
|
|
|
* coroutining is now a part of attvars.
|
|
|
|
* some more fixes.
|
|
|
|
*
|
|
|
|
* Revision 1.41 2004/04/29 03:45:50 vsc
|
|
|
|
* fix garbage collection in execute_tail
|
|
|
|
*
|
|
|
|
* Revision 1.40 2004/03/31 01:03:10 vsc
|
|
|
|
* support expand group of clauses
|
|
|
|
*
|
|
|
|
* Revision 1.39 2004/03/19 11:35:42 vsc
|
|
|
|
* trim_trail for default machine
|
|
|
|
* be more aggressive about try-retry-trust chains.
|
|
|
|
* - handle cases where block starts with a wait
|
|
|
|
* - don't use _killed instructions, just let the thing rot by itself.
|
|
|
|
* *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
2002-06-04 19:21:55 +01:00
|
|
|
#ifdef SCCS
|
2016-01-03 02:06:09 +00:00
|
|
|
static char SccsId[] = "@(#)rheap.c 1.3 3/15/90";
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif
|
|
|
|
|
2017-11-11 02:15:59 +00:00
|
|
|
#ifndef RHEAP_H
|
|
|
|
#define RHEAP_H 1
|
|
|
|
|
|
|
|
#include "YapHeap.h"
|
|
|
|
#include "absmi.h"
|
|
|
|
#include "clause.h"
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
#define Atomics 0
|
|
|
|
#define Funcs 1
|
2002-06-04 19:21:55 +01:00
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
#define ConstantTermAdjust(P) ConstantTermAdjust__(P PASS_REGS)
|
|
|
|
#define DBGroundTermAdjust(P) DBGroundTermAdjust__(P PASS_REGS)
|
2016-01-03 02:06:09 +00:00
|
|
|
#define AdjustDBTerm(P, A, B, C) AdjustDBTerm__(P, A, B, C PASS_REGS)
|
|
|
|
#define AdjustSwitchTable(op, table, i) \
|
|
|
|
AdjustSwitchTable__(op, table, i PASS_REGS)
|
|
|
|
#define RestoreOtaplInst(start, opc, pe) \
|
|
|
|
RestoreOtaplInst__(start, opc, pe PASS_REGS)
|
|
|
|
#define RestoreDBErasedMarker() RestoreDBErasedMarker__(PASS_REGS1)
|
|
|
|
#define RestoreLogDBErasedMarker() RestoreLogDBErasedMarker__(PASS_REGS1)
|
|
|
|
#define RestoreForeignCode() RestoreForeignCode__(PASS_REGS1)
|
|
|
|
#define RestoreEmptyWakeups() RestoreEmptyWakeups__(PASS_REGS1)
|
|
|
|
#define RestoreAtoms() RestoreAtoms__(PASS_REGS1)
|
|
|
|
#define RestoreWideAtoms() RestoreWideAtoms__(PASS_REGS1)
|
|
|
|
#define RestoreSWIBlobs() RestoreSWIBlobs__(PASS_REGS1)
|
|
|
|
#define RestoreSWIBlobTypes() RestoreSWIBlobTypes__(PASS_REGS1)
|
|
|
|
#define RestoreInvisibleAtoms() RestoreInvisibleAtoms__(PASS_REGS1)
|
|
|
|
#define RestorePredHash() RestorePredHash__(PASS_REGS1)
|
|
|
|
#define RestoreHiddenPredicates() RestoreHiddenPredicates__(PASS_REGS1)
|
|
|
|
#define RestoreDBTermsList() RestoreDBTermsList__(PASS_REGS1)
|
|
|
|
#define RestoreExpandList() RestoreExpandList__(PASS_REGS1)
|
|
|
|
#define RestoreIntKeys() RestoreIntKeys__(PASS_REGS1)
|
|
|
|
#define RestoreIntLUKeys() RestoreIntLUKeys__(PASS_REGS1)
|
|
|
|
#define RestoreIntBBKeys() RestoreIntBBKeys__(PASS_REGS1)
|
|
|
|
#define RestoreDeadStaticClauses() RestoreDeadStaticClauses__(PASS_REGS1)
|
|
|
|
#define RestoreDeadMegaClauses() RestoreDeadMegaClauses__(PASS_REGS1)
|
|
|
|
#define RestoreDeadStaticIndices() RestoreDeadStaticIndices__(PASS_REGS1)
|
|
|
|
#define RestoreDBErasedList() RestoreDBErasedList__(PASS_REGS1)
|
|
|
|
#define RestoreDBErasedIList() RestoreDBErasedIList__(PASS_REGS1)
|
|
|
|
#define RestoreYapRecords() RestoreYapRecords__(PASS_REGS1)
|
|
|
|
static Term ConstantTermAdjust__(Term t USES_REGS) {
|
2008-08-29 17:27:11 +01:00
|
|
|
if (IsAtomTerm(t))
|
|
|
|
return AtomTermAdjust(t);
|
2010-12-16 20:39:53 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static Term DBGroundTermAdjust__(Term t USES_REGS) {
|
2010-12-16 22:21:46 +00:00
|
|
|
/* The term itself is restored by dbtermlist */
|
2010-12-16 20:39:53 +00:00
|
|
|
if (IsPairTerm(t)) {
|
2010-12-16 22:21:46 +00:00
|
|
|
return AbsPair(PtoHeapCellAdjust(RepPair(t)));
|
2010-12-12 16:45:39 +00:00
|
|
|
} else {
|
2010-12-16 22:21:46 +00:00
|
|
|
return AbsAppl(PtoHeapCellAdjust(RepAppl(t)));
|
2010-12-12 16:45:39 +00:00
|
|
|
}
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
|
|
|
|
2002-06-04 19:21:55 +01:00
|
|
|
/* Now, everything on its place so you must adjust the pointers */
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void do_clean_susp_clauses(yamop *ipc USES_REGS) {
|
2004-09-27 21:45:04 +01:00
|
|
|
COUNT i;
|
2016-01-03 02:06:09 +00:00
|
|
|
yamop **st = (yamop **)NEXTOP(ipc, sssllp);
|
2004-09-27 21:45:04 +01:00
|
|
|
|
|
|
|
ipc->opc = Yap_opcode(_expand_clauses);
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.sssllp.p = PtoPredAdjust(ipc->y_u.sssllp.p);
|
|
|
|
if (ipc->y_u.sssllp.sprev) {
|
|
|
|
ipc->y_u.sssllp.sprev = PtoOpAdjust(ipc->y_u.sssllp.sprev);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2014-05-30 01:06:09 +01:00
|
|
|
if (ipc->y_u.sssllp.snext) {
|
|
|
|
ipc->y_u.sssllp.snext = PtoOpAdjust(ipc->y_u.sssllp.snext);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2014-05-30 01:06:09 +01:00
|
|
|
for (i = 0; i < ipc->y_u.sssllp.s1; i++, st++) {
|
2004-09-27 21:45:04 +01:00
|
|
|
if (*st) {
|
|
|
|
*st = PtoOpAdjust(*st);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void AdjustSwitchTable__(op_numbers op, yamop *table,
|
|
|
|
COUNT i USES_REGS) {
|
2008-08-29 17:27:11 +01:00
|
|
|
CELL *startcode = (CELL *)table;
|
2011-02-04 01:23:01 +00:00
|
|
|
/* in case the table is already gone */
|
|
|
|
if (!table)
|
|
|
|
return;
|
2008-08-29 17:27:11 +01:00
|
|
|
switch (op) {
|
2016-01-03 02:06:09 +00:00
|
|
|
case _switch_on_func: {
|
|
|
|
COUNT j;
|
|
|
|
CELL *oldcode;
|
|
|
|
|
|
|
|
oldcode = startcode;
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
Functor oldfunc = (Functor)(oldcode[0]);
|
|
|
|
CODEADDR oldjmp = (CODEADDR)(oldcode[1]);
|
|
|
|
if (oldfunc) {
|
|
|
|
oldcode[0] = (CELL)FuncAdjust(oldfunc);
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
oldcode[1] = (CELL)CodeAddrAdjust(oldjmp);
|
|
|
|
oldcode += 2;
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
rehash(startcode, i, Funcs PASS_REGS);
|
|
|
|
} break;
|
|
|
|
case _switch_on_cons: {
|
|
|
|
COUNT j;
|
|
|
|
CELL *oldcode;
|
2008-08-29 17:27:11 +01:00
|
|
|
|
|
|
|
#if !defined(USE_OFFSETS)
|
2016-01-03 02:06:09 +00:00
|
|
|
oldcode = startcode;
|
2008-08-29 17:27:11 +01:00
|
|
|
#endif
|
2016-01-03 02:06:09 +00:00
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
Term oldcons = oldcode[0];
|
|
|
|
CODEADDR oldjmp = (CODEADDR)(oldcode[1]);
|
|
|
|
if (oldcons != 0x0 && IsAtomTerm(oldcons)) {
|
|
|
|
oldcode[0] = AtomTermAdjust(oldcons);
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
oldcode[1] = (CELL)CodeAddrAdjust(oldjmp);
|
|
|
|
oldcode += 2;
|
|
|
|
}
|
2008-08-29 17:27:11 +01:00
|
|
|
#if !USE_OFFSETS
|
2016-01-03 02:06:09 +00:00
|
|
|
rehash(startcode, i, Atomics PASS_REGS);
|
2008-08-29 17:27:11 +01:00
|
|
|
#endif
|
2016-01-03 02:06:09 +00:00
|
|
|
} break;
|
|
|
|
case _go_on_func: {
|
|
|
|
Functor oldfunc = (Functor)(startcode[0]);
|
|
|
|
|
|
|
|
startcode[0] = (CELL)FuncAdjust(oldfunc);
|
|
|
|
startcode[1] = (CELL)CodeAddrAdjust((CODEADDR)startcode[1]);
|
|
|
|
startcode[3] = (CELL)CodeAddrAdjust((CODEADDR)startcode[3]);
|
|
|
|
} break;
|
|
|
|
case _go_on_cons: {
|
|
|
|
Term oldcons = startcode[0];
|
|
|
|
|
|
|
|
if (IsAtomTerm(oldcons)) {
|
|
|
|
startcode[0] = AtomTermAdjust(oldcons);
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
startcode[1] = (CELL)CodeAddrAdjust((CODEADDR)startcode[1]);
|
|
|
|
startcode[3] = (CELL)CodeAddrAdjust((CODEADDR)startcode[3]);
|
|
|
|
} break;
|
|
|
|
case _if_func: {
|
|
|
|
Int j;
|
2008-08-29 17:27:11 +01:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
Functor oldfunc = (Functor)(startcode[0]);
|
|
|
|
CODEADDR oldjmp = (CODEADDR)(startcode[1]);
|
2008-08-29 17:27:11 +01:00
|
|
|
startcode[0] = (CELL)FuncAdjust(oldfunc);
|
2016-01-03 02:06:09 +00:00
|
|
|
startcode[1] = (CELL)CodeAddrAdjust(oldjmp);
|
|
|
|
startcode += 2;
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
/* adjust fail code */
|
2017-09-19 13:19:13 +01:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
startcode[1] = (CELL)CodeAddrAdjust((CODEADDR)startcode[1]);
|
|
|
|
} break;
|
|
|
|
case _if_cons: {
|
|
|
|
Int j;
|
2008-08-29 17:27:11 +01:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
Term oldcons = startcode[0];
|
|
|
|
CODEADDR oldjmp = (CODEADDR)(startcode[1]);
|
2008-08-29 17:27:11 +01:00
|
|
|
if (IsAtomTerm(oldcons)) {
|
2016-01-03 02:06:09 +00:00
|
|
|
startcode[0] = (CELL)AtomTermAdjust(oldcons);
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
startcode[1] = (CELL)CodeAddrAdjust(oldjmp);
|
|
|
|
startcode += 2;
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
/* adjust fail code */
|
|
|
|
startcode[1] = (CELL)CodeAddrAdjust((CODEADDR)startcode[1]);
|
|
|
|
} break;
|
2008-08-29 17:27:11 +01:00
|
|
|
default:
|
2016-01-03 02:06:09 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL, 0L,
|
|
|
|
"Opcode Not Implemented in AdjustSwitchTable");
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreAtomList(Atom CACHE_TYPE);
|
|
|
|
static void RestoreAtom(AtomEntry *CACHE_TYPE);
|
|
|
|
static void RestoreHashPreds(CACHE_TYPE1);
|
2009-10-30 23:59:00 +00:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreAtoms__(USES_REGS1) {
|
2009-10-30 23:59:00 +00:00
|
|
|
AtomHashEntry *HashPtr;
|
2016-01-03 02:06:09 +00:00
|
|
|
register int i;
|
2009-10-30 23:59:00 +00:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
HashChain = PtoAtomHashEntryAdjust(HashChain);
|
2009-10-30 23:59:00 +00:00
|
|
|
HashPtr = HashChain;
|
|
|
|
for (i = 0; i < AtomHashTableSize; ++i) {
|
2010-10-26 10:04:36 +01:00
|
|
|
HashPtr->Entry = NoAGCAtomAdjust(HashPtr->Entry);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreAtomList(HashPtr->Entry PASS_REGS);
|
2009-10-30 23:59:00 +00:00
|
|
|
HashPtr++;
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreWideAtoms__(USES_REGS1) {
|
2009-10-30 23:59:00 +00:00
|
|
|
AtomHashEntry *HashPtr;
|
2016-01-03 02:06:09 +00:00
|
|
|
register int i;
|
2009-10-30 23:59:00 +00:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
WideHashChain = PtoAtomHashEntryAdjust(WideHashChain);
|
2009-10-30 23:59:00 +00:00
|
|
|
HashPtr = WideHashChain;
|
|
|
|
for (i = 0; i < WideAtomHashTableSize; ++i) {
|
|
|
|
HashPtr->Entry = AtomAdjust(HashPtr->Entry);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreAtomList(HashPtr->Entry PASS_REGS);
|
2009-10-30 23:59:00 +00:00
|
|
|
HashPtr++;
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreInvisibleAtoms__(USES_REGS1) {
|
2009-10-30 23:59:00 +00:00
|
|
|
INVISIBLECHAIN.Entry = AtomAdjust(INVISIBLECHAIN.Entry);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreAtomList(INVISIBLECHAIN.Entry PASS_REGS);
|
|
|
|
RestoreAtom(RepAtom(AtomFoundVar) PASS_REGS);
|
|
|
|
RestoreAtom(RepAtom(AtomFreeTerm) PASS_REGS);
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
#include "rclause.h"
|
|
|
|
|
|
|
|
/* adjusts terms stored in the data base, when they have no variables */
|
2016-01-03 02:06:09 +00:00
|
|
|
static Term AdjustDBTerm__(Term trm, Term *p_base, Term *p_lim,
|
|
|
|
Term *p_max USES_REGS) {
|
2008-05-12 15:04:23 +01:00
|
|
|
if (IsVarTerm(trm))
|
|
|
|
return CodeVarAdjust(trm);
|
2008-05-12 23:31:37 +01:00
|
|
|
if (IsAtomTerm(trm))
|
|
|
|
return AtomTermAdjust(trm);
|
2006-03-22 20:07:28 +00:00
|
|
|
if (IsPairTerm(trm)) {
|
2016-01-03 02:06:09 +00:00
|
|
|
Term *p;
|
2008-04-03 12:34:47 +01:00
|
|
|
Term out;
|
2006-03-22 20:07:28 +00:00
|
|
|
|
|
|
|
p = PtoHeapCellAdjust(RepPair(trm));
|
2008-04-03 12:34:47 +01:00
|
|
|
out = AbsPair(p);
|
|
|
|
loop:
|
2012-06-06 00:09:14 +01:00
|
|
|
if (p >= p_base || p < p_lim) {
|
2012-06-12 14:50:36 +01:00
|
|
|
p[0] = AdjustDBTerm(p[0], p, p_lim, p_max);
|
2008-04-03 12:34:47 +01:00
|
|
|
if (IsPairTerm(p[1])) {
|
2016-01-03 02:06:09 +00:00
|
|
|
/* avoid term recursion with very deep lists */
|
|
|
|
Term *newp = PtoHeapCellAdjust(RepPair(p[1]));
|
|
|
|
p[1] = AbsPair(newp);
|
|
|
|
p_base = p;
|
|
|
|
p = newp;
|
|
|
|
goto loop;
|
2008-04-03 12:34:47 +01:00
|
|
|
} else {
|
2016-01-03 02:06:09 +00:00
|
|
|
p[1] = AdjustDBTerm(p[1], p, p_lim, p_max);
|
2008-04-03 12:34:47 +01:00
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
2008-04-03 12:34:47 +01:00
|
|
|
return out;
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
if (IsApplTerm(trm)) {
|
2016-01-03 02:06:09 +00:00
|
|
|
Term *p;
|
2006-03-22 20:07:28 +00:00
|
|
|
Functor f;
|
|
|
|
Term *p0 = p = PtoHeapCellAdjust(RepAppl(trm));
|
|
|
|
/* if it is before the current position, then we are looking
|
|
|
|
at old code */
|
2012-06-06 00:09:14 +01:00
|
|
|
if (p >= p_base || p < p_lim) {
|
2012-06-12 14:50:36 +01:00
|
|
|
if (p >= p_max || p < p_lim) {
|
2016-01-03 02:06:09 +00:00
|
|
|
if (DBRefOfTerm(trm) != DBRefAdjust(DBRefOfTerm(trm), FALSE))
|
|
|
|
/* external term pointer, has to be a DBRef */
|
|
|
|
return MkDBRefTerm(DBRefAdjust(DBRefOfTerm(trm), FALSE));
|
2012-06-12 14:50:36 +01:00
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
f = (Functor)p[0];
|
|
|
|
if (!IsExtensionFunctor(f)) {
|
2016-01-03 02:06:09 +00:00
|
|
|
UInt Arity, i;
|
|
|
|
|
|
|
|
f = FuncAdjust(f);
|
|
|
|
*p++ = (Term)f;
|
|
|
|
Arity = ArityOfFunctor(f);
|
|
|
|
for (i = 0; i < Arity; ++i) {
|
|
|
|
*p = AdjustDBTerm(*p, p0, p_lim, p_max);
|
|
|
|
p++;
|
|
|
|
}
|
2012-06-12 14:50:36 +01:00
|
|
|
} else if (f == FunctorDBRef) {
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return AbsAppl(p0);
|
|
|
|
}
|
|
|
|
return trm;
|
|
|
|
}
|
|
|
|
|
2016-02-28 19:30:46 +00:00
|
|
|
static void RestoreDBTerm(DBTerm *dbr, bool src, int attachments USES_REGS) {
|
2007-11-06 17:02:13 +00:00
|
|
|
if (attachments) {
|
2006-03-22 20:07:28 +00:00
|
|
|
#ifdef COROUTINING
|
2016-01-03 02:06:09 +00:00
|
|
|
if (attachments == 1 && dbr->ag.attachments)
|
|
|
|
dbr->ag.attachments =
|
|
|
|
AdjustDBTerm(dbr->ag.attachments, dbr->Contents, dbr->Contents,
|
|
|
|
dbr->Contents + dbr->NOfCells);
|
2006-03-22 20:07:28 +00:00
|
|
|
#endif
|
2007-11-06 17:02:13 +00:00
|
|
|
} else {
|
2008-04-01 09:42:46 +01:00
|
|
|
if (dbr->ag.NextDBT)
|
|
|
|
dbr->ag.NextDBT = DBTermAdjust(dbr->ag.NextDBT);
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
2012-06-12 14:50:36 +01:00
|
|
|
if (dbr->DBRefs) {
|
2016-01-03 02:06:09 +00:00
|
|
|
DBRef *cp;
|
|
|
|
DBRef tm;
|
2006-03-22 20:07:28 +00:00
|
|
|
|
|
|
|
dbr->DBRefs = DBRefPAdjust(dbr->DBRefs);
|
|
|
|
cp = dbr->DBRefs;
|
2012-06-12 14:50:36 +01:00
|
|
|
while ((tm = *--cp) != 0) {
|
2016-01-03 02:06:09 +00:00
|
|
|
*cp = DBRefAdjust(tm, TRUE);
|
2012-06-12 14:50:36 +01:00
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
dbr->Entry = AdjustDBTerm(dbr->Entry, dbr->Contents, dbr->Contents,
|
|
|
|
dbr->Contents + dbr->NOfCells);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
|
2007-11-06 17:02:13 +00:00
|
|
|
/* Restoring the heap */
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreEmptyWakeups__(USES_REGS1) {
|
2013-04-30 21:23:01 +01:00
|
|
|
int i;
|
2016-01-03 02:06:09 +00:00
|
|
|
for (i = 0; i < MaxEmptyWakeups; i++) {
|
2013-04-30 21:23:01 +01:00
|
|
|
EmptyWakeups[i] = AtomAdjust(EmptyWakeups[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
/* Restores a prolog clause, in its compiled form */
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreStaticClause(StaticClause *cl USES_REGS)
|
2006-03-22 20:07:28 +00:00
|
|
|
/*
|
|
|
|
* Cl points to the start of the code, IsolFlag tells if we have a single
|
2016-01-03 02:06:09 +00:00
|
|
|
* clause for this predicate or not
|
2006-03-22 20:07:28 +00:00
|
|
|
*/
|
|
|
|
{
|
2016-02-28 19:30:46 +00:00
|
|
|
if (cl->ClFlags & SrcMask && !(cl->ClFlags & FactMask)) {
|
2013-11-05 17:59:19 +00:00
|
|
|
cl->usc.ClSource = DBTermAdjust(cl->usc.ClSource);
|
2016-02-28 19:30:46 +00:00
|
|
|
RestoreDBTerm(cl->usc.ClSource, true, 2 PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
if (cl->ClNext) {
|
|
|
|
cl->ClNext = PtoStCAdjust(cl->ClNext);
|
|
|
|
}
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_opcodes(cl->ClCode, NULL PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Restores a prolog clause, in its compiled form */
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreMegaClause(MegaClause *cl USES_REGS)
|
2006-03-22 20:07:28 +00:00
|
|
|
/*
|
|
|
|
* Cl points to the start of the code, IsolFlag tells if we have a single
|
2016-01-03 02:06:09 +00:00
|
|
|
* clause for this predicate or not
|
2006-03-22 20:07:28 +00:00
|
|
|
*/
|
|
|
|
{
|
2012-04-23 23:24:35 +01:00
|
|
|
yamop *ptr, *max, *nextptr;
|
2009-11-02 12:46:39 +00:00
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
cl->ClPred = PtoPredAdjust(cl->ClPred);
|
|
|
|
if (cl->ClNext) {
|
2009-11-02 12:46:39 +00:00
|
|
|
cl->ClNext = (MegaClause *)AddrAdjust((ADDR)(cl->ClNext));
|
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
max = (yamop *)((CODEADDR)cl + cl->ClSize);
|
2009-11-02 12:46:39 +00:00
|
|
|
|
2013-01-11 18:36:34 +00:00
|
|
|
if (cl->ClFlags & ExoMask) {
|
2016-01-03 02:06:09 +00:00
|
|
|
CELL *base = (CELL *)((ADDR)cl->ClCode + 2 * sizeof(struct index_t *));
|
|
|
|
CELL *end = (CELL *)max, *ptr;
|
2013-01-11 18:36:34 +00:00
|
|
|
|
|
|
|
for (ptr = base; ptr < end; ptr++) {
|
|
|
|
Term t = *ptr;
|
2016-01-03 02:06:09 +00:00
|
|
|
if (IsAtomTerm(t))
|
|
|
|
*ptr = AtomTermAdjust(t);
|
2013-01-11 18:36:34 +00:00
|
|
|
/* don't handle other complex terms just yet, ints are ok */
|
|
|
|
}
|
|
|
|
} else {
|
2016-01-03 02:06:09 +00:00
|
|
|
for (ptr = cl->ClCode; ptr < max;) {
|
2013-01-11 18:36:34 +00:00
|
|
|
nextptr = (yamop *)((char *)ptr + cl->ClItemSize);
|
|
|
|
restore_opcodes(ptr, nextptr PASS_REGS);
|
|
|
|
ptr = nextptr;
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restores a prolog clause, in its compiled form */
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDynamicClause(DynamicClause *cl, PredEntry *pp USES_REGS)
|
2006-03-22 20:07:28 +00:00
|
|
|
/*
|
|
|
|
* Cl points to the start of the code, IsolFlag tells if we have a single
|
2016-01-03 02:06:09 +00:00
|
|
|
* clause for this predicate or not
|
2006-03-22 20:07:28 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
if (cl->ClPrevious != NULL) {
|
|
|
|
cl->ClPrevious = PtoOpAdjust(cl->ClPrevious);
|
|
|
|
}
|
|
|
|
INIT_LOCK(cl->ClLock);
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_opcodes(cl->ClCode, NULL PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Restores a prolog clause, in its compiled form */
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreLUClause(LogUpdClause *cl, PredEntry *pp USES_REGS)
|
2006-03-22 20:07:28 +00:00
|
|
|
/*
|
|
|
|
* Cl points to the start of the code, IsolFlag tells if we have a single
|
2016-01-03 02:06:09 +00:00
|
|
|
* clause for this predicate or not
|
2006-03-22 20:07:28 +00:00
|
|
|
*/
|
|
|
|
{
|
2008-08-07 21:51:23 +01:00
|
|
|
// INIT_LOCK(cl->ClLock);
|
2006-03-22 20:07:28 +00:00
|
|
|
if (cl->ClFlags & LogUpdRuleMask) {
|
|
|
|
cl->ClExt = PtoOpAdjust(cl->ClExt);
|
|
|
|
}
|
2013-11-05 17:59:19 +00:00
|
|
|
if (!(cl->ClFlags & FactMask)) {
|
|
|
|
cl->lusl.ClSource = DBTermAdjust(cl->lusl.ClSource);
|
2016-02-28 19:30:46 +00:00
|
|
|
RestoreDBTerm(cl->lusl.ClSource, true, 2 PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
if (cl->ClPrev) {
|
|
|
|
cl->ClPrev = PtoLUCAdjust(cl->ClPrev);
|
|
|
|
}
|
|
|
|
if (cl->ClNext) {
|
|
|
|
cl->ClNext = PtoLUCAdjust(cl->ClNext);
|
|
|
|
}
|
|
|
|
cl->ClPred = PtoPredAdjust(cl->ClPred);
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_opcodes(cl->ClCode, NULL PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDBTermEntry(struct dbterm_list *dbl USES_REGS) {
|
2007-11-06 17:02:13 +00:00
|
|
|
DBTerm *dbt;
|
|
|
|
|
2008-04-01 09:42:46 +01:00
|
|
|
if (dbl->dbterms)
|
|
|
|
dbt = dbl->dbterms = DBTermAdjust(dbl->dbterms);
|
|
|
|
else
|
|
|
|
return;
|
2007-11-06 17:02:13 +00:00
|
|
|
dbl->clause_code = PtoOpAdjust(dbl->clause_code);
|
2008-04-01 09:42:46 +01:00
|
|
|
if (dbl->next_dbl)
|
|
|
|
dbl->next_dbl = PtoDBTLAdjust(dbl->next_dbl);
|
2007-11-06 17:02:13 +00:00
|
|
|
dbl->p = PredEntryAdjust(dbl->p);
|
|
|
|
while (dbt) {
|
2016-02-28 19:30:46 +00:00
|
|
|
RestoreDBTerm(dbt, false, 0 PASS_REGS);
|
2007-11-06 17:02:13 +00:00
|
|
|
dbt = dbt->ag.NextDBT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void CleanLUIndex(LogUpdIndex *idx, int recurse USES_REGS) {
|
2008-08-07 21:51:23 +01:00
|
|
|
// INIT_LOCK(idx->ClLock);
|
2006-03-22 20:07:28 +00:00
|
|
|
idx->ClPred = PtoPredAdjust(idx->ClPred);
|
|
|
|
if (idx->ParentIndex)
|
|
|
|
idx->ParentIndex = LUIndexAdjust(idx->ParentIndex);
|
2008-01-23 17:57:56 +00:00
|
|
|
if (idx->PrevSiblingIndex) {
|
|
|
|
idx->PrevSiblingIndex = LUIndexAdjust(idx->PrevSiblingIndex);
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
if (idx->SiblingIndex) {
|
|
|
|
idx->SiblingIndex = LUIndexAdjust(idx->SiblingIndex);
|
2008-05-12 15:04:23 +01:00
|
|
|
if (recurse)
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanLUIndex(idx->SiblingIndex, TRUE PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
if (idx->ChildIndex) {
|
|
|
|
idx->ChildIndex = LUIndexAdjust(idx->ChildIndex);
|
2008-05-12 15:04:23 +01:00
|
|
|
if (recurse)
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanLUIndex(idx->ChildIndex, TRUE PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
2008-04-01 09:42:46 +01:00
|
|
|
if (!(idx->ClFlags & SwitchTableMask)) {
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_opcodes(idx->ClCode, NULL PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void CleanSIndex(StaticIndex *idx, int recurse USES_REGS) {
|
|
|
|
beginning:
|
2010-10-07 18:14:55 +01:00
|
|
|
if (!(idx->ClFlags & SwitchTableMask)) {
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_opcodes(idx->ClCode, NULL PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
2010-10-07 18:14:55 +01:00
|
|
|
idx->ClPred = PtoPredAdjust(idx->ClPred);
|
2006-03-22 20:07:28 +00:00
|
|
|
if (idx->ChildIndex) {
|
|
|
|
idx->ChildIndex = SIndexAdjust(idx->ChildIndex);
|
2008-05-12 15:04:23 +01:00
|
|
|
if (recurse)
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanSIndex(idx->ChildIndex, TRUE PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
2010-10-07 18:14:55 +01:00
|
|
|
if (idx->SiblingIndex) {
|
|
|
|
idx->SiblingIndex = SIndexAdjust(idx->SiblingIndex);
|
|
|
|
/* use loop to avoid recursion with very complex indices */
|
|
|
|
if (recurse) {
|
2016-01-03 02:06:09 +00:00
|
|
|
idx = idx->SiblingIndex;
|
2010-10-07 18:14:55 +01:00
|
|
|
goto beginning;
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
#define RestoreBlobTypes() RestoreBlobTypes__(PASS_REGS1)
|
|
|
|
#define RestoreBlobs() RestoreBlobs__(PASS_REGS1);
|
2015-06-19 00:56:24 +01:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreBlobTypes__(USES_REGS1) {}
|
2015-06-19 00:56:24 +01:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreBlobs__(USES_REGS1) {
|
2015-06-19 00:56:24 +01:00
|
|
|
Blobs = AtomAdjust(Blobs);
|
|
|
|
RestoreAtomList(Blobs PASS_REGS);
|
2010-11-29 23:17:06 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreHiddenPredicates__(USES_REGS1) {
|
2012-10-19 18:10:48 +01:00
|
|
|
HIDDEN_PREDICATES = PropAdjust(HIDDEN_PREDICATES);
|
|
|
|
RestoreEntries(HIDDEN_PREDICATES, TRUE PASS_REGS);
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestorePredHash__(USES_REGS1) {
|
2009-10-28 13:11:35 +00:00
|
|
|
PredHash = PtoPtoPredAdjust(PredHash);
|
|
|
|
if (PredHash == NULL) {
|
2016-01-03 02:06:09 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR_FATAL, MkIntTerm(0),
|
|
|
|
"restore should find predicate hash table");
|
2009-10-28 13:11:35 +00:00
|
|
|
}
|
|
|
|
REINIT_RWLOCK(PredHashRWLock);
|
2016-01-03 02:06:09 +00:00
|
|
|
RestoreHashPreds(PASS_REGS1); /* does most of the work */
|
2009-10-28 13:11:35 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreEnvInst(yamop start[2], yamop **instp, op_numbers opc,
|
|
|
|
PredEntry *pred) {
|
2009-10-28 13:11:35 +00:00
|
|
|
yamop *ipc = start;
|
|
|
|
|
|
|
|
ipc->opc = Yap_opcode(_call);
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.Osbpp.p = pred;
|
|
|
|
ipc->y_u.Osbpp.p0 = pred;
|
|
|
|
ipc->y_u.Osbpp.bmap = NULL;
|
|
|
|
ipc->y_u.Osbpp.s = -Signed(RealEnvSize);
|
2009-10-28 13:11:35 +00:00
|
|
|
ipc = NEXTOP(ipc, Osbpp);
|
|
|
|
ipc->opc = Yap_opcode(opc);
|
|
|
|
*instp = ipc;
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreOtaplInst__(yamop start[1], OPCODE opc,
|
|
|
|
PredEntry *pe USES_REGS) {
|
2009-10-28 13:11:35 +00:00
|
|
|
yamop *ipc = start;
|
|
|
|
|
|
|
|
/* this is a place holder, it should not really be used */
|
|
|
|
ipc->opc = Yap_opcode(opc);
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.Otapl.s = 0;
|
|
|
|
ipc->y_u.Otapl.p = pe;
|
|
|
|
if (ipc->y_u.Otapl.d)
|
|
|
|
ipc->y_u.Otapl.d = PtoOpAdjust(ipc->y_u.Otapl.d);
|
2002-06-04 19:21:55 +01:00
|
|
|
#ifdef YAPOR
|
2009-10-28 13:11:35 +00:00
|
|
|
INIT_YAMOP_LTT(ipc, 1);
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif /* YAPOR */
|
|
|
|
#ifdef TABLING
|
2014-05-30 01:06:09 +01:00
|
|
|
ipc->y_u.Otapl.te = NULL;
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif /* TABLING */
|
2009-10-28 13:11:35 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDBTermsList__(USES_REGS1) {
|
|
|
|
if (DBTermsList) {
|
|
|
|
struct dbterm_list *dbl = PtoDBTLAdjust(DBTermsList);
|
|
|
|
DBTermsList = dbl;
|
2009-10-28 15:20:46 +00:00
|
|
|
while (dbl) {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBTermEntry(dbl PASS_REGS);
|
2009-10-28 15:20:46 +00:00
|
|
|
dbl = dbl->next_dbl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreExpandList__(USES_REGS1) {
|
|
|
|
if (ExpandClausesFirst)
|
|
|
|
ExpandClausesFirst = PtoOpAdjust(ExpandClausesFirst);
|
|
|
|
if (ExpandClausesLast)
|
|
|
|
ExpandClausesLast = PtoOpAdjust(ExpandClausesLast);
|
2004-09-27 21:45:04 +01:00
|
|
|
{
|
2016-01-03 02:06:09 +00:00
|
|
|
yamop *ptr = ExpandClausesFirst;
|
2004-09-27 21:45:04 +01:00
|
|
|
while (ptr) {
|
2011-03-07 16:02:55 +00:00
|
|
|
do_clean_susp_clauses(ptr PASS_REGS);
|
2014-05-30 01:06:09 +01:00
|
|
|
ptr = ptr->y_u.sssllp.snext;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
2009-10-28 15:20:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreUdiControlBlocks(void) {}
|
2009-10-28 15:53:23 +00:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreIntKeys__(USES_REGS1) {
|
|
|
|
if (INT_KEYS != NULL) {
|
|
|
|
INT_KEYS = (Prop *)AddrAdjust((ADDR)(INT_KEYS));
|
2009-10-28 15:53:23 +00:00
|
|
|
{
|
|
|
|
UInt i;
|
2016-01-03 02:06:09 +00:00
|
|
|
for (i = 0; i < INT_KEYS_SIZE; i++) {
|
|
|
|
if (INT_KEYS[i] != NIL) {
|
|
|
|
Prop p0 = INT_KEYS[i] = PropAdjust(INT_KEYS[i]);
|
|
|
|
RestoreEntries(RepProp(p0), TRUE PASS_REGS);
|
|
|
|
}
|
2009-10-28 15:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreIntLUKeys__(USES_REGS1) {
|
|
|
|
if (INT_LU_KEYS != NULL) {
|
|
|
|
INT_LU_KEYS = (Prop *)AddrAdjust((ADDR)(INT_LU_KEYS));
|
2009-10-28 15:53:23 +00:00
|
|
|
{
|
|
|
|
Int i;
|
|
|
|
for (i = 0; i < INT_KEYS_SIZE; i++) {
|
2016-01-03 02:06:09 +00:00
|
|
|
Prop p0 = INT_LU_KEYS[i];
|
|
|
|
if (p0) {
|
|
|
|
p0 = PropAdjust(p0);
|
|
|
|
INT_LU_KEYS[i] = p0;
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *pe = RepPredProp(p0);
|
|
|
|
pe->NextOfPE = PropAdjust(pe->NextOfPE);
|
|
|
|
CleanCode(pe PASS_REGS);
|
|
|
|
p0 = RepProp(pe->NextOfPE);
|
|
|
|
}
|
|
|
|
}
|
2009-10-28 15:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreIntBBKeys__(USES_REGS1) {
|
|
|
|
if (INT_BB_KEYS != NULL) {
|
|
|
|
INT_BB_KEYS = (Prop *)AddrAdjust((ADDR)(INT_BB_KEYS));
|
2009-10-28 15:53:23 +00:00
|
|
|
{
|
|
|
|
UInt i;
|
2016-01-03 02:06:09 +00:00
|
|
|
for (i = 0; i < INT_BB_KEYS_SIZE; i++) {
|
|
|
|
if (INT_BB_KEYS[i] != NIL) {
|
|
|
|
Prop p0 = INT_BB_KEYS[i] = PropAdjust(INT_BB_KEYS[i]);
|
|
|
|
RestoreEntries(RepProp(p0), TRUE PASS_REGS);
|
|
|
|
}
|
2009-10-28 15:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDBErasedMarker__(USES_REGS1) {
|
|
|
|
DBErasedMarker = DBRefAdjust(DBErasedMarker, TRUE);
|
|
|
|
DBErasedMarker->id = FunctorDBRef;
|
|
|
|
DBErasedMarker->Flags = ErasedMask;
|
|
|
|
DBErasedMarker->Code = NULL;
|
|
|
|
DBErasedMarker->DBT.DBRefs = NULL;
|
|
|
|
DBErasedMarker->Parent = NULL;
|
2009-10-28 15:53:23 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreLogDBErasedMarker__(USES_REGS1) {
|
|
|
|
LogDBErasedMarker = PtoLUCAdjust(LogDBErasedMarker);
|
|
|
|
LogDBErasedMarker->Id = FunctorDBRef;
|
|
|
|
LogDBErasedMarker->ClFlags = ErasedMask | LogUpdMask;
|
|
|
|
LogDBErasedMarker->lusl.ClSource = NULL;
|
|
|
|
LogDBErasedMarker->ClRefCount = 0;
|
|
|
|
LogDBErasedMarker->ClPred = PredLogUpdClause;
|
|
|
|
LogDBErasedMarker->ClExt = NULL;
|
|
|
|
LogDBErasedMarker->ClPrev = NULL;
|
|
|
|
LogDBErasedMarker->ClNext = NULL;
|
|
|
|
LogDBErasedMarker->ClSize = (UInt)NEXTOP(((LogUpdClause *)NULL)->ClCode, e);
|
|
|
|
LogDBErasedMarker->ClCode->opc = Yap_opcode(_op_fail);
|
|
|
|
INIT_CLREF_COUNT(LogDBErasedMarker);
|
2009-10-28 15:53:23 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDeadStaticClauses__(USES_REGS1) {
|
|
|
|
if (DeadStaticClauses) {
|
|
|
|
StaticClause *sc = PtoStCAdjust(DeadStaticClauses);
|
|
|
|
DeadStaticClauses = sc;
|
2006-03-22 20:07:28 +00:00
|
|
|
while (sc) {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreStaticClause(sc PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
sc = sc->ClNext;
|
|
|
|
}
|
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDeadMegaClauses__(USES_REGS1) {
|
|
|
|
if (DeadMegaClauses) {
|
|
|
|
MegaClause *mc = (MegaClause *)AddrAdjust((ADDR)(DeadMegaClauses));
|
|
|
|
DeadMegaClauses = mc;
|
2006-03-22 20:07:28 +00:00
|
|
|
while (mc) {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreMegaClause(mc PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
mc = mc->ClNext;
|
|
|
|
}
|
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDeadStaticIndices__(USES_REGS1) {
|
|
|
|
if (DeadStaticIndices) {
|
|
|
|
StaticIndex *si = (StaticIndex *)AddrAdjust((ADDR)(DeadStaticIndices));
|
|
|
|
DeadStaticIndices = si;
|
2006-03-22 20:07:28 +00:00
|
|
|
while (si) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanSIndex(si, FALSE PASS_REGS);
|
2006-03-22 20:07:28 +00:00
|
|
|
si = si->SiblingIndex;
|
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDBErasedList__(USES_REGS1) {
|
|
|
|
if (DBErasedList) {
|
|
|
|
LogUpdClause *lcl = DBErasedList = PtoLUCAdjust(DBErasedList);
|
2008-05-12 15:04:23 +01:00
|
|
|
while (lcl) {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreLUClause(lcl, FALSE PASS_REGS);
|
2008-05-12 15:04:23 +01:00
|
|
|
lcl = lcl->ClNext;
|
|
|
|
}
|
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDBErasedIList__(USES_REGS1) {
|
|
|
|
if (DBErasedIList) {
|
|
|
|
LogUpdIndex *icl = DBErasedIList = LUIndexAdjust(DBErasedIList);
|
2008-05-12 15:04:23 +01:00
|
|
|
while (icl) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanLUIndex(icl, FALSE PASS_REGS);
|
2008-05-12 15:04:23 +01:00
|
|
|
icl = icl->SiblingIndex;
|
|
|
|
}
|
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreForeignCode__(USES_REGS1) {
|
2009-10-30 23:59:00 +00:00
|
|
|
ForeignObj *f_code;
|
|
|
|
|
|
|
|
if (!ForeignCodeLoaded)
|
|
|
|
return;
|
2016-01-03 02:06:09 +00:00
|
|
|
if (ForeignCodeLoaded != NULL)
|
2009-10-30 23:59:00 +00:00
|
|
|
ForeignCodeLoaded = (void *)AddrAdjust((ADDR)ForeignCodeLoaded);
|
|
|
|
f_code = ForeignCodeLoaded;
|
|
|
|
while (f_code != NULL) {
|
|
|
|
StringList objs, libs;
|
|
|
|
if (f_code->objs != NULL)
|
|
|
|
f_code->objs = (StringList)AddrAdjust((ADDR)f_code->objs);
|
|
|
|
objs = f_code->objs;
|
|
|
|
while (objs != NULL) {
|
|
|
|
if (objs->next != NULL)
|
2016-01-03 02:06:09 +00:00
|
|
|
objs->next = (StringList)AddrAdjust((ADDR)objs->next);
|
|
|
|
objs->name = AtomAdjust(objs->name);
|
2009-10-30 23:59:00 +00:00
|
|
|
objs = objs->next;
|
|
|
|
}
|
|
|
|
if (f_code->libs != NULL)
|
|
|
|
f_code->libs = (StringList)AddrAdjust((ADDR)f_code->libs);
|
|
|
|
libs = f_code->libs;
|
|
|
|
while (libs != NULL) {
|
|
|
|
if (libs->next != NULL)
|
2016-01-03 02:06:09 +00:00
|
|
|
libs->next = (StringList)AddrAdjust((ADDR)libs->next);
|
2010-12-12 18:28:55 +00:00
|
|
|
libs->name = AtomAdjust(libs->name);
|
2009-10-30 23:59:00 +00:00
|
|
|
libs = libs->next;
|
|
|
|
}
|
2012-06-11 22:11:30 +01:00
|
|
|
if (f_code->f != NULL) {
|
|
|
|
f_code->f = AtomAdjust(f_code->f);
|
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
if (f_code->next != NULL)
|
|
|
|
f_code->next = (ForeignObj *)AddrAdjust((ADDR)f_code->next);
|
|
|
|
f_code = f_code->next;
|
2008-04-01 10:41:05 +01:00
|
|
|
}
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 20:59:10 +01:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreYapRecords__(USES_REGS1) {
|
2011-01-03 03:16:29 +00:00
|
|
|
struct record_list *ptr;
|
|
|
|
|
|
|
|
Yap_Records = DBRecordAdjust(Yap_Records);
|
|
|
|
ptr = Yap_Records;
|
|
|
|
while (ptr) {
|
|
|
|
ptr->next_rec = DBRecordAdjust(ptr->next_rec);
|
|
|
|
ptr->prev_rec = DBRecordAdjust(ptr->prev_rec);
|
|
|
|
ptr->dbrecord = DBTermAdjust(ptr->dbrecord);
|
2016-09-21 20:59:10 +01:00
|
|
|
RestoreDBTerm(ptr->dbrecord, false, 0 PASS_REGS);
|
2013-01-22 16:01:37 +00:00
|
|
|
ptr = ptr->next_rec;
|
2011-01-03 03:16:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:49:51 +01:00
|
|
|
#if defined(THREADS) || defined(YAPOR)
|
2016-02-03 10:17:01 +00:00
|
|
|
#include "rglobals.h"
|
2016-08-01 23:49:51 +01:00
|
|
|
#endif
|
2016-01-03 02:06:09 +00:00
|
|
|
|
2016-02-03 10:17:01 +00:00
|
|
|
#include "rlocals.h"
|
2010-03-21 22:12:42 +00:00
|
|
|
|
2009-10-30 23:59:00 +00:00
|
|
|
/* restore the failcodes */
|
2016-01-03 02:06:09 +00:00
|
|
|
static void restore_codes(void) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2016-01-03 02:06:09 +00:00
|
|
|
HeapTop = AddrAdjust(LOCAL_OldHeapTop);
|
2002-06-04 19:21:55 +01:00
|
|
|
|
2016-02-03 10:17:01 +00:00
|
|
|
#include "rhstruct.h"
|
2002-06-04 19:21:55 +01:00
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
RestoreWorker(worker_id PASS_REGS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RestoreDBEntry(DBRef dbr USES_REGS) {
|
2002-06-04 19:21:55 +01:00
|
|
|
#ifdef DEBUG_RESTORE
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, "Restoring at %x", dbr);
|
2002-06-04 19:21:55 +01:00
|
|
|
if (dbr->Flags & DBAtomic)
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, " an atomic term\n");
|
2002-06-04 19:21:55 +01:00
|
|
|
else if (dbr->Flags & DBNoVars)
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, " with no vars\n");
|
2002-06-04 19:21:55 +01:00
|
|
|
else if (dbr->Flags & DBComplex)
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, " complex term\n");
|
2002-06-04 19:21:55 +01:00
|
|
|
else if (dbr->Flags & DBIsRef)
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, " a ref\n");
|
2002-06-04 19:21:55 +01:00
|
|
|
else
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, " a var\n");
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif
|
2016-02-28 19:30:46 +00:00
|
|
|
RestoreDBTerm(&(dbr->DBT), true, 1 PASS_REGS);
|
2005-10-19 20:00:48 +01:00
|
|
|
if (dbr->Parent) {
|
|
|
|
dbr->Parent = (DBProp)AddrAdjust((ADDR)(dbr->Parent));
|
|
|
|
}
|
2003-02-12 13:20:52 +00:00
|
|
|
if (dbr->Code != NULL)
|
|
|
|
dbr->Code = PtoOpAdjust(dbr->Code);
|
2002-06-04 19:21:55 +01:00
|
|
|
if (dbr->Prev != NULL)
|
2016-01-03 02:06:09 +00:00
|
|
|
dbr->Prev = DBRefAdjust(dbr->Prev, TRUE);
|
2002-06-04 19:21:55 +01:00
|
|
|
if (dbr->Next != NULL)
|
2016-01-03 02:06:09 +00:00
|
|
|
dbr->Next = DBRefAdjust(dbr->Next, TRUE);
|
2002-06-04 19:21:55 +01:00
|
|
|
#ifdef DEBUG_RESTORE2
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, "Recomputing masks\n");
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif
|
|
|
|
recompute_mask(dbr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restores a DB structure, as it was saved in the heap */
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreDB(DBEntry *pp USES_REGS) {
|
|
|
|
register DBRef dbr;
|
2002-06-04 19:21:55 +01:00
|
|
|
|
|
|
|
if (pp->First != NULL)
|
2016-01-03 02:06:09 +00:00
|
|
|
pp->First = DBRefAdjust(pp->First, TRUE);
|
2002-06-04 19:21:55 +01:00
|
|
|
if (pp->Last != NULL)
|
2012-06-12 14:50:36 +01:00
|
|
|
pp->Last = DBRefAdjust(pp->Last, TRUE);
|
2002-06-04 19:21:55 +01:00
|
|
|
if (pp->ArityOfDB)
|
|
|
|
pp->FunctorOfDB = FuncAdjust(pp->FunctorOfDB);
|
|
|
|
else
|
2016-01-03 02:06:09 +00:00
|
|
|
pp->FunctorOfDB = (Functor)AtomAdjust((Atom)(pp->FunctorOfDB));
|
2006-02-24 14:03:42 +00:00
|
|
|
if (pp->F0 != NULL)
|
2012-06-12 14:50:36 +01:00
|
|
|
pp->F0 = DBRefAdjust(pp->F0, TRUE);
|
2006-02-24 14:03:42 +00:00
|
|
|
if (pp->L0 != NULL)
|
2012-06-12 14:50:36 +01:00
|
|
|
pp->L0 = DBRefAdjust(pp->L0, TRUE);
|
2006-02-24 14:03:42 +00:00
|
|
|
/* immediate update semantics */
|
|
|
|
dbr = pp->F0;
|
|
|
|
/* While we have something in the data base, even if erased, restore it */
|
|
|
|
while (dbr) {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBEntry(dbr PASS_REGS);
|
2006-02-24 14:03:42 +00:00
|
|
|
if (dbr->n != NULL)
|
2012-06-12 14:50:36 +01:00
|
|
|
dbr->n = DBRefAdjust(dbr->n, TRUE);
|
2006-02-24 14:03:42 +00:00
|
|
|
if (dbr->p != NULL)
|
2012-06-12 14:50:36 +01:00
|
|
|
dbr->p = DBRefAdjust(dbr->p, TRUE);
|
2006-02-24 14:03:42 +00:00
|
|
|
dbr = dbr->n;
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restores a group of clauses for the same predicate, starting with First
|
2016-01-03 02:06:09 +00:00
|
|
|
* and ending with Last, First may be equal to Last
|
2002-06-04 19:21:55 +01:00
|
|
|
*/
|
2016-01-03 02:06:09 +00:00
|
|
|
static void CleanClauses(yamop *First, yamop *Last, PredEntry *pp USES_REGS) {
|
|
|
|
if (!First)
|
|
|
|
return;
|
2003-08-27 14:37:10 +01:00
|
|
|
if (pp->PredFlags & LogUpdatePredFlag) {
|
|
|
|
LogUpdClause *cl = ClauseCodeToLogUpdClause(First);
|
|
|
|
while (cl != NULL) {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreLUClause(cl, pp PASS_REGS);
|
2003-08-27 14:37:10 +01:00
|
|
|
cl = cl->ClNext;
|
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
} else if (pp->PredFlags & MegaClausePredFlag) {
|
|
|
|
MegaClause *cl = ClauseCodeToMegaClause(First);
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreMegaClause(cl PASS_REGS);
|
2003-11-26 18:36:35 +00:00
|
|
|
} else if (pp->PredFlags & DynamicPredFlag) {
|
|
|
|
yamop *cl = First;
|
|
|
|
|
|
|
|
do {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDynamicClause(ClauseCodeToDynamicClause(cl), pp PASS_REGS);
|
2016-01-03 02:06:09 +00:00
|
|
|
if (cl == Last)
|
|
|
|
return;
|
2003-11-26 18:36:35 +00:00
|
|
|
cl = NextDynamicClause(cl);
|
|
|
|
} while (TRUE);
|
2003-08-27 14:37:10 +01:00
|
|
|
} else {
|
2004-02-06 02:26:23 +00:00
|
|
|
StaticClause *cl = ClauseCodeToStaticClause(First);
|
2003-08-27 14:37:10 +01:00
|
|
|
|
|
|
|
do {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreStaticClause(cl PASS_REGS);
|
2016-01-03 02:06:09 +00:00
|
|
|
if (cl->ClCode == Last)
|
|
|
|
return;
|
2004-02-06 02:26:23 +00:00
|
|
|
cl = cl->ClNext;
|
2003-08-27 14:37:10 +01:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
|
2005-06-01 14:53:46 +01:00
|
|
|
/* Restores a DB structure, as it was saved in the heap */
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreBB(BlackBoardEntry *pp, int int_key USES_REGS) {
|
2005-06-01 14:53:46 +01:00
|
|
|
Term t = pp->Element;
|
|
|
|
if (t) {
|
2007-02-18 00:26:36 +00:00
|
|
|
if (!IsVarTerm(t)) {
|
|
|
|
if (IsAtomicTerm(t)) {
|
2016-01-03 02:06:09 +00:00
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
pp->Element = AtomTermAdjust(t);
|
|
|
|
}
|
2007-02-18 00:26:36 +00:00
|
|
|
} else {
|
2016-01-03 02:06:09 +00:00
|
|
|
RestoreLUClause((LogUpdClause *)DBRefOfTerm(t), NULL PASS_REGS);
|
2007-02-18 00:26:36 +00:00
|
|
|
}
|
2005-06-01 14:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2008-04-03 12:34:47 +01:00
|
|
|
if (!int_key) {
|
|
|
|
pp->KeyOfBB = AtomAdjust(pp->KeyOfBB);
|
|
|
|
}
|
2008-05-12 15:04:23 +01:00
|
|
|
if (pp->ModuleOfBB) {
|
|
|
|
pp->ModuleOfBB = AtomTermAdjust(pp->ModuleOfBB);
|
|
|
|
}
|
2005-06-01 14:53:46 +01:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void restore_static_array(StaticArrayEntry *ae USES_REGS) {
|
2002-06-04 19:21:55 +01:00
|
|
|
Int sz = -ae->ArrayEArity;
|
|
|
|
switch (ae->ArrayType) {
|
|
|
|
case array_of_ints:
|
|
|
|
case array_of_doubles:
|
|
|
|
case array_of_chars:
|
|
|
|
case array_of_uchars:
|
2016-01-03 02:06:09 +00:00
|
|
|
return;
|
|
|
|
case array_of_ptrs: {
|
|
|
|
AtomEntry **base = (AtomEntry **)AddrAdjust((ADDR)(ae->ValueOfVE.ptrs));
|
|
|
|
Int i;
|
|
|
|
ae->ValueOfVE.ptrs = base;
|
|
|
|
if (ae != NULL) {
|
|
|
|
for (i = 0; i < sz; i++) {
|
|
|
|
AtomEntry *reg = *base;
|
|
|
|
if (reg == NULL) {
|
|
|
|
base++;
|
|
|
|
} else if (IsOldCode((CELL)reg)) {
|
|
|
|
*base++ = AtomEntryAdjust(reg);
|
|
|
|
} else if (IsOldLocalInTR((CELL)reg)) {
|
|
|
|
*base++ = (AtomEntry *)LocalAddrAdjust((ADDR)reg);
|
|
|
|
} else if (IsOldGlobal((CELL)reg)) {
|
|
|
|
*base++ = (AtomEntry *)GlobalAddrAdjust((ADDR)reg);
|
|
|
|
} else if (IsOldTrail((CELL)reg)) {
|
|
|
|
*base++ = (AtomEntry *)TrailAddrAdjust((ADDR)reg);
|
|
|
|
} else {
|
|
|
|
/* oops */
|
|
|
|
base++;
|
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case array_of_atoms: {
|
|
|
|
Term *base = (Term *)AddrAdjust((ADDR)(ae->ValueOfVE.atoms));
|
|
|
|
Int i;
|
|
|
|
ae->ValueOfVE.atoms = base;
|
|
|
|
if (ae != 0L) {
|
|
|
|
for (i = 0; i < sz; i++) {
|
|
|
|
Term reg = *base;
|
|
|
|
if (reg == 0L) {
|
|
|
|
base++;
|
|
|
|
} else {
|
|
|
|
*base++ = AtomTermAdjust(reg);
|
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case array_of_dbrefs: {
|
|
|
|
Term *base = (Term *)AddrAdjust((ADDR)(ae->ValueOfVE.dbrefs));
|
|
|
|
Int i;
|
|
|
|
|
|
|
|
ae->ValueOfVE.dbrefs = base;
|
|
|
|
if (ae != 0L) {
|
|
|
|
for (i = 0; i < sz; i++) {
|
|
|
|
Term reg = *base;
|
|
|
|
if (reg == 0L) {
|
|
|
|
base++;
|
|
|
|
} else {
|
|
|
|
*base++ = AbsAppl(PtoHeapCellAdjust(RepAppl(reg)));
|
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case array_of_nb_terms: {
|
|
|
|
live_term *base = (live_term *)AddrAdjust((ADDR)(ae->ValueOfVE.lterms));
|
|
|
|
Int i;
|
|
|
|
|
|
|
|
ae->ValueOfVE.lterms = base;
|
|
|
|
if (ae != 0L) {
|
|
|
|
for (i = 0; i < sz; i++, base++) {
|
|
|
|
Term reg = base->tlive;
|
|
|
|
if (IsVarTerm(reg)) {
|
|
|
|
CELL *var = (CELL *)reg;
|
|
|
|
|
|
|
|
if (IsOldGlobalPtr(var)) {
|
|
|
|
base->tlive = (CELL)PtoGloAdjust(var);
|
|
|
|
} else {
|
|
|
|
base->tlive = (CELL)PtoHeapCellAdjust(var);
|
|
|
|
}
|
|
|
|
} else if (IsAtomTerm(reg)) {
|
|
|
|
base->tlive = AtomTermAdjust(reg);
|
|
|
|
} else if (IsApplTerm(reg)) {
|
|
|
|
CELL *db = RepAppl(reg);
|
|
|
|
db = PtoGloAdjust(db);
|
|
|
|
base->tlive = AbsAppl(db);
|
|
|
|
} else if (IsApplTerm(reg)) {
|
|
|
|
CELL *db = RepPair(reg);
|
|
|
|
db = PtoGloAdjust(db);
|
|
|
|
base->tlive = AbsPair(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
reg = base->tstore;
|
|
|
|
if (IsVarTerm(reg)) {
|
|
|
|
base->tstore = (Term)GlobalAddrAdjust((ADDR)reg);
|
|
|
|
} else if (IsAtomTerm(reg)) {
|
|
|
|
base->tstore = AtomTermAdjust(reg);
|
|
|
|
} else {
|
|
|
|
DBTerm *db = (DBTerm *)RepAppl(reg);
|
|
|
|
db = DBTermAdjust(db);
|
2016-02-28 19:30:46 +00:00
|
|
|
RestoreDBTerm(db, false, 1 PASS_REGS);
|
2016-01-03 02:06:09 +00:00
|
|
|
base->tstore = AbsAppl((CELL *)db);
|
|
|
|
}
|
2005-10-19 20:00:48 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
|
|
|
case array_of_terms: {
|
|
|
|
DBTerm **base = (DBTerm **)AddrAdjust((ADDR)(ae->ValueOfVE.terms));
|
|
|
|
Int i;
|
|
|
|
|
|
|
|
ae->ValueOfVE.terms = base;
|
|
|
|
if (ae != 0L) {
|
|
|
|
for (i = 0; i < sz; i++) {
|
|
|
|
DBTerm *reg = *base;
|
|
|
|
if (reg == NULL) {
|
|
|
|
base++;
|
|
|
|
} else {
|
|
|
|
*base++ = reg = DBTermAdjust(reg);
|
2016-02-28 19:30:46 +00:00
|
|
|
RestoreDBTerm(reg, false, 1 PASS_REGS);
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
}
|
|
|
|
return;
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean all the code for a particular predicate, this can get a bit tricky,
|
2016-01-03 02:06:09 +00:00
|
|
|
* because of the indexing code
|
2002-06-04 19:21:55 +01:00
|
|
|
*/
|
2016-01-03 02:06:09 +00:00
|
|
|
static void CleanCode(PredEntry *pp USES_REGS) {
|
|
|
|
pred_flags_t flag;
|
2002-06-04 19:21:55 +01:00
|
|
|
|
|
|
|
/* Init takes care of the first 2 cases */
|
2004-02-12 17:09:17 +00:00
|
|
|
if (pp->ModuleOfPred) {
|
|
|
|
pp->ModuleOfPred = AtomTermAdjust(pp->ModuleOfPred);
|
|
|
|
}
|
2005-05-30 04:26:37 +01:00
|
|
|
if (pp->ArityOfPE) {
|
|
|
|
if (pp->ModuleOfPred == IDB_MODULE) {
|
2008-02-07 21:39:51 +00:00
|
|
|
if (pp->PredFlags & NumberDBPredFlag) {
|
2016-01-03 02:06:09 +00:00
|
|
|
/* it's an integer, do nothing */
|
2008-02-07 21:39:51 +00:00
|
|
|
} else if (pp->PredFlags & AtomDBPredFlag) {
|
2016-01-03 02:06:09 +00:00
|
|
|
pp->FunctorOfPred = (Functor)AtomAdjust((Atom)(pp->FunctorOfPred));
|
2005-05-30 04:26:37 +01:00
|
|
|
} else {
|
2016-01-03 02:06:09 +00:00
|
|
|
pp->FunctorOfPred = FuncAdjust(pp->FunctorOfPred);
|
2005-05-30 04:26:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pp->FunctorOfPred = FuncAdjust(pp->FunctorOfPred);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pp->FunctorOfPred = (Functor)AtomAdjust((Atom)(pp->FunctorOfPred));
|
|
|
|
}
|
2004-02-06 10:19:49 +00:00
|
|
|
if (!(pp->PredFlags & NumberDBPredFlag)) {
|
2011-08-28 01:23:14 +01:00
|
|
|
if (pp->src.OwnerFile) {
|
|
|
|
pp->src.OwnerFile = AtomAdjust(pp->src.OwnerFile);
|
2008-04-04 10:10:02 +01:00
|
|
|
}
|
2004-02-06 10:19:49 +00:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pp->OpcodeOfPred = Yap_opcode(Yap_op_from_opcode(pp->OpcodeOfPred));
|
2008-04-06 12:53:02 +01:00
|
|
|
if (pp->NextPredOfModule) {
|
|
|
|
pp->NextPredOfModule = PtoPredAdjust(pp->NextPredOfModule);
|
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
if (pp->PredFlags & (AsmPredFlag | CPredFlag)) {
|
2002-06-04 19:21:55 +01:00
|
|
|
/* assembly */
|
2002-12-27 16:53:09 +00:00
|
|
|
if (pp->CodeOfPred) {
|
|
|
|
pp->CodeOfPred = PtoOpAdjust(pp->CodeOfPred);
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanClauses(pp->CodeOfPred, pp->CodeOfPred, pp PASS_REGS);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
} else {
|
2016-01-03 02:06:09 +00:00
|
|
|
yamop *FirstC, *LastC;
|
2002-12-27 16:53:09 +00:00
|
|
|
/* Prolog code */
|
|
|
|
if (pp->cs.p_code.FirstClause)
|
|
|
|
pp->cs.p_code.FirstClause = PtoOpAdjust(pp->cs.p_code.FirstClause);
|
|
|
|
if (pp->cs.p_code.LastClause)
|
|
|
|
pp->cs.p_code.LastClause = PtoOpAdjust(pp->cs.p_code.LastClause);
|
2016-01-03 02:06:09 +00:00
|
|
|
pp->CodeOfPred = PtoOpAdjust(pp->CodeOfPred);
|
2002-12-27 16:53:09 +00:00
|
|
|
pp->cs.p_code.TrueCodeOfPred = PtoOpAdjust(pp->cs.p_code.TrueCodeOfPred);
|
2003-08-27 14:37:10 +01:00
|
|
|
pp->cs.p_code.ExpandCode = Yap_opcode(_expand_index);
|
2002-06-04 19:21:55 +01:00
|
|
|
flag = pp->PredFlags;
|
2002-12-27 16:53:09 +00:00
|
|
|
FirstC = pp->cs.p_code.FirstClause;
|
|
|
|
LastC = pp->cs.p_code.LastClause;
|
2002-06-04 19:21:55 +01:00
|
|
|
/* We just have a fail here */
|
2004-02-06 10:19:49 +00:00
|
|
|
if (FirstC == NULL && LastC == NULL) {
|
2002-06-04 19:21:55 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
#ifdef DEBUG_RESTORE2
|
|
|
|
fprintf(stderr, "at %lx Correcting clauses from %p to %p\n",
|
|
|
|
*(OPCODE *)FirstC, FirstC, LastC);
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanClauses(FirstC, LastC, pp PASS_REGS);
|
2004-02-06 02:26:23 +00:00
|
|
|
if (flag & IndexedPredFlag) {
|
2016-01-03 02:06:09 +00:00
|
|
|
#ifdef DEBUG_RESTORE2
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, "Correcting indexed code\n");
|
|
|
|
#endif
|
|
|
|
if (flag & LogUpdatePredFlag) {
|
2016-01-03 02:06:09 +00:00
|
|
|
CleanLUIndex(ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred),
|
|
|
|
TRUE PASS_REGS);
|
2004-02-06 02:26:23 +00:00
|
|
|
} else {
|
2016-01-03 02:06:09 +00:00
|
|
|
CleanSIndex(ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred),
|
|
|
|
TRUE PASS_REGS);
|
|
|
|
}
|
2004-02-06 02:26:23 +00:00
|
|
|
} else if (flag & DynamicPredFlag) {
|
2016-01-03 02:06:09 +00:00
|
|
|
#ifdef DEBUG_RESTORE2
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, "Correcting dynamic code\n");
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif
|
2016-01-03 02:06:09 +00:00
|
|
|
RestoreDynamicClause(
|
|
|
|
ClauseCodeToDynamicClause(pp->cs.p_code.TrueCodeOfPred),
|
|
|
|
pp PASS_REGS);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* we are pointing at ourselves */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restores all of the entries, for a particular atom, we only have problems
|
2016-01-03 02:06:09 +00:00
|
|
|
* if we find code or data bases
|
2002-06-04 19:21:55 +01:00
|
|
|
*/
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreEntries(PropEntry *pp, int int_key USES_REGS) {
|
2002-06-04 19:21:55 +01:00
|
|
|
while (!EndOfPAEntr(pp)) {
|
2016-01-03 02:06:09 +00:00
|
|
|
switch (pp->KindOfPE) {
|
|
|
|
case FunctorProperty: {
|
|
|
|
FunctorEntry *fe = (FunctorEntry *)pp;
|
|
|
|
Prop p0;
|
|
|
|
fe->NextOfPE = PropAdjust(fe->NextOfPE);
|
|
|
|
fe->NameOfFE = AtomAdjust(fe->NameOfFE);
|
|
|
|
p0 = fe->PropsOfFE = PropAdjust(fe->PropsOfFE);
|
|
|
|
if (!EndOfPAEntr(p0)) {
|
|
|
|
/* at most one property */
|
|
|
|
CleanCode(RepPredProp(p0) PASS_REGS);
|
|
|
|
RepPredProp(p0)->NextOfPE = PropAdjust(RepPredProp(p0)->NextOfPE);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
} break;
|
|
|
|
case ValProperty: {
|
|
|
|
ValEntry *ve = (ValEntry *)pp;
|
|
|
|
Term tv = ve->ValueOfVE;
|
|
|
|
ve->NextOfPE = PropAdjust(ve->NextOfPE);
|
|
|
|
if (IsAtomTerm(tv))
|
|
|
|
ve->ValueOfVE = AtomTermAdjust(tv);
|
|
|
|
} break;
|
|
|
|
case HoldProperty: {
|
|
|
|
HoldEntry *he = (HoldEntry *)pp;
|
|
|
|
he->NextOfPE = PropAdjust(he->NextOfPE);
|
|
|
|
} break;
|
|
|
|
case MutexProperty: {
|
|
|
|
HoldEntry *he = (HoldEntry *)pp;
|
|
|
|
he->NextOfPE = PropAdjust(he->NextOfPE);
|
|
|
|
} break;
|
|
|
|
case TranslationProperty: {
|
|
|
|
TranslationEntry *he = (TranslationEntry *)pp;
|
|
|
|
he->NextOfPE = PropAdjust(he->NextOfPE);
|
|
|
|
} break;
|
|
|
|
case FlagProperty: {
|
|
|
|
FlagEntry *he = (FlagEntry *)pp;
|
|
|
|
he->NextOfPE = PropAdjust(he->NextOfPE);
|
|
|
|
} break;
|
|
|
|
case ArrayProperty: {
|
|
|
|
ArrayEntry *ae = (ArrayEntry *)pp;
|
|
|
|
ae->NextOfPE = PropAdjust(ae->NextOfPE);
|
|
|
|
if (ae->TypeOfAE == STATIC_ARRAY) {
|
|
|
|
/* static array entry */
|
|
|
|
StaticArrayEntry *sae = (StaticArrayEntry *)ae;
|
|
|
|
if (sae->NextAE)
|
|
|
|
sae->NextAE = PtoArraySAdjust(sae->NextAE);
|
|
|
|
restore_static_array(sae PASS_REGS);
|
|
|
|
} else {
|
|
|
|
if (ae->NextAE)
|
|
|
|
ae->NextAE = PtoArrayEAdjust(ae->NextAE);
|
|
|
|
if (IsVarTerm(ae->ValueOfVE))
|
|
|
|
RESET_VARIABLE(&(ae->ValueOfVE));
|
|
|
|
else {
|
|
|
|
CELL *ptr = RepAppl(ae->ValueOfVE);
|
|
|
|
/* in fact it should just be a pointer to the global,
|
|
|
|
but we'll be conservative.
|
|
|
|
Notice that the variable should have been reset in restore_program
|
|
|
|
mode.
|
|
|
|
*/
|
|
|
|
if (IsOldGlobalPtr(ptr)) {
|
|
|
|
ae->ValueOfVE = AbsAppl(PtoGloAdjust(ptr));
|
|
|
|
} else if (IsOldCodeCellPtr(ptr)) {
|
|
|
|
ae->ValueOfVE = AbsAppl(PtoHeapCellAdjust(ptr));
|
|
|
|
} else if (IsOldLocalInTRPtr(ptr)) {
|
|
|
|
ae->ValueOfVE = AbsAppl(PtoLocAdjust(ptr));
|
|
|
|
} else if (IsOldTrailPtr(ptr)) {
|
|
|
|
ae->ValueOfVE = AbsAppl(CellPtoTRAdjust(ptr));
|
|
|
|
}
|
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
} break;
|
|
|
|
case PEProp: {
|
|
|
|
PredEntry *pe = (PredEntry *)pp;
|
|
|
|
pe->NextOfPE = PropAdjust(pe->NextOfPE);
|
|
|
|
CleanCode(pe PASS_REGS);
|
|
|
|
} break;
|
2002-06-04 19:21:55 +01:00
|
|
|
case DBProperty:
|
|
|
|
case CodeDBProperty:
|
|
|
|
#ifdef DEBUG_RESTORE2
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, "Correcting data base clause at %p\n", pp);
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif
|
|
|
|
{
|
2016-01-03 02:06:09 +00:00
|
|
|
DBEntry *de = (DBEntry *)pp;
|
|
|
|
de->NextOfPE = PropAdjust(de->NextOfPE);
|
|
|
|
RestoreDB(de PASS_REGS);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
break;
|
2016-01-03 02:06:09 +00:00
|
|
|
case BBProperty: {
|
|
|
|
BlackBoardEntry *bb = (BlackBoardEntry *)pp;
|
|
|
|
bb->NextOfPE = PropAdjust(bb->NextOfPE);
|
|
|
|
RestoreBB(bb, int_key PASS_REGS);
|
|
|
|
} break;
|
|
|
|
case GlobalProperty: {
|
|
|
|
GlobalEntry *gb = (GlobalEntry *)pp;
|
|
|
|
Term gbt = gb->global;
|
|
|
|
|
|
|
|
gb->NextOfPE = PropAdjust(gb->NextOfPE);
|
|
|
|
gb->AtomOfGE = AtomEntryAdjust(gb->AtomOfGE);
|
|
|
|
if (gb->NextGE) {
|
|
|
|
gb->NextGE = GlobalEntryAdjust(gb->NextGE);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
if (IsVarTerm(gbt)) {
|
|
|
|
CELL *gbp = VarOfTerm(gbt);
|
|
|
|
if (IsOldGlobalPtr(gbp))
|
|
|
|
gbp = PtoGloAdjust(gbp);
|
|
|
|
else
|
|
|
|
gbp = CellPtoHeapAdjust(gbp);
|
|
|
|
gb->global = (CELL)gbp;
|
|
|
|
} else if (IsPairTerm(gbt)) {
|
|
|
|
gb->global = AbsPair(PtoGloAdjust(RepPair(gbt)));
|
|
|
|
} else if (IsApplTerm(gbt)) {
|
|
|
|
CELL *gbp = RepAppl(gbt);
|
|
|
|
if (IsOldGlobalPtr(gbp))
|
|
|
|
gbp = PtoGloAdjust(gbp);
|
|
|
|
else
|
|
|
|
gbp = CellPtoHeapAdjust(gbp);
|
|
|
|
gb->global = AbsAppl(gbp);
|
|
|
|
} else if (IsAtomTerm(gbt)) {
|
|
|
|
gb->global = AtomTermAdjust(gbt);
|
|
|
|
} /* numbers need no adjusting */
|
|
|
|
} break;
|
|
|
|
case OpProperty: {
|
|
|
|
OpEntry *opp = (OpEntry *)pp;
|
|
|
|
if (opp->NextOfPE) {
|
|
|
|
opp->NextOfPE = PropAdjust(opp->NextOfPE);
|
2007-01-08 08:27:19 +00:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
opp->OpName = AtomAdjust(opp->OpName);
|
|
|
|
if (opp->OpModule) {
|
|
|
|
opp->OpModule = AtomTermAdjust(opp->OpModule);
|
2005-10-21 17:09:03 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
if (opp->OpNext) {
|
|
|
|
opp->OpNext = OpEntryAdjust(opp->OpNext);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case ModProperty: {
|
|
|
|
ModEntry *me = (ModEntry *)pp;
|
|
|
|
if (me->NextOfPE) {
|
|
|
|
me->NextOfPE = PropAdjust(me->NextOfPE);
|
2007-04-10 23:13:21 +01:00
|
|
|
}
|
2016-01-03 02:06:09 +00:00
|
|
|
if (me->PredForME) {
|
|
|
|
me->PredForME = PtoPredAdjust(me->PredForME);
|
|
|
|
}
|
|
|
|
me->AtomOfME = AtomAdjust(me->AtomOfME);
|
|
|
|
if (me->NextME)
|
|
|
|
me->NextME = (struct mod_entry *)AddrAdjust((ADDR)me->NextME);
|
|
|
|
} break;
|
2007-04-10 23:13:21 +01:00
|
|
|
case ExpProperty:
|
2016-01-03 02:06:09 +00:00
|
|
|
pp->NextOfPE = PropAdjust(pp->NextOfPE);
|
2009-06-02 15:51:57 +01:00
|
|
|
break;
|
2011-03-08 00:22:32 +00:00
|
|
|
case BlobProperty:
|
2016-01-03 02:06:09 +00:00
|
|
|
pp->NextOfPE = PropAdjust(pp->NextOfPE);
|
2011-03-08 00:22:32 +00:00
|
|
|
{
|
2015-10-22 00:33:38 +01:00
|
|
|
YAP_BlobPropEntry *bpe = (YAP_BlobPropEntry *)pp;
|
2016-01-03 02:06:09 +00:00
|
|
|
bpe->blob_type = BlobTypeAdjust(bpe->blob_type);
|
2011-03-08 00:22:32 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-06-04 19:21:55 +01:00
|
|
|
default:
|
|
|
|
/* OOPS */
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
2016-01-03 02:06:09 +00:00
|
|
|
"Invalid Atom Property %d at %p", pp->KindOfPE, pp);
|
2002-06-04 19:21:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
pp = RepProp(pp->NextOfPE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
static void RestoreAtom(AtomEntry *at USES_REGS) {
|
2008-05-12 23:31:37 +01:00
|
|
|
AtomEntry *nat;
|
|
|
|
|
2009-11-23 16:02:05 +00:00
|
|
|
/* this should be done before testing for wide atoms */
|
|
|
|
at->PropsOfAE = PropAdjust(at->PropsOfAE);
|
2016-01-03 02:06:09 +00:00
|
|
|
#if DEBUG_RESTORE2 /* useful during debug */
|
2008-05-12 23:31:37 +01:00
|
|
|
if (IsWideAtom(AbsAtom(at)))
|
2014-09-16 10:00:31 +01:00
|
|
|
fprintf(stderr, "Restoring %S\n", at->WStrOfAE);
|
2008-05-12 23:31:37 +01:00
|
|
|
else
|
2014-09-16 10:00:31 +01:00
|
|
|
fprintf(stderr, "Restoring %s\n", at->StrOfAE);
|
2008-05-12 23:31:37 +01:00
|
|
|
#endif
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreEntries(RepProp(at->PropsOfAE), FALSE PASS_REGS);
|
2008-05-12 23:31:37 +01:00
|
|
|
/* cannot use AtomAdjust without breaking agc */
|
|
|
|
nat = RepAtom(at->NextOfAE);
|
|
|
|
if (nat)
|
|
|
|
at->NextOfAE = AbsAtom(AtomEntryAdjust(nat));
|
|
|
|
}
|
2017-11-11 02:15:59 +00:00
|
|
|
|
|
|
|
#endif
|