diff --git a/C/qlyr.c b/C/qlyr.c index 850ab4172..d92c87af1 100755 --- a/C/qlyr.c +++ b/C/qlyr.c @@ -1,20 +1,20 @@ /************************************************************************* -* * -* YAP Prolog * -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- * -* * -************************************************************************** -* * -* File: qlyr.c * -* comments: quick saver/loader * -* * -* Last rev: $Date: 2011-08-29$,$Author: vsc $ * -* $Log: not supported by cvs2svn $ * -* * -*************************************************************************/ + * * + * YAP Prolog * + * * + * Yap Prolog was developed at NCCUP - Universidade do Porto * + * * + * Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- * + * * + ************************************************************************** + * * + * File: qlyr.c * + * comments: quick saver/loader * + * * + * Last rev: $Date: 2011-08-29$,$Author: vsc $ * + * $Log: not supported by cvs2svn $ * + * * + *************************************************************************/ /** * * @file 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:-")) @@ -696,7 +696,7 @@ static void ReadHash(FILE *stream) { Atom at; qlf_tag_t tg = read_tag(stream); - if (tg == QLY_ATOM) { + if (tg == QLY_ATOM) { char *rep = (char *)AllocTempSpace(); UInt len; diff --git a/C/qlyw.c b/C/qlyw.c index ebe2bfd0f..66665d3a0 100755 --- a/C/qlyw.c +++ b/C/qlyw.c @@ -1,20 +1,20 @@ /************************************************************************* -* * -* YAP Prolog * -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- * -* * -************************************************************************** -* * -* File: qlyw.c * -* comments: quick saver/loader * -* * -* Last rev: $Date: 2011-08-29$,$Author: vsc $ * -* $Log: not supported by cvs2svn $ * -* * -*************************************************************************/ + * * + * YAP Prolog * + * * + * Yap Prolog was developed at NCCUP - Universidade do Porto * + * * + * Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- * + * * + ************************************************************************** + * * + * File: qlyw.c * + * comments: quick saver/loader * + * * + * Last rev: $Date: 2011-08-29$,$Author: vsc $ * + * $Log: not supported by cvs2svn $ * + * * + *************************************************************************/ /** * @@ -25,49 +25,49 @@ * */ -#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 #endif #include "qly.h" -static void RestoreEntries(PropEntry *, int USES_REGS); -static void CleanCode(PredEntry * USES_REGS); +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; } p = oldt; - for (i = 0 ; i < size ; p++,i++) { + for (i = 0; i < size; p++, i++) { Atom a = p->val; export_atom_hash_entry_t *newp; 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; + hash = HashFunction(apt) / (2 * sizeof(CELL)) % new_size; + newp = newt + hash; while (newp->val) { newp++; - if (newp == newt+new_size) - newp = newt; + if (newp == newt + new_size) + newp = newt; } newp->val = a; } @@ -76,29 +76,24 @@ 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; export_atom_hash_entry_t *a; - a = LOCAL_ExportAtomHashChain+hash; + a = LOCAL_ExportAtomHashChain + hash; while (a->val) { if (a->val == at) { return; } a++; - if (a == LOCAL_ExportAtomHashChain+LOCAL_ExportAtomHashTableSize) + 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,31 +101,32 @@ 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; } p = oldt; - for (i = 0 ; i < size ; p++,i++) { + for (i = 0; i < size; p++, i++) { Functor f = p->val; export_functor_hash_entry_t *newp; CELL hash; - if (!f) continue; - hash = ((CELL)(f))/(2*sizeof(CELL)) % new_size; - newp = newt+hash; + if (!f) + continue; + hash = ((CELL)(f)) / (2 * sizeof(CELL)) % new_size; + newp = newt + hash; while (newp->val) { newp++; - if (newp == newt+new_size) - newp = newt; + if (newp == newt + new_size) + newp = newt; } newp->val = p->val; newp->arity = p->arity; @@ -141,22 +137,21 @@ 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); + UInt arity = ArityOfFunctor(fun); - f = LOCAL_ExportFunctorHashChain+hash; + f = LOCAL_ExportFunctorHashChain + hash; while (f->val) { if (f->val == fun) { return; } f++; - if (f == LOCAL_ExportFunctorHashChain+LOCAL_ExportFunctorHashTableSize) + if (f == LOCAL_ExportFunctorHashChain + LOCAL_ExportFunctorHashTableSize) f = LOCAL_ExportFunctorHashChain; } LookupAtom(name); @@ -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,31 +167,33 @@ 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; } p = oldt; - for (i = 0 ; i < size ; p++,i++) { + for (i = 0; i < size; p++, i++) { PredEntry *pe = p->val; export_pred_entry_hash_entry_t *newp; CELL hash; - if (!pe) continue; - hash = ((CELL)(pe))/(2*sizeof(CELL)) % new_size; - newp = newt+hash; + if (!pe) + continue; + hash = ((CELL)(pe)) / (2 * sizeof(CELL)) % new_size; + newp = newt + hash; while (newp->val) { newp++; - if (newp == newt+new_size) - newp = newt; + if (newp == newt + new_size) + newp = newt; } newp->val = p->val; newp->arity = p->arity; @@ -210,21 +205,21 @@ 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; + UInt arity = pe->ArityOfPE; - p = LOCAL_ExportPredEntryHashChain+hash; + p = LOCAL_ExportPredEntryHashChain + hash; while (p->val) { if (p->val == 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,32 +261,32 @@ 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; } p = oldt; - for (i = 0 ; i < size ; p++,i++) { + for (i = 0; i < size; p++, i++) { DBRef dbr = p->val; export_dbref_hash_entry_t *newp; CELL hash; - if (!dbr) continue; - hash = ((CELL)(dbr))/(2*sizeof(CELL)) % new_size; - newp = newt+hash; + if (!dbr) + continue; + hash = ((CELL)(dbr)) / (2 * sizeof(CELL)) % new_size; + newp = newt + hash; while (newp->val) { newp++; - if (newp == newt+new_size) - newp = newt; + if (newp == newt + new_size) + newp = newt; } newp->val = p->val; newp->sz = p->sz; @@ -303,30 +297,27 @@ 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; + a = LOCAL_ExportDBRefHashChain + hash; while (a->val) { if (a->val == ref) { a->refs++; return; } a++; - if (a == LOCAL_ExportDBRefHashChain+LOCAL_ExportDBRefHashTableSize) + if (a == LOCAL_ExportDBRefHashChain + LOCAL_ExportDBRefHashTableSize) a = LOCAL_ExportDBRefHashChain; } a->val = 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 @@ -420,7 +402,7 @@ TermToGlobalOrAtomAdjust(Term t) #define NoAGCAtomAdjust(P) (P) #define OrArgAdjust(P) #define TabEntryAdjust(P) -#define IntegerAdjust(D) (D) +#define IntegerAdjust(D) (D) #define AddrAdjust(P) (P) #define MFileAdjust(P) (P) #define CodeVarAdjust(P) (P) @@ -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) @@ -468,10 +444,8 @@ PtoPredAdjust(PredEntry *pe) #define DelayAdjust(P) (P) #define GlobalAdjust(P) (P) -#define DBRefAdjust(P,DoRef) DBRefAdjust__(P PASS_REGS) -static inline DBRef -DBRefAdjust__ (DBRef dbt USES_REGS) -{ +#define DBRefAdjust(P, DoRef) DBRefAdjust__(P PASS_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 */ @@ -582,25 +537,26 @@ SaveHash(FILE *stream) save_UInt(stream, (UInt)&ARG1); CHECK(save_tag(stream, QLY_START_OPCODES)); save_Int(stream, _std_top); - for (i= 0; i <= _std_top; i++) { + for (i = 0; i <= _std_top; i++) { save_UInt(stream, (UInt)Yap_opcode(i)); } CHECK(save_tag(stream, QLY_START_ATOMS)); CHECK(save_UInt(stream, LOCAL_ExportAtomHashTableNum)); for (i = 0; i < LOCAL_ExportAtomHashTableSize; i++) { - export_atom_hash_entry_t *a = LOCAL_ExportAtomHashChain+i; + export_atom_hash_entry_t *a = LOCAL_ExportAtomHashChain + i; if (a->val) { Atom at = a->val; 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_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))); } } save_tag(stream, QLY_START_FUNCTORS); save_UInt(stream, LOCAL_ExportFunctorHashTableNum); for (i = 0; i < LOCAL_ExportFunctorHashTableSize; i++) { - export_functor_hash_entry_t *f = LOCAL_ExportFunctorHashChain+i; + export_functor_hash_entry_t *f = LOCAL_ExportFunctorHashChain + i; if (!(f->val)) continue; CHECK(save_UInt(stream, (UInt)(f->val))); @@ -610,7 +566,7 @@ SaveHash(FILE *stream) save_tag(stream, QLY_START_PRED_ENTRIES); save_UInt(stream, LOCAL_ExportPredEntryHashTableNum); for (i = 0; i < LOCAL_ExportPredEntryHashTableSize; i++) { - export_pred_entry_hash_entry_t *p = LOCAL_ExportPredEntryHashChain+i; + export_pred_entry_hash_entry_t *p = LOCAL_ExportPredEntryHashChain + i; if (!(p->val)) continue; CHECK(save_UInt(stream, (UInt)(p->val))); @@ -621,7 +577,7 @@ SaveHash(FILE *stream) save_tag(stream, QLY_START_DBREFS); save_UInt(stream, LOCAL_ExportDBRefHashTableNum); for (i = 0; i < LOCAL_ExportDBRefHashTableSize; i++) { - export_dbref_hash_entry_t *p = LOCAL_ExportDBRefHashChain+i; + export_dbref_hash_entry_t *p = LOCAL_ExportDBRefHashChain + i; if (p->val) { CHECK(save_UInt(stream, (UInt)(p->val))); CHECK(save_UInt(stream, p->sz)); @@ -633,9 +589,8 @@ SaveHash(FILE *stream) return 1; } -static size_t -save_clauses(FILE *stream, PredEntry *pp) { - yamop *FirstC, *LastC; +static size_t save_clauses(FILE *stream, PredEntry *pp) { + yamop *FirstC, *LastC; FirstC = pp->cs.p_code.FirstClause; LastC = pp->cs.p_code.LastClause; @@ -647,11 +602,11 @@ save_clauses(FILE *stream, PredEntry *pp) { while (cl != NULL) { if (IN_BETWEEN(cl->ClTimeStart, pp->TimeStampOfPred, cl->ClTimeEnd)) { - UInt size = cl->ClSize; - CHECK(save_tag(stream, QLY_START_LU_CLAUSE)); - CHECK(save_UInt(stream, (UInt)cl)); - CHECK(save_UInt(stream, size)); - CHECK(save_bytes(stream, cl, size)); + UInt size = cl->ClSize; + CHECK(save_tag(stream, QLY_START_LU_CLAUSE)); + CHECK(save_UInt(stream, (UInt)cl)); + CHECK(save_UInt(stream, size)); + CHECK(save_bytes(stream, cl, size)); } cl = cl->ClNext; } @@ -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) { @@ -735,7 +689,7 @@ mark_pred(PredEntry *ap) FuncAdjust(ap->FunctorOfPred); } } - if (!(ap->PredFlags & (MultiFileFlag|NumberDBPredFlag)) && + if (!(ap->PredFlags & (MultiFileFlag | NumberDBPredFlag)) && ap->src.OwnerFile) { AtomAdjust(ap->src.OwnerFile); } @@ -743,22 +697,20 @@ 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) { AtomAdjust(op->OpName); if (op->OpModule) - AtomTermAdjust(op->OpModule); + AtomTermAdjust(op->OpModule); } op = op->OpNext; } 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,19 +727,19 @@ 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); - return save_bytes(stream, msg, strlen(msg)+1); + 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," ); + save_header(stream, "saved module,"); InitHash(); ModuleAdjust(mod); while (ap) { @@ -813,12 +765,11 @@ 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(); - save_header( stream, "saved state," ); + save_header(stream, "saved state,"); /* should we allow the user to see hidden predicates? */ while (me) { PredEntry *pp; @@ -826,7 +777,7 @@ save_program(FILE *stream) { AtomAdjust(me->AtomOfME); while (pp != NULL) { #if DEBUG - // Yap_PrintPredName( pp ); +// Yap_PrintPredName( pp ); #endif pp = PredEntryAdjust(pp); CHECK(mark_pred(pp)); @@ -858,12 +809,11 @@ 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(); - save_header( stream, "saved file," ); + save_header(stream, "saved file,"); /* should we allow the user to see hidden predicates? */ while (me) { PredEntry *pp; @@ -872,10 +822,10 @@ 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) { - CHECK(mark_pred(pp)); + !(pp->PredFlags & (MultiFileFlag | NumberDBPredFlag | AtomDBPredFlag | + CPredFlag | AsmPredFlag | UserCPredFlag)) && + pp->ModuleOfPred != IDB_MODULE && pp->src.OwnerFile == FileName) { + CHECK(mark_pred(pp)); } pp = pp->NextPredOfModule; } @@ -893,10 +843,11 @@ 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->src.OwnerFile == FileName) { - CHECK(save_tag(stream, QLY_START_PREDICATE)); - CHECK(save_pred(stream, pp)); + !(pp->PredFlags & (MultiFileFlag | NumberDBPredFlag | AtomDBPredFlag | + CPredFlag | AsmPredFlag | UserCPredFlag)) && + pp->src.OwnerFile == FileName) { + CHECK(save_tag(stream, QLY_START_PREDICATE)); + CHECK(save_pred(stream, pp)); } pp = pp->NextPredOfModule; } @@ -909,78 +860,72 @@ 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); if (IsVarTerm(t1)) { - Yap_Error(INSTANTIATION_ERROR,t1,"save_module/3"); + Yap_Error(INSTANTIATION_ERROR, t1, "save_module/3"); return FALSE; } if (!IsAtomTerm(t1)) { - Yap_Error(TYPE_ERROR_ATOM,t1,"save_module/3"); - return(FALSE); + Yap_Error(TYPE_ERROR_ATOM, t1, "save_module/3"); + return (FALSE); } - if (!(stream = Yap_GetOutputStream(t1, "save_module") )){ + if (!(stream = Yap_GetOutputStream(t1, "save_module"))) { return FALSE; } if (IsVarTerm(tmod)) { - Yap_Error(INSTANTIATION_ERROR,tmod,"save_module/2"); + Yap_Error(INSTANTIATION_ERROR, tmod, "save_module/2"); return FALSE; } if (!IsAtomTerm(tmod)) { - Yap_Error(TYPE_ERROR_ATOM,tmod,"save_module/2"); + Yap_Error(TYPE_ERROR_ATOM, tmod, "save_module/2"); return FALSE; } return save_module(stream, tmod) != 0; } -static Int -qsave_program( USES_REGS1 ) -{ +static Int qsave_program(USES_REGS1) { FILE *stream; Term t1 = Deref(ARG1); - if (!(stream = Yap_GetOutputStream(t1,"save_program")) ) { + if (!(stream = Yap_GetOutputStream(t1, "save_program"))) { return FALSE; } 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); - if (!(stream = Yap_GetOutputStream(t1, "save_file/2") ) ) { + if (!(stream = Yap_GetOutputStream(t1, "save_file/2"))) { return FALSE; } if (IsVarTerm(tfile)) { - Yap_Error(INSTANTIATION_ERROR,tfile,"save_file/2"); + Yap_Error(INSTANTIATION_ERROR, tfile, "save_file/2"); return FALSE; } if (!IsAtomTerm(tfile)) { - Yap_Error(TYPE_ERROR_ATOM,tfile,"save_file/2"); + Yap_Error(TYPE_ERROR_ATOM, tfile, "save_file/2"); return FALSE; } - return save_file(stream, AtomOfTerm(tfile) ) != 0; + 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(); } } /// @} - - diff --git a/C/save.c b/C/save.c index 08d89722e..3735b825f 100755 --- a/C/save.c +++ b/C/save.c @@ -8,14 +8,13 @@ * * ************************************************************************** * * - * 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 -static char SccsId[] = "@(#)save.c 1.3 3/15/90"; +static char SccsId[] = "@(#)save.c 1.3 3/15/90"; #endif #include "absmi.h" @@ -24,24 +23,24 @@ static char SccsId[] = "@(#)save.c 1.3 3/15/90"; #if HAVE_WINSOCK2_H #include #endif -#include #include +#include #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 #endif #if !HAVE_STRNCAT -#define strncat(X,Y,Z) strcat(X,Y) +#define strncat(X, Y, Z) strcat(X, Y) #endif #if !HAVE_STRNCPY -#define strncpy(X,Y,Z) strcpy(X,Y) +#define strncpy(X, Y, Z) strcpy(X, Y) #endif #if HAVE_FCNTL_H @@ -60,7 +59,7 @@ static char SccsId[] = "@(#)save.c 1.3 3/15/90"; /********* hack for accesing several kinds of terms. Should be cleaned **/ -static char end_msg[256] ="*** End of YAP saved state *****"; +static char end_msg[256] = "*** End of YAP saved state *****"; /* SWI IO, must be restarted after restore */ void initIO(void); @@ -86,56 +85,57 @@ void initIO(void); #endif -static int myread(FILE *, char *, Int); -static Int mywrite(FILE *, char *, Int); +static int myread(FILE *, char *, Int); +static Int mywrite(FILE *, char *, Int); static FILE *open_file(char *, int); -static int close_file(void); -static Int putout(CELL); -static Int putcellptr(CELL *); -static CELL get_cell(void); -static CELL *get_cellptr( /* CELL * */ void); -static int put_info(int, int CACHE_TYPE); -static int save_regs(int CACHE_TYPE); -static int save_code_info(void); -static int save_heap(void); -static int save_stacks(int CACHE_TYPE); -static int save_crc(void); -static Int do_save(int CACHE_TYPE); -static Int p_save2( CACHE_TYPE1 ); -static Int p_save_program( CACHE_TYPE1 ); -static int check_header(CELL *, CELL *, CELL *, CELL * CACHE_TYPE); -static int get_heap_info(CACHE_TYPE1); -static int get_regs(int CACHE_TYPE); -static int get_insts(OPCODE []); -static int get_hash(void); -static int CopyCode( CACHE_TYPE1 ); -static int CopyStacks( CACHE_TYPE1 ); -static int get_coded(int, OPCODE [] CACHE_TYPE); -static void restore_codes(void); -static void RestoreDB(DBEntry * CACHE_TYPE); -static void RestoreDBTerm(DBTerm *, bool, int CACHE_TYPE); -static void CleanClauses(yamop *First, yamop *Last, PredEntry *pp USES_REGS); -static void rehash(CELL *, int, int CACHE_TYPE); -static void CleanCode(PredEntry * CACHE_TYPE); -static void RestoreEntries(PropEntry *, int CACHE_TYPE); -static void RestoreFreeSpace( CACHE_TYPE1 ); -static void restore_heap(void); +static int close_file(void); +static Int putout(CELL); +static Int putcellptr(CELL *); +static CELL get_cell(void); +static CELL *get_cellptr(/* CELL * */ void); +static int put_info(int, int CACHE_TYPE); +static int save_regs(int CACHE_TYPE); +static int save_code_info(void); +static int save_heap(void); +static int save_stacks(int CACHE_TYPE); +static int save_crc(void); +static Int do_save(int CACHE_TYPE); +static Int p_save2(CACHE_TYPE1); +static Int p_save_program(CACHE_TYPE1); +static int check_header(CELL *, CELL *, CELL *, CELL *CACHE_TYPE); +static int get_heap_info(CACHE_TYPE1); +static int get_regs(int CACHE_TYPE); +static int get_insts(OPCODE[]); +static int get_hash(void); +static int CopyCode(CACHE_TYPE1); +static int CopyStacks(CACHE_TYPE1); +static int get_coded(int, OPCODE[] CACHE_TYPE); +static void restore_codes(void); +static void RestoreDB(DBEntry *CACHE_TYPE); +static void RestoreDBTerm(DBTerm *, bool, int CACHE_TYPE); +static void CleanClauses(yamop *First, yamop *Last, PredEntry *pp USES_REGS); +static void rehash(CELL *, int, int CACHE_TYPE); +static void CleanCode(PredEntry *CACHE_TYPE); +static void RestoreEntries(PropEntry *, int CACHE_TYPE); +static void RestoreFreeSpace(CACHE_TYPE1); +static void restore_heap(void); #ifdef DEBUG_RESTORE3 -static void ShowAtoms(void); -static void ShowEntries(PropEntry *); +static void ShowAtoms(void); +static void ShowEntries(PropEntry *); #endif -static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *, CELL *, FILE **); -static void CloseRestore(void); +static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *, + CELL *, FILE **); +static void CloseRestore(void); #ifndef _WIN32 -static int check_opcodes(OPCODE []); +static int check_opcodes(OPCODE[]); #endif -static void RestoreHeap(OPCODE [] CACHE_TYPE); -static Int p_restore( CACHE_TYPE1 ); -static void restore_heap_regs( CACHE_TYPE1 ); -static void restore_regs(int CACHE_TYPE); +static void RestoreHeap(OPCODE[] CACHE_TYPE); +static Int p_restore(CACHE_TYPE1); +static void restore_heap_regs(CACHE_TYPE1); +static void restore_regs(int CACHE_TYPE); #ifdef MACYAP static void NewFileInfo(long, long); -extern int DefVol; +extern int DefVol; #endif #ifdef _WIN32 @@ -146,52 +146,48 @@ extern int DefVol; #ifdef LIGHT -#include #include +#include -void -LightBug(char *); +void LightBug(char *); -static void -LightBug(s) - char *s; -{ -} +static void LightBug(s) char *s; +{} -#endif /* LIGHT */ +#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); + 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; @@ -215,37 +210,33 @@ mywrite(FILE *fd, char *buff, Int len) { return len; } -#define FullSaved 1 +#define FullSaved 1 /* Where the code was before */ - - -typedef CELL *CELLPOINTER; +typedef CELL *CELLPOINTER; static FILE *splfild = NULL; #ifdef DEBUG #ifdef DEBUG_RESTORE4 -static FILE *errout; +static FILE *errout; #else #define errout GLOBAL_stderr #endif -#endif /* DEBUG */ +#endif /* DEBUG */ -static Int OldHeapUsed; +static Int OldHeapUsed; -static CELL which_save; +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; + int i = 0; if (flag & O_RDONLY) { flags[i++] = 'r'; @@ -265,57 +256,47 @@ open_file(char *my_file, int flag) } #endif flags[i] = '\0'; - splfild = fopen( my_file, flags); + splfild = fopen(my_file, flags); #ifdef undf0 fprintf(errout, "Opened file %s\n", my_file); #endif 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) -{ - return mywrite(splfild, (char *) &l, sizeof(CELLPOINTER)); +static Int putcellptr(CELL *l) { + return mywrite(splfild, (char *)&l, sizeof(CELLPOINTER)); } /* gets a cell from a file */ -static CELL -get_cell(void) -{ - CELL l; - myread(splfild, (char *) &l, Unsigned(sizeof(CELL))); +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"); + 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"); return 0L; } count += n; @@ -324,12 +305,10 @@ get_header_cell(void) } /* gets a pointer to cell from a file */ -static CELL * -get_cellptr(void) -{ - CELL *l; +static CELL *get_cellptr(void) { + CELL *l; - if (myread(splfild, (char *) &l, Unsigned(sizeof(CELLPOINTER))) < 0) + if (myread(splfild, (char *)&l, Unsigned(sizeof(CELLPOINTER))) < 0) return NULL; return (l); } @@ -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) @@ -353,19 +333,19 @@ put_info(int info, int mode USES_REGS) return -1; /* current state of stacks, to be used by SavedInfo */ /* space available in heap area */ - if (putout(Unsigned(LOCAL_GlobalBase)-Unsigned(Yap_HeapBase)) < 0) + if (putout(Unsigned(LOCAL_GlobalBase) - Unsigned(Yap_HeapBase)) < 0) return -1; /* space available for stacks */ - if (putout(Unsigned(LOCAL_LocalBase)-Unsigned(LOCAL_GlobalBase)) < 0) + if (putout(Unsigned(LOCAL_LocalBase) - Unsigned(LOCAL_GlobalBase)) < 0) return -1; /* space available for trail */ - if (putout(Unsigned(LOCAL_TrailTop)-Unsigned(LOCAL_TrailBase)) < 0) + if (putout(Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase)) < 0) return -1; /* Space used in heap area */ - if (putout(Unsigned(HeapTop)-Unsigned(Yap_HeapBase)) < 0) + if (putout(Unsigned(HeapTop) - Unsigned(Yap_HeapBase)) < 0) return -1; /* Space used for local stack */ - if (putout(Unsigned(LCL0)-Unsigned(ASP)) < 0) + if (putout(Unsigned(LCL0) - Unsigned(ASP)) < 0) return -1; /* Space used for global stack */ if (putout(Unsigned(HR) - Unsigned(LOCAL_GlobalBase)) < 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; @@ -429,7 +407,7 @@ save_regs(int mode USES_REGS) if (putout(LOCAL_WokenGoals) < 0) return -1; #endif -#ifdef DEPTH_LIMIT +#ifdef DEPTH_LIMIT if (putout(DEPTH) < 0) return -1; #endif @@ -475,7 +453,7 @@ save_regs(int mode USES_REGS) return -1; if (which_save == 2) { if (putout(ARG2) < 0) - return -1; + return -1; } if (putcellptr(CellPtr(LOCAL_TrailBase)) < 0) return -1; @@ -483,29 +461,26 @@ save_regs(int mode USES_REGS) return 0; } -static int -save_code_info(void) -{ +static int save_code_info(void) { /* First the instructions */ { op_numbers i; - OPCODE my_ops[_std_top+1]; + OPCODE my_ops[_std_top + 1]; for (i = _Ystop; i <= _std_top; ++i) my_ops[i] = Yap_opcode(i); - if (mywrite(splfild, (char *)my_ops, sizeof(OPCODE)*(_std_top+1)) < 0) + if (mywrite(splfild, (char *)my_ops, sizeof(OPCODE) * (_std_top + 1)) < 0) 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 @@ -514,14 +489,12 @@ save_heap(void) Yap_ResetConsultStack(); j = Unsigned(HeapTop) - Unsigned(Yap_HeapBase); /* store 10 more cells because of the memory manager */ - if (mywrite(splfild, (char *) Yap_HeapBase, j) < 0) + if (mywrite(splfild, (char *)Yap_HeapBase, j) < 0) return -1; return 0; } -static int -save_stacks(int mode USES_REGS) -{ +static int save_stacks(int mode USES_REGS) { int j; switch (mode) { @@ -529,38 +502,37 @@ save_stacks(int mode USES_REGS) /* Now, go and save the state */ /* Save the local stack */ j = Unsigned(LCL0) - Unsigned(ASP); - if (mywrite(splfild, (char *) ASP, j) < 0) + if (mywrite(splfild, (char *)ASP, j) < 0) return -1; /* Save the global stack */ j = Unsigned(HR) - Unsigned(LOCAL_GlobalBase); - if (mywrite(splfild, (char *) LOCAL_GlobalBase, j) < 0) + if (mywrite(splfild, (char *)LOCAL_GlobalBase, j) < 0) return -1; /* Save the trail */ j = Unsigned(TR) - Unsigned(LOCAL_TrailBase); - if (mywrite(splfild, (char *) LOCAL_TrailBase, j) < 0) + if (mywrite(splfild, (char *)LOCAL_TrailBase, j) < 0) return -1; break; - case DO_ONLY_CODE: - { - tr_fr_ptr tr_ptr = TR; - while (tr_ptr != (tr_fr_ptr)LOCAL_TrailBase) { - CELL val = TrailTerm(tr_ptr-1); - if (IsVarTerm(val)) { - CELL *d1 = VarOfTerm(val); - if (d1 < (CELL *)HeapTop) { - if (putout(val) < 0) - return -1; - } - } else if (IsPairTerm(val)) { - CELL *d1 = RepPair(val); - if (d1 < (CELL *)HeapTop) { - if (putout(val) < 0) - return -1; - } - } - tr_ptr--; + case DO_ONLY_CODE: { + tr_fr_ptr tr_ptr = TR; + while (tr_ptr != (tr_fr_ptr)LOCAL_TrailBase) { + CELL val = TrailTerm(tr_ptr - 1); + if (IsVarTerm(val)) { + CELL *d1 = VarOfTerm(val); + if (d1 < (CELL *)HeapTop) { + if (putout(val) < 0) + return -1; + } + } else if (IsPairTerm(val)) { + CELL *d1 = RepPair(val); + if (d1 < (CELL *)HeapTop) { + if (putout(val) < 0) + return -1; + } } + tr_ptr--; } + } if (putcellptr(NULL) < 0) return -1; break; @@ -568,31 +540,31 @@ 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)) { - Yap_Error(TYPE_ERROR_LIST,t1,"save/1"); + Yap_Error(TYPE_ERROR_LIST, t1, "save/1"); return FALSE; } Yap_CloseStreams(TRUE); if ((splfild = open_file(LOCAL_FileNameBuf, O_WRONLY | O_CREAT)) < 0) { - Yap_Error(SYSTEM_ERROR_INTERNAL,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)), - "restore/1, open(%s)", strerror(errno)); - return(FALSE); + Yap_Error(SYSTEM_ERROR_INTERNAL, + MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)), + "restore/1, open(%s)", strerror(errno)); + return (FALSE); } if (put_info(FullSaved, mode PASS_REGS) < 0) return -1; @@ -611,31 +583,29 @@ 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(); Term t; #ifdef YAPOR if (GLOBAL_number_workers != 1) { - Yap_Error(SYSTEM_ERROR_INTERNAL,TermNil, - "cannot perform save: more than a worker/thread running"); - return(FALSE); + 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"); - return(FALSE); + Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, + "cannot perform save: more than a worker/thread running"); + return (FALSE); } #endif /* THREADS */ /* avoid double saves */ if (IsNonVarTerm(t = Deref(ARG2))) return TRUE; - if (!Yap_unify(ARG2,MkIntTerm(1))) + if (!Yap_unify(ARG2, MkIntTerm(1))) return FALSE; which_save = 2; 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); @@ -677,17 +645,20 @@ 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"); - return FAIL_RESTORE; + 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"); + return FAIL_RESTORE; } count += n; } } 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); + 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); LOCAL_Error_TYPE = SYSTEM_ERROR_SAVED_STATE; return FAIL_RESTORE; } @@ -722,8 +693,8 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS) if (LOCAL_ErrorMessage) return FAIL_RESTORE; while (Yap_HeapBase != NULL && - hp_size > Unsigned(HeapLim) - Unsigned(Yap_HeapBase)) { - if(!Yap_growheap(FALSE, hp_size, NULL)) { + hp_size > Unsigned(HeapLim) - Unsigned(Yap_HeapBase)) { + if (!Yap_growheap(FALSE, hp_size, NULL)) { return FAIL_RESTORE; } } @@ -731,17 +702,21 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS) lc_size = get_cell(); if (LOCAL_ErrorMessage) return FAIL_RESTORE; - gb_size=get_cell(); + 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"; + 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"; + LOCAL_ErrorMessage = "could not allocate enough trail space"; return FAIL_RESTORE; } } else { @@ -756,24 +731,22 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS) if (LOCAL_ErrorMessage) return FAIL_RESTORE; } - return(mode); + return (mode); } /* Gets the state of the heap, and evaluates the related variables */ -static int -get_heap_info(USES_REGS1) -{ - LOCAL_OldHeapBase = (ADDR) get_cellptr(); +static int get_heap_info(USES_REGS1) { + LOCAL_OldHeapBase = (ADDR)get_cellptr(); if (LOCAL_ErrorMessage) return -1; - LOCAL_OldHeapTop = (ADDR) get_cellptr(); + LOCAL_OldHeapTop = (ADDR)get_cellptr(); if (LOCAL_ErrorMessage) return -1; - OldHeapUsed = (Int) get_cell(); + OldHeapUsed = (Int)get_cell(); if (LOCAL_ErrorMessage) return -1; - FreeBlocks = (BlockHeader *) get_cellptr(); + FreeBlocks = (BlockHeader *)get_cellptr(); if (LOCAL_ErrorMessage) return -1; AuxBase = (ADDR)get_cellptr(); @@ -801,12 +774,10 @@ 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) -{ - CELL *NewGlobalBase = (CELL *)LOCAL_GlobalBase; - CELL *NewLCL0 = LCL0; - CELL *OldXREGS; +static int get_regs(int flag USES_REGS) { + CELL *NewGlobalBase = (CELL *)LOCAL_GlobalBase; + CELL *NewLCL0 = LCL0; + CELL *OldXREGS; /* Get regs */ compile_arrays = (int)get_cell(); @@ -877,7 +848,7 @@ get_regs(int flag USES_REGS) if (LOCAL_ErrorMessage) return -1; #endif -#ifdef DEPTH_LIMIT +#ifdef DEPTH_LIMIT DEPTH = get_cell(); if (LOCAL_ErrorMessage) return -1; @@ -899,10 +870,10 @@ get_regs(int flag USES_REGS) which_save = get_cell(); if (LOCAL_ErrorMessage) return -1; - LOCAL_XDiff = (CELL)XREGS - (CELL)OldXREGS; + LOCAL_XDiff = (CELL)XREGS - (CELL)OldXREGS; if (LOCAL_ErrorMessage) return -1; - if (get_heap_info( PASS_REGS1 ) < 0) + if (get_heap_info(PASS_REGS1) < 0) return -1; if (flag == DO_EVERYTHING) { ARG1 = get_cell(); @@ -911,7 +882,7 @@ get_regs(int flag USES_REGS) if (which_save == 2) { ARG2 = get_cell(); if (LOCAL_ErrorMessage) - return -1; + return -1; } /* get old trail base */ LOCAL_OldTrailBase = (ADDR)get_cellptr(); @@ -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[]) -{ - return myread(splfild, (char *)old_ops, sizeof(OPCODE)*(_std_top+1)); +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,18 +926,16 @@ 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 ) -{ - Int j; - char *NewASP; +static int CopyStacks(USES_REGS1) { + Int j; + char *NewASP; j = Unsigned(LOCAL_OldLCL0) - Unsigned(ASP); - NewASP = (char *) (Unsigned(ASP) + (Unsigned(LCL0) - Unsigned(LOCAL_OldLCL0))); - if (myread(splfild, (char *) NewASP, j) < 0) + NewASP = (char *)(Unsigned(ASP) + (Unsigned(LCL0) - Unsigned(LOCAL_OldLCL0))); + if (myread(splfild, (char *)NewASP, j) < 0) return -1; j = Unsigned(HR) - Unsigned(LOCAL_OldGlobalBase); - if (myread(splfild, (char *) LOCAL_GlobalBase, j) < 0) + if (myread(splfild, (char *)LOCAL_GlobalBase, j) < 0) return -1; j = Unsigned(TR) - Unsigned(LOCAL_OldTrailBase); if (myread(splfild, LOCAL_TrailBase, j)) @@ -980,10 +945,8 @@ 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 ) -{ - CELL entry, *Entries; +static int CopyTrailEntries(USES_REGS1) { + CELL entry, *Entries; Entries = (CELL *)LOCAL_TrailBase; do { @@ -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) @@ -1006,49 +967,44 @@ get_coded(int flag, OPCODE old_ops[] USES_REGS) return -1; if (get_hash() < 0) return -1; - if (CopyCode( PASS_REGS1 ) < 0) + if (CopyCode(PASS_REGS1) < 0) return -1; switch (flag) { case DO_EVERYTHING: - if (CopyStacks( PASS_REGS1 ) < 0) + if (CopyStacks(PASS_REGS1) < 0) return -1; break; case DO_ONLY_CODE: - if (CopyTrailEntries( PASS_REGS1 ) < 0) + if (CopyTrailEntries(PASS_REGS1) < 0) return -1; break; } /* Check CRC */ if (myread(splfild, my_end_msg, 256) < 0) return -1; - if (strcmp(end_msg,my_end_msg) != 0) { + if (strcmp(end_msg, my_end_msg) != 0) { LOCAL_ErrorMessage = "bad trailing CRC in saved state"; return -1; } 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; + *((YAP_SEG_SIZE *)HeapTop) = InUseFlag; } // HeapMax = HeapUsed = OldHeapUsed; HeapLim = LOCAL_GlobalBase; } /* adjust abstract machine registers */ -static void -restore_regs(int flag USES_REGS) -{ - restore_heap_regs( PASS_REGS1 ); +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,11 +1021,9 @@ 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)); + dbr->Mask = Yap_EvalMasks((Term)dbr->DBT.Entry, &(dbr->Key)); } else if (dbr->Flags & DBComplex) { /* This is quite nasty, we want to recalculate the mask but we don't want to rebuild the whole term. We'll just build whatever we @@ -1078,39 +1032,40 @@ recompute_mask(DBRef dbr) CELL *x = (CELL *)HeapTop, *tp; unsigned int Arity, i; Term out; - char *tbase = CharP(dbr->DBT.Contents-1); + char *tbase = CharP(dbr->DBT.Contents - 1); if (IsPairTerm(dbr->DBT.Entry)) { out = AbsPair(x); Arity = 2; - tp = (CELL *)(tbase + (CELL) RepPair(dbr->DBT.Entry)); + tp = (CELL *)(tbase + (CELL)RepPair(dbr->DBT.Entry)); } else { Functor f; - tp = (CELL *)(tbase + (CELL) RepAppl(dbr->DBT.Entry)); + tp = (CELL *)(tbase + (CELL)RepAppl(dbr->DBT.Entry)); f = (Functor)(*tp++); 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++; + register Term tw = *tp++; if (IsVarTerm(tw)) { - RESET_VARIABLE(x); + RESET_VARIABLE(x); } else if (IsApplTerm(tw)) { - /* just fetch the functor from where it is in the data-base. - This guarantees we have access to references and friends. */ - CELL offset = (CELL)RepAppl(tw); - if (offset > dbr->DBT.NOfCells*sizeof(CELL)) - *x = tw; - else - *x = AbsAppl((CELL *)(tbase + offset)); + /* just fetch the functor from where it is in the data-base. + This guarantees we have access to references and friends. */ + CELL offset = (CELL)RepAppl(tw); + if (offset > dbr->DBT.NOfCells * sizeof(CELL)) + *x = tw; + else + *x = AbsAppl((CELL *)(tbase + offset)); } else if (IsAtomicTerm(tw)) { - *x = tw; + *x = tw; } else if (IsPairTerm(tw)) { - *x = AbsPair(x); + *x = AbsPair(x); } x++; } @@ -1126,27 +1081,25 @@ 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) -{ - register CELL *savep, *basep; - CELL *oldp = oldcode; - int TableSize = NOfE - 1, NOfEntries; - register int i; - int hash; - CELL WorkTerm, failplace = 0; - CELL *Base = oldcode; +static void rehash(CELL *oldcode, int NOfE, int KindOfEntries USES_REGS) { + register CELL *savep, *basep; + CELL *oldp = oldcode; + int TableSize = NOfE - 1, NOfEntries; + register int i; + int hash; + CELL WorkTerm, failplace = 0; + CELL *Base = oldcode; if (LOCAL_HDiff == 0) return; basep = HR; - if (HR + (NOfE*2) > ASP) { + if (HR + (NOfE * 2) > ASP) { basep = (CELL *)TR; - if (basep + (NOfE*2) > (CELL *)LOCAL_TrailTop) { - if (!Yap_growtrail((ADDR)(basep + (NOfE*2))-LOCAL_TrailTop, TRUE)) { - Yap_Error(RESOURCE_ERROR_TRAIL, TermNil, - "not enough space to restore hash tables for indexing"); - Yap_exit(1); + if (basep + (NOfE * 2) > (CELL *)LOCAL_TrailTop) { + if (!Yap_growtrail((ADDR)(basep + (NOfE * 2)) - LOCAL_TrailTop, TRUE)) { + Yap_Error(RESOURCE_ERROR_TRAIL, TermNil, + "not enough space to restore hash tables for indexing"); + Yap_exit(1); } } } @@ -1169,13 +1122,13 @@ rehash(CELL *oldcode, int NOfE, int KindOfEntries USES_REGS) } oldp += 2; } - NOfEntries = (savep - basep)/2; + NOfEntries = (savep - basep) / 2; savep = basep; for (i = 0; i < NOfEntries; ++i) { - register Int d; + register Int d; CELL *hentry; - WorkTerm = savep[i*2]; + WorkTerm = savep[i * 2]; hash = (Unsigned(WorkTerm) >> HASH_SHIFT) & TableSize; hentry = Base + hash * 2; d = TableSize & (Unsigned(WorkTerm) | 1); @@ -1189,27 +1142,18 @@ rehash(CELL *oldcode, int NOfE, int KindOfEntries USES_REGS) hentry = Base + hash * 2; } hentry[0] = WorkTerm; - hentry[1] = savep[i*2+1]; + hentry[1] = savep[i * 2 + 1]; } } - -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(); @@ -1241,9 +1185,9 @@ RestoreFreeSpace( USES_REGS1 ) bsz = bpt->b_next = BlockAdjust(bpt->b_next); while (bsz != NULL) { if (bsz->b_next_size != NULL) - bsz->b_next_size = BlockAdjust(bsz->b_next_size); + bsz->b_next_size = BlockAdjust(bsz->b_next_size); if (bsz->b_next != NULL) - bsz->b_next = BlockAdjust(bsz->b_next); + bsz->b_next = BlockAdjust(bsz->b_next); bsz = bsz->b_next; } } @@ -1251,14 +1195,12 @@ RestoreFreeSpace( USES_REGS1 ) bpt->b_next_size = BlockAdjust(bpt->b_next_size); bpt = bpt->b_next_size; } - *((YAP_SEG_SIZE *) HeapTop) = InUseFlag; + *((YAP_SEG_SIZE *)HeapTop) = InUseFlag; #endif } -static void -RestoreAtomList(Atom atm USES_REGS) -{ - AtomEntry *at; +static void RestoreAtomList(Atom atm USES_REGS) { + AtomEntry *at; at = RepAtom(atm); if (EndOfPAEntr(at)) @@ -1269,20 +1211,18 @@ 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; UInt i; PredEntry **oldp = PredHash; - np = (PredEntry **) Yap_AllocAtomSpace(sizeof(PredEntry *)*size); + 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"); + if (!(np = (PredEntry **)malloc(sizeof(PredEntry *) * size))) { + Yap_Error(SYSTEM_ERROR_FATAL, TermNil, + "Could not allocate space for pred table"); return; } malloced = TRUE; @@ -1300,7 +1240,7 @@ RestoreHashPreds( USES_REGS1 ) UInt hsh; if (p->NextOfPE) - p->NextOfPE = PropAdjust(p->NextOfPE); + p->NextOfPE = PropAdjust(p->NextOfPE); nextp = p->NextOfPE; CleanCode(p PASS_REGS); hsh = PRED_HASH(p->FunctorOfPred, p->ModuleOfPred, size); @@ -1321,37 +1261,30 @@ 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); + fprintf(GLOBAL_stderr, "Estou a ver a prop %x em %x\n", pp->KindOfPE, pp); pp = RepProp(pp->NextOfPE); } } -static void -ShowAtoms() -{ - AtomHashEntry *HashPtr = HashChain; - register int i; +static void ShowAtoms() { + AtomHashEntry *HashPtr = HashChain; + register int i; for (i = 0; i < AtomHashTableSize; ++i) { if (HashPtr->Entry != NIL) { - AtomEntry *at; + AtomEntry *at; at = RepAtom(HashPtr->Entry); do { - fprintf(GLOBAL_stderr,"Passei ao %s em %x\n", at->StrOfAE, at); - ShowEntries(RepProp(at->PropsOfAE)); + fprintf(GLOBAL_stderr, "Passei ao %s em %x\n", at->StrOfAE, at); + ShowEntries(RepProp(at->PropsOfAE)); } while (!EndOfPAEntr(at = RepAtom(at->NextOfAE))); } HashPtr++; @@ -1359,11 +1292,11 @@ ShowAtoms() HashPtr = WideHashChain; for (i = 0; i < WideAtomHashTableSize; ++i) { if (HashPtr->Entry != NIL) { - AtomEntry *at; + AtomEntry *at; at = RepAtom(HashPtr->Entry); do { - fprintf(GLOBAL_stderr,"Passei ao %s em %x\n", at->StrOfAE, at); - ShowEntries(RepProp(at->PropsOfAE)); + fprintf(GLOBAL_stderr, "Passei ao %s em %x\n", at->StrOfAE, at); + ShowEntries(RepProp(at->PropsOfAE)); } while (!EndOfPAEntr(at = RepAtom(at->NextOfAE))); } HashPtr++; @@ -1374,17 +1307,19 @@ ShowAtoms() #include -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; + int mode; - if ((mode = check_header(Astate,ATrail,AStack,AHeap PASS_REGS)) == FAIL_RESTORE) - return(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); + if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) { + 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,43 +1346,46 @@ 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; + LOCAL_ErrorMessage = NULL; return mode; } 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]; + 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"); + strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX - 1); + 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,21 +1397,17 @@ Yap_OpenRestore(const char *inpf, const char *YapLibDir) return stream; } -static void -CloseRestore(void) -{ +static void CloseRestore(void) { CACHE_REGS #ifdef DEBUG_RESTORE3 - ShowAtoms(); + ShowAtoms(); #endif close_file(); LOCAL_PrologMode = UserMode; } #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; @@ -1508,7 +1441,7 @@ RestoreHeap(OPCODE old_ops[] USES_REGS) /* opcodes_moved has side-effects and should be tried first */ if (heap_moved) { opcodes_moved = TRUE; - RestoreFreeSpace( PASS_REGS1 ); + RestoreFreeSpace(PASS_REGS1); } if (heap_moved || opcodes_moved) { restore_heap(); @@ -1519,10 +1452,10 @@ RestoreHeap(OPCODE old_ops[] USES_REGS) Yap_InitCPreds(); Yap_InitBackCPreds(); } - if (!(Yap_ReInitConstExps() && - Yap_ReInitUnaryExps() && - Yap_ReInitBinaryExps())) { - Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "arithmetic operator not in saved state"); + if (!(Yap_ReInitConstExps() && Yap_ReInitUnaryExps() && + Yap_ReInitBinaryExps())) { + Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, + "arithmetic operator not in saved state"); } #ifdef DEBUG_RESTORE1 fprintf(errout, "phase 1 done\n"); @@ -1534,20 +1467,20 @@ 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; + 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; } close_file(); - if (! *AHeap) + if (!*AHeap) *AHeap = MyHeap / 1024; if (mode != DO_ONLY_CODE && *AStack) *AStack = MyStack / 1024; @@ -1556,10 +1489,8 @@ Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail, CELL *A return (MyState); } -static void -UnmarkTrEntries( USES_REGS1 ) -{ - CELL entry, *Entries; +static void UnmarkTrEntries(USES_REGS1) { + CELL entry, *Entries; /* initialize a choice point */ B = (choiceptr)LCL0; @@ -1568,34 +1499,34 @@ UnmarkTrEntries( USES_REGS1 ) Entries = (CELL *)LOCAL_TrailBase; while ((entry = *Entries++) != (CELL)NULL) { if (!IsVarTerm(entry)) { - if(IsPairTerm(entry)) { - CELL *ent = CellPtoHeapAdjust(RepPair(entry)); - register CELL flags; + if (IsPairTerm(entry)) { + CELL *ent = CellPtoHeapAdjust(RepPair(entry)); + register CELL flags; - flags = *ent; - ResetFlag(InUseMask, flags); - *ent = flags; - if (FlagOn((DirtyMask|ErasedMask), flags)) { - if (FlagOn(DBClMask, flags)) { - Yap_ErDBE(DBStructFlagsToDBStruct(ent)); - } else { - if (flags & LogUpdMask) { - if (flags & IndexMask) { - if (FlagOn(ErasedMask, flags)) - Yap_ErLogUpdIndex(ClauseFlagsToLogUpdIndex(ent)); - else - Yap_CleanUpIndex(ClauseFlagsToLogUpdIndex(ent)); - } else { - Yap_ErLogUpdCl(ClauseFlagsToLogUpdClause(ent)); - } - } else { - Yap_ErCl(ClauseFlagsToDynamicClause(ent)); - } - } - } + flags = *ent; + ResetFlag(InUseMask, flags); + *ent = flags; + if (FlagOn((DirtyMask | ErasedMask), flags)) { + if (FlagOn(DBClMask, flags)) { + Yap_ErDBE(DBStructFlagsToDBStruct(ent)); + } else { + if (flags & LogUpdMask) { + if (flags & IndexMask) { + if (FlagOn(ErasedMask, flags)) + Yap_ErLogUpdIndex(ClauseFlagsToLogUpdIndex(ent)); + else + Yap_CleanUpIndex(ClauseFlagsToLogUpdIndex(ent)); + } else { + Yap_ErLogUpdCl(ClauseFlagsToLogUpdClause(ent)); + } + } else { + Yap_ErCl(ClauseFlagsToDynamicClause(ent)); + } + } + } #ifdef MULTI_ASSIGNMENT_VARIABLES } else /* if (IsApplTerm(d1)) */ { - Entries += 2; + Entries += 2; #endif } } @@ -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,16 +1554,15 @@ 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]; + 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) - return(FALSE); + if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack, + &MyHeap, NULL)) == FAIL_RESTORE) + return (FALSE); Yap_ShutdownLoadForeign(); in_limbo = TRUE; if (get_coded(restore_mode, old_ops PASS_REGS) < 0) @@ -1643,17 +1571,16 @@ Restore(char *s, char *lib_dir USES_REGS) in_limbo = FALSE; /*#endif*/ RestoreHeap(old_ops PASS_REGS); - switch(restore_mode) { + switch (restore_mode) { case DO_EVERYTHING: - if (LOCAL_OldHeapBase != Yap_HeapBase || - LOCAL_OldLCL0 != LCL0 || - LOCAL_OldGlobalBase != (CELL *)LOCAL_GlobalBase || - LOCAL_OldTrailBase != LOCAL_TrailBase) { + if (LOCAL_OldHeapBase != Yap_HeapBase || LOCAL_OldLCL0 != LCL0 || + LOCAL_OldGlobalBase != (CELL *)LOCAL_GlobalBase || + LOCAL_OldTrailBase != LOCAL_TrailBase) { Yap_AdjustStacksAndTrail(); if (which_save == 2) { - Yap_AdjustRegs(2); + Yap_AdjustRegs(2); } else { - Yap_AdjustRegs(1); + Yap_AdjustRegs(1); } break; #ifdef DEBUG_RESTORE2 @@ -1662,8 +1589,8 @@ Restore(char *s, char *lib_dir USES_REGS) } break; case DO_ONLY_CODE: - UnmarkTrEntries( PASS_REGS1 ); - Yap_InitYaamRegs( 0 ); + UnmarkTrEntries(PASS_REGS1); + Yap_InitYaamRegs(0); break; } @@ -1675,7 +1602,7 @@ Restore(char *s, char *lib_dir USES_REGS) Yap_ReInitWTime(); #if USE_DL_MALLOC || USE_SYSTEM_MALLOC if (!AuxSp) { - Yap_InitPreAllocCodeSpace( 0 ); + Yap_InitPreAllocCodeSpace(0); } #endif CloseRestore(); @@ -1685,45 +1612,41 @@ 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); + 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]; + 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"); - return(FALSE); + 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"); - return(FALSE); + Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, + "cannot perform save: more than a worker/thread running"); + return (FALSE); } #endif /* THREADS */ if (!Yap_GetName(s, YAP_FILENAME_MAX, t1)) { - Yap_Error(TYPE_ERROR_LIST,t1,"restore/1"); - return(FALSE); + Yap_Error(TYPE_ERROR_LIST, t1, "restore/1"); + return (FALSE); } if ((mode = Restore(s, NULL PASS_REGS)) == DO_ONLY_CODE) { - Yap_RestartYap( 3 ); + Yap_RestartYap(3); } - return(mode != FAIL_RESTORE); + 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); diff --git a/H/Foreign.h b/H/Foreign.h index 764e7d6f4..135ed4bbf 100644 --- a/H/Foreign.h +++ b/H/Foreign.h @@ -1,23 +1,23 @@ /************************************************************************* -* * -* YAP Prolog * -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-97 * -* * -************************************************************************** -* * -* File: Foreign.h * -* comments: header file for dynamic loading routines * -*************************************************************************/ + * * + * YAP Prolog * + * * + * Yap Prolog was developed at NCCUP - Universidade do Porto * + * * + * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-97 * + * * + ************************************************************************** + * * + * File: Foreign.h * + * comments: header file for dynamic loading routines * + *************************************************************************/ #define NO_DYN 1 #ifndef FOREIGN_H #define FOREIGN_H -/** +/** @: @file Foreign.h @@ -25,27 +25,30 @@ load_foreign_files/3 has works for the following configurations: - linux: should work both for a.out (untested by me) and ELF; - + - WIN32: works (notice that symbols are not exported by default) - OSX: works using Mach dynamic libs. - osf: should work, but isn't working yet. - + - sunos4: should work, using A.OUT format; - + - svr4, eg solaris: should work, using ELF format; - AIX: should work for 3.2 and 4.1 at least, using ECOFF; - + YAP should be able to load on most BSD Unixes, but you will need to say that here. YAP also supports COFF loading (pretty much the same technique as - used for A.OUT loading) but that is untested so far. + used for A.OUT loading) but that is untested so far. */ +#include "Yap.h" +#include "YapHeap.h" + #ifdef _AIX #undef NO_DYN #endif /* __AIX */ @@ -96,8 +99,8 @@ #endif #endif /* LOAD_DYLD */ -#define LOAD_SUCCEEDED 0 -#define LOAD_FAILLED -1 +#define LOAD_SUCCEEDED 0 +#define LOAD_FAILLED -1 typedef struct StringListItem { Atom name; @@ -115,16 +118,15 @@ typedef struct ForeignLoadItem { typedef void (*YapInitProc)(void); +void *Yap_LoadForeignFile(char *, int); +int Yap_CallForeignFile(void *, char *); +int Yap_CloseForeignFile(void *); +Int Yap_LoadForeign(StringList, StringList, char *, YapInitProc *); +Int Yap_ReLoadForeign(StringList, StringList, char *, YapInitProc *); +void Yap_ReOpenLoadForeign(void); +void Yap_ShutdownLoadForeign(void); -void *Yap_LoadForeignFile(char *, int); -int Yap_CallForeignFile(void *, char *); -int Yap_CloseForeignFile(void *); -Int Yap_LoadForeign(StringList, StringList, char *, YapInitProc *); -Int Yap_ReLoadForeign(StringList, StringList, char *, YapInitProc *); -void Yap_ReOpenLoadForeign(void); -void Yap_ShutdownLoadForeign(void); - -#define EAGER_LOADING 1 +#define EAGER_LOADING 1 #define GLOBAL_LOADING 2 #endif diff --git a/H/Yap.h b/H/Yap.h index 40ebc7927..c982d55a2 100755 --- a/H/Yap.h +++ b/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" + diff --git a/H/YapHeap.h b/H/YapHeap.h index be01833d8..9b56a38d7 100755 --- a/H/YapHeap.h +++ b/H/YapHeap.h @@ -18,6 +18,9 @@ #ifndef HEAP_H #define HEAP_H 1 +#include "Atoms.h" +#include "Yap.h" + #if LOW_PROF #include #endif diff --git a/H/rheap.h b/H/rheap.h index 30330e583..2b0d4a178 100644 --- a/H/rheap.h +++ b/H/rheap.h @@ -1,243 +1,251 @@ /************************************************************************* -* * -* YAP Prolog * -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: rheap.h * -* comments: walk through heap code * -* * -* Last rev: $Date: 2008-08-07 20:51:23 $,$Author: vsc $ -** -* $Log: not supported by cvs2svn $ -* Revision 1.99 2008/07/22 23:34:49 vsc -* SWI and module fixes -* -* Revision 1.98 2008/05/12 22:31:37 vsc -* fix previous fixes -* -* Revision 1.97 2008/05/12 14:04:23 vsc -* updates to restore -* -* Revision 1.96 2008/04/11 16:58:17 ricroc -* yapor: seq_def initialization -* -* Revision 1.95 2008/04/06 12:06:48 vsc -* more small fixes -* -* Revision 1.94 2008/04/06 11:53:02 vsc -* fix some restore bugs -* -* Revision 1.93 2008/04/04 09:10:02 vsc -* restore was restoring twice -* -* Revision 1.92 2008/04/03 11:34:47 vsc -* fix restorebb in cases entry key is not an atom (obs from Nicos -* Angelopoulos) -* -* Revision 1.91 2008/04/01 15:31:43 vsc -* more saved state fixes -* -* Revision 1.90 2008/04/01 14:09:43 vsc -* improve restore -* -* Revision 1.89 2008/04/01 09:41:05 vsc -* more fixes to restore -* -* Revision 1.88 2008/04/01 08:42:46 vsc -* fix restore and small VISTA thingies -* -* Revision 1.87 2008/03/25 22:03:14 vsc -* fix some icc warnings -* -* Revision 1.86 2008/03/25 16:45:53 vsc -* make or-parallelism compile again -* -* Revision 1.85 2008/02/12 17:03:52 vsc -* SWI-portability changes -* -* Revision 1.84 2008/02/07 21:39:51 vsc -* fix case where predicate is for an integer (DBEntry). -* -* Revision 1.83 2008/01/23 17:57:55 vsc -* valgrind it! -* enable atom garbage collection. -* -* Revision 1.82 2007/12/05 12:17:23 vsc -* improve JT -* fix graph compatibility with SICStus -* re-export declaration. -* -* Revision 1.81 2007/11/26 23:43:09 vsc -* fixes to support threads and assert correctly, even if inefficiently. -* -* Revision 1.80 2007/11/07 09:35:53 vsc -* small fix -* -* Revision 1.79 2007/11/07 09:25:27 vsc -* speedup meta-calls -* -* Revision 1.78 2007/11/06 17:02:12 vsc -* compile ground terms away. -* -* Revision 1.77 2007/10/10 09:44:24 vsc -* some more fixes to make YAP swi compatible -* fix absolute_file_name (again) -* fix setarg -* -* Revision 1.76 2007/09/28 23:18:17 vsc -* handle learning from interpretations. -* -* Revision 1.75 2007/04/10 22:13:21 vsc -* fix max modules limitation -* -* Revision 1.74 2007/03/22 11:12:21 vsc -* make sure that YAP_Restart does not restart a failed goal. -* -* Revision 1.73 2007/02/18 00:26:36 vsc -* fix atom garbage collector (although it is still off by default) -* make valgrind feel better -* -* Revision 1.72 2007/01/08 08:27:19 vsc -* fix restore (Trevor) -* make indexing a bit faster on IDB -* -* Revision 1.71 2006/11/27 17:42:03 vsc -* support for UNICODE, and other bug fixes. -* -* Revision 1.70 2006/08/25 19:50:35 vsc -* global data structures -* -* Revision 1.69 2006/08/22 16:12:46 vsc -* global variables -* -* Revision 1.68 2006/08/02 18:18:30 vsc -* preliminary support for readutil library (SWI compatible). -* -* Revision 1.67 2006/05/17 18:38:11 vsc -* make system library use true file name -* -* Revision 1.66 2006/04/28 15:48:33 vsc -* do locking on streams -* -* Revision 1.65 2006/04/28 13:23:23 vsc -* fix number of overflow bugs affecting threaded version -* make current_op faster. -* -* Revision 1.64 2006/03/22 20:07:28 vsc -* take better care of zombies -* -* Revision 1.63 2006/03/06 14:04:56 vsc -* fixes to garbage collector -* fixes to debugger -* -* Revision 1.62 2006/02/24 14:03:42 vsc -* fix refs to old LogUpd implementation (pre 5). -* -* Revision 1.61 2006/01/02 02:16:18 vsc -* support new interface between YAP and GMP, so that we don't rely on our own -* allocation routines. -* Several big fixes. -* -* Revision 1.60 2005/12/17 03:25:39 vsc -* major changes to support online event-based profiling -* improve error discovery and restart on scanner. -* -* Revision 1.59 2005/12/05 17:16:11 vsc -* write_depth/3 -* overflow handlings and garbage collection -* Several ipdates to CLPBN -* dif/2 could be broken in the presence of attributed variables. -* -* Revision 1.58 2005/11/23 03:01:33 vsc -* fix several bugs in save/restore.b -* -* Revision 1.57 2005/10/28 17:38:50 vsc -* sveral updates -* -* Revision 1.56 2005/10/21 16:09:03 vsc -* SWI compatible module only operators -* -* Revision 1.55 2005/10/19 19:00:48 vsc -* extend arrays with nb_terms so that we can implement nb_ builtins -* correctly. -* -* Revision 1.54 2005/09/09 17:24:39 vsc -* a new and hopefully much better implementation of atts. -* -* Revision 1.53 2005/08/01 15:40:38 ricroc -* TABLING NEW: better support for incomplete tabling -* -* Revision 1.52 2005/07/06 19:34:11 ricroc -* TABLING: answers for completed calls can now be obtained by loading (new -*option) or executing (default) them from the trie data structure. -* -* Revision 1.51 2005/07/06 15:10:15 vsc -* improvements to compiler: merged instructions and fixes for -> -* -* Revision 1.50 2005/06/01 13:53:46 vsc -* improve bb routines to use the DB efficiently -* change interface between DB and BB. -* -* Revision 1.49 2005/05/30 03:26:37 vsc -* add some atom gc fixes -* -* Revision 1.48 2005/01/04 02:50:21 vsc -* - allow MegaClauses with blobs -* - change Diffs to be thread specific -* - include Christian's updates -* -* Revision 1.47 2004/12/02 06:06:47 vsc -* fix threads so that they at least start -* allow error handling to work with threads -* replace heap_base by Yap_heap_base, according to Yap's convention for globals. -* -* Revision 1.46 2004/11/23 21:16:21 vsc -* A few extra fixes for saved states. -* -* Revision 1.45 2004/10/26 20:16:18 vsc -* More bug fixes for overflow handling -* -* Revision 1.44 2004/10/06 16:55:47 vsc -* change configure to support big mem configs -* get rid of extra globals -* fix trouble with multifile preds -* -* Revision 1.43 2004/09/27 20:45:04 vsc -* Mega clauses -* Fixes to sizeof(expand_clauses) which was being overestimated -* Fixes to profiling+indexing -* Fixes to reallocation of memory after restoring -* Make sure all clauses, even for C, end in _Ystop -* Don't reuse space for Streams -* Fix Stream_F on StreaNo+1 -* -* Revision 1.42 2004/06/05 03:37:00 vsc -* coroutining is now a part of attvars. -* some more fixes. -* -* Revision 1.41 2004/04/29 03:45:50 vsc -* fix garbage collection in execute_tail -* -* Revision 1.40 2004/03/31 01:03:10 vsc -* support expand group of clauses -* -* Revision 1.39 2004/03/19 11:35:42 vsc -* trim_trail for default machine -* be more aggressive about try-retry-trust chains. -* - handle cases where block starts with a wait -* - don't use _killed instructions, just let the thing rot by itself. -* * -* * -*************************************************************************/ + * * + * YAP Prolog * + * * + * Yap Prolog was developed at NCCUP - Universidade do Porto * + * * + * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * + * * + ************************************************************************** + * * + * File: rheap.h * + * comments: walk through heap code * + * * + * Last rev: $Date: 2008-08-07 20:51:23 $,$Author: vsc $ + ** + * $Log: not supported by cvs2svn $ + * Revision 1.99 2008/07/22 23:34:49 vsc + * SWI and module fixes + * + * Revision 1.98 2008/05/12 22:31:37 vsc + * fix previous fixes + * + * Revision 1.97 2008/05/12 14:04:23 vsc + * updates to restore + * + * Revision 1.96 2008/04/11 16:58:17 ricroc + * yapor: seq_def initialization + * + * Revision 1.95 2008/04/06 12:06:48 vsc + * more small fixes + * + * Revision 1.94 2008/04/06 11:53:02 vsc + * fix some restore bugs + * + * Revision 1.93 2008/04/04 09:10:02 vsc + * restore was restoring twice + * + * Revision 1.92 2008/04/03 11:34:47 vsc + * fix restorebb in cases entry key is not an atom (obs from Nicos + * Angelopoulos) + * + * Revision 1.91 2008/04/01 15:31:43 vsc + * more saved state fixes + * + * Revision 1.90 2008/04/01 14:09:43 vsc + * improve restore + * + * Revision 1.89 2008/04/01 09:41:05 vsc + * more fixes to restore + * + * Revision 1.88 2008/04/01 08:42:46 vsc + * fix restore and small VISTA thingies + * + * Revision 1.87 2008/03/25 22:03:14 vsc + * fix some icc warnings + * + * Revision 1.86 2008/03/25 16:45:53 vsc + * make or-parallelism compile again + * + * Revision 1.85 2008/02/12 17:03:52 vsc + * SWI-portability changes + * + * Revision 1.84 2008/02/07 21:39:51 vsc + * fix case where predicate is for an integer (DBEntry). + * + * Revision 1.83 2008/01/23 17:57:55 vsc + * valgrind it! + * enable atom garbage collection. + * + * Revision 1.82 2007/12/05 12:17:23 vsc + * improve JT + * fix graph compatibility with SICStus + * re-export declaration. + * + * Revision 1.81 2007/11/26 23:43:09 vsc + * fixes to support threads and assert correctly, even if inefficiently. + * + * Revision 1.80 2007/11/07 09:35:53 vsc + * small fix + * + * Revision 1.79 2007/11/07 09:25:27 vsc + * speedup meta-calls + * + * Revision 1.78 2007/11/06 17:02:12 vsc + * compile ground terms away. + * + * Revision 1.77 2007/10/10 09:44:24 vsc + * some more fixes to make YAP swi compatible + * fix absolute_file_name (again) + * fix setarg + * + * Revision 1.76 2007/09/28 23:18:17 vsc + * handle learning from interpretations. + * + * Revision 1.75 2007/04/10 22:13:21 vsc + * fix max modules limitation + * + * Revision 1.74 2007/03/22 11:12:21 vsc + * make sure that YAP_Restart does not restart a failed goal. + * + * Revision 1.73 2007/02/18 00:26:36 vsc + * fix atom garbage collector (although it is still off by default) + * make valgrind feel better + * + * Revision 1.72 2007/01/08 08:27:19 vsc + * fix restore (Trevor) + * make indexing a bit faster on IDB + * + * Revision 1.71 2006/11/27 17:42:03 vsc + * support for UNICODE, and other bug fixes. + * + * Revision 1.70 2006/08/25 19:50:35 vsc + * global data structures + * + * Revision 1.69 2006/08/22 16:12:46 vsc + * global variables + * + * Revision 1.68 2006/08/02 18:18:30 vsc + * preliminary support for readutil library (SWI compatible). + * + * Revision 1.67 2006/05/17 18:38:11 vsc + * make system library use true file name + * + * Revision 1.66 2006/04/28 15:48:33 vsc + * do locking on streams + * + * Revision 1.65 2006/04/28 13:23:23 vsc + * fix number of overflow bugs affecting threaded version + * make current_op faster. + * + * Revision 1.64 2006/03/22 20:07:28 vsc + * take better care of zombies + * + * Revision 1.63 2006/03/06 14:04:56 vsc + * fixes to garbage collector + * fixes to debugger + * + * Revision 1.62 2006/02/24 14:03:42 vsc + * fix refs to old LogUpd implementation (pre 5). + * + * Revision 1.61 2006/01/02 02:16:18 vsc + * support new interface between YAP and GMP, so that we don't rely on our own + * allocation routines. + * Several big fixes. + * + * Revision 1.60 2005/12/17 03:25:39 vsc + * major changes to support online event-based profiling + * improve error discovery and restart on scanner. + * + * Revision 1.59 2005/12/05 17:16:11 vsc + * write_depth/3 + * overflow handlings and garbage collection + * Several ipdates to CLPBN + * dif/2 could be broken in the presence of attributed variables. + * + * Revision 1.58 2005/11/23 03:01:33 vsc + * fix several bugs in save/restore.b + * + * Revision 1.57 2005/10/28 17:38:50 vsc + * sveral updates + * + * Revision 1.56 2005/10/21 16:09:03 vsc + * SWI compatible module only operators + * + * Revision 1.55 2005/10/19 19:00:48 vsc + * extend arrays with nb_terms so that we can implement nb_ builtins + * correctly. + * + * Revision 1.54 2005/09/09 17:24:39 vsc + * a new and hopefully much better implementation of atts. + * + * Revision 1.53 2005/08/01 15:40:38 ricroc + * TABLING NEW: better support for incomplete tabling + * + * Revision 1.52 2005/07/06 19:34:11 ricroc + * TABLING: answers for completed calls can now be obtained by loading (new + *option) or executing (default) them from the trie data structure. + * + * Revision 1.51 2005/07/06 15:10:15 vsc + * improvements to compiler: merged instructions and fixes for -> + * + * Revision 1.50 2005/06/01 13:53:46 vsc + * improve bb routines to use the DB efficiently + * change interface between DB and BB. + * + * Revision 1.49 2005/05/30 03:26:37 vsc + * add some atom gc fixes + * + * Revision 1.48 2005/01/04 02:50:21 vsc + * - allow MegaClauses with blobs + * - change Diffs to be thread specific + * - include Christian's updates + * + * Revision 1.47 2004/12/02 06:06:47 vsc + * fix threads so that they at least start + * allow error handling to work with threads + * replace heap_base by Yap_heap_base, according to Yap's convention for + *globals. + * + * Revision 1.46 2004/11/23 21:16:21 vsc + * A few extra fixes for saved states. + * + * Revision 1.45 2004/10/26 20:16:18 vsc + * More bug fixes for overflow handling + * + * Revision 1.44 2004/10/06 16:55:47 vsc + * change configure to support big mem configs + * get rid of extra globals + * fix trouble with multifile preds + * + * Revision 1.43 2004/09/27 20:45:04 vsc + * Mega clauses + * Fixes to sizeof(expand_clauses) which was being overestimated + * Fixes to profiling+indexing + * Fixes to reallocation of memory after restoring + * Make sure all clauses, even for C, end in _Ystop + * Don't reuse space for Streams + * Fix Stream_F on StreaNo+1 + * + * Revision 1.42 2004/06/05 03:37:00 vsc + * coroutining is now a part of attvars. + * some more fixes. + * + * Revision 1.41 2004/04/29 03:45:50 vsc + * fix garbage collection in execute_tail + * + * Revision 1.40 2004/03/31 01:03:10 vsc + * support expand group of clauses + * + * Revision 1.39 2004/03/19 11:35:42 vsc + * trim_trail for default machine + * be more aggressive about try-retry-trust chains. + * - handle cases where block starts with a wait + * - don't use _killed instructions, just let the thing rot by itself. + * * + * * + *************************************************************************/ #ifdef SCCS 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 diff --git a/info/build.sh b/info/build.sh index c8ffac3fe..e9d1cc9fa 100644 --- a/info/build.sh +++ b/info/build.sh @@ -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 diff --git a/info/meta.yaml b/info/meta.yaml index 8e24404b1..b507432b7 100644 --- a/info/meta.yaml +++ b/info/meta.yaml @@ -12,6 +12,8 @@ requirements: - r - notebook run: + - python + - pythonlab - readline - gmp - r diff --git a/packages/cplint/cplint_yap.c b/packages/cplint/cplint_yap.c index 0b4db4b70..ec8581e4d 100644 --- a/packages/cplint/cplint_yap.c +++ b/packages/cplint/cplint_yap.c @@ -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); diff --git a/packages/python/CMakeLists.txt b/packages/python/CMakeLists.txt index 65338997b..78561e1ca 100644 --- a/packages/python/CMakeLists.txt +++ b/packages/python/CMakeLists.txt @@ -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) diff --git a/packages/python/py2pl.c b/packages/python/py2pl.c index 7dcf0b158..32f94fb21 100644 --- a/packages/python/py2pl.c +++ b/packages/python/py2pl.c @@ -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; } } } diff --git a/packages/python/swig/CMakeLists.txt b/packages/python/swig/CMakeLists.txt index 97fc9d99d..dc5ab31fe 100644 --- a/packages/python/swig/CMakeLists.txt +++ b/packages/python/swig/CMakeLists.txt @@ -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)