Merge branch 'master' of ssh://git.dcc.fc.up.pt/yap-6.3

Conflicts:
	library/parameters.yap
	packages/myddas/pl/myddas.ypp
This commit is contained in:
Vítor Santos Costa 2015-03-11 22:31:18 +00:00
commit 55bd75b8d8
15 changed files with 1338 additions and 1179 deletions

View File

@ -10,6 +10,18 @@
#endif /* INDENT_CODE */ #endif /* INDENT_CODE */
BOp(call_cpred, Osbpp); BOp(call_cpred, Osbpp);
#if __ANDROID__
char *s; Atom name;
if (PREG->y_u.Osbpp.p->ArityOfPE) {
Functor f = PREG->y_u.Osbpp.p->FunctorOfPred;
name = f->NameOfFE;
} else {
name = (Atom)(PREG->y_u.Osbpp.p->FunctorOfPred);
}
s = name->StrOfAE;
__android_log_print(ANDROID_LOG_INFO, "YAP", " %s ", s);
#endif
check_trail(TR); check_trail(TR);
if (!(PREG->y_u.Osbpp.p->PredFlags & (SafePredFlag|NoTracePredFlag|HiddenPredFlag))) { if (!(PREG->y_u.Osbpp.p->PredFlags & (SafePredFlag|NoTracePredFlag|HiddenPredFlag))) {
CACHE_Y_AS_ENV(YREG); CACHE_Y_AS_ENV(YREG);

View File

@ -929,33 +929,39 @@ char *
Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags) Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags)
{ {
char *r, buf[4096]; char *buf;
int64_t size; size_t size = 4096, total = size;
IOSTREAM *fd; IOSTREAM *fd;
r = buf; total = size;
fd = Sopenmem(&r, &sz, "w"); buf = malloc(total);
fd->encoding = ENC_UTF8; while ( (fd = Sopenmem(&buf, &size, "w")) == NULL ||
if ( PL_write_term(fd, l, 1200, flags) && (( fd->encoding = ENC_UTF8) && FALSE) ||
Sputcode(EOS, fd) >= 0 && (PL_write_term(fd, l, 1200, flags) == 0) ||
Sflush(fd) >= 0 ) Sputcode(EOS, fd) < 0 ||
Sflush(fd) < 0 ) /* failure */
{ {
size = Stell64(fd); #ifdef DEBUG
*length = size-1; {CACHE_REGS
char *bf = malloc(*length+1); __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %p, %x buf=%s\n", fd, LOCAL_SlotBase[28], buf);}
if (!bf) #endif
return NULL;
strncpy(bf,buf,*length+1);
Sclose(fd); Sclose(fd);
r = bf; if (!fd)
return r;
}
/* failed */
if ( r != buf ) {
Sfree(r);
}
return NULL; return NULL;
total += size;
buf = realloc(buf, total);
if (!buf)
return NULL;
Sclose(fd);
}
#ifdef DEBUG
{CACHE_REGS
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text done %s", buf);}
#endif
Sclose(fd);
/* success */
return buf;
} }

View File

@ -931,6 +931,7 @@ static Int cont_current_predicate(USES_REGS1) {
if (!is_det) { if (!is_det) {
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(p); EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(p);
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(q); EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(q);
B->cp_h = HR;
} }
} else if (IsNonVarTerm(t2)) { } else if (IsNonVarTerm(t2)) {
// operating within the same module. // operating within the same module.
@ -943,6 +944,7 @@ static Int cont_current_predicate(USES_REGS1) {
npp = pp->NextPredOfModule; npp = pp->NextPredOfModule;
if (npp) { if (npp) {
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(npp); EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(npp);
B->cp_h = HR;
} else { } else {
is_det = true; is_det = true;
} }
@ -957,12 +959,14 @@ static Int cont_current_predicate(USES_REGS1) {
else { else {
pp = m->PredForME; pp = m->PredForME;
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(m); EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(m);
B->cp_h = HR;
} }
} // we found a new answer } // we found a new answer
if (!pp) if (!pp)
cut_fail(); cut_fail();
else else
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(pp->NextPredOfModule); EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(pp->NextPredOfModule);
B->cp_h = HR;
} }
if (pp->ModuleOfPred != IDB_MODULE) { if (pp->ModuleOfPred != IDB_MODULE) {
f = pp->FunctorOfPred; f = pp->FunctorOfPred;
@ -1081,6 +1085,7 @@ static Int init_current_predicate(USES_REGS1) {
cut_fail(); cut_fail();
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(p); EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(p);
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(q); EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(q);
B->cp_h = HR;
} }
} }
// check module // check module
@ -1102,6 +1107,7 @@ static Int init_current_predicate(USES_REGS1) {
} }
EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(m); EXTRA_CBACK_ARG(4, 2) = MkAddressTerm(m);
EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(pp); EXTRA_CBACK_ARG(4, 1) = MkAddressTerm(pp);
B->cp_h = HR;
} }
// ensure deref access to choice-point fields. // ensure deref access to choice-point fields.
return cont_current_predicate(PASS_REGS1); return cont_current_predicate(PASS_REGS1);
@ -1156,6 +1162,7 @@ static Int cont_current_op(USES_REGS1) {
READ_UNLOCK(op->OpRWLock); READ_UNLOCK(op->OpRWLock);
if (next) { if (next) {
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next); EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
B->cp_h = HR;
return TRUE; return TRUE;
} else { } else {
cut_succeed(); cut_succeed();
@ -1164,6 +1171,7 @@ static Int cont_current_op(USES_REGS1) {
READ_UNLOCK(op->OpRWLock); READ_UNLOCK(op->OpRWLock);
if (next) { if (next) {
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next); EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
B->cp_h = HR;
return FALSE; return FALSE;
} else { } else {
cut_fail(); cut_fail();
@ -1171,9 +1179,9 @@ static Int cont_current_op(USES_REGS1) {
} }
} }
static Int init_current_op( static Int init_current_op(USES_REGS1) { /* current_op(-Precedence,-Type,-Atom) */
USES_REGS1) { /* current_op(-Precedence,-Type,-Atom) */
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)OpList); EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)OpList);
B->cp_h = HR;
return cont_current_op(PASS_REGS1); return cont_current_op(PASS_REGS1);
} }
@ -1186,6 +1194,7 @@ static Int cont_current_atom_op(USES_REGS1) {
READ_UNLOCK(op->OpRWLock); READ_UNLOCK(op->OpRWLock);
if (next) { if (next) {
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next); EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
B->cp_h = HR;
return TRUE; return TRUE;
} else { } else {
cut_succeed(); cut_succeed();
@ -1194,6 +1203,7 @@ static Int cont_current_atom_op(USES_REGS1) {
READ_UNLOCK(op->OpRWLock); READ_UNLOCK(op->OpRWLock);
if (next) { if (next) {
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next); EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((CELL)next);
B->cp_h = HR;
return FALSE; return FALSE;
} else { } else {
cut_fail(); cut_fail();
@ -1216,6 +1226,7 @@ static Int init_current_atom_op(
cut_fail(); cut_fail();
} }
EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope); EXTRA_CBACK_ARG(5, 1) = (CELL)MkIntegerTerm((Int)ope);
B->cp_h = HR;
return cont_current_atom_op(PASS_REGS1); return cont_current_atom_op(PASS_REGS1);
} }

View File

@ -1189,19 +1189,18 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
} }
} }
struct write_globs wglb;
struct rewind_term rwt;
void Yap_plwrite(Term t, void *mywrite, int max_depth, int flags, int priority) void Yap_plwrite(Term t, void *mywrite, int max_depth, int flags, int priority)
/* term to be written */ /* term to be written */
/* consumer */ /* consumer */
/* write options */ /* write options */
{ {
struct write_globs wglb;
struct rewind_term rwt;
if (!mywrite) if (!mywrite)
wglb.stream = Serror; wglb.stream = Serror;
else else
wglb.stream = mywrite; wglb.stream = mywrite;
wglb.lw = separator; wglb.lw = separator;
wglb.last_atom_minus = FALSE; wglb.last_atom_minus = FALSE;
wglb.Quote_illegal = flags & Quote_illegal_f; wglb.Quote_illegal = flags & Quote_illegal_f;

View File

@ -88,6 +88,7 @@ YAPStringTerm::YAPStringTerm(char *s, size_t len) { // build string
BACKUP_H(); BACKUP_H();
CACHE_REGS CACHE_REGS
seq_tv_t inp, out; seq_tv_t inp, out;
inp.val.c = s; inp.val.c = s;
inp.type = YAP_STRING_CHARS; inp.type = YAP_STRING_CHARS;
@ -104,6 +105,7 @@ YAPStringTerm::YAPStringTerm(wchar_t *s): YAPTerm() { // build string
BACKUP_H(); BACKUP_H();
CACHE_REGS CACHE_REGS
seq_tv_t inp, out; seq_tv_t inp, out;
inp.val.w = s; inp.val.w = s;
inp.type = YAP_STRING_WCHARS; inp.type = YAP_STRING_WCHARS;
@ -119,6 +121,7 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len) : YAPTerm() { // build stri
BACKUP_H(); BACKUP_H();
CACHE_REGS CACHE_REGS
seq_tv_t inp, out; seq_tv_t inp, out;
inp.val.w = s; inp.val.w = s;
inp.type = YAP_STRING_WCHARS; inp.type = YAP_STRING_WCHARS;
@ -133,17 +136,24 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len) : YAPTerm() { // build stri
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) : YAPTerm() { YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) : YAPTerm() {
BACKUP_MACHINE_REGS();
UInt arity = ArityOfFunctor(f.f); UInt arity = ArityOfFunctor(f.f);
mk ( Yap_MkApplTerm( f.f, arity, (Term *)ts) ); mk ( Yap_MkApplTerm( f.f, arity, (Term *)ts) );
RECOVER_MACHINE_REGS();
} }
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm() { YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm() {
BACKUP_MACHINE_REGS();
UInt arity = ArityOfFunctor(f.f); UInt arity = ArityOfFunctor(f.f);
mk ( Yap_MkNewApplTerm( f.f, arity) ); mk ( Yap_MkNewApplTerm( f.f, arity) );
RECOVER_MACHINE_REGS();
} }
YAPTerm YAPApplTerm::getArg(int arg) { YAPTerm YAPApplTerm::getArg(int arg) {
return YAPTerm( ArgOfTerm(arg, gt() ) ); BACKUP_MACHINE_REGS();
YAPTerm to = YAPTerm( ArgOfTerm(arg, gt() ) );
RECOVER_MACHINE_REGS();
return to;
} }
YAPFunctor YAPApplTerm::getFunctor() { YAPFunctor YAPApplTerm::getFunctor() {
@ -152,11 +162,15 @@ YAPFunctor YAPApplTerm::getFunctor() {
YAPPairTerm::YAPPairTerm(YAPTerm th, YAPTerm tl) : YAPTerm() { YAPPairTerm::YAPPairTerm(YAPTerm th, YAPTerm tl) : YAPTerm() {
CACHE_REGS CACHE_REGS
BACKUP_MACHINE_REGS();
mk ( MkPairTerm( th.term(), tl.term() ) ); mk ( MkPairTerm( th.term(), tl.term() ) );
RECOVER_MACHINE_REGS();
} }
YAPPairTerm::YAPPairTerm() : YAPTerm() { YAPPairTerm::YAPPairTerm() : YAPTerm() {
BACKUP_MACHINE_REGS();
t = Yap_MkNewPairTerm( ); t = Yap_MkNewPairTerm( );
RECOVER_MACHINE_REGS();
} }
void YAPTerm::mk(Term t0) { CACHE_REGS t = Yap_InitSlot( t0 PASS_REGS); } void YAPTerm::mk(Term t0) { CACHE_REGS t = Yap_InitSlot( t0 PASS_REGS); }
@ -268,16 +282,24 @@ intptr_t YAPTerm::hashTerm(size_t sz, size_t depth, bool variant) {
return out; return out;
} }
char *YAPTerm::text() { const char *YAPTerm::text() {
size_t sze = 4096, length; size_t sze = 4096, length;
char *os; char *os;
int enc; int enc;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
#ifdef DEBUG
{CACHE_REGS
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %d, %x \n", t, LOCAL_SlotBase[t]);}
#endif
if (!(os = Yap_HandleToString(t, sze, &length, &enc, 0))) { if (!(os = Yap_HandleToString(t, sze, &length, &enc, 0))) {
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return (char *)NULL; return (char *)NULL;
} }
#ifdef DEBUG
{CACHE_REGS
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %d, %x %p\n", t, LOCAL_SlotBase[t], os);}
#endif
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return os; return os;
} }
@ -287,21 +309,19 @@ char *YAPQuery::text() {
char *os; char *os;
int enc; int enc;
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "I LCL0+%p/t=(%d) %x", LCL0, *q_g, LCL0[-15]) ; } { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "I t=(%d) %lx", *q_g) ; }
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
if (!(os = Yap_HandleToString(*q_g, sze, &length, &enc, 0))) { if (!(os = Yap_HandleToString(*q_g, sze, &length, &enc, 0))) {
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "IIa LCL0+t=(%p) %x oz=%p %s", LCL0, LCL0[-15], os, os) ; }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return (char *)NULL; return (char *)NULL;
} }
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II LCL0+t=(%p) %x", LCL0, LCL0[-15]) ; } { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II ") ; }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return os; return os;
} }
bool YAPListTerm::nil() { bool YAPListTerm::nil() {
CACHE_REGS CACHE_REGS
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d LCL0+t=(%p)", t, LCL0+t) ;
return gt() == TermNil; return gt() == TermNil;
} }
@ -327,8 +347,8 @@ YAPTerm::YAPTerm(intptr_t i) { CACHE_REGS Term tn = MkIntegerTerm( i ); mk( tn )
YAPTerm YAPListTerm::car() YAPTerm YAPListTerm::car()
{ {
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d LCL0+t=(%p)", t, LCL0+t) ; }
Term to = gt(); Term to = gt();
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "to=%d", to) ; }
if (IsPairTerm(to)) if (IsPairTerm(to))
return YAPTerm(HeadOfTerm(to)); return YAPTerm(HeadOfTerm(to));
else else

View File

@ -1,6 +1,8 @@
#ifndef YAPT_HH #ifndef YAPT_HH
#define YAPT_HH 1 #define YAPT_HH 1
class YAPAtomTerm;
/** /**
* @brief Generic Prolog Term * @brief Generic Prolog Term
*/ */
@ -10,6 +12,7 @@ class YAPTerm {
friend class YAPQuery; friend class YAPQuery;
friend class YAPModule; friend class YAPModule;
friend class YAPModuleProp; friend class YAPModuleProp;
friend class YAPApplTerm;
protected: protected:
yhandle_t t; /// handle to term, equivalent to term_t yhandle_t t; /// handle to term, equivalent to term_t
void mk(Term t0); /// internal method to convert from term to handle void mk(Term t0); /// internal method to convert from term to handle
@ -37,33 +40,39 @@ public:
bool unifiable(YAPTerm t1); /// we can unify t and t1 bool unifiable(YAPTerm t1); /// we can unify t and t1
bool variant(YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming bool variant(YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming
intptr_t hashTerm(size_t sz, size_t depth, bool variant); /// term hash, intptr_t hashTerm(size_t sz, size_t depth, bool variant); /// term hash,
bool isVar() { return IsVarTerm( gt() ); } /// type check for unbound virtual bool isVar() { return IsVarTerm( gt() ); } /// type check for unbound
bool isAtom() { return IsAtomTerm( gt() ); } /// type check for atom virtual bool isAtom() { return IsAtomTerm( gt() ); } /// type check for atom
bool isInteger() { return IsIntegerTerm( gt() ); } /// type check for integer virtual bool isInteger() { return IsIntegerTerm( gt() ); } /// type check for integer
bool isFloat() { return IsFloatTerm( gt() ); } /// type check for floating-point virtual bool isFloat() { return IsFloatTerm( gt() ); } /// type check for floating-point
bool isString() { return IsStringTerm( gt() ); } /// type check for a string " ... " virtual bool isString() { return IsStringTerm( gt() ); } /// type check for a string " ... "
bool isCompound() { return !(IsVarTerm( gt() ) || IsNumTerm( gt() )); } /// is a primitive term virtual bool isCompound() { return !(IsVarTerm( gt() ) || IsNumTerm( gt() )); } /// is a primitive term
bool isAppl() { return IsApplTerm( gt() ); } /// is a structured term virtual bool isAppl() { return IsApplTerm( gt() ); } /// is a structured term
bool isPair() { return IsPairTerm( gt() ); } /// is a pair term virtual bool isPair() { return IsPairTerm( gt() ); } /// is a pair term
bool isGround() { return Yap_IsGroundTerm( gt() ); } /// term is ground virtual bool isGround() { return Yap_IsGroundTerm( gt() ); } /// term is ground
bool isList() { return Yap_IsListTerm( gt() ); } /// term is a list virtual bool isList() { return Yap_IsListTerm( gt() ); } /// term is a list
/// extract the argument i of the term, where i in 1...arity /// extract the argument i of the term, where i in 1...arity
inline YAPTerm getArg(int i) { inline YAPTerm getArg(int i) {
BACKUP_MACHINE_REGS();
Term t0 = gt(); Term t0 = gt();
YAPTerm tf;
if (IsApplTerm(t0)) if (IsApplTerm(t0))
return YAPTerm(ArgOfTerm(i, t0)); tf = YAPTerm(ArgOfTerm(i, t0));
else if (IsPairTerm(t0)) { else if (IsPairTerm(t0)) {
if (i==1) if (i==1)
return YAPTerm(HeadOfTerm(t0)); tf = YAPTerm(HeadOfTerm(t0));
if (i==2) else if (i==2)
return YAPTerm(TailOfTerm(t0)); tf = YAPTerm(TailOfTerm(t0));
} else {
tf = YAPTerm((Term)0);
} }
return YAPTerm((Term)0); RECOVER_MACHINE_REGS();
//{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "after getArg H= %p, i=%d", HR, tf.gt()) ; }
return tf;
} }
/// return a string with a textual representation of the term /// return a string with a textual representation of the term
char *text(); virtual const char *text();
}; };
/** /**
@ -78,6 +87,44 @@ public:
CELL *getVar() { return VarOfTerm( gt() ); } CELL *getVar() { return VarOfTerm( gt() ); }
/// is the variable bound to another one /// is the variable bound to another one
bool unbound() { return IsUnboundVar(VarOfTerm( gt() )); } bool unbound() { return IsUnboundVar(VarOfTerm( gt() )); }
virtual bool isVar() { return true; } /// type check for unbound
virtual bool isAtom() { return false; } /// type check for atom
virtual bool isInteger() { return false; } /// type check for integer
virtual bool isFloat() { return false; } /// type check for floating-point
virtual bool isString() { return false; } /// type check for a string " ... "
virtual bool isCompound() { return false; } /// is a primitive term
virtual bool isAppl() { return false; } /// is a structured term
virtual bool isPair() { return false; } /// is a pair term
virtual bool isGround() { return false; } /// term is ground
virtual bool isList() { return false; } /// term is a list
};
/**
* @brief Atom Term
* Term Representation of an Atom
*/
class YAPAtomTerm: YAPTerm {
friend class YAPModule;
// Constructor: receives a C-atom;
YAPAtomTerm(Atom a) { mk( MkAtomTerm(a) ); }
YAPAtomTerm(Term t): YAPTerm(t) { IsAtomTerm(t); }
// Getter for Prolog atom
Term getTerm() { return t; }
public:
// Constructor: receives an atom;
YAPAtomTerm(YAPAtom a): YAPTerm() { mk( MkAtomTerm(a.a) ); }
// Constructor: receives a sequence of ISO-LATIN1 codes;
YAPAtomTerm(char *s) ;
// Constructor: receives a sequence of up to n ISO-LATIN1 codes;
YAPAtomTerm(char *s, size_t len);
// Constructor: receives a sequence of wchar_ts, whatever they may be;
YAPAtomTerm(wchar_t *s) ;
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
YAPAtomTerm(wchar_t *s, size_t len);
// Getter: outputs the atom;
YAPAtom getAtom() { return YAPAtom(AtomOfTerm( gt() )); }
// Getter: outputs the name as a sequence of ISO-LATIN1 codes;
const char *getName() { return AtomOfTerm( gt() )->StrOfAE; }
}; };
/** /**
@ -123,6 +170,10 @@ public:
/// Create a list term out of a standard term. Check if a valid operation. /// Create a list term out of a standard term. Check if a valid operation.
/// ///
/// @param[in] the term /// @param[in] the term
YAPListTerm() { mk(TermNil); /* else type_error */ }
/// Create an empty list term.
///
/// @param[in] the term
YAPListTerm(Term t0) { mk(t0); /* else type_error */ } YAPListTerm(Term t0) { mk(t0); /* else type_error */ }
/* /// Create a list term out of an array of terms. /* /// Create a list term out of an array of terms.
/// ///
@ -145,8 +196,9 @@ public:
Term to = gt(); Term to = gt();
if (IsPairTerm( to )) if (IsPairTerm( to ))
return YAPListTerm(TailOfTerm( to )); return YAPListTerm(TailOfTerm( to ));
else else if ( to == TermNil)
return MkIntTerm(-1); return YAPListTerm( );
/* error */;
} }
/// Check if the list is empty. /// Check if the list is empty.
@ -171,32 +223,4 @@ public:
const char *getString() { return StringOfTerm( gt() ); } const char *getString() { return StringOfTerm( gt() ); }
}; };
/**
* @brief Atom Term
* Term Representation of an Atom
*/
class YAPAtomTerm: YAPTerm {
friend class YAPModule;
// Constructor: receives a C-atom;
YAPAtomTerm(Atom a) { mk( MkAtomTerm(a) ); }
YAPAtomTerm(Term t): YAPTerm(t) { IsAtomTerm(t); }
// Getter for Prolog atom
Term getTerm() { return t; }
public:
// Constructor: receives an atom;
YAPAtomTerm(YAPAtom a): YAPTerm() { mk( MkAtomTerm(a.a) ); }
// Constructor: receives a sequence of ISO-LATIN1 codes;
YAPAtomTerm(char *s) ;
// Constructor: receives a sequence of up to n ISO-LATIN1 codes;
YAPAtomTerm(char *s, size_t len);
// Constructor: receives a sequence of wchar_ts, whatever they may be;
YAPAtomTerm(wchar_t *s) ;
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
YAPAtomTerm(wchar_t *s, size_t len);
// Getter: outputs the atom;
YAPAtom getAtom() { return YAPAtom(AtomOfTerm( gt() )); }
// Getter: outputs the name as a sequence of ISO-LATIN1 codes;
const char *getName() { return AtomOfTerm( gt() )->StrOfAE; }
};
#endif /* YAPT_HH */ #endif /* YAPT_HH */

View File

@ -72,7 +72,7 @@
:- use_module( library(bdd) ). :- use_module( library(bdd) ).
:- dynamic extension/4, init/2, frame/2. :- dynamic extension/4, init/2, frame/2, exclusive/0.
user:term_expansion(Term,Clauses) :- user:term_expansion(Term,Clauses) :-
Term = ( Spec :- Body), Term = ( Spec :- Body),
@ -92,11 +92,11 @@ find_name( [_|UnsortedCurrentNames] , V, Name) :-
expand( Skel, Names, GoalVars, Body, Tests, Out) :- expand( Skel, Names, GoalVars, Body, Tests, Out) :-
Skel =.. [N|As], % Skel =.. [N|As], %
%pick(Vs, As, Os), %pick(Vs, As, Os),
trace,
append(As, GoalVars, Os), append(As, GoalVars, Os),
Head =.. [N|Os], Head =.. [N|Os],
maplist(original_name(GoalVars), Names, Ts), maplist(original_name(GoalVars), Names, Ts),
LinkGoal =.. [access|Ts], LinkGoal =.. [access|Ts],
trace,
formula( Tests, Fs, Dic), formula( Tests, Fs, Dic),
bdd_new(Fs , BDD), bdd_new(Fs , BDD),
bdd_print( BDD, '/Users/vsc/bdd.dot', Names), bdd_print( BDD, '/Users/vsc/bdd.dot', Names),
@ -105,37 +105,48 @@ expand( Skel, Names, GoalVars, Body, Tests, Out) :-
% portray_clause((Head:-GExtBody)), % portray_clause((Head:-GExtBody)),
unnumbervars((Head:- LinkGoal,Body), Out). unnumbervars((Head:- LinkGoal,Body), Out).
ptree( bdd(_,L,_Vs) , Names, Dic) :- swap_f(Key-V, Key=V).
ptree( bdd(Root,L,_Vs) , Names, File, Dic) :-
% term_variables(L, LVs), % term_variables(L, LVs),
% Vs =.. [_|LVs], % Vs =.. [_|LVs],
% trace,
maplist( bindv,Names), maplist( bindv,Names),
rb_visit(Dic, Pairs), rb_visit(Dic, Pairs),
maplist( bindv,Pairs), maplist( bindv,Pairs),
open('bdd.dot', write, S) , absolute_file_name( File, [], AbsFile ),
open(AbsFile, write, S) ,
format(S,'digraph "DD" { format(S,'digraph "DD" {
size = "7.5,10" size = "7.5,10"
center = true;~n', []), center = true;~n', []),
format(S,' "~w" [label = "~w"];~n', [1, Root]),
maplist( print_node(S), L), maplist( print_node(S), L),
format(S, '}~n', []), format(S, '}~n', []),
close(S), close(S),
fail. fail.
ptree(_, _, _). ptree(_, _, _).
bindv( X = '$VAR'(X) ). bindv( X = '$VAR'(X) ) :- !.
bindv( X - '$VAR'(X) ). bindv( X - '$VAR'(X) ) :- !.
bindv(_).
print_node(S,pp( Val, Name, Left, Right )) :- print_node(S,pp( Val, Name, Left, Right )) :-
%writeln(Name),
simplify(Name, N), simplify(Name, N),
format(S,' "~w" [label = "~w"];~n', [Val, N]), format(S,' "~w" [label = "~w"];~n', [Val, N]),
format(S,' "~w" -> "~w";~n', [Val, Right]), format(S,' "~w" -> "~w" [arrowType="none" color="red"] ;~n', [Val, Left]),
format(S,' "~w" -> "~w" [style = dashed];~n', [Val, Left]). format(S,' "~w" -> "~w" [style = dashed arrowType="none"];~n', [Val, Right]).
print_node(S,pn( Val, Name, Left, Right )) :- print_node(S,pn( Val, Name, Left, Right )) :-
simplify(Name, N), simplify(Name, N),
%writeln(Name),
format(S,' "~w" [label = "~w"];~n', [Val, N]), format(S,' "~w" [label = "~w"];~n', [Val, N]),
format(S,' "~w" -> "~w";~n', [Val, Right]), format(S,' "~w" -> "~w" [arrowType="none" color="red"];~n', [Val,Left]),
format(S,' "~w" -> "~w" [style = dashed];~n', [Val, Left]). ( Right == 1 ->
format(S,' "~w" -> "0" [dir=none style = dotted];~n', [Val])
;
format(S,' "~w" -> "~w" [style = dotted type="odot"];~n', [Val, Right])
).
simplify(V,V) :- var(V),!.
simplify('$VAR'(X),Y) :- !, simplify(X,Y). simplify('$VAR'(X),Y) :- !, simplify(X,Y).
simplify(c^(X),Y) :- !, simplify(X,Y). simplify(c^(X),Y) :- !, simplify(X,Y).
simplify(G, X:M) :- G=.. [X,N], !, simplify(N,M). simplify(G, X:M) :- G=.. [X,N], !, simplify(N,M).
@ -428,16 +439,16 @@ ensure((X in D)) :-
formula( Axioms, FormulaE, Dic) :- formula( Axioms, FormulaE, Dic) :-
rb_new( Dic0 ), rb_new( Dic0 ),
partition( is_init, Axioms, _Inits, OGoals), partition( is_frame, Axioms, _, Goals),
partition( is_frame, OGoals, _Frames, Goals),
foldl2( eq, Goals, Formula, Dic0, Dic, [], Extras), foldl2( eq, Goals, Formula, Dic0, Dic, [], Extras),
append(Formula, Extras, FormulaL), append(Formula, Extras, FormulaL),
maplist(writeln,FormulaL),
list2prod( FormulaL, FormulaE). list2prod( FormulaL, FormulaE).
is_init( A ?= B ) :- assert(init(A, B)).
is_frame( A =:= B ) :- assert( frame(A, B)). is_frame( A =:= B ) :- assert( frame(A, B)).
is_frame( level(N, [H|L]) ) :- !, maplist( assertn(level, N), [H|L] ).
is_frame( level(N, L ) ) :- assert( level( N, L) ).
assertn(level, N, L) :- assert( level( N, L) ).
list2prod( [], true). list2prod( [], true).
list2prod( [F], F). list2prod( [F], F).
@ -445,6 +456,9 @@ list2prod( [F1,F2|Fs], F1*NF) :-
list2prod( [F2|Fs], NF). list2prod( [F2|Fs], NF).
%eq(G,_,_,_,_,_) :- writeln(a:G), fail. %eq(G,_,_,_,_,_) :- writeln(a:G), fail.
eq(1, 1, Dic, Dic, I, I) :- !.
eq(X, VX, Dic0, Dic, I0, I) :- var(X), !,
add(X, VX, Dic0, Dic, I0, I).
eq(X == Exp, (-TA + TY)*(-TY + TA), Dic0, Dic, I0, I) :- !, eq(X == Exp, (-TA + TY)*(-TY + TA), Dic0, Dic, I0, I) :- !,
eq(X, TA, Dic0, Dic1, I0, I1), eq(X, TA, Dic0, Dic1, I0, I1),
eq(Exp, TY, Dic1, Dic, I1, I). eq(Exp, TY, Dic1, Dic, I1, I).
@ -485,6 +499,28 @@ eq(one_of(D), Ds, Dic0, Dic, I0, I) :-
eq(G, NG, Dic0, Dic, I0, I) :- eq(G, NG, Dic0, Dic, I0, I) :-
add( G, NG, Dic0, Dic, I0, I). add( G, NG, Dic0, Dic, I0, I).
add_xors(L, V, I0, I) :-
foldl(add_xor(V), L, I0, I).
add_xor(V, V0, I, I) :- V == V0, !.
add_xor(V, V0, I, [(V-V0)|I]).
xor( VX, DV0s, DV , Disj0, Disj0+Conj) :- !,
foldl( add_all2(VX, DV), DV0s, 1,Conj).
add_all2(VX, G, GD, C, C*(VX=G)
) :- G == GD, ! .
add_all2(VX, _, G, C, C*(-(VX=G))).
list2prod(X, P, X *P).
list2sum(X, P, X +P).
t_domain0( [D], DX, Dic0, Dic, I0, I) :- !,
eq(D , DX , Dic0, Dic, I0, I).
t_domain0( [D1|D2s], (DX1+ (-DX1*D2Xs)), Dic0, Dic, I0, I) :-
eq(D1, DX1, Dic0, Dic1, I0, I1),
t_domain0(D2s, D2Xs, Dic1, Dic, I1, I).
t_domain( [D], X, _VX, VDX, Dic0, Dic, I0, I) :- !, t_domain( [D], X, _VX, VDX, Dic0, Dic, I0, I) :- !,
add( X=D, VDX, Dic0, Dic, I0, I). add( X=D, VDX, Dic0, Dic, I0, I).
t_domain( [D1|D2s], X, VX, VDX + (-VDX*D2S), Dic0, Dic, I0, I) :- t_domain( [D1|D2s], X, VX, VDX + (-VDX*D2S), Dic0, Dic, I0, I) :-
@ -507,6 +543,7 @@ add( AG, V, Dic0, Dic, I0, IF) :-
add( AG, V, Dic0, Dic, I, I) :- add( AG, V, Dic0, Dic, I, I) :-
rb_insert( Dic0, AG, V, Dic). rb_insert( Dic0, AG, V, Dic).
simp_key(G , G) :- var(G), !.
simp_key(_^_:error(_^G) , G) :- !. simp_key(_^_:error(_^G) , G) :- !.
simp_key(_^_:G , G) :- !. simp_key(_^_:G , G) :- !.
simp_key('$VAR'(S):A, SAG) :- simp_key('$VAR'(S):A, SAG) :-

View File

@ -262,7 +262,19 @@ writeTopTerm(term_t t, int prec, write_options *options)
if (flags & PL_WRT_BLOB_PORTRAY) if (flags & PL_WRT_BLOB_PORTRAY)
yap_flag |= Blob_Portray_f; yap_flag |= Blob_Portray_f;
old_module = CurrentModule; old_module = CurrentModule;
char * buf[1024];
size_t length;
int encode; Term tn;
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "Yap_REGS=%p\n", Yap_REGS);
CurrentModule = Yap_GetModuleFromEntry(options->module); CurrentModule = Yap_GetModuleFromEntry(options->module);
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d\n", t) ;
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "LOCAl_SlotBase[t]=%ld\n", LOCAL_SlotBase[t]);
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "LOCAl_SlotBase=%ld\n", Deref(LOCAL_SlotBase[t]));
Yap_plwrite(Yap_GetFromSlot(t PASS_REGS), options->out, options->max_depth, yap_flag, prec); Yap_plwrite(Yap_GetFromSlot(t PASS_REGS), options->out, options->max_depth, yap_flag, prec);
CurrentModule = old_module; CurrentModule = old_module;
return TRUE; return TRUE;
@ -609,7 +621,6 @@ PL_write_term(IOSTREAM *s, term_t term, int precedence, int flags)
options.flags = flags; options.flags = flags;
options.out = s; options.out = s;
options.module = MODULE_user; options.module = MODULE_user;
PutOpenToken(EOF, s); /* reset this */ PutOpenToken(EOF, s); /* reset this */
return writeTopTerm(term, precedence, &options); return writeTopTerm(term, precedence, &options);
} }

View File

@ -32,6 +32,7 @@ The following predicates construct a BDD:
bdd_print/3, bdd_print/3,
bdd_to_probability_sum_product/2, bdd_to_probability_sum_product/2,
bdd_to_probability_sum_product/3, bdd_to_probability_sum_product/3,
bdd_reorder/2,
bdd_close/1, bdd_close/1,
mtbdd_close/1]). mtbdd_close/1]).
@ -338,6 +339,14 @@ bdd_close(cudd(M,_,_Vars, _)) :-
bdd_close(add(M,_,_Vars, _)) :- bdd_close(add(M,_,_Vars, _)) :-
cudd_die(M). cudd_die(M).
/** @pred bdd_close( _BDDHandle_)
close the BDD and release any resources it holds.
*/
bdd_reorder(cudd(M,Top,_Vars, _), How) :-
cudd_reorder(M, Top,How).
/** @pred bdd_size(+ _BDDHandle_, - _Size_) /** @pred bdd_size(+ _BDDHandle_, - _Size_)
Unify _Size_ with the number of nodes in _BDDHandle_. Unify _Size_ with the number of nodes in _BDDHandle_.
@ -356,19 +365,23 @@ Output bdd _BDDHandle_ as a dot file to _File_.
*/ */
bdd_print(cudd(M,Top,_Vars, _), File) :- bdd_print(cudd(M,Top,_Vars, _), File) :-
cudd_print(M, Top, File). absolute_file_name(File, AFile, []),
cudd_print(M, Top, AFile).
bdd_print(add(M,Top,_Vars, _), File) :- bdd_print(add(M,Top,_Vars, _), File) :-
cudd_print(M, Top, File). absolute_file_name(File, AFile, []),
cudd_print(M, Top, AFile).
bdd_print(cudd(M,Top, Vars, _), File, Names) :- bdd_print(cudd(M,Top, Vars, _), File, Names) :-
Vars =.. [_|LVars], Vars =.. [_|LVars],
%trace, %trace,
maplist( fetch_name(Names), LVars, Ss), maplist( fetch_name(Names), LVars, Ss),
cudd_print(M, Top, File, Ss). absolute_file_name(File, AFile, []),
cudd_print(M, Top, AFile, Ss).
bdd_print(add(M,Top, Vars, _), File, Names) :- bdd_print(add(M,Top, Vars, _), File, Names) :-
Vars =.. [_|LVars], Vars =.. [_|LVars],
maplist( fetch_name(Names), LVars, Ss), maplist( fetch_name(Names), LVars, Ss),
cudd_print(M, Top, File, Ss). absolute_file_name(File, AFile, []),
cudd_print(M, Top, AFile, Ss).
fetch_name([S=V1|_], V2, SN) :- V1 == V2, !, fetch_name([S=V1|_], V2, SN) :- V1 == V2, !,
( atom(S) -> SN = S ; format(atom(SN), '~w', [S]) ). ( atom(S) -> SN = S ; format(atom(SN), '~w', [S]) ).

View File

@ -632,6 +632,13 @@ get_vars(YAP_Term t3)
return YAP_ArityOfFunctor(YAP_FunctorOfTerm(t3)); return YAP_ArityOfFunctor(YAP_FunctorOfTerm(t3));
} }
static YAP_Bool
p_cudd_reorder(void)
{
DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1);
return Cudd_ReduceHeap( manager, CUDD_REORDER_EXACT, 1);
}
static YAP_Bool static YAP_Bool
p_cudd_to_term(void) p_cudd_to_term(void)
{ {
@ -870,10 +877,12 @@ p_cudd_print_with_names(void)
DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1); DdManager *manager = (DdManager *)YAP_IntOfTerm(YAP_ARG1);
DdNode *n0 = (DdNode *)YAP_IntOfTerm(YAP_ARG2); DdNode *n0 = (DdNode *)YAP_IntOfTerm(YAP_ARG2);
const char *s = YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3)); const char *s = YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3));
const char **namesp; char **namesp;
YAP_Term names = YAP_ARG4; YAP_Term names = YAP_ARG4;
FILE *f; FILE *f;
YAP_Int len; YAP_Int len;
YAP_Int i = 0;
if (!strcmp(s, "user_output")) f = stdout; if (!strcmp(s, "user_output")) f = stdout;
else if (!strcmp(s, "user_error")) f = stderr; else if (!strcmp(s, "user_error")) f = stderr;
else if (!strcmp(s, "user")) f = stdout; else if (!strcmp(s, "user")) f = stdout;
@ -883,18 +892,34 @@ p_cudd_print_with_names(void)
if ((namesp = malloc(sizeof(const char *)*len)) == NULL) if ((namesp = malloc(sizeof(const char *)*len)) == NULL)
return FALSE; return FALSE;
while (YAP_IsPairTerm(names)) { while (YAP_IsPairTerm(names)) {
YAP_Int i = 0;
YAP_Term hd = YAP_HeadOfTerm( names); YAP_Term hd = YAP_HeadOfTerm( names);
char * s = YAP_AtomName(YAP_AtomOfTerm(hd)); const char *f;
const char *ns = malloc(strlen(s)+1);
if (YAP_IsAtomTerm(hd)) {
const char * s = YAP_AtomName(YAP_AtomOfTerm(hd));
char *ns = malloc(strlen(s)+1);
strncpy(ns, s, strlen(s)+1); strncpy(ns, s, strlen(s)+1);
namesp[i++] = ns; f = ns;
names = YAP_TailOfTerm( names); } else {
size_t sz =256;
char *s = malloc(sz+256);
while( !YAP_WriteBuffer(hd, s, sz-1, 0) ) {
sz+=1024;
s = realloc(s, sz);
} }
Cudd_DumpDot(manager, 1, &n0, (char **)namesp, NULL, f); f = s;
free( namesp ); }
names = YAP_TailOfTerm( names);
namesp[i++] = f;
}
Cudd_DumpDot(manager, 1, &n0, namesp, NULL, f);
if (f != stdout && f != stderr) if (f != stdout && f != stderr)
fclose(f); fclose(f);
while (i > 0) {
i--;
free(namesp[i]);
}
free( namesp );
return TRUE; return TRUE;
} }
@ -943,6 +968,7 @@ init_cudd(void)
FunctorCudd = YAP_MkFunctor(YAP_LookupAtom("cudd"), 1); FunctorCudd = YAP_MkFunctor(YAP_LookupAtom("cudd"), 1);
TermMinusOne = YAP_MkIntTerm(-1); TermMinusOne = YAP_MkIntTerm(-1);
TermPlusOne = YAP_MkIntTerm(+1); TermPlusOne = YAP_MkIntTerm(+1);
TermZero = YAP_MkIntTerm(0);
TermFalse = YAP_MkAtomTerm(YAP_LookupAtom("false")); TermFalse = YAP_MkAtomTerm(YAP_LookupAtom("false"));
TermTrue = YAP_MkAtomTerm(YAP_LookupAtom("true")); TermTrue = YAP_MkAtomTerm(YAP_LookupAtom("true"));
YAP_UserCPredicate("term_to_cudd", p_term_to_cudd, 3); YAP_UserCPredicate("term_to_cudd", p_term_to_cudd, 3);
@ -954,6 +980,7 @@ init_cudd(void)
YAP_UserCPredicate("cudd_to_probability_sum_product", p_cudd_to_p, 4); YAP_UserCPredicate("cudd_to_probability_sum_product", p_cudd_to_p, 4);
YAP_UserCPredicate("cudd_size", p_cudd_size, 3); YAP_UserCPredicate("cudd_size", p_cudd_size, 3);
YAP_UserCPredicate("cudd_die", p_cudd_die, 1); YAP_UserCPredicate("cudd_die", p_cudd_die, 1);
YAP_UserCPredicate("cudd_reorder", p_cudd_reorder, 2);
YAP_UserCPredicate("cudd_release_node", p_cudd_release_node, 2); YAP_UserCPredicate("cudd_release_node", p_cudd_release_node, 2);
YAP_UserCPredicate("cudd_print", p_cudd_print, 3); YAP_UserCPredicate("cudd_print", p_cudd_print, 3);
YAP_UserCPredicate("cudd_print", p_cudd_print_with_names, 4); YAP_UserCPredicate("cudd_print", p_cudd_print_with_names, 4);

View File

@ -57,31 +57,36 @@ MYDDAS_SOURCES= \
myddas_wkb2prolog.c myddas_wkb2prolog.c
MYDDAS_PROLOG= \ MYDDAS_PROLOG= \
$(srcdir)/pl/myddas.ypp \ myddas.ypp \
$(srcdir)/pl/myddas_assert_predicates.ypp \ myddas_assert_predicates.ypp \
$(srcdir)/pl/myddas_mysql.ypp \ myddas_mysql.ypp \
$(srcdir)/pl/myddas_sqlite3.ypp \ myddas_sqlite3.ypp \
$(srcdir)/pl/myddas_top_level.ypp \ myddas_top_level.ypp \
$(srcdir)/pl/myddas_errors.ypp \ myddas_errors.ypp \
$(srcdir)/pl/myddas_postgres.ypp \ myddas_postgres.ypp \
$(srcdir)/pl/myddas_prolog2sql.ypp \ myddas_prolog2sql.ypp \
$(srcdir)/pl/myddas_util_predicates.ypp \ myddas_util_predicates.ypp \
$(srcdir)/pl/myddas_prolog2sql_optimizer.ypp myddas_prolog2sql_optimizer.ypp
OBJS= $(MYDDAS_SOURCES:.c=.o) OBJS= $(MYDDAS_SOURCES:.c=.o)
MYDDAS_YAP= $(MYDDAS_PROLOG:.ypp=.yap)
SOBJS= myddas.@SO@ SOBJS= myddas.@SO@
#in some systems we just create a single object, in others we need to #in some systems we just create a single object, in others we need to
# create a libray # create a libray
all: $(SOBJS) all: $(SOBJS) $(MYDDAS_YAP)
.PRECIOUS: %.o .PRECIOUS: %.o %.yap
%.o: $(srcdir)/%.c %.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
%.yap: $(srcdir)/pl/%.ypp
cpp $(YAP_EXTRAS) -P -E -w $< -o $@
@DO_SECOND_LD@%.@SO@: $(OBJS) @DO_SECOND_LD@%.@SO@: $(OBJS)
@DO_SECOND_LD@ @SHLIB_LD@ $(LDFLAGS) -o $@ $(OBJS) @EXTRA_LIBS_FOR_DLLS@ @MYDDAS_LIBS@ @DO_SECOND_LD@ @SHLIB_LD@ $(LDFLAGS) -o $@ $(OBJS) @EXTRA_LIBS_FOR_DLLS@ @MYDDAS_LIBS@
@ -97,7 +102,7 @@ install_myddas:
mkdir -p $(DESTDIR)$(SHAREDIR); \ mkdir -p $(DESTDIR)$(SHAREDIR); \
for p in $(MYDDAS_PROLOG); \ for p in $(MYDDAS_PROLOG); \
do name=`basename $$p .ypp`; echo $$name;\ do name=`basename $$p .ypp`; echo $$name;\
cpp $(YAP_EXTRAS) -P -E -w $$p > $(DESTDIR)$(SHAREDIR)/$$name.yap; \ $(INSTALL_DATA) $$name.yap $(DESTDIR)$(SHAREDIR); \
done; \ done; \
fi fi

View File

@ -15,7 +15,7 @@
* * * *
*************************************************************************/ *************************************************************************/
#if USE_MYDDAS #if 1 //USE_MYDDAS
:- load_foreign_files([myddas], [], init_myddas). :- load_foreign_files([myddas], [], init_myddas).
@ -157,7 +157,7 @@ we were using Datalog.
The system includes four main blocks that are put together through the The system includes four main blocks that are put together through the
MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an
ODBC layer and a Prolog to SQL compiler. Current effort is put on the ODBC level and a Prolog to SQL compiler. Current effort is put on the
MySQL interface rather than on the ODBC interface. If you want to use MySQL interface rather than on the ODBC interface. If you want to use
the full power of the MYDDAS interface we recommend you to use a MySQL the full power of the MYDDAS interface we recommend you to use a MySQL
database. Other databases, such as Oracle, PostGres or Microsoft SQL database. Other databases, such as Oracle, PostGres or Microsoft SQL
@ -958,19 +958,15 @@ i_integer(X) =:= integer(X) \/ i_var(X) \/ err(integer(X)),
list( Protocol ) . list( Protocol ) .
/* /*
((Protocol = odbc) :- c_db_c_db_odbc_connect_connect ==> c_db_odbc_connect,
c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) ), c_db_my_connect ==> c_db_connect,
c_c_postgres_connect_connect ==> c_postgres_connect,
c_sqlite3_connect ==> sqlite3.
*/
((Protocol = mysql) :- %c_db_odbc_connect ==> i_atom( Password ) * i_atom( User ) *
c^c_db_my_connect(Host,User,Password,Db,Port,Socket,Handle)),
((Protocol = postgres) :- c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle)),
((Protocol = sqlite3) :-
c^c_sqlite3_connect(File,User,Password,Handle),
t_atom(File), i_atom(User)),
Protocol in [ mysql, postgres, odbc, sqlite3 ],
(- (c^c_sqlite3_connect(File,User,Password,Handle)) :- (c ^fail) ). (- (c^c_sqlite3_connect(File,User,Password,Handle)) :- (c ^fail) ).
@ -1029,21 +1025,16 @@ c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) +
c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle) + c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle) +
c^c_sqlite3_connect(File,User,Password,Handle). c^c_sqlite3_connect(File,User,Password,Handle).
*/ */
db_open(Protocol) :- true. db_open(Protocol) :- true.
#else #else
db_close:- db_open:-
db_close(myddas). db_open(myddas).
db_close(Connection):-
'$error_checks'(db_close(Connection)), db_open(Protocol) :-
get_value(Connection,Con), '$error_checks'(db_open(Protocol)),
'$abolish_all'(Con). get_value(Protocol,Con),
db_close(Connection) :-
'$error_checks'(db_close(Connection)),
get_value(Connection,Con),
c_db_connection_type(Con,ConType), c_db_connection_type(Con,ConType),
( ConType == mysql -> ( ConType == mysql ->
c_db_my_disconnect(Con) c_db_my_disconnect(Con)
@ -1054,7 +1045,7 @@ c_db_connection_type(Con,ConType),
; ;
c_db_odbc_disconnect(Con) c_db_odbc_disconnect(Con)
), ),
set_value(Connection,[]). % "deletes" atom set_value(Protocol,[]). % "deletes" atom
#endif #endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -1067,13 +1058,13 @@ set_value(Connection,[]). % "deletes" atom
% %
db_close:- db_close:-
db_close(myddas). db_close(myddas).
db_close(Connection):- db_close(Protocol):-
'$error_checks'(db_close(Connection)), '$error_checks'(db_close(Protocol)),
get_value(Connection,Con), get_value(Protocol,Con),
'$abolish_all'(Con). '$abolish_all'(Con).
db_close(Connection) :- db_close(Protocol) :-
'$error_checks'(db_close(Connection)), '$error_checks'(db_close(Protocol)),
get_value(Connection,Con), get_value(Protocol,Con),
c_db_connection_type(Con,ConType), c_db_connection_type(Con,ConType),
( ConType == mysql -> ( ConType == mysql ->
c_db_my_disconnect(Con) c_db_my_disconnect(Con)
@ -1084,7 +1075,7 @@ c_db_connection_type(Con,ConType),
; ;
c_db_odbc_disconnect(Con) c_db_odbc_disconnect(Con)
), ),
set_value(Connection,[]). % "deletes" atom set_value(Protocol,[]). % "deletes" atom
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -1135,14 +1126,14 @@ c_db_check_if_exists_pred(PredName,Arity,Module).
db_stats(List):- db_stats(List):-
db_stats(myddas,List). db_stats(myddas,List).
db_stats(Connection,List):- db_stats(Protocol,List):-
'$error_checks'(db_stats(Connection,List)), '$error_checks'(db_stats(Protocol,List)),
NumberOfStats = 10, NumberOfStats = 10,
'$make_a_list'(NumberOfStats,ListX1), '$make_a_list'(NumberOfStats,ListX1),
( var(Connection) -> ( var(Protocol) ->
c_db_stats(0,ListX1) c_db_stats(0,ListX1)
; ;
get_value(Connection,Conn), get_value(Protocol,Conn),
c_db_stats(Conn,ListX1) c_db_stats(Conn,ListX1)
), ),
'$make_stats_list'(ListX1,List). '$make_stats_list'(ListX1,List).
@ -1168,8 +1159,8 @@ c_db_stats_time(Reference,Time).
% %
%compatibility %compatibility
db_sql_select(Connection,SQL,LA):- db_sql_select(Protocol,SQL,LA):-
db_sql(Connection,SQL,LA). db_sql(Protocol,SQL,LA).
db_sql(SQL,LA):- db_sql(SQL,LA):-
db_sql(myddas,SQL,LA). db_sql(myddas,SQL,LA).

@ -1 +1 @@
Subproject commit b36fdac2281b7eef141095375d81456410dbcd2f Subproject commit 36f99e3c3c978fef25f899dc4fab1ffee334d73c

View File

@ -116,8 +116,7 @@ android/jni/yap_wrap.cpp: $(YAP_SWIG_INTERFACE) android/AndroidManifest.xml
$(SWIG) -c++ -java -I$(srcdir)/../../CXX -package pt.up.fc.dcc.yap -outdir android/src/pt/up/fc/dcc/yap -o $@ $< $(SWIG) -c++ -java -I$(srcdir)/../../CXX -package pt.up.fc.dcc.yap -outdir android/src/pt/up/fc/dcc/yap -o $@ $<
install-android: android install-android: android
adb uninstall pt.up.fc.dcc.yap adb install -r android/bin/JavaYap-debug.apk
adb install android/bin/JavaYap-debug.apk
R: R:

View File

@ -89,15 +89,19 @@ public class JavaYap extends Activity
} }
while (rc = q.next()) { while (rc = q.next()) {
if (BuildConfig.DEBUG) {
//Log.i(TAG, "q= "+vs0.text()+"\n");
}
YAPListTerm vs = vs0; YAPListTerm vs = vs0;
while(!vs.nil()){ while(!vs.nil()){
YAPTerm eq = vs.car(); YAPTerm eq = vs.car();
if (BuildConfig.DEBUG) {
Log.i(TAG, "q= "+vs0+"\n");
}
//outputText.append(Integer.toString(i) + ": " + eq.text() ); //outputText.append(Integer.toString(i) + ": " + eq.text() );
outputText.append(Integer.toString(i++) + ":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" ); outputText.append(Integer.toString(i++));
Log.i(TAG, "q= "+ eq.getArg(1)+"\n");
Log.i(TAG, "q= "+ eq.getArg(2)+"\n");
Log.i(TAG, "q= "+ eq.getArg(1).text()+"\n");
Log.i(TAG, "q= "+ eq.getArg(2).text()+"\n");
outputText.append(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" );
vs = vs.cdr(); vs = vs.cdr();
} }
} }