Merge branch 'master' of ssh://yap.git.sourceforge.net/gitroot/yap/yap-6.3
This commit is contained in:
commit
b6aca9463d
12
C/absmi.c
12
C/absmi.c
|
@ -1679,18 +1679,18 @@ Yap_absmi(int inp)
|
|||
*****************************************************************/
|
||||
|
||||
/* ensure_space */
|
||||
BOp(ensure_space, Osbpi);
|
||||
BOp(ensure_space, Osbpa);
|
||||
{
|
||||
Int sz = PREG->u.Osbpi.i;
|
||||
UInt arity = PREG->u.Osbpi.p->ArityOfPE;
|
||||
Int sz = PREG->u.Osbpa.i;
|
||||
UInt arity = PREG->u.Osbpa.p->ArityOfPE;
|
||||
if (Unsigned(H) + sz > Unsigned(YREG)-CreepFlag) {
|
||||
YENV[E_CP] = (CELL) CPREG;
|
||||
YENV[E_E] = (CELL) ENV;
|
||||
#ifdef DEPTH_LIMIT
|
||||
YENV[E_DEPTH] = DEPTH;
|
||||
#endif /* DEPTH_LIMIT */
|
||||
SET_ASP(YREG, PREG->u.Osbpi.s);
|
||||
PREG = NEXTOP(PREG,Osbpi);
|
||||
SET_ASP(YREG, PREG->u.Osbpa.s);
|
||||
PREG = NEXTOP(PREG,Osbpa);
|
||||
saveregs();
|
||||
if (!Yap_gcl(sz, arity, YENV, PREG)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR,TermNil,LOCAL_ErrorMessage);
|
||||
|
@ -1700,7 +1700,7 @@ Yap_absmi(int inp)
|
|||
setregs();
|
||||
}
|
||||
} else {
|
||||
PREG = NEXTOP(PREG,Osbpi);
|
||||
PREG = NEXTOP(PREG,Osbpa);
|
||||
}
|
||||
}
|
||||
JMPNext();
|
||||
|
|
55
C/adtdefs.c
55
C/adtdefs.c
|
@ -69,9 +69,9 @@ InlinedUnlockedMkFunctor(AtomEntry *ae, unsigned int arity)
|
|||
p->NameOfFE = AbsAtom(ae);
|
||||
p->ArityOfFE = arity;
|
||||
p->PropsOfFE = NIL;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
INIT_RWLOCK(p->FRWLock);
|
||||
ae->PropsOfAE = AbsProp((PropEntry *) p);
|
||||
/* respect the first property, in case this is a wide atom */
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
return ((Functor) p);
|
||||
}
|
||||
|
||||
|
@ -104,8 +104,7 @@ Yap_MkFunctorWithAddress(Atom ap, unsigned int arity, FunctorEntry *p)
|
|||
p->KindOfPE = FunctorProperty;
|
||||
p->NameOfFE = ap;
|
||||
p->ArityOfFE = arity;
|
||||
p->NextOfPE = RepAtom(ap)->PropsOfAE;
|
||||
ae->PropsOfAE = AbsProp((PropEntry *) p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
}
|
||||
|
||||
|
@ -493,6 +492,7 @@ Yap_GetOpProp(Atom a, op_type type USES_REGS)
|
|||
{ /* look property list of atom a for kind */
|
||||
AtomEntry *ae = RepAtom(a);
|
||||
PropEntry *pp;
|
||||
OpEntry *oinfo = NULL;
|
||||
|
||||
READ_LOCK(ae->ARWLock);
|
||||
pp = RepProp(ae->PropsOfAE);
|
||||
|
@ -524,9 +524,21 @@ Yap_GetOpProp(Atom a, op_type type USES_REGS)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
READ_LOCK(info->OpRWLock);
|
||||
/* if it is not the latest module */
|
||||
if (info->OpModule == PROLOG_MODULE) {
|
||||
/* cannot commit now */
|
||||
oinfo = info;
|
||||
pp = RepProp(pp->NextOfPE);
|
||||
} else {
|
||||
READ_LOCK(info->OpRWLock);
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
if (oinfo) {
|
||||
READ_LOCK(oinfo->OpRWLock);
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return info;
|
||||
return oinfo;
|
||||
}
|
||||
READ_UNLOCK(ae->ARWLock);
|
||||
return NULL;
|
||||
|
@ -898,7 +910,6 @@ Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod)
|
|||
p->beamTable = NULL;
|
||||
#endif
|
||||
/* careful that they don't cross MkFunctor */
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
if (PRED_GOAL_EXPANSION_FUNC) {
|
||||
Prop p1 = ae->PropsOfAE;
|
||||
|
||||
|
@ -914,7 +925,8 @@ Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod)
|
|||
p1 = pe->NextOfPE;
|
||||
}
|
||||
}
|
||||
ae->PropsOfAE = p0 = AbsPredProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
p0 = AbsPredProp(p);
|
||||
p->FunctorOfPred = (Functor)AbsAtom(ae);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
#ifdef LOW_PROF
|
||||
|
@ -1033,10 +1045,9 @@ Yap_PutValue(Atom a, Term v)
|
|||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return;
|
||||
}
|
||||
p->NextOfPE = RepAtom(a)->PropsOfAE;
|
||||
RepAtom(a)->PropsOfAE = AbsValProp(p);
|
||||
p->KindOfPE = ValProperty;
|
||||
p->ValueOfVE = TermNil;
|
||||
AddPropToAtom(RepAtom(a), (PropEntry *)p);
|
||||
/* take care that the lock for the property will be inited even
|
||||
if someone else searches for the property */
|
||||
INIT_RWLOCK(p->VRWLock);
|
||||
|
@ -1431,30 +1442,6 @@ Yap_RecoverSlots(int n USES_REGS)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
Term
|
||||
Yap_GetFromSlot(Int slot USES_REGS)
|
||||
{
|
||||
return(Deref(LCL0[slot]));
|
||||
}
|
||||
|
||||
Term
|
||||
Yap_GetPtrFromSlot(Int slot USES_REGS)
|
||||
{
|
||||
return(LCL0[slot]);
|
||||
}
|
||||
|
||||
Term *
|
||||
Yap_AddressFromSlot(Int slot USES_REGS)
|
||||
{
|
||||
return(LCL0+slot);
|
||||
}
|
||||
|
||||
void
|
||||
Yap_PutInSlot(Int slot, Term t USES_REGS)
|
||||
{
|
||||
LCL0[slot] = t;
|
||||
}
|
||||
|
||||
static HoldEntry *
|
||||
InitAtomHold(void)
|
||||
{
|
||||
|
|
|
@ -944,7 +944,6 @@ InitWorkSpace(Int s)
|
|||
#else
|
||||
a = mmap(NULL, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
fprintf(stderr,"a=%p\n",a);
|
||||
#endif
|
||||
#else
|
||||
fd = open("/dev/zero", O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
|
|
10
C/amasm.c
10
C/amasm.c
|
@ -1104,12 +1104,12 @@ a_ensure_space(op_numbers opcode, yamop *code_p, int pass_no, struct intermediat
|
|||
if (cip->cpc->rnd1 > 4096) {
|
||||
if (pass_no) {
|
||||
code_p->opc = emit_op(opcode);
|
||||
code_p->u.Osbpi.i = sizeof(CELL) * cip->cpc->rnd1;
|
||||
code_p->u.Osbpi.p = clinfo->CurrentPred;
|
||||
code_p->u.Osbpi.bmap = NULL;
|
||||
code_p->u.Osbpi.s = emit_count(-Signed(RealEnvSize));
|
||||
code_p->u.Osbpa.i = sizeof(CELL) * cip->cpc->rnd1;
|
||||
code_p->u.Osbpa.p = clinfo->CurrentPred;
|
||||
code_p->u.Osbpa.bmap = NULL;
|
||||
code_p->u.Osbpa.s = emit_count(-Signed(RealEnvSize));
|
||||
}
|
||||
GONEXT(Osbpi);
|
||||
GONEXT(Osbpa);
|
||||
}
|
||||
return code_p;
|
||||
}
|
||||
|
|
|
@ -198,8 +198,7 @@ Yap_InitConstExps(void)
|
|||
p->ArityOfEE = 0;
|
||||
p->ENoOfEE = 0;
|
||||
p->FOfEE = InitConstTab[i].f;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsExpProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -835,8 +835,7 @@ Yap_InitUnaryExps(void)
|
|||
p->ArityOfEE = 1;
|
||||
p->ENoOfEE = 1;
|
||||
p->FOfEE = InitUnTab[i].f;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsExpProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
}
|
||||
Yap_InitCPred("is", 3, p_unary_is, TestPredFlag | SafePredFlag);
|
||||
|
|
|
@ -1217,8 +1217,7 @@ Yap_InitBinaryExps(void)
|
|||
p->ArityOfEE = 2;
|
||||
p->ENoOfEE = 2;
|
||||
p->FOfEE = InitBinTab[i].f;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsExpProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
}
|
||||
Yap_InitCPred("is", 4, p_binary_is, TestPredFlag | SafePredFlag);
|
||||
|
|
|
@ -566,9 +566,8 @@ CreateNamedArray(PropEntry * pp, Int dim, AtomEntry *ae USES_REGS)
|
|||
|
||||
p = (ArrayEntry *) Yap_AllocAtomSpace(sizeof(*p));
|
||||
p->KindOfPE = ArrayProperty;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
INIT_RWLOCK(p->ArRWLock);
|
||||
ae->PropsOfAE = AbsArrayProp(p);
|
||||
#if THREADS
|
||||
p->owner_id = worker_id;
|
||||
#endif
|
||||
|
@ -629,15 +628,14 @@ CreateStaticArray(AtomEntry *ae, Int dim, static_array_types type, CODEADDR star
|
|||
}
|
||||
}
|
||||
p->KindOfPE = ArrayProperty;
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
INIT_RWLOCK(p->ArRWLock);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
p->NextAE = LOCAL_StaticArrays;
|
||||
LOCAL_StaticArrays = p;
|
||||
}
|
||||
WRITE_LOCK(p->ArRWLock);
|
||||
p->ArrayEArity = -dim;
|
||||
p->ArrayType = type;
|
||||
ae->PropsOfAE = AbsArrayProp((ArrayEntry *)p);
|
||||
if (start_addr == NULL) {
|
||||
int i;
|
||||
|
||||
|
|
3
C/bb.c
3
C/bb.c
|
@ -43,8 +43,7 @@ PutBBProp(AtomEntry *ae, Term mod USES_REGS) /* get BBentry for at; */
|
|||
Yap_Error(OUT_OF_HEAP_ERROR,ARG1,"could not allocate space in bb_put/2");
|
||||
return(NULL);
|
||||
}
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsBBProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
p->ModuleOfBB = mod;
|
||||
p->Element = 0L;
|
||||
p->KeyOfBB = AbsAtom(ae);
|
||||
|
|
71
C/bignum.c
71
C/bignum.c
|
@ -183,6 +183,77 @@ int Yap_CleanOpaqueVariable(CELL *pt)
|
|||
return (GLOBAL_OpaqueHandlers[blob_info].fail_handler)((void *)(blobp+1));
|
||||
}
|
||||
|
||||
Opaque_CallOnWrite
|
||||
Yap_blob_write_handler_from_slot(Int slot)
|
||||
{
|
||||
CELL blob_info, blob_tag;
|
||||
MP_INT *blobp;
|
||||
Term t = Yap_GetFromSlot(slot);
|
||||
CELL *pt = RepAppl(t);
|
||||
|
||||
#ifdef DEBUG
|
||||
/* sanity checking */
|
||||
if (pt[0] != (CELL)FunctorBigInt) {
|
||||
Yap_Error(SYSTEM_ERROR, TermNil, "CleanOpaqueVariable bad call");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
blob_tag = pt[1];
|
||||
if (blob_tag < USER_BLOB_START ||
|
||||
blob_tag >= USER_BLOB_END) {
|
||||
Yap_Error(SYSTEM_ERROR, AbsAppl(pt), "clean opaque: bad blob with tag " UInt_FORMAT ,blob_tag);
|
||||
return FALSE;
|
||||
}
|
||||
blob_info = blob_tag - USER_BLOB_START;
|
||||
if (!GLOBAL_OpaqueHandlers)
|
||||
return NULL;
|
||||
blobp = (MP_INT *)(pt+2);
|
||||
return GLOBAL_OpaqueHandlers[blob_info].write_handler;
|
||||
}
|
||||
|
||||
extern Int Yap_blob_tag_from_slot(Int slot)
|
||||
{
|
||||
Term t = Yap_GetFromSlot(slot);
|
||||
CELL *pt = RepAppl(t);
|
||||
|
||||
#ifdef DEBUG
|
||||
/* sanity checking */
|
||||
if (pt[0] != (CELL)FunctorBigInt) {
|
||||
Yap_Error(SYSTEM_ERROR, TermNil, "CleanOpaqueVariable bad call");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
return pt[1];
|
||||
}
|
||||
|
||||
void *
|
||||
Yap_blob_info_from_slot(Int slot)
|
||||
{
|
||||
CELL blob_info, blob_tag;
|
||||
MP_INT *blobp;
|
||||
Term t = Yap_GetFromSlot(slot);
|
||||
CELL *pt = RepAppl(t);
|
||||
|
||||
#ifdef DEBUG
|
||||
/* sanity checking */
|
||||
if (pt[0] != (CELL)FunctorBigInt) {
|
||||
Yap_Error(SYSTEM_ERROR, TermNil, "CleanOpaqueVariable bad call");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
blob_tag = pt[1];
|
||||
if (blob_tag < USER_BLOB_START ||
|
||||
blob_tag >= USER_BLOB_END) {
|
||||
Yap_Error(SYSTEM_ERROR, AbsAppl(pt), "clean opaque: bad blob with tag " UInt_FORMAT ,blob_tag);
|
||||
return FALSE;
|
||||
}
|
||||
blob_info = blob_tag - USER_BLOB_START;
|
||||
if (!GLOBAL_OpaqueHandlers)
|
||||
return FALSE;
|
||||
blobp = (MP_INT *)(pt+2);
|
||||
return (void *)(blobp+1);
|
||||
}
|
||||
|
||||
Term
|
||||
Yap_MkULLIntTerm(YAP_ULONG_LONG n)
|
||||
{
|
||||
|
|
|
@ -2896,8 +2896,7 @@ FetchDBPropFromKey(Term twork, int flag, int new, char *error_mssg)
|
|||
p->FunctorOfDB = (Functor) At;
|
||||
else
|
||||
p->FunctorOfDB = Yap_UnlockedMkFunctor(ae,arity);
|
||||
p->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsDBProp(p);
|
||||
AddPropToAtom(ae, (PropEntry *)p);
|
||||
}
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return
|
||||
|
|
|
@ -858,8 +858,7 @@ GetGlobalEntry(Atom at USES_REGS)
|
|||
new->NextGE = LOCAL_GlobalVariables;
|
||||
LOCAL_GlobalVariables = new;
|
||||
new->AtomOfGE = ae;
|
||||
new->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsGlobalProp(new);
|
||||
AddPropToAtom(ae, (PropEntry *)new);
|
||||
RESET_VARIABLE(&new->global);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return new;
|
||||
|
|
|
@ -3225,7 +3225,7 @@ compact_heap( USES_REGS1 )
|
|||
*/
|
||||
|
||||
#ifdef TABLING
|
||||
if (depfr != NULL && gc_B >= DepFr_cons_cp(depfr)) {
|
||||
if (depfr && gc_B >= DepFr_cons_cp(depfr)) {
|
||||
gc_B = DepFr_cons_cp(depfr);
|
||||
depfr = DepFr_next(depfr);
|
||||
}
|
||||
|
@ -3408,7 +3408,7 @@ icompact_heap( USES_REGS1 )
|
|||
*/
|
||||
|
||||
#ifdef TABLING
|
||||
if (depfr != NULL && gc_B >= DepFr_cons_cp(depfr)) {
|
||||
if (depfr && gc_B >= DepFr_cons_cp(depfr)) {
|
||||
gc_B = DepFr_cons_cp(depfr);
|
||||
depfr = DepFr_next(depfr);
|
||||
}
|
||||
|
|
9
C/init.c
9
C/init.c
|
@ -151,14 +151,13 @@ OpDec(int p, char *type, Atom a, Term m)
|
|||
if (EndOfPAEntr(info)) {
|
||||
info = (OpEntry *) Yap_AllocAtomSpace(sizeof(OpEntry));
|
||||
info->KindOfPE = Ord(OpProperty);
|
||||
info->NextOfPE = RepAtom(a)->PropsOfAE;
|
||||
info->OpModule = m;
|
||||
info->OpName = a;
|
||||
LOCK(OpListLock);
|
||||
info->OpNext = OpList;
|
||||
OpList = info;
|
||||
UNLOCK(OpListLock);
|
||||
RepAtom(a)->PropsOfAE = AbsOpProp(info);
|
||||
AddPropToAtom(ae, (PropEntry *)info);
|
||||
INIT_RWLOCK(info->OpRWLock);
|
||||
WRITE_LOCK(info->OpRWLock);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
|
@ -391,8 +390,6 @@ update_flags_from_prolog(UInt flags, PredEntry *pe)
|
|||
flags |= SourcePredFlag;
|
||||
if (pe->PredFlags & SequentialPredFlag)
|
||||
flags |= SequentialPredFlag;
|
||||
if (pe->PredFlags & MyddasPredFlag)
|
||||
flags |= MyddasPredFlag;
|
||||
if (pe->PredFlags & UDIPredFlag)
|
||||
flags |= UDIPredFlag;
|
||||
if (pe->PredFlags & ModuleTransparentPredFlag)
|
||||
|
@ -1205,9 +1202,11 @@ InitCodes(void)
|
|||
#include "ihstruct.h"
|
||||
#if THREADS
|
||||
Yap_InitThread(0);
|
||||
#endif
|
||||
#endif /* THREADS */
|
||||
InitGlobal();
|
||||
#if !THREADS
|
||||
InitWorker(0);
|
||||
#endif /* THREADS */
|
||||
InitFirstWorkerThreadHandle();
|
||||
/* make sure no one else can use these two atoms */
|
||||
CurrentModule = 0;
|
||||
|
|
|
@ -754,8 +754,10 @@ p_read2 ( USES_REGS1 )
|
|||
Int out;
|
||||
|
||||
if (!Yap_getInputStream(Yap_InitSlot(Deref(ARG8) PASS_REGS), &inp_stream)) {
|
||||
Yap_RecoverSlots(1 PASS_REGS);
|
||||
return(FALSE);
|
||||
}
|
||||
Yap_RecoverSlots(1 PASS_REGS);
|
||||
out = do_read(inp_stream, 8 PASS_REGS);
|
||||
return out;
|
||||
}
|
||||
|
@ -1094,8 +1096,10 @@ p_encoding ( USES_REGS1 )
|
|||
IOSTREAM *st;
|
||||
Term t = Deref(ARG2);
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &st)) {
|
||||
Yap_RecoverSlots(1 PASS_REGS);
|
||||
return FALSE;
|
||||
}
|
||||
Yap_RecoverSlots(1 PASS_REGS);
|
||||
if (IsVarTerm(t)) {
|
||||
return Yap_unify(ARG2, MkIntegerTerm(st->encoding));
|
||||
}
|
||||
|
@ -1129,7 +1133,7 @@ Yap_InitIOPreds(void)
|
|||
Yap_InitCPred ("$force_char_conversion", 0, p_force_char_conversion, SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$disable_char_conversion", 0, p_disable_char_conversion, SyncPredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred ("$get_default_encoding", 1, p_get_default_encoding, SafePredFlag|TestPredFlag);
|
||||
Yap_InitCPred ("$encoding", 2, p_encoding, SafePredFlag|SyncPredFlag),
|
||||
Yap_InitCPred ("$encoding", 2, p_encoding, SafePredFlag|SyncPredFlag|UserCPredFlag),
|
||||
#if HAVE_SELECT
|
||||
// Yap_InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag);
|
||||
#endif
|
||||
|
|
|
@ -72,8 +72,7 @@ GetModuleEntry(Atom at)
|
|||
new->NextME = CurrentModules;
|
||||
CurrentModules = new;
|
||||
new->AtomOfME = ae;
|
||||
new->NextOfPE = ae->PropsOfAE;
|
||||
ae->PropsOfAE = AbsModProp(new);
|
||||
AddPropToAtom(ae, (PropEntry *)new);
|
||||
return new;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,451 @@
|
|||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V. Santos Costa and Universidade do Porto 1985-- *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: stdpreds.c *
|
||||
* comments: quick saver/loader *
|
||||
* *
|
||||
* Last rev: $Date: 2011-08-29$,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $ *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#if DEBUG
|
||||
|
||||
#include "absmi.h"
|
||||
#include "Foreign.h"
|
||||
#include "alloc.h"
|
||||
#include "yapio.h"
|
||||
#include "iopreds.h"
|
||||
#include "attvar.h"
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include <SWI-Stream.h>
|
||||
|
||||
STATIC_PROTO(void RestoreEntries, (PropEntry *, int USES_REGS));
|
||||
STATIC_PROTO(void CleanCode, (PredEntry * USES_REGS));
|
||||
|
||||
#define EXPORT_ATOM_TABLE_SIZE (16*4096)
|
||||
#define EXPORT_FUNCTOR_TABLE_SIZE (16*4096)
|
||||
|
||||
typedef struct export_atom_hash_entry_struct {
|
||||
Atom val;
|
||||
struct export_atom_hash_entry_struct *next;
|
||||
} export_atom_hash_entry_t;
|
||||
|
||||
static void
|
||||
LookupAtom(Atom at)
|
||||
{
|
||||
char *p = RepAtom(at)->StrOfAE;
|
||||
CELL hash = HashFunction((unsigned char *)p) % LOCAL_ExportAtomHashTableSize;
|
||||
export_atom_hash_entry_t *a;
|
||||
|
||||
a = LOCAL_ExportAtomHashChain[hash];
|
||||
while (a) {
|
||||
if (a->val == at) {
|
||||
return;
|
||||
}
|
||||
a = a->next;
|
||||
}
|
||||
a = (export_atom_hash_entry_t *)malloc(sizeof(export_atom_hash_entry_t));
|
||||
if (!a) {
|
||||
return;
|
||||
}
|
||||
a->val = at;
|
||||
fprintf(stderr,"+%s\n",RepAtom(at)->StrOfAE);
|
||||
a->next = LOCAL_ExportAtomHashChain[hash];
|
||||
LOCAL_ExportAtomHashChain[hash] = a;
|
||||
LOCAL_ExportAtomHashTableNum++;
|
||||
}
|
||||
|
||||
typedef struct export_functor_hash_entry_struct {
|
||||
Atom name;
|
||||
UInt arity;
|
||||
struct export_functor_hash_entry_struct *next;
|
||||
} export_functor_hash_entry_t;
|
||||
|
||||
static void
|
||||
LookupFunctor(Functor fun)
|
||||
{
|
||||
CELL hash = (CELL)(fun) % LOCAL_ExportFunctorHashTableSize;
|
||||
export_functor_hash_entry_t *f;
|
||||
Atom name = NameOfFunctor(fun);
|
||||
UInt arity = ArityOfFunctor(fun);
|
||||
|
||||
f = LOCAL_ExportFunctorHashChain[hash];
|
||||
while (f) {
|
||||
if (f->name == name && f->arity == arity) {
|
||||
return;
|
||||
}
|
||||
f = f->next;
|
||||
}
|
||||
f = (export_functor_hash_entry_t *)malloc(sizeof(export_functor_hash_entry_t));
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
LookupAtom(name);
|
||||
f->name = name;
|
||||
f->arity = arity;
|
||||
f->next = LOCAL_ExportFunctorHashChain[hash];
|
||||
LOCAL_ExportFunctorHashChain[hash] = f;
|
||||
LOCAL_ExportFunctorHashTableNum++;
|
||||
}
|
||||
|
||||
static void
|
||||
InitHash(void)
|
||||
{
|
||||
LOCAL_ExportFunctorHashTableSize = EXPORT_FUNCTOR_TABLE_SIZE;
|
||||
LOCAL_ExportFunctorHashChain = (export_functor_hash_entry_t **)calloc(1, sizeof(export_functor_hash_entry_t *)* LOCAL_ExportFunctorHashTableSize);
|
||||
LOCAL_ExportAtomHashTableSize = EXPORT_ATOM_TABLE_SIZE;
|
||||
LOCAL_ExportAtomHashChain = (export_atom_hash_entry_t **)calloc(1, sizeof(export_atom_hash_entry_t *)* LOCAL_ExportAtomHashTableSize);
|
||||
}
|
||||
|
||||
static inline Atom
|
||||
AtomAdjust(Atom a)
|
||||
{
|
||||
LookupAtom(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
static inline Functor
|
||||
FuncAdjust(Functor f)
|
||||
{
|
||||
LookupFunctor(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
static inline Term
|
||||
AtomTermAdjust(Term t)
|
||||
{
|
||||
LookupAtom(AtomOfTerm(t));
|
||||
return 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
|
||||
#define IsOldDelayPtr(P) FALSE
|
||||
#define IsOldLocalInTR(P) FALSE
|
||||
#define IsOldLocalInTRPtr(P) FALSE
|
||||
#define IsOldGlobal(P) FALSE
|
||||
#define IsOldGlobalPtr(P) FALSE
|
||||
#define IsOldTrail(P) FALSE
|
||||
#define IsOldTrailPtr(P) FALSE
|
||||
|
||||
#define CharP(X) ((char *)(X))
|
||||
|
||||
#define REINIT_LOCK(P)
|
||||
#define REINIT_RWLOCK(P)
|
||||
#define BlobTypeAdjust(P) (P)
|
||||
#define NoAGCAtomAdjust(P) (P)
|
||||
#define OrArgAdjust(P)
|
||||
#define TabEntryAdjust(P)
|
||||
#define IntegerAdjust(D) (D)
|
||||
#define AddrAdjust(P) (P)
|
||||
#define MFileAdjust(P) (P)
|
||||
#define CodeVarAdjust(P) (P)
|
||||
#define ConstantAdjust(P) (P)
|
||||
#define ArityAdjust(P) (P)
|
||||
#define DoubleInCodeAdjust(P)
|
||||
#define IntegerInCodeAdjust(P)
|
||||
#define OpcodeAdjust(P) (P)
|
||||
#define ModuleAdjust(P) (P)
|
||||
#define ExternalFunctionAdjust(P) (P)
|
||||
#define DBRecordAdjust(P) (P)
|
||||
#define PredEntryAdjust(P) (P)
|
||||
#define ModEntryPtrAdjust(P) (P)
|
||||
#define AtomEntryAdjust(P) (P)
|
||||
#define GlobalEntryAdjust(P) (P)
|
||||
#define BlobTermInCodeAdjust(P) (P)
|
||||
#define CellPtoHeapAdjust(P) (P)
|
||||
#define PtoAtomHashEntryAdjust(P) (P)
|
||||
#define CellPtoHeapCellAdjust(P) (P)
|
||||
#define CellPtoTRAdjust(P) (P)
|
||||
#define CodeAddrAdjust(P) (P)
|
||||
#define ConsultObjAdjust(P) (P)
|
||||
#define DelayAddrAdjust(P) (P)
|
||||
#define DelayAdjust(P) (P)
|
||||
#define GlobalAdjust(P) (P)
|
||||
#define DBRefAdjust(P) (P)
|
||||
#define DBRefPAdjust(P) (P)
|
||||
#define DBTermAdjust(P) (P)
|
||||
#define LUIndexAdjust(P) (P)
|
||||
#define SIndexAdjust(P) (P)
|
||||
#define LocalAddrAdjust(P) (P)
|
||||
#define GlobalAddrAdjust(P) (P)
|
||||
#define OpListAdjust(P) (P)
|
||||
#define PtoLUCAdjust(P) (P)
|
||||
#define PtoStCAdjust(P) (P)
|
||||
#define PtoArrayEAdjust(P) (P)
|
||||
#define PtoArraySAdjust(P) (P)
|
||||
#define PtoGlobalEAdjust(P) (P)
|
||||
#define PtoDelayAdjust(P) (P)
|
||||
#define PtoGloAdjust(P) (P)
|
||||
#define PtoLocAdjust(P) (P)
|
||||
#define PtoHeapCellAdjust(P) (P)
|
||||
#define TermToGlobalAdjust(P) (P)
|
||||
#define PtoOpAdjust(P) (P)
|
||||
#define PtoLUClauseAdjust(P) (P)
|
||||
#define PtoLUIndexAdjust(P) (P)
|
||||
#define PtoDBTLAdjust(P) (P)
|
||||
#define PtoPredAdjust(P) (P)
|
||||
#define PtoPtoPredAdjust(P) (P)
|
||||
#define OpRTableAdjust(P) (P)
|
||||
#define OpEntryAdjust(P) (P)
|
||||
#define PropAdjust(P) (P)
|
||||
#define TrailAddrAdjust(P) (P)
|
||||
#define XAdjust(P) (P)
|
||||
#define YAdjust(P) (P)
|
||||
#define HoldEntryAdjust(P) (P)
|
||||
#define CodeCharPAdjust(P) (P)
|
||||
#define CodeVoidPAdjust(P) (P)
|
||||
#define HaltHookAdjust(P) (P)
|
||||
|
||||
#define recompute_mask(dbr)
|
||||
|
||||
#define rehash(oldcode, NOfE, KindOfEntries)
|
||||
|
||||
#define RestoreSWIHash()
|
||||
|
||||
#include "rheap.h"
|
||||
|
||||
static void
|
||||
RestoreHashPreds( USES_REGS1 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static void init_reg_copies(USES_REGS1)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
RestoreAtomList(Atom atm USES_REGS)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mark_trail(USES_REGS1)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mark_registers(USES_REGS1)
|
||||
{
|
||||
}
|
||||
|
||||
#define NEXTOP(V,TYPE) ((yamop *)(&((V)->u.TYPE.next)))
|
||||
|
||||
typedef enum {
|
||||
QLY_START_PREDICATE,
|
||||
QLY_END_PREDICATE,
|
||||
QLY_START_CLAUSE,
|
||||
QLY_END_CLAUSES,
|
||||
QLY_FUNCTORS,
|
||||
QLY_ATOMS,
|
||||
QLY_ATOM_WIDE,
|
||||
QLY_ATOM
|
||||
} qlf_tag_t;
|
||||
|
||||
#define CHECK(F) { size_t r = (F); if (!r) return r; }
|
||||
|
||||
static size_t save_bytes(IOSTREAM *stream, void *ptr, size_t sz)
|
||||
{
|
||||
return Sfwrite(ptr, sz, 1, stream);
|
||||
}
|
||||
|
||||
static size_t save_byte(IOSTREAM *stream, int byte)
|
||||
{
|
||||
return Sputc(byte, stream);
|
||||
}
|
||||
|
||||
static size_t save_uint(IOSTREAM *stream, UInt val)
|
||||
{
|
||||
UInt v = val;
|
||||
return save_bytes(stream, &v, sizeof(UInt));
|
||||
}
|
||||
|
||||
static size_t save_tag(IOSTREAM *stream, qlf_tag_t tag)
|
||||
{
|
||||
return save_byte(stream, tag);
|
||||
}
|
||||
|
||||
static int
|
||||
SaveHash(IOSTREAM *stream)
|
||||
{
|
||||
UInt i;
|
||||
CHECK(save_tag(stream, QLY_ATOMS));
|
||||
CHECK(save_uint(stream, LOCAL_ExportAtomHashTableNum));
|
||||
for (i = 0; i < LOCAL_ExportAtomHashTableSize; i++) {
|
||||
export_atom_hash_entry_t *a = LOCAL_ExportAtomHashChain[i];
|
||||
while (a) {
|
||||
export_atom_hash_entry_t *a0 = a;
|
||||
Atom at = a->val;
|
||||
CHECK(save_uint(stream, (UInt)at));
|
||||
if (IsWideAtom(at)) {
|
||||
CHECK(save_tag(stream, QLY_ATOM_WIDE));
|
||||
CHECK(save_uint(stream, wcslen(RepAtom(at)->WStrOfAE)));
|
||||
CHECK(save_bytes(stream, at->WStrOfAE, wcslen(at->WStrOfAE)*sizeof(wchar_t)));
|
||||
} else {
|
||||
CHECK(save_tag(stream, QLY_ATOM));
|
||||
CHECK(save_uint(stream, strlen(RepAtom(at)->StrOfAE)));
|
||||
CHECK(save_bytes(stream, at->StrOfAE, (strlen(at->StrOfAE)+1)*sizeof(char)));
|
||||
}
|
||||
a = a->next;
|
||||
free(a0);
|
||||
}
|
||||
}
|
||||
save_tag(stream, QLY_FUNCTORS);
|
||||
save_uint(stream, LOCAL_ExportFunctorHashTableNum);
|
||||
for (i = 0; i < LOCAL_ExportFunctorHashTableSize; i++) {
|
||||
export_functor_hash_entry_t *f = LOCAL_ExportFunctorHashChain[i];
|
||||
while (f) {
|
||||
export_functor_hash_entry_t *f0 = f;
|
||||
CHECK(save_uint(stream, f->arity));
|
||||
CHECK(save_uint(stream, (CELL)(f->name)));
|
||||
f = f->next;
|
||||
free(f0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static size_t
|
||||
save_clauses(IOSTREAM *stream, PredEntry *pp) {
|
||||
yamop *FirstC, *LastC;
|
||||
|
||||
FirstC = pp->cs.p_code.FirstClause;
|
||||
LastC = pp->cs.p_code.LastClause;
|
||||
if (FirstC == NULL && LastC == NULL) {
|
||||
return save_tag(stream, QLY_END_CLAUSES);
|
||||
}
|
||||
if (pp->PredFlags & LogUpdatePredFlag) {
|
||||
LogUpdClause *cl = ClauseCodeToLogUpdClause(FirstC);
|
||||
|
||||
while (cl != NULL) {
|
||||
UInt size = cl->ClSize;
|
||||
CHECK(save_bytes(stream, cl, size));
|
||||
cl = cl->ClNext;
|
||||
}
|
||||
} else if (pp->PredFlags & MegaClausePredFlag) {
|
||||
MegaClause *cl = ClauseCodeToMegaClause(FirstC);
|
||||
UInt size = cl->ClSize;
|
||||
|
||||
CHECK(save_bytes(stream, cl, size));
|
||||
} else if (pp->PredFlags & DynamicPredFlag) {
|
||||
yamop *cl = FirstC;
|
||||
|
||||
do {
|
||||
DynamicClause *dcl = ClauseCodeToDynamicClause(cl);
|
||||
UInt size = dcl->ClSize;
|
||||
|
||||
CHECK(save_bytes(stream, dcl, size));
|
||||
if (cl == LastC) return 1;
|
||||
cl = NextDynamicClause(cl);
|
||||
} while (TRUE);
|
||||
} else {
|
||||
StaticClause *cl = ClauseCodeToStaticClause(FirstC);
|
||||
|
||||
do {
|
||||
UInt size = cl->ClSize;
|
||||
|
||||
CHECK(save_bytes(stream, cl, size));
|
||||
if (cl->ClCode == LastC) return 1;
|
||||
cl = cl->ClNext;
|
||||
} while (TRUE);
|
||||
}
|
||||
return save_tag(stream, QLY_END_CLAUSES);
|
||||
}
|
||||
|
||||
static size_t
|
||||
save_pred(IOSTREAM *stream, PredEntry *ap) {
|
||||
CHECK(save_uint(stream, (UInt)(ap->FunctorOfPred)));
|
||||
CHECK(save_uint(stream, ap->ArityOfPE));
|
||||
CHECK(save_uint(stream, ap->PredFlags));
|
||||
CHECK(save_uint(stream, ap->cs.p_code.NOfClauses));
|
||||
return save_clauses(stream, ap);
|
||||
}
|
||||
|
||||
static int
|
||||
clean_pred(PredEntry *pp USES_REGS) {
|
||||
if (pp->PredFlags & (AsmPredFlag|CPredFlag)) {
|
||||
/* assembly */
|
||||
if (pp->CodeOfPred) {
|
||||
CleanClauses(pp->CodeOfPred, pp->CodeOfPred, pp PASS_REGS);
|
||||
}
|
||||
} else {
|
||||
CleanClauses(pp->cs.p_code.FirstClause, pp->cs.p_code.LastClause, pp PASS_REGS);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static size_t
|
||||
save_module(IOSTREAM *stream, Term mod) {
|
||||
CACHE_REGS
|
||||
PredEntry *ap = Yap_ModulePred(mod);
|
||||
InitHash();
|
||||
while (ap) {
|
||||
fprintf(stderr,"P %s\n",RepAtom(NameOfFunctor(ap->FunctorOfPred))->StrOfAE);
|
||||
if (ap->ArityOfPE) {
|
||||
FuncAdjust(ap->FunctorOfPred);
|
||||
} else {
|
||||
AtomAdjust((Atom)(ap->FunctorOfPred));
|
||||
}
|
||||
CHECK(clean_pred(ap PASS_REGS));
|
||||
ap = ap->NextPredOfModule;
|
||||
}
|
||||
SaveHash(stream);
|
||||
ap = Yap_ModulePred(mod);
|
||||
while (ap) {
|
||||
CHECK(save_pred(stream, ap));
|
||||
ap = ap->NextPredOfModule;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_save_module_preds( USES_REGS1 )
|
||||
{
|
||||
IOSTREAM *stream;
|
||||
Term tmod = Deref(ARG2);
|
||||
|
||||
if (!Yap_getOutputStream(Yap_InitSlot(Deref(ARG1) PASS_REGS), &stream)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (IsVarTerm(tmod)) {
|
||||
Yap_Error(INSTANTIATION_ERROR,tmod,"save_module/2");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsAtomTerm(tmod)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM,tmod,"save_module/2");
|
||||
return FALSE;
|
||||
}
|
||||
return save_module(stream, tmod) != 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Yap_InitQLY(void)
|
||||
{
|
||||
#if DEBUG
|
||||
Yap_InitCPred("$save_module_preds", 2, p_save_module_preds, SyncPredFlag|HiddenPredFlag|UserCPredFlag);
|
||||
#endif
|
||||
}
|
||||
|
29
C/scanner.c
29
C/scanner.c
|
@ -1260,13 +1260,32 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp)
|
|||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF);
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
} else {
|
||||
Atom ae;
|
||||
TokImage = ((AtomEntry *) ( Yap_PreAllocCodeSpace()))->StrOfAE;
|
||||
charp = TokImage;
|
||||
*charp++ = och;
|
||||
for (; chtype(ch) == SY; ch = getchr(inp_stream))
|
||||
*charp++ = ch;
|
||||
*charp = '\0';
|
||||
t->TokInfo = Unsigned(Yap_LookupAtom(TokImage));
|
||||
wcharp = NULL;
|
||||
add_ch_to_buff(och);
|
||||
for (; chtype(ch) == SY; ch = getchr(inp_stream)) {
|
||||
if (charp == (char *)AuxSp-1024) {
|
||||
goto huge_var_error;
|
||||
}
|
||||
add_ch_to_buff(ch);
|
||||
}
|
||||
add_ch_to_buff('\0');
|
||||
if (wcharp) {
|
||||
ae = Yap_LookupWideAtom((wchar_t *)TokImage);
|
||||
} else {
|
||||
ae = Yap_LookupAtom(TokImage);
|
||||
}
|
||||
if (ae == NIL) {
|
||||
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
|
||||
LOCAL_ErrorMessage = "Code Space Overflow";
|
||||
if (p)
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
t->TokInfo = Unsigned(ae);
|
||||
if (t->TokInfo == (CELL)NIL) {
|
||||
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
|
||||
LOCAL_ErrorMessage = "Code Space Overflow";
|
||||
|
|
|
@ -4481,6 +4481,7 @@ Yap_InitCPreds(void)
|
|||
Yap_InitSavePreds();
|
||||
Yap_InitSysPreds();
|
||||
Yap_InitUnify();
|
||||
Yap_InitQLY();
|
||||
#if defined CUT_C && defined MYDDAS_MYSQL
|
||||
Yap_InitMYDDAS_MySQLPreds();
|
||||
#endif
|
||||
|
|
|
@ -191,6 +191,9 @@ setup_engine(int myworker_id, int init_thread)
|
|||
GLOBAL_NOfThreadsCreated++;
|
||||
DEBUG_TLOCK_ACCESS(2, myworker_id);
|
||||
pthread_mutex_unlock(&(REMOTE_ThreadHandle(myworker_id).tlock));
|
||||
#ifdef TABLING
|
||||
DepFr_cons_cp(LOCAL_top_dep_fr) = B; /* same as in Yap_init_root_frames() */
|
||||
#endif /* TABLING */
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -686,9 +686,8 @@ p_softfunctor()
|
|||
WRITE_LOCK(RepAtom(a)->ARWLock);
|
||||
if ((p0 = Yap_GetAProp(a, SFProperty)) == NIL) {
|
||||
pe = (SFEntry *) Yap_AllocAtomSpace(sizeof(*pe));
|
||||
pe->NextOfPE = RepAtom(a)->PropsOfAE;
|
||||
pe->KindOfPE = SFProperty;
|
||||
RepAtom(a)->PropsOfAE = AbsSFProp(pe);
|
||||
AddPropToAtom(RepAtom(a), (PropEntry *)pe);
|
||||
} else
|
||||
pe = RepSFProp(p0);
|
||||
WRITE_UNLOCK(RepAtom(a)->ARWLock);
|
||||
|
|
102
H/Yap.h
102
H/Yap.h
|
@ -1186,44 +1186,6 @@ typedef enum
|
|||
} yap_exec_mode;
|
||||
|
||||
|
||||
/*************************************************************************************************
|
||||
slots
|
||||
*************************************************************************************************/
|
||||
|
||||
|
||||
static inline void
|
||||
Yap_StartSlots( USES_REGS1 ) {
|
||||
*--ASP = MkIntegerTerm(CurSlot);
|
||||
*--ASP = MkIntTerm(0);
|
||||
CurSlot = LCL0-ASP;
|
||||
}
|
||||
|
||||
static inline void
|
||||
Yap_CloseSlots( USES_REGS1 ) {
|
||||
Int old_slots;
|
||||
old_slots = IntOfTerm(ASP[0]);
|
||||
ASP += (old_slots+1);
|
||||
CurSlot = IntOfTerm(*ASP);
|
||||
ASP++;
|
||||
}
|
||||
|
||||
static inline Int
|
||||
Yap_CurrentSlot( USES_REGS1 ) {
|
||||
return IntOfTerm(ASP[0]);
|
||||
}
|
||||
|
||||
/* pop slots when pruning */
|
||||
static inline void
|
||||
Yap_PopSlots( USES_REGS1 ) {
|
||||
while (LCL0-CurSlot < ASP) {
|
||||
Int old_slots;
|
||||
CELL *ptr = LCL0-CurSlot;
|
||||
old_slots = IntOfTerm(ptr[0]);
|
||||
ptr += (old_slots+1);
|
||||
CurSlot = IntOfTerm(*ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/************************/
|
||||
#ifdef THREADS
|
||||
typedef struct thandle {
|
||||
|
@ -1400,4 +1362,68 @@ TailOfTermCell (Term t)
|
|||
return (Term) ((CELL) (RepPair (t) + 1));
|
||||
}
|
||||
|
||||
/*************************************************************************************************
|
||||
slots
|
||||
*************************************************************************************************/
|
||||
|
||||
|
||||
static inline void
|
||||
Yap_StartSlots( USES_REGS1 ) {
|
||||
*--ASP = MkIntegerTerm(CurSlot);
|
||||
*--ASP = MkIntTerm(0);
|
||||
CurSlot = LCL0-ASP;
|
||||
}
|
||||
|
||||
static inline void
|
||||
Yap_CloseSlots( USES_REGS1 ) {
|
||||
Int old_slots;
|
||||
old_slots = IntOfTerm(ASP[0]);
|
||||
ASP += (old_slots+1);
|
||||
CurSlot = IntOfTerm(*ASP);
|
||||
ASP++;
|
||||
}
|
||||
|
||||
static inline Int
|
||||
Yap_CurrentSlot( USES_REGS1 ) {
|
||||
return IntOfTerm(ASP[0]);
|
||||
}
|
||||
|
||||
/* pop slots when pruning */
|
||||
static inline void
|
||||
Yap_PopSlots( USES_REGS1 ) {
|
||||
while (LCL0-CurSlot < ASP) {
|
||||
Int old_slots;
|
||||
CELL *ptr = LCL0-CurSlot;
|
||||
old_slots = IntOfTerm(ptr[0]);
|
||||
ptr += (old_slots+1);
|
||||
CurSlot = IntOfTerm(*ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static inline Term
|
||||
Yap_GetFromSlot(Int slot USES_REGS)
|
||||
{
|
||||
return(Deref(LCL0[slot]));
|
||||
}
|
||||
|
||||
static inline Term
|
||||
Yap_GetPtrFromSlot(Int slot USES_REGS)
|
||||
{
|
||||
return(LCL0[slot]);
|
||||
}
|
||||
|
||||
static inline Term *
|
||||
Yap_AddressFromSlot(Int slot USES_REGS)
|
||||
{
|
||||
return(LCL0+slot);
|
||||
}
|
||||
|
||||
static inline void
|
||||
Yap_PutInSlot(Int slot, Term t USES_REGS)
|
||||
{
|
||||
LCL0[slot] = t;
|
||||
}
|
||||
|
||||
|
||||
#endif /* YAP_H */
|
||||
|
||||
|
|
|
@ -34,11 +34,17 @@ typedef int (*SWI_PLGetStreamPositionFunction)(void *);
|
|||
#include "../include/dswiatoms.h"
|
||||
|
||||
typedef int (*Opaque_CallOnFail)(void *);
|
||||
typedef int (*Opaque_CallOnWrite)(void *, int, void *, int);
|
||||
|
||||
typedef struct opaque_handler_struct {
|
||||
Opaque_CallOnFail fail_handler;
|
||||
Opaque_CallOnWrite write_handler;
|
||||
} opaque_handler_t;
|
||||
|
||||
extern Opaque_CallOnWrite Yap_blob_write_handler_from_slot(Int slot);
|
||||
extern Int Yap_blob_tag_from_slot(Int slot);
|
||||
extern void *Yap_blob_info_from_slot(Int slot);
|
||||
|
||||
#ifndef INT_KEYS_DEFAULT_SIZE
|
||||
#define INT_KEYS_DEFAULT_SIZE 256
|
||||
#endif
|
||||
|
|
|
@ -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),
|
||||
|
|
13
H/Yapproto.h
13
H/Yapproto.h
|
@ -61,11 +61,7 @@ int STD_PROTO(Yap_AtomDecreaseHold,(Atom));
|
|||
|
||||
Int STD_PROTO(Yap_InitSlot,(Term CACHE_TYPE));
|
||||
Int STD_PROTO(Yap_NewSlots,(int CACHE_TYPE));
|
||||
Term STD_PROTO(Yap_GetFromSlot,(Int CACHE_TYPE));
|
||||
int STD_PROTO(Yap_RecoverSlots,(int CACHE_TYPE));
|
||||
Term STD_PROTO(Yap_GetPtrFromSlot,(Int CACHE_TYPE));
|
||||
Term *STD_PROTO(Yap_AddressFromSlot,(Int CACHE_TYPE));
|
||||
void STD_PROTO(Yap_PutInSlot,(Int, Term CACHE_TYPE));
|
||||
|
||||
|
||||
#ifdef SFUNC
|
||||
|
@ -311,6 +307,9 @@ Term STD_PROTO(Yap_Parse,(void));
|
|||
/* readutil.c */
|
||||
void STD_PROTO(Yap_InitReadUtil,(void));
|
||||
|
||||
/* qly.c */
|
||||
void STD_PROTO(Yap_InitQLY,(void));
|
||||
|
||||
/* save.c */
|
||||
int STD_PROTO(Yap_SavedInfo,(char *,char *,CELL *,CELL *,CELL *));
|
||||
int STD_PROTO(Yap_Restore,(char *, char *));
|
||||
|
@ -491,3 +490,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
|
||||
|
||||
|
|
21
H/Yatom.h
21
H/Yatom.h
|
@ -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 */
|
||||
/* MyddasPredFlag = 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
|
||||
|
@ -1606,5 +1606,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
|
||||
|
||||
|
|
|
@ -693,7 +693,7 @@ typedef struct yami {
|
|||
struct pred_entry *p;
|
||||
Int i;
|
||||
CELL next;
|
||||
} Osbpi;
|
||||
} Osbpa;
|
||||
struct {
|
||||
#ifdef YAPOR
|
||||
unsigned int or_arg;
|
||||
|
|
13
H/dlocals.h
13
H/dlocals.h
|
@ -329,3 +329,16 @@
|
|||
#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_
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -182,10 +182,17 @@ 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_;
|
||||
} w_local;
|
||||
|
|
|
@ -188,4 +188,11 @@ 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;
|
||||
}
|
||||
|
|
14
H/rclause.h
14
H/rclause.h
|
@ -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:
|
||||
|
|
|
@ -188,4 +188,11 @@ static void RestoreWorker(int wid USES_REGS) {
|
|||
#ifdef LOW_LEVEL_TRACER
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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:
|
||||
|
|
10
Makefile.in
10
Makefile.in
|
@ -248,6 +248,7 @@ C_SOURCES= \
|
|||
$(srcdir)/C/load_shl.c $(srcdir)/C/load_dyld.c \
|
||||
$(srcdir)/C/mavar.c $(srcdir)/C/modules.c $(srcdir)/C/other.c \
|
||||
$(srcdir)/C/parser.c \
|
||||
$(srcdir)/C/qlyw.c \
|
||||
$(srcdir)/C/save.c $(srcdir)/C/scanner.c \
|
||||
$(srcdir)/C/sort.c $(srcdir)/C/stdpreds.c $(srcdir)/C/sysbits.c \
|
||||
$(srcdir)/C/threads.c \
|
||||
|
@ -315,6 +316,7 @@ PL_SOURCES= \
|
|||
$(srcdir)/pl/modules.yap $(srcdir)/pl/preds.yap \
|
||||
$(srcdir)/pl/profile.yap \
|
||||
$(srcdir)/pl/protect.yap \
|
||||
$(srcdir)/pl/qly.yap \
|
||||
$(srcdir)/pl/save.yap \
|
||||
$(srcdir)/pl/setof.yap \
|
||||
$(srcdir)/pl/signals.yap \
|
||||
|
@ -356,7 +358,7 @@ ENGINE_OBJECTS = \
|
|||
myddas_mysql.o myddas_odbc.o myddas_shared.o myddas_initialization.o \
|
||||
myddas_util.o myddas_statistics.o myddas_top_level.o \
|
||||
myddas_wkb2prolog.o modules.o other.o \
|
||||
parser.o save.o scanner.o sort.o stdpreds.o \
|
||||
parser.o qlyw.o save.o scanner.o sort.o stdpreds.o \
|
||||
sysbits.o threads.o tracer.o \
|
||||
udi.o rtree.o rtree_udi.o\
|
||||
unify.o userpreds.o utilpreds.o \
|
||||
|
@ -442,6 +444,9 @@ init.o: $(srcdir)/C/init.c config.h
|
|||
load_foreign.o: $(srcdir)/C/load_foreign.c config.h
|
||||
$(CC) -c $(CFLAGS) $(srcdir)/C/load_foreign.c -o $@
|
||||
|
||||
qlyw.o: $(srcdir)/C/qlyw.c config.h
|
||||
$(CC) -c $(CFLAGS) $(srcdir)/C/qlyw.c -o $@
|
||||
|
||||
save.o: $(srcdir)/C/save.c config.h
|
||||
$(CC) -c $(CFLAGS) $(srcdir)/C/save.c -o $@
|
||||
|
||||
|
@ -672,6 +677,7 @@ mycb: $(srcdir)/mycb.c
|
|||
$(CC) $(CFLAGS) $(srcdir)/mycb.c -o mycb
|
||||
|
||||
all: startup.yss
|
||||
@ENABLE_GECODE@ @INSTALL_DLLS@ (cd library/gecode; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/lammpi; $(MAKE))
|
||||
@INSTALL_MATLAB@ (cd library/matlab; $(MAKE))
|
||||
@INSTALL_DLLS@ (cd library/matrix; $(MAKE))
|
||||
|
@ -744,6 +750,7 @@ install_unix: startup.yss libYap.a
|
|||
@INSTALL_DLLS@ (cd library/rltree; $(MAKE) install)
|
||||
@INSTALL_DLLS@ (cd library/system; $(MAKE) install)
|
||||
@INSTALL_DLLS@ (cd library/tries; $(MAKE) install)
|
||||
@ENABLE_GECODE@ @INSTALL_DLLS@ (cd library/gecode; $(MAKE) install)
|
||||
@ENABLE_CLIB@ @INSTALL_DLLS@ (cd packages/clib; $(MAKE) install)
|
||||
@ENABLE_HTTP@ @INSTALL_DLLS@ (cd packages/http; $(MAKE) install)
|
||||
@ENABLE_PLDOC@ @INSTALL_DLLS@ (cd packages/pldoc; $(MAKE) install)
|
||||
|
@ -851,6 +858,7 @@ depend: $(HEADERS) $(C_SOURCES)
|
|||
|
||||
clean: clean_docs
|
||||
rm -f *.o *~ *.BAK *.a
|
||||
@ENABLE_GECODE@ @INSTALL_DLLS@ (cd library/gecode; $(MAKE) clean)
|
||||
@INSTALL_DLLS@ (cd library/lammpi; $(MAKE) clean)
|
||||
@INSTALL_MATLAB@ (cd library/matlab; $(MAKE) clean)
|
||||
@INSTALL_DLLS@ (cd library/matrix; $(MAKE) clean)
|
||||
|
|
|
@ -140,7 +140,9 @@ void Yap_init_global_optyap_data(int max_table_size, int n_workers, int sch_loop
|
|||
GLOBAL_last_sg_fr = NULL;
|
||||
GLOBAL_check_sg_fr = NULL;
|
||||
#endif /* LIMIT_TABLING */
|
||||
#ifdef YAPOR
|
||||
new_dependency_frame(GLOBAL_root_dep_fr, FALSE, NULL, NULL, NULL, NULL, NULL);
|
||||
#endif /* YAPOR */
|
||||
for (i = 0; i < MAX_TABLE_VARS; i++) {
|
||||
CELL *pt = GLOBAL_table_var_enumerator_addr(i);
|
||||
RESET_VARIABLE(pt);
|
||||
|
@ -175,10 +177,12 @@ void Yap_init_local_optyap_data(int wid) {
|
|||
/* local data related to tabling */
|
||||
REMOTE_next_free_ans_node(wid) = NULL;
|
||||
REMOTE_top_sg_fr(wid) = NULL;
|
||||
REMOTE_top_dep_fr(wid) = GLOBAL_root_dep_fr;
|
||||
#ifdef YAPOR
|
||||
REMOTE_top_dep_fr(wid) = GLOBAL_root_dep_fr;
|
||||
Set_REMOTE_top_cp_on_stack(wid, (choiceptr) LOCAL_LocalBase); /* ??? */
|
||||
REMOTE_top_susp_or_fr(wid) = GLOBAL_root_or_fr;
|
||||
#else
|
||||
new_dependency_frame(REMOTE_top_dep_fr(wid), FALSE, NULL, NULL, NULL, NULL, NULL);
|
||||
#endif /* YAPOR */
|
||||
#endif /* TABLING */
|
||||
return;
|
||||
|
@ -214,7 +218,11 @@ void Yap_init_root_frames(void) {
|
|||
|
||||
#ifdef TABLING
|
||||
/* root dependency frame */
|
||||
#ifdef YAPOR
|
||||
DepFr_cons_cp(GLOBAL_root_dep_fr) = B;
|
||||
#else
|
||||
DepFr_cons_cp(LOCAL_top_dep_fr) = B;
|
||||
#endif /* YAPOR */
|
||||
#endif /* TABLING */
|
||||
}
|
||||
|
||||
|
|
|
@ -393,17 +393,17 @@ static Int p_show_tabled_predicates( USES_REGS1 ) {
|
|||
IOSTREAM *out;
|
||||
tab_ent_ptr tab_ent;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
tab_ent = GLOBAL_root_tab_ent;
|
||||
Sfprintf(out, "Tabled predicates\n");
|
||||
if (tab_ent == NULL)
|
||||
Sfprintf(out, " NONE\n");
|
||||
else
|
||||
while(tab_ent) {
|
||||
Sfprintf(out, " %s/%d\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
|
||||
tab_ent = TabEnt_next(tab_ent);
|
||||
}
|
||||
else while(tab_ent) {
|
||||
Sfprintf(out, " %s/%d\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
|
||||
tab_ent = TabEnt_next(tab_ent);
|
||||
}
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
@ -413,7 +413,7 @@ static Int p_show_table( USES_REGS1 ) {
|
|||
Term mod, t;
|
||||
tab_ent_ptr tab_ent;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
mod = Deref(ARG2);
|
||||
t = Deref(ARG3);
|
||||
|
@ -421,9 +421,12 @@ static Int p_show_table( USES_REGS1 ) {
|
|||
tab_ent = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod))->TableOfPred;
|
||||
else if (IsApplTerm(t))
|
||||
tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred;
|
||||
else
|
||||
else {
|
||||
PL_release_stream(out);
|
||||
return (FALSE);
|
||||
}
|
||||
show_table(tab_ent, SHOW_MODE_STRUCTURE, out);
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
@ -432,20 +435,31 @@ static Int p_show_all_tables( USES_REGS1 ) {
|
|||
IOSTREAM *out;
|
||||
tab_ent_ptr tab_ent;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
tab_ent = GLOBAL_root_tab_ent;
|
||||
while(tab_ent) {
|
||||
show_table(tab_ent, SHOW_MODE_STRUCTURE, out);
|
||||
tab_ent = TabEnt_next(tab_ent);
|
||||
}
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Int p_show_all_local_tables( USES_REGS1 ) {
|
||||
#ifdef THREADS
|
||||
IOSTREAM *out;
|
||||
tab_ent_ptr tab_ent;
|
||||
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
tab_ent = GLOBAL_root_tab_ent;
|
||||
while(tab_ent) {
|
||||
show_table(tab_ent, SHOW_MODE_STRUCTURE, out);
|
||||
tab_ent = TabEnt_next(tab_ent);
|
||||
}
|
||||
PL_release_stream(out);
|
||||
#else
|
||||
p_show_all_tables();
|
||||
#endif /* THREADS */
|
||||
|
@ -456,9 +470,10 @@ static Int p_show_all_local_tables( USES_REGS1 ) {
|
|||
static Int p_show_global_trie( USES_REGS1 ) {
|
||||
IOSTREAM *out;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
show_global_trie(SHOW_MODE_STRUCTURE, out);
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
@ -468,7 +483,7 @@ static Int p_show_statistics_table( USES_REGS1 ) {
|
|||
Term mod, t;
|
||||
tab_ent_ptr tab_ent;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
mod = Deref(ARG2);
|
||||
t = Deref(ARG3);
|
||||
|
@ -476,9 +491,12 @@ static Int p_show_statistics_table( USES_REGS1 ) {
|
|||
tab_ent = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod))->TableOfPred;
|
||||
else if (IsApplTerm(t))
|
||||
tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred;
|
||||
else
|
||||
else {
|
||||
PL_release_stream(out);
|
||||
return (FALSE);
|
||||
}
|
||||
show_table(tab_ent, SHOW_MODE_STATISTICS, out);
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
@ -487,7 +505,7 @@ static Int p_show_statistics_tabling( USES_REGS1 ) {
|
|||
IOSTREAM *out;
|
||||
long total_bytes = 0, aux_bytes;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
aux_bytes = 0;
|
||||
Sfprintf(out, "Execution data structures\n");
|
||||
|
@ -518,15 +536,17 @@ static Int p_show_statistics_tabling( USES_REGS1 ) {
|
|||
#else
|
||||
Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes);
|
||||
#endif /* USE_PAGES_MALLOC */
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static Int p_show_statistics_global_trie( USES_REGS1 ) {
|
||||
IOSTREAM *out;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
show_global_trie(SHOW_MODE_STATISTICS, out);
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
#endif /* TABLING */
|
||||
|
@ -592,7 +612,7 @@ static Int p_yapor_workers( USES_REGS1 ) {
|
|||
return Yap_unify(MkIntegerTerm(GLOBAL_number_workers),ARG1);
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
#endif /* YAPOR_THREADS */
|
||||
}
|
||||
|
||||
|
||||
|
@ -628,7 +648,7 @@ static Int p_show_statistics_or( USES_REGS1 ) {
|
|||
IOSTREAM *out;
|
||||
long total_bytes = 0, aux_bytes;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
aux_bytes = 0;
|
||||
Sfprintf(out, "Execution data structures\n");
|
||||
|
@ -649,6 +669,7 @@ static Int p_show_statistics_or( USES_REGS1 ) {
|
|||
#else
|
||||
Sfprintf(out, "Total memory in use (I+II): %10ld bytes\n", total_bytes);
|
||||
#endif /* USE_PAGES_MALLOC */
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
#endif /* YAPOR */
|
||||
|
@ -664,7 +685,7 @@ static Int p_show_statistics_opt( USES_REGS1 ) {
|
|||
IOSTREAM *out;
|
||||
long total_bytes = 0, aux_bytes;
|
||||
|
||||
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
|
||||
if (!PL_get_stream_handle(Yap_InitSlot(Deref(ARG1) PASS_REGS), &out))
|
||||
return (FALSE);
|
||||
aux_bytes = 0;
|
||||
Sfprintf(out, "Execution data structures\n");
|
||||
|
@ -707,6 +728,7 @@ static Int p_show_statistics_opt( USES_REGS1 ) {
|
|||
#else
|
||||
Sfprintf(out, "Total memory in use (I+II+III+IV): %10ld bytes\n", total_bytes);
|
||||
#endif /* USE_PAGES_MALLOC */
|
||||
PL_release_stream(out);
|
||||
return (TRUE);
|
||||
}
|
||||
#endif /* YAPOR && TABLING */
|
||||
|
|
|
@ -209,7 +209,9 @@ struct global_optyap_data {
|
|||
struct subgoal_frame *last_subgoal_frame;
|
||||
struct subgoal_frame *check_subgoal_frame;
|
||||
#endif /* LIMIT_TABLING */
|
||||
#ifdef YAPOR
|
||||
struct dependency_frame *root_dependency_frame;
|
||||
#endif /* YAPOR */
|
||||
CELL table_var_enumerator[MAX_TABLE_VARS];
|
||||
#ifdef TABLE_LOCK_AT_WRITE_LEVEL
|
||||
lockvar table_lock[TABLE_LOCK_BUCKETS];
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
#include "parms.h"
|
||||
|
||||
/* are dynamic arrays supported? */
|
||||
#undef HAVE_DYNARRAY
|
||||
|
||||
/* are we using gcc */
|
||||
#undef HAVE_GCC
|
||||
|
||||
|
|
60
configure.in
60
configure.in
|
@ -55,6 +55,41 @@ AC_PROG_AWK
|
|||
AC_SUBST(GCC)
|
||||
AC_SUBST(C_INTERF_FLAGS)
|
||||
AC_SUBST(C_PARSER_FLAGS)
|
||||
AC_LANG(C)
|
||||
|
||||
dnl Gecode support
|
||||
AC_CHECK_HEADER(gecode/support/config.hpp,
|
||||
have_gecode=yes, have_gecode=no)
|
||||
use_gecode_default=no
|
||||
AC_SUBST(PYTHON)
|
||||
if test "$have_gecode" = yes; then
|
||||
AC_CHECK_PROGS(PYTHON, [python2.78 python], [none])
|
||||
if test "$PYTHON" != none; then
|
||||
use_gecode_default=yes
|
||||
fi
|
||||
else
|
||||
PYTHON=none
|
||||
fi
|
||||
AC_ARG_ENABLE(gecode,
|
||||
[ --enable-gecode install gecode library],
|
||||
[use_gecode="$enableval"
|
||||
if test "$use_gecode" = yes; then
|
||||
if test "$have_gecode" = no; then
|
||||
AC_MSG_ERROR([cannot enable gecode: gecode library not found])
|
||||
fi
|
||||
if test "$PYTHON" = none; then
|
||||
AC_MSG_ERROR([cannot enable gecode: python not found])
|
||||
fi
|
||||
fi], use_gecode=$use_gecode_default)
|
||||
AC_MSG_CHECKING([if dynamic arrays are supported])
|
||||
AC_COMPILE_IFELSE([
|
||||
AC_LANG_PROGRAM([[void foo(int n) { int a[n]; a[1]=0; }]],[[foo(3);]])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE([HAVE_DYNARRAY],[1],[Define if dynamic arrays are supported])
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(tabling,
|
||||
[ --enable-tabling support tabling ],
|
||||
|
@ -198,7 +233,7 @@ AC_ARG_WITH(cudd,
|
|||
[yap_cv_cudd=no])
|
||||
|
||||
AC_ARG_ENABLE(myddas,
|
||||
v [ --enable-myddas[[=DIR]] enable the MYDDAS library],
|
||||
[ --enable-myddas[[=DIR]] enable the MYDDAS library],
|
||||
if test "$enableval" = yes; then
|
||||
yap_cv_myddas=/usr
|
||||
elif test "$enableval" = no; then
|
||||
|
@ -475,11 +510,11 @@ if test "$GCC" = "yes"
|
|||
then
|
||||
if test "$debugyap" = "yes"
|
||||
then
|
||||
CXXFLAGS="-O -g -Wall $CFLAGS"
|
||||
CXXFLAGS="-O -g -Wall $CXXFLAGS"
|
||||
C_INTERF_FLAGS="-O -g -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
|
||||
CFLAGS="-O -g -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
|
||||
else
|
||||
CXXFLAGS="-O3 -fomit-frame-pointer -Wall $CFLAGS"
|
||||
CXXFLAGS="-O3 -fomit-frame-pointer -Wall $CXXFLAGS"
|
||||
C_INTERF_FLAGS="-O3 -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
|
||||
C_PARSER_FLAGS="-O3 -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
|
||||
CFLAGS="-O3 -fomit-frame-pointer -Wall -Wstrict-prototypes -Wmissing-prototypes $CFLAGS"
|
||||
|
@ -495,7 +530,7 @@ then
|
|||
case "$target_os" in
|
||||
*solaris[2-9]*) dnl
|
||||
CFLAGS="-mno-app-regs -DOPTIMISE_ALL_REGS_FOR_SPARC=1 $CFLAGS"
|
||||
CXXFLAGS="-mno-app-regs -DOPTIMISE_ALL_REGS_FOR_SPARC=1 $CFPPLAGS"
|
||||
CXXFLAGS="-mno-app-regs -DOPTIMISE_ALL_REGS_FOR_SPARC=1 $CXXFLAGS"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
@ -544,7 +579,7 @@ else
|
|||
CFLAGS="-A -A $CFLAGS"
|
||||
elif test "$CC" = "cl"
|
||||
then
|
||||
CXXFLAGS="-/nologo $CFLAGS"
|
||||
CXXFLAGS="-/nologo $CXXFLAGS"
|
||||
CFLAGS="/nologo $CFLAGS"
|
||||
CPP="/nologo /E"
|
||||
fi
|
||||
|
@ -554,10 +589,10 @@ else
|
|||
then
|
||||
if test "$debugyap" = "yes"
|
||||
then
|
||||
CXXFLAGS="-Ae -g -O $CFLAGS"
|
||||
CXXFLAGS="-Ae -g -O $CXXFLAGS"
|
||||
CFLAGS="-Ae -g -O $CFLAGS"
|
||||
else
|
||||
CXXFLAGS="-Ae +O3 +Onolimit $CFLAGS"
|
||||
CXXFLAGS="-Ae +O3 +Onolimit $CXXFLAGS"
|
||||
CFLAGS="-Ae +O3 +Onolimit $CFLAGS"
|
||||
fi
|
||||
fi
|
||||
|
@ -747,6 +782,13 @@ fi
|
|||
CMFLAGS=-fpic
|
||||
CIFLAGS=-I.
|
||||
|
||||
if test "$use_gecode" = no; then
|
||||
ENABLE_GECODE="@# "
|
||||
else
|
||||
ENABLE_GECODE=""
|
||||
fi
|
||||
AC_SUBST(ENABLE_GECODE)
|
||||
|
||||
if test "$use_chr" = no; then
|
||||
ENABLE_CHR="@# "
|
||||
elif test -e "$srcdir"/packages/chr/Makefile.in; then
|
||||
|
@ -2225,5 +2267,9 @@ if test "$ENABLE_CLPBN_BP" = ""; then
|
|||
AC_CONFIG_FILES([packages/CLPBN/clpbn/bp/Makefile])
|
||||
fi
|
||||
|
||||
if test "$ENABLE_GECODE" = ""; then
|
||||
AC_CONFIG_FILES([library/gecode/Makefile])
|
||||
fi
|
||||
|
||||
AC_OUTPUT()
|
||||
|
||||
|
|
|
@ -205,12 +205,14 @@ typedef int (*YAP_agc_hook)(void *_Atom);
|
|||
|
||||
typedef void (*YAP_halt_hook)(int exit_code, void *closure);
|
||||
|
||||
typedef int YAP_opaque_tag_t;
|
||||
typedef YAP_Int YAP_opaque_tag_t;
|
||||
|
||||
typedef int (*YAP_Opaque_CallOnFail)(void *);
|
||||
typedef int (*YAP_Opaque_CallOnWrite)(void *, YAP_opaque_tag_t, void *, int);
|
||||
|
||||
typedef struct YAP_opaque_handler_struct {
|
||||
YAP_Opaque_CallOnFail fail_handler;
|
||||
YAP_Opaque_CallOnFail fail_handler;
|
||||
YAP_Opaque_CallOnWrite write_handler;
|
||||
} YAP_opaque_handler_t;
|
||||
|
||||
/********* execution mode ***********************/
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
chdir/1,
|
||||
compile_aux_clauses/1,
|
||||
convert_time/2,
|
||||
convert_time/8,
|
||||
'$declare_module'/5,
|
||||
'$set_predicate_attribute'/3,
|
||||
stamp_date_time/3,
|
||||
|
@ -91,7 +92,6 @@
|
|||
|
||||
:- yap_flag(autoload,true).
|
||||
|
||||
|
||||
:- set_prolog_flag(user_flags,silent).
|
||||
|
||||
% Time is given as a float in SWI-Prolog.
|
||||
|
@ -168,9 +168,40 @@ cvt_bindings([[Name|Value]|L],[AName=Value|Bindings]) :-
|
|||
|
||||
chdir(X) :- cd(X).
|
||||
|
||||
% Time is received as int, and converted to "..."
|
||||
% ctime is a built-in.
|
||||
convert_time(X,Y) :- swi:ctime(X,Y).
|
||||
%% convert_time(+Stamp, -String)
|
||||
%
|
||||
% Convert a time-stamp as obtained though get_time/1 into a textual
|
||||
% representation using the C-library function ctime(). The value is
|
||||
% returned as a SWI-Prolog string object (see section 4.23). See
|
||||
% also convert_time/8.
|
||||
%
|
||||
% @deprecated Use format_time/3.
|
||||
|
||||
|
||||
convert_time(Stamp, String) :-
|
||||
format_time(string(String), '%+', Stamp).
|
||||
|
||||
%% convert_time(+Stamp, -Y, -Mon, -Day, -Hour, -Min, -Sec, -MilliSec)
|
||||
%
|
||||
% Convert a time stamp, provided by get_time/1, time_file/2,
|
||||
% etc. Year is unified with the year, Month with the month number
|
||||
% (January is 1), Day with the day of the month (starting with 1),
|
||||
% Hour with the hour of the day (0--23), Minute with the minute
|
||||
% (0--59). Second with the second (0--59) and MilliSecond with the
|
||||
% milliseconds (0--999). Note that the latter might not be accurate
|
||||
% or might always be 0, depending on the timing capabilities of the
|
||||
% system. See also convert_time/2.
|
||||
%
|
||||
% @deprecated Use stamp_date_time/3.
|
||||
|
||||
convert_time(Stamp, Y, Mon, Day, Hour, Min, Sec, MilliSec) :-
|
||||
stamp_date_time(Stamp,
|
||||
date(Y, Mon, Day,
|
||||
Hour, Min, FSec,
|
||||
_, _, _),
|
||||
local),
|
||||
Sec is integer(float_integer_part(FSec)),
|
||||
MilliSec is integer(float_fractional_part(FSec)*1000).
|
||||
|
||||
compile_aux_clauses([]).
|
||||
compile_aux_clauses([(:- G)|Cls]) :-
|
||||
|
|
|
@ -2681,32 +2681,6 @@ PL_foreign_context_address(control_t ctx)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SWI_ctime(void)
|
||||
{
|
||||
#if HAVE_CTIME
|
||||
time_t tim;
|
||||
#endif
|
||||
YAP_Term t1 = YAP_ARG1;
|
||||
|
||||
if (YAP_IsVarTerm(t1)) {
|
||||
YAP_Error(0,t1,"bad argumento to ctime");
|
||||
return FALSE;
|
||||
}
|
||||
#if HAVE_CTIME
|
||||
if (YAP_IsIntTerm(t1))
|
||||
tim = (time_t)YAP_IntOfTerm(t1);
|
||||
else if (YAP_IsFloatTerm(t1))
|
||||
tim = (time_t)YAP_FloatOfTerm(t1);
|
||||
else
|
||||
return FALSE;
|
||||
return YAP_Unify(YAP_BufferToString(ctime(&tim)), YAP_ARG2);
|
||||
#else
|
||||
YAP_Error(0,0L,"convert_time requires ctime");
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
X_API int
|
||||
PL_get_signum_ex(term_t sig, int *n)
|
||||
{
|
||||
|
@ -2805,7 +2779,6 @@ void
|
|||
Yap_swi_install(void)
|
||||
{
|
||||
Yap_install_blobs();
|
||||
YAP_UserCPredicate("ctime", SWI_ctime, 2);
|
||||
}
|
||||
|
||||
int Yap_read_term(term_t t, IOSTREAM *st, term_t *excep, term_t vs);
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
USING THE GECODE MODULE
|
||||
=======================
|
||||
|
||||
:- use_module(gecode).
|
||||
or
|
||||
:- use_module(library(gecode)).
|
||||
if it is installed as a library module
|
||||
|
||||
CREATING A SPACE
|
||||
================
|
||||
|
||||
Space := space
|
||||
|
||||
CREATING VARIABLES
|
||||
==================
|
||||
|
||||
Unlike in Gecode, variable objects are not bound to a specific Space. Each one
|
||||
actually contains an index with which it is possible to access a Space-bound
|
||||
Gecode variable. Variables can be created using the following expressions:
|
||||
|
||||
IVar := intvar(Space,SPEC...)
|
||||
BVar := boolvar(Space)
|
||||
SVar := setvar(Space,SPEC...)
|
||||
|
||||
where SPEC... is the same as in Gecode. For creating lists of variables use
|
||||
the following variants:
|
||||
|
||||
IVars := intvars(Space,N,SPEC...)
|
||||
BVars := boolvars(Space,N,SPEC...)
|
||||
SVars := setvars(Space,N,SPEC...)
|
||||
|
||||
where N is the number of variables to create (just like for XXXVarArray in
|
||||
Gecode). Sometimes an IntSet is necessary:
|
||||
|
||||
ISet := intset([SPEC...])
|
||||
|
||||
where each SPEC is either an integer or a pair (I,J) of integers. An IntSet
|
||||
describes a set of ints by providing either intervals, or integers (which stand
|
||||
for an interval of themselves). It might be tempting to simply represent an
|
||||
IntSet as a list of specs, but this would be ambiguous with IntArgs which,
|
||||
here, are represented as lists of ints.
|
||||
|
||||
CONSTRAINTS AND BRANCHINGS
|
||||
==========================
|
||||
|
||||
all constraint and branching posting functions are available just like in
|
||||
Gecode. Wherever a XXXArgs or YYYSharedArray is expected, simply use a list.
|
||||
At present, there is no support for minimodel-like constraint posting.
|
||||
Constraints and branchings are added to a space using:
|
||||
|
||||
Space += CONSTRAINT
|
||||
Space += BRANCHING
|
||||
|
||||
For example:
|
||||
|
||||
Space += rel(X,'IRT_EQ',Y)
|
||||
|
||||
arrays of variables are represented by lists of variables, and constants are
|
||||
represented by atoms with the same name as the Gecode constant
|
||||
(e.g. 'INT_VAR_SIZE_MIN').
|
||||
|
||||
SEARCHING FOR SOLUTIONS
|
||||
=======================
|
||||
|
||||
SolSpace := search(Space)
|
||||
|
||||
This is a backtrackable predicate that enumerates all solution spaces
|
||||
(SolSpace).
|
||||
|
||||
EXTRACTING INFO FROM A SOLUTION
|
||||
===============================
|
||||
|
||||
An advantage of non Space-bound variables, is that you can use them both to
|
||||
post constraints in the original space AND to consult their values in
|
||||
solutions. Below are methods for looking up information about variables. Each
|
||||
of these methods can either take a variable as argument, or a list of
|
||||
variables, and returns resp. either a value, or a list of values:
|
||||
|
||||
Val := assigned(Space,X)
|
||||
|
||||
Val := min(Space,X)
|
||||
Val := max(Space,X)
|
||||
Val := med(Space,X)
|
||||
Val := val(Space,X)
|
||||
Val := size(Space,X)
|
||||
Val := width(Space,X)
|
||||
Val := regret_min(Space,X)
|
||||
Val := regret_max(Space,X)
|
||||
|
||||
Val := glbSize(Space,V)
|
||||
Val := lubSize(Space,V)
|
||||
Val := unknownSize(Space,V)
|
||||
Val := cardMin(Space,V)
|
||||
Val := cardMax(Space,V)
|
||||
Val := lubMin(Space,V)
|
||||
Val := lubMax(Space,V)
|
||||
Val := glbMin(Space,V)
|
||||
Val := glbMax(Space,V)
|
||||
Val := glb_ranges(Space,V)
|
||||
Val := lub_ranges(Space,V)
|
||||
Val := unknown_ranges(Space,V)
|
||||
Val := glb_values(Space,V)
|
||||
Val := lub_values(Space,V)
|
||||
Val := unknown_values(Space,V)
|
||||
|
||||
DISJUNCTORS
|
||||
===========
|
||||
|
||||
Disjunctors provide support for disjunctions of clauses, where each clause is a
|
||||
conjunction of constraints:
|
||||
|
||||
C1 or C2 or ... or Cn
|
||||
|
||||
Each clause is executed "speculatively": this means it does not affect the main
|
||||
space. When a clause becomes failed, it is discarded. When only one clause
|
||||
remains, it is committed: this means that it now affects the main space.
|
||||
|
||||
Example:
|
||||
|
||||
Consider the problem where either X=Y=0 or X=Y+(1 or 2) for variable X and Y
|
||||
that take values in 0..3.
|
||||
|
||||
Space := space,
|
||||
[X,Y] := intvars(Space,2,0,3),
|
||||
|
||||
First, we must create a disjunctor as a manager for our 2 clauses:
|
||||
|
||||
Disj := disjunctor(Space),
|
||||
|
||||
We can now create our first clause:
|
||||
|
||||
C1 := clause(Disj),
|
||||
|
||||
This clause wants to constrain X and Y to 0. However, since it must be
|
||||
executed "speculatively", it must operate on new variables X1 and Y1 that
|
||||
shadow X and Y:
|
||||
|
||||
[X1,Y1] := intvars(C1,2,0,3),
|
||||
C1 += forward([X,Y],[X1,Y1]),
|
||||
|
||||
The forward(...) stipulation indicates which global variable is shadowed by
|
||||
which clause-local variable. Now we can post the speculative clause-local
|
||||
constraints for X=Y=0:
|
||||
|
||||
C1 += rel(X1,'IRT_EQ',0),
|
||||
C1 += rel(Y1,'IRT_EQ',0),
|
||||
|
||||
We now create the second clause which uses X2 and Y2 to shadow X and Y:
|
||||
|
||||
C2 := clause(Disj),
|
||||
[X2,Y2] := intvars(C2,2,0,3),
|
||||
C2 += forward([X,Y],[X2,Y2]),
|
||||
|
||||
However, this clause also needs a clause-local variable Z2 taking values 1 or
|
||||
2 in order to post the clause-local constraint X2=Y2+Z2:
|
||||
|
||||
Z2 := intvar(C2,1,2),
|
||||
C2 += linear([-1,1,1],[X2,Y2,Z2],'IRT_EQ',0),
|
||||
|
||||
Finally, we can branch and search:
|
||||
|
||||
Space += branch([X,Y],'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
|
||||
SolSpace := search(Space),
|
||||
|
||||
and lookup values of variables in each solution:
|
||||
|
||||
[X_,Y_] := val(SolSpace,[X,Y]).
|
|
@ -0,0 +1,89 @@
|
|||
#
|
||||
# default base directory for YAP installation
|
||||
# (EROOT for architecture-dependent files)
|
||||
#
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
ROOTDIR = $(prefix)
|
||||
EROOTDIR = @exec_prefix@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
#
|
||||
# where the binary should be
|
||||
#
|
||||
BINDIR = $(EROOTDIR)/bin
|
||||
#
|
||||
# where YAP should look for libraries
|
||||
#
|
||||
LIBDIR=@libdir@
|
||||
YAPLIBDIR=@libdir@/Yap
|
||||
#
|
||||
# where YAP should look for architecture-independent Prolog libraries
|
||||
#
|
||||
SHAREDIR=$(ROOTDIR)/share
|
||||
#
|
||||
#
|
||||
CXX=@CXX@
|
||||
CXXFLAGS= @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) -I. -I$(srcdir) -I../.. -I$(srcdir)/../../include
|
||||
#
|
||||
#
|
||||
# You shouldn't need to change what follows.
|
||||
#
|
||||
INSTALL=@INSTALL@
|
||||
INSTALL_DATA=@INSTALL_DATA@
|
||||
INSTALL_PROGRAM=@INSTALL_PROGRAM@
|
||||
SHELL=/bin/sh
|
||||
RANLIB=@RANLIB@
|
||||
srcdir=@srcdir@
|
||||
SO=@SO@
|
||||
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
|
||||
CWD=$(PWD)
|
||||
#
|
||||
|
||||
OBJS=gecode_yap.o
|
||||
SOBJS=gecode_yap.@SO@
|
||||
|
||||
CODEGEN=$(srcdir)/code-generator.py
|
||||
DISJUNCTOR = -DDISJUNCTOR
|
||||
PYTHON = @PYTHON@
|
||||
export PYTHONPATH:=$(srcdir):$(PYTHONPATH)
|
||||
|
||||
all: $(SOBJS) gecode.yap
|
||||
|
||||
gecode_yap.o: \
|
||||
$(srcdir)/gecode_yap.cc \
|
||||
$(srcdir)/gecode-common.icc \
|
||||
gecode_yap_cc_impl_auto_generated.icc \
|
||||
gecode_yap_cc_init_auto_generated.icc \
|
||||
gecode_yap_cc_forward_auto_generated.icc \
|
||||
$(srcdir)/disjunctor.icc \
|
||||
$(srcdir)/disjunctor.hh
|
||||
$(CXX) -c $(CXXFLAGS) $(DISJUNCTOR) -o $@ $<
|
||||
|
||||
@DO_SECOND_LD@gecode_yap.@SO@: gecode_yap.o
|
||||
@DO_SECOND_LD@ @SHLIB_LD@ -o gecode_yap.@SO@ gecode_yap.o $(LDFLAGS) -lgecodeint -lgecodeset -lgecodesearch @EXTRA_LIBS_FOR_DLLS@
|
||||
|
||||
gecode_yap_cc_init_auto_generated.icc: $(CODEGEN)
|
||||
$(PYTHON) $< -t yap-cc-init -s $(srcdir) > $@
|
||||
|
||||
gecode_yap_cc_impl_auto_generated.icc: $(CODEGEN)
|
||||
$(PYTHON) $< -t yap-cc-impl -s $(srcdir) > $@
|
||||
|
||||
gecode_yap_cc_forward_auto_generated.icc: $(CODEGEN)
|
||||
$(PYTHON) $< -t yap-cc-forward -s $(srcdir) > $@
|
||||
|
||||
gecode_yap_auto_generated.yap: $(CODEGEN)
|
||||
$(PYTHON) $< -t yap-prolog -s $(srcdir) > $@
|
||||
|
||||
gecode.yap: $(srcdir)/gecode_yap_hand_written.yap gecode_yap_auto_generated.yap
|
||||
cat $^ > $@
|
||||
|
||||
.PHONY: all clean install
|
||||
|
||||
clean:
|
||||
-rm -f *.o *.so *~ *_auto_generated* gecode.yap *.pyc
|
||||
|
||||
install: all
|
||||
mkdir -p $(DESTDIR)$(YAPLIBDIR)
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap
|
||||
$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(YAPLIBDIR)
|
||||
$(INSTALL) gecode.yap $(DESTDIR)$(SHAREDIR)/Yap
|
|
@ -0,0 +1,34 @@
|
|||
CODEGEN=code-generator.py
|
||||
DISJUNCTOR = -DDISJUNCTOR
|
||||
|
||||
yap: gecode_yap.so gecode.yap
|
||||
|
||||
gecode_yap.o: gecode_yap.cc gecode-common.icc \
|
||||
gecode_yap_cc_impl_auto_generated.icc \
|
||||
gecode_yap_cc_init_auto_generated.icc \
|
||||
gecode_yap_cc_forward_auto_generated.icc \
|
||||
disjunctor.icc disjunctor.hh
|
||||
$(CXX) -Wall -ggdb -c -shared -fPIC $(DISJUNCTOR) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $<
|
||||
|
||||
gecode_yap.so: gecode_yap.o
|
||||
$(CXX) -shared $(LDFLAGS) -o $@ $< -lgecodeint -lgecodeset -lgecodesearch
|
||||
|
||||
gecode_yap_cc_init_auto_generated.icc: $(CODEGEN)
|
||||
python $< -t yap-cc-init > $@
|
||||
|
||||
gecode_yap_cc_impl_auto_generated.icc: $(CODEGEN)
|
||||
python $< -t yap-cc-impl > $@
|
||||
|
||||
gecode_yap_cc_forward_auto_generated.icc: $(CODEGEN)
|
||||
python $< -t yap-cc-forward > $@
|
||||
|
||||
gecode_yap_auto_generated.yap: $(CODEGEN)
|
||||
python $< -t yap-prolog > $@
|
||||
|
||||
gecode.yap: gecode_yap_hand_written.yap gecode_yap_auto_generated.yap
|
||||
cat $^ > $@
|
||||
|
||||
.PHONY: yap
|
||||
|
||||
clean:
|
||||
-rm -f *.o *.so *~ *_auto_generated* gecode.yap
|
|
@ -0,0 +1,709 @@
|
|||
# -*- python -*-
|
||||
#==============================================================================
|
||||
# Copyright (C) 2011 by Denys Duchier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program. If not, see <http:##www.gnu.org/licenses/>.
|
||||
#==============================================================================
|
||||
|
||||
import re
|
||||
|
||||
NOTICE_CC = """// -*- c++ -*-
|
||||
//=============================================================================
|
||||
// Copyright (C) 2011 by Denys Duchier
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published by the
|
||||
// Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
// more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//=============================================================================
|
||||
"""
|
||||
|
||||
NOTICE_PROLOG="""%% -*- prolog -*-
|
||||
%%=============================================================================
|
||||
%% Copyright (C) 2011 by Denys Duchier
|
||||
%%
|
||||
%% This program is free software: you can redistribute it and/or modify it
|
||||
%% under the terms of the GNU Lesser General Public License as published by the
|
||||
%% Free Software Foundation, either version 3 of the License, or (at your
|
||||
%% option) any later version.
|
||||
%%
|
||||
%% This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
%% more details.
|
||||
%%
|
||||
%% You should have received a copy of the GNU Lesser General Public License
|
||||
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
%%=============================================================================
|
||||
"""
|
||||
|
||||
def prolog_print_notice():
|
||||
print NOTICE_PROLOG
|
||||
|
||||
def cc_print_notice():
|
||||
print NOTICE_CC
|
||||
|
||||
class Type(object):
|
||||
|
||||
DEFAULT = re.compile("""^(.+)=(.+)$""")
|
||||
CONST = re.compile("""^const\\b(.+)$""")
|
||||
UNSIGNED = re.compile("""^unsigned\\b(.+)$""")
|
||||
REFERENCE = re.compile("""^(.+)&$""")
|
||||
|
||||
def __init__(self, text):
|
||||
if isinstance(text, Type):
|
||||
self.clone_from(text)
|
||||
return
|
||||
text = text.strip()
|
||||
m = self.DEFAULT.match(text)
|
||||
if m:
|
||||
self.default = m.group(2).strip()
|
||||
text = m.group(1).strip()
|
||||
else:
|
||||
self.default = None
|
||||
m = self.CONST.match(text)
|
||||
if m:
|
||||
self.const = True
|
||||
text = m.group(1).strip()
|
||||
else:
|
||||
self.const = False
|
||||
m = self.UNSIGNED.match(text)
|
||||
if m:
|
||||
self.unsigned = True
|
||||
text = m.group(1).strip()
|
||||
else:
|
||||
self.unsigned = False
|
||||
m = self.REFERENCE.match(text)
|
||||
if m:
|
||||
self.reference = True
|
||||
text = m.group(1).strip()
|
||||
else:
|
||||
self.reference = False
|
||||
self.type = text
|
||||
|
||||
def __str__(self):
|
||||
l = []
|
||||
if self.const: l.append("const ")
|
||||
if self.unsigned: l.append("unsigned ")
|
||||
l.append(self.type)
|
||||
if self.reference: l.append("&")
|
||||
if self.default is not None:
|
||||
l.append("=")
|
||||
l.append(self.default)
|
||||
return ''.join(l)
|
||||
|
||||
def clone_from(self, other):
|
||||
self.const = other.const
|
||||
self.unsigned = other.unsigned
|
||||
self.type = other.type
|
||||
self.reference = other.reference
|
||||
self.default = other.default
|
||||
|
||||
def clone(self):
|
||||
return type(self)(self)
|
||||
|
||||
|
||||
class Constraint(object):
|
||||
|
||||
DECL = re.compile("""^([^(]+)\\b(\w+)\((.*)\);$""")
|
||||
ARG = re.compile("""((?:[^,<(]|<[^>]*>|\([^)]*\))+),?""")
|
||||
|
||||
def __init__(self, line):
|
||||
if isinstance(line, Constraint):
|
||||
self.clone_from(line)
|
||||
return
|
||||
line = line.strip()
|
||||
m = self.DECL.match(line)
|
||||
self.rettype = Type(m.group(1).strip())
|
||||
self.name = m.group(2)
|
||||
argtypes = []
|
||||
for x in self.ARG.finditer(m.group(3).strip()):
|
||||
argtypes.append(Type(x.group(1)))
|
||||
self.argtypes = tuple(argtypes)
|
||||
self.api = None
|
||||
|
||||
def __str__(self):
|
||||
l = []
|
||||
l.append(str(self.rettype))
|
||||
l.append(" ")
|
||||
l.append(self.name)
|
||||
sep = "("
|
||||
for x in self.argtypes:
|
||||
l.append(sep)
|
||||
sep = ", "
|
||||
l.append(str(x))
|
||||
l.append(")")
|
||||
if self.api is not None:
|
||||
l.append(" -> ")
|
||||
l.append(self.api)
|
||||
l.append(";")
|
||||
return ''.join(l)
|
||||
|
||||
def clone_from(self, other):
|
||||
self.rettype = other.rettype.clone()
|
||||
self.name = other.name
|
||||
self.argtypes = tuple(t.clone() for t in other.argtypes)
|
||||
|
||||
def clone(self):
|
||||
return type(self)(self)
|
||||
|
||||
|
||||
COMMENT = re.compile("""^\\s*//.*$""")
|
||||
|
||||
def load_decls(filename):
|
||||
decls = []
|
||||
for line in open(filename):
|
||||
line = line.strip()
|
||||
if not line: continue
|
||||
m = COMMENT.match(line)
|
||||
if m: continue
|
||||
decls.append(Constraint(line))
|
||||
return decls
|
||||
|
||||
class DeclsLoader(object):
|
||||
|
||||
def __init__(self, filename):
|
||||
self.decls = load_decls(filename)
|
||||
|
||||
def print_decls(self):
|
||||
for con in self.decls:
|
||||
print str(con)
|
||||
|
||||
class PredGenerator(DeclsLoader):
|
||||
|
||||
OMIT = ("DFA", # NOT YET SUPPORTED!!!
|
||||
"TupleSet", # NOT YET SUPPORTED!!!
|
||||
"VarBranchOptions",
|
||||
"ValBranchOptions",
|
||||
"TieBreakVarBranch<IntVarBranch>",
|
||||
"TieBreakVarBranchOptions",
|
||||
"TieBreakVarBranch<SetVarBranch>")
|
||||
|
||||
def __init__(self, filename):
|
||||
super(PredGenerator, self).__init__(filename)
|
||||
self._change_home_to_space()
|
||||
self._change_intsharedarray_to_intargs()
|
||||
self._generate()
|
||||
self._number()
|
||||
|
||||
def _change_home_to_space(self):
|
||||
for p in self.decls:
|
||||
for t in p.argtypes:
|
||||
if t.type=="Home":
|
||||
t.type="Space"
|
||||
|
||||
def _change_intsharedarray_to_intargs(self):
|
||||
for p in self.decls:
|
||||
for t in p.argtypes:
|
||||
if t.type=="IntSharedArray":
|
||||
t.type="IntArgs"
|
||||
|
||||
def _generate(self):
|
||||
# drop the constraints and optional arguments we can't handle
|
||||
preds = []
|
||||
for con in self.decls:
|
||||
if self._con_ok(con):
|
||||
con = con.clone()
|
||||
con.argtypes = tuple(self._drop_deco(t) for t in con.argtypes
|
||||
if t.type not in self.OMIT)
|
||||
preds.append(con)
|
||||
# for each pred that has an argument with a default produce
|
||||
# 2 preds (1 without, 1 with). repeat until all defaults have
|
||||
# been removed.
|
||||
again = True
|
||||
while again:
|
||||
preds_ = []
|
||||
again = False
|
||||
for con in preds:
|
||||
i = self._defaulted(con.argtypes)
|
||||
if i is None:
|
||||
preds_.append(con)
|
||||
else:
|
||||
again = True
|
||||
before = con.argtypes[:i]
|
||||
# without the default argument
|
||||
# and therefore without the args that follow
|
||||
con1 = con.clone()
|
||||
con1.argtypes = before
|
||||
preds_.append(con1)
|
||||
# with the default argument (not default anymore)
|
||||
con2 = con.clone()
|
||||
arg = con.argtypes[i].clone()
|
||||
arg.default=None
|
||||
after = con.argtypes[i+1:]
|
||||
con2.argtypes = before + (arg,) + after
|
||||
preds_.append(con2)
|
||||
preds = preds_
|
||||
self.preds = preds
|
||||
|
||||
def _con_ok(self, con):
|
||||
for t in con.argtypes:
|
||||
if (t.type in self.OMIT) and (t.default is None):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _drop_deco(self, t):
|
||||
# drop const, ref, and unsigned indications
|
||||
t.const = False
|
||||
t.reference = False
|
||||
t.unsigned = False
|
||||
return t
|
||||
|
||||
def _defaulted(self, argtypes):
|
||||
i = 0
|
||||
for x in argtypes:
|
||||
if x.default is not None:
|
||||
return i
|
||||
i += 1
|
||||
return None
|
||||
|
||||
def _number(self):
|
||||
i = 1
|
||||
for x in self.preds:
|
||||
x.api = "%s_%d" % (x.name,i)
|
||||
i += 1
|
||||
|
||||
def print_preds(self):
|
||||
for p in self.preds:
|
||||
print str(p)
|
||||
|
||||
class Cluster(object):
|
||||
|
||||
def __init__(self, name, arity):
|
||||
self.name = name
|
||||
self.arity = arity
|
||||
self.preds = []
|
||||
|
||||
# discriminating tree based on argument types
|
||||
class DTree(object):
|
||||
|
||||
def __init__(self, i, preds):
|
||||
self.index = i
|
||||
if len(preds) == 1 and len(preds[0].argtypes) == i:
|
||||
self.is_leaf = True
|
||||
self.pred = preds[0]
|
||||
return
|
||||
self.is_leaf = False
|
||||
# i is the index of the current arg
|
||||
# preds are the predicates to be indexed under this tree node
|
||||
dispatch = {}
|
||||
for p in preds:
|
||||
t = p.argtypes[i]
|
||||
d = dispatch.get(t.type, None)
|
||||
if d is None:
|
||||
d = []
|
||||
dispatch[t.type] = d
|
||||
d.append(p)
|
||||
self.subtrees = tuple((t2,DTree(i+1,p2))
|
||||
for t2,p2 in dispatch.iteritems())
|
||||
|
||||
def _generate_body(self, user_vars, lib_vars):
|
||||
if self.is_leaf:
|
||||
return PrologLiteral("gecode_constraint_%s(%s)" % (self.pred.api, ",".join(lib_vars)))
|
||||
X = user_vars[self.index]
|
||||
Y = lib_vars[self.index]
|
||||
return self._generate_dispatch(0, user_vars, lib_vars)
|
||||
|
||||
def _generate_dispatch(self, i, user_vars, lib_vars):
|
||||
if i == len(self.subtrees):
|
||||
return PrologLiteral("throw(gecode_argument_error)")
|
||||
typ, dtree = self.subtrees[i]
|
||||
idx = self.index
|
||||
X = user_vars[idx]
|
||||
Y = lib_vars[idx]
|
||||
# hack for disjunctor support
|
||||
if typ=="Space":
|
||||
typ = "Space_or_Clause"
|
||||
return PrologIF(
|
||||
PrologLiteral("is_%s(%s,%s)" % (typ,X,Y)),
|
||||
dtree._generate_body(user_vars, lib_vars),
|
||||
self._generate_dispatch(i+1, user_vars, lib_vars))
|
||||
|
||||
def _cc_descriptors(self, name, argtypes):
|
||||
if self.is_leaf:
|
||||
return (CCDescriptor(name, argtypes, self.pred.api),)
|
||||
descriptors = []
|
||||
for typ,dtree in self.subtrees:
|
||||
descriptors.extend(dtree._cc_descriptors(name,(argtypes+(typ,))))
|
||||
return descriptors
|
||||
|
||||
class YAPConstraintGeneratorBase(PredGenerator):
|
||||
|
||||
def __init__(self, filename):
|
||||
super(YAPConstraintGeneratorBase, self).__init__(filename)
|
||||
self._classify()
|
||||
self._dtreefy()
|
||||
|
||||
# create clusters (predicate,arity)
|
||||
def _classify(self):
|
||||
clusters = {}
|
||||
for pred in self.preds:
|
||||
name = pred.name
|
||||
arity = len(pred.argtypes)
|
||||
key = (name,arity)
|
||||
cluster = clusters.get(key, None)
|
||||
if cluster is None:
|
||||
cluster = Cluster(name, arity)
|
||||
clusters[key] = cluster
|
||||
cluster.preds.append(pred)
|
||||
self.clusters = clusters
|
||||
|
||||
# for each cluster, create a dtree
|
||||
def _dtreefy(self):
|
||||
dtrees = {}
|
||||
for key, cluster in self.clusters.iteritems():
|
||||
dtree = DTree(0, cluster.preds)
|
||||
dtrees[key] = dtree
|
||||
self.dtrees = dtrees
|
||||
|
||||
def _user_vars(self, arity):
|
||||
return tuple(("X%d" % i) for i in range(arity))
|
||||
|
||||
def _lib_vars(self, arity):
|
||||
return tuple(("Y%d" % i) for i in range(arity))
|
||||
|
||||
class YAPConstraintPrologGenerator(YAPConstraintGeneratorBase):
|
||||
|
||||
def __init__(self, filename):
|
||||
super(YAPConstraintPrologGenerator, self).__init__(filename)
|
||||
|
||||
def _prolog_clauses(self):
|
||||
clauses = []
|
||||
for (name, arity), dtree in self.dtrees.iteritems():
|
||||
user_vars = self._user_vars(arity)
|
||||
lib_vars = self._lib_vars(arity)
|
||||
head = "%s(%s)" % (name, ",".join(user_vars))
|
||||
body = dtree._generate_body(user_vars, lib_vars)
|
||||
clause = PrologClause(head, body)
|
||||
clauses.append(clause)
|
||||
return clauses
|
||||
|
||||
def generate(self):
|
||||
out = OStream(sys.stdout)
|
||||
for clause in self._prolog_clauses():
|
||||
clause.pp(out, 0)
|
||||
|
||||
class YAPConstraintCCGenerator(YAPConstraintGeneratorBase):
|
||||
|
||||
def __init__(self, filename):
|
||||
super(YAPConstraintCCGenerator, self).__init__(filename)
|
||||
|
||||
def _cc_descriptors(self):
|
||||
descriptors = []
|
||||
for (name, arity), dtree in self.dtrees.iteritems():
|
||||
descriptors.extend(dtree._cc_descriptors(name,()))
|
||||
return descriptors
|
||||
|
||||
def generate_impl(self):
|
||||
for d in self._cc_descriptors():
|
||||
d.generate_impl()
|
||||
|
||||
def generate_init(self):
|
||||
for d in self._cc_descriptors():
|
||||
d.generate_init()
|
||||
|
||||
# output stream that keeps track of the current column
|
||||
# to facilitate proper indentation
|
||||
|
||||
import sys
|
||||
|
||||
class OStream(object):
|
||||
|
||||
def __init__(self, fd=sys.stdout):
|
||||
self.file = fd
|
||||
self.column = 0
|
||||
|
||||
def write(self, s):
|
||||
reset = False
|
||||
for x in s.split('\n'):
|
||||
if reset:
|
||||
self.newline()
|
||||
else:
|
||||
reset = True
|
||||
self.file.write(x)
|
||||
self.column += len(x)
|
||||
|
||||
def newline(self):
|
||||
self.file.write("\n")
|
||||
self.column = 0
|
||||
|
||||
def writeln(self, s=None):
|
||||
if s is not None:
|
||||
self.write(s)
|
||||
self.newline()
|
||||
|
||||
def indent_to(self, n):
|
||||
if n<self.column:
|
||||
self.newline()
|
||||
n = n - self.column
|
||||
while n>0:
|
||||
self.write(' ')
|
||||
n -= 1
|
||||
|
||||
# representation of prolog code that automatically supports proper indentation
|
||||
|
||||
class PrologObject(object):
|
||||
pass
|
||||
|
||||
class PrologClause(PrologObject):
|
||||
|
||||
def __init__(self, head, body):
|
||||
self.head = head
|
||||
self.body = body
|
||||
|
||||
def pp(self, out, offset):
|
||||
out.indent_to(offset)
|
||||
out.write(self.head)
|
||||
out.writeln(" :-")
|
||||
self.body.pp(out, offset+8)
|
||||
out.writeln(".")
|
||||
out.writeln()
|
||||
|
||||
class PrologLiteral(PrologObject):
|
||||
|
||||
def __init__(self, lit):
|
||||
self.literal = lit
|
||||
|
||||
def pp(self, out, offset):
|
||||
out.indent_to(offset)
|
||||
out.write(self.literal)
|
||||
|
||||
class PrologIF(PrologObject):
|
||||
|
||||
def __init__(self, cond, left, right):
|
||||
self.cond = cond
|
||||
self.left = left
|
||||
self.right = right
|
||||
|
||||
def pp(self, out, offset):
|
||||
out.indent_to(offset)
|
||||
out.write("("),
|
||||
indent = offset+1
|
||||
self.cond.pp(out, indent)
|
||||
out.writeln()
|
||||
out.indent_to(indent)
|
||||
out.write("-> ")
|
||||
self.left.pp(out, indent+3)
|
||||
out.writeln()
|
||||
out.indent_to(indent)
|
||||
out.write("; ")
|
||||
self.right.pp(out, indent+3)
|
||||
out.write(")")
|
||||
|
||||
ENUM_CLASSES = None
|
||||
ENUM_CLASSES_AVOID = ('ScriptMode','ViewSelStatus','ExecStatus',
|
||||
'ActorProperty','SpaceStatus')
|
||||
|
||||
def enum_classes():
|
||||
global ENUM_CLASSES
|
||||
filename = "gecode-enums-%s.py" % gecode_version()
|
||||
if SRCDIR is not None:
|
||||
import os.path
|
||||
filename = os.path.join(SRCDIR,filename)
|
||||
if ENUM_CLASSES is None:
|
||||
import imp
|
||||
ENUM_CLASSES = imp.load_source(
|
||||
"gecode_enums",
|
||||
filename).ENUM_CLASSES
|
||||
ENUM_CLASSES = (x for x in ENUM_CLASSES if x.TYPE not in ENUM_CLASSES_AVOID)
|
||||
return ENUM_CLASSES
|
||||
|
||||
class YAPEnumImpl(object):
|
||||
|
||||
def generate(self):
|
||||
self._generate_atoms()
|
||||
self._generate_from_term()
|
||||
|
||||
def _generate_atoms(self):
|
||||
for x in self.ENUM:
|
||||
print "static YAP_Term gecode_%s;" % x
|
||||
print
|
||||
|
||||
def _generate_from_term(self):
|
||||
print "static %s gecode_%s_from_term(YAP_Term X)" % (self.TYPE,self.TYPE)
|
||||
print "{"
|
||||
for x in self.ENUM:
|
||||
print " if (X==gecode_%s) return %s;" % (x,x)
|
||||
print ' cerr << "this should never happen" << endl; exit(1);'
|
||||
print "}"
|
||||
print
|
||||
|
||||
def _generate_from_term_forward_decl(self):
|
||||
print "static %s gecode_%s_from_term(YAP_Term);" % (self.TYPE,self.TYPE)
|
||||
|
||||
class YAPEnumImplGenerator(object):
|
||||
|
||||
def generate(self):
|
||||
for c in enum_classes():
|
||||
class C(c,YAPEnumImpl): pass
|
||||
o = C()
|
||||
o.generate()
|
||||
|
||||
class YAPEnumForwardGenerator(object):
|
||||
|
||||
def generate(self):
|
||||
for c in enum_classes():
|
||||
class C(c,YAPEnumImpl): pass
|
||||
o = C()
|
||||
o._generate_from_term_forward_decl()
|
||||
|
||||
class YAPEnumInit(object):
|
||||
|
||||
def generate(self):
|
||||
for x in self.ENUM:
|
||||
print '{ YAP_Atom X= YAP_LookupAtom("%s");' % x
|
||||
print ' gecode_%s = YAP_MkAtomTerm(X);' % x
|
||||
print ' YAP_AtomGetHold(X); }'
|
||||
print
|
||||
|
||||
class YAPEnumInitGenerator(object):
|
||||
|
||||
def generate(self):
|
||||
for c in enum_classes():
|
||||
class C(c,YAPEnumInit): pass
|
||||
o = C()
|
||||
o.generate()
|
||||
|
||||
class YAPEnumProlog(object):
|
||||
|
||||
def generate(self):
|
||||
for x in self.ENUM:
|
||||
print "is_%s_('%s')." % (self.TYPE, x)
|
||||
print
|
||||
for x in self.ENUM:
|
||||
print "is_%s_('%s','%s')." % (self.TYPE, x, x)
|
||||
print
|
||||
print "is_%s(X,Y) :- nonvar(X), is_%s_(X,Y)." % (self.TYPE,self.TYPE)
|
||||
print "is_%s(X) :- is_%s(X,_)." % (self.TYPE,self.TYPE)
|
||||
print
|
||||
|
||||
class YAPEnumPrologGenerator(object):
|
||||
|
||||
def generate(self):
|
||||
for c in enum_classes():
|
||||
class C(c,YAPEnumProlog): pass
|
||||
o = C()
|
||||
o.generate()
|
||||
|
||||
class CCDescriptor(object):
|
||||
|
||||
def __init__(self, name, argtypes, api):
|
||||
self.name = name
|
||||
self.argtypes = argtypes
|
||||
self.api = api
|
||||
|
||||
def generate_impl(self):
|
||||
print "static int gecode_constraint_%s(void)" % self.api
|
||||
print "{"
|
||||
i = 1
|
||||
args = []
|
||||
for t in self.argtypes:
|
||||
v = "X%d" % i
|
||||
a = "YAP_ARG%d" % i
|
||||
if t=="Space":
|
||||
v = "*space"
|
||||
print " GenericSpace* space = gecode_Space_from_term(%s);" % a
|
||||
else:
|
||||
extra = ""
|
||||
if t in ("IntVar","BoolVar","SetVar","IntVarArgs","BoolVarArgs","SetVarArgs"):
|
||||
extra = "space,"
|
||||
print " %s %s = gecode_%s_from_term(%s%s);" % (t,v,t,extra,a)
|
||||
args.append(v)
|
||||
i += 1
|
||||
print " %s(%s);" % (self.name, ",".join(args))
|
||||
print " return TRUE;"
|
||||
print "}"
|
||||
print
|
||||
|
||||
def generate_init(self):
|
||||
print 'YAP_UserCPredicate("gecode_constraint_%s", gecode_constraint_%s, %d);' \
|
||||
% (self.api, self.api, len(self.argtypes))
|
||||
|
||||
GECODE_VERSION = None
|
||||
|
||||
def gecode_version():
|
||||
global GECODE_VERSION
|
||||
if GECODE_VERSION is not None:
|
||||
return GECODE_VERSION
|
||||
from distutils.ccompiler import new_compiler, customize_compiler
|
||||
import os
|
||||
cxx = new_compiler()
|
||||
customize_compiler(cxx)
|
||||
pid = os.getpid()
|
||||
file_hh = "_gecode_version_%d.hh" % pid
|
||||
file_txt = "_gecode_version_%d.txt" % pid
|
||||
f = file(file_hh,"w")
|
||||
f.write("""#include "gecode/support/config.hpp"
|
||||
@@GECODE_VERSION""")
|
||||
f.close()
|
||||
cxx.preprocess(file_hh,output_file=file_txt)
|
||||
f = open(file_txt)
|
||||
version = ""
|
||||
for line in f:
|
||||
if line.startswith("@@"):
|
||||
version = line[3:-2]
|
||||
break
|
||||
f.close()
|
||||
os.remove(file_hh)
|
||||
os.remove(file_txt)
|
||||
GECODE_VERSION = version
|
||||
return version
|
||||
|
||||
SRCDIR = None
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(
|
||||
description="code generator for gecode bindings")
|
||||
parser.add_argument(
|
||||
"-t", "--target", choices=("yap-prolog","yap-cc-impl","yap-cc-init",
|
||||
"yap-cc-forward"),
|
||||
default=None, metavar="TARGET", required=True,
|
||||
help="type of code to generate")
|
||||
parser.add_argument(
|
||||
"-s", "--srcdir", metavar="DIR", default=None,
|
||||
help="source directory")
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.srcdir is not None:
|
||||
import os.path
|
||||
SRCDIR = os.path.abspath(args.srcdir)
|
||||
filename = "gecode-prototypes-%s.hh" % gecode_version()
|
||||
if SRCDIR is not None:
|
||||
filename = os.path.join(SRCDIR,filename)
|
||||
if args.target == "yap-prolog":
|
||||
prolog_print_notice()
|
||||
YAPEnumPrologGenerator().generate()
|
||||
YAPConstraintPrologGenerator(filename).generate()
|
||||
elif args.target == "yap-cc-impl":
|
||||
cc_print_notice()
|
||||
YAPEnumImplGenerator().generate()
|
||||
YAPConstraintCCGenerator(filename).generate_impl()
|
||||
elif args.target == "yap-cc-init":
|
||||
cc_print_notice()
|
||||
YAPEnumInitGenerator().generate()
|
||||
YAPConstraintCCGenerator(filename).generate_init()
|
||||
elif args.target == "yap-cc-forward":
|
||||
cc_print_notice()
|
||||
YAPEnumForwardGenerator().generate()
|
||||
else:
|
||||
raise NotImplementedError("target not yet suported: %s" % args.target)
|
|
@ -0,0 +1,156 @@
|
|||
// -*- c++ -*-
|
||||
//=============================================================================
|
||||
// Copyright (C) 2011 by Denys Duchier
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published by the
|
||||
// Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
// more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//=============================================================================
|
||||
|
||||
#ifndef __GECODE_DISJUNCTOR_HH__
|
||||
#define __GECODE_DISJUNCTOR_HH__
|
||||
|
||||
#include <gecode/kernel.hh>
|
||||
#include <gecode/int.hh>
|
||||
#include <gecode/set.hh>
|
||||
|
||||
namespace Gecode { namespace Disjunctor_ {
|
||||
|
||||
using namespace generic_gecode;
|
||||
|
||||
//=========================================================================
|
||||
// from a user perspective, a Disjunctor corresponds to a set of
|
||||
// speculative clauses:
|
||||
//
|
||||
// - when a non-committed clause fails, it is simply discarded
|
||||
// - when a single clause remains, it is committed
|
||||
//
|
||||
// from an implementation perspective, a Disjunctor is an object shared by
|
||||
// several clauses, that contains a counter keeping track of how many
|
||||
// clauses remain. when the counter reaches 1, the remaining clause
|
||||
// becomes committed.
|
||||
//=========================================================================
|
||||
|
||||
// following the example in MPG
|
||||
struct Disjunctor: public LocalHandle
|
||||
{
|
||||
Disjunctor();
|
||||
Disjunctor(Space& home);
|
||||
Disjunctor(const Disjunctor& d);
|
||||
int get() const;
|
||||
void incr();
|
||||
void decr();
|
||||
void dispose(Space& home);
|
||||
};
|
||||
|
||||
//=========================================================================
|
||||
// a Clause encapsulates the speculative execution of a set of propagators.
|
||||
// Therefore, these propagators must be posted in a separate (sub)space.
|
||||
// However they normally want to constrain variables of the original home
|
||||
// space: for each such variable X, a variable Y local to the subspace must
|
||||
// be created and used instead, and a forwarder must be created from X to
|
||||
// Y. A Clause is then a Propagator that subscribes to the Xs. Whenever a
|
||||
// X changes, the domains of the Xs are forwarded into the Ys and
|
||||
// constraint propagation is run in the subspace. When a clause is
|
||||
// committed, after propagation, the domains of Ys are forwarded back into
|
||||
// the Xs.
|
||||
//=========================================================================
|
||||
|
||||
// TODO: copy (difficulty is forwarder list)
|
||||
|
||||
class SubSpace;
|
||||
|
||||
class Clause: public Propagator {
|
||||
Disjunctor disj;
|
||||
SubSpace*const subhome;
|
||||
public:
|
||||
Clause(Space& home_, Disjunctor disj_);
|
||||
Clause(Space& home, bool share, Clause& c);
|
||||
virtual Propagator* copy(Space& home, bool share);
|
||||
virtual size_t dispose(Space& home);
|
||||
virtual PropCost cost(const Space&, const ModEventDelta&) const;
|
||||
virtual ExecStatus propagate(Space& home, const ModEventDelta&);
|
||||
// user API
|
||||
operator GenericSpace&();
|
||||
operator Space&();
|
||||
operator Home();
|
||||
GenericSpace* generic_space() const;
|
||||
Space* space() const;
|
||||
void forward(Space& home, IntVar outer, IntVar inner);
|
||||
void forward(Space& home, BoolVar outer, BoolVar inner);
|
||||
void forward(Space& home, SetVar outer, SetVar inner);
|
||||
protected:
|
||||
ExecStatus forward_in();
|
||||
ExecStatus forward_out(Space& outer_home);
|
||||
bool committed() const;
|
||||
};
|
||||
|
||||
//=========================================================================
|
||||
// a SubSpace is the Space associated with a Clause. It also contains the
|
||||
// forwarder linked-list because we want it to manage the memory for that
|
||||
// list.
|
||||
//=========================================================================
|
||||
|
||||
class BasicForwarder;
|
||||
using Int::IntView;
|
||||
using Int::BoolView;
|
||||
using Set::SetView;
|
||||
|
||||
class SubSpace: public GenericSpace
|
||||
{
|
||||
private:
|
||||
Space* homeDuringCloning;
|
||||
// linked-list of pairs of a variable in the parent space and a
|
||||
// corresponding variable in the subspace
|
||||
BasicForwarder* forwarder;
|
||||
// auxiliary methods for adding an entry to the forwarder list
|
||||
void forward(IntView outer, IntView inner);
|
||||
void forward(BoolView outer, BoolView inner);
|
||||
void forward(SetView outer, SetView inner);
|
||||
// for forwarding domains into and out of the subhome
|
||||
ExecStatus forward_in();
|
||||
ExecStatus forward_out(Space&);
|
||||
// for cancelling subscriptions
|
||||
void cancel(Space& home, Clause&);
|
||||
// allow Clause to use this private API
|
||||
friend class Clause;
|
||||
public:
|
||||
SubSpace();
|
||||
SubSpace(bool share, SubSpace& s);
|
||||
virtual Space* copy(bool share);
|
||||
SubSpace* copy(Space& home, bool share);
|
||||
};
|
||||
}}
|
||||
|
||||
namespace Gecode
|
||||
{
|
||||
using Disjunctor_::Disjunctor;
|
||||
|
||||
class Clause
|
||||
{
|
||||
generic_gecode::GenericSpace& _home;
|
||||
Disjunctor_::Clause* _clause;
|
||||
public:
|
||||
Clause(generic_gecode::GenericSpace& home, Disjunctor disj);
|
||||
operator generic_gecode::GenericSpace&();
|
||||
operator Space&();
|
||||
operator Home();
|
||||
generic_gecode::GenericSpace* generic_space();
|
||||
generic_gecode::GenericSpace* generic_parent();
|
||||
Space* space();
|
||||
void forward(IntVar outer, IntVar inner);
|
||||
void forward(BoolVar outer, BoolVar inner);
|
||||
void forward(SetVar outer, SetVar inner);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,380 @@
|
|||
// -*- c++ -*-
|
||||
//=============================================================================
|
||||
// Copyright (C) 2011 by Denys Duchier
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published by the
|
||||
// Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
// more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//=============================================================================
|
||||
#include "disjunctor.hh"
|
||||
|
||||
namespace Gecode { namespace Disjunctor_ {
|
||||
|
||||
//=========================================================================
|
||||
// Disjunctor (following example in MPG)
|
||||
//=========================================================================
|
||||
|
||||
struct DisjunctorObject: public LocalObject
|
||||
{
|
||||
int n;
|
||||
DisjunctorObject(Space& home) : LocalObject(home), n(0) {}
|
||||
DisjunctorObject(Space& home, bool share, DisjunctorObject& d)
|
||||
: LocalObject(home, share, d), n(d.n) {}
|
||||
virtual LocalObject* copy(Space& home, bool share)
|
||||
{ return new (home) DisjunctorObject(home, share, *this); }
|
||||
virtual size_t dispose(Space&) { return sizeof(*this); }
|
||||
};
|
||||
|
||||
Disjunctor::Disjunctor(): LocalHandle() {}
|
||||
Disjunctor::Disjunctor(Space& home)
|
||||
: LocalHandle(new (home) DisjunctorObject(home)) {}
|
||||
Disjunctor::Disjunctor(const Disjunctor& d): LocalHandle(d) {}
|
||||
int Disjunctor::get() const { return static_cast<DisjunctorObject*>(object())->n; }
|
||||
void Disjunctor::incr() { static_cast<DisjunctorObject*>(object())->n += 1; }
|
||||
void Disjunctor::decr() { static_cast<DisjunctorObject*>(object())->n -= 1; }
|
||||
void Disjunctor::dispose(Space& home)
|
||||
{ static_cast<DisjunctorObject*>(object())->dispose(home); }
|
||||
|
||||
//=========================================================================
|
||||
// Forwarder<View>
|
||||
// used to forward the domain of a view V1 into a view V2 located in a
|
||||
// subspace (the subspace of a speculative clause). V2 represents V1 in
|
||||
// that space.
|
||||
//
|
||||
// BasicForwarder
|
||||
// base class of all Forwarders. It declares the virtual functions
|
||||
// that must be implemented to do the actual work, and contains the pointer
|
||||
// implementing the singly-linked list of Forwarders associated with each
|
||||
// clause. It also redefines new and delete to manage memory in the
|
||||
// subspace.
|
||||
//=========================================================================
|
||||
|
||||
struct BasicForwarder
|
||||
{
|
||||
BasicForwarder* next;
|
||||
|
||||
BasicForwarder() : next(NULL) {}
|
||||
|
||||
// forward V1's domain into V2. This is used each time the Clause (as a
|
||||
// a propagator) is woken to perform propagation.
|
||||
|
||||
virtual ExecStatus forward_in(Space& inner_home) = 0;
|
||||
|
||||
// forward V2's domain into V1. This is used after propagation in the
|
||||
// case where the Clause has been committed to (because it is the last
|
||||
// one remaining).
|
||||
|
||||
virtual void forward_out(Space& outer_home) = 0;
|
||||
|
||||
// needed by delete to know how much to free
|
||||
virtual size_t size() const = 0;
|
||||
|
||||
// usage: new (home) FRWRDR(...);
|
||||
// to allocate the instance of FRWRDR on home's heap
|
||||
|
||||
static void* operator new(size_t n, Space& home)
|
||||
{ return home.ralloc(n); }
|
||||
|
||||
// usage: delete (home) PTR;
|
||||
// to free the instance pointed to by PTR from home's heap
|
||||
|
||||
static void operator delete(void* ptr, Space& home)
|
||||
{ home.rfree(ptr, ((BasicForwarder*)ptr)->size()); }
|
||||
|
||||
virtual BasicForwarder*
|
||||
copy(Space& outer_home, Space& inner_home, bool share) = 0;
|
||||
|
||||
virtual void cancel(Space& home, Clause&) = 0;
|
||||
};
|
||||
|
||||
// Forwarder parametrized by View
|
||||
|
||||
template <typename View>
|
||||
struct Forwarder: public BasicForwarder
|
||||
{
|
||||
View outer;
|
||||
View inner;
|
||||
Forwarder(View v1, View v2): outer(v1), inner(v2) {}
|
||||
Forwarder() {}
|
||||
virtual ExecStatus forward_in(Space& home);
|
||||
virtual void forward_out(Space& home);
|
||||
virtual size_t size() const { return sizeof(*this); }
|
||||
virtual BasicForwarder* copy(Space& outer_home, Space& inner_home, bool share)
|
||||
{
|
||||
Forwarder<View>* fwd = new (inner_home) Forwarder<View>();
|
||||
fwd->outer.update(outer_home, share, outer);
|
||||
fwd->inner.update(inner_home, share, inner);
|
||||
return fwd;
|
||||
}
|
||||
virtual void cancel(Space& home, Clause& c);
|
||||
};
|
||||
|
||||
// instances of Forwarder that we actually use
|
||||
|
||||
typedef Forwarder<Int::IntView> IntForwarder;
|
||||
typedef Forwarder<Int::BoolView> BoolForwarder;
|
||||
typedef Forwarder<Set::SetView> SetForwarder;
|
||||
|
||||
//=========================================================================
|
||||
// IntForwarder
|
||||
//=========================================================================
|
||||
|
||||
template <>
|
||||
ExecStatus IntForwarder::forward_in(Space& home) // inner home
|
||||
{
|
||||
Int::ViewRanges<Int::IntView> r(outer);
|
||||
GECODE_ME_CHECK(inner.inter_r(home,r));
|
||||
return ES_OK;
|
||||
}
|
||||
|
||||
template <>
|
||||
void IntForwarder::forward_out(Space& home) // outer home
|
||||
{
|
||||
// it is guaranteed by design that after successful propagation the
|
||||
// domain of the inner variable is a non-empty narrowing of the domain of
|
||||
// the outer variable. therefore, we can simply replace the domain of
|
||||
// the outer variable with the domain of the inner variable.
|
||||
Int::ViewRanges<Int::IntView> r(inner);
|
||||
outer.narrow_r(home, r, false);
|
||||
}
|
||||
|
||||
template <>
|
||||
void IntForwarder::cancel(Space& home, Clause& c)
|
||||
{ outer.cancel(home, c, Int::PC_INT_DOM); }
|
||||
|
||||
//=========================================================================
|
||||
// BoolForwarder
|
||||
//=========================================================================
|
||||
|
||||
template <>
|
||||
ExecStatus BoolForwarder::forward_in(Space& home)
|
||||
{
|
||||
Int::ViewRanges<Int::BoolView> r(outer);
|
||||
GECODE_ME_CHECK(inner.inter_r(home,r));
|
||||
return ES_OK;
|
||||
}
|
||||
|
||||
template <>
|
||||
void BoolForwarder::forward_out(Space& home)
|
||||
{
|
||||
Int::ViewRanges<Int::BoolView> r(inner);
|
||||
outer.narrow_r(home, r, false);
|
||||
}
|
||||
|
||||
template <>
|
||||
void BoolForwarder::cancel(Space& home, Clause& c)
|
||||
{ outer.cancel(home, c, Int::PC_INT_DOM); }
|
||||
|
||||
//=========================================================================
|
||||
// SetForwarder
|
||||
//=========================================================================
|
||||
|
||||
template <>
|
||||
ExecStatus SetForwarder::forward_in(Space& home)
|
||||
{
|
||||
Set::GlbRanges<SetView> gr(outer);
|
||||
GECODE_ME_CHECK(inner.includeI(home,gr));
|
||||
Set::LubRanges<SetView> lr(outer);
|
||||
GECODE_ME_CHECK(inner.intersectI(home,lr));
|
||||
GECODE_ME_CHECK(inner.cardMin(home, outer.cardMin()));
|
||||
GECODE_ME_CHECK(inner.cardMax(home, outer.cardMax()));
|
||||
return ES_OK;
|
||||
}
|
||||
|
||||
template <>
|
||||
void SetForwarder::forward_out(Space& home)
|
||||
{
|
||||
Set::GlbRanges<SetView> gr(inner);
|
||||
outer.includeI(home, gr);
|
||||
Set::LubRanges<SetView> lr(inner);
|
||||
outer.intersectI(home, lr);
|
||||
outer.cardMin(home, inner.cardMin());
|
||||
outer.cardMax(home, inner.cardMax());
|
||||
}
|
||||
|
||||
template <>
|
||||
void SetForwarder::cancel(Space& home, Clause& c)
|
||||
{ outer.cancel(home, c, Set::PC_SET_ANY); }
|
||||
|
||||
//=========================================================================
|
||||
// SubSpace
|
||||
//=========================================================================
|
||||
|
||||
void SubSpace::forward(IntView outer, IntView inner)
|
||||
{
|
||||
BasicForwarder* fwd = new (*this) IntForwarder(outer, inner);
|
||||
fwd->next = forwarder;
|
||||
forwarder = fwd;
|
||||
}
|
||||
|
||||
void SubSpace::forward(BoolView outer, BoolView inner)
|
||||
{
|
||||
BasicForwarder* fwd = new (*this) BoolForwarder(outer, inner);
|
||||
fwd->next = forwarder;
|
||||
forwarder = fwd;
|
||||
}
|
||||
|
||||
void SubSpace::forward(SetView outer, SetView inner)
|
||||
{
|
||||
BasicForwarder* fwd = new (*this) SetForwarder(outer, inner);
|
||||
fwd->next = forwarder;
|
||||
forwarder = fwd;
|
||||
}
|
||||
|
||||
ExecStatus SubSpace::forward_in()
|
||||
{
|
||||
for (BasicForwarder* p=forwarder; p!=NULL; p=p->next)
|
||||
GECODE_ES_CHECK(p->forward_in(*this));
|
||||
return ES_OK;
|
||||
}
|
||||
|
||||
ExecStatus SubSpace::forward_out(Space& home) // outer home
|
||||
{
|
||||
for (BasicForwarder* p=forwarder; p!=NULL; p=p->next)
|
||||
p->forward_out(home);
|
||||
return ES_OK;
|
||||
}
|
||||
|
||||
SubSpace::SubSpace(): GenericSpace(), forwarder(NULL) {}
|
||||
|
||||
SubSpace::SubSpace(bool share, SubSpace& s)
|
||||
: GenericSpace(share, s), forwarder(NULL)
|
||||
{
|
||||
BasicForwarder** prev = &forwarder;
|
||||
for (BasicForwarder* p=s.forwarder; p!=NULL; p=p->next)
|
||||
{
|
||||
BasicForwarder* fwd = p->copy(*s.homeDuringCloning, *this, share);
|
||||
*prev = fwd;
|
||||
prev = &fwd->next;
|
||||
}
|
||||
}
|
||||
|
||||
Space* SubSpace::copy(bool share)
|
||||
{ return new SubSpace(share,*this); }
|
||||
|
||||
SubSpace* SubSpace::copy(Space& home, bool share)
|
||||
{ homeDuringCloning = &home; return static_cast<SubSpace*>(clone(share)); }
|
||||
|
||||
void SubSpace::cancel(Space& home, Clause& c)
|
||||
{
|
||||
for (BasicForwarder*p = forwarder; p!=NULL; p=p->next)
|
||||
p->cancel(home, c);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// Clause
|
||||
//=========================================================================
|
||||
|
||||
Clause::operator GenericSpace&() { return *subhome; }
|
||||
Clause::operator Space&() { return *subhome; }
|
||||
Clause::operator Home() { return *subhome; }
|
||||
|
||||
GenericSpace* Clause::generic_space() const { return subhome; }
|
||||
Space* Clause::space() const { return subhome; }
|
||||
|
||||
Clause::Clause(Space& home_, Disjunctor disj_)
|
||||
: Propagator(home_), disj(disj_), subhome(new SubSpace())
|
||||
{
|
||||
disj.incr();
|
||||
}
|
||||
|
||||
Clause::Clause(Space& home, bool share, Clause& c)
|
||||
: Propagator(home, share, c), subhome(c.subhome->copy(home, share))
|
||||
{
|
||||
disj.update(home, share, c.disj);
|
||||
}
|
||||
|
||||
Propagator* Clause::copy(Space& home, bool share)
|
||||
{ return new (home) Clause(home, share, *this); }
|
||||
|
||||
void Clause::forward(Space& home, IntVar outer, IntVar inner)
|
||||
{
|
||||
IntView oview(outer);
|
||||
IntView iview(inner);
|
||||
subhome->forward(oview, iview);
|
||||
oview.subscribe(home, *this, Int::PC_INT_DOM);
|
||||
}
|
||||
|
||||
void Clause::forward(Space& home, BoolVar outer, BoolVar inner)
|
||||
{
|
||||
BoolView oview(outer);
|
||||
BoolView iview(inner);
|
||||
subhome->forward(oview, iview);
|
||||
oview.subscribe(home, *this, Int::PC_INT_DOM);
|
||||
}
|
||||
|
||||
void Clause::forward(Space& home, SetVar outer, SetVar inner)
|
||||
{
|
||||
SetView oview(outer);
|
||||
SetView iview(inner);
|
||||
subhome->forward(oview, iview);
|
||||
oview.subscribe(home, *this, Set::PC_SET_ANY);
|
||||
}
|
||||
|
||||
ExecStatus Clause::forward_in()
|
||||
{ return subhome->forward_in(); }
|
||||
|
||||
ExecStatus Clause::forward_out(Space& home) // outer home
|
||||
{ return subhome->forward_out(home); }
|
||||
|
||||
inline bool Clause::committed() const { return disj.get() == 1; }
|
||||
|
||||
ExecStatus Clause::propagate(Space& home, const ModEventDelta&)
|
||||
{
|
||||
if (forward_in() == ES_FAILED ||
|
||||
subhome->status() == SS_FAILED )
|
||||
{
|
||||
if (committed()) return ES_FAILED;
|
||||
disj.decr();
|
||||
return home.ES_SUBSUMED(*this);
|
||||
}
|
||||
if (committed()) forward_out(home);
|
||||
// maybe do something clever about subsumption later
|
||||
return ES_FIX;
|
||||
}
|
||||
|
||||
size_t Clause::dispose(Space& home)
|
||||
{
|
||||
subhome->cancel(home, *this);
|
||||
delete subhome;
|
||||
// the memory for the disj's LocalObject is not recovered
|
||||
(void) Propagator::dispose(home);
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
PropCost Clause::cost(const Space&, const ModEventDelta&) const
|
||||
{
|
||||
// consider a clause to be crazy expensive
|
||||
return PropCost::crazy(PropCost::HI,10);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Clause (user API)
|
||||
//===========================================================================
|
||||
|
||||
Clause::Clause(generic_gecode::GenericSpace& home, Disjunctor disj)
|
||||
: _home(home), _clause(new (home) Disjunctor_::Clause(home, disj)) {}
|
||||
Clause::operator generic_gecode::GenericSpace&() { return *_clause; }
|
||||
Clause::operator Space&() { return *_clause; }
|
||||
Clause::operator Home() { return *_clause; }
|
||||
generic_gecode::GenericSpace* Clause::generic_space() { return _clause->generic_space(); }
|
||||
generic_gecode::GenericSpace* Clause::generic_parent() { return &_home; }
|
||||
Space* Clause::space() { return _clause->space(); }
|
||||
void Clause::forward(IntVar outer, IntVar inner)
|
||||
{ _clause->forward(_home, outer, inner); }
|
||||
void Clause::forward(BoolVar outer, BoolVar inner)
|
||||
{ _clause->forward(_home, outer, inner); }
|
||||
void Clause::forward(SetVar outer, SetVar inner)
|
||||
{ _clause->forward(_home, outer, inner); }
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
%% -*- prolog -*-
|
||||
%%=============================================================================
|
||||
%% Copyright (C) 2011 by Denys Duchier
|
||||
%%
|
||||
%% This program is free software: you can redistribute it and/or modify it
|
||||
%% under the terms of the GNU Lesser General Public License as published by the
|
||||
%% Free Software Foundation, either version 3 of the License, or (at your
|
||||
%% option) any later version.
|
||||
%%
|
||||
%% This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
%% more details.
|
||||
%%
|
||||
%% You should have received a copy of the GNU Lesser General Public License
|
||||
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
%%=============================================================================
|
||||
|
||||
:- use_module(gecode).
|
||||
|
||||
disjunctor1(X_,Y_) :-
|
||||
Space := space,
|
||||
[X,Y] := intvars(Space,2,0,3),
|
||||
D := disjunctor(Space),
|
||||
C1 := clause(D),
|
||||
[X1,Y1] := intvars(C1,2,0,3),
|
||||
C1 += rel(X1,'IRT_EQ',1),
|
||||
C1 += rel(Y1,'IRT_EQ',1),
|
||||
C1 += forward([X,Y],[X1,Y1]),
|
||||
C2 := clause(D),
|
||||
[X2,Y2] := intvars(C2,2,0,3),
|
||||
C2 += rel(X2,'IRT_EQ',2),
|
||||
C2 += rel(Y2,'IRT_EQ',2),
|
||||
C2 += forward([X,Y],[X2,Y2]),
|
||||
Space += branch([X,Y],'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
|
||||
SolSpace := search(Space),
|
||||
[X_,Y_] := val(SolSpace,[X,Y]).
|
|
@ -0,0 +1,37 @@
|
|||
%% -*- prolog -*-
|
||||
%%=============================================================================
|
||||
%% Copyright (C) 2011 by Denys Duchier
|
||||
%%
|
||||
%% This program is free software: you can redistribute it and/or modify it
|
||||
%% under the terms of the GNU Lesser General Public License as published by the
|
||||
%% Free Software Foundation, either version 3 of the License, or (at your
|
||||
%% option) any later version.
|
||||
%%
|
||||
%% This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
%% more details.
|
||||
%%
|
||||
%% You should have received a copy of the GNU Lesser General Public License
|
||||
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
%%=============================================================================
|
||||
|
||||
:- use_module(gecode).
|
||||
|
||||
disjunctor2(X_,Y_) :-
|
||||
Space := space,
|
||||
[X,Y] := intvars(Space,2,0,3),
|
||||
D := disjunctor(Space),
|
||||
C1 := clause(D),
|
||||
[X1,Y1] := intvars(C1,2,0,3),
|
||||
C1 += forward([X,Y],[X1,Y1]),
|
||||
C1 += rel(X1,'IRT_EQ',0),
|
||||
C1 += rel(Y1,'IRT_EQ',0),
|
||||
C2 := clause(D),
|
||||
[X2,Y2] := intvars(C2,2,0,3),
|
||||
C2 += forward([X,Y],[X2,Y2]),
|
||||
Z2 := intvar(C2,1,2),
|
||||
C2 += linear([-1,1,1],[X2,Y2,Z2],'IRT_EQ',0),
|
||||
Space += branch([X,Y],'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
|
||||
SolSpace := search(Space),
|
||||
[X_,Y_] := val(SolSpace,[X,Y]).
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,33 @@
|
|||
GECODEDIR := $(shell g++ -q $(CPPFLAGS) $(CXXFLAGS) -H -E gecodedir.hh 2>&1 >/dev/null | grep gecode/kernel.hh | awk '{print $$2}' | sed 's|/kernel.hh||')
|
||||
GECODECONFIG := $(GECODEDIR)/support/config.hpp
|
||||
GECODEVERSION := $(shell cat $(GECODECONFIG) | egrep GECODE_VERSION | awk '{print $$3}' | sed 's/"//g')
|
||||
PROTOTYPES = gecode-prototypes-$(GECODEVERSION).hh
|
||||
ENUMS = gecode-enums-$(GECODEVERSION).py
|
||||
|
||||
all: $(PROTOTYPES) $(ENUMS)
|
||||
|
||||
$(PROTOTYPES): % : xml/namespaceGecode.xml extract-prototypes.xsl
|
||||
cat notice.hh > $@
|
||||
xsltproc extract-prototypes.xsl $< \
|
||||
| sed 's/Gecode:://g' \
|
||||
| sed 's/< /</g' \
|
||||
| sed 's/ >/>/g' \
|
||||
| sed 's/ \&/\&/g' \
|
||||
| sed 's/, /,/g' \
|
||||
| sed 's/forceinline //g' \
|
||||
| sed 's/GECODE_INT_EXPORT //g' \
|
||||
| sed 's/GECODE_SET_EXPORT //g' \
|
||||
| grep -v '*' | sort >> $@
|
||||
|
||||
$(ENUMS): % : xml/namespaceGecode.xml extract-enums.xsl
|
||||
cat notice.py > $@
|
||||
xsltproc extract-enums.xsl $< >> $@
|
||||
|
||||
xml/namespaceGecode.xml: Doxyfile
|
||||
doxygen Doxyfile
|
||||
|
||||
Doxyfile: Doxyfile.in
|
||||
cat $< | sed "s#@GECODEDIR@#$(GECODEDIR)#" > $@
|
||||
|
||||
clean:
|
||||
-rm -rf *~ gecode-prototypes-*.hh gecode-enums-*.py Doxyfile xml
|
|
@ -0,0 +1,2 @@
|
|||
This directory contains support code for automatically extracting
|
||||
prototypes from the local Gecode installation.
|
|
@ -0,0 +1,31 @@
|
|||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:output method="text" version="1.0"/>
|
||||
<xsl:template match="/">
|
||||
<xsl:text>ENUM_CLASSES = []
|
||||
|
||||
</xsl:text>
|
||||
<xsl:for-each select="/doxygen/compounddef/sectiondef[@kind='enum']/memberdef">
|
||||
<xsl:text>class </xsl:text>
|
||||
<xsl:value-of select="name"/>
|
||||
<xsl:text>(object):
|
||||
</xsl:text>
|
||||
<xsl:text> TYPE = '</xsl:text>
|
||||
<xsl:value-of select="name"/>
|
||||
<xsl:text>'
|
||||
ENUM = [</xsl:text>
|
||||
<xsl:for-each select="enumvalue">
|
||||
<xsl:if test="position()!=1"><xsl:text>,</xsl:text></xsl:if>
|
||||
<xsl:text>'</xsl:text>
|
||||
<xsl:value-of select="name"/>
|
||||
<xsl:text>'</xsl:text>
|
||||
</xsl:for-each>
|
||||
<xsl:text>]
|
||||
|
||||
ENUM_CLASSES.append(</xsl:text>
|
||||
<xsl:value-of select="name"/>
|
||||
<xsl:text>)
|
||||
|
||||
</xsl:text>
|
||||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
|
@ -0,0 +1,21 @@
|
|||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:output method="text" version="1.0"/>
|
||||
<xsl:template match="/">
|
||||
<xsl:for-each select="/doxygen/compounddef/sectiondef[@kind='func']/memberdef[starts-with(@id,'group__TaskModel') and not(starts-with(name,'operator')) and name!='tiebreak' and name!='wait' and not(starts-with(@id,'group__TaskModelMiniModel'))]">
|
||||
<xsl:value-of select="type"/>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:value-of select="name"/>
|
||||
<xsl:for-each select="param">
|
||||
<xsl:if test="position()=1"><xsl:text>(</xsl:text></xsl:if>
|
||||
<xsl:if test="position()!=1"><xsl:text>,</xsl:text></xsl:if>
|
||||
<xsl:value-of select="type"/>
|
||||
<xsl:for-each select="defval">
|
||||
<xsl:text>=</xsl:text>
|
||||
<xsl:value-of select="."/>
|
||||
</xsl:for-each>
|
||||
</xsl:for-each>
|
||||
<xsl:text>);
|
||||
</xsl:text>
|
||||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
|
@ -0,0 +1 @@
|
|||
#include "gecode/kernel.hh"
|
|
@ -0,0 +1,3 @@
|
|||
// This file was automatically extracted from Gecode source files.
|
||||
// It is subject to the same Copyright as the source files from which
|
||||
// it is derived, and is distributed under the same Licensing conditions.
|
|
@ -0,0 +1,3 @@
|
|||
# This file was automatically extracted from Gecode source files.
|
||||
# It is subject to the same Copyright as the source files from which
|
||||
# it is derived, and is distributed under the same Licensing conditions.
|
|
@ -0,0 +1,259 @@
|
|||
// -*- c++ -*-
|
||||
//=============================================================================
|
||||
// Copyright (C) 2011 by Denys Duchier
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published by the
|
||||
// Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
// more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//=============================================================================
|
||||
|
||||
#ifndef GECODE_COMMON
|
||||
#define GECODE_COMMON
|
||||
|
||||
#include "gecode/int.hh"
|
||||
#include "gecode/set.hh"
|
||||
#include "gecode/search.hh"
|
||||
#include <vector>
|
||||
|
||||
namespace generic_gecode
|
||||
{
|
||||
using namespace std;
|
||||
using namespace Gecode;
|
||||
|
||||
// description of the optimization criterion
|
||||
struct Optimizing
|
||||
{
|
||||
enum What { OPT_NONE, OPT_INT, OPT_RATIO };
|
||||
enum How { OPT_MIN, OPT_MAX };
|
||||
int num;
|
||||
int den;
|
||||
What what;
|
||||
How how;
|
||||
Optimizing(): num(-1), den(-1), what(OPT_NONE), how(OPT_MAX) {}
|
||||
Optimizing(Optimizing& o)
|
||||
: num(o.num), den(o.den), what(o.what), how(o.how) {}
|
||||
void maximize(int i)
|
||||
{ what = OPT_INT; how = OPT_MAX; num = i; };
|
||||
void maximize(int i,int j)
|
||||
{ what = OPT_RATIO; how = OPT_MAX; num = i; den = j; };
|
||||
void minimize(int i)
|
||||
{ what = OPT_INT; how = OPT_MIN; num = i; };
|
||||
void minimize(int i,int j)
|
||||
{ what = OPT_RATIO; how = OPT_MIN; num = i; den = j; };
|
||||
};
|
||||
|
||||
struct GenericSpace;
|
||||
|
||||
struct GenericEngine
|
||||
{
|
||||
virtual GenericSpace* next(void)=0;
|
||||
virtual ~GenericEngine() {};
|
||||
};
|
||||
|
||||
struct GenericDFS: GenericEngine
|
||||
{
|
||||
DFS<GenericSpace> engine;
|
||||
GenericDFS(GenericSpace* s) : engine(s) {}
|
||||
virtual GenericSpace* next(void) { return engine.next(); }
|
||||
};
|
||||
|
||||
struct GenericBAB: GenericEngine
|
||||
{
|
||||
BAB<GenericSpace> engine;
|
||||
GenericBAB(GenericSpace* s) : engine(s) {}
|
||||
virtual GenericSpace* next(void) { return engine.next(); }
|
||||
};
|
||||
|
||||
struct GenericSpace: Space
|
||||
{
|
||||
Optimizing optim;
|
||||
IntVarArray ivars;
|
||||
BoolVarArray bvars;
|
||||
SetVarArray svars;
|
||||
vector<IntVar>* _ivars;
|
||||
vector<BoolVar>* _bvars;
|
||||
vector<SetVar>* _svars;
|
||||
|
||||
Space* space() { return this; }
|
||||
|
||||
GenericSpace(bool share, GenericSpace& s)
|
||||
: Space(share, s), optim(s.optim),
|
||||
_ivars(NULL), _bvars(NULL), _svars(NULL)
|
||||
{
|
||||
ivars.update(*this, share, s.ivars);
|
||||
bvars.update(*this, share, s.bvars);
|
||||
svars.update(*this, share, s.svars);
|
||||
}
|
||||
|
||||
Space* copy(bool share)
|
||||
{ freeze(); return new GenericSpace(share, *this); }
|
||||
|
||||
GenericSpace() : _ivars(NULL), _bvars(NULL), _svars(NULL) {}
|
||||
|
||||
// freeze the space before handing it off to a search engine
|
||||
void freeze()
|
||||
{
|
||||
if (_ivars)
|
||||
{
|
||||
int n = _ivars->size();
|
||||
ivars = IntVarArray(*this, n);
|
||||
vector<IntVar>& v(*_ivars);
|
||||
for (; n--;) ivars[n] = v[n];
|
||||
delete _ivars;
|
||||
_ivars = NULL;
|
||||
}
|
||||
|
||||
if (_bvars)
|
||||
{
|
||||
int n = _bvars->size();
|
||||
bvars = BoolVarArray(*this, n);
|
||||
vector<BoolVar>& v(*_bvars);
|
||||
for (; n--;) bvars[n] = v[n];
|
||||
delete _bvars;
|
||||
_bvars = NULL;
|
||||
}
|
||||
|
||||
if (_svars)
|
||||
{
|
||||
int n = _svars->size();
|
||||
svars = SetVarArray(*this, n);
|
||||
vector<SetVar>& v(*_svars);
|
||||
for (; n--;) svars[n] = v[n];
|
||||
delete _svars;
|
||||
_svars = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
IntVar get_ivar(int i) const { return (_ivars) ? (*_ivars)[i] : ivars[i]; }
|
||||
BoolVar get_bvar(int i) const { return (_bvars) ? (*_bvars)[i] : bvars[i]; }
|
||||
SetVar get_svar(int i) const { return (_svars) ? (*_svars)[i] : svars[i]; }
|
||||
|
||||
GenericEngine* new_engine()
|
||||
{
|
||||
freeze();
|
||||
return (optim.what == Optimizing::OPT_NONE)
|
||||
? static_cast<GenericEngine*>(new GenericDFS(this))
|
||||
: static_cast<GenericEngine*>(new GenericBAB(this));
|
||||
}
|
||||
|
||||
int _new_ivar(IntVar& v)
|
||||
{
|
||||
if (!_ivars) _ivars = new vector<IntVar>;
|
||||
int i = _ivars->size();
|
||||
_ivars->push_back(v);
|
||||
return i;
|
||||
}
|
||||
|
||||
int new_ivar(int lo, int hi)
|
||||
{
|
||||
IntVar v(*this, lo, hi);
|
||||
return _new_ivar(v);
|
||||
}
|
||||
|
||||
int new_ivar(IntSet& s)
|
||||
{
|
||||
IntVar v(*this, s);
|
||||
return _new_ivar(v);
|
||||
}
|
||||
|
||||
int _new_bvar(BoolVar& v)
|
||||
{
|
||||
if (!_bvars) _bvars = new vector<BoolVar>;
|
||||
int i = _bvars->size();
|
||||
_bvars->push_back(v);
|
||||
return i;
|
||||
}
|
||||
|
||||
int new_bvar()
|
||||
{
|
||||
BoolVar v(*this, 0, 1);
|
||||
return _new_bvar(v);
|
||||
}
|
||||
|
||||
int _new_svar(SetVar& v)
|
||||
{
|
||||
if (!_svars) _svars = new vector<SetVar>;
|
||||
int i = _svars->size();
|
||||
_svars->push_back(v);
|
||||
return i;
|
||||
}
|
||||
|
||||
int new_svar(int glbMin, int glbMax, int lubMin, int lubMax,
|
||||
unsigned int cardMin=0,
|
||||
unsigned int cardMax=Set::Limits::card)
|
||||
{
|
||||
SetVar v(*this, glbMin, glbMax, lubMin, lubMax, cardMin, cardMax);
|
||||
return _new_svar(v);
|
||||
}
|
||||
|
||||
int new_svar(IntSet glb, int lubMin, int lubMax,
|
||||
unsigned int cardMin=0,
|
||||
unsigned int cardMax=Set::Limits::card)
|
||||
{
|
||||
SetVar v(*this, glb, lubMin, lubMax, cardMin, cardMax);
|
||||
return _new_svar(v);
|
||||
}
|
||||
|
||||
int new_svar(int glbMin, int glbMax, IntSet lub,
|
||||
unsigned int cardMin=0,
|
||||
unsigned int cardMax=Set::Limits::card)
|
||||
{
|
||||
SetVar v(*this, glbMin, glbMax, lub, cardMin, cardMax);
|
||||
return _new_svar(v);
|
||||
}
|
||||
|
||||
int new_svar(IntSet glb, IntSet lub,
|
||||
unsigned int cardMin=0,
|
||||
unsigned int cardMax=Set::Limits::card)
|
||||
{
|
||||
SetVar v(*this, glb, lub, cardMin, cardMax);
|
||||
return _new_svar(v);
|
||||
}
|
||||
|
||||
void minimize(int i) { optim.minimize(i); }
|
||||
void minimize(int i, int j) { optim.minimize(i,j); }
|
||||
void maximize(int i) { optim.maximize(i); }
|
||||
void maximize(int i, int j) { optim.maximize(i,j); }
|
||||
|
||||
virtual void constrain(const Space& s)
|
||||
{
|
||||
const GenericSpace& sol = static_cast<const GenericSpace&>(s);
|
||||
switch (optim.what)
|
||||
{
|
||||
case Optimizing::OPT_NONE:
|
||||
break;
|
||||
case Optimizing::OPT_INT:
|
||||
rel(*this, ivars[optim.num],
|
||||
((optim.how==Optimizing::OPT_MIN) ? IRT_LE : IRT_GR),
|
||||
sol.ivars[optim.num].val());
|
||||
break;
|
||||
case Optimizing::OPT_RATIO:
|
||||
{
|
||||
IntArgs c(2, sol.ivars[optim.den].val(),
|
||||
- sol.ivars[optim.num].val());
|
||||
IntVarArgs v(2);
|
||||
v[0] = ivars[optim.num];
|
||||
v[1] = ivars[optim.den];
|
||||
linear(*this, c, v,
|
||||
((optim.how==Optimizing::OPT_MIN) ? IRT_LE : IRT_GR), 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef DISJUNCTOR
|
||||
#include "disjunctor.icc"
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,113 @@
|
|||
# This file was automatically extracted from Gecode source files.
|
||||
# It is subject to the same Copyright as the source files from which
|
||||
# it is derived, and is distributed under the same Licensing conditions.
|
||||
ENUM_CLASSES = []
|
||||
|
||||
class ScriptMode(object):
|
||||
TYPE = 'ScriptMode'
|
||||
ENUM = ['SM_SOLUTION','SM_TIME','SM_STAT','SM_GIST']
|
||||
|
||||
ENUM_CLASSES.append(ScriptMode)
|
||||
|
||||
class IntRelType(object):
|
||||
TYPE = 'IntRelType'
|
||||
ENUM = ['IRT_EQ','IRT_NQ','IRT_LQ','IRT_LE','IRT_GQ','IRT_GR']
|
||||
|
||||
ENUM_CLASSES.append(IntRelType)
|
||||
|
||||
class BoolOpType(object):
|
||||
TYPE = 'BoolOpType'
|
||||
ENUM = ['BOT_AND','BOT_OR','BOT_IMP','BOT_EQV','BOT_XOR']
|
||||
|
||||
ENUM_CLASSES.append(BoolOpType)
|
||||
|
||||
class IntConLevel(object):
|
||||
TYPE = 'IntConLevel'
|
||||
ENUM = ['ICL_VAL','ICL_BND','ICL_DOM','ICL_DEF']
|
||||
|
||||
ENUM_CLASSES.append(IntConLevel)
|
||||
|
||||
class TaskType(object):
|
||||
TYPE = 'TaskType'
|
||||
ENUM = ['TT_FIXP','TT_FIXS','TT_FIXE']
|
||||
|
||||
ENUM_CLASSES.append(TaskType)
|
||||
|
||||
class ExtensionalPropKind(object):
|
||||
TYPE = 'ExtensionalPropKind'
|
||||
ENUM = ['EPK_DEF','EPK_SPEED','EPK_MEMORY']
|
||||
|
||||
ENUM_CLASSES.append(ExtensionalPropKind)
|
||||
|
||||
class IntVarBranch(object):
|
||||
TYPE = 'IntVarBranch'
|
||||
ENUM = ['INT_VAR_NONE','INT_VAR_RND','INT_VAR_DEGREE_MIN','INT_VAR_DEGREE_MAX','INT_VAR_AFC_MIN','INT_VAR_AFC_MAX','INT_VAR_MIN_MIN','INT_VAR_MIN_MAX','INT_VAR_MAX_MIN','INT_VAR_MAX_MAX','INT_VAR_SIZE_MIN','INT_VAR_SIZE_MAX','INT_VAR_SIZE_DEGREE_MIN','INT_VAR_SIZE_DEGREE_MAX','INT_VAR_SIZE_AFC_MIN','INT_VAR_SIZE_AFC_MAX','INT_VAR_REGRET_MIN_MIN','INT_VAR_REGRET_MIN_MAX','INT_VAR_REGRET_MAX_MIN','INT_VAR_REGRET_MAX_MAX']
|
||||
|
||||
ENUM_CLASSES.append(IntVarBranch)
|
||||
|
||||
class IntValBranch(object):
|
||||
TYPE = 'IntValBranch'
|
||||
ENUM = ['INT_VAL_MIN','INT_VAL_MED','INT_VAL_MAX','INT_VAL_RND','INT_VAL_SPLIT_MIN','INT_VAL_SPLIT_MAX','INT_VAL_RANGE_MIN','INT_VAL_RANGE_MAX','INT_VALUES_MIN','INT_VALUES_MAX']
|
||||
|
||||
ENUM_CLASSES.append(IntValBranch)
|
||||
|
||||
class IntAssign(object):
|
||||
TYPE = 'IntAssign'
|
||||
ENUM = ['INT_ASSIGN_MIN','INT_ASSIGN_MED','INT_ASSIGN_MAX','INT_ASSIGN_RND']
|
||||
|
||||
ENUM_CLASSES.append(IntAssign)
|
||||
|
||||
class ViewSelStatus(object):
|
||||
TYPE = 'ViewSelStatus'
|
||||
ENUM = ['VSS_BEST','VSS_BETTER','VSS_TIE','VSS_WORSE']
|
||||
|
||||
ENUM_CLASSES.append(ViewSelStatus)
|
||||
|
||||
class ExecStatus(object):
|
||||
TYPE = 'ExecStatus'
|
||||
ENUM = ['__ES_SUBSUMED','ES_FAILED','ES_NOFIX','ES_OK','ES_FIX','ES_NOFIX_FORCE','__ES_PARTIAL']
|
||||
|
||||
ENUM_CLASSES.append(ExecStatus)
|
||||
|
||||
class ActorProperty(object):
|
||||
TYPE = 'ActorProperty'
|
||||
ENUM = ['AP_DISPOSE','AP_WEAKLY']
|
||||
|
||||
ENUM_CLASSES.append(ActorProperty)
|
||||
|
||||
class SpaceStatus(object):
|
||||
TYPE = 'SpaceStatus'
|
||||
ENUM = ['SS_FAILED','SS_SOLVED','SS_BRANCH']
|
||||
|
||||
ENUM_CLASSES.append(SpaceStatus)
|
||||
|
||||
class SetRelType(object):
|
||||
TYPE = 'SetRelType'
|
||||
ENUM = ['SRT_EQ','SRT_NQ','SRT_SUB','SRT_SUP','SRT_DISJ','SRT_CMPL']
|
||||
|
||||
ENUM_CLASSES.append(SetRelType)
|
||||
|
||||
class SetOpType(object):
|
||||
TYPE = 'SetOpType'
|
||||
ENUM = ['SOT_UNION','SOT_DUNION','SOT_INTER','SOT_MINUS']
|
||||
|
||||
ENUM_CLASSES.append(SetOpType)
|
||||
|
||||
class SetVarBranch(object):
|
||||
TYPE = 'SetVarBranch'
|
||||
ENUM = ['SET_VAR_NONE','SET_VAR_RND','SET_VAR_DEGREE_MIN','SET_VAR_DEGREE_MAX','SET_VAR_AFC_MIN','SET_VAR_AFC_MAX','SET_VAR_MIN_MIN','SET_VAR_MIN_MAX','SET_VAR_MAX_MIN','SET_VAR_MAX_MAX','SET_VAR_SIZE_MIN','SET_VAR_SIZE_MAX','SET_VAR_SIZE_DEGREE_MIN','SET_VAR_SIZE_DEGREE_MAX','SET_VAR_SIZE_AFC_MIN','SET_VAR_SIZE_AFC_MAX']
|
||||
|
||||
ENUM_CLASSES.append(SetVarBranch)
|
||||
|
||||
class SetValBranch(object):
|
||||
TYPE = 'SetValBranch'
|
||||
ENUM = ['SET_VAL_MIN_INC','SET_VAL_MIN_EXC','SET_VAL_MED_INC','SET_VAL_MED_EXC','SET_VAL_MAX_INC','SET_VAL_MAX_EXC','SET_VAL_RND_INC','SET_VAL_RND_EXC']
|
||||
|
||||
ENUM_CLASSES.append(SetValBranch)
|
||||
|
||||
class SetAssign(object):
|
||||
TYPE = 'SetAssign'
|
||||
ENUM = ['SET_ASSIGN_MIN_INC','SET_ASSIGN_MIN_EXC','SET_ASSIGN_MED_INC','SET_ASSIGN_MED_EXC','SET_ASSIGN_MAX_INC','SET_ASSIGN_MAX_EXC','SET_ASSIGN_RND_INC','SET_ASSIGN_RND_EXC']
|
||||
|
||||
ENUM_CLASSES.append(SetAssign)
|
||||
|
Binary file not shown.
|
@ -0,0 +1,209 @@
|
|||
// This file was automatically extracted from Gecode source files.
|
||||
// It is subject to the same Copyright as the source files from which
|
||||
// it is derived, and is distributed under the same Licensing conditions.
|
||||
void abs(Home,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void assign(Home,BoolVar,IntAssign,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void assign(Home,const BoolVarArgs&,IntAssign,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void assign(Home,const IntVarArgs&,IntAssign,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void assign(Home,const SetVarArgs&,SetAssign,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void assign(Home,IntVar,IntAssign,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void assign(Home,SetVar,SetAssign,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void atmostOne(Home,const SetVarArgs&,unsigned int);
|
||||
void binpacking(Home,const IntVarArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void branch(Home,BoolVar,IntValBranch,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void branch(Home,const BoolVarArgs&,const TieBreakVarBranch<IntVarBranch>&,IntValBranch,const TieBreakVarBranchOptions&=TieBreakVarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void branch(Home,const BoolVarArgs&,IntVarBranch,IntValBranch,const VarBranchOptions&=VarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void branch(Home,const IntVarArgs&,const TieBreakVarBranch<IntVarBranch>&,IntValBranch,const TieBreakVarBranchOptions&=TieBreakVarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void branch(Home,const IntVarArgs&,IntVarBranch,IntValBranch,const VarBranchOptions&=VarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void branch(Home,const SetVarArgs&,const TieBreakVarBranch<SetVarBranch>&,SetValBranch,const TieBreakVarBranchOptions&=TieBreakVarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void branch(Home,const SetVarArgs&,SetVarBranch,SetValBranch,const VarBranchOptions&=VarBranchOptions::def,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void branch(Home,IntVar,IntValBranch,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void branch(Home,SetVar,SetValBranch,const ValBranchOptions&=ValBranchOptions::def);
|
||||
void cardinality(Home,SetVar,IntVar);
|
||||
void cardinality(Home,SetVar,unsigned int,unsigned int);
|
||||
void channel(Home,BoolVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void channel(Home,const BoolVarArgs&,IntVar,int=0,IntConLevel=ICL_DEF);
|
||||
void channel(Home,const BoolVarArgs&,SetVar);
|
||||
void channel(Home,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void channel(Home,const IntVarArgs&,const SetVarArgs&);
|
||||
void channel(Home,const IntVarArgs&,int,const IntVarArgs&,int,IntConLevel=ICL_DEF);
|
||||
void channel(Home,IntVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void channelSorted(Home,const IntVarArgs&,SetVar);
|
||||
void circuit(Home,const IntArgs&,const IntVarArgs&,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
|
||||
void circuit(Home,const IntArgs&,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
|
||||
void circuit(Home,const IntArgs&,int,const IntVarArgs&,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
|
||||
void circuit(Home,const IntArgs&,int,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
|
||||
void circuit(Home,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void circuit(Home,int,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void clause(Home,BoolOpType,const BoolVarArgs&,const BoolVarArgs&,BoolVar,IntConLevel=ICL_DEF);
|
||||
void clause(Home,BoolOpType,const BoolVarArgs&,const BoolVarArgs&,int,IntConLevel=ICL_DEF);
|
||||
void convex(Home,SetVar);
|
||||
void convex(Home,SetVar,SetVar);
|
||||
void count(Home,const IntVarArgs&,const IntArgs&,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,const IntArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,const IntSetArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,const IntSetArgs&,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,const IntSet&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,int,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,int,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,IntVar,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void count(Home,const IntVarArgs&,IntVar,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,int,const IntVarArgs&,const IntArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,int,const IntVarArgs&,const IntArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,int,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,int,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,int,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,int,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,IntVar,const IntVarArgs&,const IntArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,IntVar,const IntVarArgs&,const IntArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,IntVar,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,IntVar,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,IntVar,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulative(Home,IntVar,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void cumulatives(Home,const IntArgs&,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
|
||||
void cumulatives(Home,const IntArgs&,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
|
||||
void cumulatives(Home,const IntArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
|
||||
void cumulatives(Home,const IntArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
|
||||
void cumulatives(Home,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
|
||||
void cumulatives(Home,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
|
||||
void cumulatives(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
|
||||
void cumulatives(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntArgs&,bool,IntConLevel=ICL_DEF);
|
||||
void distinct(Home,const IntArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void distinct(Home,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void div(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void divmod(Home,IntVar,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void dom(Home,const IntVarArgs&,const IntSet&,IntConLevel=ICL_DEF);
|
||||
void dom(Home,const IntVarArgs&,int,IntConLevel=ICL_DEF);
|
||||
void dom(Home,const IntVarArgs&,int,int,IntConLevel=ICL_DEF);
|
||||
void dom(Home,IntVar,const IntSet&,BoolVar,IntConLevel=ICL_DEF);
|
||||
void dom(Home,IntVar,const IntSet&,IntConLevel=ICL_DEF);
|
||||
void dom(Home,IntVar,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void dom(Home,IntVar,int,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void dom(Home,IntVar,int,IntConLevel=ICL_DEF);
|
||||
void dom(Home,IntVar,int,int,IntConLevel=ICL_DEF);
|
||||
void dom(Home,SetVar,SetRelType,const IntSet&);
|
||||
void dom(Home,SetVar,SetRelType,const IntSet&,BoolVar);
|
||||
void dom(Home,SetVar,SetRelType,int);
|
||||
void dom(Home,SetVar,SetRelType,int,BoolVar);
|
||||
void dom(Home,SetVar,SetRelType,int,int);
|
||||
void dom(Home,SetVar,SetRelType,int,int,BoolVar);
|
||||
void element(Home,const BoolVarArgs&,IntVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void element(Home,const BoolVarArgs&,IntVar,int,IntConLevel=ICL_DEF);
|
||||
void element(Home,const BoolVarArgs&,IntVar,int,IntVar,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void element(Home,const IntSetArgs&,IntVar,int,IntVar,int,SetVar);
|
||||
void element(Home,const IntSetArgs&,IntVar,SetVar);
|
||||
void element(Home,const IntVarArgs&,IntVar,int,IntConLevel=ICL_DEF);
|
||||
void element(Home,const IntVarArgs&,IntVar,int,IntVar,int,IntVar,IntConLevel=ICL_DEF);
|
||||
void element(Home,const IntVarArgs&,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void element(Home,const SetVarArgs&,IntVar,int,IntVar,int,SetVar);
|
||||
void element(Home,const SetVarArgs&,IntVar,SetVar);
|
||||
void element(Home,IntSharedArray,IntVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void element(Home,IntSharedArray,IntVar,int,IntConLevel=ICL_DEF);
|
||||
void element(Home,IntSharedArray,IntVar,int,IntVar,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void element(Home,IntSharedArray,IntVar,int,IntVar,int,IntVar,IntConLevel=ICL_DEF);
|
||||
void element(Home,IntSharedArray,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void element(Home,SetOpType,const IntSetArgs&,SetVar,SetVar,const IntSet&=IntSet(Set::Limits::min,Set::Limits::max));
|
||||
void element(Home,SetOpType,const SetVarArgs&,SetVar,SetVar,const IntSet&=IntSet(Set::Limits::min,Set::Limits::max));
|
||||
void extensional(Home,const BoolVarArgs&,const TupleSet&,ExtensionalPropKind=EPK_DEF,IntConLevel=ICL_DEF);
|
||||
void extensional(Home,const BoolVarArgs&,DFA,IntConLevel=ICL_DEF);
|
||||
void extensional(Home,const IntVarArgs&,const TupleSet&,ExtensionalPropKind=EPK_DEF,IntConLevel=ICL_DEF);
|
||||
void extensional(Home,const IntVarArgs&,DFA,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const BoolVarArgs&,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const BoolVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const BoolVarArgs&,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const BoolVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntArgs&,const BoolVarArgs&,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntArgs&,const BoolVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntArgs&,const BoolVarArgs&,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntArgs&,const BoolVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntArgs&,const IntVarArgs&,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntArgs&,const IntVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntArgs&,const IntVarArgs&,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntArgs&,const IntVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntVarArgs&,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntVarArgs&,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void linear(Home,const IntVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void max(Home,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
|
||||
void max(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void max(Home,SetVar,IntVar);
|
||||
void max(Home,SetVar,IntVar,BoolVar);
|
||||
void min(Home,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
|
||||
void min(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void min(Home,SetVar,IntVar);
|
||||
void min(Home,SetVar,IntVar,BoolVar);
|
||||
void mod(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void mult(Home,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void nooverlap(Home,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void nooverlap(Home,const IntVarArgs&,const IntArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void nooverlap(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void nooverlap(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void notMax(Home,SetVar,IntVar);
|
||||
void notMin(Home,SetVar,IntVar);
|
||||
void path(Home,const IntArgs&,const IntVarArgs&,IntVar,IntVar,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
|
||||
void path(Home,const IntArgs&,const IntVarArgs&,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void path(Home,const IntArgs&,int,const IntVarArgs&,IntVar,IntVar,const IntVarArgs&,IntVar,IntConLevel=ICL_DEF);
|
||||
void path(Home,const IntArgs&,int,const IntVarArgs&,IntVar,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void path(Home,const IntVarArgs&,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void path(Home,int,const IntVarArgs&,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void precede(Home,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void precede(Home,const IntVarArgs&,int,int,IntConLevel=ICL_DEF);
|
||||
void precede(Home,const SetVarArgs&,const IntArgs&);
|
||||
void precede(Home,const SetVarArgs&,int,int);
|
||||
void rel(Home,BoolOpType,const BoolVarArgs&,BoolVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,BoolOpType,const BoolVarArgs&,int,IntConLevel=ICL_DEF);
|
||||
void rel(Home,BoolVar,BoolOpType,BoolVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,BoolVar,BoolOpType,BoolVar,int,IntConLevel=ICL_DEF);
|
||||
void rel(Home,BoolVar,IntRelType,BoolVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,BoolVar,IntRelType,BoolVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,BoolVar,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,BoolVar,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void rel(Home,const BoolVarArgs&,IntRelType,BoolVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,const BoolVarArgs&,IntRelType,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void rel(Home,const BoolVarArgs&,IntRelType,IntConLevel=ICL_DEF);
|
||||
void rel(Home,const BoolVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void rel(Home,const IntSet&,SetOpType,SetVar,SetRelType,const IntSet&);
|
||||
void rel(Home,const IntSet&,SetOpType,SetVar,SetRelType,SetVar);
|
||||
void rel(Home,const IntVarArgs&,IntRelType,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void rel(Home,const IntVarArgs&,IntRelType,IntConLevel=ICL_DEF);
|
||||
void rel(Home,const IntVarArgs&,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void rel(Home,const IntVarArgs&,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,IntVar,IntRelType,int,BoolVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,IntVar,IntRelType,int,IntConLevel=ICL_DEF);
|
||||
void rel(Home,IntVar,IntRelType,IntVar,BoolVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,IntVar,IntRelType,IntVar,IntConLevel=ICL_DEF);
|
||||
void rel(Home,IntVar,IntRelType,SetVar);
|
||||
void rel(Home,IntVar,SetRelType,SetVar);
|
||||
void rel(Home,IntVar,SetRelType,SetVar,BoolVar);
|
||||
void rel(Home,SetOpType,const IntVarArgs&,const IntSet&,SetVar);
|
||||
void rel(Home,SetOpType,const IntVarArgs&,SetVar);
|
||||
void rel(Home,SetOpType,const SetVarArgs&,const IntSet&,SetVar);
|
||||
void rel(Home,SetOpType,const SetVarArgs&,SetVar);
|
||||
void rel(Home,SetVar,IntRelType,IntVar);
|
||||
void rel(Home,SetVar,SetOpType,const IntSet&,SetRelType,const IntSet&);
|
||||
void rel(Home,SetVar,SetOpType,const IntSet&,SetRelType,SetVar);
|
||||
void rel(Home,SetVar,SetOpType,SetVar,SetRelType,const IntSet&);
|
||||
void rel(Home,SetVar,SetOpType,SetVar,SetRelType,SetVar);
|
||||
void rel(Home,SetVar,SetRelType,IntVar);
|
||||
void rel(Home,SetVar,SetRelType,IntVar,BoolVar);
|
||||
void rel(Home,SetVar,SetRelType,SetVar);
|
||||
void rel(Home,SetVar,SetRelType,SetVar,BoolVar);
|
||||
void sequence(Home,const BoolVarArgs&,const IntSet&,int,int,int,IntConLevel=ICL_DEF);
|
||||
void sequence(Home,const IntVarArgs&,const IntSet&,int,int,int,IntConLevel=ICL_DEF);
|
||||
void sequence(Home,const SetVarArgs&);
|
||||
void sequence(Home,const SetVarArgs&,SetVar);
|
||||
void sorted(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void sorted(Home,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void sqr(Home,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void sqrt(Home,IntVar,IntVar,IntConLevel=ICL_DEF);
|
||||
void unary(Home,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void unary(Home,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void unary(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void unary(Home,const IntVarArgs&,const IntVarArgs&,const IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void unary(Home,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,const BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void unary(Home,const TaskTypeArgs&,const IntVarArgs&,const IntArgs&,IntConLevel=ICL_DEF);
|
||||
void unshare(Home,BoolVarArgs&,IntConLevel=ICL_DEF);
|
||||
void unshare(Home,IntVarArgs&,IntConLevel=ICL_DEF);
|
||||
void weights(Home,const IntArgs&,const IntArgs&,SetVar,IntVar);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,760 @@
|
|||
%% -*- prolog -*-
|
||||
%%=============================================================================
|
||||
%% Copyright (C) 2011 by Denys Duchier
|
||||
%%
|
||||
%% This program is free software: you can redistribute it and/or modify it
|
||||
%% under the terms of the GNU Lesser General Public License as published by the
|
||||
%% Free Software Foundation, either version 3 of the License, or (at your
|
||||
%% option) any later version.
|
||||
%%
|
||||
%% This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
%% more details.
|
||||
%%
|
||||
%% You should have received a copy of the GNU Lesser General Public License
|
||||
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
%%=============================================================================
|
||||
|
||||
:- module(gecode, [(:=)/2, op(500, xfx, ':='),
|
||||
(+=)/2, op(500, xfx, '+=')]).
|
||||
|
||||
:- op(500, xfx, ':=').
|
||||
:- op(500, xfx, '+=').
|
||||
:- load_foreign_files([gecode_yap],[],gecode_init).
|
||||
|
||||
is_int(X,Y) :- integer(X), Y=X.
|
||||
is_int(X) :- integer(X).
|
||||
|
||||
is_bool_(true,true).
|
||||
is_bool_(false,false).
|
||||
is_bool(X,Y) :- nonvar(X), Y=X.
|
||||
is_bool(X) :- is_bool(X,_).
|
||||
|
||||
is_IntVar_('IntVar'(I),I) :- integer(I).
|
||||
is_BoolVar_('BoolVar'(I),I) :- integer(I).
|
||||
is_SetVar_('SetVar'(I),I) :- integer(I).
|
||||
|
||||
is_IntVar(X,I) :- nonvar(X), is_IntVar_(X,I).
|
||||
is_BoolVar(X,I) :- nonvar(X), is_BoolVar_(X,I).
|
||||
is_SetVar(X,I) :- nonvar(X), is_SetVar_(X,I).
|
||||
|
||||
is_IntVar(X) :- is_IntVar(X,_).
|
||||
is_BoolVar(X) :- is_BoolVar(X,_).
|
||||
is_SetVar(X) :- is_SetVar(X,_).
|
||||
|
||||
is_IntVarArgs_([],[]).
|
||||
is_IntVarArgs_([H|T],[H2|T2]) :- is_IntVar(H,H2), is_IntVarArgs(T,T2).
|
||||
is_IntVarArgs(X,Y) :- nonvar(X), is_IntVarArgs_(X,Y).
|
||||
is_IntVarArgs(X) :- \+ \+ is_IntVarArgs(X,_).
|
||||
|
||||
is_BoolVarArgs_([],[]).
|
||||
is_BoolVarArgs_([H|T],[H2|T2]) :- is_BoolVar(H,H2), is_BoolVarArgs(T,T2).
|
||||
is_BoolVarArgs(X,Y) :- nonvar(X), is_BoolVarArgs_(X,Y).
|
||||
is_BoolVarArgs(X) :- \+ \+ is_BoolVarArgs(X,_).
|
||||
|
||||
is_SetVarArgs_([],[]).
|
||||
is_SetVarArgs_([H|T],[H2|T2]) :- is_SetVar(H,H2), is_SetVarArgs(T,T2).
|
||||
is_SetVarArgs(X,Y) :- nonvar(X), is_SetVarArgs_(X,Y).
|
||||
is_SetVarArgs(X) :- \+ \+ is_SetVarArgs(X,_).
|
||||
|
||||
is_IntArgs_([],[]).
|
||||
is_IntArgs_([H|T],[H|T2]) :- integer(H), is_IntArgs(T,T2).
|
||||
is_IntArgs(X,Y) :- nonvar(X), is_IntArgs_(X,Y).
|
||||
is_IntArgs(X) :- \+ \+ is_IntArgs(X,_).
|
||||
|
||||
is_IntSharedArray(X) :- is_IntArgs(X).
|
||||
is_IntSharedArray(X,Y) :- is_IntArgs(X,Y).
|
||||
|
||||
is_TaskTypeArgs_([],[]).
|
||||
is_TaskTypeArgs_([H|T],[H2|T2]) :- is_TaskType(H,H2), is_TaskTypeArgs(T,T2).
|
||||
is_TaskTypeArgs(X,Y) :- nonvar(X), is_TaskTypeArgs_(X,Y).
|
||||
is_TaskTypeArgs(X) :- \+ \+ is_TaskTypeArgs(X,_).
|
||||
|
||||
is_IntSet_('IntSet'(L),L).
|
||||
is_IntSet(X,Y) :- nonvar(X), is_IntSet_(X,Y).
|
||||
is_IntSet(X) :- is_IntSet(X,_).
|
||||
|
||||
is_IntSetArgs_([],[]).
|
||||
is_IntSetArgs_([H|T],[H2|T2]) :- is_IntSet(H,H2), is_IntSetArgs(T,T2).
|
||||
is_IntSetArgs(X,Y) :- nonvar(X), is_IntSetArgs_(X,Y).
|
||||
is_IntSetArgs(X) :- \+ \+ is_IntSetArgs(X,_).
|
||||
|
||||
new_intset(X,I,J) :- intset(X,I,J).
|
||||
new_intset(X,L) :- intset(X,L).
|
||||
|
||||
intset(X, I, J) :-
|
||||
integer(I),
|
||||
integer(J),
|
||||
X='IntSet'([(I,J)]).
|
||||
intset(X, L) :-
|
||||
is_list_of_intset_specs(L,L2),
|
||||
X='IntSet'(L2).
|
||||
|
||||
is_list_of_intset_specs(X,Y) :-
|
||||
nonvar(X), is_list_of_intset_specs_(X,Y).
|
||||
is_list_of_intset_specs_([],[]).
|
||||
is_list_of_intset_specs_([H|T],[H2|T2]) :-
|
||||
is_intset_spec(H,H2),
|
||||
is_list_of_intset_specs(T,T2).
|
||||
|
||||
is_intset_spec(X,Y) :- nonvar(X), is_intset_spec_(X,Y).
|
||||
is_intset_spec_((I,J),(I,J)) :- !, integer(I), integer(J).
|
||||
is_intset_spec_(I,(I,I)) :- integer(I).
|
||||
|
||||
assert_var(X,Y) :-
|
||||
var(X) -> X=Y; throw(gecode_error(expected(var))).
|
||||
assert_is_int(X,Y) :-
|
||||
integer(X) -> X=Y ; throw(gecode_error(expected(int))).
|
||||
assert_is_Space(X,Y) :-
|
||||
is_Space(X,Y) -> true ; throw(gecode_error(expected(space))).
|
||||
assert_is_IntSet(X,Y) :-
|
||||
is_IntSet(X,Y) -> true ; throw(gecode_error(expected(intset))).
|
||||
assert_is_IntVar(X,Y) :-
|
||||
is_IntVar(X,Y) -> true ; throw(gecode_error(expected(intvar))).
|
||||
assert_is_BoolVar(X,Y) :-
|
||||
is_BoolVar(X,Y) -> true ; throw(gecode_error(expected(boolvar))).
|
||||
assert_is_SetVar(X,Y) :-
|
||||
is_SetVar(X,Y) -> true ; throw(gecode_error(expected(setvar))).
|
||||
assert_is_IntArgs(X,Y) :-
|
||||
is_IntArgs(X,Y) -> true ; throw(gecode_error(expected(intargs))).
|
||||
assert_is_IntVarArgs(X,Y) :-
|
||||
is_IntVarArgs(X,Y) -> true ; throw(gecode_error(expected(intvarargs))).
|
||||
assert_is_BoolVarArgs(X,Y) :-
|
||||
is_BoolVarArgs(X,Y) -> true ; throw(gecode_error(expected(boolvarargs))).
|
||||
assert_is_SetVarArgs(X,Y) :-
|
||||
is_SetVarArgs(X,Y) -> true ; throw(gecode_error(expected(setvarargs))).
|
||||
|
||||
assert_var(X) :- assert_var(X,_).
|
||||
assert_is_int(X) :- assert_is_int(X,_).
|
||||
assert_is_Space(X) :- assert_is_Space(X,_).
|
||||
assert_is_IntSet(X) :- assert_is_IntSet(X,_).
|
||||
assert_is_IntVar(X) :- assert_is_IntVar(X,_).
|
||||
assert_is_BoolVar(X) :- assert_is_BoolVar(X,_).
|
||||
assert_is_SetVar(X) :- assert_is_SetVar(X,_).
|
||||
assert_is_IntArgs(X) :- assert_is_IntArgs(X,_).
|
||||
assert_is_IntVarArgs(X) :- assert_is_IntVarArgs(X,_).
|
||||
assert_is_BoolVarArgs(X) :- assert_is_BoolVarArgs(X,_).
|
||||
assert_is_SetVarArgs(X) :- assert_is_SetVarArgs(X,_).
|
||||
|
||||
new_space(Space) :-
|
||||
assert_var(Space),
|
||||
gecode_new_space(Space_),
|
||||
Space='Space'(Space_).
|
||||
|
||||
is_Space_('Space'(X),X).
|
||||
is_Space(X,Y) :- nonvar(X), is_Space_(X,Y).
|
||||
is_Space(X) :- is_Space(X,_).
|
||||
|
||||
%% AUTOGENERATE ALL VARIANTS LATER!
|
||||
|
||||
new_intvars([], Space, Lo, Hi).
|
||||
new_intvars([IVar|IVars], Space, Lo, Hi) :-
|
||||
new_intvar(IVar, Space, Lo, Hi),
|
||||
new_intvars(IVars, Space, Lo, Hi).
|
||||
|
||||
new_intvars([], Space, IntSet).
|
||||
new_intvars([IVar|IVars], Space, IntSet) :-
|
||||
new_intvar(IVar, Space, IntSet),
|
||||
new_intvars(IVars, Space, IntSet).
|
||||
|
||||
new_boolvars([], Space).
|
||||
new_boolvars([BVar|BVars], Space) :-
|
||||
new_boolvar(BVar, Space),
|
||||
new_boolvars(BVars, Space).
|
||||
|
||||
new_setvars([], Space, X1, X2, X3, X4, X5, X6).
|
||||
new_setvars([SVar|SVars], Space, X1, X2, X3, X4, X5, X6) :-
|
||||
new_setvar(SVar, Space, X1, X2, X3, X4, X5, X6),
|
||||
new_setvars(SVars, Space, X1, X2, X3, X4, X5, X6).
|
||||
|
||||
new_setvars([], Space, X1, X2, X3, X4, X5).
|
||||
new_setvars([SVar|SVars], Space, X1, X2, X3, X4, X5) :-
|
||||
new_setvar(SVar, Space, X1, X2, X3, X4, X5),
|
||||
new_setvars(SVars, Space, X1, X2, X3, X4, X5).
|
||||
|
||||
new_setvars([], Space, X1, X2, X3, X4).
|
||||
new_setvars([SVar|SVars], Space, X1, X2, X3, X4) :-
|
||||
new_setvar(SVar, Space, X1, X2, X3, X4),
|
||||
new_setvars(SVars, Space, X1, X2, X3, X4).
|
||||
|
||||
new_setvars([], Space, X1, X2, X3).
|
||||
new_setvars([SVar|SVars], Space, X1, X2, X3) :-
|
||||
new_setvar(SVar, Space, X1, X2, X3),
|
||||
new_setvars(SVars, Space, X1, X2, X3).
|
||||
|
||||
new_setvars([], Space, X1, X2).
|
||||
new_setvars([SVar|SVars], Space, X1, X2) :-
|
||||
new_setvar(SVar, Space, X1, X2),
|
||||
new_setvars(SVars, Space, X1, X2).
|
||||
|
||||
%% AUTOGENERATE LATER
|
||||
|
||||
assert_integer(X) :- assert_is_int(X).
|
||||
|
||||
new_intvar(IVar, Space, Lo, Hi) :- !,
|
||||
assert_var(IVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
assert_integer(Lo),
|
||||
assert_integer(Hi),
|
||||
gecode_new_intvar_from_bounds(Idx,Space_,Lo,Hi),
|
||||
IVar='IntVar'(Idx).
|
||||
new_intvar(IVar, Space, IntSet) :- !,
|
||||
assert_var(IVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
assert_is_IntSet(IntSet, L),
|
||||
gecode_new_intvar_from_intset(Idx,Space_,L),
|
||||
IVar='IntVar'(Idx).
|
||||
|
||||
new_boolvar(BVar, Space) :- !,
|
||||
assert_var(BVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
gecode_new_boolvar(Idx,Space_),
|
||||
BVar='BoolVar'(Idx).
|
||||
|
||||
%% (GlbMin,GlbMax,LubMin,LubMax,CardMin,CardMax) 6 new_setvar_1
|
||||
%% (GlbMin,GlbMax,LubMin,LubMax,CardMin) 5 new_setvar_2
|
||||
%% (GlbMin,GlbMax,LubMin,LubMax) 4 new_setvar_3
|
||||
%% (Glb,LubMin,LubMax,CardMin,CardMax) 5 new_setvar_4
|
||||
%% (Glb,LubMin,LubMax,CardMin) 4 new_setvar_5
|
||||
%% (Glb,LubMin,LubMax) 3 new_setvar_6
|
||||
%% (GlbMin,GlbMax,Lub,CardMin,CardMax) 5 new_setvar_7
|
||||
%% (GlbMin,GlbMax,Lub,CardMin) 4 new_setvar_8
|
||||
%% (GlbMin,GlbMax,Lub) 3 new_setvar_9
|
||||
%% (Glb,Lub,CardMin,CardMax) 4 new_setvar_10
|
||||
%% (Glb,Lub,CardMin) 3 new_setvar_11
|
||||
%% (Glb,Lub) 2 new_setvar_12
|
||||
|
||||
%% 6 arguments
|
||||
%% (GlbMin,GlbMax,LubMin,LubMax,CardMin,CardMax) 6 new_setvar_1
|
||||
new_setvar(SVar, Space, GlbMin, GlbMax, LubMin, LubMax, CardMin, CardMax) :-
|
||||
assert_var(SVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
assert_integer(GlbMin),
|
||||
assert_integer(GlbMax),
|
||||
assert_integer(LubMin),
|
||||
assert_integer(LubMax),
|
||||
assert_integer(CardMin),
|
||||
assert_integer(CardMax),
|
||||
gecode_new_setvar(Idx, Space_, GlbMin, GlbMax, LubMib, LubMax, CardMin, CardMax),
|
||||
SVar='SetVar'(Idx).
|
||||
|
||||
%% 5 arguments
|
||||
%% (GlbMin,GlbMax,LubMin,LubMax,CardMin) 5 new_setvar_2
|
||||
%% (Glb,LubMin,LubMax,CardMin,CardMax) 5 new_setvar_4
|
||||
%% (GlbMin,GlbMax,Lub,CardMin,CardMax) 5 new_setvar_7
|
||||
new_setvar(SVar, Space, X1, X2, X3, X4, X5) :-
|
||||
assert_var(SVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
(integer(X1)
|
||||
->
|
||||
assert_integer(X2),
|
||||
assert_integer(X4),
|
||||
assert_integer(X5),
|
||||
(is_IntSet(X3,X3_)
|
||||
-> gecode_new_setvar_7(Idx,Space_,X1,X2,X3_,X4,X5)
|
||||
; gecode_new_setvar_2(Idx,Space_,X1,X2,X3,X4,X5))
|
||||
;
|
||||
assert_is_IntSet(X1,X1_),
|
||||
assert_integer(X2),
|
||||
assert_integer(X3),
|
||||
assert_integer(X4),
|
||||
assert_integer(X5),
|
||||
gecode_new_setvar_4(Idx,Space_,X1_,X2,X3,X4,X5)),
|
||||
SVar='SetVar'(Idx).
|
||||
|
||||
%% 4 arguments
|
||||
%% (GlbMin,GlbMax,LubMin,LubMax) 4 new_setvar_3
|
||||
%% (Glb,LubMin,LubMax,CardMin) 4 new_setvar_5
|
||||
%% (GlbMin,GlbMax,Lub,CardMin) 4 new_setvar_8
|
||||
%% (Glb,Lub,CardMin,CardMax) 4 new_setvar_10
|
||||
new_setvar(SVar,Space,X1,X2,X3,X4) :-
|
||||
assert_var(SVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
assert_integer(X4),
|
||||
(is_IntSet(X1,X1_)
|
||||
-> (is_IntSet(X2,X2_)
|
||||
->
|
||||
assert_integer(X3),
|
||||
gecode_new_setvar_10(Idx,Space_,X1_,X2_,X3,X4)
|
||||
;
|
||||
assert_integer(X2),
|
||||
assert_integer(X3),
|
||||
gecode_new_setvar_5(Idx,Space_,X1_,X2,X3,X4))
|
||||
;
|
||||
assert_integer(X1),
|
||||
assert_integer(X2),
|
||||
(is_IntSet(X3,X3_)
|
||||
->
|
||||
gecode_new_setvar_8(Idx,Space_,X1,X2,X3_,X4)
|
||||
;
|
||||
assert_integer(X3),
|
||||
gecode_new_setvar_3(Idx,Space_,X1,X2,X3,X4))),
|
||||
SVar='SetVar'(Idx).
|
||||
|
||||
%% 3 arguments
|
||||
%% (Glb,LubMin,LubMax) 3 new_setvar_6
|
||||
%% (GlbMin,GlbMax,Lub) 3 new_setvar_9
|
||||
%% (Glb,Lub,CardMin) 3 new_setvar_11
|
||||
new_setvar(SVar,Space,X1,X2,X3) :-
|
||||
assert_var(SVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
(is_IntSet(X1,X1_)
|
||||
-> (is_IntSet(X2,X2_)
|
||||
->
|
||||
assert_integer(X3),
|
||||
gecode_new_setvar_11(Idx,Space_,X1_,X2_,X3)
|
||||
;
|
||||
assert_integer(X2),
|
||||
assert_integer(X3),
|
||||
gecode_new_setvar_6(Idx,Space_,X1_,X2,X3))
|
||||
;
|
||||
assert_integer(X1),
|
||||
assert_integer(X2),
|
||||
assert_is_IntSet(X3,X3_),
|
||||
gecode_new_setvar_9(Idx,Space_,X1,X2,X3_)),
|
||||
SVar='SetVar'(Idx).
|
||||
|
||||
%% 2 arguments
|
||||
%% (Glb,Lub) 2 new_setvar_12
|
||||
new_setvar(SVar,Space,X1,X2) :-
|
||||
assert_var(SVar),
|
||||
assert_is_Space_or_Clause(Space,Space_),
|
||||
assert_is_IntSet(X1,X1_),
|
||||
assert_is_IntSet(X2,X2_),
|
||||
gecode_new_setvar_12(Idx,Space_,X1_,X2_),
|
||||
SVar='SetVar'(Idx).
|
||||
|
||||
minimize(Space,IVar) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
assert_is_IntVar(IVar,IVar_),
|
||||
gecode_space_minimize(Space_,IVar_).
|
||||
maximize(Space,IVar) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
assert_is_IntVar(IVar,IVar_),
|
||||
gecode_space_maximize(Space_,IVar_).
|
||||
minimize(Space,IVar1,IVar2) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
assert_is_IntVar(IVar1,IVar1_),
|
||||
assert_is_IntVar(IVar2,IVar2_),
|
||||
gecode_space_minimize_ratio(Space_,IVar1_,IVar2_).
|
||||
maximize(Space,IVar1,IVar2) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
assert_is_IntVar(IVar1,IVar1_),
|
||||
assert_is_IntVar(IVar2,IVar2_),
|
||||
gecode_space_maximize_ratio(Space_,IVar1_,IVar2_).
|
||||
|
||||
search(Space, Solution) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
assert_var(Solution),
|
||||
gecode_new_engine(Space_,Engine_),
|
||||
gecode_engine_search(Engine_,Solution_),
|
||||
Solution='Space'(Solution_).
|
||||
|
||||
%% INSPECTING VARIABLES
|
||||
|
||||
get_for_vars([],Space,[],F).
|
||||
get_for_vars([V|Vs],Space,[V2|V2s],F) :-
|
||||
call_with_args(F,V,Space,V2),
|
||||
get_for_vars(Vs,Space,V2s,F).
|
||||
|
||||
get_assigned(Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_assigned(Space_,Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_assigned(Space_,Var_)
|
||||
; is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_assigned(Space_,Var_)
|
||||
; throw(gecode_error(expected(variable))).
|
||||
|
||||
get_min(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_min(X, Space_, Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_min(X, Space_, Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_min).
|
||||
|
||||
get_max(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_max(X, Space_, Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_max(X, Space_, Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_max).
|
||||
|
||||
get_med(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_med(X, Space_, Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_med(X, Space_, Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_med).
|
||||
|
||||
get_val(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_val(X, Space_, Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_val(X, Space_, Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_val).
|
||||
|
||||
get_size(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_size(X, Space_, Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_size(X, Space_, Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_size).
|
||||
|
||||
get_width(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_width(X, Space_, Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_width(X, Space_, Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_width).
|
||||
|
||||
get_regret_min(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_regret_min(X, Space_, Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_regret_min(X, Space_, Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_regret_min).
|
||||
|
||||
get_regret_max(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_regret_max(X, Space_, Var_)
|
||||
; is_BoolVar(Var,Var_)
|
||||
-> gecode_boolvar_regret_max(X, Space_, Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_regret_max).
|
||||
|
||||
get_glbSize(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_glbSize(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_glbSize).
|
||||
|
||||
get_lubSize(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_lubSize(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_lubSize).
|
||||
|
||||
get_unknownSize(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_unknownSize(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_unknownSize).
|
||||
|
||||
get_cardMin(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_cardMin(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_cardMin).
|
||||
|
||||
get_cardMax(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_cardMax(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_cardMax).
|
||||
|
||||
get_lubMin(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_lubMin(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_lubMin).
|
||||
|
||||
get_lubMax(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_lubMax(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_lubMax).
|
||||
|
||||
get_glbMin(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_glbMin(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_glbMin).
|
||||
|
||||
get_glbMax(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_glbMax(X,Space_,Var_)
|
||||
; get_for_vars(X, Space, Var, gecode:get_glbMax).
|
||||
|
||||
get_glb_ranges(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_glb_ranges(X,Space_,Var_)
|
||||
; get_for_vars(X,Space,Var,gecode:get_glb_ranges).
|
||||
|
||||
get_lub_ranges(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_lub_ranges(X,Space_,Var_)
|
||||
; get_for_vars(X,Space,Var,gecode:get_lub_ranges).
|
||||
|
||||
get_unknown_ranges(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_unknown_ranges(X,Space_,Var_)
|
||||
; get_for_vars(X,Space,Var,gecode:get_unknown_ranges).
|
||||
|
||||
get_glb_values(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_glb_values(X,Space_,Var_)
|
||||
; get_for_vars(X,Space,Var,gecode:get_glb_values).
|
||||
|
||||
get_lub_values(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_lub_values(X,Space_,Var_)
|
||||
; get_for_vars(X,Space,Var,gecode:get_lub_values).
|
||||
|
||||
get_unknown_values(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_SetVar(Var,Var_)
|
||||
-> gecode_setvar_unknown_values(X,Space_,Var_)
|
||||
; get_for_vars(X,Space,Var,gecode:get_unknown_values).
|
||||
|
||||
get_ranges(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_ranges(X,Space_,Var_)
|
||||
; get_for_vars(X,Space,Var,gecode:get_ranges).
|
||||
|
||||
get_values(X, Space, Var) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
is_IntVar(Var,Var_)
|
||||
-> gecode_intvar_values(X,Space_,Var_)
|
||||
; get_for_vars(X,Space,Var,gecode:get_values).
|
||||
|
||||
new_disjunctor(X, Space) :-
|
||||
assert_is_Space(Space,Space_),
|
||||
gecode_new_disjunctor(D,Space_),
|
||||
X='Disjunctor'(D).
|
||||
|
||||
is_Disjunctor_('Disjunctor'(D),D).
|
||||
is_Disjunctor(X,Y) :- nonvar(X), is_Disjunctor_(X,Y).
|
||||
is_Disjunctor(X) :- is_Disjunctor(X,_).
|
||||
|
||||
assert_is_Disjunctor(X,Y) :-
|
||||
is_Disjunctor(X,Y) -> true ; throw(gecode_error(expected(disjunctor))).
|
||||
|
||||
new_clause(X, Disj) :-
|
||||
assert_is_Disjunctor(Disj,Disj_),
|
||||
gecode_new_clause(C, Disj_),
|
||||
X='Clause'(C).
|
||||
|
||||
is_Clause_('Clause'(C),C).
|
||||
is_Clause(X,Y) :- nonvar(X), is_Clause_(X,Y).
|
||||
is_Clause(X) :- is_Clause(X,_).
|
||||
|
||||
assert_is_Clause(X,Y) :-
|
||||
is_Clause(X,Y) -> true ; throw(gecode_error(expected(clause))).
|
||||
|
||||
is_Space_or_Clause(X,Y) :-
|
||||
(is_Space(X,Y);is_Clause(X,Y)), !.
|
||||
assert_is_Space_or_Clause(X,Y) :-
|
||||
is_Space_or_Clause(X,Y) -> true
|
||||
; throw(gecode_error(expected(space,clause))).
|
||||
|
||||
new_forward(Clause, X, Y) :-
|
||||
assert_is_Clause(Clause, Clause_),
|
||||
(is_IntVar(X,X_)
|
||||
-> (is_IntVar(Y,Y_)
|
||||
-> gecode_clause_intvar_forward(Clause_,X_,Y_)
|
||||
; throw(gecode_error(forward)))
|
||||
; (is_BoolVar(X,X_)
|
||||
-> (is_BoolVar(Y,Y_)
|
||||
-> gecode_clause_boolvar_forward(Clause_,X_,Y_)
|
||||
; throw(gecode_error(forward)))
|
||||
; (is_SetVar(X,X_)
|
||||
-> (is_SetVar(Y,Y_)
|
||||
-> gecode_clause_setvar_forward(Clause_,X_,Y_)
|
||||
; throw(gecode_error(forward)))
|
||||
; (X=[]
|
||||
-> Y=[]
|
||||
;(X=[H1|T1],Y=[H2|T2])
|
||||
-> (new_forward(Clause,H1,H2),
|
||||
new_forward(Clause,T1,T2))
|
||||
; throw(gecode_error(forward)))))).
|
||||
|
||||
new_intvars_(L,Space,N,I,J) :- length(L,N), new_intvars(L,Space,I,J).
|
||||
new_intvars_(L,Space,N,IntSet) :- length(L,N), new_intvars(L,Space,IntSet).
|
||||
new_boolvars_(L,Space,N) :- length(L,N), new_boolvars(L,Space).
|
||||
new_setvars_(L,Space,N,X1,X2,X3,X4,X5,X6) :- length(L,N), new_setvars(L,Space,X1,X2,X3,X4,X5,X6).
|
||||
new_setvars_(L,Space,N,X1,X2,X3,X4,X5) :- length(L,N), new_setvars(L,Space,X1,X2,X3,X4,X5).
|
||||
new_setvars_(L,Space,N,X1,X2,X3,X4) :- length(L,N), new_setvars(L,Space,X1,X2,X3,X4).
|
||||
new_setvars_(L,Space,N,X1,X2,X3) :- length(L,N), new_setvars(L,Space,X1,X2,X3).
|
||||
new_setvars_(L,Space,N,X1,X2) :- length(L,N), new_setvars(L,Space,X1,X2).
|
||||
|
||||
%% more concise interface:
|
||||
(X := Y) :- var(Y), !, throw(gecode_error((X := Y))).
|
||||
(X := intset(I,J)) :- !, new_intset(X,I,J).
|
||||
(X := intset(L)) :- !, new_intset(X,L).
|
||||
(X := space) :- !, new_space(X).
|
||||
(X := intvar(Space,I,J)) :- !, new_intvar(X,Space,I,J).
|
||||
(X := intvar(Space,IntSet)) :- !, new_intvar(X,Space,IntSet).
|
||||
(X := boolvar(Space)) :- !, new_boolvar(X,Space).
|
||||
(X := setvar(Space,X1,X2,X3,X4,X5,X6)) :- !, new_setvar(X,Space,X1,X2,X3,X4,X5,X6).
|
||||
(X := setvar(Space,X1,X2,X3,X4,X5)) :- !, new_setvar(X,Space,X1,X2,X3,X4,X5).
|
||||
(X := setvar(Space,X1,X2,X3,X4)) :- !, new_setvar(X,Space,X1,X2,X3,X4).
|
||||
(X := setvar(Space,X1,X2,X3)) :- !, new_setvar(X,Space,X1,X2,X3).
|
||||
(X := setvar(Space,X1,X2)) :- !, new_setvar(X,Space,X1,X2).
|
||||
(X := intvars(Space,N,I,J)) :- !, new_intvars_(X,Space,N,I,J).
|
||||
(X := intvars(Space,N,IntSet)) :- !, new_intvars_(X,Space,N,IntSet).
|
||||
(X := boolvars(Space,N)) :- !, new_boolvars_(X,Space,N).
|
||||
(X := setvars(Space,N,X1,X2,X3,X4,X5,X6)) :- !, new_setvars_(X,Space,N,X1,X2,X3,X4,X5,X6).
|
||||
(X := setvars(Space,N,X1,X2,X3,X4,X5)) :- !, new_setvars_(X,Space,N,X1,X2,X3,X4,X5).
|
||||
(X := setvars(Space,N,X1,X2,X3,X4)) :- !, new_setvars_(X,Space,N,X1,X2,X3,X4).
|
||||
(X := setvars(Space,N,X1,X2,X3)) :- !, new_setvars_(X,Space,N,X1,X2,X3).
|
||||
(X := setvars(Space,N,X1,X2)) :- !, new_setvars_(X,Space,N,X1,X2).
|
||||
|
||||
(X := min(Space,Var)) :- !, get_min(X,Space,Var).
|
||||
(X := max(Space,Var)) :- !, get_max(X,Space,Var).
|
||||
(X := med(Space,Var)) :- !, get_med(X,Space,Var).
|
||||
(X := val(Space,Var)) :- !, get_val(X,Space,Var).
|
||||
(X := size(Space,Var)) :- !, get_size(X,Space,Var).
|
||||
(X := width(Space,Var)) :- !, get_width(X,Space,Var).
|
||||
(X := regret_min(Space,Var)) :- !, get_regret_min(X,Space,Var).
|
||||
(X := regret_max(Space,Var)) :- !, get_regret_max(X,Space,Var).
|
||||
(X := ranges(Space,Var)) :- !, get_ranges(X,Space,Var).
|
||||
(X := values(Space,Var)) :- !, get_values(X,Space,Var).
|
||||
|
||||
(X := glbSize(Space,Var)) :- !, get_glbSize(X,Space,Var).
|
||||
(X := lubSize(Space,Var)) :- !, get_lubSize(X,Space,Var).
|
||||
(X := unknownSize(Space,Var)) :- !, get_unknownSize(X,Space,Var).
|
||||
(X := cardMin(Space,Var)) :- !, get_cardMin(X,Space,Var).
|
||||
(X := cardMax(Space,Var)) :- !, get_cardMax(X,Space,Var).
|
||||
(X := lubMin(Space,Var)) :- !, get_lubMin(X,Space,Var).
|
||||
(X := lubMax(Space,Var)) :- !, get_lubMax(X,Space,Var).
|
||||
(X := glbMin(Space,Var)) :- !, get_glbMin(X,Space,Var).
|
||||
(X := glbMax(Space,Var)) :- !, get_glbMax(X,Space,Var).
|
||||
(X := glb_ranges(Space,Var)) :- !, get_glb_ranges(X,Space,Var).
|
||||
(X := lub_ranges(Space,Var)) :- !, get_lub_ranges(X,Space,Var).
|
||||
(X := unknown_ranges(Space,Var)) :- !, get_unknown_ranges(X,Space,Var).
|
||||
(X := glb_values(Space,Var)) :- !, get_glb_values(X,Space,Var).
|
||||
(X := lub_values(Space,Var)) :- !, get_lub_values(X,Space,Var).
|
||||
(X := unknown_values(Space,Var)) :- !, get_unknown_values(X,Space,Var).
|
||||
|
||||
(X := disjunctor(Space)) :- !, new_disjunctor(X,Space).
|
||||
(X := clause(Disj)) :- !, new_clause(X,Disj).
|
||||
|
||||
(X := search(Y)) :- !, search(Y,X).
|
||||
|
||||
% these should be autogenerated:
|
||||
(C += forward(X,Y)) :- !, new_forward(C,X,Y).
|
||||
(Space += abs(X1,X2)) :- !, abs(Space,X1,X2).
|
||||
(Space += abs(X1,X2,X3)) :- !, abs(Space,X1,X2,X3).
|
||||
(Space += assign(X1,X2)) :- !, assign(Space,X1,X2).
|
||||
(Space += atmostOne(X1,X2)) :- !, atmostOne(Space,X1,X2).
|
||||
(Space += binpacking(X1,X2,X3)) :- !, binpacking(Space,X1,X2,X3).
|
||||
(Space += binpacking(X1,X2,X3,X4)) :- !, binpacking(Space,X1,X2,X3,X4).
|
||||
(Space += branch(X1,X2)) :- !, branch(Space,X1,X2).
|
||||
(Space += branch(X1,X2,X3)) :- !, branch(Space,X1,X2,X3).
|
||||
(Space += cardinality(X1,X2)) :- !, cardinality(Space,X1,X2).
|
||||
(Space += cardinality(X1,X2,X3)) :- !, cardinality(Space,X1,X2,X3).
|
||||
(Space += channel(X1,X2)) :- !, channel(Space,X1,X2).
|
||||
(Space += channel(X1,X2,X3)) :- !, channel(Space,X1,X2,X3).
|
||||
(Space += channel(X1,X2,X3,X4)) :- !, channel(Space,X1,X2,X3,X4).
|
||||
(Space += channel(X1,X2,X3,X4,X5)) :- !, channel(Space,X1,X2,X3,X4,X5).
|
||||
(Space += channelSorted(X1,X2)) :- !, channelSorted(Space,X1,X2).
|
||||
(Space += circuit(X1)) :- !, circuit(Space,X1).
|
||||
(Space += circuit(X1,X2)) :- !, circuit(Space,X1,X2).
|
||||
(Space += circuit(X1,X2,X3)) :- !, circuit(Space,X1,X2,X3).
|
||||
(Space += circuit(X1,X2,X3,X4)) :- !, circuit(Space,X1,X2,X3,X4).
|
||||
(Space += circuit(X1,X2,X3,X4,X5)) :- !, circuit(Space,X1,X2,X3,X4,X5).
|
||||
(Space += circuit(X1,X2,X3,X4,X5,X6)) :- !, circuit(Space,X1,X2,X3,X4,X5,X6).
|
||||
(Space += clause(X1,X2,X3,X4)) :- !, clause(Space,X1,X2,X3,X4).
|
||||
(Space += clause(X1,X2,X3,X4,X5)) :- !, clause(Space,X1,X2,X3,X4,X5).
|
||||
(Space += convex(X1)) :- !, convex(Space,X1).
|
||||
(Space += convex(X1,X2)) :- !, convex(Space,X1,X2).
|
||||
(Space += count(X1,X2)) :- !, count(Space,X1,X2).
|
||||
(Space += count(X1,X2,X3)) :- !, count(Space,X1,X2,X3).
|
||||
(Space += count(X1,X2,X3,X4)) :- !, count(Space,X1,X2,X3,X4).
|
||||
(Space += count(X1,X2,X3,X4,X5)) :- !, count(Space,X1,X2,X3,X4,X5).
|
||||
(Space += cumulative(X1,X2,X3,X4)) :- !, cumulative(Space,X1,X2,X3,X4).
|
||||
(Space += cumulative(X1,X2,X3,X4,X5)) :- !, cumulative(Space,X1,X2,X3,X4,X5).
|
||||
(Space += cumulative(X1,X2,X3,X4,X5,X6)) :- !, cumulative(Space,X1,X2,X3,X4,X5,X6).
|
||||
(Space += cumulative(X1,X2,X3,X4,X5,X6,X7)) :- !, cumulative(Space,X1,X2,X3,X4,X5,X6,X7).
|
||||
(Space += cumulatives(X1,X2,X3,X4,X5,X6,X7)) :- !, cumulatives(Space,X1,X2,X3,X4,X5,X6,X7).
|
||||
(Space += cumulatives(X1,X2,X3,X4,X5,X6,X7,X8)) :- !, cumulatives(Space,X1,X2,X3,X4,X5,X6,X7,X8).
|
||||
(Space += distinct(X1)) :- !, distinct(Space,X1).
|
||||
(Space += distinct(X1,X2)) :- !, distinct(Space,X1,X2).
|
||||
(Space += distinct(X1,X2,X3)) :- !, distinct(Space,X1,X2,X3).
|
||||
(Space += div(X1,X2,X3)) :- !, div(Space,X1,X2,X3).
|
||||
(Space += div(X1,X2,X3,X4)) :- !, div(Space,X1,X2,X3,X4).
|
||||
(Space += divmod(X1,X2,X3,X4)) :- !, divmod(Space,X1,X2,X3,X4).
|
||||
(Space += divmod(X1,X2,X3,X4,X5)) :- !, divmod(Space,X1,X2,X3,X4,X5).
|
||||
(Space += dom(X1,X2)) :- !, dom(Space,X1,X2).
|
||||
(Space += dom(X1,X2,X3)) :- !, dom(Space,X1,X2,X3).
|
||||
(Space += dom(X1,X2,X3,X4)) :- !, dom(Space,X1,X2,X3,X4).
|
||||
(Space += dom(X1,X2,X3,X4,X5)) :- !, dom(Space,X1,X2,X3,X4,X5).
|
||||
(Space += element(X1,X2,X3)) :- !, element(Space,X1,X2,X3).
|
||||
(Space += element(X1,X2,X3,X4)) :- !, element(Space,X1,X2,X3,X4).
|
||||
(Space += element(X1,X2,X3,X4,X5)) :- !, element(Space,X1,X2,X3,X4,X5).
|
||||
(Space += element(X1,X2,X3,X4,X5,X6)) :- !, element(Space,X1,X2,X3,X4,X5,X6).
|
||||
(Space += element(X1,X2,X3,X4,X5,X6,X7)) :- !, element(Space,X1,X2,X3,X4,X5,X6,X7).
|
||||
(Space += linear(X1,X2,X3)) :- !, linear(Space,X1,X2,X3).
|
||||
(Space += linear(X1,X2,X3,X4)) :- !, linear(Space,X1,X2,X3,X4).
|
||||
(Space += linear(X1,X2,X3,X4,X5)) :- !, linear(Space,X1,X2,X3,X4,X5).
|
||||
(Space += linear(X1,X2,X3,X4,X5,X6)) :- !, linear(Space,X1,X2,X3,X4,X5,X6).
|
||||
(Space += max(X1,X2)) :- !, max(Space,X1,X2).
|
||||
(Space += max(X1,X2,X3)) :- !, max(Space,X1,X2,X3).
|
||||
(Space += max(X1,X2,X3,X4)) :- !, max(Space,X1,X2,X3,X4).
|
||||
(Space += min(X1,X2)) :- !, min(Space,X1,X2).
|
||||
(Space += min(X1,X2,X3)) :- !, min(Space,X1,X2,X3).
|
||||
(Space += min(X1,X2,X3,X4)) :- !, min(Space,X1,X2,X3,X4).
|
||||
(Space += mod(X1,X2,X3)) :- !, mod(Space,X1,X2,X3).
|
||||
(Space += mod(X1,X2,X3,X4)) :- !, mod(Space,X1,X2,X3,X4).
|
||||
(Space += mult(X1,X2,X3)) :- !, mult(Space,X1,X2,X3).
|
||||
(Space += mult(X1,X2,X3,X4)) :- !, mult(Space,X1,X2,X3,X4).
|
||||
(Space += nooverlap(X1,X2,X3,X4)) :- !, nooverlap(Space,X1,X2,X3,X4).
|
||||
(Space += nooverlap(X1,X2,X3,X4,X5)) :- !, nooverlap(Space,X1,X2,X3,X4,X5).
|
||||
(Space += nooverlap(X1,X2,X3,X4,X5,X6)) :- !, nooverlap(Space,X1,X2,X3,X4,X5,X6).
|
||||
(Space += nooverlap(X1,X2,X3,X4,X5,X6,X7)) :- !, nooverlap(Space,X1,X2,X3,X4,X5,X6,X7).
|
||||
(Space += nooverlap(X1,X2,X3,X4,X5,X6,X7,X8)) :- !, nooverlap(Space,X1,X2,X3,X4,X5,X6,X7,X8).
|
||||
(Space += notMax(X1,X2)) :- !, notMax(Space,X1,X2).
|
||||
(Space += notMin(X1,X2)) :- !, notMin(Space,X1,X2).
|
||||
(Space += path(X1,X2,X3)) :- !, path(Space,X1,X2,X3).
|
||||
(Space += path(X1,X2,X3,X4)) :- !, path(Space,X1,X2,X3,X4).
|
||||
(Space += path(X1,X2,X3,X4,X5)) :- !, path(Space,X1,X2,X3,X4,X5).
|
||||
(Space += path(X1,X2,X3,X4,X5,X6)) :- !, path(Space,X1,X2,X3,X4,X5,X6).
|
||||
(Space += path(X1,X2,X3,X4,X5,X6,X7)) :- !, path(Space,X1,X2,X3,X4,X5,X6,X7).
|
||||
(Space += path(X1,X2,X3,X4,X5,X6,X7,X8)) :- !, path(Space,X1,X2,X3,X4,X5,X6,X7,X8).
|
||||
(Space += precede(X1,X2)) :- !, precede(Space,X1,X2).
|
||||
(Space += precede(X1,X2,X3)) :- !, precede(Space,X1,X2,X3).
|
||||
(Space += precede(X1,X2,X3,X4)) :- !, precede(Space,X1,X2,X3,X4).
|
||||
(Space += rel(X1,X2)) :- !, rel(Space,X1,X2).
|
||||
(Space += rel(X1,X2,X3)) :- !, rel(Space,X1,X2,X3).
|
||||
(Space += rel(X1,X2,X3,X4)) :- !, rel(Space,X1,X2,X3,X4).
|
||||
(Space += rel(X1,X2,X3,X4,X5)) :- !, rel(Space,X1,X2,X3,X4,X5).
|
||||
(Space += sequence(X1)) :- !, sequence(Space,X1).
|
||||
(Space += sequence(X1,X2)) :- !, sequence(Space,X1,X2).
|
||||
(Space += sequence(X1,X2,X3,X4,X5)) :- !, sequence(Space,X1,X2,X3,X4,X5).
|
||||
(Space += sequence(X1,X2,X3,X4,X5,X6)) :- !, sequence(Space,X1,X2,X3,X4,X5,X6).
|
||||
(Space += sorted(X1,X2)) :- !, sorted(Space,X1,X2).
|
||||
(Space += sorted(X1,X2,X3)) :- !, sorted(Space,X1,X2,X3).
|
||||
(Space += sorted(X1,X2,X3,X4)) :- !, sorted(Space,X1,X2,X3,X4).
|
||||
(Space += sqr(X0,X1,X2,X3)) :- !, sqr(Space,X0,X1,X2,X3).
|
||||
(Space += sqr(X1,X2)) :- !, sqr(Space,X1,X2).
|
||||
(Space += sqrt(X1,X2)) :- !, sqrt(Space,X1,X2).
|
||||
(Space += sqrt(X1,X2,X3)) :- !, sqrt(Space,X1,X2,X3).
|
||||
(Space += unary(X1,X2)) :- !, unary(Space,X1,X2).
|
||||
(Space += unary(X1,X2,X3)) :- !, unary(Space,X1,X2,X3).
|
||||
(Space += unary(X1,X2,X3,X4)) :- !, unary(Space,X1,X2,X3,X4).
|
||||
(Space += unary(X1,X2,X3,X4,X5)) :- !, unary(Space,X1,X2,X3,X4,X5).
|
||||
(Space += unshare(X1)) :- !, unshare(Space,X1).
|
||||
(Space += unshare(X1,X2)) :- !, unshare(Space,X1,X2).
|
||||
(Space += weights(X1,X2,X3,X4)) :- !; weights(Space,X1,X2,X3,X4).
|
||||
|
||||
(Space += minimize(X)) :- !, minimize(Space,X).
|
||||
(Space += maximize(X)) :- !, maximize(Space,X).
|
||||
(Space += minimize(X,Y)) :- !, minimize(Space,X,Y).
|
||||
(Space += maximize(X,Y)) :- !, maximize(Space,X,Y).
|
|
@ -0,0 +1,41 @@
|
|||
%% -*- prolog -*-
|
||||
%%=============================================================================
|
||||
%% Copyright (C) 2011 by Denys Duchier
|
||||
%%
|
||||
%% This program is free software: you can redistribute it and/or modify it
|
||||
%% under the terms of the GNU Lesser General Public License as published by the
|
||||
%% Free Software Foundation, either version 3 of the License, or (at your
|
||||
%% option) any later version.
|
||||
%%
|
||||
%% This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
%% more details.
|
||||
%%
|
||||
%% You should have received a copy of the GNU Lesser General Public License
|
||||
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
%%=============================================================================
|
||||
|
||||
:- use_module(gecode).
|
||||
|
||||
% S E N D
|
||||
% + M O R E
|
||||
% ---------
|
||||
% M O N E Y
|
||||
send_more_money(Solution) :-
|
||||
Space := space,
|
||||
Letters := intvars(Space,8,0,9),
|
||||
[S,E,N,D,M,O,R,Y] = Letters,
|
||||
Space += rel(M,'IRT_NQ',0),
|
||||
Space += rel(S,'IRT_NQ',0),
|
||||
Space += distinct(Letters),
|
||||
C = [1000, 100, 10, 1,
|
||||
1000, 100, 10, 1,
|
||||
-10000, -1000, -100, -10, -1],
|
||||
X = [S,E,N,D,
|
||||
M,O,R,E,
|
||||
M,O,N,E,Y],
|
||||
Space += linear(C, X, 'IRT_EQ', 0),
|
||||
Space += branch(Letters, 'INT_VAR_SIZE_MIN', 'INT_VAL_MIN'),
|
||||
SolSpace := search(Space),
|
||||
Solution := val(SolSpace,Letters).
|
|
@ -0,0 +1,45 @@
|
|||
%% -*- prolog -*-
|
||||
%%=============================================================================
|
||||
%% Copyright (C) 2011 by Denys Duchier
|
||||
%%
|
||||
%% This program is free software: you can redistribute it and/or modify it
|
||||
%% under the terms of the GNU Lesser General Public License as published by the
|
||||
%% Free Software Foundation, either version 3 of the License, or (at your
|
||||
%% option) any later version.
|
||||
%%
|
||||
%% This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
%% more details.
|
||||
%%
|
||||
%% You should have received a copy of the GNU Lesser General Public License
|
||||
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
%%=============================================================================
|
||||
|
||||
:- use_module(gecode).
|
||||
|
||||
% S E N D
|
||||
% + M O S T
|
||||
% ---------
|
||||
% M O N E Y
|
||||
send_most_money(Solution,Amount) :-
|
||||
Space := space,
|
||||
Letters := intvars(Space,8,0,9),
|
||||
[S,E,N,D,M,O,T,Y] = Letters,
|
||||
Space += rel(M,'IRT_NQ',0),
|
||||
Space += rel(S,'IRT_NQ',0),
|
||||
Space += distinct(Letters),
|
||||
C = [1000, 100, 10, 1,
|
||||
1000, 100, 10, 1,
|
||||
-10000, -1000, -100, -10, -1],
|
||||
X = [S,E,N,D,
|
||||
M,O,S,T,
|
||||
M,O,N,E,Y],
|
||||
Space += linear(C, X, 'IRT_EQ', 0),
|
||||
Money := intvar(Space,0,99999),
|
||||
Space += linear([10000,1000,100,10,1],[M,O,N,E,Y],'IRT_EQ',Money),
|
||||
Space += maximize(Money),
|
||||
Space += branch(Letters,'INT_VAR_SIZE_MIN','INT_VAL_MIN'),
|
||||
SolSpace := search(Space),
|
||||
Solution := val(SolSpace,Letters),
|
||||
Amount := val(SolSpace,Money).
|
13
misc/LOCALS
13
misc/LOCALS
|
@ -206,7 +206,7 @@ Int total_atom_table_overflow_time =0
|
|||
|
||||
//load_dyld
|
||||
#ifdef LOAD_DYLD
|
||||
static dl_errno =0
|
||||
int dl_errno =0
|
||||
#endif
|
||||
|
||||
//tracer.c
|
||||
|
@ -214,7 +214,12 @@ static dl_errno =0
|
|||
int do_trace_primitives =TRUE
|
||||
#endif
|
||||
|
||||
//quick loader
|
||||
struct export_atom_hash_entry_struct **ExportAtomHashChain =NULL
|
||||
UInt ExportAtomHashTableSize =0
|
||||
UInt ExportAtomHashTableNum =0
|
||||
struct export_functor_hash_entry_struct **ExportFunctorHashChain =NULL
|
||||
UInt ExportFunctorHashTableSize =0
|
||||
UInt ExportFunctorHashTableNum =0
|
||||
|
||||
END_WORKER_LOCAL
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -31,44 +31,51 @@ main :-
|
|||
open('H/walkclause.h',write,L),
|
||||
open('H/findclause.h',write,F),
|
||||
open('H/headclause.h',write,H),
|
||||
open('H/saveclause.h',write,S),
|
||||
header(W),
|
||||
header_rclause(C),
|
||||
header_walk_clause(L),
|
||||
header_find_clause(F),
|
||||
header_find_clause(H),
|
||||
file('C/absmi.c', W, C, L, F, H),
|
||||
start_ifdef("YAPOR", W, C, L, F, H),
|
||||
file('OPTYap/or.insts.i',W, C, L, F, H),
|
||||
end_ifdef(W, C, L, F, H),
|
||||
start_ifdef("TABLING", W, C, L, F, H),
|
||||
file('OPTYap/tab.insts.i',W,C,L, F, H),
|
||||
header_save_clause(S),
|
||||
file('C/absmi.c', W, C, L, F, H, S),
|
||||
start_ifdef("YAPOR", W, C, L, F, H, S),
|
||||
file('OPTYap/or.insts.i',W, C, L, F, H, S),
|
||||
end_ifdef(W, C, L, F, H, S),
|
||||
start_ifdef("TABLING", W, C, L, F, H, S),
|
||||
file('OPTYap/tab.insts.i',W,C,L, F, H, S),
|
||||
retractall(op(_,_)),
|
||||
file('OPTYap/tab.tries.insts.i', W, C, L, F, H),
|
||||
end_ifdef(W, C, L, F, H),
|
||||
file('OPTYap/tab.tries.insts.i', W, C, L, F, H, S),
|
||||
end_ifdef(W, C, L, F, H, S),
|
||||
footer(W),
|
||||
footer_rclause(C),
|
||||
footer_walk_clause(L),
|
||||
footer_find_clause(F),
|
||||
footer_find_clause(H),
|
||||
footer_save_clause(S),
|
||||
close(F),
|
||||
close(L),
|
||||
close(W),
|
||||
close(C).
|
||||
close(C),
|
||||
close(H),
|
||||
close(S).
|
||||
|
||||
start_ifdef(D, W, C, L, F, H) :-
|
||||
start_ifdef(D, W, C, L, F, H, S) :-
|
||||
retractall(op(_,_)),
|
||||
format(W, '#ifdef ~s~n',[D]),
|
||||
format(C, '#ifdef ~s~n',[D]),
|
||||
format(L, '#ifdef ~s~n',[D]),
|
||||
format(F, '#ifdef ~s~n',[D]),
|
||||
format(H, '#ifdef ~s~n',[D]).
|
||||
format(H, '#ifdef ~s~n',[D]),
|
||||
format(S, '#ifdef ~s~n',[D]).
|
||||
|
||||
end_ifdef(W,C,L,F,H) :-
|
||||
end_ifdef(W,C,L,F,H, S) :-
|
||||
format(W, '#endif~n',[]),
|
||||
format(C, '#endif~n',[]),
|
||||
format(L, '#endif~n',[]),
|
||||
format(F, '#endif~n',[]),
|
||||
format(H, '#endif~n',[]).
|
||||
format(H, '#endif~n',[]),
|
||||
format(S, '#endif~n',[]).
|
||||
|
||||
header(W) :-
|
||||
format(W,'~n /* This file was generated automatically by \"yap -L misc/buildops\"~n please do not update */~n~n',[]).
|
||||
|
@ -101,6 +108,17 @@ header_walk_clause(W) :-
|
|||
switch (op) {
|
||||
',[]).
|
||||
|
||||
header_save_clause(W) :-
|
||||
format(W,'~n /* This file was generated automatically by \"yap -L misc/buildops\"~n please do not update */~n~n
|
||||
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) {
|
||||
',[]).
|
||||
|
||||
header_find_clause(W) :-
|
||||
format(W,'~n /* This file was generated automatically by \"yap -L misc/buildops\"~n please do not update */~n~n
|
||||
|
@ -110,14 +128,15 @@ header_find_clause(W) :-
|
|||
',[]).
|
||||
|
||||
|
||||
file(I,W,C,L,F,H) :-
|
||||
file(I,W,C,L,F,H, S) :-
|
||||
open(I,read,R),
|
||||
process(R,grep_opcode(W)),
|
||||
close(R),
|
||||
output_rclause(C),
|
||||
output_walk_clause(L),
|
||||
output_find_clause(F),
|
||||
output_head_clause(H).
|
||||
output_head_clause(H),
|
||||
output_save_clause(S).
|
||||
|
||||
grep_opcode(W, Line) :-
|
||||
split(Line," ,();",[OP,Name,Type]),
|
||||
|
@ -728,6 +747,12 @@ footer_find_clause(W) :-
|
|||
}
|
||||
}~n',[]).
|
||||
|
||||
footer_save_clause(S) :-
|
||||
format(S,'default:
|
||||
return -1;
|
||||
}
|
||||
}~n',[]).
|
||||
|
||||
get_field_names(F) :-
|
||||
open(F, read, A),
|
||||
loop_for_fields(A),
|
||||
|
@ -1098,3 +1123,43 @@ opinfo("alloc_for_logical_pred",[body]).
|
|||
opinfo("deallocate",[body]).
|
||||
opinfo("table_try_single",[]).
|
||||
opinfo("native_me",[]).
|
||||
|
||||
output_save_clause(S) :-
|
||||
setof(T,O^op(T,O),Types),
|
||||
member(T, Types),
|
||||
output_save_type(S, T),
|
||||
fail.
|
||||
output_save_clause(_).
|
||||
|
||||
output_save_type(S, T) :-
|
||||
format(S,' /* instructions type ~s */~n',[T]),
|
||||
setof(Op,op(T,Op),Ops),
|
||||
dump_ops(S,Ops),
|
||||
% then the code for every instruction with this header.
|
||||
tinfo(T, Desc),
|
||||
output_save(S, T, Desc, T),
|
||||
format(S,' pc = NEXTOP(pc,~s);~n',[T]),
|
||||
format(S,' break;~n',[]).
|
||||
|
||||
output_save(S, "e", [], _) :-
|
||||
format(S, " if (op == _Nstop || op == _copy_idb_term || op == _unify_idb_term) return 1;~n", []).
|
||||
output_save(_, [], [], _).
|
||||
output_save(S, [Name|Names], [Type|Types], Desc) :-
|
||||
output_save_type(S, Name, Type, Desc),
|
||||
output_save(S, Names, Types, Desc).
|
||||
|
||||
output_save_type(S, OpT, T-"none", Desc) :- !,
|
||||
get_op(OpT, Name),
|
||||
format(S, " CHECK(save_~s(stream, pc->u.~s.~s));~n", [Name, Desc, T]).
|
||||
output_save_type(S, OpT, T-Def, Desc) :-
|
||||
get_op(OpT, Name),
|
||||
format(S, "#ifdef ~s~n CHECK(save_~s(stream, pc->u.~s.~s));~n#endif~n", [Def,Name, Desc, T]).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <windows.h>
|
||||
#include <uxnt.h>
|
||||
#define O_HASDRIVES 1
|
||||
#define O_HASSHARES 1
|
||||
#endif
|
||||
|
||||
#ifndef PL_CONSOLE
|
||||
|
@ -25,6 +26,7 @@
|
|||
|
||||
#include "Yap.h"
|
||||
#include "YapHeap.h"
|
||||
|
||||
/* try not to pollute the SWI space */
|
||||
#ifdef P
|
||||
#undef P
|
||||
|
|
|
@ -74,7 +74,9 @@ too much.
|
|||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#ifndef __YAP_PROLOG__
|
||||
static void setArgvPrologFlag(void);
|
||||
#endif
|
||||
static void setTZPrologFlag(void);
|
||||
#ifndef __YAP_PROLOG__
|
||||
static void setVersionPrologFlag(void);
|
||||
#endif
|
||||
static atom_t lookupAtomFlag(atom_t key);
|
||||
|
@ -1111,7 +1113,9 @@ initPrologFlags(void)
|
|||
|
||||
#ifndef __YAP_PROLOG__
|
||||
setArgvPrologFlag();
|
||||
#endif /* YAP_PROLOG */
|
||||
setTZPrologFlag();
|
||||
#ifndef __YAP_PROLOG__
|
||||
setOSPrologFlags();
|
||||
setVersionPrologFlag();
|
||||
#endif /* YAP_PROLOG */
|
||||
|
@ -1141,6 +1145,8 @@ setArgvPrologFlag()
|
|||
PL_discard_foreign_frame(fid);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void
|
||||
setTZPrologFlag()
|
||||
{ tzset();
|
||||
|
@ -1148,6 +1154,7 @@ setTZPrologFlag()
|
|||
setPrologFlag("timezone", FT_INTEGER|FF_READONLY, timezone);
|
||||
}
|
||||
|
||||
#ifndef __YAP_PROLOG__
|
||||
|
||||
static void
|
||||
setVersionPrologFlag(void)
|
||||
|
|
|
@ -276,7 +276,6 @@ PutToken(const char *s, IOSTREAM *stream)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PutTokenN(const char *s, size_t len, IOSTREAM *stream)
|
||||
{ if ( len > 0 )
|
||||
|
@ -291,6 +290,63 @@ PutTokenN(const char *s, size_t len, IOSTREAM *stream)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#if __YAP_PROLOG__
|
||||
static bool
|
||||
PutWideStringN(const wchar_t *str, size_t length, IOSTREAM *s)
|
||||
{ size_t i;
|
||||
const wchar_t *q = (const wchar_t *)str;
|
||||
|
||||
for(i=0; i<length; i++, q++)
|
||||
{ if ( Sputcode(*q, s) == EOF )
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static bool
|
||||
PutWideString(const wchar_t *str, IOSTREAM *s)
|
||||
{ const wchar_t *q = (const wchar_t *)str;
|
||||
|
||||
for( ; *q != EOS; q++ )
|
||||
{ if ( Sputcode(*q, s) == EOF )
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PutWideToken(const wchar_t *s, IOSTREAM *stream)
|
||||
{ if ( s[0] )
|
||||
{ int rc;
|
||||
|
||||
TRY(rc=PutOpenToken(s[0]&0xff, stream));
|
||||
TRY(PutWideString(s, stream));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
PutWideTokenN(const wchar_t *s, size_t len, IOSTREAM *stream)
|
||||
{ if ( len > 0 )
|
||||
{ int rc;
|
||||
|
||||
TRY(rc=PutOpenToken(s[0]&0xff, stream));
|
||||
TRY(PutWideStringN(s, len, stream));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
PutOpenBrace()/PutCloseBrace() are used to put additional braces around
|
||||
|
@ -518,6 +574,11 @@ writeAtom(atom_t a, write_options *options)
|
|||
case AT_SYMBOL:
|
||||
case AT_SOLO:
|
||||
case AT_SPECIAL:
|
||||
#if __YAP_PROLOG__
|
||||
if (isWideAtom(atom)) {
|
||||
return PutWideToken(nameOfWideAtom(atom), options->out);
|
||||
}
|
||||
#endif
|
||||
return PutToken(nameOfAtom(atom), options->out);
|
||||
case AT_QUOTE:
|
||||
case AT_FULLSTOP:
|
||||
|
@ -532,8 +593,14 @@ writeAtom(atom_t a, write_options *options)
|
|||
return rc;
|
||||
}
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
#if __YAP_PROLOG__
|
||||
if (isWideAtom(atom)) {
|
||||
return PutWideTokenN(nameOfWideAtom(atom), atomLength(atom), options->out);
|
||||
}
|
||||
#endif
|
||||
return PutTokenN(nameOfAtom(atom), atomLength(atom), options->out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -886,10 +953,16 @@ writePrimitive(term_t t, write_options *options)
|
|||
|
||||
#if __YAP_PROLOG__
|
||||
{
|
||||
number n;
|
||||
n.type = V_INTEGER;
|
||||
n.value.i = 0;
|
||||
return WriteNumber(&n, options);
|
||||
Opaque_CallOnWrite f;
|
||||
|
||||
if ( (f = Yap_blob_write_handler_from_slot(t)) ) {
|
||||
return (f)(options->out, Yap_blob_tag_from_slot(t), Yap_blob_info_from_slot(t), options->flags);
|
||||
} else {
|
||||
number n;
|
||||
n.type = V_INTEGER;
|
||||
n.value.i = 0;
|
||||
return WriteNumber(&n, options);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -993,6 +993,14 @@ int Yap_getInputStream(term_t t, IOSTREAM **s)
|
|||
return getInputStream(t, s);
|
||||
}
|
||||
|
||||
extern int Yap_getOutputStream(term_t t, IOSTREAM **s);
|
||||
|
||||
int Yap_getOutputStream(term_t t, IOSTREAM **s)
|
||||
{
|
||||
GET_LD
|
||||
return getOutputStream(t, s);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
@ -1157,6 +1165,20 @@ Yap_dowrite(Term t, IOSTREAM *stream, int flags, int priority)
|
|||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
isWideAtom(atom_t atom)
|
||||
{
|
||||
Atom a = (Atom)atomValue(atom);
|
||||
return IsWideAtom(a);
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
nameOfWideAtom(atom_t atom)
|
||||
{
|
||||
Atom a = (Atom)atomValue(atom);
|
||||
return RepAtom(a)->WStrOfAE;
|
||||
}
|
||||
|
||||
|
||||
#if THREADS
|
||||
|
||||
|
@ -1207,7 +1229,6 @@ error:
|
|||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
recursiveMutexInit(recursiveMutex *m)
|
||||
{
|
||||
|
|
|
@ -148,6 +148,9 @@ 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) )
|
||||
|
|
|
@ -516,7 +516,7 @@ are in UTF-8 encoding!
|
|||
|
||||
char *
|
||||
_xos_limited_os_filename(const char *spec, char *limited)
|
||||
{ const unsigned char *i = (const unsigned char*)spec;
|
||||
{ const char *i = spec;
|
||||
char *o = limited;
|
||||
|
||||
while(*i)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a6f0f4ec7d5fd51ca8b268b8392da9b20bfd1b44
|
||||
Subproject commit c9493b2c73e3c8ab8b8524a13352bf0f3ec545a9
|
|
@ -1 +1 @@
|
|||
Subproject commit f1c3ef54f4d9431ba5b4188cb72ca3056d20b202
|
||||
Subproject commit 17f0b15b0fb0af5fc558bc303e32d4f5e3bdce98
|
50
pl/boot.yap
50
pl/boot.yap
|
@ -143,8 +143,8 @@ true :- true.
|
|||
*/
|
||||
|
||||
/* main execution loop */
|
||||
'$read_vars'(user_input, Goal, Mod, Pos, Bindings, Prompt, ReadComments) :-
|
||||
'$swi_current_prolog_flag'(readline, true),
|
||||
'$read_toplevel'(Goal, Bindings) :-
|
||||
'$swi_current_prolog_flag'(readline, true), !,
|
||||
read_history(h, '!h',
|
||||
[trace, end_of_file],
|
||||
Prompt, Goal, Bindings), !,
|
||||
|
@ -153,13 +153,28 @@ true :- true.
|
|||
;
|
||||
true
|
||||
).
|
||||
'$read_vars'(Stream, T, Mod, Pos, V, _Prompt, ReadComments) :-
|
||||
'$read'(true, T, Mod, V, Pos, Err, ReadComments, Stream),
|
||||
(nonvar(Err) ->
|
||||
print_message(error,Err), fail
|
||||
;
|
||||
true
|
||||
).
|
||||
'$read_toplevel'(Goal, Bindings) :-
|
||||
prompt(_,'?- '),
|
||||
prompt1('|: '),
|
||||
'$system_catch'('$raw_read'(user_input, Line), prolog, E,
|
||||
(print_message(error, E),
|
||||
( E = error(syntax_error(_), _)
|
||||
-> fail
|
||||
; throw(E)
|
||||
))),
|
||||
( current_predicate(_, user:rl_add_history(_))
|
||||
-> format(atom(CompleteLine), '~W~W',
|
||||
[ Line, [partial(true)],
|
||||
'.', [partial(true)]
|
||||
]),
|
||||
call(user:rl_add_history(CompleteLine))
|
||||
; true
|
||||
),
|
||||
'$system_catch'(atom_to_term(Line, Goal, Bindings), prolog, E,
|
||||
( print_message(error, E),
|
||||
fail
|
||||
)), !.
|
||||
|
||||
|
||||
% reset alarms when entering top-level.
|
||||
'$enter_top_level' :-
|
||||
|
@ -187,19 +202,19 @@ true :- true.
|
|||
'$enter_top_level' :-
|
||||
get_value('$top_level_goal',GA), GA \= [], !,
|
||||
set_value('$top_level_goal',[]),
|
||||
format('hello1 ~w~n',[GA]),
|
||||
'$run_atom_goal'(GA),
|
||||
set_value('$live','$false').
|
||||
'$enter_top_level' :-
|
||||
'$disable_docreep',
|
||||
prompt(_,'| '),
|
||||
'$run_toplevel_hooks',
|
||||
prompt1('|: '),
|
||||
'$read_vars'(user_input,Command,_,Pos,Varnames, ' ?- ', no),
|
||||
prompt1(' ?- '),
|
||||
'$read_toplevel'(Command,Varnames),
|
||||
nb_setval('$spy_gn',1),
|
||||
% stop at spy-points if debugging is on.
|
||||
% stop at spy-points if debugging is on.
|
||||
nb_setval('$debug_run',off),
|
||||
nb_setval('$debug_jump',off),
|
||||
'$command'(Command,Varnames,Pos,top),
|
||||
'$command'(Command,Varnames,_Pos,top),
|
||||
'$sync_mmapped_arrays',
|
||||
set_value('$live','$false').
|
||||
|
||||
|
@ -1102,6 +1117,13 @@ bootstrap(F) :-
|
|||
!,
|
||||
close(Stream).
|
||||
|
||||
'$read_vars'(Stream, T, Mod, Pos, V, _Prompt, ReadComments) :-
|
||||
'$read'(true, T, Mod, V, Pos, Err, ReadComments, Stream),
|
||||
(nonvar(Err) ->
|
||||
print_message(error,Err), fail
|
||||
;
|
||||
true
|
||||
).
|
||||
|
||||
'$init_path_extensions' :-
|
||||
get_value('$extend_file_search_path',P), !,
|
||||
|
|
13
pl/flags.yap
13
pl/flags.yap
|
@ -288,6 +288,12 @@ yap_flag(informational_messages,off) :- !,
|
|||
yap_flag(informational_messages,X) :-
|
||||
'$do_error'(domain_error(flag_value,informational_messages+X),yap_flag(informational_messages,X)).
|
||||
|
||||
yap_flag(timezone,X) :-
|
||||
var(X), !,
|
||||
'$swi_current_prolog_flag'(timezone, X).
|
||||
yap_flag(timezone,X) :-
|
||||
'$swi_set_prolog_flag'(timezone, X).
|
||||
|
||||
yap_flag(verbose,X) :- var(X), !,
|
||||
get_value('$verbose',X0),
|
||||
(X0 == on -> X = normal ; X = silent).
|
||||
|
@ -748,8 +754,7 @@ yap_flag(user_error,Stream) :-
|
|||
yap_flag(debugger_print_options,OUT) :-
|
||||
var(OUT),
|
||||
recorded('$print_options','$debugger'(OUT),_), !.
|
||||
yap_flag(debugger_print_options,Opts) :- !,
|
||||
'$check_io_opts'(Opts, yap_flag(debugger_print_options,Opts)),
|
||||
yap_flag(debugger_print_options,Opts) :-
|
||||
recorda('$print_options','$debugger'(Opts),_).
|
||||
|
||||
:- recorda('$print_options','$debugger'([quoted(true),numbervars(true),portrayed(true),max_depth(10)]),_).
|
||||
|
@ -757,8 +762,7 @@ yap_flag(debugger_print_options,Opts) :- !,
|
|||
yap_flag(toplevel_print_options,OUT) :-
|
||||
var(OUT),
|
||||
recorded('$print_options','$toplevel'(OUT),_), !.
|
||||
yap_flag(toplevel_print_options,Opts) :- !,
|
||||
'$check_io_opts'(Opts, yap_flag(toplevel_print_options,Opts)),
|
||||
yap_flag(toplevel_print_options,Opts) :-
|
||||
recorda('$print_options','$toplevel'(Opts),_).
|
||||
|
||||
:- recorda('$print_options','$toplevel'([quoted(true),numbervars(true),portrayed(true)]),_).
|
||||
|
@ -885,6 +889,7 @@ yap_flag(dialect,yap).
|
|||
'$yap_system_flag'(strict_iso).
|
||||
'$yap_system_flag'(syntax_errors).
|
||||
'$yap_system_flag'(system_options).
|
||||
'$yap_system_flag'(timezone).
|
||||
'$yap_system_flag'(to_chars_mode).
|
||||
'$yap_system_flag'(toplevel_hook).
|
||||
'$yap_system_flag'(toplevel_print_options).
|
||||
|
|
|
@ -82,6 +82,7 @@ otherwise.
|
|||
'eam.yap',
|
||||
'chtypes.yap',
|
||||
'yapor.yap',
|
||||
'qly.yap',
|
||||
'udi.yap'].
|
||||
|
||||
:- dynamic prolog:'$user_defined_flag'/4.
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2011 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: qly.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: fast save/restore *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
save_module(Mod) :-
|
||||
atom_concat(Mod,'.qly',F),
|
||||
open(F, write, S, [type(binary)]),
|
||||
'$save_module_preds'(S, Mod),
|
||||
close(S).
|
||||
|
|
@ -33,8 +33,6 @@
|
|||
'$check_opt_read'(Opt, G).
|
||||
'$check_opt'(stream_property(_,_),Opt,G) :-
|
||||
'$check_opt_sp'(Opt, G).
|
||||
'$check_opt'(yap_flag(_,_),Opt,G) :-
|
||||
'$check_opt_write'(Opt, G).
|
||||
|
||||
'$check_opt_read'(variables(_), _) :- !.
|
||||
'$check_opt_read'(variable_names(_), _) :- !.
|
||||
|
@ -94,7 +92,8 @@ fileerrors :- '$swi_set_prolog_flag'(fileerrors, true).
|
|||
|
||||
nofileerrors :- '$swi_set_prolog_flag'(fileerrors, false).
|
||||
|
||||
exists(F) :- access_file(F,exist).
|
||||
exists(F) :-
|
||||
absolute_file_name(F, _, [file_errors(fail),access(exist),expand(true)]).
|
||||
|
||||
/* Term IO */
|
||||
|
||||
|
|
Reference in New Issue