anaconda
This commit is contained in:
parent
4271f3debe
commit
d23f7c149f
2
C/qlyr.c
2
C/qlyr.c
@ -638,7 +638,7 @@ static bool checkChars(FILE *stream, char s[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Atom do_header(FILE *stream) {
|
static Atom do_header(FILE *stream) {
|
||||||
char s[256], *p = s, ch;
|
char s[2560], *p = s, ch;
|
||||||
Atom at;
|
Atom at;
|
||||||
|
|
||||||
if (!checkChars(stream, "#!/bin/sh\nexec_dir=${YAPBINDIR:-"))
|
if (!checkChars(stream, "#!/bin/sh\nexec_dir=${YAPBINDIR:-"))
|
||||||
|
277
C/qlyw.c
277
C/qlyw.c
@ -25,12 +25,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "absmi.h"
|
|
||||||
#include "Foreign.h"
|
#include "Foreign.h"
|
||||||
|
#include "absmi.h"
|
||||||
#include "alloc.h"
|
#include "alloc.h"
|
||||||
#include "yapio.h"
|
|
||||||
#include "iopreds.h"
|
|
||||||
#include "attvar.h"
|
#include "attvar.h"
|
||||||
|
#include "iopreds.h"
|
||||||
|
#include "yapio.h"
|
||||||
#if HAVE_STRING_H
|
#if HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
@ -40,15 +40,15 @@
|
|||||||
static void RestoreEntries(PropEntry *, int USES_REGS);
|
static void RestoreEntries(PropEntry *, int USES_REGS);
|
||||||
static void CleanCode(PredEntry *USES_REGS);
|
static void CleanCode(PredEntry *USES_REGS);
|
||||||
|
|
||||||
static void
|
static void GrowAtomTable(void) {
|
||||||
GrowAtomTable(void) {
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
UInt size = LOCAL_ExportAtomHashTableSize;
|
UInt size = LOCAL_ExportAtomHashTableSize;
|
||||||
export_atom_hash_entry_t *p, *newt, *oldt = LOCAL_ExportAtomHashChain;
|
export_atom_hash_entry_t *p, *newt, *oldt = LOCAL_ExportAtomHashChain;
|
||||||
UInt new_size = size + (size > 1024 ? size : 1024);
|
UInt new_size = size + (size > 1024 ? size : 1024);
|
||||||
UInt i;
|
UInt i;
|
||||||
|
|
||||||
newt = (export_atom_hash_entry_t *)calloc(new_size,sizeof(export_atom_hash_entry_t));
|
newt = (export_atom_hash_entry_t *)calloc(new_size,
|
||||||
|
sizeof(export_atom_hash_entry_t));
|
||||||
if (!newt) {
|
if (!newt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -59,8 +59,8 @@ GrowAtomTable(void) {
|
|||||||
CELL hash;
|
CELL hash;
|
||||||
const unsigned char *apt;
|
const unsigned char *apt;
|
||||||
|
|
||||||
|
if (!a)
|
||||||
if (!a) continue;
|
continue;
|
||||||
apt = RepAtom(a)->UStrOfAE;
|
apt = RepAtom(a)->UStrOfAE;
|
||||||
hash = HashFunction(apt) / (2 * sizeof(CELL)) % new_size;
|
hash = HashFunction(apt) / (2 * sizeof(CELL)) % new_size;
|
||||||
newp = newt + hash;
|
newp = newt + hash;
|
||||||
@ -76,9 +76,7 @@ GrowAtomTable(void) {
|
|||||||
free(oldt);
|
free(oldt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void LookupAtom(Atom at) {
|
||||||
LookupAtom(Atom at)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
const unsigned char *p = RepAtom(at)->UStrOfAE;
|
const unsigned char *p = RepAtom(at)->UStrOfAE;
|
||||||
CELL hash = HashFunction(p) % LOCAL_ExportAtomHashTableSize;
|
CELL hash = HashFunction(p) % LOCAL_ExportAtomHashTableSize;
|
||||||
@ -92,13 +90,10 @@ LookupAtom(Atom at)
|
|||||||
a++;
|
a++;
|
||||||
if (a == LOCAL_ExportAtomHashChain + LOCAL_ExportAtomHashTableSize)
|
if (a == LOCAL_ExportAtomHashChain + LOCAL_ExportAtomHashTableSize)
|
||||||
a = LOCAL_ExportAtomHashChain;
|
a = LOCAL_ExportAtomHashChain;
|
||||||
|
|
||||||
}
|
}
|
||||||
a->val = at;
|
a->val = at;
|
||||||
LOCAL_ExportAtomHashTableNum++;
|
LOCAL_ExportAtomHashTableNum++;
|
||||||
if (LOCAL_ExportAtomHashTableNum >
|
if (LOCAL_ExportAtomHashTableNum > LOCAL_ExportAtomHashTableSize / 2) {
|
||||||
LOCAL_ExportAtomHashTableSize/2
|
|
||||||
) {
|
|
||||||
GrowAtomTable();
|
GrowAtomTable();
|
||||||
if (!LOCAL_ExportAtomHashChain) {
|
if (!LOCAL_ExportAtomHashChain) {
|
||||||
return;
|
return;
|
||||||
@ -106,15 +101,15 @@ LookupAtom(Atom at)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void GrowFunctorTable(void) {
|
||||||
GrowFunctorTable(void) {
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
UInt size = LOCAL_ExportFunctorHashTableSize;
|
UInt size = LOCAL_ExportFunctorHashTableSize;
|
||||||
export_functor_hash_entry_t *p, *newt, *oldt = LOCAL_ExportFunctorHashChain;
|
export_functor_hash_entry_t *p, *newt, *oldt = LOCAL_ExportFunctorHashChain;
|
||||||
UInt new_size = size + (size > 1024 ? size : 1024);
|
UInt new_size = size + (size > 1024 ? size : 1024);
|
||||||
UInt i;
|
UInt i;
|
||||||
|
|
||||||
newt = (export_functor_hash_entry_t *)calloc(new_size,sizeof(export_functor_hash_entry_t));
|
newt = (export_functor_hash_entry_t *)calloc(
|
||||||
|
new_size, sizeof(export_functor_hash_entry_t));
|
||||||
if (!newt) {
|
if (!newt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -124,7 +119,8 @@ GrowFunctorTable(void) {
|
|||||||
export_functor_hash_entry_t *newp;
|
export_functor_hash_entry_t *newp;
|
||||||
CELL hash;
|
CELL hash;
|
||||||
|
|
||||||
if (!f) continue;
|
if (!f)
|
||||||
|
continue;
|
||||||
hash = ((CELL)(f)) / (2 * sizeof(CELL)) % new_size;
|
hash = ((CELL)(f)) / (2 * sizeof(CELL)) % new_size;
|
||||||
newp = newt + hash;
|
newp = newt + hash;
|
||||||
while (newp->val) {
|
while (newp->val) {
|
||||||
@ -141,11 +137,10 @@ GrowFunctorTable(void) {
|
|||||||
free(oldt);
|
free(oldt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void LookupFunctor(Functor fun) {
|
||||||
LookupFunctor(Functor fun)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
CELL hash = ((CELL)(fun))/(2*sizeof(CELL)) % LOCAL_ExportFunctorHashTableSize;
|
CELL hash =
|
||||||
|
((CELL)(fun)) / (2 * sizeof(CELL)) % LOCAL_ExportFunctorHashTableSize;
|
||||||
export_functor_hash_entry_t *f;
|
export_functor_hash_entry_t *f;
|
||||||
Atom name = NameOfFunctor(fun);
|
Atom name = NameOfFunctor(fun);
|
||||||
UInt arity = ArityOfFunctor(fun);
|
UInt arity = ArityOfFunctor(fun);
|
||||||
@ -164,9 +159,7 @@ LookupFunctor(Functor fun)
|
|||||||
f->name = name;
|
f->name = name;
|
||||||
f->arity = arity;
|
f->arity = arity;
|
||||||
LOCAL_ExportFunctorHashTableNum++;
|
LOCAL_ExportFunctorHashTableNum++;
|
||||||
if (LOCAL_ExportFunctorHashTableNum >
|
if (LOCAL_ExportFunctorHashTableNum > LOCAL_ExportFunctorHashTableSize / 2) {
|
||||||
LOCAL_ExportFunctorHashTableSize/2
|
|
||||||
) {
|
|
||||||
GrowFunctorTable();
|
GrowFunctorTable();
|
||||||
if (!LOCAL_ExportFunctorHashChain) {
|
if (!LOCAL_ExportFunctorHashChain) {
|
||||||
return;
|
return;
|
||||||
@ -174,15 +167,16 @@ LookupFunctor(Functor fun)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void GrowPredTable(void) {
|
||||||
GrowPredTable(void) {
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
UInt size = LOCAL_ExportPredEntryHashTableSize;
|
UInt size = LOCAL_ExportPredEntryHashTableSize;
|
||||||
export_pred_entry_hash_entry_t *p, *newt, *oldt = LOCAL_ExportPredEntryHashChain;
|
export_pred_entry_hash_entry_t *p, *newt,
|
||||||
|
*oldt = LOCAL_ExportPredEntryHashChain;
|
||||||
UInt new_size = size + (size > 1024 ? size : 1024);
|
UInt new_size = size + (size > 1024 ? size : 1024);
|
||||||
UInt i;
|
UInt i;
|
||||||
|
|
||||||
newt = (export_pred_entry_hash_entry_t *)calloc(new_size,sizeof(export_pred_entry_hash_entry_t));
|
newt = (export_pred_entry_hash_entry_t *)calloc(
|
||||||
|
new_size, sizeof(export_pred_entry_hash_entry_t));
|
||||||
if (!newt) {
|
if (!newt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -192,7 +186,8 @@ GrowPredTable(void) {
|
|||||||
export_pred_entry_hash_entry_t *newp;
|
export_pred_entry_hash_entry_t *newp;
|
||||||
CELL hash;
|
CELL hash;
|
||||||
|
|
||||||
if (!pe) continue;
|
if (!pe)
|
||||||
|
continue;
|
||||||
hash = ((CELL)(pe)) / (2 * sizeof(CELL)) % new_size;
|
hash = ((CELL)(pe)) / (2 * sizeof(CELL)) % new_size;
|
||||||
newp = newt + hash;
|
newp = newt + hash;
|
||||||
while (newp->val) {
|
while (newp->val) {
|
||||||
@ -210,11 +205,10 @@ GrowPredTable(void) {
|
|||||||
free(oldt);
|
free(oldt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void LookupPredEntry(PredEntry *pe) {
|
||||||
LookupPredEntry(PredEntry *pe)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
CELL hash = (((CELL)(pe))/(2*sizeof(CELL))) % LOCAL_ExportPredEntryHashTableSize;
|
CELL hash =
|
||||||
|
(((CELL)(pe)) / (2 * sizeof(CELL))) % LOCAL_ExportPredEntryHashTableSize;
|
||||||
export_pred_entry_hash_entry_t *p;
|
export_pred_entry_hash_entry_t *p;
|
||||||
UInt arity = pe->ArityOfPE;
|
UInt arity = pe->ArityOfPE;
|
||||||
|
|
||||||
@ -224,7 +218,8 @@ LookupPredEntry(PredEntry *pe)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
if (p == LOCAL_ExportPredEntryHashChain+LOCAL_ExportPredEntryHashTableSize)
|
if (p ==
|
||||||
|
LOCAL_ExportPredEntryHashChain + LOCAL_ExportPredEntryHashTableSize)
|
||||||
p = LOCAL_ExportPredEntryHashChain;
|
p = LOCAL_ExportPredEntryHashChain;
|
||||||
}
|
}
|
||||||
p->arity = arity;
|
p->arity = arity;
|
||||||
@ -258,8 +253,7 @@ LookupPredEntry(PredEntry *pe)
|
|||||||
LookupAtom(p->module);
|
LookupAtom(p->module);
|
||||||
LOCAL_ExportPredEntryHashTableNum++;
|
LOCAL_ExportPredEntryHashTableNum++;
|
||||||
if (LOCAL_ExportPredEntryHashTableNum >
|
if (LOCAL_ExportPredEntryHashTableNum >
|
||||||
LOCAL_ExportPredEntryHashTableSize/2
|
LOCAL_ExportPredEntryHashTableSize / 2) {
|
||||||
) {
|
|
||||||
GrowPredTable();
|
GrowPredTable();
|
||||||
if (!LOCAL_ExportPredEntryHashChain) {
|
if (!LOCAL_ExportPredEntryHashChain) {
|
||||||
return;
|
return;
|
||||||
@ -267,16 +261,15 @@ LookupPredEntry(PredEntry *pe)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void GrowDBRefTable(void) {
|
||||||
static void
|
|
||||||
GrowDBRefTable(void) {
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
UInt size = LOCAL_ExportDBRefHashTableSize;
|
UInt size = LOCAL_ExportDBRefHashTableSize;
|
||||||
export_dbref_hash_entry_t *p, *newt, *oldt = LOCAL_ExportDBRefHashChain;
|
export_dbref_hash_entry_t *p, *newt, *oldt = LOCAL_ExportDBRefHashChain;
|
||||||
UInt new_size = size + (size > 1024 ? size : 1024);
|
UInt new_size = size + (size > 1024 ? size : 1024);
|
||||||
UInt i;
|
UInt i;
|
||||||
|
|
||||||
newt = (export_dbref_hash_entry_t *)calloc(new_size,sizeof(export_dbref_hash_entry_t));
|
newt = (export_dbref_hash_entry_t *)calloc(new_size,
|
||||||
|
sizeof(export_dbref_hash_entry_t));
|
||||||
if (!newt) {
|
if (!newt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -286,7 +279,8 @@ GrowDBRefTable(void) {
|
|||||||
export_dbref_hash_entry_t *newp;
|
export_dbref_hash_entry_t *newp;
|
||||||
CELL hash;
|
CELL hash;
|
||||||
|
|
||||||
if (!dbr) continue;
|
if (!dbr)
|
||||||
|
continue;
|
||||||
hash = ((CELL)(dbr)) / (2 * sizeof(CELL)) % new_size;
|
hash = ((CELL)(dbr)) / (2 * sizeof(CELL)) % new_size;
|
||||||
newp = newt + hash;
|
newp = newt + hash;
|
||||||
while (newp->val) {
|
while (newp->val) {
|
||||||
@ -303,11 +297,10 @@ GrowDBRefTable(void) {
|
|||||||
free(oldt);
|
free(oldt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void LookupDBRef(DBRef ref) {
|
||||||
LookupDBRef(DBRef ref)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
CELL hash = ((CELL)(ref))/(2*sizeof(CELL)) % LOCAL_ExportDBRefHashTableSize;
|
CELL hash =
|
||||||
|
((CELL)(ref)) / (2 * sizeof(CELL)) % LOCAL_ExportDBRefHashTableSize;
|
||||||
export_dbref_hash_entry_t *a;
|
export_dbref_hash_entry_t *a;
|
||||||
|
|
||||||
a = LOCAL_ExportDBRefHashChain + hash;
|
a = LOCAL_ExportDBRefHashChain + hash;
|
||||||
@ -324,9 +317,7 @@ LookupDBRef(DBRef ref)
|
|||||||
a->sz = ((LogUpdClause *)ref)->ClSize;
|
a->sz = ((LogUpdClause *)ref)->ClSize;
|
||||||
a->refs = 1;
|
a->refs = 1;
|
||||||
LOCAL_ExportDBRefHashTableNum++;
|
LOCAL_ExportDBRefHashTableNum++;
|
||||||
if (LOCAL_ExportDBRefHashTableNum >
|
if (LOCAL_ExportDBRefHashTableNum > LOCAL_ExportDBRefHashTableSize / 2) {
|
||||||
LOCAL_ExportDBRefHashTableSize/2
|
|
||||||
) {
|
|
||||||
GrowDBRefTable();
|
GrowDBRefTable();
|
||||||
if (!LOCAL_ExportDBRefHashChain) {
|
if (!LOCAL_ExportDBRefHashChain) {
|
||||||
return;
|
return;
|
||||||
@ -334,27 +325,28 @@ LookupDBRef(DBRef ref)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void InitHash(void) {
|
||||||
InitHash(void)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_ExportFunctorHashTableNum = 0;
|
LOCAL_ExportFunctorHashTableNum = 0;
|
||||||
LOCAL_ExportFunctorHashTableSize = EXPORT_FUNCTOR_TABLE_SIZE;
|
LOCAL_ExportFunctorHashTableSize = EXPORT_FUNCTOR_TABLE_SIZE;
|
||||||
LOCAL_ExportFunctorHashChain = (export_functor_hash_entry_t *)calloc(LOCAL_ExportFunctorHashTableSize, sizeof(export_functor_hash_entry_t ));
|
LOCAL_ExportFunctorHashChain = (export_functor_hash_entry_t *)calloc(
|
||||||
|
LOCAL_ExportFunctorHashTableSize, sizeof(export_functor_hash_entry_t));
|
||||||
LOCAL_ExportAtomHashTableNum = 0;
|
LOCAL_ExportAtomHashTableNum = 0;
|
||||||
LOCAL_ExportAtomHashTableSize = EXPORT_ATOM_TABLE_SIZE;
|
LOCAL_ExportAtomHashTableSize = EXPORT_ATOM_TABLE_SIZE;
|
||||||
LOCAL_ExportAtomHashChain = (export_atom_hash_entry_t *)calloc( LOCAL_ExportAtomHashTableSize, sizeof(export_atom_hash_entry_t));
|
LOCAL_ExportAtomHashChain = (export_atom_hash_entry_t *)calloc(
|
||||||
|
LOCAL_ExportAtomHashTableSize, sizeof(export_atom_hash_entry_t));
|
||||||
LOCAL_ExportPredEntryHashTableNum = 0;
|
LOCAL_ExportPredEntryHashTableNum = 0;
|
||||||
LOCAL_ExportPredEntryHashTableSize = EXPORT_PRED_ENTRY_TABLE_SIZE;
|
LOCAL_ExportPredEntryHashTableSize = EXPORT_PRED_ENTRY_TABLE_SIZE;
|
||||||
LOCAL_ExportPredEntryHashChain = (export_pred_entry_hash_entry_t *)calloc(LOCAL_ExportPredEntryHashTableSize, sizeof(export_pred_entry_hash_entry_t));
|
LOCAL_ExportPredEntryHashChain = (export_pred_entry_hash_entry_t *)calloc(
|
||||||
|
LOCAL_ExportPredEntryHashTableSize,
|
||||||
|
sizeof(export_pred_entry_hash_entry_t));
|
||||||
LOCAL_ExportDBRefHashTableNum = 0;
|
LOCAL_ExportDBRefHashTableNum = 0;
|
||||||
LOCAL_ExportDBRefHashTableSize = EXPORT_DBREF_TABLE_SIZE;
|
LOCAL_ExportDBRefHashTableSize = EXPORT_DBREF_TABLE_SIZE;
|
||||||
LOCAL_ExportDBRefHashChain = (export_dbref_hash_entry_t *)calloc(EXPORT_DBREF_TABLE_SIZE, sizeof(export_dbref_hash_entry_t));
|
LOCAL_ExportDBRefHashChain = (export_dbref_hash_entry_t *)calloc(
|
||||||
|
EXPORT_DBREF_TABLE_SIZE, sizeof(export_dbref_hash_entry_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void CloseHash(void) {
|
||||||
CloseHash(void)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_ExportFunctorHashTableNum = 0;
|
LOCAL_ExportFunctorHashTableNum = 0;
|
||||||
LOCAL_ExportFunctorHashTableSize = 0L;
|
LOCAL_ExportFunctorHashTableSize = 0L;
|
||||||
@ -370,37 +362,27 @@ CloseHash(void)
|
|||||||
free(LOCAL_ExportDBRefHashChain);
|
free(LOCAL_ExportDBRefHashChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Atom
|
static inline Atom AtomAdjust(Atom a) {
|
||||||
AtomAdjust(Atom a)
|
|
||||||
{
|
|
||||||
LookupAtom(a);
|
LookupAtom(a);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Functor
|
static inline Functor FuncAdjust(Functor f) {
|
||||||
FuncAdjust(Functor f)
|
|
||||||
{
|
|
||||||
LookupFunctor(f);
|
LookupFunctor(f);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline Term AtomTermAdjust(Term t) {
|
||||||
static inline Term
|
|
||||||
AtomTermAdjust(Term t)
|
|
||||||
{
|
|
||||||
LookupAtom(AtomOfTerm(t));
|
LookupAtom(AtomOfTerm(t));
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Term
|
static inline Term TermToGlobalOrAtomAdjust(Term t) {
|
||||||
TermToGlobalOrAtomAdjust(Term t)
|
|
||||||
{
|
|
||||||
if (t && IsAtomTerm(t))
|
if (t && IsAtomTerm(t))
|
||||||
return AtomTermAdjust(t);
|
return AtomTermAdjust(t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define IsOldCode(P) FALSE
|
#define IsOldCode(P) FALSE
|
||||||
#define IsOldCodeCellPtr(P) FALSE
|
#define IsOldCodeCellPtr(P) FALSE
|
||||||
#define IsOldDelay(P) FALSE
|
#define IsOldDelay(P) FALSE
|
||||||
@ -430,28 +412,22 @@ TermToGlobalOrAtomAdjust(Term t)
|
|||||||
#define IntegerInCodeAdjust(P)
|
#define IntegerInCodeAdjust(P)
|
||||||
#define OpcodeAdjust(P) (P)
|
#define OpcodeAdjust(P) (P)
|
||||||
|
|
||||||
static inline Term
|
static inline Term ModuleAdjust(Term t) {
|
||||||
ModuleAdjust(Term t)
|
if (!t)
|
||||||
{
|
return t;
|
||||||
if (!t) return t;
|
|
||||||
return AtomTermAdjust(t);
|
return AtomTermAdjust(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline PredEntry *
|
static inline PredEntry *PredEntryAdjust(PredEntry *pe) {
|
||||||
PredEntryAdjust(PredEntry *pe)
|
|
||||||
{
|
|
||||||
LookupPredEntry(pe);
|
LookupPredEntry(pe);
|
||||||
return pe;
|
return pe;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline PredEntry *
|
static inline PredEntry *PtoPredAdjust(PredEntry *pe) {
|
||||||
PtoPredAdjust(PredEntry *pe)
|
|
||||||
{
|
|
||||||
LookupPredEntry(pe);
|
LookupPredEntry(pe);
|
||||||
return pe;
|
return pe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define ExternalFunctionAdjust(P) (P)
|
#define ExternalFunctionAdjust(P) (P)
|
||||||
#define DBRecordAdjust(P) (P)
|
#define DBRecordAdjust(P) (P)
|
||||||
#define ModEntryPtrAdjust(P) (P)
|
#define ModEntryPtrAdjust(P) (P)
|
||||||
@ -469,9 +445,7 @@ PtoPredAdjust(PredEntry *pe)
|
|||||||
#define GlobalAdjust(P) (P)
|
#define GlobalAdjust(P) (P)
|
||||||
|
|
||||||
#define DBRefAdjust(P, DoRef) DBRefAdjust__(P PASS_REGS)
|
#define DBRefAdjust(P, DoRef) DBRefAdjust__(P PASS_REGS)
|
||||||
static inline DBRef
|
static inline DBRef DBRefAdjust__(DBRef dbt USES_REGS) {
|
||||||
DBRefAdjust__ (DBRef dbt USES_REGS)
|
|
||||||
{
|
|
||||||
LookupDBRef(dbt);
|
LookupDBRef(dbt);
|
||||||
return dbt;
|
return dbt;
|
||||||
}
|
}
|
||||||
@ -514,67 +488,48 @@ DBRefAdjust__ (DBRef dbt USES_REGS)
|
|||||||
|
|
||||||
#define rehash(oldcode, NOfE, KindOfEntries)
|
#define rehash(oldcode, NOfE, KindOfEntries)
|
||||||
|
|
||||||
|
static void RestoreFlags(UInt NFlags) {}
|
||||||
static void RestoreFlags( UInt NFlags )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "rheap.h"
|
#include "rheap.h"
|
||||||
|
|
||||||
static void
|
static void RestoreHashPreds(USES_REGS1) {}
|
||||||
RestoreHashPreds( USES_REGS1 )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
static void RestoreAtomList(Atom atm USES_REGS) {}
|
||||||
|
|
||||||
static void
|
static size_t save_bytes(FILE *stream, void *ptr, size_t sz) {
|
||||||
RestoreAtomList(Atom atm USES_REGS)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t save_bytes(FILE *stream, void *ptr, size_t sz)
|
|
||||||
{
|
|
||||||
return fwrite(ptr, sz, 1, stream);
|
return fwrite(ptr, sz, 1, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t save_byte(FILE *stream, int byte)
|
static size_t save_byte(FILE *stream, int byte) {
|
||||||
{
|
|
||||||
fputc(byte, stream);
|
fputc(byte, stream);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t save_bits16(FILE *stream, BITS16 val)
|
static size_t save_bits16(FILE *stream, BITS16 val) {
|
||||||
{
|
|
||||||
BITS16 v = val;
|
BITS16 v = val;
|
||||||
return save_bytes(stream, &v, sizeof(BITS16));
|
return save_bytes(stream, &v, sizeof(BITS16));
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t save_UInt(FILE *stream, UInt val)
|
static size_t save_UInt(FILE *stream, UInt val) {
|
||||||
{
|
|
||||||
UInt v = val;
|
UInt v = val;
|
||||||
return save_bytes(stream, &v, sizeof(UInt));
|
return save_bytes(stream, &v, sizeof(UInt));
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t save_Int(FILE *stream, Int val)
|
static size_t save_Int(FILE *stream, Int val) {
|
||||||
{
|
|
||||||
Int v = val;
|
Int v = val;
|
||||||
return save_bytes(stream, &v, sizeof(Int));
|
return save_bytes(stream, &v, sizeof(Int));
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t save_tag(FILE *stream, qlf_tag_t tag)
|
static size_t save_tag(FILE *stream, qlf_tag_t tag) {
|
||||||
{
|
|
||||||
return save_byte(stream, tag);
|
return save_byte(stream, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t save_predFlags(FILE *stream, pred_flags_t predFlags)
|
static size_t save_predFlags(FILE *stream, pred_flags_t predFlags) {
|
||||||
{
|
|
||||||
pred_flags_t v = predFlags;
|
pred_flags_t v = predFlags;
|
||||||
return save_bytes(stream, &v, sizeof(pred_flags_t));
|
return save_bytes(stream, &v, sizeof(pred_flags_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int SaveHash(FILE *stream) {
|
||||||
SaveHash(FILE *stream)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
UInt i;
|
UInt i;
|
||||||
/* first, current opcodes */
|
/* first, current opcodes */
|
||||||
@ -594,7 +549,8 @@ SaveHash(FILE *stream)
|
|||||||
CHECK(save_UInt(stream, (UInt)at));
|
CHECK(save_UInt(stream, (UInt)at));
|
||||||
CHECK(save_tag(stream, QLY_ATOM));
|
CHECK(save_tag(stream, QLY_ATOM));
|
||||||
CHECK(save_UInt(stream, strlen((char *)RepAtom(at)->StrOfAE)));
|
CHECK(save_UInt(stream, strlen((char *)RepAtom(at)->StrOfAE)));
|
||||||
CHECK(save_bytes(stream, (char *)at->StrOfAE, (strlen((char *)at->StrOfAE)+1)*sizeof(char)));
|
CHECK(save_bytes(stream, (char *)at->StrOfAE,
|
||||||
|
(strlen((char *)at->StrOfAE) + 1) * sizeof(char)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
save_tag(stream, QLY_START_FUNCTORS);
|
save_tag(stream, QLY_START_FUNCTORS);
|
||||||
@ -633,8 +589,7 @@ SaveHash(FILE *stream)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t save_clauses(FILE *stream, PredEntry *pp) {
|
||||||
save_clauses(FILE *stream, PredEntry *pp) {
|
|
||||||
yamop *FirstC, *LastC;
|
yamop *FirstC, *LastC;
|
||||||
|
|
||||||
FirstC = pp->cs.p_code.FirstClause;
|
FirstC = pp->cs.p_code.FirstClause;
|
||||||
@ -674,7 +629,8 @@ save_clauses(FILE *stream, PredEntry *pp) {
|
|||||||
CHECK(save_UInt(stream, (UInt)cl));
|
CHECK(save_UInt(stream, (UInt)cl));
|
||||||
CHECK(save_UInt(stream, size));
|
CHECK(save_UInt(stream, size));
|
||||||
CHECK(save_bytes(stream, dcl, size));
|
CHECK(save_bytes(stream, dcl, size));
|
||||||
if (cl == LastC) return 1;
|
if (cl == LastC)
|
||||||
|
return 1;
|
||||||
cl = NextDynamicClause(cl);
|
cl = NextDynamicClause(cl);
|
||||||
} while (TRUE);
|
} while (TRUE);
|
||||||
} else {
|
} else {
|
||||||
@ -689,15 +645,15 @@ save_clauses(FILE *stream, PredEntry *pp) {
|
|||||||
CHECK(save_UInt(stream, (UInt)cl));
|
CHECK(save_UInt(stream, (UInt)cl));
|
||||||
CHECK(save_UInt(stream, size));
|
CHECK(save_UInt(stream, size));
|
||||||
CHECK(save_bytes(stream, cl, size));
|
CHECK(save_bytes(stream, cl, size));
|
||||||
if (cl->ClCode == LastC) return 1;
|
if (cl->ClCode == LastC)
|
||||||
|
return 1;
|
||||||
cl = cl->ClNext;
|
cl = cl->ClNext;
|
||||||
} while (TRUE);
|
} while (TRUE);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t save_pred(FILE *stream, PredEntry *ap) {
|
||||||
save_pred(FILE *stream, PredEntry *ap) {
|
|
||||||
CHECK(save_UInt(stream, (UInt)ap));
|
CHECK(save_UInt(stream, (UInt)ap));
|
||||||
CHECK(save_predFlags(stream, ap->PredFlags));
|
CHECK(save_predFlags(stream, ap->PredFlags));
|
||||||
if (ap->PredFlags & ForeignPredFlags)
|
if (ap->PredFlags & ForeignPredFlags)
|
||||||
@ -708,19 +664,17 @@ save_pred(FILE *stream, PredEntry *ap) {
|
|||||||
return save_clauses(stream, ap);
|
return save_clauses(stream, ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int clean_pred(PredEntry *pp USES_REGS) {
|
||||||
clean_pred(PredEntry *pp USES_REGS) {
|
|
||||||
if (pp->PredFlags & ForeignPredFlags) {
|
if (pp->PredFlags & ForeignPredFlags) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
CleanClauses(pp->cs.p_code.FirstClause, pp->cs.p_code.LastClause, pp PASS_REGS);
|
CleanClauses(pp->cs.p_code.FirstClause, pp->cs.p_code.LastClause,
|
||||||
|
pp PASS_REGS);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t mark_pred(PredEntry *ap) {
|
||||||
mark_pred(PredEntry *ap)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
if (ap->ModuleOfPred != IDB_MODULE) {
|
if (ap->ModuleOfPred != IDB_MODULE) {
|
||||||
if (ap->ArityOfPE) {
|
if (ap->ArityOfPE) {
|
||||||
@ -743,8 +697,7 @@ mark_pred(PredEntry *ap)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t mark_ops(FILE *stream, Term mod) {
|
||||||
mark_ops(FILE *stream, Term mod) {
|
|
||||||
OpEntry *op = OpList;
|
OpEntry *op = OpList;
|
||||||
while (op) {
|
while (op) {
|
||||||
if (!mod || op->OpModule == mod) {
|
if (!mod || op->OpModule == mod) {
|
||||||
@ -757,8 +710,7 @@ mark_ops(FILE *stream, Term mod) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t save_ops(FILE *stream, Term mod) {
|
||||||
save_ops(FILE *stream, Term mod) {
|
|
||||||
OpEntry *op = OpList;
|
OpEntry *op = OpList;
|
||||||
while (op) {
|
while (op) {
|
||||||
if (!mod || op->OpModule == mod) {
|
if (!mod || op->OpModule == mod) {
|
||||||
@ -775,17 +727,17 @@ save_ops(FILE *stream, Term mod) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int save_header(FILE *stream, char type[]) {
|
||||||
save_header(FILE *stream, char type[])
|
char msg[256 * 16];
|
||||||
{
|
|
||||||
char msg[256];
|
|
||||||
|
|
||||||
sprintf(msg, "#!/bin/sh\nexec_dir=${YAPBINDIR:-%s}\nexec $exec_dir/yap $0 \"$@\"\n%s %s\n", YAP_BINDIR, type, YAP_FULL_VERSION);
|
sprintf(msg,
|
||||||
|
"#!/bin/sh\nexec_dir=${YAPBINDIR:-%s}\nexec $exec_dir/yap $0 "
|
||||||
|
"\"$@\"\n%s %s\n",
|
||||||
|
YAP_BINDIR, type, YAP_FULL_VERSION);
|
||||||
return save_bytes(stream, msg, strlen(msg) + 1);
|
return save_bytes(stream, msg, strlen(msg) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t save_module(FILE *stream, Term mod) {
|
||||||
save_module(FILE *stream, Term mod) {
|
|
||||||
PredEntry *ap = Yap_ModulePred(mod);
|
PredEntry *ap = Yap_ModulePred(mod);
|
||||||
save_header(stream, "saved module,");
|
save_header(stream, "saved module,");
|
||||||
InitHash();
|
InitHash();
|
||||||
@ -813,8 +765,7 @@ save_module(FILE *stream, Term mod) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t save_program(FILE *stream) {
|
||||||
save_program(FILE *stream) {
|
|
||||||
ModEntry *me = CurrentModules;
|
ModEntry *me = CurrentModules;
|
||||||
|
|
||||||
InitHash();
|
InitHash();
|
||||||
@ -858,8 +809,7 @@ save_program(FILE *stream) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t save_file(FILE *stream, Atom FileName) {
|
||||||
save_file(FILE *stream, Atom FileName) {
|
|
||||||
ModEntry *me = CurrentModules;
|
ModEntry *me = CurrentModules;
|
||||||
|
|
||||||
InitHash();
|
InitHash();
|
||||||
@ -872,9 +822,9 @@ save_file(FILE *stream, Atom FileName) {
|
|||||||
while (pp != NULL) {
|
while (pp != NULL) {
|
||||||
pp = PredEntryAdjust(pp);
|
pp = PredEntryAdjust(pp);
|
||||||
if (pp &&
|
if (pp &&
|
||||||
!(pp->PredFlags & (MultiFileFlag|NumberDBPredFlag|AtomDBPredFlag|CPredFlag|AsmPredFlag|UserCPredFlag)) &&
|
!(pp->PredFlags & (MultiFileFlag | NumberDBPredFlag | AtomDBPredFlag |
|
||||||
pp->ModuleOfPred != IDB_MODULE &&
|
CPredFlag | AsmPredFlag | UserCPredFlag)) &&
|
||||||
pp->src.OwnerFile == FileName) {
|
pp->ModuleOfPred != IDB_MODULE && pp->src.OwnerFile == FileName) {
|
||||||
CHECK(mark_pred(pp));
|
CHECK(mark_pred(pp));
|
||||||
}
|
}
|
||||||
pp = pp->NextPredOfModule;
|
pp = pp->NextPredOfModule;
|
||||||
@ -893,7 +843,8 @@ save_file(FILE *stream, Atom FileName) {
|
|||||||
CHECK(save_UInt(stream, (UInt)MkAtomTerm(me->AtomOfME)));
|
CHECK(save_UInt(stream, (UInt)MkAtomTerm(me->AtomOfME)));
|
||||||
while (pp != NULL) {
|
while (pp != NULL) {
|
||||||
if (pp &&
|
if (pp &&
|
||||||
!(pp->PredFlags & (MultiFileFlag|NumberDBPredFlag|AtomDBPredFlag|CPredFlag|AsmPredFlag|UserCPredFlag)) &&
|
!(pp->PredFlags & (MultiFileFlag | NumberDBPredFlag | AtomDBPredFlag |
|
||||||
|
CPredFlag | AsmPredFlag | UserCPredFlag)) &&
|
||||||
pp->src.OwnerFile == FileName) {
|
pp->src.OwnerFile == FileName) {
|
||||||
CHECK(save_tag(stream, QLY_START_PREDICATE));
|
CHECK(save_tag(stream, QLY_START_PREDICATE));
|
||||||
CHECK(save_pred(stream, pp));
|
CHECK(save_pred(stream, pp));
|
||||||
@ -909,9 +860,7 @@ save_file(FILE *stream, Atom FileName) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int qsave_module_preds(USES_REGS1) {
|
||||||
qsave_module_preds( USES_REGS1 )
|
|
||||||
{
|
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
Term tmod = Deref(ARG2);
|
Term tmod = Deref(ARG2);
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
@ -938,9 +887,7 @@ qsave_module_preds( USES_REGS1 )
|
|||||||
return save_module(stream, tmod) != 0;
|
return save_module(stream, tmod) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int qsave_program(USES_REGS1) {
|
||||||
qsave_program( USES_REGS1 )
|
|
||||||
{
|
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
|
|
||||||
@ -950,9 +897,7 @@ qsave_program( USES_REGS1 )
|
|||||||
return save_program(stream) != 0;
|
return save_program(stream) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int qsave_file(USES_REGS1) {
|
||||||
qsave_file( USES_REGS1 )
|
|
||||||
{
|
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Term tfile = Deref(ARG2);
|
Term tfile = Deref(ARG2);
|
||||||
@ -971,16 +916,16 @@ qsave_file( USES_REGS1 )
|
|||||||
return save_file(stream, AtomOfTerm(tfile)) != 0;
|
return save_file(stream, AtomOfTerm(tfile)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_InitQLY(void)
|
void Yap_InitQLY(void) {
|
||||||
{
|
Yap_InitCPred("$qsave_module_preds", 2, qsave_module_preds,
|
||||||
Yap_InitCPred("$qsave_module_preds", 2, qsave_module_preds, SyncPredFlag|UserCPredFlag);
|
SyncPredFlag | UserCPredFlag);
|
||||||
Yap_InitCPred("$qsave_program", 1, qsave_program, SyncPredFlag|UserCPredFlag);
|
Yap_InitCPred("$qsave_program", 1, qsave_program,
|
||||||
Yap_InitCPred("$qsave_file_preds", 2, qsave_file, SyncPredFlag|UserCPredFlag);
|
SyncPredFlag | UserCPredFlag);
|
||||||
|
Yap_InitCPred("$qsave_file_preds", 2, qsave_file,
|
||||||
|
SyncPredFlag | UserCPredFlag);
|
||||||
if (FALSE) {
|
if (FALSE) {
|
||||||
restore_codes();
|
restore_codes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
||||||
|
385
C/save.c
385
C/save.c
@ -8,10 +8,9 @@
|
|||||||
* *
|
* *
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* *
|
* *
|
||||||
* File: save.c *
|
* File: save.c * Last
|
||||||
* Last rev: *
|
*rev: * mods:
|
||||||
* mods: *
|
** comments: saving and restoring a Prolog computation *
|
||||||
* comments: saving and restoring a Prolog computation *
|
|
||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
#ifdef SCCS
|
#ifdef SCCS
|
||||||
@ -24,16 +23,16 @@ static char SccsId[] = "@(#)save.c 1.3 3/15/90";
|
|||||||
#if HAVE_WINSOCK2_H
|
#if HAVE_WINSOCK2_H
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#endif
|
#endif
|
||||||
#include <windows.h>
|
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
#if USE_DL_MALLOC
|
#if USE_DL_MALLOC
|
||||||
#include "dlmalloc.h"
|
#include "dlmalloc.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "Foreign.h"
|
||||||
#include "YapText.h"
|
#include "YapText.h"
|
||||||
#include "sshift.h"
|
#include "sshift.h"
|
||||||
#include "yapio.h"
|
#include "yapio.h"
|
||||||
#include "Foreign.h"
|
|
||||||
#if HAVE_STRING_H
|
#if HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
@ -124,7 +123,8 @@ static void restore_heap(void);
|
|||||||
static void ShowAtoms(void);
|
static void ShowAtoms(void);
|
||||||
static void ShowEntries(PropEntry *);
|
static void ShowEntries(PropEntry *);
|
||||||
#endif
|
#endif
|
||||||
static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *, CELL *, FILE **);
|
static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *,
|
||||||
|
CELL *, FILE **);
|
||||||
static void CloseRestore(void);
|
static void CloseRestore(void);
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static int check_opcodes(OPCODE[]);
|
static int check_opcodes(OPCODE[]);
|
||||||
@ -146,52 +146,48 @@ extern int DefVol;
|
|||||||
|
|
||||||
#ifdef LIGHT
|
#ifdef LIGHT
|
||||||
|
|
||||||
#include <unix.h>
|
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include <unix.h>
|
||||||
|
|
||||||
void
|
void LightBug(char *);
|
||||||
LightBug(char *);
|
|
||||||
|
|
||||||
static void
|
static void LightBug(s) char *s;
|
||||||
LightBug(s)
|
{}
|
||||||
char *s;
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* LIGHT */
|
#endif /* LIGHT */
|
||||||
|
|
||||||
static Int
|
static Int do_SYSTEM_ERROR_INTERNAL(yap_error_number etype, const char *msg) {
|
||||||
do_SYSTEM_ERROR_INTERNAL(yap_error_number etype, const char *msg)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
char *buf = malloc(1043);
|
char *buf = malloc(1043);
|
||||||
#if HAVE_SNPRINTF
|
#if HAVE_SNPRINTF
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
snprintf(buf,1043-1,"%s (%s when reading %s)", msg,
|
snprintf(buf, 1043 - 1, "%s (%s when reading %s)", msg, strerror(errno),
|
||||||
strerror(errno), LOCAL_FileNameBuf);
|
LOCAL_FileNameBuf);
|
||||||
#else
|
#else
|
||||||
snprintf(buf,1024-1,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf);
|
snprintf(buf, 1024 - 1, "%s, (system error %d when reading %s)", msg, errno,
|
||||||
|
LOCAL_FileNameBuf);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
snprintf(buf,1024-1,"%s, (%s when reading %s)",msg,strerror(errno),LOCAL_FileNameBuf);
|
snprintf(buf, 1024 - 1, "%s, (%s when reading %s)", msg, strerror(errno),
|
||||||
|
LOCAL_FileNameBuf);
|
||||||
#else
|
#else
|
||||||
snprintf(buf,1024-1,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf);
|
snprintf(buf, 1024 - 1, "%s, (system error %d when reading %s)", msg, errno,
|
||||||
|
LOCAL_FileNameBuf);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
LOCAL_Error_TYPE = etype;
|
LOCAL_Error_TYPE = etype;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static int myread(FILE *fd, char *buffer, Int len) {
|
||||||
inline static
|
|
||||||
int myread(FILE *fd, char *buffer, Int len) {
|
|
||||||
size_t nread;
|
size_t nread;
|
||||||
|
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
nread = fread(buffer, 1, (int)len, fd);
|
nread = fread(buffer, 1, (int)len, fd);
|
||||||
if (nread < 1) {
|
if (nread < 1) {
|
||||||
return do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"bad read on saved state");
|
return do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,
|
||||||
|
"bad read on saved state");
|
||||||
}
|
}
|
||||||
buffer += nread;
|
buffer += nread;
|
||||||
len -= nread;
|
len -= nread;
|
||||||
@ -199,15 +195,14 @@ int myread(FILE *fd, char *buffer, Int len) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static
|
inline static Int mywrite(FILE *fd, char *buff, Int len) {
|
||||||
Int
|
|
||||||
mywrite(FILE *fd, char *buff, Int len) {
|
|
||||||
size_t nwritten;
|
size_t nwritten;
|
||||||
|
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
nwritten = fwrite(buff, 1, (size_t)len, fd);
|
nwritten = fwrite(buff, 1, (size_t)len, fd);
|
||||||
if ((long int)nwritten < 0) {
|
if ((long int)nwritten < 0) {
|
||||||
return do_SYSTEM_ERROR_INTERNAL(SYSTEM_ERROR_INTERNAL,"bad write on saved state");
|
return do_SYSTEM_ERROR_INTERNAL(SYSTEM_ERROR_INTERNAL,
|
||||||
|
"bad write on saved state");
|
||||||
}
|
}
|
||||||
buff += nwritten;
|
buff += nwritten;
|
||||||
len -= nwritten;
|
len -= nwritten;
|
||||||
@ -219,8 +214,6 @@ mywrite(FILE *fd, char *buff, Int len) {
|
|||||||
|
|
||||||
/* Where the code was before */
|
/* Where the code was before */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef CELL *CELLPOINTER;
|
typedef CELL *CELLPOINTER;
|
||||||
|
|
||||||
static FILE *splfild = NULL;
|
static FILE *splfild = NULL;
|
||||||
@ -240,9 +233,7 @@ static Int OldHeapUsed;
|
|||||||
static CELL which_save;
|
static CELL which_save;
|
||||||
|
|
||||||
/* Open a file to read or to write */
|
/* Open a file to read or to write */
|
||||||
static FILE *
|
static FILE *open_file(char *my_file, int flag) {
|
||||||
open_file(char *my_file, int flag)
|
|
||||||
{
|
|
||||||
FILE *splfild;
|
FILE *splfild;
|
||||||
char flags[6];
|
char flags[6];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -272,50 +263,40 @@ open_file(char *my_file, int flag)
|
|||||||
return splfild;
|
return splfild;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int close_file(void) {
|
||||||
close_file(void)
|
|
||||||
{
|
|
||||||
if (splfild == 0)
|
if (splfild == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (fclose(splfild) < 0)
|
if (fclose(splfild) < 0)
|
||||||
return do_SYSTEM_ERROR_INTERNAL(SYSTEM_ERROR_INTERNAL,"bad close on saved state");
|
return do_SYSTEM_ERROR_INTERNAL(SYSTEM_ERROR_INTERNAL,
|
||||||
|
"bad close on saved state");
|
||||||
splfild = 0;
|
splfild = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stores a cell in a file */
|
/* stores a cell in a file */
|
||||||
static Int
|
static Int putout(CELL l) { return mywrite(splfild, (char *)&l, sizeof(CELL)); }
|
||||||
putout(CELL l)
|
|
||||||
{
|
|
||||||
return mywrite(splfild, (char *) &l, sizeof(CELL));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* stores a pointer to a cell in a file */
|
/* stores a pointer to a cell in a file */
|
||||||
static Int
|
static Int putcellptr(CELL *l) {
|
||||||
putcellptr(CELL *l)
|
|
||||||
{
|
|
||||||
return mywrite(splfild, (char *)&l, sizeof(CELLPOINTER));
|
return mywrite(splfild, (char *)&l, sizeof(CELLPOINTER));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* gets a cell from a file */
|
/* gets a cell from a file */
|
||||||
static CELL
|
static CELL get_cell(void) {
|
||||||
get_cell(void)
|
|
||||||
{
|
|
||||||
CELL l;
|
CELL l;
|
||||||
myread(splfild, (char *)&l, Unsigned(sizeof(CELL)));
|
myread(splfild, (char *)&l, Unsigned(sizeof(CELL)));
|
||||||
return (l);
|
return (l);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* gets a cell from a file */
|
/* gets a cell from a file */
|
||||||
static CELL
|
static CELL get_header_cell(void) {
|
||||||
get_header_cell(void)
|
|
||||||
{
|
|
||||||
CELL l;
|
CELL l;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
int n;
|
int n;
|
||||||
while (count < sizeof(CELL)) {
|
while (count < sizeof(CELL)) {
|
||||||
if ((n = fread(&l, 1, sizeof(CELL) - count, splfild)) < 0) {
|
if ((n = fread(&l, 1, sizeof(CELL) - count, splfild)) < 0) {
|
||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to read saved state header");
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,
|
||||||
|
"failed to read saved state header");
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
count += n;
|
count += n;
|
||||||
@ -324,9 +305,7 @@ get_header_cell(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* gets a pointer to cell from a file */
|
/* gets a pointer to cell from a file */
|
||||||
static CELL *
|
static CELL *get_cellptr(void) {
|
||||||
get_cellptr(void)
|
|
||||||
{
|
|
||||||
CELL *l;
|
CELL *l;
|
||||||
|
|
||||||
if (myread(splfild, (char *)&l, Unsigned(sizeof(CELLPOINTER))) < 0)
|
if (myread(splfild, (char *)&l, Unsigned(sizeof(CELLPOINTER))) < 0)
|
||||||
@ -338,12 +317,13 @@ get_cellptr(void)
|
|||||||
* writes the header (at the moment YAPV*), info about what kind of saved
|
* writes the header (at the moment YAPV*), info about what kind of saved
|
||||||
* set, the work size, and the space ocuppied
|
* set, the work size, and the space ocuppied
|
||||||
*/
|
*/
|
||||||
static int
|
static int put_info(int info, int mode USES_REGS) {
|
||||||
put_info(int info, int mode USES_REGS)
|
char msg[256 * 16];
|
||||||
{
|
|
||||||
char msg[256];
|
|
||||||
|
|
||||||
sprintf(msg, "#!/bin/sh\nexec_dir=${YAPBINDIR:-%s}\nexec $exec_dir/yap $0 \"$@\"\n%cYAP-%s", YAP_BINDIR, 1, YAP_FULL_VERSION);
|
sprintf(msg,
|
||||||
|
"#!/bin/sh\nexec_dir=${YAPBINDIR:-%s}\nexec $exec_dir/yap $0 "
|
||||||
|
"\"$@\"\n%cYAP-%s",
|
||||||
|
YAP_BINDIR, 1, YAP_FULL_VERSION);
|
||||||
if (mywrite(splfild, msg, strlen(msg) + 1))
|
if (mywrite(splfild, msg, strlen(msg) + 1))
|
||||||
return -1;
|
return -1;
|
||||||
if (putout(Unsigned(info)) < 0)
|
if (putout(Unsigned(info)) < 0)
|
||||||
@ -376,9 +356,7 @@ put_info(int info, int mode USES_REGS)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int save_regs(int mode USES_REGS) {
|
||||||
save_regs(int mode USES_REGS)
|
|
||||||
{
|
|
||||||
/* save all registers */
|
/* save all registers */
|
||||||
if (putout((CELL)compile_arrays) < 0)
|
if (putout((CELL)compile_arrays) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -483,9 +461,7 @@ save_regs(int mode USES_REGS)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int save_code_info(void) {
|
||||||
save_code_info(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* First the instructions */
|
/* First the instructions */
|
||||||
{
|
{
|
||||||
@ -498,14 +474,13 @@ save_code_info(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* and the current character codes */
|
/* and the current character codes */
|
||||||
if (mywrite(splfild, (char *)Yap_chtype, NUMBER_OF_CHARS*sizeof(char_kind_t)) < 0)
|
if (mywrite(splfild, (char *)Yap_chtype,
|
||||||
|
NUMBER_OF_CHARS * sizeof(char_kind_t)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int save_heap(void) {
|
||||||
save_heap(void)
|
|
||||||
{
|
|
||||||
#ifdef USE_SYSTEM_MALLOC
|
#ifdef USE_SYSTEM_MALLOC
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
@ -519,9 +494,7 @@ save_heap(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int save_stacks(int mode USES_REGS) {
|
||||||
save_stacks(int mode USES_REGS)
|
|
||||||
{
|
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
@ -540,8 +513,7 @@ save_stacks(int mode USES_REGS)
|
|||||||
if (mywrite(splfild, (char *)LOCAL_TrailBase, j) < 0)
|
if (mywrite(splfild, (char *)LOCAL_TrailBase, j) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
case DO_ONLY_CODE:
|
case DO_ONLY_CODE: {
|
||||||
{
|
|
||||||
tr_fr_ptr tr_ptr = TR;
|
tr_fr_ptr tr_ptr = TR;
|
||||||
while (tr_ptr != (tr_fr_ptr)LOCAL_TrailBase) {
|
while (tr_ptr != (tr_fr_ptr)LOCAL_TrailBase) {
|
||||||
CELL val = TrailTerm(tr_ptr - 1);
|
CELL val = TrailTerm(tr_ptr - 1);
|
||||||
@ -568,20 +540,19 @@ save_stacks(int mode USES_REGS)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int save_crc(void) {
|
||||||
save_crc(void)
|
|
||||||
{
|
|
||||||
/* Save a CRC */
|
/* Save a CRC */
|
||||||
return mywrite(splfild, end_msg, 256);
|
return mywrite(splfild, end_msg, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int do_save(int mode USES_REGS) {
|
||||||
do_save(int mode USES_REGS) {
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
|
|
||||||
if (Yap_HoleSize) {
|
if (Yap_HoleSize) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),
|
Yap_Error(SYSTEM_ERROR_INTERNAL,
|
||||||
"restore/1: address space has holes of size %ld, cannot save", (long int)Yap_HoleSize);
|
MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),
|
||||||
|
"restore/1: address space has holes of size %ld, cannot save",
|
||||||
|
(long int)Yap_HoleSize);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!Yap_GetName(LOCAL_FileNameBuf, YAP_FILENAME_MAX, t1)) {
|
if (!Yap_GetName(LOCAL_FileNameBuf, YAP_FILENAME_MAX, t1)) {
|
||||||
@ -590,7 +561,8 @@ do_save(int mode USES_REGS) {
|
|||||||
}
|
}
|
||||||
Yap_CloseStreams(TRUE);
|
Yap_CloseStreams(TRUE);
|
||||||
if ((splfild = open_file(LOCAL_FileNameBuf, O_WRONLY | O_CREAT)) < 0) {
|
if ((splfild = open_file(LOCAL_FileNameBuf, O_WRONLY | O_CREAT)) < 0) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),
|
Yap_Error(SYSTEM_ERROR_INTERNAL,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),
|
||||||
"restore/1, open(%s)", strerror(errno));
|
"restore/1, open(%s)", strerror(errno));
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@ -611,9 +583,7 @@ do_save(int mode USES_REGS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Saves a complete prolog environment */
|
/* Saves a complete prolog environment */
|
||||||
static Int
|
static Int p_save2(USES_REGS1) {
|
||||||
p_save2( USES_REGS1 )
|
|
||||||
{
|
|
||||||
Int res;
|
Int res;
|
||||||
yhandle_t CurSlot = Yap_StartSlots();
|
yhandle_t CurSlot = Yap_StartSlots();
|
||||||
|
|
||||||
@ -645,9 +615,7 @@ p_save2( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Just save the program, not the stacks */
|
/* Just save the program, not the stacks */
|
||||||
static Int
|
static Int p_save_program(USES_REGS1) {
|
||||||
p_save_program( USES_REGS1 )
|
|
||||||
{
|
|
||||||
which_save = 0;
|
which_save = 0;
|
||||||
return do_save(DO_ONLY_CODE PASS_REGS);
|
return do_save(DO_ONLY_CODE PASS_REGS);
|
||||||
}
|
}
|
||||||
@ -655,9 +623,8 @@ p_save_program( USES_REGS1 )
|
|||||||
/* Now, to restore the saved code */
|
/* Now, to restore the saved code */
|
||||||
|
|
||||||
/* First check out if we are dealing with a valid file */
|
/* First check out if we are dealing with a valid file */
|
||||||
static int
|
static int check_header(CELL *info, CELL *ATrail, CELL *AStack,
|
||||||
check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
CELL *AHeap USES_REGS) {
|
||||||
{
|
|
||||||
char pp[256];
|
char pp[256];
|
||||||
char msg[256];
|
char msg[256];
|
||||||
CELL hp_size, gb_size, lc_size, tr_size, mode;
|
CELL hp_size, gb_size, lc_size, tr_size, mode;
|
||||||
@ -668,7 +635,8 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
|||||||
pp[0] = '\0';
|
pp[0] = '\0';
|
||||||
do {
|
do {
|
||||||
if ((n = fread(pp, 1, 1, splfild)) <= 0) {
|
if ((n = fread(pp, 1, 1, splfild)) <= 0) {
|
||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan first line from saved state");
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,
|
||||||
|
"failed to scan first line from saved state");
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
} while (pp[0] != 1);
|
} while (pp[0] != 1);
|
||||||
@ -678,7 +646,9 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
|||||||
int count = 0, n, to_read = Unsigned(strlen(msg) + 1);
|
int count = 0, n, to_read = Unsigned(strlen(msg) + 1);
|
||||||
while (count < to_read) {
|
while (count < to_read) {
|
||||||
if ((n = fread(pp, 1, to_read - count, splfild)) <= 0) {
|
if ((n = fread(pp, 1, to_read - count, splfild)) <= 0) {
|
||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan version info from saved state");
|
do_SYSTEM_ERROR_INTERNAL(
|
||||||
|
PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,
|
||||||
|
"failed to scan version info from saved state");
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
count += n;
|
count += n;
|
||||||
@ -687,7 +657,8 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
|||||||
if (strcmp(pp, msg) != 0) {
|
if (strcmp(pp, msg) != 0) {
|
||||||
strncpy(LOCAL_ErrorMessage, "saved state ", MAX_ERROR_MSG_SIZE - 1);
|
strncpy(LOCAL_ErrorMessage, "saved state ", MAX_ERROR_MSG_SIZE - 1);
|
||||||
strncat(LOCAL_ErrorMessage, LOCAL_FileNameBuf, MAX_ERROR_MSG_SIZE - 1);
|
strncat(LOCAL_ErrorMessage, LOCAL_FileNameBuf, MAX_ERROR_MSG_SIZE - 1);
|
||||||
strncat(LOCAL_ErrorMessage, " failed to match version ID", MAX_ERROR_MSG_SIZE-1);
|
strncat(LOCAL_ErrorMessage, " failed to match version ID",
|
||||||
|
MAX_ERROR_MSG_SIZE - 1);
|
||||||
LOCAL_Error_TYPE = SYSTEM_ERROR_SAVED_STATE;
|
LOCAL_Error_TYPE = SYSTEM_ERROR_SAVED_STATE;
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
@ -734,12 +705,16 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
|||||||
gb_size = get_cell();
|
gb_size = get_cell();
|
||||||
if (LOCAL_ErrorMessage)
|
if (LOCAL_ErrorMessage)
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
if (Yap_HeapBase != NULL && lc_size+gb_size > Unsigned(LOCAL_LocalBase) - Unsigned(LOCAL_GlobalBase)) {
|
if (Yap_HeapBase != NULL &&
|
||||||
|
lc_size + gb_size >
|
||||||
|
Unsigned(LOCAL_LocalBase) - Unsigned(LOCAL_GlobalBase)) {
|
||||||
if (LOCAL_ErrorMessage != NULL)
|
if (LOCAL_ErrorMessage != NULL)
|
||||||
LOCAL_ErrorMessage = "could not allocate enough stack space";
|
LOCAL_ErrorMessage = "could not allocate enough stack space";
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
if (Yap_HeapBase != NULL && (tr_size = get_cell()) > Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase)) {
|
if (Yap_HeapBase != NULL &&
|
||||||
|
(tr_size = get_cell()) >
|
||||||
|
Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase)) {
|
||||||
if (LOCAL_ErrorMessage != NULL)
|
if (LOCAL_ErrorMessage != NULL)
|
||||||
LOCAL_ErrorMessage = "could not allocate enough trail space";
|
LOCAL_ErrorMessage = "could not allocate enough trail space";
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
@ -760,9 +735,7 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Gets the state of the heap, and evaluates the related variables */
|
/* Gets the state of the heap, and evaluates the related variables */
|
||||||
static int
|
static int get_heap_info(USES_REGS1) {
|
||||||
get_heap_info(USES_REGS1)
|
|
||||||
{
|
|
||||||
LOCAL_OldHeapBase = (ADDR)get_cellptr();
|
LOCAL_OldHeapBase = (ADDR)get_cellptr();
|
||||||
if (LOCAL_ErrorMessage)
|
if (LOCAL_ErrorMessage)
|
||||||
return -1;
|
return -1;
|
||||||
@ -801,9 +774,7 @@ get_heap_info(USES_REGS1)
|
|||||||
/* Gets the register array */
|
/* Gets the register array */
|
||||||
/* Saves the old bases for the work areas */
|
/* Saves the old bases for the work areas */
|
||||||
/* and evaluates the difference from the old areas to the new ones */
|
/* and evaluates the difference from the old areas to the new ones */
|
||||||
static int
|
static int get_regs(int flag USES_REGS) {
|
||||||
get_regs(int flag USES_REGS)
|
|
||||||
{
|
|
||||||
CELL *NewGlobalBase = (CELL *)LOCAL_GlobalBase;
|
CELL *NewGlobalBase = (CELL *)LOCAL_GlobalBase;
|
||||||
CELL *NewLCL0 = LCL0;
|
CELL *NewLCL0 = LCL0;
|
||||||
CELL *OldXREGS;
|
CELL *OldXREGS;
|
||||||
@ -934,24 +905,20 @@ get_regs(int flag USES_REGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the old opcodes and place them in a hash table */
|
/* Get the old opcodes and place them in a hash table */
|
||||||
static int
|
static int get_insts(OPCODE old_ops[]) {
|
||||||
get_insts(OPCODE old_ops[])
|
|
||||||
{
|
|
||||||
return myread(splfild, (char *)old_ops, sizeof(OPCODE) * (_std_top + 1));
|
return myread(splfild, (char *)old_ops, sizeof(OPCODE) * (_std_top + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the old atoms hash table */
|
/* Get the old atoms hash table */
|
||||||
static int
|
static int get_hash(void) {
|
||||||
get_hash(void)
|
return myread(splfild, (char *)Yap_chtype,
|
||||||
{
|
NUMBER_OF_CHARS * sizeof(char_kind_t));
|
||||||
return myread(splfild, (char *)Yap_chtype , NUMBER_OF_CHARS*sizeof(char_kind_t));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy all of the old code to the new Heap */
|
/* Copy all of the old code to the new Heap */
|
||||||
static int
|
static int CopyCode(USES_REGS1) {
|
||||||
CopyCode( USES_REGS1 )
|
if (myread(splfild, (char *)Yap_HeapBase,
|
||||||
{
|
(Unsigned(LOCAL_OldHeapTop) - Unsigned(LOCAL_OldHeapBase))) < 0) {
|
||||||
if (myread(splfild, (char *) Yap_HeapBase, (Unsigned(LOCAL_OldHeapTop) - Unsigned(LOCAL_OldHeapBase))) < 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -959,9 +926,7 @@ CopyCode( USES_REGS1 )
|
|||||||
|
|
||||||
/* Copy the local and global stack and also the trail to their new home */
|
/* Copy the local and global stack and also the trail to their new home */
|
||||||
/* In REGS we still have nonadjusted values !! */
|
/* In REGS we still have nonadjusted values !! */
|
||||||
static int
|
static int CopyStacks(USES_REGS1) {
|
||||||
CopyStacks( USES_REGS1 )
|
|
||||||
{
|
|
||||||
Int j;
|
Int j;
|
||||||
char *NewASP;
|
char *NewASP;
|
||||||
|
|
||||||
@ -980,9 +945,7 @@ CopyStacks( USES_REGS1 )
|
|||||||
|
|
||||||
/* Copy the local and global stack and also the trail to their new home */
|
/* Copy the local and global stack and also the trail to their new home */
|
||||||
/* In REGS we still have nonadjusted values !! */
|
/* In REGS we still have nonadjusted values !! */
|
||||||
static int
|
static int CopyTrailEntries(USES_REGS1) {
|
||||||
CopyTrailEntries( USES_REGS1 )
|
|
||||||
{
|
|
||||||
CELL entry, *Entries;
|
CELL entry, *Entries;
|
||||||
|
|
||||||
Entries = (CELL *)LOCAL_TrailBase;
|
Entries = (CELL *)LOCAL_TrailBase;
|
||||||
@ -995,9 +958,7 @@ CopyTrailEntries( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* get things which are saved in the file */
|
/* get things which are saved in the file */
|
||||||
static int
|
static int get_coded(int flag, OPCODE old_ops[] USES_REGS) {
|
||||||
get_coded(int flag, OPCODE old_ops[] USES_REGS)
|
|
||||||
{
|
|
||||||
char my_end_msg[256];
|
char my_end_msg[256];
|
||||||
|
|
||||||
if (get_regs(flag PASS_REGS) < 0)
|
if (get_regs(flag PASS_REGS) < 0)
|
||||||
@ -1028,12 +989,8 @@ get_coded(int flag, OPCODE old_ops[] USES_REGS)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* restore some heap registers */
|
/* restore some heap registers */
|
||||||
static void
|
static void restore_heap_regs(USES_REGS1) {
|
||||||
restore_heap_regs( USES_REGS1 )
|
|
||||||
{
|
|
||||||
if (HeapTop) {
|
if (HeapTop) {
|
||||||
HeapTop = AddrAdjust(HeapTop);
|
HeapTop = AddrAdjust(HeapTop);
|
||||||
*((YAP_SEG_SIZE *)HeapTop) = InUseFlag;
|
*((YAP_SEG_SIZE *)HeapTop) = InUseFlag;
|
||||||
@ -1043,12 +1000,11 @@ restore_heap_regs( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* adjust abstract machine registers */
|
/* adjust abstract machine registers */
|
||||||
static void
|
static void restore_regs(int flag USES_REGS) {
|
||||||
restore_regs(int flag USES_REGS)
|
|
||||||
{
|
|
||||||
restore_heap_regs(PASS_REGS1);
|
restore_heap_regs(PASS_REGS1);
|
||||||
if (CurrentModule) {
|
if (CurrentModule) {
|
||||||
CurrentModule = AtomTermAdjust(CurrentModule);;
|
CurrentModule = AtomTermAdjust(CurrentModule);
|
||||||
|
;
|
||||||
}
|
}
|
||||||
if (flag == DO_EVERYTHING) {
|
if (flag == DO_EVERYTHING) {
|
||||||
CP = PtoOpAdjust(CP);
|
CP = PtoOpAdjust(CP);
|
||||||
@ -1065,9 +1021,7 @@ restore_regs(int flag USES_REGS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void recompute_mask(DBRef dbr) {
|
||||||
recompute_mask(DBRef dbr)
|
|
||||||
{
|
|
||||||
if (dbr->Flags & DBNoVars) {
|
if (dbr->Flags & DBNoVars) {
|
||||||
dbr->Mask = Yap_EvalMasks((Term)dbr->DBT.Entry, &(dbr->Key));
|
dbr->Mask = Yap_EvalMasks((Term)dbr->DBT.Entry, &(dbr->Key));
|
||||||
} else if (dbr->Flags & DBComplex) {
|
} else if (dbr->Flags & DBComplex) {
|
||||||
@ -1093,7 +1047,8 @@ recompute_mask(DBRef dbr)
|
|||||||
out = AbsAppl(x);
|
out = AbsAppl(x);
|
||||||
Arity = ArityOfFunctor(f);
|
Arity = ArityOfFunctor(f);
|
||||||
*x++ = (CELL)f;
|
*x++ = (CELL)f;
|
||||||
if (Arity > 3) Arity = 3;
|
if (Arity > 3)
|
||||||
|
Arity = 3;
|
||||||
}
|
}
|
||||||
for (i = 0; i < Arity; i++) {
|
for (i = 0; i < Arity; i++) {
|
||||||
register Term tw = *tp++;
|
register Term tw = *tp++;
|
||||||
@ -1126,9 +1081,7 @@ recompute_mask(DBRef dbr)
|
|||||||
* routine is very dependent on the hash function used, and it destroys the
|
* routine is very dependent on the hash function used, and it destroys the
|
||||||
* previous "hit" order
|
* previous "hit" order
|
||||||
*/
|
*/
|
||||||
static void
|
static void rehash(CELL *oldcode, int NOfE, int KindOfEntries USES_REGS) {
|
||||||
rehash(CELL *oldcode, int NOfE, int KindOfEntries USES_REGS)
|
|
||||||
{
|
|
||||||
register CELL *savep, *basep;
|
register CELL *savep, *basep;
|
||||||
CELL *oldp = oldcode;
|
CELL *oldp = oldcode;
|
||||||
int TableSize = NOfE - 1, NOfEntries;
|
int TableSize = NOfE - 1, NOfEntries;
|
||||||
@ -1193,23 +1146,14 @@ rehash(CELL *oldcode, int NOfE, int KindOfEntries USES_REGS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void RestoreFlags(UInt NFlags) {}
|
||||||
static void RestoreFlags( UInt NFlags )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "rheap.h"
|
#include "rheap.h"
|
||||||
|
|
||||||
/* restore the atom entries which are invisible for the user */
|
/* restore the atom entries which are invisible for the user */
|
||||||
static void
|
static void RestoreIOStructures(void) { Yap_InitStdStreams(); }
|
||||||
RestoreIOStructures(void)
|
|
||||||
{
|
|
||||||
Yap_InitStdStreams();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void RestoreFreeSpace(USES_REGS1) {
|
||||||
RestoreFreeSpace( USES_REGS1 )
|
|
||||||
{
|
|
||||||
#if USE_DL_MALLOC
|
#if USE_DL_MALLOC
|
||||||
Yap_av = (struct malloc_state *)AddrAdjust((ADDR)Yap_av);
|
Yap_av = (struct malloc_state *)AddrAdjust((ADDR)Yap_av);
|
||||||
Yap_RestoreDLMalloc();
|
Yap_RestoreDLMalloc();
|
||||||
@ -1255,9 +1199,7 @@ RestoreFreeSpace( USES_REGS1 )
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void RestoreAtomList(Atom atm USES_REGS) {
|
||||||
RestoreAtomList(Atom atm USES_REGS)
|
|
||||||
{
|
|
||||||
AtomEntry *at;
|
AtomEntry *at;
|
||||||
|
|
||||||
at = RepAtom(atm);
|
at = RepAtom(atm);
|
||||||
@ -1269,10 +1211,7 @@ RestoreAtomList(Atom atm USES_REGS)
|
|||||||
} while (!EndOfPAEntr(at));
|
} while (!EndOfPAEntr(at));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void RestoreHashPreds(USES_REGS1) {
|
||||||
static void
|
|
||||||
RestoreHashPreds( USES_REGS1 )
|
|
||||||
{
|
|
||||||
UInt size = PredHashTableSize;
|
UInt size = PredHashTableSize;
|
||||||
bool malloced = FALSE;
|
bool malloced = FALSE;
|
||||||
PredEntry **np;
|
PredEntry **np;
|
||||||
@ -1282,7 +1221,8 @@ RestoreHashPreds( USES_REGS1 )
|
|||||||
np = (PredEntry **)Yap_AllocAtomSpace(sizeof(PredEntry *) * size);
|
np = (PredEntry **)Yap_AllocAtomSpace(sizeof(PredEntry *) * size);
|
||||||
if (!np) {
|
if (!np) {
|
||||||
if (!(np = (PredEntry **)malloc(sizeof(PredEntry *) * size))) {
|
if (!(np = (PredEntry **)malloc(sizeof(PredEntry *) * size))) {
|
||||||
Yap_Error(SYSTEM_ERROR_FATAL,TermNil,"Could not allocate space for pred table");
|
Yap_Error(SYSTEM_ERROR_FATAL, TermNil,
|
||||||
|
"Could not allocate space for pred table");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
malloced = TRUE;
|
malloced = TRUE;
|
||||||
@ -1321,18 +1261,13 @@ RestoreHashPreds( USES_REGS1 )
|
|||||||
/*
|
/*
|
||||||
* This is the really tough part, to restore the whole of the heap
|
* This is the really tough part, to restore the whole of the heap
|
||||||
*/
|
*/
|
||||||
static void
|
static void restore_heap(void) {
|
||||||
restore_heap(void)
|
|
||||||
{
|
|
||||||
restore_codes();
|
restore_codes();
|
||||||
RestoreIOStructures();
|
RestoreIOStructures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_RESTORE3
|
#ifdef DEBUG_RESTORE3
|
||||||
static void
|
static void ShowEntries(pp) PropEntry *pp;
|
||||||
ShowEntries(pp)
|
|
||||||
PropEntry *pp;
|
|
||||||
{
|
{
|
||||||
while (!EndOfPAEntr(pp)) {
|
while (!EndOfPAEntr(pp)) {
|
||||||
fprintf(GLOBAL_stderr, "Estou a ver a prop %x em %x\n", pp->KindOfPE, pp);
|
fprintf(GLOBAL_stderr, "Estou a ver a prop %x em %x\n", pp->KindOfPE, pp);
|
||||||
@ -1340,9 +1275,7 @@ ShowEntries(pp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void ShowAtoms() {
|
||||||
ShowAtoms()
|
|
||||||
{
|
|
||||||
AtomHashEntry *HashPtr = HashChain;
|
AtomHashEntry *HashPtr = HashChain;
|
||||||
register int i;
|
register int i;
|
||||||
for (i = 0; i < AtomHashTableSize; ++i) {
|
for (i = 0; i < AtomHashTableSize; ++i) {
|
||||||
@ -1374,17 +1307,19 @@ ShowAtoms()
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static int
|
static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
|
||||||
commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap) {
|
CELL *AStack, CELL *AHeap) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
if ((mode = check_header(Astate,ATrail,AStack,AHeap PASS_REGS)) == FAIL_RESTORE)
|
if ((mode = check_header(Astate, ATrail, AStack, AHeap PASS_REGS)) ==
|
||||||
|
FAIL_RESTORE)
|
||||||
return (FAIL_RESTORE);
|
return (FAIL_RESTORE);
|
||||||
LOCAL_PrologMode = BootMode;
|
LOCAL_PrologMode = BootMode;
|
||||||
if (Yap_HeapBase) {
|
if (Yap_HeapBase) {
|
||||||
if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) {
|
if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) {
|
||||||
Yap_findFile(s, NULL, NULL, LOCAL_FileNameBuf2, true, YAP_QLY, true, true);
|
Yap_findFile(s, NULL, NULL, LOCAL_FileNameBuf2, true, YAP_QLY, true,
|
||||||
|
true);
|
||||||
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
|
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
|
||||||
}
|
}
|
||||||
Yap_CloseStreams(TRUE);
|
Yap_CloseStreams(TRUE);
|
||||||
@ -1398,7 +1333,8 @@ commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *A
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, FILE **streamp) {
|
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
|
||||||
|
CELL *AHeap, FILE **streamp) {
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
if (streamp) {
|
if (streamp) {
|
||||||
@ -1410,7 +1346,8 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *
|
|||||||
if ((splfild = open_file(inpf, O_RDONLY)) < 0) {
|
if ((splfild = open_file(inpf, O_RDONLY)) < 0) {
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
if ((mode = commit_to_saved_state(inpf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
|
if ((mode = commit_to_saved_state(inpf, Astate, ATrail, AStack, AHeap)) !=
|
||||||
|
FAIL_RESTORE) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_ErrorMessage = NULL;
|
LOCAL_ErrorMessage = NULL;
|
||||||
return mode;
|
return mode;
|
||||||
@ -1418,35 +1355,37 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate,
|
||||||
OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, FILE **streamp)
|
CELL *ATrail, CELL *AStack, CELL *AHeap,
|
||||||
{
|
FILE **streamp) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
int mode;
|
int mode;
|
||||||
char fname[YAP_FILENAME_MAX + 1];
|
char fname[YAP_FILENAME_MAX + 1];
|
||||||
|
|
||||||
if (!Yap_findFile( inpf, YAP_STARTUP, YapLibDir, fname, true, YAP_SAVED_STATE, true, true))
|
if (!Yap_findFile(inpf, YAP_STARTUP, YapLibDir, fname, true, YAP_SAVED_STATE,
|
||||||
|
true, true))
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
if (fname[0] &&
|
if (fname[0] && (mode = try_open(fname, Astate, ATrail, AStack, AHeap,
|
||||||
(mode = try_open(fname,Astate,ATrail,AStack,AHeap,streamp)) != FAIL_RESTORE) {
|
streamp)) != FAIL_RESTORE) {
|
||||||
setAtomicGlobalPrologFlag( RESOURCE_DATABASE_FLAG, MkAtomTerm(Yap_LookupAtom(fname)) );
|
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(fname)));
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
/* try to open from current directory */
|
/* try to open from current directory */
|
||||||
/* could not open file */
|
/* could not open file */
|
||||||
if (LOCAL_ErrorMessage == NULL) {
|
if (LOCAL_ErrorMessage == NULL) {
|
||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,"incorrect saved state ");
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
||||||
|
"incorrect saved state ");
|
||||||
} else {
|
} else {
|
||||||
strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX - 1);
|
strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX - 1);
|
||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,"could not open saved state");
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
||||||
|
"could not open saved state");
|
||||||
}
|
}
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *
|
FILE *Yap_OpenRestore(const char *inpf, const char *YapLibDir) {
|
||||||
Yap_OpenRestore(const char *inpf, const char *YapLibDir)
|
|
||||||
{
|
|
||||||
FILE *stream = NULL;
|
FILE *stream = NULL;
|
||||||
|
|
||||||
if (!inpf)
|
if (!inpf)
|
||||||
@ -1458,9 +1397,7 @@ Yap_OpenRestore(const char *inpf, const char *YapLibDir)
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void CloseRestore(void) {
|
||||||
CloseRestore(void)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
#ifdef DEBUG_RESTORE3
|
#ifdef DEBUG_RESTORE3
|
||||||
ShowAtoms();
|
ShowAtoms();
|
||||||
@ -1470,9 +1407,7 @@ CloseRestore(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
static int
|
static int check_opcodes(OPCODE old_ops[]) {
|
||||||
check_opcodes(OPCODE old_ops[])
|
|
||||||
{
|
|
||||||
#if USE_THREADED_CODE
|
#if USE_THREADED_CODE
|
||||||
bool have_shifted = FALSE;
|
bool have_shifted = FALSE;
|
||||||
op_numbers op = _Ystop;
|
op_numbers op = _Ystop;
|
||||||
@ -1490,11 +1425,9 @@ check_opcodes(OPCODE old_ops[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void RestoreHeap(OPCODE old_ops[] USES_REGS) {
|
||||||
RestoreHeap(OPCODE old_ops[] USES_REGS)
|
bool heap_moved = (LOCAL_OldHeapBase != Yap_HeapBase || LOCAL_XDiff),
|
||||||
{
|
opcodes_moved;
|
||||||
bool heap_moved = (LOCAL_OldHeapBase != Yap_HeapBase ||
|
|
||||||
LOCAL_XDiff), opcodes_moved;
|
|
||||||
Term mod = CurrentModule;
|
Term mod = CurrentModule;
|
||||||
|
|
||||||
CurrentModule = PROLOG_MODULE;
|
CurrentModule = PROLOG_MODULE;
|
||||||
@ -1519,10 +1452,10 @@ RestoreHeap(OPCODE old_ops[] USES_REGS)
|
|||||||
Yap_InitCPreds();
|
Yap_InitCPreds();
|
||||||
Yap_InitBackCPreds();
|
Yap_InitBackCPreds();
|
||||||
}
|
}
|
||||||
if (!(Yap_ReInitConstExps() &&
|
if (!(Yap_ReInitConstExps() && Yap_ReInitUnaryExps() &&
|
||||||
Yap_ReInitUnaryExps() &&
|
|
||||||
Yap_ReInitBinaryExps())) {
|
Yap_ReInitBinaryExps())) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "arithmetic operator not in saved state");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"arithmetic operator not in saved state");
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_RESTORE1
|
#ifdef DEBUG_RESTORE1
|
||||||
fprintf(errout, "phase 1 done\n");
|
fprintf(errout, "phase 1 done\n");
|
||||||
@ -1534,15 +1467,15 @@ RestoreHeap(OPCODE old_ops[] USES_REGS)
|
|||||||
* This function is called to know about the parameters of the last saved
|
* This function is called to know about the parameters of the last saved
|
||||||
* state
|
* state
|
||||||
*/
|
*/
|
||||||
int
|
int Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail,
|
||||||
Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
CELL *AStack, CELL *AHeap) {
|
||||||
{
|
|
||||||
return DO_ONLY_CODE;
|
return DO_ONLY_CODE;
|
||||||
|
|
||||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap, NULL);
|
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap,
|
||||||
|
NULL);
|
||||||
if (mode == FAIL_RESTORE) {
|
if (mode == FAIL_RESTORE) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1556,9 +1489,7 @@ Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail, CELL *A
|
|||||||
return (MyState);
|
return (MyState);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void UnmarkTrEntries(USES_REGS1) {
|
||||||
UnmarkTrEntries( USES_REGS1 )
|
|
||||||
{
|
|
||||||
CELL entry, *Entries;
|
CELL entry, *Entries;
|
||||||
|
|
||||||
/* initialize a choice point */
|
/* initialize a choice point */
|
||||||
@ -1603,12 +1534,10 @@ UnmarkTrEntries( USES_REGS1 )
|
|||||||
B = NULL;
|
B = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int in_limbo = FALSE;
|
int in_limbo = FALSE;
|
||||||
|
|
||||||
/* cleanup any records we had in the saved state. They are now inaccessible */
|
/* cleanup any records we had in the saved state. They are now inaccessible */
|
||||||
static void
|
static void FreeRecords(void) {
|
||||||
FreeRecords(void) {
|
|
||||||
struct record_list *ptr;
|
struct record_list *ptr;
|
||||||
|
|
||||||
ptr = Yap_Records;
|
ptr = Yap_Records;
|
||||||
@ -1625,15 +1554,14 @@ FreeRecords(void) {
|
|||||||
* This function is called when wanting only to restore the heap and
|
* This function is called when wanting only to restore the heap and
|
||||||
* associated registers
|
* associated registers
|
||||||
*/
|
*/
|
||||||
static int
|
static int Restore(char *s, char *lib_dir USES_REGS) {
|
||||||
Restore(char *s, char *lib_dir USES_REGS)
|
|
||||||
{
|
|
||||||
int restore_mode;
|
int restore_mode;
|
||||||
|
|
||||||
OPCODE old_ops[_std_top + 1];
|
OPCODE old_ops[_std_top + 1];
|
||||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||||
|
|
||||||
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack, &MyHeap, NULL)) == FAIL_RESTORE)
|
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack,
|
||||||
|
&MyHeap, NULL)) == FAIL_RESTORE)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
Yap_ShutdownLoadForeign();
|
Yap_ShutdownLoadForeign();
|
||||||
in_limbo = TRUE;
|
in_limbo = TRUE;
|
||||||
@ -1645,8 +1573,7 @@ Restore(char *s, char *lib_dir USES_REGS)
|
|||||||
RestoreHeap(old_ops PASS_REGS);
|
RestoreHeap(old_ops PASS_REGS);
|
||||||
switch (restore_mode) {
|
switch (restore_mode) {
|
||||||
case DO_EVERYTHING:
|
case DO_EVERYTHING:
|
||||||
if (LOCAL_OldHeapBase != Yap_HeapBase ||
|
if (LOCAL_OldHeapBase != Yap_HeapBase || LOCAL_OldLCL0 != LCL0 ||
|
||||||
LOCAL_OldLCL0 != LCL0 ||
|
|
||||||
LOCAL_OldGlobalBase != (CELL *)LOCAL_GlobalBase ||
|
LOCAL_OldGlobalBase != (CELL *)LOCAL_GlobalBase ||
|
||||||
LOCAL_OldTrailBase != LOCAL_TrailBase) {
|
LOCAL_OldTrailBase != LOCAL_TrailBase) {
|
||||||
Yap_AdjustStacksAndTrail();
|
Yap_AdjustStacksAndTrail();
|
||||||
@ -1685,29 +1612,27 @@ Restore(char *s, char *lib_dir USES_REGS)
|
|||||||
return restore_mode;
|
return restore_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int Yap_SavedStateRestore(char *s, char *lib_dir) {
|
||||||
Yap_SavedStateRestore(char *s, char *lib_dir)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return Restore(s, lib_dir PASS_REGS);
|
return Restore(s, lib_dir PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int p_restore(USES_REGS1) {
|
||||||
p_restore( USES_REGS1 )
|
|
||||||
{
|
|
||||||
int mode;
|
int mode;
|
||||||
char s[YAP_FILENAME_MAX + 1];
|
char s[YAP_FILENAME_MAX + 1];
|
||||||
|
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
if (GLOBAL_number_workers != 1) {
|
if (GLOBAL_number_workers != 1) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL,TermNil,"cannot perform save: more than a worker/thread running");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"cannot perform save: more than a worker/thread running");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
#ifdef THREADS
|
#ifdef THREADS
|
||||||
if (GLOBAL_NOfThreads != 1) {
|
if (GLOBAL_NOfThreads != 1) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL,TermNil,"cannot perform save: more than a worker/thread running");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"cannot perform save: more than a worker/thread running");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
#endif /* THREADS */
|
#endif /* THREADS */
|
||||||
@ -1721,9 +1646,7 @@ p_restore( USES_REGS1 )
|
|||||||
return (mode != FAIL_RESTORE);
|
return (mode != FAIL_RESTORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Yap_InitSavePreds(void) {
|
||||||
Yap_InitSavePreds(void)
|
|
||||||
{
|
|
||||||
Yap_InitCPred("$save", 2, p_save2, SyncPredFlag);
|
Yap_InitCPred("$save", 2, p_save2, SyncPredFlag);
|
||||||
Yap_InitCPred("$save_program", 1, p_save_program, SyncPredFlag);
|
Yap_InitCPred("$save_program", 1, p_save_program, SyncPredFlag);
|
||||||
Yap_InitCPred("$restore", 1, p_restore, SyncPredFlag);
|
Yap_InitCPred("$restore", 1, p_restore, SyncPredFlag);
|
||||||
|
@ -46,6 +46,9 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Yap.h"
|
||||||
|
#include "YapHeap.h"
|
||||||
|
|
||||||
#ifdef _AIX
|
#ifdef _AIX
|
||||||
#undef NO_DYN
|
#undef NO_DYN
|
||||||
#endif /* __AIX */
|
#endif /* __AIX */
|
||||||
@ -115,7 +118,6 @@ typedef struct ForeignLoadItem {
|
|||||||
|
|
||||||
typedef void (*YapInitProc)(void);
|
typedef void (*YapInitProc)(void);
|
||||||
|
|
||||||
|
|
||||||
void *Yap_LoadForeignFile(char *, int);
|
void *Yap_LoadForeignFile(char *, int);
|
||||||
int Yap_CallForeignFile(void *, char *);
|
int Yap_CallForeignFile(void *, char *);
|
||||||
int Yap_CloseForeignFile(void *);
|
int Yap_CloseForeignFile(void *);
|
||||||
|
4
H/Yap.h
4
H/Yap.h
@ -822,6 +822,8 @@ inline static void LOG0(const char *f, int l, const char *fmt, ...) {
|
|||||||
|
|
||||||
extern bool Yap_embedded, Yap_Server;
|
extern bool Yap_embedded, Yap_Server;
|
||||||
|
|
||||||
|
#include "YapText.h"
|
||||||
|
|
||||||
#endif /* YAP_H */
|
#endif /* YAP_H */
|
||||||
|
|
||||||
#include "YapText.h"
|
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
#ifndef HEAP_H
|
#ifndef HEAP_H
|
||||||
#define HEAP_H 1
|
#define HEAP_H 1
|
||||||
|
|
||||||
|
#include "Atoms.h"
|
||||||
|
#include "Yap.h"
|
||||||
|
|
||||||
#if LOW_PROF
|
#if LOW_PROF
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
12
H/rheap.h
12
H/rheap.h
@ -194,7 +194,8 @@
|
|||||||
* Revision 1.47 2004/12/02 06:06:47 vsc
|
* Revision 1.47 2004/12/02 06:06:47 vsc
|
||||||
* fix threads so that they at least start
|
* fix threads so that they at least start
|
||||||
* allow error handling to work with threads
|
* allow error handling to work with threads
|
||||||
* replace heap_base by Yap_heap_base, according to Yap's convention for globals.
|
* replace heap_base by Yap_heap_base, according to Yap's convention for
|
||||||
|
*globals.
|
||||||
*
|
*
|
||||||
* Revision 1.46 2004/11/23 21:16:21 vsc
|
* Revision 1.46 2004/11/23 21:16:21 vsc
|
||||||
* A few extra fixes for saved states.
|
* A few extra fixes for saved states.
|
||||||
@ -238,6 +239,13 @@
|
|||||||
static char SccsId[] = "@(#)rheap.c 1.3 3/15/90";
|
static char SccsId[] = "@(#)rheap.c 1.3 3/15/90";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef RHEAP_H
|
||||||
|
#define RHEAP_H 1
|
||||||
|
|
||||||
|
#include "YapHeap.h"
|
||||||
|
#include "absmi.h"
|
||||||
|
#include "clause.h"
|
||||||
|
|
||||||
#define Atomics 0
|
#define Atomics 0
|
||||||
#define Funcs 1
|
#define Funcs 1
|
||||||
|
|
||||||
@ -1495,3 +1503,5 @@ static void RestoreAtom(AtomEntry *at USES_REGS) {
|
|||||||
if (nat)
|
if (nat)
|
||||||
at->NextOfAE = AbsAtom(AtomEntryAdjust(nat));
|
at->NextOfAE = AbsAtom(AtomEntryAdjust(nat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -6,13 +6,13 @@ export MACOSX_DEPLOYMENT_TARGET=10.9
|
|||||||
export R_COMMAND=$R
|
export R_COMMAND=$R
|
||||||
export CMAKE_BUILD_TYPE=Debug
|
export CMAKE_BUILD_TYPE=Debug
|
||||||
export CMAKE=$PREFIX/bin/cmake
|
export CMAKE=$PREFIX/bin/cmake
|
||||||
export CMAKE_INCLUDE_PATH=$SYS_PREFIX/include
|
export CMAKE_INCLUDE_PATH=$PREFIX/include
|
||||||
export CMAKE_LIBRARY_PATH=$SYS_PREFIX/lib
|
export CMAKE_LIBRARY_PATH=$PREFIX/lib
|
||||||
export CMAKE_INSTALL_PREFIX=$PREFIX
|
export CMAKE_INSTALL_PREFIX=$PREFIX
|
||||||
export GENERATOR="-GNinja"
|
export GENERATOR="-GNinja"
|
||||||
export PYTHON_EXECUTABLE="$PYTHON"
|
export PYTHON_EXECUTABLE="$PYTHON"
|
||||||
export PYTHON_LIBRARY="$STDLIB_DIR/../libPython${PY_VER}m$SHLIB_EXT"
|
export PYTHON_LIBRARY="$CMAKE_LIBRARY_PATH/libpython${PY_VER}m$SHLIB_EXT"
|
||||||
export PYTHON_INCLUDE_DIR="$STDLIB_DIR/../../include/python$PY_VER"m
|
export PYTHON_INCLUDE_DIR="$CMAKE_INCLUDE_PATH/python$PY_VER"m
|
||||||
|
|
||||||
mkdir $PREFIX/conda
|
mkdir $PREFIX/conda
|
||||||
cd $PREFIX/conda
|
cd $PREFIX/conda
|
||||||
@ -27,7 +27,7 @@ cd $PREFIX/conda
|
|||||||
-DPYTHON_INCLUDE_DIR:PATH="$PYTHON_INCLUDE_DIR" \
|
-DPYTHON_INCLUDE_DIR:PATH="$PYTHON_INCLUDE_DIR" \
|
||||||
$RECIPE_DIR/..
|
$RECIPE_DIR/..
|
||||||
|
|
||||||
make -j install CMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX"
|
make install CMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX"
|
||||||
|
|
||||||
# Remove the created lib64 directory
|
# Remove the created lib64 directory
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ requirements:
|
|||||||
- r
|
- r
|
||||||
- notebook
|
- notebook
|
||||||
run:
|
run:
|
||||||
|
- python
|
||||||
|
- pythonlab
|
||||||
- readline
|
- readline
|
||||||
- gmp
|
- gmp
|
||||||
- r
|
- r
|
||||||
|
@ -134,7 +134,7 @@ static YAP_Bool compute_prob(void)
|
|||||||
expr expression;
|
expr expression;
|
||||||
DdNode * function;
|
DdNode * function;
|
||||||
DdManager * mgr;
|
DdManager * mgr;
|
||||||
int nBVar,i,intBits,create_dot;
|
int nBVar,i,create_dot;
|
||||||
FILE * file;
|
FILE * file;
|
||||||
DdNode * array[1];
|
DdNode * array[1];
|
||||||
double prob;
|
double prob;
|
||||||
@ -184,11 +184,10 @@ static YAP_Bool compute_prob(void)
|
|||||||
array[0]=function;
|
array[0]=function;
|
||||||
onames[0]="Out";
|
onames[0]="Out";
|
||||||
file = open_file("cpl.dot", "w");
|
file = open_file("cpl.dot", "w");
|
||||||
Cudd_DumpDot(mgr,1,array,names,onames,file);
|
Cudd_DumpDot(mgr,1,array,names,( char * const*)onames,file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
nodes=init_table(vars.nBVar);
|
nodes=init_table(vars.nBVar);
|
||||||
intBits=sizeof(unsigned int)*8;
|
|
||||||
prob=Prob(function,vars,nodes);
|
prob=Prob(function,vars,nodes);
|
||||||
out=YAP_MkFloatTerm(prob);
|
out=YAP_MkFloatTerm(prob);
|
||||||
destroy_table(nodes,vars.nBVar);
|
destroy_table(nodes,vars.nBVar);
|
||||||
|
@ -24,9 +24,8 @@ PROPERTIES VERSION ${YAP_FULL_VERSION}
|
|||||||
SOVERSION ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION}
|
SOVERSION ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES})
|
|
||||||
|
|
||||||
# arithmetic hassle.
|
# arithmetic hassle.
|
||||||
|
target_link_libraries(Py4YAP YAPPython libYap ${PYTHON_LIBRARIES})
|
||||||
|
|
||||||
|
|
||||||
install(TARGETS Py4YAP
|
install(TARGETS Py4YAP
|
||||||
@ -36,16 +35,9 @@ install(TARGETS Py4YAP
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
install(TARGETS YAPPython
|
|
||||||
LIBRARY DESTINATION ${dlls}
|
|
||||||
RUNTIME DESTINATION ${dlls}
|
|
||||||
ARCHIVE DESTINATION ${dlls} )
|
|
||||||
|
|
||||||
target_link_libraries( YAPPython Py4YAP )
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(YAPPython libYap ${PYTHON_LIBRARIES})
|
target_link_libraries(YAPPython libYap)
|
||||||
|
|
||||||
# arithmetic hassle.
|
# arithmetic hassle.
|
||||||
set_property(TARGET YAPPython PROPERTY CXX_STANDARD_REQUIRED ON)
|
set_property(TARGET YAPPython PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||||
|
@ -271,21 +271,18 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
|||||||
if (PL_skip_list(t, tail, &len) &&
|
if (PL_skip_list(t, tail, &len) &&
|
||||||
PL_get_nil(tail)) { // true list
|
PL_get_nil(tail)) { // true list
|
||||||
|
|
||||||
bool o = true;
|
|
||||||
if (PySequence_Check(exp) && PySequence_Length(exp) == len)
|
if (PySequence_Check(exp) && PySequence_Length(exp) == len)
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
PyObject *p;
|
PyObject *p;
|
||||||
if (!PL_get_list(t, arg, t)) {
|
if (!PL_get_list(t, arg, t)) {
|
||||||
PL_reset_term_refs(tail);
|
PL_reset_term_refs(tail);
|
||||||
o = false;
|
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
}
|
}
|
||||||
if ((p = PySequence_GetItem(exp, i)) == NULL)
|
if ((p = PySequence_GetItem(exp, i)) == NULL)
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
if (!python_assign(arg, p, context)) {
|
if (!python_assign(arg, p, context)) {
|
||||||
PL_reset_term_refs(tail);
|
PL_reset_term_refs(tail);
|
||||||
o = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ configure_file("MANIFEST.in" ${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in)
|
|||||||
configure_file("YAP4PY.md" README.md)
|
configure_file("YAP4PY.md" README.md)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/include
|
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/include
|
||||||
DEPENDS ${SWIG_SOURCES} YAP++
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -43,7 +42,9 @@ INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/i
|
|||||||
# LIBRARY DESTINATION ${PYTHON_MODULE_PATH}
|
# LIBRARY DESTINATION ${PYTHON_MODULE_PATH}
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/yap4py)
|
||||||
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (CONDA)
|
if (CONDA)
|
||||||
set(bdist bdist_conda)
|
set(bdist bdist_conda)
|
||||||
|
Reference in New Issue
Block a user