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