Merge branch 'master' of git://yap.git.sourceforge.net/gitroot/yap/yap-6.3

This commit is contained in:
Joao
2011-09-15 15:44:26 +01:00
338 changed files with 13523 additions and 2160 deletions

0
H/TermExt.h Executable file → Normal file
View File

10
H/Yap.h Executable file → Normal file
View File

@@ -691,7 +691,13 @@ typedef enum
if you place things in the lower addresses (power to the libc people).
*/
#if (defined(_AIX) || (defined(__APPLE__) && !defined(__LP64__)) || defined(_WIN32) || defined(sparc) || defined(__sparc) || defined(mips) || defined(__FreeBSD__) || defined(_POWER) || defined(__POWERPC__) || defined(__linux__) || defined(IN_SECOND_QUADRANT) || defined(__CYGWIN__)) || defined(__NetBSD__) || defined(__DragonFly__)
#if defined(__APPLE__)
/* mmap on __APPLE__ is not the greatest idea. It overwrites memory allocated by malloc */
#undef USE_DL_MALLOC
#ifndef USE_SYSTEM_MALLOC
#define USE_SYSTEM_MALLOC 1
#endif
#elif (defined(_AIX) || (defined(__APPLE__) && !defined(__LP64__)) || defined(_WIN32) || defined(sparc) || defined(__sparc) || defined(mips) || defined(__FreeBSD__) || defined(_POWER) || defined(__POWERPC__) || defined(__linux__) || defined(IN_SECOND_QUADRANT) || defined(__CYGWIN__)) || defined(__NetBSD__) || defined(__DragonFly__)
#define USE_LOW32_TAGS 1
#endif
@@ -1377,6 +1383,8 @@ Yap_StartSlots( USES_REGS1 ) {
static inline void
Yap_CloseSlots( USES_REGS1 ) {
Int old_slots;
if (CurSlot < LCL0-ASP)
return;
old_slots = IntOfTerm(ASP[0]);
ASP += (old_slots+1);
CurSlot = IntOfTerm(*ASP);

0
H/YapHeap.h Executable file → Normal file
View File

View File

@@ -24,7 +24,7 @@
OPCODE(alloc_for_logical_pred ,L),
OPCODE(copy_idb_term ,e),
OPCODE(unify_idb_term ,e),
OPCODE(ensure_space ,Osbpi),
OPCODE(ensure_space ,Osbpa),
OPCODE(spy_or_trymark ,Otapl),
OPCODE(try_and_mark ,Otapl),
OPCODE(count_retry_and_mark ,Otapl),

17
H/Yapproto.h Executable file → Normal file
View File

@@ -58,7 +58,7 @@ Term STD_PROTO(Yap_NWideStringToListOfAtoms,(wchar_t *, size_t));
Term STD_PROTO(Yap_NWideStringToDiffListOfAtoms,(wchar_t *, Term, size_t));
int STD_PROTO(Yap_AtomIncreaseHold,(Atom));
int STD_PROTO(Yap_AtomDecreaseHold,(Atom));
struct operator_entry *STD_PROTO(Yap_OpPropForModule,(Atom, Term));
Int STD_PROTO(Yap_InitSlot,(Term CACHE_TYPE));
Int STD_PROTO(Yap_NewSlots,(int CACHE_TYPE));
int STD_PROTO(Yap_RecoverSlots,(int CACHE_TYPE));
@@ -136,6 +136,7 @@ void STD_PROTO(Yap_Abolish,(struct pred_entry *));
void STD_PROTO(Yap_BuildMegaClause,(struct pred_entry *));
void STD_PROTO(Yap_EraseMegaClause,(yamop *,struct pred_entry *));
void STD_PROTO(Yap_ResetConsultStack,(void));
void STD_PROTO(Yap_AssertzClause,(struct pred_entry *, yamop *));
/* cmppreds.c */
@@ -307,9 +308,15 @@ Term STD_PROTO(Yap_Parse,(void));
/* readutil.c */
void STD_PROTO(Yap_InitReadUtil,(void));
/* qly.c */
void STD_PROTO(Yap_InitQLY,(void));
int STD_PROTO(Yap_Restore,(char *, char *));
void STD_PROTO(Yap_InitQLYR,(void));
/* save.c */
int STD_PROTO(Yap_SavedInfo,(char *,char *,CELL *,CELL *,CELL *));
int STD_PROTO(Yap_Restore,(char *, char *));
int STD_PROTO(Yap_SavedStateRestore,(char *, char *));
struct io_stream *STD_PROTO(Yap_OpenRestore,(char *, char *));
void STD_PROTO(Yap_InitSavePreds,(void));
/* scanner.c */
@@ -487,3 +494,9 @@ gc_P(yamop *p, yamop *cp)
{
return (p->opc == Yap_opcode(_execute_cpred) ? cp : p);
}
#ifdef _PL_STREAM_H
extern int Yap_getInputStream(Int t, IOSTREAM **s);
extern int Yap_getOutputStream(Int t, IOSTREAM **s);
#endif

114
H/Yatom.h Executable file → Normal file
View File

@@ -674,7 +674,7 @@ typedef enum
TabledPredFlag = 0x00000040L, /* is tabled */
SequentialPredFlag = 0x00000020L, /* may not create parallel choice points! */
ProfiledPredFlag = 0x00000010L, /* pred is being profiled */
MyddasPredFlag = 0x00000008L, /* Myddas Imported pred */
BackCPredFlag = 0x00000008L, /* Myddas Imported pred */
ModuleTransparentPredFlag = 0x00000004L, /* ModuleTransparent pred */
SWIEnvPredFlag = 0x00000002L, /* new SWI interface */
UDIPredFlag = 0x00000001L /* User Defined Indexing */
@@ -708,7 +708,7 @@ typedef struct pred_entry
struct yami *CodeOfPred;
OPCODE OpcodeOfPred; /* undefcode, indexcode, spycode, .... */
CELL PredFlags;
unsigned int ArityOfPE; /* arity of property */
UInt ArityOfPE; /* arity of property */
union
{
struct
@@ -727,7 +727,6 @@ typedef struct pred_entry
{
Atom OwnerFile; /* File where the predicate was defined */
Int IndxId; /* Index for a certain key */
struct mfile *file_srcs; /* for multifile predicates */
} src;
#if defined(YAPOR) || defined(THREADS)
lockvar PELock; /* a simple lock to protect expansion */
@@ -1481,6 +1480,9 @@ PRED_HASH(FunctorEntry *fe, Term cur_mod, UInt size)
return (((CELL)fe+cur_mod)>>2) % size;
}
EXTERN inline Prop STD_PROTO(GetPredPropByFuncAndModHavingLock, (FunctorEntry *, Term));
EXTERN inline Prop STD_PROTO(PredPropByFuncAndMod, (FunctorEntry *, Term));
EXTERN inline Prop STD_PROTO(PredPropByAtomAndMod, (Atom, Term));
EXTERN inline Prop STD_PROTO(GetPredPropByFuncHavingLock, (FunctorEntry *, Term));
#ifdef THREADS
@@ -1565,6 +1567,64 @@ PredPropByFunc (Functor fe, Term cur_mod)
return Yap_NewPredPropByFunctor (fe, cur_mod);
}
EXTERN inline Prop
GetPredPropByFuncAndModHavingLock (FunctorEntry *fe, Term cur_mod)
{
PredEntry *p;
if (!(p = RepPredProp(fe->PropsOfFE))) {
return NIL;
}
if (p->ModuleOfPred == cur_mod) {
#ifdef THREADS
/* Thread Local Predicates */
if (p->PredFlags & ThreadLocalPredFlag) {
return AbsPredProp (Yap_GetThreadPred (p INIT_REGS));
}
#endif
return AbsPredProp(p);
}
if (p->NextOfPE) {
UInt hash = PRED_HASH(fe,cur_mod,PredHashTableSize);
READ_LOCK(PredHashRWLock);
p = PredHash[hash];
while (p) {
if (p->FunctorOfPred == fe &&
p->ModuleOfPred == cur_mod)
{
#ifdef THREADS
/* Thread Local Predicates */
if (p->PredFlags & ThreadLocalPredFlag) {
READ_UNLOCK(PredHashRWLock);
return AbsPredProp (Yap_GetThreadPred (p INIT_REGS));
}
#endif
READ_UNLOCK(PredHashRWLock);
return AbsPredProp(p);
}
p = RepPredProp(p->NextOfPE);
}
READ_UNLOCK(PredHashRWLock);
}
return NIL;
}
EXTERN inline Prop
PredPropByFuncAndMod (Functor fe, Term cur_mod)
/* get predicate entry for ap/arity; create it if neccessary. */
{
Prop p0;
WRITE_LOCK (fe->FRWLock);
p0 = GetPredPropByFuncAndModHavingLock(fe, cur_mod);
if (p0) {
WRITE_UNLOCK (fe->FRWLock);
return p0;
}
return Yap_NewPredPropByFunctor (fe, cur_mod);
}
EXTERN inline Prop
PredPropByAtom (Atom at, Term cur_mod)
/* get predicate entry for ap/arity; create it if neccessary. */
@@ -1596,6 +1656,37 @@ PredPropByAtom (Atom at, Term cur_mod)
return Yap_NewPredPropByAtom (ae, cur_mod);
}
EXTERN inline Prop
PredPropByAtomAndMod (Atom at, Term cur_mod)
/* get predicate entry for ap/arity; create it if neccessary. */
{
Prop p0;
AtomEntry *ae = RepAtom (at);
WRITE_LOCK (ae->ARWLock);
p0 = ae->PropsOfAE;
while (p0)
{
PredEntry *pe = RepPredProp (p0);
if (pe->KindOfPE == PEProp &&
(pe->ModuleOfPred == cur_mod))
{
#ifdef THREADS
/* Thread Local Predicates */
if (pe->PredFlags & ThreadLocalPredFlag)
{
WRITE_UNLOCK (ae->ARWLock);
return AbsPredProp (Yap_GetThreadPred (pe INIT_REGS));
}
#endif
WRITE_UNLOCK (ae->ARWLock);
return (p0);
}
p0 = pe->NextOfPE;
}
return Yap_NewPredPropByAtom (ae, cur_mod);
}
#if DEBUG_PELOCKING
#define PELOCK(I,Z) \
{ LOCK((Z)->PELock); (Z)->StatisticsForPred.NOfEntries=(I);(Z)->StatisticsForPred.NOfHeadSuccesses=pthread_self(); }
@@ -1606,5 +1697,22 @@ PredPropByAtom (Atom at, Term cur_mod)
#define UNLOCKPE(I,Z) UNLOCK((Z)->PELock)
#endif
EXTERN inline void STD_PROTO(AddPropToAtom, (AtomEntry *, PropEntry *p));
EXTERN inline void
AddPropToAtom(AtomEntry *ae, PropEntry *p)
{
/* old properties should be always last, and wide atom properties
should always be first */
if (ae->PropsOfAE != NIL &&
RepProp(ae->PropsOfAE)->KindOfPE == WideAtomProperty) {
PropEntry *pp = RepProp(ae->PropsOfAE);
p->NextOfPE = pp->NextOfPE;
pp->NextOfPE = AbsProp(p);
} else {
p->NextOfPE = ae->PropsOfAE;
ae->PropsOfAE = AbsProp(p);
}
}
#endif

0
H/alloc.h Executable file → Normal file
View File

View File

@@ -693,7 +693,7 @@ typedef struct yami {
struct pred_entry *p;
Int i;
CELL next;
} Osbpi;
} Osbpa;
struct {
#ifdef YAPOR
unsigned int or_arg;

0
H/compile.h Executable file → Normal file
View File

0
H/cut_c.h Executable file → Normal file
View File

0
H/dlmalloc.h Executable file → Normal file
View File

View File

@@ -329,3 +329,58 @@
#define REMOTE_do_trace_primitives(wid) REMOTE(wid)->do_trace_primitives_
#endif
#define LOCAL_ExportAtomHashChain LOCAL->ExportAtomHashChain_
#define REMOTE_ExportAtomHashChain(wid) REMOTE(wid)->ExportAtomHashChain_
#define LOCAL_ExportAtomHashTableSize LOCAL->ExportAtomHashTableSize_
#define REMOTE_ExportAtomHashTableSize(wid) REMOTE(wid)->ExportAtomHashTableSize_
#define LOCAL_ExportAtomHashTableNum LOCAL->ExportAtomHashTableNum_
#define REMOTE_ExportAtomHashTableNum(wid) REMOTE(wid)->ExportAtomHashTableNum_
#define LOCAL_ExportFunctorHashChain LOCAL->ExportFunctorHashChain_
#define REMOTE_ExportFunctorHashChain(wid) REMOTE(wid)->ExportFunctorHashChain_
#define LOCAL_ExportFunctorHashTableSize LOCAL->ExportFunctorHashTableSize_
#define REMOTE_ExportFunctorHashTableSize(wid) REMOTE(wid)->ExportFunctorHashTableSize_
#define LOCAL_ExportFunctorHashTableNum LOCAL->ExportFunctorHashTableNum_
#define REMOTE_ExportFunctorHashTableNum(wid) REMOTE(wid)->ExportFunctorHashTableNum_
#define LOCAL_ExportPredEntryHashChain LOCAL->ExportPredEntryHashChain_
#define REMOTE_ExportPredEntryHashChain(wid) REMOTE(wid)->ExportPredEntryHashChain_
#define LOCAL_ExportPredEntryHashTableSize LOCAL->ExportPredEntryHashTableSize_
#define REMOTE_ExportPredEntryHashTableSize(wid) REMOTE(wid)->ExportPredEntryHashTableSize_
#define LOCAL_ExportPredEntryHashTableNum LOCAL->ExportPredEntryHashTableNum_
#define REMOTE_ExportPredEntryHashTableNum(wid) REMOTE(wid)->ExportPredEntryHashTableNum_
#define LOCAL_ExportDBRefHashChain LOCAL->ExportDBRefHashChain_
#define REMOTE_ExportDBRefHashChain(wid) REMOTE(wid)->ExportDBRefHashChain_
#define LOCAL_ExportDBRefHashTableSize LOCAL->ExportDBRefHashTableSize_
#define REMOTE_ExportDBRefHashTableSize(wid) REMOTE(wid)->ExportDBRefHashTableSize_
#define LOCAL_ExportDBRefHashTableNum LOCAL->ExportDBRefHashTableNum_
#define REMOTE_ExportDBRefHashTableNum(wid) REMOTE(wid)->ExportDBRefHashTableNum_
#define LOCAL_ImportAtomHashChain LOCAL->ImportAtomHashChain_
#define REMOTE_ImportAtomHashChain(wid) REMOTE(wid)->ImportAtomHashChain_
#define LOCAL_ImportAtomHashTableSize LOCAL->ImportAtomHashTableSize_
#define REMOTE_ImportAtomHashTableSize(wid) REMOTE(wid)->ImportAtomHashTableSize_
#define LOCAL_ImportAtomHashTableNum LOCAL->ImportAtomHashTableNum_
#define REMOTE_ImportAtomHashTableNum(wid) REMOTE(wid)->ImportAtomHashTableNum_
#define LOCAL_ImportFunctorHashChain LOCAL->ImportFunctorHashChain_
#define REMOTE_ImportFunctorHashChain(wid) REMOTE(wid)->ImportFunctorHashChain_
#define LOCAL_ImportFunctorHashTableSize LOCAL->ImportFunctorHashTableSize_
#define REMOTE_ImportFunctorHashTableSize(wid) REMOTE(wid)->ImportFunctorHashTableSize_
#define LOCAL_ImportFunctorHashTableNum LOCAL->ImportFunctorHashTableNum_
#define REMOTE_ImportFunctorHashTableNum(wid) REMOTE(wid)->ImportFunctorHashTableNum_
#define LOCAL_ImportOPCODEHashChain LOCAL->ImportOPCODEHashChain_
#define REMOTE_ImportOPCODEHashChain(wid) REMOTE(wid)->ImportOPCODEHashChain_
#define LOCAL_ImportOPCODEHashTableSize LOCAL->ImportOPCODEHashTableSize_
#define REMOTE_ImportOPCODEHashTableSize(wid) REMOTE(wid)->ImportOPCODEHashTableSize_
#define LOCAL_ImportPredEntryHashChain LOCAL->ImportPredEntryHashChain_
#define REMOTE_ImportPredEntryHashChain(wid) REMOTE(wid)->ImportPredEntryHashChain_
#define LOCAL_ImportPredEntryHashTableSize LOCAL->ImportPredEntryHashTableSize_
#define REMOTE_ImportPredEntryHashTableSize(wid) REMOTE(wid)->ImportPredEntryHashTableSize_
#define LOCAL_ImportPredEntryHashTableNum LOCAL->ImportPredEntryHashTableNum_
#define REMOTE_ImportPredEntryHashTableNum(wid) REMOTE(wid)->ImportPredEntryHashTableNum_
#define LOCAL_ImportDBRefHashChain LOCAL->ImportDBRefHashChain_
#define REMOTE_ImportDBRefHashChain(wid) REMOTE(wid)->ImportDBRefHashChain_
#define LOCAL_ImportDBRefHashTableSize LOCAL->ImportDBRefHashTableSize_
#define REMOTE_ImportDBRefHashTableSize(wid) REMOTE(wid)->ImportDBRefHashTableSize_
#define LOCAL_ImportDBRefHashTableNum LOCAL->ImportDBRefHashTableNum_
#define REMOTE_ImportDBRefHashTableNum(wid) REMOTE(wid)->ImportDBRefHashTableNum_
#define LOCAL_ImportFAILCODE LOCAL->ImportFAILCODE_
#define REMOTE_ImportFAILCODE(wid) REMOTE(wid)->ImportFAILCODE_

View File

@@ -16,7 +16,7 @@
cl = NEXTOP(cl,N);
break;
case _ensure_space:
cl = NEXTOP(cl,Osbpi);
cl = NEXTOP(cl,Osbpa);
break;
case _native_me:
cl = NEXTOP(cl,aFlp);

0
H/heapgc.h Executable file → Normal file
View File

View File

@@ -182,10 +182,38 @@ typedef struct worker_local {
Int total_atom_table_overflow_time_;
#ifdef LOAD_DYLD
static dl_errno_;
int dl_errno_;
#endif
#ifdef LOW_LEVEL_TRACER
int do_trace_primitives_;
#endif
struct export_atom_hash_entry_struct **ExportAtomHashChain_;
UInt ExportAtomHashTableSize_;
UInt ExportAtomHashTableNum_;
struct export_functor_hash_entry_struct **ExportFunctorHashChain_;
UInt ExportFunctorHashTableSize_;
UInt ExportFunctorHashTableNum_;
struct export_pred_entry_hash_entry_struct **ExportPredEntryHashChain_;
UInt ExportPredEntryHashTableSize_;
UInt ExportPredEntryHashTableNum_;
struct export_dbref_hash_entry_struct **ExportDBRefHashChain_;
UInt ExportDBRefHashTableSize_;
UInt ExportDBRefHashTableNum_;
struct import_atom_hash_entry_struct **ImportAtomHashChain_;
UInt ImportAtomHashTableSize_;
UInt ImportAtomHashTableNum_;
struct import_functor_hash_entry_struct **ImportFunctorHashChain_;
UInt ImportFunctorHashTableSize_;
UInt ImportFunctorHashTableNum_;
struct import_opcode_hash_entry_struct **ImportOPCODEHashChain_;
UInt ImportOPCODEHashTableSize_;
struct import_pred_entry_hash_entry_struct **ImportPredEntryHashChain_;
UInt ImportPredEntryHashTableSize_;
UInt ImportPredEntryHashTableNum_;
struct import_dbref_hash_entry_struct **ImportDBRefHashChain_;
UInt ImportDBRefHashTableSize_;
UInt ImportDBRefHashTableNum_;
yamop *ImportFAILCODE_;
} w_local;

View File

@@ -188,4 +188,32 @@ static void InitWorker(int wid) {
#ifdef LOW_LEVEL_TRACER
REMOTE_do_trace_primitives(wid) = TRUE;
#endif
REMOTE_ExportAtomHashChain(wid) = NULL;
REMOTE_ExportAtomHashTableSize(wid) = 0;
REMOTE_ExportAtomHashTableNum(wid) = 0;
REMOTE_ExportFunctorHashChain(wid) = NULL;
REMOTE_ExportFunctorHashTableSize(wid) = 0;
REMOTE_ExportFunctorHashTableNum(wid) = 0;
REMOTE_ExportPredEntryHashChain(wid) = NULL;
REMOTE_ExportPredEntryHashTableSize(wid) = 0;
REMOTE_ExportPredEntryHashTableNum(wid) = 0;
REMOTE_ExportDBRefHashChain(wid) = NULL;
REMOTE_ExportDBRefHashTableSize(wid) = 0;
REMOTE_ExportDBRefHashTableNum(wid) = 0;
REMOTE_ImportAtomHashChain(wid) = NULL;
REMOTE_ImportAtomHashTableSize(wid) = 0;
REMOTE_ImportAtomHashTableNum(wid) = 0;
REMOTE_ImportFunctorHashChain(wid) = NULL;
REMOTE_ImportFunctorHashTableSize(wid) = 0;
REMOTE_ImportFunctorHashTableNum(wid) = 0;
REMOTE_ImportOPCODEHashChain(wid) = NULL;
REMOTE_ImportOPCODEHashTableSize(wid) = 0;
REMOTE_ImportPredEntryHashChain(wid) = NULL;
REMOTE_ImportPredEntryHashTableSize(wid) = 0;
REMOTE_ImportPredEntryHashTableNum(wid) = 0;
REMOTE_ImportDBRefHashChain(wid) = NULL;
REMOTE_ImportDBRefHashTableSize(wid) = 0;
REMOTE_ImportDBRefHashTableNum(wid) = 0;
REMOTE_ImportFAILCODE(wid) = NULL;
}

View File

@@ -76,7 +76,6 @@ typedef struct stream_desc
int (* stream_wgetc_for_read)(int);
int (* stream_wgetc)(int);
int (* stream_wputc)(int,wchar_t);
encoding_t encoding;
mbstate_t mbstate;
}
StreamDesc;

298
H/pl-global.h Normal file
View File

@@ -0,0 +1,298 @@
typedef struct _PL_thread_info_t
{ int pl_tid; /* Prolog thread id */
size_t local_size; /* Stack sizes */
size_t global_size;
size_t trail_size;
size_t stack_size; /* system (C-) stack */
int (*cancel)(int id); /* cancel function */
int open_count; /* for PL_thread_detach_engine() */
bool detached; /* detached thread */
int status; /* PL_THREAD_* */
pthread_t tid; /* Thread identifier */
int has_tid; /* TRUE: tid = valid */
#ifdef __linux__
pid_t pid; /* for identifying */
#endif
#ifdef __WINDOWS__
unsigned long w32id; /* Win32 thread HANDLE */
#endif
struct PL_local_data *thread_data; /* The thread-local data */
module_t module; /* Module for starting goal */
record_t goal; /* Goal to start thread */
record_t return_value; /* Value (term) returned */
atom_t name; /* Name of the thread */
ldata_status_t ldata_status; /* status of forThreadLocalData() */
} PL_thread_info_t;
/* The GD global variable */
typedef struct {
int io_initialised;
cleanup_status cleaning; /* Inside PL_cleanup() */
pl_defaults_t defaults; /* system default settings */
struct
{ Table table; /* global (read-only) features */
} prolog_flag;
struct
{ Table tmp_files; /* Known temporary files */
CanonicalDir _canonical_dirlist;
char * myhome; /* expansion of ~ */
char * fred; /* last expanded ~user */
char * fredshome; /* home of fred */
OnHalt on_halt_list; /* list of onhalt hooks */
int halting; /* process is shutting down */
int gui_app; /* Win32: Application is a gui app */
IOFUNCTIONS iofunctions; /* initial IO functions */
IOFUNCTIONS org_terminal; /* IO+Prolog terminal functions */
IOFUNCTIONS rl_functions; /* IO+Terminal+Readline functions */
} os;
struct
{ size_t heap; /* heap in use */
size_t atoms; /* No. of atoms defined */
size_t atomspace; /* # bytes used to store atoms */
size_t stack_space; /* # bytes on stacks */
#ifdef O_ATOMGC
size_t atomspacefreed; /* Freed atom-space */
#endif
int functors; /* No. of functors defined */
int predicates; /* No. of predicates defined */
int modules; /* No. of modules in the system */
intptr_t codes; /* No. of byte codes generated */
#ifdef O_PLMT
int threads_created; /* # threads created */
int threads_finished; /* # finished threads */
double thread_cputime; /* Total CPU time of threads */
#endif
double start_time; /* When Prolog was started */
} statistics;
struct
{ atom_t * array; /* index --> atom */
size_t count; /* elements in array */
atom_t *for_code[256]; /* code --> one-char-atom */
} atoms;
struct
{
int optimise; /* -O: optimised compilation */
} cmdline;
struct
{ ExtensionCell _ext_head; /* head of registered extensions */
ExtensionCell _ext_tail; /* tail of this chain */
InitialiseHandle initialise_head; /* PL_initialise_hook() */
InitialiseHandle initialise_tail;
PL_dispatch_hook_t dispatch_events; /* PL_dispatch_hook() */
int _loaded; /* system extensions are loaded */
} foreign;
#ifdef O_PLMT
FreeChunk left_over_pool; /* Left-over from threads */
struct
{ struct _at_exit_goal *exit_goals; /* Global thread_at_exit/1 goals */
int enabled; /* threads are enabled */
Table mutexTable; /* Name --> mutex table */
int mutex_next_id; /* next id for anonymous mutexes */
struct pl_mutex* MUTEX_load; /* The $load mutex */
#ifdef __WINDOWS__
HINSTANCE instance; /* Win32 process instance */
#endif
counting_mutex *mutexes; /* Registered mutexes */
int thread_max; /* Maximum # threads */
PL_thread_info_t **threads; /* Pointers to thread-info */
} thread;
#endif /*O_PLMT*/
struct /* pl-format.c */
{ Table predicates;
} format;
struct
{/* Procedure dgarbage_collect1; */
/* Procedure catch3; */
/* Procedure true0; */
/* Procedure fail0; */
/* Procedure equals2; /\* =/2 *\/ */
/* Procedure is2; /\* is/2 *\/ */
/* Procedure strict_equal2; /\* ==/2 *\/ */
/* Procedure event_hook1; */
/* Procedure exception_hook4; */
/* Procedure print_message2; */
/* Procedure foreign_registered2; /\* $foreign_registered/2 *\/ */
/* Procedure prolog_trace_interception4; */
predicate_t portray; /* portray/1 */
/* Procedure dcall1; /\* $call/1 *\/ */
/* Procedure setup_call_catcher_cleanup4; /\* setup_call_catcher_cleanup/4 *\/ */
/* Procedure undefinterc4; /\* $undefined_procedure/4 *\/ */
/* Procedure dthread_init0; /\* $thread_init/0 *\/ */
/* Procedure dc_call_prolog0; /\* $c_call_prolog/0 *\/ */
/* #ifdef O_ATTVAR */
/* Procedure dwakeup1; /\* system:$wakeup/1 *\/ */
predicate_t portray_attvar1; /* $attvar:portray_attvar/1 */
/* #endif */
/* #ifdef O_CALL_RESIDUE */
/* Procedure call_residue_vars2; /\* $attvar:call_residue_vars/2 *\/ */
/* #endif */
/* SourceFile reloading; /\* source file we are re-loading *\/ */
/* int active_marked; /\* #prodedures marked active *\/ */
/* int static_dirty; /\* #static dirty procedures *\/ */
/* #ifdef O_CLAUSEGC */
/* DefinitionChain dirty; /\* List of dirty static procedures *\/ */
/* #endif */
} procedures;
} gds_t;
extern gds_t gds;
#define GD (&gds)
/* The LD macro layer */
typedef struct PL_local_data {
struct /* Local IO stuff */
{ IOSTREAM *streams[6]; /* handles for standard streams */
struct input_context *input_stack; /* maintain input stream info */
struct output_context *output_stack; /* maintain output stream info */
} IO;
struct
{ Table table; /* Feature table */
pl_features_t mask; /* Masked access to booleans */
int write_attributes; /* how to write attvars? */
occurs_check_t occurs_check; /* Unify and occurs check */
} feature;
source_location read_source; /* file, line, char of last term */
struct
{ int active; /* doing pipe I/O */
jmp_buf context; /* context of longjmp() */
} pipe;
struct
{ atom_t current; /* current global prompt */
atom_t first; /* how to prompt first line */
int first_used; /* did we do the first line? */
int next; /* prompt on next read operation */
} prompt;
struct
{ Table table; /* Feature table */
pl_features_t mask; /* Masked access to booleans */
int write_attributes; /* how to write attvars? */
occurs_check_t occurs_check; /* Unify and occurs check */
} prolog_flag;
void * glob_info; /* pl-glob.c */
IOENC encoding; /* default I/O encoding */
struct
{ char * _CWDdir;
size_t _CWDlen;
#ifdef __BEOS__
status_t dl_error; /* dlopen() emulation in pl-beos.c */
#endif
int rand_initialised; /* have we initialised random? */
} os;
struct
{ int64_t pending; /* PL_raise() pending signals */
int current; /* currently processing signal */
int is_sync; /* current signal is synchronous */
record_t exception; /* Pending exception from signal */
#ifdef O_PLMT
simpleMutex sig_lock; /* lock delivery and processing */
#endif
} signal;
int critical; /* heap is being modified */
struct
{ term_t term; /* exception term */
term_t bin; /* temporary handle for exception */
term_t printed; /* already printed exception */
term_t tmp; /* tmp for errors */
term_t pending; /* used by the debugger */
int in_hook; /* inside exception_hook() */
int processing; /* processing an exception */
exception_frame *throw_environment; /* PL_throw() environments */
} exception;
const char *float_format; /* floating point format */
struct {
buffer _discardable_buffer; /* PL_*() character buffers */
buffer _buffer_ring[BUFFER_RING_SIZE];
int _current_buffer_id;
} fli;
#ifdef O_GMP
struct
{
int persistent; /* do persistent operations */
} gmp;
#endif
} PL_local_data_t;
#define usedStack(D) 0
#define features (LD->feature.mask)
extern PL_local_data_t lds;
#define exception_term (LD->exception.term)
// THIS HAS TO BE ABSTRACTED
#define GLOBAL_LD (LOCAL_PL_local_data_p)
#if !defined(O_PLMT) && !defined(YAPOR)
#define LOCAL_LD (GLOBAL_LD)
#define LD (GLOBAL_LD)
#define ARG1_LD void
#define ARG_LD
#define GET_LD
#define PRED_LD
#define PASS_LD
#define PASS_LD1
#else
#define LOCAL_LD (__PL_ld)
#define LD LOCAL_LD
#define GET_LD CACHE_REGS PL_local_data_t *__PL_ld = GLOBAL_LD;
#define ARG1_LD PL_local_data_t *__PL_ld
#define ARG_LD , ARG1_LD
#define PASS_LD1 LD
#define PASS_LD , LD
#define PRED_LD GET_LD
#endif
#define Suser_input (LD->IO.streams[0])
#define Suser_output (LD->IO.streams[1])
#define Suser_error (LD->IO.streams[2])
#define Scurin (LD->IO.streams[3])
#define Scurout (LD->IO.streams[4])
#define Sprotocol (LD->IO.streams[5])
#define Sdin Suser_input /* not used for now */
#define Sdout Suser_output
#define source_line_no (LD->read_source.line)
#define source_file_name (LD->read_source.file)
#define source_line_pos (LD->read_source.linepos)
#define source_char_no (LD->read_source.character)

877
H/pl-incl.h Normal file
View File

@@ -0,0 +1,877 @@
#include "config.h"
#if USE_GMP
#define O_GMP 1
#endif
#ifdef __WINDOWS__
#include <windows.h>
#include <uxnt.h>
#define O_HASDRIVES 1
#define O_HASSHARES 1
#endif
#ifndef PL_CONSOLE
#define PL_KERNEL 1
#endif
#ifdef __MINGW32__
#define O_XOS 1
#endif
#ifndef __unix__
#if defined(_AIX) || defined(__APPLE__) || defined(__unix) || defined(__BEOS__) || defined(__NetBSD__)
#define __unix__ 1
#endif
#endif
#ifdef THREADS
#define O_PLMT 1
#endif
#include "Yap.h"
#include "YapHeap.h"
/* try not to pollute the SWI space */
#ifdef P
#undef P
#endif
#ifdef B
#undef B
#endif
#ifdef S
#undef S
#endif
#ifdef H
#undef H
#endif
/* vsc: needs defining before getting rid of YAP locks */
static inline int
do_startCritical(void) {
CACHE_REGS
YAPEnterCriticalSection();
return 1;
}
static inline int
do_endCritical(void) {
CACHE_REGS
YAPLeaveCriticalSection();
return 1;
}
#define startCritical do_startCritical()
#define endCritical do_endCritical()
#ifdef LOCK
#undef LOCK
#endif
#ifdef UNLOCK
#undef UNLOCK
#endif
#include <SWI-Stream.h>
#include <SWI-Prolog.h>
typedef int bool;
typedef int Char; /* char that can pass EOF */
typedef uintptr_t word; /* Anonymous 4 byte object */
#if SIZE_DOUBLE==SIZEOF_INT_P
#define WORDS_PER_DOUBLE 1
#else
#define WORDS_PER_DOUBLE 2
#endif
// numbers
typedef enum
{ V_INTEGER, /* integer (64-bit) value */
#ifdef O_GMP
V_MPZ, /* mpz_t */
V_MPQ, /* mpq_t */
#endif
V_FLOAT /* Floating point number (double) */
} numtype;
typedef struct
{ numtype type; /* type of number */
union { double f; /* value as real */
int64_t i; /* value as integer */
word w[WORDS_PER_DOUBLE]; /* for packing/unpacking the double */
#ifdef O_GMP
mpz_t mpz; /* GMP integer */
mpq_t mpq; /* GMP rational */
#endif
} value;
} number, *Number;
#define TOINT_CONVERT_FLOAT 0x1 /* toIntegerNumber() */
#define TOINT_TRUNCATE 0x2
#ifdef O_GMP
#define intNumber(n) ((n)->type <= V_MPZ)
#else
#define intNumber(n) ((n)->type < V_FLOAT)
#endif
#define floatNumber(n) ((n)->type >= V_FLOAT)
typedef enum
{ NUM_ERROR = FALSE, /* Syntax error */
NUM_OK = TRUE, /* Ok */
NUM_FUNDERFLOW = -1, /* Float underflow */
NUM_FOVERFLOW = -2, /* Float overflow */
NUM_IOVERFLOW = -3 /* Integer overflow */
} strnumstat;
#define Arg(N) (PL__t0+((n)-1))
#define A1 (PL__t0)
#define A2 (PL__t0+1)
#define A3 (PL__t0+2)
#define A3 (PL__t0+2)
#define A4 (PL__t0+3)
#define A5 (PL__t0+4)
#define A6 (PL__t0+5)
#define A7 (PL__t0+6)
#define A8 (PL__t0+7)
#define A9 (PL__t0+8)
#define A10 (PL__t0+9)
/* atom_t macro layer */
#define NULL_ATOM ((atom_t)0)
#if __YAP_PROLOG__
#include "dswiatoms.h"
#else
#include "atoms.h"
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#define COMMON(X) X
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#include <setjmp.h>
#include <assert.h>
#if HAVE_SYS_PARAM_H
#include <sys/param.h> //MAXPATHLEN
#endif
#if __YAP_PROLOG__
#include "pl-yap.h"
#if _WIN32
typedef int pthread_t;
#define __WINDOWS__ 1
#else
#include <pthread.h>
#endif
#endif
typedef uintptr_t PL_atomic_t; /* same a word */
#define MAXSIGNAL 64
#define SIG_PROLOG_OFFSET 32 /* Start of Prolog signals */
#define SIG_EXCEPTION (SIG_PROLOG_OFFSET+0)
#ifdef O_ATOMGC
#define SIG_ATOM_GC (SIG_PROLOG_OFFSET+1)
#endif
#define SIG_GC (SIG_PROLOG_OFFSET+2)
#ifdef O_PLMT
#define SIG_THREAD_SIGNAL (SIG_PROLOG_OFFSET+3)
#endif
#define SIG_FREECLAUSES (SIG_PROLOG_OFFSET+4)
#define SIG_PLABORT (SIG_PROLOG_OFFSET+5)
#define LOCAL_OVERFLOW (-1)
#define GLOBAL_OVERFLOW (-2)
#define TRAIL_OVERFLOW (-3)
#define ARGUMENT_OVERFLOW (-4)
/********************************
* UTILITIES *
*********************************/
#define ROUND(p, n) ((((p) + (n) - 1) & ~((n) - 1)))
/********************************
* HASH TABLES *
*********************************/
#include "pl-table.h"
/********************************
* OS *
*********************************/
#include "pl-os.h"
/********************************
* Error *
*********************************/
#include "pl-error.h"
/********************************
* Files *
*********************************/
#include "pl-files.h"
/********************************
* BUFFERS *
*********************************/
#define BUFFER_RING_SIZE 16 /* foreign buffer ring (pl-fli.c) */
#include "pl-buffer.h"
/*******************************
* OPTION LISTS *
*******************************/
#include "pl-option.h"
/*******************************
* TEXT PROCESSING *
*******************************/
typedef enum
{ CVT_ok = 0, /* Conversion ok */
CVT_wide, /* Conversion needs wide characters */
CVT_partial, /* Input list is partial */
CVT_nolist, /* Input list is not a list */
CVT_nocode, /* List contains a non-code */
CVT_nochar /* List contains a non-char */
} CVT_status;
typedef struct
{ CVT_status status;
word culprit; /* for CVT_nocode/CVT_nochar */
} CVT_result;
#define MAXNEWLINES 5 /* maximum # of newlines in atom */
#define LONGATOM_CHECK 0x01 /* read/1: error on intptr_t atoms */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Operator types. NOTE: if you change OP_*, check operatorTypeToAtom()!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#define OP_MAXPRIORITY 1200 /* maximum operator priority */
#define OP_PREFIX 0
#define OP_INFIX 1
#define OP_POSTFIX 2
#define OP_MASK 0xf
#define OP_FX (0x10|OP_PREFIX)
#define OP_FY (0x20|OP_PREFIX)
#define OP_XF (0x30|OP_POSTFIX)
#define OP_YF (0x40|OP_POSTFIX)
#define OP_XFX (0x50|OP_INFIX)
#define OP_XFY (0x60|OP_INFIX)
#define OP_YFX (0x70|OP_INFIX)
#define CHARESCAPE (0x0004) /* module */
/*******************************
* COMPARE *
*******************************/
/* Results from comparison operations. Mostly used by compareStandard() */
#define CMP_ERROR -2 /* Error (out of memory) */
#define CMP_LESS -1 /* < */
#define CMP_EQUAL 0 /* == */
#define CMP_GREATER 1 /* > */
#define CMP_NOTEQ 2 /* \== */
/*******************************
* NUMBERVARS *
*******************************/
typedef enum
{ AV_BIND,
AV_SKIP,
AV_ERROR
} av_action;
typedef struct
{ functor_t functor; /* Functor to use ($VAR/1) */
av_action on_attvar; /* How to handle attvars */
int singletons; /* Write singletons as $VAR('_') */
} nv_options;
/*******************************
* GET-PROCEDURE *
*******************************/
#define GP_FIND 0 /* find anywhere */
#define GP_FINDHERE 1 /* find in this module */
#define GP_CREATE 2 /* create (in this module) */
#define GP_DEFINE 4 /* define a procedure */
#define GP_RESOLVE 5 /* find defenition */
#define GP_HOW_MASK 0x0ff
#define GP_NAMEARITY 0x100 /* or'ed mask */
#define GP_HIDESYSTEM 0x200 /* hide system module */
#define GP_TYPE_QUIET 0x400 /* don't throw errors on wrong types */
#define GP_EXISTENCE_ERROR 0x800 /* throw error if proc is not found */
#define GP_QUALIFY 0x1000 /* Always module-qualify */
/* get_functor() */
#define GF_EXISTING 1
#define GF_PROCEDURE 2 /* check for max arity */
#ifdef O_PLMT
typedef struct free_chunk *FreeChunk; /* left-over chunk */
struct free_chunk
{ FreeChunk next; /* next of chain */
size_t size; /* size of free bit */
};
#endif
/*******************************
* LIST BUILDING *
*******************************/
#include "pl-privitf.h"
typedef enum
{ CLN_NORMAL = 0, /* Normal mode */
CLN_ACTIVE, /* Started cleanup */
CLN_FOREIGN, /* Foreign hooks */
CLN_PROLOG, /* Prolog hooks */
CLN_SHARED, /* Unload shared objects */
CLN_DATA /* Remaining data */
} cleanup_status;
typedef struct
{ char *state; /* system's boot file */
char *startup; /* default user startup file */
int local; /* default local stack size (K) */
int global; /* default global stack size (K) */
int trail; /* default trail stack size (K) */
char *goal; /* default initialisation goal */
char *toplevel; /* default top level goal */
bool notty; /* use tty? */
char *arch; /* machine/OS we are using */
char *home; /* systems home directory */
} pl_defaults_t;
typedef enum
{ LDATA_IDLE = 0,
LDATA_SIGNALLED,
LDATA_ANSWERING,
LDATA_ANSWERED
} ldata_status_t;
typedef struct tempfile * TempFile; /* pl-os.c */
typedef struct canonical_dir * CanonicalDir; /* pl-os.c */
typedef struct on_halt * OnHalt; /* pl-os.c */
typedef struct extension_cell * ExtensionCell; /* pl-ext.c */
typedef struct initialise_handle * InitialiseHandle;
typedef struct
{ unsigned long flags; /* Fast access to some boolean Prolog flags */
} pl_features_t;
#define truePrologFlag(flag) true(&LD->prolog_flag.mask, flag)
#define setPrologFlagMask(flag) set(&LD->prolog_flag.mask, flag)
#define clearPrologFlagMask(flag) clear(&LD->prolog_flag.mask, flag)
// LOCAL variables (heap will get this form LOCAL
#define FT_ATOM 0 /* atom feature */
#define FT_BOOL 1 /* boolean feature (true, false) */
#define FT_INTEGER 2 /* integer feature */
#define FT_FLOAT 3 /* float feature */
#define FT_TERM 4 /* term feature */
#define FT_INT64 5 /* passed as int64_t */
#define FT_FROM_VALUE 0x0f /* Determine type from value */
#define FT_MASK 0x0f /* mask to get type */
#define FF_READONLY 0x10 /* feature is read-only */
#define FF_KEEP 0x20 /* keep value it already set */
#define PLFLAG_CHARESCAPE 0x000001 /* handle \ in atoms */
#define PLFLAG_GC 0x000002 /* do GC */
#define PLFLAG_TRACE_GC 0x000004 /* verbose gc */
#define PLFLAG_TTY_CONTROL 0x000008 /* allow for tty control */
#define PLFLAG_READLINE 0x000010 /* readline is loaded */
#define PLFLAG_DEBUG_ON_ERROR 0x000020 /* start tracer on error */
#define PLFLAG_REPORT_ERROR 0x000040 /* print error message */
#define PLFLAG_FILE_CASE 0x000080 /* file names are case sensitive */
#define PLFLAG_FILE_CASE_PRESERVING 0x000100 /* case preserving file names */
#define PLFLAG_DOS_FILE_NAMES 0x000200 /* dos (8+3) file names */
#define ALLOW_VARNAME_FUNCTOR 0x000400 /* Read Foo(x) as 'Foo'(x) */
#define PLFLAG_ISO 0x000800 /* Strict ISO compliance */
#define PLFLAG_OPTIMISE 0x001000 /* -O: optimised compilation */
#define PLFLAG_FILEVARS 0x002000 /* Expand $var and ~ in filename */
#define PLFLAG_AUTOLOAD 0x004000 /* do autoloading */
#define PLFLAG_CHARCONVERSION 0x008000 /* do character-conversion */
#define PLFLAG_LASTCALL 0x010000 /* Last call optimization enabled? */
#define PLFLAG_EX_ABORT 0x020000 /* abort with exception */
#define PLFLAG_BACKQUOTED_STRING 0x040000 /* `a string` */
#define PLFLAG_SIGNALS 0x080000 /* Handle signals */
#define PLFLAG_DEBUGINFO 0x100000 /* generate debug info */
#define PLFLAG_FILEERRORS 0x200000 /* Edinburgh file errors */
typedef enum
{ OCCURS_CHECK_FALSE = 0,
OCCURS_CHECK_TRUE,
OCCURS_CHECK_ERROR
} occurs_check_t;
typedef struct
{ atom_t file; /* current source file */
int line; /* current line */
int linepos; /* position in the line */
int64_t character; /* current character location */
} source_location;
typedef struct exception_frame /* PL_throw exception environments */
{ struct exception_frame *parent; /* parent frame */
jmp_buf exception_jmp_env; /* longjmp environment */
} exception_frame;
/* vsc: global variables */
#include "pl-global.h"
#define EXCEPTION_GUARDED(code, cleanup) \
{ exception_frame __throw_env; \
__throw_env.parent = LD->exception.throw_environment; \
if ( setjmp(__throw_env.exception_jmp_env) != 0 ) \
{ LD->exception.throw_environment = __throw_env.parent; \
cleanup; \
} else \
{ LD->exception.throw_environment = &__throw_env; \
code; \
LD->exception.throw_environment = __throw_env.parent; \
} \
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
At times an abort is not allowed because the heap is inconsistent the
programmer should call startCritical to start such a code region and
endCritical to end it.
MT/TBD: how to handle this gracefully in the multi-threading case. Does
it mean anything?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define succeed return TRUE
#define fail return FALSE
#define TRY(goal) if ((goal) == FALSE) fail
extern int fileerrors;
extern int ttymode;
#define CHARESCAPE_FEATURE 0x00001 /* handle \ in atoms */
#define GC_FEATURE 0x00002 /* do GC */
#define TRACE_GC_FEATURE 0x00004 /* verbose gc */
#define TTY_CONTROL_FEATURE 0x00008 /* allow for tty control */
#define READLINE_FEATURE 0x00010 /* readline is loaded */
#define DEBUG_ON_ERROR_FEATURE 0x00020 /* start tracer on error */
#define REPORT_ERROR_FEATURE 0x00040 /* print error message */
#define FILE_CASE_FEATURE 0x00080 /* file names are case sensitive */
#define FILE_CASE_PRESERVING_FEATURE 0x0100 /* case preserving file names */
#define DOS_FILE_NAMES_FEATURE 0x00200 /* dos (8+3) file names */
#define ISO_FEATURE 0x00800 /* Strict ISO compliance */
#define OPTIMISE_FEATURE 0x01000 /* -O: optimised compilation */
#define FILEVARS_FEATURE 0x02000 /* Expand $var and ~ in filename */
#define AUTOLOAD_FEATURE 0x04000 /* do autoloading */
#define CHARCONVERSION_FEATURE 0x08000 /* do character-conversion */
#define LASTCALL_FEATURE 0x10000 /* Last call optimization enabled? */
#define EX_ABORT_FEATURE 0x20000 /* abort with exception */
#define BACKQUOTED_STRING_FEATURE 0x40000 /* `a string` */
#define SIGNALS_FEATURE 0x80000 /* Handle signals */
#define DEBUGINFO_FEATURE 0x100000 /* generate debug info */
int defFeature(const char *c, int f, ...);
int trueFeature(int f);
/*******************************
* WAKEUP *
*******************************/
#define WAKEUP_STATE_WAKEUP 0x1
#define WAKEUP_STATE_EXCEPTION 0x2
#define WAKEUP_STATE_SKIP_EXCEPTION 0x4
typedef struct wakeup_state
{ fid_t fid; /* foreign frame reference */
int flags;
} wakeup_state;
/*******************************
* STREAM I/O *
*******************************/
#define REDIR_MAGIC 0x23a9bef3
typedef struct redir_context
{ int magic; /* REDIR_MAGIC */
IOSTREAM *stream; /* temporary output */
int is_stream; /* redirect to stream */
int redirected; /* output is redirected */
term_t term; /* redirect target */
int out_format; /* output type */
int out_arity; /* 2 for difference-list versions */
size_t size; /* size of I/O buffer */
char *data; /* data written */
char buffer[1024]; /* fast temporary buffer */
} redir_context;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Defining built-in predicates using the new interface
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#define EOS '\0'
#define ESC ((char) 27)
#define streq(s, q) ((strcmp((s), (q)) == 0))
#define CHAR_MODE 0 /* See PL_unify_char() */
#define CODE_MODE 1
#define BYTE_MODE 2
/* string stuff */
/*******************************
* STRING SUPPORT *
*******************************/
char * store_string(const char *s);
void remove_string(char *s);
/* from foreign interface */
/*******************************
* FILENAME SUPPORT *
*******************************/
#define PL_FILE_ABSOLUTE 0x01 /* return absolute path */
#define PL_FILE_OSPATH 0x02 /* return path in OS notation */
#define PL_FILE_SEARCH 0x04 /* use file_search_path */
#define PL_FILE_EXIST 0x08 /* demand file to exist */
#define PL_FILE_READ 0x10 /* demand read-access */
#define PL_FILE_WRITE 0x20 /* demand write-access */
#define PL_FILE_EXECUTE 0x40 /* demand execute-access */
#define PL_FILE_NOERRORS 0x80 /* do not raise exceptions */
#define PL_FA_ISO (0x20) /* Internal: ISO core predicate */
/********************************
* READ WARNINGS *
*********************************/
#define ReadingSource (source_line_no > 0 && \
source_file_name != NULL_ATOM)
#include <pl-text.h>
typedef double real;
#define true(s, a) ((s)->flags & (a))
#define false(s, a) (!true((s), (a)))
#define set(s, a) ((s)->flags |= (a))
#define clear(s, a) ((s)->flags &= ~(a))
#ifdef DEBUG
/* should have messages here */
#undef DEBUG
#define DEBUG(LEVEL, COMMAND)
#else
#define DEBUG(LEVEL, COMMAND)
#endif
#define forwards static /* forwards function declarations */
/* uxnt package interface */
#if defined(__YAP_PROLOG__) && defined(__MINGW32__)
#ifndef __WINDOWS__
#define __WINDOWS__ 1
#endif
#endif
extern int PL_unify_char(term_t chr, int c, int how);
extern int PL_get_char(term_t chr, int *c, int eof);
extern void PL_cleanup_fork(void);
extern int PL_rethrow(void);
extern void PL_get_number(term_t l, number *n);
extern int PL_unify_atomic(term_t t, PL_atomic_t a);
extern int _PL_unify_atomic(term_t t, PL_atomic_t a);
extern int _PL_unify_string(term_t t, word w);
#define _PL_get_arg(X,Y,Z) PL_get_arg(X,Y,Z)
extern IOSTREAM ** /* provide access to Suser_input, */
_PL_streams(void); /* Suser_output and Suser_error */
extern int get_atom_text(atom_t atom, PL_chars_t *text);
COMMON(int) get_string_text(atom_t atom, PL_chars_t *text ARG_LD);
extern char *format_float(double f, char *buf);
/**** stuff from pl-ctype.c ****/
extern IOENC initEncoding(void);
/**** stuff from pl-error.c ****/
extern int PL_get_bool_ex(term_t t, int *i);
extern int PL_get_nchars_ex(term_t t, size_t *len, char **s, unsigned int flags);
extern int PL_get_chars_ex(term_t t, char **s, unsigned int flags);
extern int PL_get_integer_ex(term_t t, int *i);
extern int PL_get_long_ex(term_t t, long *i);
extern int PL_get_int64_ex(term_t t, int64_t *i);
extern int PL_get_intptr_ex(term_t t, intptr_t *i);
extern int PL_get_bool_ex(term_t t, int *i);
extern int PL_get_float_ex(term_t t, double *f);
extern int PL_get_char_ex(term_t t, int *p, int eof);
extern int PL_unify_list_ex(term_t l, term_t h, term_t t);
extern int PL_unify_nil_ex(term_t l);
extern int PL_get_list_ex(term_t l, term_t h, term_t t);
extern int PL_get_nil_ex(term_t l);
extern int PL_unify_bool_ex(term_t t, bool val);
extern int PL_unify_bool_ex(term_t t, bool val);
extern int PL_get_bool_ex(term_t t, int *i);
extern int PL_get_integer_ex(term_t t, int *i);
extern int PL_get_module_ex(term_t t, module_t *m);
/**** stuff from pl-file.c ****/
extern void initIO(void);
extern void dieIO(void);
extern void protocol(const char *str, size_t n);
extern bool readLine(IOSTREAM *in, IOSTREAM *out, char *buffer);
extern bool tellString(char **s, size_t *size, IOENC enc);
extern bool tellString(char **s, size_t *size, IOENC enc);
extern bool toldString(void);
extern int setupOutputRedirect(term_t to, redir_context *ctx, int redir);
extern void discardOutputRedirect(redir_context *ctx);
extern int closeOutputRedirect(redir_context *ctx);
extern IOENC atom_to_encoding(atom_t);
void closeFiles(int);
atom_t PrologPrompt(void);
word pl_current_input(term_t);
word pl_current_output(term_t);
word pl_exists_file(term_t name);
char *DirName(const char *f, char *dir);
void outOfCore(void);
word pl_noprotocol(void);
IOSTREAM *PL_current_input(void);
IOSTREAM *PL_current_output(void);
COMMON(int) stricmp(const char *s1, const char *s2);
COMMON(word) textToString(PL_chars_t *text);
COMMON(int) reportStreamError(IOSTREAM *s);
extern int digitValue(int b, int c);
PL_EXPORT(int) PL_unify_stream(term_t t, IOSTREAM *s);
PL_EXPORT(int) PL_unify_stream_or_alias(term_t t, IOSTREAM *s);
PL_EXPORT(int) PL_get_stream_handle(term_t t, IOSTREAM **s);
PL_EXPORT(void) PL_write_prompt(int);
PL_EXPORT(int) PL_release_stream(IOSTREAM *s);
COMMON(atom_t) fileNameStream(IOSTREAM *s);
COMMON(int) streamStatus(IOSTREAM *s);
COMMON(int) getOutputStream(term_t t, IOSTREAM **s);
COMMON(void) pushOutputContext(void);
COMMON(void) popOutputContext(void);
COMMON(int) getSingleChar(IOSTREAM *s, int signals);
COMMON(void) prompt1(atom_t prompt);
COMMON(atom_t) encoding_to_atom(IOENC enc);
COMMON(int) pl_see(term_t f);
COMMON(int) pl_seen(void);
COMMON(int) unicode_separator(pl_wchar_t c);
COMMON(word) pl_raw_read(term_t term);
COMMON(word) pl_raw_read2(term_t stream, term_t term);
/**** stuff from pl-error.c ****/
extern void outOfCore(void);
extern void fatalError(const char *fm, ...);
extern int callProlog(void * module, term_t goal, int flags, term_t *ex);
extern word notImplemented(char *name, int arity);
/**** stuff from pl-ctype.c ****/
extern void initCharTypes(void);
/**** stuff from pl-fmt.c ****/
COMMON(word) pl_current_format_predicate(term_t chr, term_t descr,
control_t h);
COMMON(intptr_t) lengthList(term_t list, int errors);
COMMON(word) pl_format_predicate(term_t chr, term_t descr);
COMMON(word) pl_format(term_t fmt, term_t args);
COMMON(word) pl_format3(term_t s, term_t fmt, term_t args);
/**** stuff from pl-glob.c ****/
extern void initGlob(void);
/**** stuff from pl-os.c ****/
extern void cleanupOs(void);
extern void PL_clock_wait_ticks(long waited);
extern void setOSFeatures(void);
extern uintptr_t FreeMemory(void);
extern uint64_t _PL_Random(void);
extern void RemoveTemporaryFiles(void);
extern int Pause(real t);
char *findExecutable(const char *av0, char *buffer);
extern void setOSPrologFlags(void);
extern void setRandom(unsigned int *seedp);
extern char *canoniseFileName(char *path);
extern char *canonisePath(char *path);
extern void PL_changed_cwd(void);
extern struct tm *LocalTime(long *t, struct tm *r);
extern size_t getenv3(const char *name, char *buf, size_t len);
extern int Setenv(char *name, char *value);
extern int Unsetenv(char *name);
extern int System(char *cmd);
extern bool expandVars(const char *pattern, char *expanded, int maxlen);
/**** SWI stuff (emulated in pl-yap.c) ****/
extern int writeAtomToStream(IOSTREAM *so, atom_t at);
extern int valueExpression(term_t t, Number r ARG_LD);
extern word lookupAtom(const char *s, size_t len);
extern atom_t lookupUCSAtom(const pl_wchar_t *s, size_t len);
extern int toIntegerNumber(Number n, int flags);
extern int get_atom_ptr_text(Atom a, PL_chars_t *text);
extern int warning(const char *fm, ...);
/**** stuff from pl-files.c ****/
void initFiles(void);
int RemoveFile(const char *path);
int PL_get_file_name(term_t n, char **namep, int flags);
PL_EXPORT(int) PL_get_file_nameW(term_t n, wchar_t **name, int flags);
COMMON(int) unifyTime(term_t t, time_t time);
COMMON(char) digitName(int n, int sm);
/**** stuff from pl-utf8.c ****/
size_t utf8_strlen(const char *s, size_t len);
/**** stuff from pl-write.c ****/
COMMON(char *) varName(term_t var, char *buf);
COMMON(int) writeUCSAtom(IOSTREAM *fd, atom_t atom, int flags);
COMMON(word) pl_nl1(term_t stream);
COMMON(word) pl_nl(void);
COMMON(int) writeAttributeMask(atom_t name);
COMMON(word) pl_write_term(term_t term, term_t options);
COMMON(word) pl_write_term3(term_t stream,
term_t term, term_t options);
COMMON(word) pl_print(term_t term);
COMMON(word) pl_write2(term_t stream, term_t term);
COMMON(word) pl_writeq2(term_t stream, term_t term);
COMMON(word) pl_print2(term_t stream, term_t term);
COMMON(word) pl_writeln(term_t term);
COMMON(word) pl_write_canonical2(term_t stream, term_t term);
/* empty stub */
extern void setPrologFlag(const char *name, int flags, ...);
extern int PL_set_prolog_flag(const char *name, int flags, ...);
extern install_t PL_install_readline(void);
COMMON(int) saveWakeup(wakeup_state *state, int forceframe ARG_LD);
COMMON(void) restoreWakeup(wakeup_state *state ARG_LD);
COMMON(int) priorityOperator(Module m, atom_t atom);
COMMON(int) currentOperator(Module m, atom_t name, int kind,
int *type, int *priority);
COMMON(int) numberVars(term_t t, nv_options *opts, int n ARG_LD);
COMMON(Buffer) codes_or_chars_to_buffer(term_t l, unsigned int flags,
int wide, CVT_result *status);
COMMON(bool) systemMode(bool accept);
COMMON(void) initPrologFlagTable(void);
COMMON(void) initPrologFlags(void);
COMMON(int) raiseStackOverflow(int overflow);
static inline word
setBoolean(int *flag, term_t old, term_t new)
{ if ( !PL_unify_bool_ex(old, *flag) ||
!PL_get_bool_ex(new, flag) )
fail;
succeed;
}
COMMON(int) getInputStream__LD(term_t t, IOSTREAM **s ARG_LD);
COMMON(int) PL_get_atom__LD(term_t t1, atom_t *a ARG_LD);
COMMON(int) PL_get_atom_ex__LD(term_t t, atom_t *a ARG_LD);
COMMON(int) PL_get_text__LD(term_t l, PL_chars_t *text, int flags ARG_LD);
COMMON(int) PL_is_variable__LD(term_t t ARG_LD);
COMMON(term_t) PL_new_term_ref__LD(ARG1_LD);
COMMON(void) PL_put_term__LD(term_t t1, term_t t2 ARG_LD);
COMMON(int) PL_unify_atom__LD(term_t t, atom_t a ARG_LD);
COMMON(int) PL_unify_integer__LD(term_t t1, intptr_t i ARG_LD);
COMMON(word) pl_get_prolog_flag(term_t key, term_t value);
COMMON(word) pl_prolog_flag5(term_t key, term_t value, word scope, word access, word type, control_t h);
COMMON(foreign_t) pl_prolog_flag(term_t name, term_t value, control_t h);
/* inlines that need ARG_LD */
static inline intptr_t
skip_list(Word l, Word *tailp ARG_LD) {
return (intptr_t)YAP_SkipList(l, tailp);
}
static inline word
valHandle__LD(term_t r ARG_LD)
{
return (word)YAP_GetFromSlot(r);
}
static inline void *allocHeap__LD(size_t n ARG_LD)
{
return YAP_AllocSpaceFromYap(n);
}
static inline void freeHeap__LD(void *mem, size_t n ARG_LD)
{
YAP_FreeSpaceFromYap(mem);
}
extern const PL_extension PL_predicates_from_ctype[];
extern const PL_extension PL_predicates_from_file[];
extern const PL_extension PL_predicates_from_files[];
extern const PL_extension PL_predicates_from_glob[];
extern const PL_extension PL_predicates_from_read[];
extern const PL_extension PL_predicates_from_tai[];
extern const PL_extension PL_predicates_from_write[];
extern const PL_extension PL_predicates_from_prologflag[];

227
H/pl-yap.h Normal file
View File

@@ -0,0 +1,227 @@
#ifndef PL_YAP_H
#define PL_YAP_H
#ifdef __YAP_PROLOG__
/* depends on tag schema, but 4 should always do */
#define LMASK_BITS 4 /* total # mask bits */
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#define SIZE_VOIDP SIZEOF_INT_P
#if SIZEOF_LONG_INT==4
#define INT64_FORMAT "%lld"
#else
#define INT64_FORMAT "%ld"
#endif
#define INTBITSIZE (sizeof(int)*8)
typedef module_t Module;
typedef YAP_Term *Word; /* Anonymous 4 byte object */
typedef YAP_Term (*Func)(term_t); /* foreign functions */
extern const char *Yap_GetCurrentPredName(void);
extern YAP_Int Yap_GetCurrentPredArity(void);
extern int Yap_read_term(term_t t, IOSTREAM *st, term_t *exc, term_t vs);
extern int Yap_LookupSWIStream(void *swi_s);
extern term_t Yap_fetch_module_for_format(term_t args, YAP_Term *modp);
extern IOENC Yap_DefaultEncoding(void);
extern void Yap_SetDefaultEncoding(IOENC);
extern atom_t codeToAtom(int chrcode);
#define valTermRef(t) ((Word)YAP_AddressFromSlot(t))
#include "pl-codelist.h"
//move this to SWI
#define GP_CREATE 2 /* create (in this module) */
#ifndef HAVE_MBSCOLL
COMMON(int) mbscoll(const char *s1, const char *s2);
#endif
#ifndef HAVE_MBSCASECOLL
COMMON(int) mbscasecoll(const char *s1, const char *s2);
#endif
COMMON(atom_t) TemporaryFile(const char *id, int *fdp);
COMMON(char *) Getenv(const char *, char *buf, size_t buflen);
/*** memory allocation stuff: SWI wraps around malloc */
#define stopItimer()
COMMON(word) pl_print(term_t term);
COMMON(word) pl_write(term_t term);
COMMON(word) pl_write_canonical(term_t term);
COMMON(word) pl_write_term(term_t term, term_t options);
COMMON(word) pl_writeq(term_t term);
static inline int
get_procedure(term_t descr, predicate_t *proc, term_t he, int f) {
YAP_Term t = YAP_GetFromSlot(descr);
if (YAP_IsVarTerm(t)) return 0;
if (YAP_IsAtomTerm(t))
*proc = YAP_Predicate(YAP_AtomOfTerm(t),0,YAP_CurrentModule());
else if (YAP_IsApplTerm(t)) {
YAP_Functor f = YAP_FunctorOfTerm(t);
*proc = YAP_Predicate(YAP_NameOfFunctor(f),YAP_ArityOfFunctor(f),YAP_CurrentModule());
}
return 1;
}
COMMON(intptr_t) lengthList(term_t list, int errors);
COMMON(int) promoteToFloatNumber(Number n);
COMMON(char *) PrologPath(const char *ospath, char *plpath, size_t len);
COMMON(char *) ExpandOneFile(const char *spec, char *file);
COMMON(char *) AbsoluteFile(const char *spec, char *path);
COMMON(char *) BaseName(const char *f);
COMMON(bool) ChDir(const char *path);
COMMON(char *) OsPath(const char *plpath, char *ospath);
COMMON(bool) ChDir(const char *path);
COMMON(int) DeleteTemporaryFile(atom_t name);
COMMON(int) IsAbsolutePath(const char *spec);
/* TBD */
extern word globalString(size_t size, char *s);
extern word globalWString(size_t size, wchar_t *s);
#define allocHeap(n) allocHeap__LD(n PASS_LD)
#define freeHeap(p, n) freeHeap__LD(p, n PASS_LD)
#define valHandle(r) valHandle__LD(r PASS_LD)
YAP_Int YAP_PLArityOfSWIFunctor(functor_t f);
YAP_Atom YAP_AtomFromSWIAtom(atom_t at);
atom_t YAP_SWIAtomFromAtom(YAP_Atom at);
PL_blob_t* YAP_find_blob_type(YAP_Atom at);
void PL_license(const char *license, const char *module);
#define arityFunctor(f) YAP_PLArityOfSWIFunctor(f)
#define stringAtom(w) YAP_AtomName(YAP_AtomFromSWIAtom(w))
#define isInteger(A) (YAP_IsIntTerm((A)) || YAP_IsBigNumTerm((A)))
#define isString(A) Yap_IsStringTerm(A)
#define isAtom(A) YAP_IsAtomTerm((A))
#define isList(A) YAP_IsPairTerm((A))
#define isNil(A) ((A) == YAP_TermNil())
#define isReal(A) YAP_IsFloatTerm((A))
#define isFloat(A) YAP_IsFloatTerm((A))
#define isVar(A) YAP_IsVarTerm((A))
#define valReal(w) YAP_FloatOfTerm((w))
#define valFloat(w) YAP_FloatOfTerm((w))
#define AtomLength(w) YAP_AtomNameLength(w)
#define atomValue(atom) YAP_AtomFromSWIAtom(atom)
#define atomFromTerm(term) YAP_SWIAtomFromAtom(YAP_AtomOfTerm(term))
#define atomName(atom) ((char *)YAP_AtomName(atom))
#define nameOfAtom(atom) ((char *)YAP_AtomName(atom))
inline static size_t
atomLength(Atom atom)
{
if (YAP_IsWideAtom(atom))
return wcslen(atom->WStrOfAE)*sizeof(wchar_t);
return(strlen(atom->StrOfAE));
}
#define atomBlobType(at) YAP_find_blob_type(at)
#define argTermP(w,i) ((Word)((YAP_ArgsOfTerm(w)+(i))))
#define deRef(t) while (IsVarTerm(*(t)) && !IsUnboundVar(t)) { t = (CELL *)(*(t)); }
#define canBind(t) FALSE // VSC: to implement
#define MODULE_user YAP_ModuleUser()
#define _PL_predicate(A,B,C,D) PL_predicate(A,B,C)
#define predicateHasClauses(A) (YAP_NumberOfClausesForPredicate((YAP_PredEntryPtr)A) != 0)
#define lookupModule(A) ((Module)PL_new_module(A))
#define charEscapeWriteOption(A) FALSE // VSC: to implement
#define wordToTermRef(A) YAP_InitSlot(*(A))
#define isTaggedInt(A) IsIntegerTerm(A)
#define valInt(A) IntegerOfTerm(A)
#define MODULE_parse ((Module)CurrentModule)
extern term_t Yap_CvtTerm(term_t ts);
#define clearNumber(n)
wchar_t *nameOfWideAtom(atom_t atom);
int isWideAtom(atom_t atom);
inline static int
charCode(Term w)
{ if ( IsAtomTerm(w) )
{
YAP_Atom a = atomValue(w);
if ( YAP_AtomNameLength(a) == 1) {
if (YAP_IsWideAtom(a)) {
return YAP_WideAtomName(a)[0];
}
return YAP_AtomName(a)[0];
}
}
return -1;
}
#define getInputStream(t, s) getInputStream__LD(t, s PASS_LD)
#define PL_get_atom(t, a) PL_get_atom__LD(t, a PASS_LD)
#define PL_get_atom_ex(t, a) PL_get_atom_ex__LD(t, a PASS_LD)
#define PL_get_text(l, t, f) PL_get_text__LD(l, t, f PASS_LD)
#define PL_is_variable(t) PL_is_variable__LD(t PASS_LD)
#define PL_new_term_ref() PL_new_term_ref__LD(PASS_LD1)
#define PL_put_term(t1, t2) PL_put_term__LD(t1, t2 PASS_LD)
#define PL_unify_atom(t, a) PL_unify_atom__LD(t, a PASS_LD)
#define PL_unify_integer(t, i) PL_unify_integer__LD(t, i PASS_LD)
#endif /* __YAP_PROLOG__ */
#if IN_PL_OS_C
static int
stripostfix(const char *s, const char *e)
{ size_t ls = strlen(s);
size_t le = strlen(e);
if ( ls >= le )
return strcasecmp(&s[ls-le], e) == 0;
return FALSE;
}
#endif
#if HAVE_SIGPROCMASK
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
static inline void
unblockSignal(int sig)
{ sigset_t set;
sigemptyset(&set);
sigaddset(&set, sig);
sigprocmask(SIG_UNBLOCK, &set, NULL);
// DEBUG(1, Sdprintf("Unblocked signal %d\n", sig));
}
#else
static inline void
unblockSignal(int sig)
{
}
#endif
#endif /* PL_YAP_H */

119
H/qly.h Normal file
View File

@@ -0,0 +1,119 @@
/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- *
* *
**************************************************************************
* *
* File: qly.h *
* comments: quick saver/loader *
* *
* Last rev: $Date: 2011-08-29$,$Author: vsc $ *
* $Log: not supported by cvs2svn $ *
* *
*************************************************************************/
#define EXPORT_ATOM_TABLE_SIZE (16*4096)
#define EXPORT_FUNCTOR_TABLE_SIZE (16*4096)
#define EXPORT_OPCODE_TABLE_SIZE (4096)
#define EXPORT_PRED_ENTRY_TABLE_SIZE (128)
#define EXPORT_DBREF_TABLE_SIZE (128)
typedef struct export_atom_hash_entry_struct {
Atom val;
struct export_atom_hash_entry_struct *next;
} export_atom_hash_entry_t;
typedef struct import_atom_hash_entry_struct {
Atom oval;
Atom val;
struct import_atom_hash_entry_struct *next;
} import_atom_hash_entry_t;
typedef struct export_functor_hash_entry_struct {
Functor val;
Atom name;
UInt arity;
struct export_functor_hash_entry_struct *next;
} export_functor_hash_entry_t;
typedef struct import_functor_hash_entry_struct {
Functor val;
Functor oval;
struct import_functor_hash_entry_struct *next;
} import_functor_hash_entry_t;
typedef struct import_opcode_hash_entry_struct {
OPCODE val;
int id;
OPCODE oval;
struct import_opcode_hash_entry_struct *next;
} import_opcode_hash_entry_t;
typedef struct export_pred_entry_hash_entry_struct {
PredEntry *val;
union {
Functor f;
Atom a;
} u;
Atom module;
UInt arity;
struct export_pred_entry_hash_entry_struct *next;
} export_pred_entry_hash_entry_t;
typedef struct import_pred_entry_hash_entry_struct {
PredEntry *val;
PredEntry *oval;
struct import_pred_entry_hash_entry_struct *next;
} import_pred_entry_hash_entry_t;
typedef struct export_dbref_hash_entry_struct {
DBRef val;
UInt sz;
UInt refs;
struct export_dbref_hash_entry_struct *next;
} export_dbref_hash_entry_t;
typedef struct import_dbref_hash_entry_struct {
DBRef val;
DBRef oval;
int count;
struct import_dbref_hash_entry_struct *next;
} import_dbref_hash_entry_t;
typedef enum {
QLY_START_X = 0,
QLY_START_OPCODES = 1,
QLY_START_ATOMS = 2,
QLY_START_FUNCTORS = 3,
QLY_START_PRED_ENTRIES = 4,
QLY_START_DBREFS = 5,
QLY_START_MODULE = 6,
QLY_END_MODULES = 7,
QLY_START_LU_CLAUSE = 8,
QLY_END_LU_CLAUSES = 9,
QLY_NEW_OP = 10,
QLY_END_OPS = 11,
QLY_START_PREDICATE = 12,
QLY_END_PREDICATES = 13,
QLY_ATOM_WIDE = 14,
QLY_FAILCODE = 15,
QLY_ATOM = 16
} qlf_tag_t;
#define STATIC_PRED_FLAGS (SourcePredFlag|DynamicPredFlag|LogUpdatePredFlag|CompiledPredFlag|MultiFileFlag|TabledPredFlag|MegaClausePredFlag|CountPredFlag|ProfiledPredFlag|ThreadLocalPredFlag|AtomDBPredFlag|ModuleTransparentPredFlag|NumberDBPredFlag|MetaPredFlag|SyncPredFlag|BackCPredFlag)
#define SYSTEM_PRED_FLAGS (BackCPredFlag|UserCPredFlag|CArgsPredFlag|AsmPredFlag|CPredFlag|BinaryPredFlag)
#define NEXTOP(V,TYPE) ((yamop *)(&((V)->u.TYPE.next)))
#define CHECK(F) { size_t r = (F); if (!r) return r; }
#define RCHECK(F) if(!(F)) { ERROR(MISMATCH); return; }
#define AllocTempSpace() (H)
#define EnoughTempSpace(sz) ((ASP-H)*sizeof(CELL) > sz)

View File

@@ -60,14 +60,14 @@ restore_opcodes(yamop *pc, yamop *max USES_REGS)
pc->u.Osbmp.p0 = PtoPredAdjust(pc->u.Osbmp.p0);
pc = NEXTOP(pc,Osbmp);
break;
/* instructions type Osbpi */
/* instructions type Osbpa */
case _ensure_space:
OrArgAdjust(pc->u.Osbpi.or_arg);
pc->u.Osbpi.s = ConstantAdjust(pc->u.Osbpi.s);
pc->u.Osbpi.bmap = CellPtoHeapAdjust(pc->u.Osbpi.bmap);
pc->u.Osbpi.p = PtoPredAdjust(pc->u.Osbpi.p);
IntegerInCodeAdjust(pc->u.Osbpi.i);
pc = NEXTOP(pc,Osbpi);
OrArgAdjust(pc->u.Osbpa.or_arg);
pc->u.Osbpa.s = ConstantAdjust(pc->u.Osbpa.s);
pc->u.Osbpa.bmap = CellPtoHeapAdjust(pc->u.Osbpa.bmap);
pc->u.Osbpa.p = PtoPredAdjust(pc->u.Osbpa.p);
pc->u.Osbpa.i = ArityAdjust(pc->u.Osbpa.i);
pc = NEXTOP(pc,Osbpa);
break;
/* instructions type Osbpp */
case _call:

25
H/rheap.h Executable file → Normal file
View File

@@ -547,10 +547,16 @@ RestoreStaticClause(StaticClause *cl USES_REGS)
* clause for this predicate or not
*/
{
if (cl->ClFlags & FactMask) {
cl->usc.ClPred = PtoPredAdjust(cl->usc.ClPred);
} else {
cl->usc.ClSource = DBTermAdjust(cl->usc.ClSource);
if (cl->usc.ClSource) {
char *x = (char *)DBTermAdjust(cl->usc.ClSource);
char *base = (char *)cl;
if (x < base || x > base+cl->ClSize) {
cl->usc.ClPred = PtoPredAdjust(cl->usc.ClPred);
} else {
cl->usc.ClSource = DBTermAdjust(cl->usc.ClSource);
RestoreDBTerm(cl->usc.ClSource, TRUE PASS_REGS);
}
}
if (cl->ClNext) {
cl->ClNext = PtoStCAdjust(cl->ClNext);
@@ -1110,9 +1116,10 @@ RestoreDB(DBEntry *pp USES_REGS)
static void
CleanClauses(yamop *First, yamop *Last, PredEntry *pp USES_REGS)
{
if (!First)
return;
if (pp->PredFlags & LogUpdatePredFlag) {
LogUpdClause *cl = ClauseCodeToLogUpdClause(First);
while (cl != NULL) {
RestoreLUClause(cl, pp PASS_REGS);
cl = cl->ClNext;
@@ -1332,12 +1339,8 @@ CleanCode(PredEntry *pp USES_REGS)
pp->FunctorOfPred = (Functor)AtomAdjust((Atom)(pp->FunctorOfPred));
}
if (!(pp->PredFlags & NumberDBPredFlag)) {
if (pp->PredFlags & MultiFileFlag) {
if (pp->src.file_srcs)
pp->src.file_srcs = MFileAdjust(pp->src.file_srcs);
} else {
if (pp->src.OwnerFile)
pp->src.OwnerFile = AtomAdjust(pp->src.OwnerFile);
if (pp->src.OwnerFile) {
pp->src.OwnerFile = AtomAdjust(pp->src.OwnerFile);
}
}
pp->OpcodeOfPred = Yap_opcode(Yap_op_from_opcode(pp->OpcodeOfPred));

View File

@@ -188,4 +188,32 @@ static void RestoreWorker(int wid USES_REGS) {
#ifdef LOW_LEVEL_TRACER
#endif
}

938
H/saveclause.h Normal file
View File

@@ -0,0 +1,938 @@
/* This file was generated automatically by "yap -L misc/buildops"
please do not update */
while (TRUE) {
op_numbers op;
if (max && pc >= max) return 1;
op = Yap_op_from_opcode(pc->opc);
save_Opcode(stream, op);
/* C-code, maybe indexing */
switch (op) {
/* instructions type D */
case _write_dbterm:
CHECK(save_DBGroundTerm(stream, pc->u.D.D));
pc = NEXTOP(pc,D);
break;
/* instructions type Illss */
case _enter_lu_pred:
CHECK(save_PtoLUIndex(stream, pc->u.Illss.I));
CHECK(save_PtoOp(stream, pc->u.Illss.l1));
CHECK(save_PtoOp(stream, pc->u.Illss.l2));
CHECK(save_Constant(stream, pc->u.Illss.s));
CHECK(save_Constant(stream, pc->u.Illss.e));
pc = NEXTOP(pc,Illss);
break;
/* instructions type L */
case _alloc_for_logical_pred:
CHECK(save_PtoLUClause(stream, pc->u.L.ClBase));
pc = NEXTOP(pc,L);
break;
/* instructions type N */
case _write_bigint:
CHECK(save_BlobTermInCode(stream, pc->u.N.b));
pc = NEXTOP(pc,N);
break;
/* instructions type Osblp */
case _either:
case _or_else:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.Osblp.or_arg));
#endif
CHECK(save_Constant(stream, pc->u.Osblp.s));
CHECK(save_CellPtoHeap(stream, pc->u.Osblp.bmap));
CHECK(save_PtoOp(stream, pc->u.Osblp.l));
CHECK(save_PtoPred(stream, pc->u.Osblp.p0));
pc = NEXTOP(pc,Osblp);
break;
/* instructions type Osbmp */
case _p_execute:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.Osbmp.or_arg));
#endif
CHECK(save_Constant(stream, pc->u.Osbmp.s));
CHECK(save_CellPtoHeap(stream, pc->u.Osbmp.bmap));
CHECK(save_Module(stream, pc->u.Osbmp.mod));
CHECK(save_PtoPred(stream, pc->u.Osbmp.p0));
pc = NEXTOP(pc,Osbmp);
break;
/* instructions type Osbpa */
case _ensure_space:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.Osbpa.or_arg));
#endif
CHECK(save_Constant(stream, pc->u.Osbpa.s));
CHECK(save_CellPtoHeap(stream, pc->u.Osbpa.bmap));
CHECK(save_PtoPred(stream, pc->u.Osbpa.p));
CHECK(save_Arity(stream, pc->u.Osbpa.i));
pc = NEXTOP(pc,Osbpa);
break;
/* instructions type Osbpp */
case _call:
case _call_cpred:
case _call_usercpred:
case _fcall:
case _p_execute2:
case _p_execute_tail:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.Osbpp.or_arg));
#endif
CHECK(save_Constant(stream, pc->u.Osbpp.s));
CHECK(save_CellPtoHeap(stream, pc->u.Osbpp.bmap));
CHECK(save_PtoPred(stream, pc->u.Osbpp.p));
CHECK(save_PtoPred(stream, pc->u.Osbpp.p0));
pc = NEXTOP(pc,Osbpp);
break;
/* instructions type OtILl */
case _count_trust_logical:
case _profiled_trust_logical:
case _trust_logical:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.OtILl.or_arg));
#endif
#ifdef TABLING
CHECK(save_TabEntry(stream, pc->u.OtILl.te));
#endif
CHECK(save_PtoLUIndex(stream, pc->u.OtILl.block));
CHECK(save_PtoLUClause(stream, pc->u.OtILl.d));
CHECK(save_PtoOp(stream, pc->u.OtILl.n));
pc = NEXTOP(pc,OtILl);
break;
/* instructions type OtaLl */
case _count_retry_logical:
case _profiled_retry_logical:
case _retry_logical:
case _try_logical:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.OtaLl.or_arg));
#endif
#ifdef TABLING
CHECK(save_TabEntry(stream, pc->u.OtaLl.te));
#endif
CHECK(save_Arity(stream, pc->u.OtaLl.s));
CHECK(save_PtoLUClause(stream, pc->u.OtaLl.d));
CHECK(save_PtoOp(stream, pc->u.OtaLl.n));
pc = NEXTOP(pc,OtaLl);
break;
/* instructions type OtapFs */
#ifdef CUT_C
case _cut_c:
#endif
#ifdef CUT_C
case _cut_userc:
#endif
case _retry_c:
case _retry_userc:
case _try_c:
case _try_userc:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.OtapFs.or_arg));
#endif
#ifdef TABLING
CHECK(save_TabEntry(stream, pc->u.OtapFs.te));
#endif
CHECK(save_Arity(stream, pc->u.OtapFs.s));
CHECK(save_PtoPred(stream, pc->u.OtapFs.p));
CHECK(save_ExternalFunction(stream, pc->u.OtapFs.f));
CHECK(save_Constant(stream, pc->u.OtapFs.extra));
pc = NEXTOP(pc,OtapFs);
break;
/* instructions type Otapl */
case _count_retry_and_mark:
case _count_retry_me:
case _count_trust_me:
case _profiled_retry_and_mark:
case _profiled_retry_me:
case _profiled_trust_me:
case _retry:
case _retry_and_mark:
case _retry_me:
case _spy_or_trymark:
case _trust:
case _trust_me:
case _try_and_mark:
case _try_clause:
case _try_me:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.Otapl.or_arg));
#endif
#ifdef TABLING
CHECK(save_TabEntry(stream, pc->u.Otapl.te));
#endif
CHECK(save_Arity(stream, pc->u.Otapl.s));
CHECK(save_PtoPred(stream, pc->u.Otapl.p));
CHECK(save_PtoOp(stream, pc->u.Otapl.d));
pc = NEXTOP(pc,Otapl);
break;
/* instructions type aFlp */
case _native_me:
CHECK(save_Arity(stream, pc->u.aFlp.n));
CHECK(save_ExternalFunction(stream, pc->u.aFlp.native));
CHECK(save_PtoOp(stream, pc->u.aFlp.native_next));
CHECK(save_PtoPred(stream, pc->u.aFlp.p));
pc = NEXTOP(pc,aFlp);
break;
/* instructions type c */
case _write_atom:
CHECK(save_ConstantTerm(stream, pc->u.c.c));
pc = NEXTOP(pc,c);
break;
/* instructions type cc */
case _get_2atoms:
CHECK(save_ConstantTerm(stream, pc->u.cc.c1));
CHECK(save_ConstantTerm(stream, pc->u.cc.c2));
pc = NEXTOP(pc,cc);
break;
/* instructions type ccc */
case _get_3atoms:
CHECK(save_ConstantTerm(stream, pc->u.ccc.c1));
CHECK(save_ConstantTerm(stream, pc->u.ccc.c2));
CHECK(save_ConstantTerm(stream, pc->u.ccc.c3));
pc = NEXTOP(pc,ccc);
break;
/* instructions type cccc */
case _get_4atoms:
CHECK(save_ConstantTerm(stream, pc->u.cccc.c1));
CHECK(save_ConstantTerm(stream, pc->u.cccc.c2));
CHECK(save_ConstantTerm(stream, pc->u.cccc.c3));
CHECK(save_ConstantTerm(stream, pc->u.cccc.c4));
pc = NEXTOP(pc,cccc);
break;
/* instructions type ccccc */
case _get_5atoms:
CHECK(save_ConstantTerm(stream, pc->u.ccccc.c1));
CHECK(save_ConstantTerm(stream, pc->u.ccccc.c2));
CHECK(save_ConstantTerm(stream, pc->u.ccccc.c3));
CHECK(save_ConstantTerm(stream, pc->u.ccccc.c4));
CHECK(save_ConstantTerm(stream, pc->u.ccccc.c5));
pc = NEXTOP(pc,ccccc);
break;
/* instructions type cccccc */
case _get_6atoms:
CHECK(save_ConstantTerm(stream, pc->u.cccccc.c1));
CHECK(save_ConstantTerm(stream, pc->u.cccccc.c2));
CHECK(save_ConstantTerm(stream, pc->u.cccccc.c3));
CHECK(save_ConstantTerm(stream, pc->u.cccccc.c4));
CHECK(save_ConstantTerm(stream, pc->u.cccccc.c5));
CHECK(save_ConstantTerm(stream, pc->u.cccccc.c6));
pc = NEXTOP(pc,cccccc);
break;
/* instructions type clll */
case _if_not_then:
CHECK(save_ConstantTerm(stream, pc->u.clll.c));
CHECK(save_PtoOp(stream, pc->u.clll.l1));
CHECK(save_PtoOp(stream, pc->u.clll.l2));
CHECK(save_PtoOp(stream, pc->u.clll.l3));
pc = NEXTOP(pc,clll);
break;
/* instructions type d */
case _write_float:
CHECK(save_DoubleInCode(stream, pc->u.d.d));
pc = NEXTOP(pc,d);
break;
/* instructions type e */
case _Nstop:
case _allocate:
case _copy_idb_term:
case _expand_index:
case _index_blob:
case _index_dbref:
case _index_long:
case _index_pred:
case _lock_pred:
case _op_fail:
case _p_equal:
case _p_functor:
case _pop:
#ifdef BEAM
case _retry_eam:
#endif
case _spy_pred:
#ifdef THREADS
case _thread_local:
#endif
case _trust_fail:
case _undef_p:
case _unify_idb_term:
case _unlock_lu:
case _write_l_list:
case _write_list:
case _write_void:
if (op == _Nstop || op == _copy_idb_term || op == _unify_idb_term) return 1;
pc = NEXTOP(pc,e);
break;
/* instructions type fa */
case _write_l_struc:
case _write_struct:
CHECK(save_Func(stream, pc->u.fa.f));
CHECK(save_Arity(stream, pc->u.fa.a));
pc = NEXTOP(pc,fa);
break;
/* instructions type i */
case _write_longint:
CHECK(save_IntegerInCode(stream, pc->u.i.i));
pc = NEXTOP(pc,i);
break;
/* instructions type l */
case _Ystop:
case _jump:
case _jump_if_var:
case _move_back:
case _p_dif:
case _p_eq:
case _retry2:
case _retry3:
case _retry4:
case _skip:
case _try_clause2:
case _try_clause3:
case _try_clause4:
case _try_in:
CHECK(save_PtoOp(stream, pc->u.l.l));
pc = NEXTOP(pc,l);
break;
/* instructions type llll */
case _switch_on_type:
CHECK(save_PtoOp(stream, pc->u.llll.l1));
CHECK(save_PtoOp(stream, pc->u.llll.l2));
CHECK(save_PtoOp(stream, pc->u.llll.l3));
CHECK(save_PtoOp(stream, pc->u.llll.l4));
pc = NEXTOP(pc,llll);
break;
/* instructions type lp */
case _user_switch:
CHECK(save_PtoOp(stream, pc->u.lp.l));
CHECK(save_PtoPred(stream, pc->u.lp.p));
pc = NEXTOP(pc,lp);
break;
/* instructions type o */
case _unify_l_list:
case _unify_l_list_write:
case _unify_l_void:
case _unify_l_void_write:
case _unify_list:
case _unify_list_write:
case _unify_void:
case _unify_void_write:
CHECK(save_Opcode(stream, pc->u.o.opcw));
pc = NEXTOP(pc,o);
break;
/* instructions type oD */
case _unify_dbterm:
case _unify_l_dbterm:
CHECK(save_Opcode(stream, pc->u.oD.opcw));
CHECK(save_DBGroundTerm(stream, pc->u.oD.D));
pc = NEXTOP(pc,oD);
break;
/* instructions type oN */
case _unify_bigint:
case _unify_l_bigint:
CHECK(save_Opcode(stream, pc->u.oN.opcw));
CHECK(save_BlobTermInCode(stream, pc->u.oN.b));
pc = NEXTOP(pc,oN);
break;
/* instructions type oc */
case _unify_atom:
case _unify_atom_write:
case _unify_l_atom:
case _unify_l_atom_write:
CHECK(save_Opcode(stream, pc->u.oc.opcw));
CHECK(save_ConstantTerm(stream, pc->u.oc.c));
pc = NEXTOP(pc,oc);
break;
/* instructions type od */
case _unify_float:
case _unify_float_write:
case _unify_l_float:
case _unify_l_float_write:
CHECK(save_Opcode(stream, pc->u.od.opcw));
CHECK(save_DoubleInCode(stream, pc->u.od.d));
pc = NEXTOP(pc,od);
break;
/* instructions type ofa */
case _unify_l_struc:
case _unify_l_struc_write:
case _unify_struct:
case _unify_struct_write:
CHECK(save_Opcode(stream, pc->u.ofa.opcw));
CHECK(save_Func(stream, pc->u.ofa.f));
CHECK(save_Arity(stream, pc->u.ofa.a));
pc = NEXTOP(pc,ofa);
break;
/* instructions type oi */
case _unify_l_longint:
case _unify_l_longint_write:
case _unify_longint:
case _unify_longint_write:
CHECK(save_Opcode(stream, pc->u.oi.opcw));
CHECK(save_IntegerInCode(stream, pc->u.oi.i));
pc = NEXTOP(pc,oi);
break;
/* instructions type ollll */
case _switch_list_nl:
CHECK(save_Opcode(stream, pc->u.ollll.pop));
CHECK(save_PtoOp(stream, pc->u.ollll.l1));
CHECK(save_PtoOp(stream, pc->u.ollll.l2));
CHECK(save_PtoOp(stream, pc->u.ollll.l3));
CHECK(save_PtoOp(stream, pc->u.ollll.l4));
pc = NEXTOP(pc,ollll);
break;
/* instructions type os */
#ifdef BEAM
case _run_eam:
#endif
case _unify_l_n_voids:
case _unify_l_n_voids_write:
case _unify_n_voids:
case _unify_n_voids_write:
CHECK(save_Opcode(stream, pc->u.os.opcw));
CHECK(save_Constant(stream, pc->u.os.s));
pc = NEXTOP(pc,os);
break;
/* instructions type osc */
case _unify_n_atoms:
case _unify_n_atoms_write:
CHECK(save_Opcode(stream, pc->u.osc.opcw));
CHECK(save_Constant(stream, pc->u.osc.s));
CHECK(save_ConstantTerm(stream, pc->u.osc.c));
pc = NEXTOP(pc,osc);
break;
/* instructions type ox */
case _save_appl_x:
case _save_appl_x_write:
case _save_pair_x:
case _save_pair_x_write:
case _unify_l_x_loc:
case _unify_l_x_loc_write:
case _unify_l_x_val:
case _unify_l_x_val_write:
case _unify_l_x_var:
case _unify_l_x_var_write:
case _unify_x_loc:
case _unify_x_loc_write:
case _unify_x_val:
case _unify_x_val_write:
case _unify_x_var:
case _unify_x_var_write:
CHECK(save_Opcode(stream, pc->u.ox.opcw));
CHECK(save_X(stream, pc->u.ox.x));
pc = NEXTOP(pc,ox);
break;
/* instructions type oxx */
case _unify_l_x_var2:
case _unify_l_x_var2_write:
case _unify_x_var2:
case _unify_x_var2_write:
CHECK(save_Opcode(stream, pc->u.oxx.opcw));
CHECK(save_X(stream, pc->u.oxx.xl));
CHECK(save_X(stream, pc->u.oxx.xr));
pc = NEXTOP(pc,oxx);
break;
/* instructions type oy */
case _save_appl_y:
case _save_appl_y_write:
case _save_pair_y:
case _save_pair_y_write:
case _unify_l_y_loc:
case _unify_l_y_loc_write:
case _unify_l_y_val:
case _unify_l_y_val_write:
case _unify_l_y_var:
case _unify_l_y_var_write:
case _unify_y_loc:
case _unify_y_loc_write:
case _unify_y_val:
case _unify_y_val_write:
case _unify_y_var:
case _unify_y_var_write:
CHECK(save_Opcode(stream, pc->u.oy.opcw));
CHECK(save_Y(stream, pc->u.oy.y));
pc = NEXTOP(pc,oy);
break;
/* instructions type p */
case _count_call:
case _count_retry:
case _deallocate:
case _enter_profiling:
case _lock_lu:
case _procceed:
case _retry_profiled:
CHECK(save_PtoPred(stream, pc->u.p.p));
pc = NEXTOP(pc,p);
break;
/* instructions type plxxs */
case _call_bfunc_xx:
CHECK(save_PtoPred(stream, pc->u.plxxs.p));
CHECK(save_PtoOp(stream, pc->u.plxxs.f));
CHECK(save_X(stream, pc->u.plxxs.x1));
CHECK(save_X(stream, pc->u.plxxs.x2));
CHECK(save_Constant(stream, pc->u.plxxs.flags));
pc = NEXTOP(pc,plxxs);
break;
/* instructions type plxys */
case _call_bfunc_xy:
case _call_bfunc_yx:
CHECK(save_PtoPred(stream, pc->u.plxys.p));
CHECK(save_PtoOp(stream, pc->u.plxys.f));
CHECK(save_X(stream, pc->u.plxys.x));
CHECK(save_Y(stream, pc->u.plxys.y));
CHECK(save_Constant(stream, pc->u.plxys.flags));
pc = NEXTOP(pc,plxys);
break;
/* instructions type plyys */
case _call_bfunc_yy:
CHECK(save_PtoPred(stream, pc->u.plyys.p));
CHECK(save_PtoOp(stream, pc->u.plyys.f));
CHECK(save_Y(stream, pc->u.plyys.y1));
CHECK(save_Y(stream, pc->u.plyys.y2));
CHECK(save_Constant(stream, pc->u.plyys.flags));
pc = NEXTOP(pc,plyys);
break;
/* instructions type pp */
case _dexecute:
case _execute:
case _execute_cpred:
CHECK(save_PtoPred(stream, pc->u.pp.p));
CHECK(save_PtoPred(stream, pc->u.pp.p0));
pc = NEXTOP(pc,pp);
break;
/* instructions type s */
case _cut:
case _cut_e:
case _cut_t:
case _pop_n:
case _write_n_voids:
CHECK(save_Constant(stream, pc->u.s.s));
pc = NEXTOP(pc,s);
break;
/* instructions type sc */
case _write_n_atoms:
CHECK(save_Constant(stream, pc->u.sc.s));
CHECK(save_ConstantTerm(stream, pc->u.sc.c));
pc = NEXTOP(pc,sc);
break;
/* instructions type sllll */
case _switch_on_sub_arg_type:
CHECK(save_Constant(stream, pc->u.sllll.s));
CHECK(save_PtoOp(stream, pc->u.sllll.l1));
CHECK(save_PtoOp(stream, pc->u.sllll.l2));
CHECK(save_PtoOp(stream, pc->u.sllll.l3));
CHECK(save_PtoOp(stream, pc->u.sllll.l4));
pc = NEXTOP(pc,sllll);
break;
/* instructions type slp */
case _call_c_wfail:
CHECK(save_Constant(stream, pc->u.slp.s));
CHECK(save_PtoOp(stream, pc->u.slp.l));
CHECK(save_PtoPred(stream, pc->u.slp.p));
pc = NEXTOP(pc,slp);
break;
/* instructions type sssl */
case _go_on_cons:
case _go_on_func:
case _if_cons:
case _if_func:
case _switch_on_cons:
case _switch_on_func:
CHECK(save_Constant(stream, pc->u.sssl.s));
CHECK(save_Constant(stream, pc->u.sssl.e));
CHECK(save_Constant(stream, pc->u.sssl.w));
CHECK(save_PtoOp(stream, pc->u.sssl.l));
pc = NEXTOP(pc,sssl);
break;
/* instructions type sssllp */
case _expand_clauses:
CHECK(save_Constant(stream, pc->u.sssllp.s1));
CHECK(save_Constant(stream, pc->u.sssllp.s2));
CHECK(save_Constant(stream, pc->u.sssllp.s3));
CHECK(save_PtoOp(stream, pc->u.sssllp.sprev));
CHECK(save_PtoOp(stream, pc->u.sssllp.snext));
CHECK(save_PtoPred(stream, pc->u.sssllp.p));
pc = NEXTOP(pc,sssllp);
break;
/* instructions type x */
case _get_list:
case _put_list:
case _save_b_x:
case _write_x_loc:
case _write_x_val:
case _write_x_var:
CHECK(save_X(stream, pc->u.x.x));
pc = NEXTOP(pc,x);
break;
/* instructions type xD */
case _get_dbterm:
case _put_dbterm:
CHECK(save_X(stream, pc->u.xD.x));
CHECK(save_DBGroundTerm(stream, pc->u.xD.D));
pc = NEXTOP(pc,xD);
break;
/* instructions type xN */
case _get_bigint:
case _put_bigint:
CHECK(save_X(stream, pc->u.xN.x));
CHECK(save_BlobTermInCode(stream, pc->u.xN.b));
pc = NEXTOP(pc,xN);
break;
/* instructions type xc */
case _get_atom:
case _put_atom:
CHECK(save_X(stream, pc->u.xc.x));
CHECK(save_ConstantTerm(stream, pc->u.xc.c));
pc = NEXTOP(pc,xc);
break;
/* instructions type xd */
case _get_float:
case _put_float:
CHECK(save_X(stream, pc->u.xd.x));
CHECK(save_DoubleInCode(stream, pc->u.xd.d));
pc = NEXTOP(pc,xd);
break;
/* instructions type xfa */
case _get_struct:
case _put_struct:
CHECK(save_X(stream, pc->u.xfa.x));
CHECK(save_Func(stream, pc->u.xfa.f));
CHECK(save_Arity(stream, pc->u.xfa.a));
pc = NEXTOP(pc,xfa);
break;
/* instructions type xi */
case _get_longint:
case _put_longint:
CHECK(save_X(stream, pc->u.xi.x));
CHECK(save_IntegerInCode(stream, pc->u.xi.i));
pc = NEXTOP(pc,xi);
break;
/* instructions type xl */
case _p_atom_x:
case _p_atomic_x:
case _p_compound_x:
case _p_db_ref_x:
case _p_float_x:
case _p_integer_x:
case _p_nonvar_x:
case _p_number_x:
case _p_primitive_x:
case _p_var_x:
CHECK(save_X(stream, pc->u.xl.x));
CHECK(save_PtoOp(stream, pc->u.xl.F));
pc = NEXTOP(pc,xl);
break;
/* instructions type xll */
case _jump_if_nonvar:
CHECK(save_X(stream, pc->u.xll.x));
CHECK(save_PtoOp(stream, pc->u.xll.l1));
CHECK(save_PtoOp(stream, pc->u.xll.l2));
pc = NEXTOP(pc,xll);
break;
/* instructions type xllll */
case _switch_on_arg_type:
CHECK(save_X(stream, pc->u.xllll.x));
CHECK(save_PtoOp(stream, pc->u.xllll.l1));
CHECK(save_PtoOp(stream, pc->u.xllll.l2));
CHECK(save_PtoOp(stream, pc->u.xllll.l3));
CHECK(save_PtoOp(stream, pc->u.xllll.l4));
pc = NEXTOP(pc,xllll);
break;
/* instructions type xps */
case _commit_b_x:
CHECK(save_X(stream, pc->u.xps.x));
CHECK(save_PtoPred(stream, pc->u.xps.p0));
CHECK(save_Constant(stream, pc->u.xps.s));
pc = NEXTOP(pc,xps);
break;
/* instructions type xx */
case _get_x_val:
case _get_x_var:
case _gl_void_valx:
case _gl_void_varx:
case _glist_valx:
case _put_x_val:
case _put_x_var:
CHECK(save_X(stream, pc->u.xx.xl));
CHECK(save_X(stream, pc->u.xx.xr));
pc = NEXTOP(pc,xx);
break;
/* instructions type xxc */
case _p_func2s_cv:
CHECK(save_X(stream, pc->u.xxc.x));
CHECK(save_X(stream, pc->u.xxc.xi));
CHECK(save_ConstantTerm(stream, pc->u.xxc.c));
pc = NEXTOP(pc,xxc);
break;
/* instructions type xxn */
case _p_and_vc:
case _p_arg_cv:
case _p_div_cv:
case _p_div_vc:
case _p_func2s_vc:
case _p_minus_cv:
case _p_or_vc:
case _p_plus_vc:
case _p_sll_cv:
case _p_sll_vc:
case _p_slr_cv:
case _p_slr_vc:
case _p_times_vc:
CHECK(save_X(stream, pc->u.xxn.x));
CHECK(save_X(stream, pc->u.xxn.xi));
CHECK(save_Integer(stream, pc->u.xxn.c));
pc = NEXTOP(pc,xxn);
break;
/* instructions type xxx */
case _p_and_vv:
case _p_arg_vv:
case _p_div_vv:
case _p_func2f_xx:
case _p_func2s_vv:
case _p_minus_vv:
case _p_or_vv:
case _p_plus_vv:
case _p_sll_vv:
case _p_slr_vv:
case _p_times_vv:
CHECK(save_X(stream, pc->u.xxx.x));
CHECK(save_X(stream, pc->u.xxx.x1));
CHECK(save_X(stream, pc->u.xxx.x2));
pc = NEXTOP(pc,xxx);
break;
/* instructions type xxxx */
case _put_xx_val:
CHECK(save_X(stream, pc->u.xxxx.xl1));
CHECK(save_X(stream, pc->u.xxxx.xl2));
CHECK(save_X(stream, pc->u.xxxx.xr1));
CHECK(save_X(stream, pc->u.xxxx.xr2));
pc = NEXTOP(pc,xxxx);
break;
/* instructions type xxy */
case _p_func2f_xy:
CHECK(save_X(stream, pc->u.xxy.x));
CHECK(save_X(stream, pc->u.xxy.x1));
CHECK(save_Y(stream, pc->u.xxy.y2));
pc = NEXTOP(pc,xxy);
break;
/* instructions type y */
case _save_b_y:
case _write_y_loc:
case _write_y_val:
case _write_y_var:
CHECK(save_Y(stream, pc->u.y.y));
pc = NEXTOP(pc,y);
break;
/* instructions type yl */
case _p_atom_y:
case _p_atomic_y:
case _p_compound_y:
case _p_db_ref_y:
case _p_float_y:
case _p_integer_y:
case _p_nonvar_y:
case _p_number_y:
case _p_primitive_y:
case _p_var_y:
CHECK(save_Y(stream, pc->u.yl.y));
CHECK(save_PtoOp(stream, pc->u.yl.F));
pc = NEXTOP(pc,yl);
break;
/* instructions type yps */
case _commit_b_y:
CHECK(save_Y(stream, pc->u.yps.y));
CHECK(save_PtoPred(stream, pc->u.yps.p0));
CHECK(save_Constant(stream, pc->u.yps.s));
pc = NEXTOP(pc,yps);
break;
/* instructions type yx */
case _get_y_val:
case _get_y_var:
case _gl_void_valy:
case _gl_void_vary:
case _glist_valy:
case _put_unsafe:
case _put_y_val:
case _put_y_var:
CHECK(save_Y(stream, pc->u.yx.y));
CHECK(save_X(stream, pc->u.yx.x));
pc = NEXTOP(pc,yx);
break;
/* instructions type yxn */
case _p_and_y_vc:
case _p_arg_y_cv:
case _p_div_y_cv:
case _p_div_y_vc:
case _p_func2s_y_cv:
case _p_func2s_y_vc:
case _p_minus_y_cv:
case _p_or_y_vc:
case _p_plus_y_vc:
case _p_sll_y_cv:
case _p_sll_y_vc:
case _p_slr_y_cv:
case _p_slr_y_vc:
case _p_times_y_vc:
CHECK(save_Y(stream, pc->u.yxn.y));
CHECK(save_X(stream, pc->u.yxn.xi));
CHECK(save_Integer(stream, pc->u.yxn.c));
pc = NEXTOP(pc,yxn);
break;
/* instructions type yxx */
case _p_and_y_vv:
case _p_arg_y_vv:
case _p_div_y_vv:
case _p_func2f_yx:
case _p_func2s_y_vv:
case _p_minus_y_vv:
case _p_or_y_vv:
case _p_plus_y_vv:
case _p_sll_y_vv:
case _p_slr_y_vv:
case _p_times_y_vv:
CHECK(save_Y(stream, pc->u.yxx.y));
CHECK(save_X(stream, pc->u.yxx.x1));
CHECK(save_X(stream, pc->u.yxx.x2));
pc = NEXTOP(pc,yxx);
break;
/* instructions type yyx */
case _p_func2f_yy:
CHECK(save_Y(stream, pc->u.yyx.y1));
CHECK(save_Y(stream, pc->u.yyx.y2));
CHECK(save_X(stream, pc->u.yyx.x));
pc = NEXTOP(pc,yyx);
break;
/* instructions type yyxx */
case _get_yy_var:
case _put_y_vals:
CHECK(save_Y(stream, pc->u.yyxx.y1));
CHECK(save_Y(stream, pc->u.yyxx.y2));
CHECK(save_X(stream, pc->u.yyxx.x1));
CHECK(save_X(stream, pc->u.yyxx.x2));
pc = NEXTOP(pc,yyxx);
break;
#ifdef YAPOR
/* instructions type Otapl */
case _getwork:
case _getwork_seq:
case _sync:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.Otapl.or_arg));
#endif
#ifdef TABLING
CHECK(save_TabEntry(stream, pc->u.Otapl.te));
#endif
CHECK(save_Arity(stream, pc->u.Otapl.s));
CHECK(save_PtoPred(stream, pc->u.Otapl.p));
CHECK(save_PtoOp(stream, pc->u.Otapl.d));
pc = NEXTOP(pc,Otapl);
break;
/* instructions type e */
case _getwork_first_time:
if (op == _Nstop || op == _copy_idb_term || op == _unify_idb_term) return 1;
pc = NEXTOP(pc,e);
break;
#endif
#ifdef TABLING
/* instructions type Otapl */
case _table_answer_resolution:
case _table_completion:
case _table_load_answer:
case _table_retry:
case _table_retry_me:
case _table_trust:
case _table_trust_me:
case _table_try:
case _table_try_answer:
case _table_try_me:
case _table_try_single:
#ifdef YAPOR
CHECK(save_OrArg(stream, pc->u.Otapl.or_arg));
#endif
#ifdef TABLING
CHECK(save_TabEntry(stream, pc->u.Otapl.te));
#endif
CHECK(save_Arity(stream, pc->u.Otapl.s));
CHECK(save_PtoPred(stream, pc->u.Otapl.p));
CHECK(save_PtoOp(stream, pc->u.Otapl.d));
pc = NEXTOP(pc,Otapl);
break;
/* instructions type e */
#ifdef TABLING_INNER_CUTS
case _clause_with_cut:
#endif
if (op == _Nstop || op == _copy_idb_term || op == _unify_idb_term) return 1;
pc = NEXTOP(pc,e);
break;
/* instructions type s */
case _table_new_answer:
CHECK(save_Constant(stream, pc->u.s.s));
pc = NEXTOP(pc,s);
break;
/* instructions type e */
case _trie_do_appl:
case _trie_do_appl_in_pair:
case _trie_do_atom:
case _trie_do_atom_in_pair:
case _trie_do_double:
case _trie_do_extension:
case _trie_do_gterm:
case _trie_do_longint:
case _trie_do_null:
case _trie_do_null_in_pair:
case _trie_do_pair:
case _trie_do_val:
case _trie_do_val_in_pair:
case _trie_do_var:
case _trie_do_var_in_pair:
case _trie_retry_appl:
case _trie_retry_appl_in_pair:
case _trie_retry_atom:
case _trie_retry_atom_in_pair:
case _trie_retry_double:
case _trie_retry_extension:
case _trie_retry_gterm:
case _trie_retry_longint:
case _trie_retry_null:
case _trie_retry_null_in_pair:
case _trie_retry_pair:
case _trie_retry_val:
case _trie_retry_val_in_pair:
case _trie_retry_var:
case _trie_retry_var_in_pair:
case _trie_trust_appl:
case _trie_trust_appl_in_pair:
case _trie_trust_atom:
case _trie_trust_atom_in_pair:
case _trie_trust_double:
case _trie_trust_extension:
case _trie_trust_gterm:
case _trie_trust_longint:
case _trie_trust_null:
case _trie_trust_null_in_pair:
case _trie_trust_pair:
case _trie_trust_val:
case _trie_trust_val_in_pair:
case _trie_trust_var:
case _trie_trust_var_in_pair:
case _trie_try_appl:
case _trie_try_appl_in_pair:
case _trie_try_atom:
case _trie_try_atom_in_pair:
case _trie_try_double:
case _trie_try_extension:
case _trie_try_gterm:
case _trie_try_longint:
case _trie_try_null:
case _trie_try_null_in_pair:
case _trie_try_pair:
case _trie_try_val:
case _trie_try_val_in_pair:
case _trie_try_var:
case _trie_try_var_in_pair:
if (op == _Nstop || op == _copy_idb_term || op == _unify_idb_term) return 1;
pc = NEXTOP(pc,e);
break;
#endif
default:
return -1;
}
}

9
H/sshift.h Executable file → Normal file
View File

@@ -49,7 +49,6 @@
// #define IntegerAdjust(D) IntegerAdjust__(P PASS_REGS)
#define AddrAdjust(P) AddrAdjust__(P PASS_REGS)
#define BlockAdjust(P) BlockAdjust__(P PASS_REGS)
#define MFileAdjust(P) MFileAdjust__(P PASS_REGS)
#define CodeVarAdjust(P) CodeVarAdjust__(P PASS_REGS)
#define ConstantAdjust(P) ConstantAdjust__(P PASS_REGS)
#define ArityAdjust(P) ArityAdjust__(P PASS_REGS)
@@ -607,14 +606,6 @@ AtomEntryAdjust__ (AtomEntry * at USES_REGS)
return (AtomEntry *) ((AtomEntry *) (CharP (at) + LOCAL_HDiff));
}
inline EXTERN struct mfile *MFileAdjust__ (struct mfile * CACHE_TYPE);
inline EXTERN struct mfile *
MFileAdjust__ (struct mfile * at USES_REGS)
{
return (struct mfile *) (CharP (at) + LOCAL_HDiff);
}
inline EXTERN GlobalEntry *GlobalEntryAdjust__ (GlobalEntry * CACHE_TYPE);
inline EXTERN GlobalEntry *

View File

@@ -34,9 +34,9 @@
case _p_execute:
pc = NEXTOP(pc,Osbmp);
break;
/* instructions type Osbpi */
/* instructions type Osbpa */
case _ensure_space:
pc = NEXTOP(pc,Osbpi);
pc = NEXTOP(pc,Osbpa);
break;
/* instructions type Osbpp */
case _call_cpred:

View File

@@ -221,28 +221,6 @@ typedef struct AliasDescS {
/************ SWI compatible support for different encodings ************/
#ifndef _PL_STREAM_H
typedef enum {
ENC_OCTET = 0,
ENC_ISO_LATIN1 = 1,
ENC_ISO_ASCII = 2,
ENC_ISO_ANSI = 4,
ENC_ISO_UTF8 = 8,
ENC_UNICODE_BE = 16,
ENC_UNICODE_LE = 32,
ENC_ISO_UTF32_BE = 64,
ENC_ISO_UTF32_LE = 128
} encoding_t;
#else
#define ENC_ISO_LATIN1 ENC_ISO_LATIN_1
#define ENC_ISO_UTF32_BE ENC_UNKNOWN //bogus
#define ENC_ISO_UTF32_LE ENC_WCHAR // bogus
#define ENC_ISO_UTF8 ENC_UTF8
#define ENC_ISO_ASCII ENC_ASCII
#define ENC_ISO_ANSI ENC_ANSI
typedef IOENC encoding_t;
#endif
#define MAX_ISO_LATIN1 255
/****************** character definition table **************************/