2002-06-04 19:21:55 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
2004-03-19 11:35:42 +00:00
|
|
|
* File: rheap.h *
|
2002-06-04 19:21:55 +01:00
|
|
|
* comments: walk through heap code *
|
|
|
|
* *
|
2008-08-07 21:51:23 +01:00
|
|
|
* Last rev: $Date: 2008-08-07 20:51:23 $,$Author: vsc $ *
|
2004-03-31 02:03:10 +01:00
|
|
|
* $Log: not supported by cvs2svn $
|
2008-08-07 21:51:23 +01:00
|
|
|
* Revision 1.99 2008/07/22 23:34:49 vsc
|
|
|
|
* SWI and module fixes
|
|
|
|
*
|
2008-07-23 00:34:50 +01:00
|
|
|
* Revision 1.98 2008/05/12 22:31:37 vsc
|
|
|
|
* fix previous fixes
|
|
|
|
*
|
2008-05-12 23:31:37 +01:00
|
|
|
* Revision 1.97 2008/05/12 14:04:23 vsc
|
|
|
|
* updates to restore
|
|
|
|
*
|
2008-05-12 15:04:23 +01:00
|
|
|
* Revision 1.96 2008/04/11 16:58:17 ricroc
|
|
|
|
* yapor: seq_def initialization
|
|
|
|
*
|
2008-04-11 17:58:17 +01:00
|
|
|
* Revision 1.95 2008/04/06 12:06:48 vsc
|
|
|
|
* more small fixes
|
|
|
|
*
|
2008-04-06 13:06:48 +01:00
|
|
|
* Revision 1.94 2008/04/06 11:53:02 vsc
|
|
|
|
* fix some restore bugs
|
|
|
|
*
|
2008-04-06 12:53:02 +01:00
|
|
|
* Revision 1.93 2008/04/04 09:10:02 vsc
|
|
|
|
* restore was restoring twice
|
|
|
|
*
|
2008-04-04 10:10:02 +01:00
|
|
|
* Revision 1.92 2008/04/03 11:34:47 vsc
|
|
|
|
* fix restorebb in cases entry key is not an atom (obs from Nicos
|
|
|
|
* Angelopoulos)
|
|
|
|
*
|
2008-04-03 12:34:47 +01:00
|
|
|
* Revision 1.91 2008/04/01 15:31:43 vsc
|
|
|
|
* more saved state fixes
|
|
|
|
*
|
2008-04-01 16:31:43 +01:00
|
|
|
* Revision 1.90 2008/04/01 14:09:43 vsc
|
|
|
|
* improve restore
|
|
|
|
*
|
2008-04-01 15:09:43 +01:00
|
|
|
* Revision 1.89 2008/04/01 09:41:05 vsc
|
|
|
|
* more fixes to restore
|
|
|
|
*
|
2008-04-01 10:41:05 +01:00
|
|
|
* Revision 1.88 2008/04/01 08:42:46 vsc
|
|
|
|
* fix restore and small VISTA thingies
|
|
|
|
*
|
2008-04-01 09:42:46 +01:00
|
|
|
* Revision 1.87 2008/03/25 22:03:14 vsc
|
|
|
|
* fix some icc warnings
|
|
|
|
*
|
2008-03-25 22:03:14 +00:00
|
|
|
* Revision 1.86 2008/03/25 16:45:53 vsc
|
|
|
|
* make or-parallelism compile again
|
|
|
|
*
|
2008-03-25 16:45:53 +00:00
|
|
|
* Revision 1.85 2008/02/12 17:03:52 vsc
|
|
|
|
* SWI-portability changes
|
|
|
|
*
|
2008-02-12 17:03:59 +00:00
|
|
|
* Revision 1.84 2008/02/07 21:39:51 vsc
|
|
|
|
* fix case where predicate is for an integer (DBEntry).
|
|
|
|
*
|
2008-02-07 21:39:51 +00:00
|
|
|
* Revision 1.83 2008/01/23 17:57:55 vsc
|
|
|
|
* valgrind it!
|
|
|
|
* enable atom garbage collection.
|
|
|
|
*
|
2008-01-23 17:57:56 +00:00
|
|
|
* Revision 1.82 2007/12/05 12:17:23 vsc
|
|
|
|
* improve JT
|
|
|
|
* fix graph compatibility with SICStus
|
|
|
|
* re-export declaration.
|
|
|
|
*
|
2007-12-05 12:17:25 +00:00
|
|
|
* Revision 1.81 2007/11/26 23:43:09 vsc
|
|
|
|
* fixes to support threads and assert correctly, even if inefficiently.
|
|
|
|
*
|
2007-11-26 23:43:10 +00:00
|
|
|
* Revision 1.80 2007/11/07 09:35:53 vsc
|
|
|
|
* small fix
|
|
|
|
*
|
2007-11-07 09:35:53 +00:00
|
|
|
* Revision 1.79 2007/11/07 09:25:27 vsc
|
|
|
|
* speedup meta-calls
|
|
|
|
*
|
2007-11-07 09:25:27 +00:00
|
|
|
* Revision 1.78 2007/11/06 17:02:12 vsc
|
|
|
|
* compile ground terms away.
|
|
|
|
*
|
2007-11-06 17:02:13 +00:00
|
|
|
* 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
|
|
|
|
*
|
2007-10-10 10:44:28 +01:00
|
|
|
* Revision 1.76 2007/09/28 23:18:17 vsc
|
|
|
|
* handle learning from interpretations.
|
|
|
|
*
|
2007-09-29 00:18:17 +01:00
|
|
|
* Revision 1.75 2007/04/10 22:13:21 vsc
|
|
|
|
* fix max modules limitation
|
|
|
|
*
|
2007-04-10 23:13:21 +01:00
|
|
|
* Revision 1.74 2007/03/22 11:12:21 vsc
|
|
|
|
* make sure that YAP_Restart does not restart a failed goal.
|
|
|
|
*
|
2007-03-22 11:12:22 +00:00
|
|
|
* 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
|
|
|
|
*
|
2007-02-18 00:26:36 +00:00
|
|
|
* Revision 1.72 2007/01/08 08:27:19 vsc
|
|
|
|
* fix restore (Trevor)
|
|
|
|
* make indexing a bit faster on IDB
|
|
|
|
*
|
2007-01-08 08:27:19 +00:00
|
|
|
* Revision 1.71 2006/11/27 17:42:03 vsc
|
|
|
|
* support for UNICODE, and other bug fixes.
|
|
|
|
*
|
2006-11-27 17:42:03 +00:00
|
|
|
* Revision 1.70 2006/08/25 19:50:35 vsc
|
|
|
|
* global data structures
|
|
|
|
*
|
2006-08-25 20:50:35 +01:00
|
|
|
* Revision 1.69 2006/08/22 16:12:46 vsc
|
|
|
|
* global variables
|
|
|
|
*
|
2006-08-22 17:12:46 +01:00
|
|
|
* Revision 1.68 2006/08/02 18:18:30 vsc
|
|
|
|
* preliminary support for readutil library (SWI compatible).
|
|
|
|
*
|
2006-08-02 19:18:31 +01:00
|
|
|
* Revision 1.67 2006/05/17 18:38:11 vsc
|
|
|
|
* make system library use true file name
|
|
|
|
*
|
2006-05-17 19:38:11 +01:00
|
|
|
* Revision 1.66 2006/04/28 15:48:33 vsc
|
|
|
|
* do locking on streams
|
|
|
|
*
|
2006-04-28 16:48:33 +01:00
|
|
|
* Revision 1.65 2006/04/28 13:23:23 vsc
|
|
|
|
* fix number of overflow bugs affecting threaded version
|
|
|
|
* make current_op faster.
|
|
|
|
*
|
2006-04-28 14:23:23 +01:00
|
|
|
* Revision 1.64 2006/03/22 20:07:28 vsc
|
|
|
|
* take better care of zombies
|
|
|
|
*
|
2006-03-22 20:07:28 +00:00
|
|
|
* Revision 1.63 2006/03/06 14:04:56 vsc
|
|
|
|
* fixes to garbage collector
|
|
|
|
* fixes to debugger
|
|
|
|
*
|
2006-03-06 14:04:57 +00:00
|
|
|
* Revision 1.62 2006/02/24 14:03:42 vsc
|
|
|
|
* fix refs to old LogUpd implementation (pre 5).
|
|
|
|
*
|
2006-02-24 14:03:42 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2006-01-02 02:16:19 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2005-12-17 03:25:39 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2005-12-05 17:16:12 +00:00
|
|
|
* Revision 1.58 2005/11/23 03:01:33 vsc
|
|
|
|
* fix several bugs in save/restore.b
|
|
|
|
*
|
2005-11-23 03:01:33 +00:00
|
|
|
* Revision 1.57 2005/10/28 17:38:50 vsc
|
|
|
|
* sveral updates
|
|
|
|
*
|
2005-10-28 18:38:50 +01:00
|
|
|
* Revision 1.56 2005/10/21 16:09:03 vsc
|
|
|
|
* SWI compatible module only operators
|
|
|
|
*
|
2005-10-21 17:09:03 +01:00
|
|
|
* Revision 1.55 2005/10/19 19:00:48 vsc
|
|
|
|
* extend arrays with nb_terms so that we can implement nb_ builtins
|
|
|
|
* correctly.
|
|
|
|
*
|
2005-10-19 20:00:48 +01:00
|
|
|
* Revision 1.54 2005/09/09 17:24:39 vsc
|
|
|
|
* a new and hopefully much better implementation of atts.
|
|
|
|
*
|
2005-09-09 18:24:39 +01:00
|
|
|
* Revision 1.53 2005/08/01 15:40:38 ricroc
|
|
|
|
* TABLING NEW: better support for incomplete tabling
|
|
|
|
*
|
2005-08-01 16:40:39 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2005-07-06 20:34:12 +01:00
|
|
|
* Revision 1.51 2005/07/06 15:10:15 vsc
|
|
|
|
* improvements to compiler: merged instructions and fixes for ->
|
|
|
|
*
|
2005-07-06 16:10:18 +01:00
|
|
|
* Revision 1.50 2005/06/01 13:53:46 vsc
|
|
|
|
* improve bb routines to use the DB efficiently
|
|
|
|
* change interface between DB and BB.
|
|
|
|
*
|
2005-06-01 14:53:46 +01:00
|
|
|
* Revision 1.49 2005/05/30 03:26:37 vsc
|
|
|
|
* add some atom gc fixes
|
|
|
|
*
|
2005-05-30 04:26:37 +01:00
|
|
|
* Revision 1.48 2005/01/04 02:50:21 vsc
|
|
|
|
* - allow MegaClauses with blobs
|
|
|
|
* - change Diffs to be thread specific
|
|
|
|
* - include Christian's updates
|
|
|
|
*
|
2005-01-04 02:50:23 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2004-12-02 06:06:47 +00:00
|
|
|
* Revision 1.46 2004/11/23 21:16:21 vsc
|
|
|
|
* A few extra fixes for saved states.
|
|
|
|
*
|
2004-11-23 21:16:21 +00:00
|
|
|
* Revision 1.45 2004/10/26 20:16:18 vsc
|
|
|
|
* More bug fixes for overflow handling
|
|
|
|
*
|
2004-10-26 21:16:18 +01:00
|
|
|
* 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
|
|
|
|
*
|
2004-10-06 17:55:48 +01:00
|
|
|
* 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
|
|
|
|
*
|
2004-09-27 21:45:04 +01:00
|
|
|
* Revision 1.42 2004/06/05 03:37:00 vsc
|
|
|
|
* coroutining is now a part of attvars.
|
|
|
|
* some more fixes.
|
|
|
|
*
|
2004-06-05 04:37:01 +01:00
|
|
|
* Revision 1.41 2004/04/29 03:45:50 vsc
|
|
|
|
* fix garbage collection in execute_tail
|
|
|
|
*
|
2004-04-29 04:45:50 +01:00
|
|
|
* Revision 1.40 2004/03/31 01:03:10 vsc
|
|
|
|
* support expand group of clauses
|
|
|
|
*
|
2004-03-31 02:03:10 +01:00
|
|
|
* 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.
|
|
|
|
* *
|
2004-03-19 11:35:42 +00:00
|
|
|
* *
|
2002-06-04 19:21:55 +01:00
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "@(#)rheap.c 1.3 3/15/90";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define Atomics 0
|
|
|
|
#define Funcs 1
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
#define ConstantTermAdjust(P) ConstantTermAdjust__(P PASS_REGS)
|
|
|
|
#define DBGroundTermAdjust(P) DBGroundTermAdjust__(P PASS_REGS)
|
2012-06-12 14:50:36 +01:00
|
|
|
#define AdjustDBTerm(P,A,B,C) AdjustDBTerm__(P,A,B,C PASS_REGS)
|
2011-03-07 16:02:55 +00:00
|
|
|
#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 )
|
2011-03-07 16:34:20 +00:00
|
|
|
#define RestoreAtoms() RestoreAtoms__( PASS_REGS1 )
|
|
|
|
#define RestoreWideAtoms() RestoreWideAtoms__( PASS_REGS1 )
|
2011-03-08 00:03:50 +00:00
|
|
|
#define RestoreSWIBlobs() RestoreSWIBlobs__( PASS_REGS1 )
|
|
|
|
#define RestoreSWIBlobTypes() RestoreSWIBlobTypes__( PASS_REGS1 )
|
2011-03-07 16:34:20 +00:00
|
|
|
#define RestoreInvisibleAtoms() RestoreInvisibleAtoms__( PASS_REGS1 )
|
|
|
|
#define RestorePredHash() RestorePredHash__( PASS_REGS1 )
|
2012-10-20 10:48:42 +01:00
|
|
|
#define RestoreHiddenPredicates() RestoreHiddenPredicates__( PASS_REGS1 )
|
2011-03-07 16:34:20 +00:00
|
|
|
#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 )
|
|
|
|
#define RestoreSWIAtoms() RestoreSWIAtoms__( PASS_REGS1 )
|
2008-08-29 17:27:11 +01:00
|
|
|
static Term
|
2011-03-07 16:02:55 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Term
|
2011-03-07 16:02:55 +00:00
|
|
|
DBGroundTermAdjust__ (Term t USES_REGS)
|
2010-12-16 20:39:53 +00:00
|
|
|
{
|
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 */
|
|
|
|
|
2004-09-27 21:45:04 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
do_clean_susp_clauses(yamop *ipc USES_REGS) {
|
2004-09-27 21:45:04 +01:00
|
|
|
COUNT i;
|
2008-08-21 13:38:25 +01:00
|
|
|
yamop **st = (yamop **)NEXTOP(ipc,sssllp);
|
2004-09-27 21:45:04 +01:00
|
|
|
|
|
|
|
ipc->opc = Yap_opcode(_expand_clauses);
|
2008-08-21 13:38:25 +01:00
|
|
|
ipc->u.sssllp.p = PtoPredAdjust(ipc->u.sssllp.p);
|
|
|
|
if (ipc->u.sssllp.sprev) {
|
|
|
|
ipc->u.sssllp.sprev = PtoOpAdjust(ipc->u.sssllp.sprev);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2008-08-21 13:38:25 +01:00
|
|
|
if (ipc->u.sssllp.snext) {
|
|
|
|
ipc->u.sssllp.snext = PtoOpAdjust(ipc->u.sssllp.snext);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2008-08-21 13:38:25 +01:00
|
|
|
for (i = 0; i < ipc->u.sssllp.s1; i++, st++) {
|
2004-09-27 21:45:04 +01:00
|
|
|
if (*st) {
|
|
|
|
*st = PtoOpAdjust(*st);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-29 17:27:11 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
oldcode[1] = (CELL)CodeAddrAdjust(oldjmp);
|
|
|
|
oldcode += 2;
|
|
|
|
}
|
2011-03-07 16:02:55 +00:00
|
|
|
rehash(startcode, i, Funcs PASS_REGS);
|
2008-08-29 17:27:11 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case _switch_on_cons:
|
|
|
|
{
|
|
|
|
COUNT j;
|
|
|
|
CELL *oldcode;
|
|
|
|
|
|
|
|
#if !defined(USE_OFFSETS)
|
|
|
|
oldcode = startcode;
|
|
|
|
#endif
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
Term oldcons = oldcode[0];
|
|
|
|
CODEADDR oldjmp = (CODEADDR)(oldcode[1]);
|
|
|
|
if (oldcons != 0x0 && IsAtomTerm(oldcons)) {
|
|
|
|
oldcode[0] = AtomTermAdjust(oldcons);
|
|
|
|
}
|
|
|
|
oldcode[1] = (CELL)CodeAddrAdjust(oldjmp);
|
|
|
|
oldcode += 2;
|
|
|
|
}
|
|
|
|
#if !USE_OFFSETS
|
2011-03-07 16:02:55 +00:00
|
|
|
rehash(startcode, i, Atomics PASS_REGS);
|
2008-08-29 17:27:11 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
startcode[1] = (CELL)CodeAddrAdjust((CODEADDR)startcode[1]);
|
|
|
|
startcode[3] = (CELL)CodeAddrAdjust((CODEADDR)startcode[3]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case _if_func:
|
|
|
|
{
|
|
|
|
Int j;
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
Functor oldfunc = (Functor)(startcode[0]);
|
|
|
|
CODEADDR oldjmp = (CODEADDR)(startcode[1]);
|
|
|
|
startcode[0] = (CELL)FuncAdjust(oldfunc);
|
|
|
|
startcode[1] = (CELL)CodeAddrAdjust(oldjmp);
|
|
|
|
startcode += 2;
|
|
|
|
}
|
|
|
|
/* adjust fail code */
|
|
|
|
startcode[1] = (CELL)CodeAddrAdjust((CODEADDR)startcode[1]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case _if_cons:
|
|
|
|
{
|
|
|
|
Int j;
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
Term oldcons = startcode[0];
|
|
|
|
CODEADDR oldjmp = (CODEADDR)(startcode[1]);
|
|
|
|
if (IsAtomTerm(oldcons)) {
|
|
|
|
startcode[0] = (CELL)AtomTermAdjust(oldcons);
|
|
|
|
}
|
|
|
|
startcode[1] = (CELL)CodeAddrAdjust(oldjmp);
|
|
|
|
startcode += 2;
|
|
|
|
}
|
|
|
|
/* adjust fail code */
|
|
|
|
startcode[1] = (CELL)CodeAddrAdjust((CODEADDR)startcode[1]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Yap_Error(INTERNAL_ERROR,0L,"Opcode Not Implemented in AdjustSwitchTable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
STATIC_PROTO(void RestoreAtomList, (Atom CACHE_TYPE));
|
|
|
|
STATIC_PROTO(void RestoreAtom, (AtomEntry * CACHE_TYPE));
|
|
|
|
STATIC_PROTO(void RestoreHashPreds, ( CACHE_TYPE1 ));
|
2009-10-30 23:59:00 +00:00
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreAtoms__( USES_REGS1 )
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
|
|
|
AtomHashEntry *HashPtr;
|
|
|
|
register int i;
|
|
|
|
|
2009-11-18 23:32:31 +00:00
|
|
|
Yap_heap_regs->hash_chain =
|
|
|
|
PtoAtomHashEntryAdjust(Yap_heap_regs->hash_chain);
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreWideAtoms__( USES_REGS1 )
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
|
|
|
AtomHashEntry *HashPtr;
|
|
|
|
register int i;
|
|
|
|
|
2009-11-18 23:32:31 +00:00
|
|
|
Yap_heap_regs->wide_hash_chain =
|
|
|
|
PtoAtomHashEntryAdjust(Yap_heap_regs->wide_hash_chain);
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
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 */
|
|
|
|
static Term
|
2012-06-12 14:50:36 +01:00
|
|
|
AdjustDBTerm__(Term trm, Term *p_base, Term *p_lim, Term *p_max USES_REGS)
|
2006-03-22 20:07:28 +00:00
|
|
|
{
|
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)) {
|
|
|
|
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])) {
|
|
|
|
/* avoid term recursion with very deep lists */
|
|
|
|
Term *newp = PtoHeapCellAdjust(RepPair(p[1]));
|
|
|
|
p[1] = AbsPair(newp);
|
|
|
|
p_base = p;
|
|
|
|
p = newp;
|
|
|
|
goto loop;
|
|
|
|
} else {
|
2012-06-12 14:50:36 +01: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)) {
|
|
|
|
Term *p;
|
|
|
|
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) {
|
|
|
|
if (DBRefOfTerm(trm)!=DBRefAdjust(DBRefOfTerm(trm),FALSE))
|
|
|
|
/* external term pointer, has to be a DBRef */
|
|
|
|
return MkDBRefTerm(DBRefAdjust(DBRefOfTerm(trm),FALSE));
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
f = (Functor)p[0];
|
|
|
|
if (!IsExtensionFunctor(f)) {
|
|
|
|
UInt Arity, i;
|
|
|
|
|
|
|
|
f = FuncAdjust(f);
|
|
|
|
*p++ = (Term)f;
|
|
|
|
Arity = ArityOfFunctor(f);
|
|
|
|
for (i = 0; i < Arity; ++i) {
|
2012-06-12 14:50:36 +01:00
|
|
|
*p = AdjustDBTerm(*p, p0, p_lim, p_max);
|
2006-03-22 20:07:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBTerm(DBTerm *dbr, int attachments USES_REGS)
|
2006-03-22 20:07:28 +00:00
|
|
|
{
|
2007-11-06 17:02:13 +00:00
|
|
|
if (attachments) {
|
2006-03-22 20:07:28 +00:00
|
|
|
#ifdef COROUTINING
|
2007-11-06 17:02:13 +00:00
|
|
|
if (dbr->ag.attachments)
|
2012-06-12 14:50:36 +01:00
|
|
|
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);
|
2007-11-06 17:02:13 +00:00
|
|
|
}
|
2012-06-12 14:50:36 +01:00
|
|
|
if (dbr->DBRefs) {
|
2006-03-22 20:07:28 +00:00
|
|
|
DBRef *cp;
|
|
|
|
DBRef tm;
|
|
|
|
|
|
|
|
dbr->DBRefs = DBRefPAdjust(dbr->DBRefs);
|
|
|
|
cp = dbr->DBRefs;
|
2012-06-12 14:50:36 +01:00
|
|
|
while ((tm = *--cp) != 0) {
|
|
|
|
*cp = DBRefAdjust(tm,TRUE);
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
2012-06-12 14:50:36 +01: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 */
|
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
/* Restores a prolog clause, in its compiled form */
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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
|
|
|
|
* clause for this predicate or not
|
|
|
|
*/
|
|
|
|
{
|
2011-08-25 03:19:12 +01:00
|
|
|
if (cl->usc.ClSource) {
|
|
|
|
char *x = (char *)DBTermAdjust(cl->usc.ClSource);
|
|
|
|
char *base = (char *)cl;
|
|
|
|
|
2012-06-06 00:09:14 +01:00
|
|
|
if (x < base || x >= base+cl->ClSize) {
|
2011-08-25 03:19:12 +01:00
|
|
|
cl->usc.ClPred = PtoPredAdjust(cl->usc.ClPred);
|
|
|
|
} else {
|
|
|
|
cl->usc.ClSource = DBTermAdjust(cl->usc.ClSource);
|
|
|
|
RestoreDBTerm(cl->usc.ClSource, TRUE 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 */
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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
|
|
|
|
* clause for this predicate or not
|
|
|
|
*/
|
|
|
|
{
|
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));
|
|
|
|
}
|
2012-04-23 23:24:35 +01:00
|
|
|
max = (yamop *)((CODEADDR)cl+cl->ClSize);
|
2009-11-02 12:46:39 +00:00
|
|
|
|
2012-04-23 23:24:35 +01:00
|
|
|
for (ptr = cl->ClCode; ptr < max; ) {
|
|
|
|
nextptr = (yamop *)((char *)ptr + cl->ClItemSize);
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_opcodes(ptr, nextptr PASS_REGS);
|
2009-11-02 12:46:39 +00:00
|
|
|
ptr = nextptr;
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restores a prolog clause, in its compiled form */
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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
|
|
|
|
* clause for this predicate or not
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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
|
|
|
|
* clause for this predicate or not
|
|
|
|
*/
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
if (cl->ClSource) {
|
|
|
|
cl->ClSource = DBTermAdjust(cl->ClSource);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBTerm(cl->ClSource, TRUE 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
|
|
|
}
|
|
|
|
|
2007-11-06 17:02:13 +00:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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) {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBTerm(dbt, FALSE PASS_REGS);
|
2007-11-06 17:02:13 +00:00
|
|
|
dbt = dbt->ag.NextDBT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-22 20:07:28 +00:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanLUIndex(LogUpdIndex *idx, int recurse USES_REGS)
|
2006-03-22 20:07:28 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanSIndex(StaticIndex *idx, int recurse USES_REGS)
|
2006-03-22 20:07:28 +00:00
|
|
|
{
|
2010-10-07 18:14:55 +01:00
|
|
|
beginning:
|
|
|
|
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) {
|
|
|
|
idx = idx->SiblingIndex;
|
|
|
|
goto beginning;
|
|
|
|
}
|
2006-03-22 20:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-03 14:26:56 +01:00
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreSWIAtoms__( USES_REGS1 )
|
2010-05-03 14:26:56 +01:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for (i=0; i < N_SWI_ATOMS; i++) {
|
|
|
|
SWI_Atoms[i] = AtomAdjust(SWI_Atoms[i]);
|
|
|
|
}
|
|
|
|
for (j=0; j < N_SWI_FUNCTORS; j++) {
|
|
|
|
SWI_Functors[j] = FuncAdjust(SWI_Functors[j]);
|
|
|
|
}
|
|
|
|
RestoreSWIHash();
|
|
|
|
}
|
|
|
|
|
2011-02-12 14:14:12 +00:00
|
|
|
static void
|
2011-03-08 00:03:50 +00:00
|
|
|
RestoreSWIBlobTypes__( USES_REGS1 )
|
2011-02-12 14:14:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-29 23:17:06 +00:00
|
|
|
static void
|
2011-03-08 00:03:50 +00:00
|
|
|
RestoreSWIBlobs__( USES_REGS1 )
|
2010-11-29 23:17:06 +00:00
|
|
|
{
|
2011-03-08 00:03:50 +00:00
|
|
|
SWI_Blobs = AtomAdjust(SWI_Blobs);
|
|
|
|
RestoreAtomList(SWI_Blobs PASS_REGS);
|
2010-11-29 23:17:06 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 18:10:48 +01:00
|
|
|
static void
|
2012-10-20 10:48:42 +01:00
|
|
|
RestoreHiddenPredicates__( USES_REGS1 )
|
2012-10-19 18:10:48 +01:00
|
|
|
{
|
|
|
|
HIDDEN_PREDICATES = PropAdjust(HIDDEN_PREDICATES);
|
|
|
|
RestoreEntries(HIDDEN_PREDICATES, TRUE PASS_REGS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-28 13:11:35 +00:00
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestorePredHash__( USES_REGS1 )
|
2002-06-04 19:21:55 +01:00
|
|
|
{
|
2009-10-28 13:11:35 +00:00
|
|
|
PredHash = PtoPtoPredAdjust(PredHash);
|
|
|
|
if (PredHash == NULL) {
|
|
|
|
Yap_Error(FATAL_ERROR,MkIntTerm(0),"restore should find predicate hash table");
|
|
|
|
}
|
|
|
|
REINIT_RWLOCK(PredHashRWLock);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreHashPreds( PASS_REGS1 ); /* does most of the work */
|
2009-10-28 13:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RestoreEnvInst(yamop start[2], yamop **instp, op_numbers opc, PredEntry *pred)
|
|
|
|
{
|
|
|
|
yamop *ipc = start;
|
|
|
|
|
|
|
|
ipc->opc = Yap_opcode(_call);
|
|
|
|
ipc->u.Osbpp.p = pred;
|
|
|
|
ipc->u.Osbpp.p0 = pred;
|
|
|
|
ipc = NEXTOP(ipc, Osbpp);
|
|
|
|
ipc->opc = Yap_opcode(opc);
|
|
|
|
*instp = ipc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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);
|
|
|
|
ipc->u.Otapl.s = 0;
|
2009-10-30 23:59:00 +00:00
|
|
|
ipc->u.Otapl.p = pe;
|
2009-10-28 13:11:35 +00:00
|
|
|
if (ipc->u.Otapl.d)
|
|
|
|
ipc->u.Otapl.d = PtoOpAdjust(ipc->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
|
2009-10-28 13:11:35 +00:00
|
|
|
ipc->u.Otapl.te = NULL;
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif /* TABLING */
|
2009-10-28 13:11:35 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 15:20:46 +00:00
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreDBTermsList__( USES_REGS1 )
|
2009-10-28 15:20:46 +00:00
|
|
|
{
|
|
|
|
if (Yap_heap_regs->dbterms_list) {
|
|
|
|
struct dbterm_list *dbl = PtoDBTLAdjust(Yap_heap_regs->dbterms_list);
|
|
|
|
Yap_heap_regs->dbterms_list = dbl;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreExpandList__( USES_REGS1 )
|
2009-10-28 13:11:35 +00:00
|
|
|
{
|
2004-12-02 06:06:47 +00:00
|
|
|
if (Yap_heap_regs->expand_clauses_first)
|
|
|
|
Yap_heap_regs->expand_clauses_first = PtoOpAdjust(Yap_heap_regs->expand_clauses_first);
|
|
|
|
if (Yap_heap_regs->expand_clauses_last)
|
|
|
|
Yap_heap_regs->expand_clauses_last = PtoOpAdjust(Yap_heap_regs->expand_clauses_last);
|
2004-09-27 21:45:04 +01:00
|
|
|
{
|
2004-12-02 06:06:47 +00:00
|
|
|
yamop *ptr = Yap_heap_regs->expand_clauses_first;
|
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);
|
2008-08-21 13:38:25 +01:00
|
|
|
ptr = ptr->u.sssllp.snext;
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
2009-10-28 15:20:46 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 15:53:23 +00:00
|
|
|
static void
|
|
|
|
RestoreUdiControlBlocks(void)
|
|
|
|
{
|
|
|
|
if (Yap_heap_regs->udi_control_blocks) {
|
|
|
|
Yap_Error(SYSTEM_ERROR, TermNil,
|
|
|
|
"YAP cannot restore UDI entries!!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreIntKeys__( USES_REGS1 )
|
2009-10-28 15:53:23 +00:00
|
|
|
{
|
|
|
|
if (Yap_heap_regs->IntKeys != NULL) {
|
|
|
|
Yap_heap_regs->IntKeys = (Prop *)AddrAdjust((ADDR)(Yap_heap_regs->IntKeys));
|
|
|
|
{
|
|
|
|
UInt i;
|
|
|
|
for (i = 0; i < Yap_heap_regs->int_keys_size; i++) {
|
|
|
|
if (Yap_heap_regs->IntKeys[i] != NIL) {
|
|
|
|
Prop p0 = Yap_heap_regs->IntKeys[i] = PropAdjust(Yap_heap_regs->IntKeys[i]);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreEntries(RepProp(p0), TRUE PASS_REGS);
|
2009-10-28 15:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreIntLUKeys__( USES_REGS1 )
|
2009-10-28 15:53:23 +00:00
|
|
|
{
|
|
|
|
if (Yap_heap_regs->IntLUKeys != NULL) {
|
|
|
|
Yap_heap_regs->IntLUKeys = (Prop *)AddrAdjust((ADDR)(Yap_heap_regs->IntLUKeys));
|
|
|
|
{
|
|
|
|
Int i;
|
|
|
|
for (i = 0; i < INT_KEYS_SIZE; i++) {
|
|
|
|
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);
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanCode(pe PASS_REGS);
|
2009-10-28 15:53:23 +00:00
|
|
|
p0 = RepProp(pe->NextOfPE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreIntBBKeys__( USES_REGS1 )
|
2009-10-28 15:53:23 +00:00
|
|
|
{
|
|
|
|
if (Yap_heap_regs->IntBBKeys != NULL) {
|
|
|
|
Yap_heap_regs->IntBBKeys = (Prop *)AddrAdjust((ADDR)(Yap_heap_regs->IntBBKeys));
|
|
|
|
{
|
|
|
|
UInt i;
|
|
|
|
for (i = 0; i < Yap_heap_regs->int_bb_keys_size; i++) {
|
|
|
|
if (Yap_heap_regs->IntBBKeys[i] != NIL) {
|
|
|
|
Prop p0 = Yap_heap_regs->IntBBKeys[i] = PropAdjust(Yap_heap_regs->IntBBKeys[i]);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreEntries(RepProp(p0), TRUE PASS_REGS);
|
2009-10-28 15:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBErasedMarker__( USES_REGS1 )
|
2009-10-28 15:53:23 +00:00
|
|
|
{
|
|
|
|
Yap_heap_regs->db_erased_marker =
|
2012-06-12 14:50:36 +01:00
|
|
|
DBRefAdjust(Yap_heap_regs->db_erased_marker,TRUE);
|
2009-10-28 15:53:23 +00:00
|
|
|
Yap_heap_regs->db_erased_marker->id = FunctorDBRef;
|
|
|
|
Yap_heap_regs->db_erased_marker->Flags = ErasedMask;
|
|
|
|
Yap_heap_regs->db_erased_marker->Code = NULL;
|
|
|
|
Yap_heap_regs->db_erased_marker->DBT.DBRefs = NULL;
|
|
|
|
Yap_heap_regs->db_erased_marker->Parent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreLogDBErasedMarker__( USES_REGS1 )
|
2009-10-28 15:53:23 +00:00
|
|
|
{
|
|
|
|
Yap_heap_regs->logdb_erased_marker =
|
|
|
|
PtoLUCAdjust(Yap_heap_regs->logdb_erased_marker);
|
|
|
|
Yap_heap_regs->logdb_erased_marker->Id = FunctorDBRef;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClFlags = ErasedMask|LogUpdMask;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClSource = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClRefCount = 0;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClPred = PredLogUpdClause;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClExt = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClPrev = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClNext = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClSize = (UInt)NEXTOP(((LogUpdClause *)NULL)->ClCode,e);
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClCode->opc = Yap_opcode(_op_fail);
|
|
|
|
INIT_CLREF_COUNT(Yap_heap_regs->logdb_erased_marker);
|
|
|
|
}
|
|
|
|
|
2009-10-28 15:20:46 +00:00
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreDeadStaticClauses__( USES_REGS1 )
|
2009-10-28 15:20:46 +00:00
|
|
|
{
|
2006-03-22 20:07:28 +00:00
|
|
|
if (Yap_heap_regs->dead_static_clauses) {
|
|
|
|
StaticClause *sc = PtoStCAdjust(Yap_heap_regs->dead_static_clauses);
|
|
|
|
Yap_heap_regs->dead_static_clauses = sc;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreDeadMegaClauses__( USES_REGS1 )
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
2006-03-22 20:07:28 +00:00
|
|
|
if (Yap_heap_regs->dead_mega_clauses) {
|
|
|
|
MegaClause *mc = (MegaClause *)AddrAdjust((ADDR)(Yap_heap_regs->dead_mega_clauses));
|
|
|
|
Yap_heap_regs->dead_mega_clauses = mc;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreDeadStaticIndices__( USES_REGS1 )
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
2006-03-22 20:07:28 +00:00
|
|
|
if (Yap_heap_regs->dead_static_indices) {
|
|
|
|
StaticIndex *si = (StaticIndex *)AddrAdjust((ADDR)(Yap_heap_regs->dead_static_indices));
|
|
|
|
Yap_heap_regs->dead_static_indices = si;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreDBErasedList__( USES_REGS1 )
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
2008-05-12 15:04:23 +01:00
|
|
|
if (Yap_heap_regs->db_erased_list) {
|
|
|
|
LogUpdClause *lcl = Yap_heap_regs->db_erased_list =
|
|
|
|
PtoLUCAdjust(Yap_heap_regs->db_erased_list);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
RestoreDBErasedIList__( USES_REGS1 )
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
2008-05-12 15:04:23 +01:00
|
|
|
if (Yap_heap_regs->db_erased_ilist) {
|
|
|
|
LogUpdIndex *icl = Yap_heap_regs->db_erased_ilist =
|
|
|
|
LUIndexAdjust(Yap_heap_regs->db_erased_ilist);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RestoreStreams(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RestoreAliases(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreForeignCode__( USES_REGS1 )
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
|
|
|
ForeignObj *f_code;
|
|
|
|
|
|
|
|
if (!ForeignCodeLoaded)
|
|
|
|
return;
|
|
|
|
if (ForeignCodeLoaded != NULL)
|
|
|
|
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)
|
|
|
|
objs->next = (StringList)AddrAdjust((ADDR)objs->next);
|
2010-12-12 18:28:55 +00:00
|
|
|
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)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-01-03 03:16:29 +00:00
|
|
|
static void
|
2011-03-07 16:34:20 +00:00
|
|
|
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);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBTerm(ptr->dbrecord, FALSE PASS_REGS);
|
2011-01-03 03:16:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-21 22:12:42 +00:00
|
|
|
static void
|
|
|
|
RestoreBallTerm(int wid)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_BallTerm) {
|
|
|
|
LOCAL_BallTerm = DBTermAdjust(LOCAL_BallTerm);
|
|
|
|
RestoreDBTerm(LOCAL_BallTerm, TRUE PASS_REGS);
|
2010-03-21 22:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "rglobals.h"
|
2011-03-23 16:45:47 +00:00
|
|
|
#include "rlocals.h"
|
2010-03-21 22:12:42 +00:00
|
|
|
|
2009-10-30 23:59:00 +00:00
|
|
|
/* restore the failcodes */
|
|
|
|
static void
|
|
|
|
restore_codes(void)
|
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2011-05-04 10:11:41 +01:00
|
|
|
Yap_heap_regs->heap_top = AddrAdjust(LOCAL_OldHeapTop);
|
2009-11-18 23:32:31 +00:00
|
|
|
#include "rhstruct.h"
|
2010-03-21 22:12:42 +00:00
|
|
|
RestoreGlobal();
|
|
|
|
#ifndef worker_id
|
|
|
|
#define worker_id 0
|
2002-06-04 19:21:55 +01:00
|
|
|
#endif
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreWorker(worker_id PASS_REGS);
|
2009-11-18 23:32:31 +00:00
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBTerm(&(dbr->DBT), TRUE 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)
|
2012-06-12 14:50:36 +01:00
|
|
|
dbr->Prev = DBRefAdjust(dbr->Prev,TRUE);
|
2002-06-04 19:21:55 +01:00
|
|
|
if (dbr->Next != NULL)
|
2012-06-12 14:50:36 +01: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 */
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDB(DBEntry *pp USES_REGS)
|
2002-06-04 19:21:55 +01:00
|
|
|
{
|
|
|
|
register DBRef dbr;
|
|
|
|
|
|
|
|
if (pp->First != NULL)
|
2012-06-12 14:50:36 +01: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
|
|
|
|
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
|
|
|
|
* and ending with Last, First may be equal to Last
|
|
|
|
*/
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanClauses(yamop *First, yamop *Last, PredEntry *pp USES_REGS)
|
2002-06-04 19:21:55 +01:00
|
|
|
{
|
2011-08-28 01:23:14 +01:00
|
|
|
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);
|
2003-11-26 18:36:35 +00:00
|
|
|
if (cl == Last) return;
|
|
|
|
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);
|
2004-02-06 02:26:23 +00:00
|
|
|
if (cl->ClCode == Last) return;
|
|
|
|
cl = cl->ClNext;
|
2003-08-27 14:37:10 +01:00
|
|
|
} while (TRUE);
|
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-06 02:26:23 +00:00
|
|
|
|
2005-06-01 14:53:46 +01:00
|
|
|
/* Restores a DB structure, as it was saved in the heap */
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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)) {
|
|
|
|
if (IsAtomTerm(t)) {
|
|
|
|
pp->Element = AtomTermAdjust(t);
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-07 16:02:55 +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
|
|
|
}
|
|
|
|
|
2002-06-04 19:21:55 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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:
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2005-10-19 20:00:48 +01:00
|
|
|
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);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBTerm(db, TRUE PASS_REGS);
|
2005-10-19 20:00:48 +01:00
|
|
|
base->tstore = AbsAppl((CELL *)db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-04 19:21:55 +01:00
|
|
|
case array_of_terms:
|
|
|
|
{
|
2003-08-27 14:37:10 +01:00
|
|
|
DBTerm **base = (DBTerm **)AddrAdjust((ADDR)(ae->ValueOfVE.terms));
|
2002-06-04 19:21:55 +01:00
|
|
|
Int i;
|
|
|
|
|
|
|
|
ae->ValueOfVE.terms = base;
|
|
|
|
if (ae != 0L) {
|
|
|
|
for (i=0; i<sz; i++) {
|
2003-08-27 14:37:10 +01:00
|
|
|
DBTerm *reg = *base;
|
2002-06-04 19:21:55 +01:00
|
|
|
if (reg == NULL) {
|
|
|
|
base++;
|
|
|
|
} else {
|
2004-02-06 02:26:23 +00:00
|
|
|
*base++ = reg = DBTermAdjust(reg);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDBTerm(reg, TRUE PASS_REGS);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean all the code for a particular predicate, this can get a bit tricky,
|
|
|
|
* because of the indexing code
|
|
|
|
*/
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanCode(PredEntry *pp USES_REGS)
|
2002-06-04 19:21:55 +01:00
|
|
|
{
|
|
|
|
CELL flag;
|
|
|
|
|
|
|
|
|
|
|
|
/* 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) {
|
|
|
|
/* it's an integer, do nothing */
|
|
|
|
} else if (pp->PredFlags & AtomDBPredFlag) {
|
2005-05-30 04:26:37 +01:00
|
|
|
pp->FunctorOfPred = (Functor)AtomAdjust((Atom)(pp->FunctorOfPred));
|
|
|
|
} else {
|
|
|
|
pp->FunctorOfPred = FuncAdjust(pp->FunctorOfPred);
|
|
|
|
}
|
|
|
|
} 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);
|
|
|
|
}
|
2002-12-27 16:53: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 {
|
2002-12-27 16:53:09 +00:00
|
|
|
yamop *FirstC, *LastC;
|
|
|
|
/* 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);
|
|
|
|
pp->CodeOfPred =PtoOpAdjust(pp->CodeOfPred);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_RESTORE2
|
2004-02-06 02:26:23 +00:00
|
|
|
fprintf(stderr, "at %ux 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) {
|
|
|
|
#ifdef DEBUG_RESTORE2
|
|
|
|
fprintf(stderr, "Correcting indexed code\n");
|
|
|
|
#endif
|
|
|
|
if (flag & LogUpdatePredFlag) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanLUIndex(ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred), TRUE PASS_REGS);
|
2004-02-06 02:26:23 +00:00
|
|
|
} else {
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanSIndex(ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred), TRUE PASS_REGS);
|
2004-02-06 02:26:23 +00:00
|
|
|
}
|
|
|
|
} else if (flag & DynamicPredFlag) {
|
2002-06-04 19:21:55 +01: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
|
2011-03-07 16:02:55 +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
|
|
|
|
* if we find code or data bases
|
|
|
|
*/
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreEntries(PropEntry *pp, int int_key USES_REGS)
|
2002-06-04 19:21:55 +01:00
|
|
|
{
|
|
|
|
while (!EndOfPAEntr(pp)) {
|
|
|
|
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);
|
2010-04-09 11:55:36 +01:00
|
|
|
if (!EndOfPAEntr(p0)) {
|
2007-09-29 00:18:17 +01:00
|
|
|
/* at most one property */
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanCode(RepPredProp(p0) PASS_REGS);
|
2007-09-29 00:18:17 +01:00
|
|
|
RepPredProp(p0)->NextOfPE =
|
2002-06-04 19:21:55 +01:00
|
|
|
PropAdjust(RepPredProp(p0)->NextOfPE);
|
2010-04-08 00:52:00 +01:00
|
|
|
p0 = RepPredProp(p0)->NextOfPE;
|
2002-06-04 19:21:55 +01: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;
|
2009-03-13 21:57:15 +00:00
|
|
|
case HoldProperty:
|
|
|
|
{
|
|
|
|
HoldEntry *he = (HoldEntry *)pp;
|
|
|
|
he->NextOfPE =
|
|
|
|
PropAdjust(he->NextOfPE);
|
|
|
|
}
|
|
|
|
break;
|
2002-06-04 19:21:55 +01:00
|
|
|
case ArrayProperty:
|
|
|
|
{
|
|
|
|
ArrayEntry *ae = (ArrayEntry *)pp;
|
|
|
|
ae->NextOfPE =
|
|
|
|
PropAdjust(ae->NextOfPE);
|
|
|
|
if (ae->ArrayEArity < 0) {
|
2005-10-28 18:38:50 +01:00
|
|
|
/* static array entry */
|
|
|
|
StaticArrayEntry *sae = (StaticArrayEntry *)ae;
|
|
|
|
if (sae->NextAE)
|
|
|
|
sae->NextAE = PtoArraySAdjust(sae->NextAE);
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_static_array(sae PASS_REGS);
|
2002-06-04 19:21:55 +01:00
|
|
|
} else {
|
2005-10-28 18:38:50 +01:00
|
|
|
if (ae->NextAE)
|
|
|
|
ae->NextAE = PtoArrayEAdjust(ae->NextAE);
|
2002-06-04 19:21:55 +01:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PEProp:
|
|
|
|
{
|
|
|
|
PredEntry *pe = (PredEntry *) pp;
|
|
|
|
pe->NextOfPE =
|
|
|
|
PropAdjust(pe->NextOfPE);
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanCode(pe PASS_REGS);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
DBEntry *de = (DBEntry *) pp;
|
|
|
|
de->NextOfPE =
|
2007-02-18 00:26:36 +00:00
|
|
|
PropAdjust(de->NextOfPE);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreDB(de PASS_REGS);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BBProperty:
|
|
|
|
{
|
|
|
|
BlackBoardEntry *bb = (BlackBoardEntry *) pp;
|
|
|
|
bb->NextOfPE =
|
|
|
|
PropAdjust(bb->NextOfPE);
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreBB(bb, int_key PASS_REGS);
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
break;
|
2007-01-08 08:27:19 +00:00
|
|
|
case GlobalProperty:
|
|
|
|
{
|
|
|
|
GlobalEntry *gb = (GlobalEntry *) pp;
|
|
|
|
Term gbt = gb->global;
|
|
|
|
|
|
|
|
gb->NextOfPE =
|
|
|
|
PropAdjust(gb->NextOfPE);
|
|
|
|
gb->AtomOfGE =
|
|
|
|
AtomEntryAdjust(gb->AtomOfGE);
|
2008-04-01 10:41:05 +01:00
|
|
|
if (gb->NextGE) {
|
|
|
|
gb->NextGE =
|
|
|
|
GlobalEntryAdjust(gb->NextGE);
|
|
|
|
}
|
2007-01-08 08:27:19 +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;
|
2002-06-04 19:21:55 +01:00
|
|
|
case OpProperty:
|
2005-10-21 17:09:03 +01:00
|
|
|
{
|
|
|
|
OpEntry *opp = (OpEntry *)pp;
|
2009-11-23 16:02:05 +00:00
|
|
|
if (opp->NextOfPE) {
|
|
|
|
opp->NextOfPE =
|
|
|
|
PropAdjust(opp->NextOfPE);
|
|
|
|
}
|
2009-11-25 00:38:05 +00:00
|
|
|
opp->OpName =
|
|
|
|
AtomAdjust(opp->OpName);
|
2005-10-21 17:09:03 +01:00
|
|
|
if (opp->OpModule) {
|
|
|
|
opp->OpModule = AtomTermAdjust(opp->OpModule);
|
|
|
|
}
|
2010-03-01 17:52:42 +00:00
|
|
|
if (opp->OpNext) {
|
|
|
|
opp->OpNext = OpEntryAdjust(opp->OpNext);
|
|
|
|
}
|
2005-10-21 17:09:03 +01:00
|
|
|
}
|
2009-11-20 00:30:36 +00:00
|
|
|
break;
|
2002-06-04 19:21:55 +01:00
|
|
|
case ModProperty:
|
2007-04-10 23:13:21 +01:00
|
|
|
{
|
|
|
|
ModEntry *me = (ModEntry *)pp;
|
2008-04-06 12:53:02 +01:00
|
|
|
if (me->NextOfPE) {
|
|
|
|
me->NextOfPE =
|
|
|
|
PropAdjust(me->NextOfPE);
|
|
|
|
}
|
|
|
|
if (me->PredForME) {
|
|
|
|
me->PredForME =
|
2007-04-10 23:13:21 +01:00
|
|
|
PtoPredAdjust(me->PredForME);
|
2008-04-06 12:53:02 +01:00
|
|
|
}
|
2007-04-10 23:13:21 +01:00
|
|
|
me->AtomOfME =
|
|
|
|
AtomAdjust(me->AtomOfME);
|
2008-04-06 13:06:48 +01:00
|
|
|
if (me->NextME)
|
|
|
|
me->NextME = (struct mod_entry *)
|
|
|
|
AddrAdjust((ADDR)me->NextME);
|
2007-04-10 23:13:21 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ExpProperty:
|
2002-06-04 19:21:55 +01:00
|
|
|
pp->NextOfPE =
|
|
|
|
PropAdjust(pp->NextOfPE);
|
|
|
|
break;
|
2009-06-02 15:51:57 +01:00
|
|
|
case WideAtomProperty:
|
|
|
|
pp->NextOfPE =
|
|
|
|
PropAdjust(pp->NextOfPE);
|
|
|
|
break;
|
2011-03-08 00:22:32 +00:00
|
|
|
case BlobProperty:
|
|
|
|
pp->NextOfPE =
|
|
|
|
PropAdjust(pp->NextOfPE);
|
|
|
|
{
|
|
|
|
BlobPropEntry *bpe = (BlobPropEntry *)pp;
|
|
|
|
bpe->blob_t =
|
|
|
|
BlobTypeAdjust(bpe->blob_t);
|
|
|
|
}
|
|
|
|
break;
|
2002-06-04 19:21:55 +01:00
|
|
|
default:
|
|
|
|
/* OOPS */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR, TermNil,
|
2002-06-04 19:21:55 +01:00
|
|
|
"Invalid Atom Property %d at %p", pp->KindOfPE, pp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pp = RepProp(pp->NextOfPE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-12 23:31:37 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
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);
|
|
|
|
#if DEBUG_RESTORE2 /* useful during debug */
|
2008-05-12 23:31:37 +01:00
|
|
|
if (IsWideAtom(AbsAtom(at)))
|
|
|
|
fprintf(errout, "Restoring %S\n", at->WStrOfAE);
|
|
|
|
else
|
|
|
|
fprintf(errout, "Restoring %s\n", at->StrOfAE);
|
|
|
|
#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));
|
|
|
|
}
|
2008-08-29 17:27:11 +01:00
|
|
|
|