Merge branch 'master' of ssh://git.code.sf.net/p/yap/yap-6.3
Conflicts: docs/doxygen.rc
This commit is contained in:
commit
f0d17d0210
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,7 +12,4 @@
|
||||
docs/yap.info*
|
||||
.build
|
||||
|
||||
.cproject
|
||||
.project
|
||||
.settings
|
||||
autom4te.cache
|
11
C/pl-yap.c
11
C/pl-yap.c
@ -1146,8 +1146,15 @@ X_API int PL_unify_int64__LD(term_t t, int64_t n ARG_LD)
|
||||
#else
|
||||
if ((long)n == n)
|
||||
return PL_unify_integer(t, n);
|
||||
fprintf(stderr,"Error in PL_unify_int64: please install GMP\n");
|
||||
return FALSE;
|
||||
// use a double, but will mess up writing.
|
||||
else {
|
||||
union {
|
||||
int64_t i;
|
||||
double d;
|
||||
} udi_;
|
||||
udi_.i = n;
|
||||
return PL_unify_float(t, udi_.d);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
530
CXX/yapi.cpp
530
CXX/yapi.cpp
@ -4,411 +4,411 @@
|
||||
#include "yapi.hh"
|
||||
|
||||
YAPAtomTerm::YAPAtomTerm(char *s) { // build string
|
||||
BACKUP_H();
|
||||
BACKUP_H();
|
||||
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_ATOM;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = MkAtomTerm(out.val.a);
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_ATOM;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = MkAtomTerm(out.val.a);
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
|
||||
YAPAtomTerm::YAPAtomTerm(char *s, size_t len) { // build string
|
||||
BACKUP_H();
|
||||
BACKUP_H();
|
||||
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_ATOM|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
|
||||
out.sz = len;
|
||||
out.max = len;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = MkAtomTerm(out.val.a);
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_ATOM|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
|
||||
out.sz = len;
|
||||
out.max = len;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = MkAtomTerm(out.val.a);
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
YAPAtomTerm::YAPAtomTerm(wchar_t *s): YAPTerm() { // build string
|
||||
BACKUP_H();
|
||||
BACKUP_H();
|
||||
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_ATOM;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = MkAtomTerm(out.val.a);
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_ATOM;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = MkAtomTerm(out.val.a);
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
|
||||
YAPAtomTerm::YAPAtomTerm(wchar_t *s, size_t len) : YAPTerm() { // build string
|
||||
BACKUP_H();
|
||||
BACKUP_H();
|
||||
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_ATOM|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
|
||||
out.sz = len;
|
||||
out.max = len;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = MkAtomTerm(out.val.a);
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_ATOM|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
|
||||
out.sz = len;
|
||||
out.max = len;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = MkAtomTerm(out.val.a);
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
|
||||
YAPStringTerm::YAPStringTerm(char *s) { // build string
|
||||
BACKUP_H();
|
||||
BACKUP_H();
|
||||
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_STRING;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = out.val.t;
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_STRING;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = out.val.t;
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
|
||||
YAPStringTerm::YAPStringTerm(char *s, size_t len) { // build string
|
||||
BACKUP_H();
|
||||
BACKUP_H();
|
||||
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_STRING|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
|
||||
out.sz = len;
|
||||
out.max = len;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = out.val.t;
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_STRING|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
|
||||
out.sz = len;
|
||||
out.max = len;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = out.val.t;
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
YAPStringTerm::YAPStringTerm(wchar_t *s): YAPTerm() { // build string
|
||||
BACKUP_H();
|
||||
BACKUP_H();
|
||||
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_STRING;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = out.val.t;
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_STRING;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = out.val.t;
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
|
||||
YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len) : YAPTerm() { // build string
|
||||
BACKUP_H();
|
||||
BACKUP_H();
|
||||
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_STRING|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
|
||||
out.sz = len;
|
||||
out.max = len;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = out.val.t;
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
CACHE_REGS
|
||||
seq_tv_t inp, out;
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
out.type = YAP_STRING_STRING|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
|
||||
out.sz = len;
|
||||
out.max = len;
|
||||
if (Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
t = out.val.t;
|
||||
else t = 0L;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
|
||||
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) : YAPTerm() {
|
||||
UInt arity = ArityOfFunctor(f.f);
|
||||
t = Yap_MkApplTerm( f.f, arity, (Term *)ts);
|
||||
UInt arity = ArityOfFunctor(f.f);
|
||||
t = Yap_MkApplTerm( f.f, arity, (Term *)ts);
|
||||
}
|
||||
|
||||
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm() {
|
||||
UInt arity = ArityOfFunctor(f.f);
|
||||
t = Yap_MkNewApplTerm( f.f, arity);
|
||||
UInt arity = ArityOfFunctor(f.f);
|
||||
t = Yap_MkNewApplTerm( f.f, arity);
|
||||
}
|
||||
|
||||
YAPTerm YAPApplTerm::getArg(unsigned int arg) {
|
||||
return YAPTerm( ArgOfTerm(arg, t) );
|
||||
return YAPTerm( ArgOfTerm(arg, t) );
|
||||
}
|
||||
|
||||
YAPFunctor YAPApplTerm::getFunctor() {
|
||||
return YAPFunctor( FunctorOfTerm(t) );
|
||||
return YAPFunctor( FunctorOfTerm(t) );
|
||||
}
|
||||
|
||||
YAPPairTerm::YAPPairTerm(YAPTerm th, YAPTerm tl) : YAPTerm() {
|
||||
CACHE_REGS
|
||||
t = MkPairTerm( th.t, tl.t);
|
||||
CACHE_REGS
|
||||
t = MkPairTerm( th.t, tl.t);
|
||||
}
|
||||
|
||||
YAPPairTerm::YAPPairTerm() : YAPTerm() {
|
||||
t = Yap_MkNewPairTerm( );
|
||||
t = Yap_MkNewPairTerm( );
|
||||
}
|
||||
|
||||
YAP_tag_t YAPTerm::tag() {
|
||||
if (IsVarTerm(t)) {
|
||||
CELL *pt = VarOfTerm(t);
|
||||
if (IsUnboundVar(pt)) {
|
||||
CACHE_REGS
|
||||
if (IsAttVar(pt))
|
||||
return YAP_TAG_ATT;
|
||||
return YAP_TAG_UNBOUND;
|
||||
}
|
||||
return YAP_TAG_REF;
|
||||
}
|
||||
if (IsPairTerm(t))
|
||||
return YAP_TAG_PAIR;
|
||||
if (IsAtomOrIntTerm(t)) {
|
||||
if (IsAtomTerm(t))
|
||||
return YAP_TAG_ATOM;
|
||||
return YAP_TAG_INT;
|
||||
} else {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
|
||||
if (IsExtensionFunctor(f)) {
|
||||
if (f == FunctorDBRef) {
|
||||
return YAP_TAG_DBREF;
|
||||
}
|
||||
if (f == FunctorLongInt) {
|
||||
return YAP_TAG_LONG_INT;
|
||||
}
|
||||
if (f == FunctorBigInt) {
|
||||
big_blob_type bt = (big_blob_type)RepAppl(t)[1];
|
||||
switch (bt) {
|
||||
case BIG_INT:
|
||||
return YAP_TAG_BIG_INT;
|
||||
case BIG_RATIONAL:
|
||||
return YAP_TAG_RATIONAL;
|
||||
default:
|
||||
return YAP_TAG_OPAQUE;
|
||||
if (IsVarTerm(t)) {
|
||||
CELL *pt = VarOfTerm(t);
|
||||
if (IsUnboundVar(pt)) {
|
||||
CACHE_REGS
|
||||
if (IsAttVar(pt))
|
||||
return YAP_TAG_ATT;
|
||||
return YAP_TAG_UNBOUND;
|
||||
}
|
||||
return YAP_TAG_REF;
|
||||
}
|
||||
if (IsPairTerm(t))
|
||||
return YAP_TAG_PAIR;
|
||||
if (IsAtomOrIntTerm(t)) {
|
||||
if (IsAtomTerm(t))
|
||||
return YAP_TAG_ATOM;
|
||||
return YAP_TAG_INT;
|
||||
} else {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
|
||||
if (IsExtensionFunctor(f)) {
|
||||
if (f == FunctorDBRef) {
|
||||
return YAP_TAG_DBREF;
|
||||
}
|
||||
if (f == FunctorLongInt) {
|
||||
return YAP_TAG_LONG_INT;
|
||||
}
|
||||
if (f == FunctorBigInt) {
|
||||
big_blob_type bt = (big_blob_type)RepAppl(t)[1];
|
||||
switch (bt) {
|
||||
case BIG_INT:
|
||||
return YAP_TAG_BIG_INT;
|
||||
case BIG_RATIONAL:
|
||||
return YAP_TAG_RATIONAL;
|
||||
default:
|
||||
return YAP_TAG_OPAQUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return YAP_TAG_APPL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return YAP_TAG_APPL;
|
||||
}
|
||||
}
|
||||
|
||||
YAPTerm YAPTerm::deepCopy() {
|
||||
Term tn;
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term tn;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
tn = Yap_CopyTerm(t);
|
||||
tn = Yap_CopyTerm(t);
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return new YAPTerm( tn );
|
||||
RECOVER_MACHINE_REGS();
|
||||
return new YAPTerm( tn );
|
||||
}
|
||||
|
||||
bool YAPTerm::exactlyEqual(YAPTerm t1) {
|
||||
int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_eq(Deref(t), Deref(t1.t));
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
out = Yap_eq(Deref(t), Deref(t1.t));
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
bool YAPTerm::unify(YAPTerm t1) {
|
||||
int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_unify(Deref(t), Deref(t1.t));
|
||||
out = Yap_unify(Deref(t), Deref(t1.t));
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
}
|
||||
|
||||
bool YAPTerm::unifiable(YAPTerm t1) {
|
||||
int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_Unifiable(Deref(t), Deref(t1.t));
|
||||
out = Yap_Unifiable(Deref(t), Deref(t1.t));
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
}
|
||||
|
||||
bool YAPTerm::variant(YAPTerm t1) {
|
||||
int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
int out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_Variant(Deref(t), Deref(t1.t));
|
||||
out = Yap_Variant(Deref(t), Deref(t1.t));
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
}
|
||||
|
||||
intptr_t YAPTerm::hash(size_t sz, size_t depth, bool variant) {
|
||||
Int out;
|
||||
Int out;
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_TermHash(t, sz, depth, variant);
|
||||
out = Yap_TermHash(t, sz, depth, variant);
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
char *YAPAtom::name(void) {
|
||||
if (IsWideAtom(a)) {
|
||||
// return an UTF-8 version
|
||||
size_t sz = 512;
|
||||
wchar_t * ptr = a->WStrOfAE;
|
||||
int ch = -1;
|
||||
char *s = new char[sz], *op = s;
|
||||
while (ch) {
|
||||
ch = *ptr++;
|
||||
utf8_put_char( op, ch );
|
||||
}
|
||||
sz = strlen(s)+1;
|
||||
char *os = new char[sz];
|
||||
memcpy(os, s, sz);
|
||||
delete s;
|
||||
return os;
|
||||
} else if (IsBlob(a)) {
|
||||
PL_blob_t *type = RepBlobProp(a->PropsOfAE)->blob_t;
|
||||
size_t sz = 512;
|
||||
if (IsWideAtom(a)) {
|
||||
// return an UTF-8 version
|
||||
size_t sz = 512;
|
||||
wchar_t * ptr = a->WStrOfAE;
|
||||
int ch = -1;
|
||||
char *s = new char[sz], *op = s;
|
||||
while (ch) {
|
||||
ch = *ptr++;
|
||||
utf8_put_char( op, ch );
|
||||
}
|
||||
sz = strlen(s)+1;
|
||||
char *os = new char[sz];
|
||||
memcpy(os, s, sz);
|
||||
delete s;
|
||||
return os;
|
||||
} else if (IsBlob(a)) {
|
||||
PL_blob_t *type = RepBlobProp(a->PropsOfAE)->blob_t;
|
||||
size_t sz = 512;
|
||||
|
||||
if (type->write) {
|
||||
char *s = new char[sz];
|
||||
IOSTREAM *stream = Sopenmem(&s, &sz, "w");
|
||||
stream->encoding = ENC_UTF8;
|
||||
atom_t at = YAP_SWIAtomFromAtom(AbsAtom(a));
|
||||
type->write(stream, at, 0);
|
||||
Sclose(stream);
|
||||
popOutputContext();
|
||||
sz = strlen(s)+1;
|
||||
char *os = new char[sz];
|
||||
memcpy(os, s, sz);
|
||||
delete s;
|
||||
return os;
|
||||
} else {
|
||||
char *s = new char[sz];
|
||||
if (type->write) {
|
||||
char *s = new char[sz];
|
||||
IOSTREAM *stream = Sopenmem(&s, &sz, "w");
|
||||
stream->encoding = ENC_UTF8;
|
||||
atom_t at = YAP_SWIAtomFromAtom(AbsAtom(a));
|
||||
type->write(stream, at, 0);
|
||||
Sclose(stream);
|
||||
popOutputContext();
|
||||
sz = strlen(s)+1;
|
||||
char *os = new char[sz];
|
||||
memcpy(os, s, sz);
|
||||
delete s;
|
||||
return os;
|
||||
} else {
|
||||
char *s = new char[sz];
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
snprintf(s, sz, "'%s'(%p)", AtomSWIStream->StrOfAE, a);
|
||||
snprintf(s, sz, "'%s'(%p)", AtomSWIStream->StrOfAE, a);
|
||||
#else
|
||||
snprintf(s, sz, "'%s'(0x%p)", AtomSWIStream->StrOfAE, a);
|
||||
snprintf(s, sz, "'%s'(0x%p)", AtomSWIStream->StrOfAE, a);
|
||||
#endif
|
||||
char *os = new char[sz];
|
||||
memcpy(os, s, sz);
|
||||
delete s;
|
||||
return os;
|
||||
}
|
||||
} else {
|
||||
return a->StrOfAE;
|
||||
}
|
||||
char *os = new char[sz];
|
||||
memcpy(os, s, sz);
|
||||
delete s;
|
||||
return os;
|
||||
}
|
||||
} else {
|
||||
return a->StrOfAE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
YAPQuery::initQuery( Term *t )
|
||||
{
|
||||
CACHE_REGS
|
||||
CACHE_REGS
|
||||
|
||||
this->oq = (YAPQuery *)LOCAL_execution;
|
||||
LOCAL_execution = (struct open_query_struct *)this;
|
||||
this->q_open=1;
|
||||
this->q_state=0;
|
||||
this->q_flags = 0;
|
||||
this->q_g = t;
|
||||
this->oq = (YAPQuery *)LOCAL_execution;
|
||||
LOCAL_execution = (struct open_query_struct *)this;
|
||||
this->q_open=1;
|
||||
this->q_state=0;
|
||||
this->q_flags = 0;
|
||||
this->q_g = t;
|
||||
}
|
||||
|
||||
|
||||
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm t[]): YAPPredicate(f, mod)
|
||||
{
|
||||
/* ignore flags for now */
|
||||
initQuery( (Term *)t );
|
||||
/* ignore flags for now */
|
||||
initQuery( (Term *)t );
|
||||
}
|
||||
|
||||
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm t[]): YAPPredicate(f)
|
||||
{
|
||||
/* ignore flags for now */
|
||||
initQuery( (Term *)t );
|
||||
/* ignore flags for now */
|
||||
initQuery( (Term *)t );
|
||||
}
|
||||
|
||||
YAPQuery::YAPQuery(YAPPredicate p, YAPTerm t[]): YAPPredicate(p.ap)
|
||||
{
|
||||
initQuery( (Term *)t );
|
||||
initQuery( (Term *)t );
|
||||
}
|
||||
|
||||
YAPQuery::YAPQuery(char *s): YAPPredicate(s, &this->q_g)
|
||||
{
|
||||
Term *t = this->q_g;
|
||||
Term *t = this->q_g;
|
||||
|
||||
initQuery( t );
|
||||
initQuery( t );
|
||||
}
|
||||
|
||||
|
||||
int YAPQuery::next()
|
||||
{
|
||||
CACHE_REGS
|
||||
int result;
|
||||
if (this->q_open != 1) return 0;
|
||||
if (setjmp(((YAPQuery *)LOCAL_execution)->q_env))
|
||||
return 0;
|
||||
// don't forget, on success these guys must create slots
|
||||
if (this->q_state == 0) {
|
||||
result = YAP_EnterGoal((YAP_PredEntryPtr)this->ap, this->q_g, &this->q_h);
|
||||
} else {
|
||||
LOCAL_AllowRestart = this->q_open;
|
||||
result = YAP_RetryGoal(&this->q_h);
|
||||
}
|
||||
this->q_state = 1;
|
||||
if (result == 0) {
|
||||
YAP_LeaveGoal(FALSE, &this->q_h);
|
||||
this->q_open = 0;
|
||||
}
|
||||
return result;
|
||||
CACHE_REGS
|
||||
int result;
|
||||
if (this->q_open != 1) return 0;
|
||||
if (setjmp(((YAPQuery *)LOCAL_execution)->q_env))
|
||||
return 0;
|
||||
// don't forget, on success these guys must create slots
|
||||
if (this->q_state == 0) {
|
||||
result = YAP_EnterGoal((YAP_PredEntryPtr)this->ap, this->q_g, &this->q_h);
|
||||
} else {
|
||||
LOCAL_AllowRestart = this->q_open;
|
||||
result = YAP_RetryGoal(&this->q_h);
|
||||
}
|
||||
this->q_state = 1;
|
||||
if (result == 0) {
|
||||
YAP_LeaveGoal(FALSE, &this->q_h);
|
||||
this->q_open = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void YAPQuery::cut()
|
||||
{
|
||||
CACHE_REGS
|
||||
CACHE_REGS
|
||||
|
||||
if (this->q_open != 1 || this->q_state == 0) return;
|
||||
YAP_LeaveGoal(FALSE, &this->q_h);
|
||||
this->q_open = 0;
|
||||
LOCAL_execution = (struct open_query_struct *)this->oq;
|
||||
if (this->q_open != 1 || this->q_state == 0) return;
|
||||
YAP_LeaveGoal(FALSE, &this->q_h);
|
||||
this->q_open = 0;
|
||||
LOCAL_execution = (struct open_query_struct *)this->oq;
|
||||
}
|
||||
|
||||
void YAPQuery::close()
|
||||
{
|
||||
CACHE_REGS
|
||||
CACHE_REGS
|
||||
|
||||
if (EX && !(this->q_flags & (PL_Q_CATCH_EXCEPTION))) {
|
||||
EX = NULL;
|
||||
}
|
||||
/* need to implement backtracking here */
|
||||
if (this->q_open != 1 || this->q_state == 0) {
|
||||
return;
|
||||
}
|
||||
YAP_LeaveGoal(FALSE, &this->q_h);
|
||||
this->q_open = 0;
|
||||
LOCAL_execution = (struct open_query_struct *)this->oq;
|
||||
if (EX && !(this->q_flags & (PL_Q_CATCH_EXCEPTION))) {
|
||||
EX = NULL;
|
||||
}
|
||||
/* need to implement backtracking here */
|
||||
if (this->q_open != 1 || this->q_state == 0) {
|
||||
return;
|
||||
}
|
||||
YAP_LeaveGoal(FALSE, &this->q_h);
|
||||
this->q_open = 0;
|
||||
LOCAL_execution = (struct open_query_struct *)this->oq;
|
||||
}
|
||||
|
||||
int YAPPredicate::call(YAPTerm t[])
|
||||
{
|
||||
YAPQuery q = YAPQuery(*this, t);
|
||||
int ret = q.next();
|
||||
q.cut();
|
||||
q.close();
|
||||
return ret;
|
||||
YAPQuery q = YAPQuery(*this, t);
|
||||
int ret = q.next();
|
||||
q.cut();
|
||||
q.close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
YAP::YAP(YAPParams const& params)
|
||||
YAPEngine::YAPEngine(YAPParams const& params)
|
||||
{ YAP_Init( (YAP_init_args *)¶ms.init_args ); }
|
||||
|
||||
|
||||
|
485
CXX/yapi.hh
485
CXX/yapi.hh
@ -1,9 +1,26 @@
|
||||
|
||||
#define YAP_CPP_INTERFACE 1
|
||||
|
||||
/**
|
||||
*
|
||||
* @defgroup yap-cplus-interface An object oriented interface for YAP.
|
||||
*
|
||||
*
|
||||
* @tableofcontents
|
||||
*
|
||||
*
|
||||
* C++ interface to YAP. Designed to be object oriented and to fit naturally
|
||||
* with the swig interface language generator. It uses ideas from the old YAP
|
||||
* interface and from the SWI foreign language interface.
|
||||
*
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if USE_GMP
|
||||
#include <gmp.h>
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
@ -43,271 +60,337 @@ extern "C" {
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
// taken from yap_structs.h
|
||||
// taken from yap_structs.h
|
||||
#include "iopreds.h"
|
||||
|
||||
// we cannot consult YapInterface.h, that conflicts with what we declare, though
|
||||
// it shouldn't
|
||||
}
|
||||
|
||||
//#include <vector>
|
||||
|
||||
class YAPEngine;
|
||||
class YAPTermHandle;
|
||||
class YAPAtom;
|
||||
class YAPFunctor;
|
||||
class YAPQuery;
|
||||
|
||||
/**
|
||||
* @brief Generic Prolog Term
|
||||
*/
|
||||
class YAPTerm {
|
||||
friend class YAPPredicate;
|
||||
friend class YAPTermHandle;
|
||||
friend class YAPApplTerm;
|
||||
friend class YAPPairTerm;
|
||||
friend class YAPPredicate;
|
||||
friend class YAPTermHandle;
|
||||
friend class YAPApplTerm;
|
||||
friend class YAPPairTerm;
|
||||
protected:
|
||||
Term t;
|
||||
Term t;
|
||||
public:
|
||||
YAPTerm() {} // do nothing constructor
|
||||
YAPTerm(int i) { CACHE_REGS t = MkIntegerTerm( i ); }
|
||||
YAPTerm(void *ptr) { CACHE_REGS t = MkIntegerTerm( (Int)ptr ); }
|
||||
YAPTerm(Term tn) { t = tn; }
|
||||
YAPTerm(char *s) { Term tp ; t = YAP_ReadBuffer(s,&tp); }
|
||||
YAPTerm() { t = TermNil; } // do nothing constructor
|
||||
YAPTerm(void *ptr) { CACHE_REGS t = MkIntegerTerm( (Int)ptr ); }
|
||||
YAPTerm(Term tn) { t = tn; }
|
||||
YAPTerm(char *s) { Term tp ; t = YAP_ReadBuffer(s,&tp); }
|
||||
|
||||
YAP_tag_t tag();
|
||||
YAPTerm deepCopy();
|
||||
bool exactlyEqual(YAPTerm t1);
|
||||
bool unify(YAPTerm t1);
|
||||
bool unifiable(YAPTerm t1);
|
||||
bool variant(YAPTerm t1);
|
||||
intptr_t hash(size_t sz, size_t depth, bool variant);
|
||||
bool isVar() { return IsVarTerm(t); }
|
||||
bool isAtom() { return IsAtomTerm(t); }
|
||||
bool isInteger() { return IsIntegerTerm(t); }
|
||||
bool isFloat() { return IsFloatTerm(t); }
|
||||
bool isCompound() { return !(IsVarTerm(t) || IsNumTerm(t)); }
|
||||
bool isAppl() { return IsApplTerm(t); }
|
||||
bool isPair() { return IsPairTerm(t); }
|
||||
bool isGround() { return Yap_IsGroundTerm(t); }
|
||||
bool isList() { return Yap_IsListTerm(t); }
|
||||
bool isString() { return IsStringTerm(t); }
|
||||
YAP_tag_t tag();
|
||||
YAPTerm deepCopy();
|
||||
bool exactlyEqual(YAPTerm t1);
|
||||
bool unify(YAPTerm t1);
|
||||
bool unifiable(YAPTerm t1);
|
||||
bool variant(YAPTerm t1);
|
||||
intptr_t hash(size_t sz, size_t depth, bool variant);
|
||||
bool isVar() { return IsVarTerm(t); }
|
||||
bool isAtom() { return IsAtomTerm(t); }
|
||||
bool isInteger() { return IsIntegerTerm(t); }
|
||||
bool isFloat() { return IsFloatTerm(t); }
|
||||
bool isCompound() { return !(IsVarTerm(t) || IsNumTerm(t)); }
|
||||
bool isAppl() { return IsApplTerm(t); }
|
||||
bool isPair() { return IsPairTerm(t); }
|
||||
bool isGround() { return Yap_IsGroundTerm(t); }
|
||||
bool isList() { return Yap_IsListTerm(t); }
|
||||
bool isString() { return IsStringTerm(t); }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Variable Term
|
||||
*/
|
||||
class YAPVarTerm: private YAPTerm {
|
||||
public:
|
||||
YAPVarTerm(): YAPTerm() { CACHE_REGS t = MkVarTerm(); }
|
||||
CELL *getVar() { return VarOfTerm(t); }
|
||||
bool unbound() { return IsUnboundVar(VarOfTerm(t)); }
|
||||
YAPVarTerm(): YAPTerm() { CACHE_REGS t = MkVarTerm(); }
|
||||
CELL *getVar() { return VarOfTerm(t); }
|
||||
bool unbound() { return IsUnboundVar(VarOfTerm(t)); }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Compound Term
|
||||
*/
|
||||
class YAPApplTerm: private YAPTerm {
|
||||
public:
|
||||
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
||||
YAPApplTerm(YAPFunctor f);
|
||||
YAPFunctor getFunctor();
|
||||
YAPTerm getArg(unsigned int i);
|
||||
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
||||
YAPApplTerm(YAPFunctor f);
|
||||
YAPFunctor getFunctor();
|
||||
YAPTerm getArg(unsigned int i);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief List Constructor Term
|
||||
*/
|
||||
class YAPPairTerm: private YAPTerm {
|
||||
public:
|
||||
YAPPairTerm(YAPTerm hd, YAPTerm tl);
|
||||
YAPPairTerm();
|
||||
YAPTerm getHead() { return YAPTerm(HeadOfTerm(t)); }
|
||||
YAPTerm getTail() { return YAPTerm(TailOfTerm(t)); }
|
||||
YAPPairTerm(YAPTerm hd, YAPTerm tl);
|
||||
YAPPairTerm();
|
||||
YAPTerm getHead() { return YAPTerm(HeadOfTerm(t)); }
|
||||
YAPTerm getTail() { return YAPTerm(TailOfTerm(t)); }
|
||||
};
|
||||
|
||||
class YAPAtom {
|
||||
friend class YAPPredicate;
|
||||
friend class YAPFunctor;
|
||||
friend class YAPAtomTerm;
|
||||
Atom a;
|
||||
/**
|
||||
* @brief Integer Term
|
||||
*/
|
||||
|
||||
class YAPIntegerTerm: private YAPTerm {
|
||||
public:
|
||||
YAPAtom( Atom at ) { a = at; }
|
||||
YAPAtom( char * s) { a = Yap_LookupAtom( s ); }
|
||||
YAPAtom( wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); }
|
||||
YAPAtom( char * s, size_t len) { a = Yap_LookupAtomWithLength( s, len ); }
|
||||
YAPAtom( wchar_t * s, size_t len) { a = Yap_LookupMaybeWideAtomWithLength( s, len ); }
|
||||
char *name(void);
|
||||
YAPIntegerTerm(intptr_t i) { CACHE_REGS t = MkIntegerTerm( i ); }
|
||||
intptr_t getInteger(YAPIntegerTerm t) { return IntegerOfTerm(t.t); }
|
||||
bool isTagged(YAPIntegerTerm i) { return IsIntTerm( t ); }
|
||||
};
|
||||
|
||||
/*
|
||||
class YAPListTerm: private YAPPairTerm {
|
||||
public:
|
||||
YAPListTerm(YAPTerm ts[], size_t n);
|
||||
YAPListTerm(Term ts[], size_t n);
|
||||
YAPListTerm( vector<YAPTerm> v );
|
||||
size_t length() { Term *tailp; return Yap_SkipList(&t, &tailp); }
|
||||
vector<YAPTerm> toVector();
|
||||
};
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Atom
|
||||
*/
|
||||
class YAPAtom {
|
||||
friend class YAPPredicate;
|
||||
friend class YAPFunctor;
|
||||
friend class YAPAtomTerm;
|
||||
Atom a;
|
||||
public:
|
||||
YAPAtom( Atom at ) { a = at; }
|
||||
YAPAtom( char * s) { a = Yap_LookupAtom( s ); }
|
||||
YAPAtom( wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); }
|
||||
YAPAtom( char * s, size_t len) { a = Yap_LookupAtomWithLength( s, len ); }
|
||||
YAPAtom( wchar_t * s, size_t len) { a = Yap_LookupMaybeWideAtomWithLength( s, len ); }
|
||||
char *name(void);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief String Term
|
||||
*/
|
||||
class YAPStringTerm: private YAPTerm {
|
||||
public:
|
||||
YAPStringTerm(char *s) ;
|
||||
YAPStringTerm(char *s, size_t len);
|
||||
YAPStringTerm(wchar_t *s) ;
|
||||
YAPStringTerm(wchar_t *s, size_t len);
|
||||
const char *getString() { return StringOfTerm(t); }
|
||||
YAPStringTerm(char *s) ;
|
||||
YAPStringTerm(char *s, size_t len);
|
||||
YAPStringTerm(wchar_t *s) ;
|
||||
YAPStringTerm(wchar_t *s, size_t len);
|
||||
const char *getString() { return StringOfTerm(t); }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Atom Term
|
||||
*/
|
||||
class YAPAtomTerm: private YAPTerm {
|
||||
public:
|
||||
YAPAtomTerm(YAPAtom a): YAPTerm() { t = MkAtomTerm(a.a); }
|
||||
YAPAtomTerm(Atom a): YAPTerm() { t = MkAtomTerm(a); }
|
||||
YAPAtomTerm(char *s) ;
|
||||
YAPAtomTerm(char *s, size_t len);
|
||||
YAPAtomTerm(wchar_t *s) ;
|
||||
YAPAtomTerm(wchar_t *s, size_t len);
|
||||
YAPAtom getAtom() { return YAPAtom(AtomOfTerm(t)); }
|
||||
YAPAtomTerm(YAPAtom a): YAPTerm() { t = MkAtomTerm(a.a); }
|
||||
YAPAtomTerm(Atom a): YAPTerm() { t = MkAtomTerm(a); }
|
||||
YAPAtomTerm(char *s) ;
|
||||
YAPAtomTerm(char *s, size_t len);
|
||||
YAPAtomTerm(wchar_t *s) ;
|
||||
YAPAtomTerm(wchar_t *s, size_t len);
|
||||
YAPAtom getAtom() { return YAPAtom(AtomOfTerm(t)); }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Functor
|
||||
*/
|
||||
class YAPFunctor {
|
||||
friend class YAPApplTerm;
|
||||
friend class YAPPredicate;
|
||||
Functor f;
|
||||
friend class YAPApplTerm;
|
||||
friend class YAPPredicate;
|
||||
Functor f;
|
||||
public:
|
||||
YAPFunctor( char * s, unsigned int arity) { f = Yap_MkFunctor( Yap_LookupAtom( s ), arity ); }
|
||||
YAPFunctor( wchar_t * s, unsigned int arity) { f = Yap_MkFunctor( Yap_LookupWideAtom( s ), arity ); }
|
||||
YAPFunctor( YAPAtom at, unsigned int arity) { f = Yap_MkFunctor( at.a, arity ); }
|
||||
YAPFunctor( Functor ff) { f = ff; }
|
||||
YAPFunctor( char * s, unsigned int arity) { f = Yap_MkFunctor( Yap_LookupAtom( s ), arity ); }
|
||||
YAPFunctor( wchar_t * s, unsigned int arity) { f = Yap_MkFunctor( Yap_LookupWideAtom( s ), arity ); }
|
||||
YAPFunctor( YAPAtom at, unsigned int arity) { f = Yap_MkFunctor( at.a, arity ); }
|
||||
YAPFunctor( Functor ff) { f = ff; }
|
||||
|
||||
Atom name(void) {
|
||||
return NameOfFunctor( f );
|
||||
}
|
||||
Atom name(void) {
|
||||
return NameOfFunctor( f );
|
||||
}
|
||||
|
||||
unsigned int arity(void) {
|
||||
return ArityOfFunctor( f );
|
||||
}
|
||||
unsigned int arity(void) {
|
||||
return ArityOfFunctor( f );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Term Handle
|
||||
*/
|
||||
class YAPTermHandle {
|
||||
long int handle;
|
||||
long int handle;
|
||||
public:
|
||||
YAPTermHandle(Term t) {
|
||||
CACHE_REGS
|
||||
handle = Yap_InitSlot(t PASS_REGS);
|
||||
}
|
||||
~YAPTermHandle(void) {
|
||||
CACHE_REGS
|
||||
Yap_RecoverSlots(1 PASS_REGS);
|
||||
}
|
||||
YAPTermHandle(Term t) {
|
||||
CACHE_REGS
|
||||
handle = Yap_InitSlot(t PASS_REGS);
|
||||
}
|
||||
~YAPTermHandle(void) {
|
||||
CACHE_REGS
|
||||
Yap_RecoverSlots(1 PASS_REGS);
|
||||
}
|
||||
|
||||
YAPTerm get() {
|
||||
CACHE_REGS
|
||||
return new YAPTerm( Yap_GetFromSlot(handle PASS_REGS) );
|
||||
}
|
||||
|
||||
void set(YAPTerm t) {
|
||||
CACHE_REGS
|
||||
Yap_PutInSlot(handle, t.t PASS_REGS);
|
||||
}
|
||||
YAPTerm get() {
|
||||
CACHE_REGS
|
||||
return new YAPTerm( Yap_GetFromSlot(handle PASS_REGS) );
|
||||
}
|
||||
|
||||
void set(YAPTerm t) {
|
||||
CACHE_REGS
|
||||
Yap_PutInSlot(handle, t.t PASS_REGS);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Predicate
|
||||
*/
|
||||
class YAPPredicate {
|
||||
friend class YAPQuery;
|
||||
PredEntry *ap;
|
||||
// trick to communicate t[] back to yapquery
|
||||
YAPPredicate(char *s, Term **th) {
|
||||
CACHE_REGS
|
||||
Term t, tp, m = CurrentModule ;
|
||||
t = YAP_ReadBuffer(s,&tp);
|
||||
t = Yap_StripModule(t, &m);
|
||||
if (IsVarTerm(t) || IsNumTerm(t))
|
||||
ap = NULL;
|
||||
if (IsAtomTerm(t)) {
|
||||
ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m));
|
||||
*th = NULL;
|
||||
} else if (IsApplTerm(t)) {
|
||||
ap = RepPredProp(PredPropByFunc(FunctorOfTerm(t), m));
|
||||
*th = RepAppl(t)+1;
|
||||
} else {
|
||||
ap = NULL;
|
||||
}
|
||||
}
|
||||
friend class YAPQuery;
|
||||
PredEntry *ap;
|
||||
// trick to communicate t[] back to yapquery
|
||||
YAPPredicate(char *s, Term **th) {
|
||||
CACHE_REGS
|
||||
Term t, tp, m = CurrentModule ;
|
||||
t = YAP_ReadBuffer(s,&tp);
|
||||
t = Yap_StripModule(t, &m);
|
||||
if (IsVarTerm(t) || IsNumTerm(t))
|
||||
ap = NULL;
|
||||
if (IsAtomTerm(t)) {
|
||||
ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m));
|
||||
*th = NULL;
|
||||
} else if (IsApplTerm(t)) {
|
||||
ap = RepPredProp(PredPropByFunc(FunctorOfTerm(t), m));
|
||||
*th = RepAppl(t)+1;
|
||||
} else {
|
||||
ap = NULL;
|
||||
}
|
||||
}
|
||||
public:
|
||||
YAPPredicate(PredEntry *pe) {
|
||||
ap = pe;
|
||||
}
|
||||
YAPPredicate(YAPFunctor f) {
|
||||
CACHE_REGS
|
||||
ap = RepPredProp(PredPropByFunc(f.f,CurrentModule));
|
||||
}
|
||||
YAPPredicate(YAPFunctor f, YAPTerm mod) {
|
||||
ap = RepPredProp(PredPropByFunc(f.f,mod.t));
|
||||
}
|
||||
YAPPredicate(YAPAtom at, YAPTerm mod) {
|
||||
ap = RepPredProp(PredPropByAtom(at.a,mod.t));
|
||||
}
|
||||
YAPPredicate(YAPAtom at) {
|
||||
CACHE_REGS
|
||||
ap = RepPredProp(PredPropByAtom(at.a,CurrentModule));
|
||||
}
|
||||
YAPPredicate(YAPAtom at, unsigned int arity, YAPTerm mod) {
|
||||
if (arity) {
|
||||
Functor f = Yap_MkFunctor(at.a, arity);
|
||||
ap = RepPredProp(PredPropByFunc(f,mod.t));
|
||||
} else {
|
||||
ap = RepPredProp(PredPropByAtom(at.a,mod.t));
|
||||
}
|
||||
}
|
||||
YAPPredicate(YAPAtom at, unsigned int arity) {
|
||||
CACHE_REGS
|
||||
if (arity) {
|
||||
Functor f = Yap_MkFunctor(at.a, arity);
|
||||
ap = RepPredProp(PredPropByFunc(f,CurrentModule));
|
||||
} else {
|
||||
ap = RepPredProp(PredPropByAtom(at.a,CurrentModule));
|
||||
}
|
||||
}
|
||||
YAPPredicate(char *s) {
|
||||
CACHE_REGS
|
||||
Term t, tp, m = CurrentModule ;
|
||||
t = YAP_ReadBuffer(s,&tp);
|
||||
t = Yap_StripModule(t, &m);
|
||||
if (IsVarTerm(t) || IsNumTerm(t))
|
||||
ap = NULL;
|
||||
if (IsAtomTerm(t)) {
|
||||
ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m));
|
||||
} else {
|
||||
ap = RepPredProp(PredPropByFunc(FunctorOfTerm(t), m));
|
||||
}
|
||||
}
|
||||
int call(YAPTerm ts[]);
|
||||
YAPPredicate(PredEntry *pe) {
|
||||
ap = pe;
|
||||
}
|
||||
YAPPredicate(YAPFunctor f) {
|
||||
CACHE_REGS
|
||||
ap = RepPredProp(PredPropByFunc(f.f,CurrentModule));
|
||||
}
|
||||
YAPPredicate(YAPFunctor f, YAPTerm mod) {
|
||||
ap = RepPredProp(PredPropByFunc(f.f,mod.t));
|
||||
}
|
||||
YAPPredicate(YAPAtom at, YAPTerm mod) {
|
||||
ap = RepPredProp(PredPropByAtom(at.a,mod.t));
|
||||
}
|
||||
YAPPredicate(YAPAtom at) {
|
||||
CACHE_REGS
|
||||
ap = RepPredProp(PredPropByAtom(at.a,CurrentModule));
|
||||
}
|
||||
YAPPredicate(YAPAtom at, unsigned int arity, YAPTerm mod) {
|
||||
if (arity) {
|
||||
Functor f = Yap_MkFunctor(at.a, arity);
|
||||
ap = RepPredProp(PredPropByFunc(f,mod.t));
|
||||
} else {
|
||||
ap = RepPredProp(PredPropByAtom(at.a,mod.t));
|
||||
}
|
||||
}
|
||||
YAPPredicate(YAPAtom at, unsigned int arity) {
|
||||
CACHE_REGS
|
||||
if (arity) {
|
||||
Functor f = Yap_MkFunctor(at.a, arity);
|
||||
ap = RepPredProp(PredPropByFunc(f,CurrentModule));
|
||||
} else {
|
||||
ap = RepPredProp(PredPropByAtom(at.a,CurrentModule));
|
||||
}
|
||||
}
|
||||
YAPPredicate(char *s) {
|
||||
CACHE_REGS
|
||||
Term t, tp, m = CurrentModule ;
|
||||
t = YAP_ReadBuffer(s,&tp);
|
||||
t = Yap_StripModule(t, &m);
|
||||
if (IsVarTerm(t) || IsNumTerm(t))
|
||||
ap = NULL;
|
||||
if (IsAtomTerm(t)) {
|
||||
ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m));
|
||||
} else {
|
||||
ap = RepPredProp(PredPropByFunc(FunctorOfTerm(t), m));
|
||||
}
|
||||
}
|
||||
int call(YAPTerm ts[]);
|
||||
};
|
||||
|
||||
/// interface to a YAP Query
|
||||
/// uses an SWI-like status info internally
|
||||
|
||||
/**
|
||||
* @brief Term Handle
|
||||
*
|
||||
* interface to a YAP Query;
|
||||
* uses an SWI-like status info internally.
|
||||
*/
|
||||
class YAPQuery: private YAPPredicate {
|
||||
int q_open;
|
||||
int q_state;
|
||||
Term *q_g;
|
||||
yamop *q_p, *q_cp;
|
||||
jmp_buf q_env;
|
||||
int q_flags;
|
||||
YAP_dogoalinfo q_h;
|
||||
YAPQuery *oq;
|
||||
void initQuery( Term *t );
|
||||
int q_open;
|
||||
int q_state;
|
||||
Term *q_g;
|
||||
yamop *q_p, *q_cp;
|
||||
jmp_buf q_env;
|
||||
int q_flags;
|
||||
YAP_dogoalinfo q_h;
|
||||
YAPQuery *oq;
|
||||
void initQuery( Term *t );
|
||||
public:
|
||||
/// full constructor, is given a functor, module, and an array of terms that must hav at least
|
||||
/// the same arity as the functor.
|
||||
YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm t[]);
|
||||
YAPQuery(YAPFunctor f, YAPTerm t[]);
|
||||
YAPQuery(YAPPredicate p, YAPTerm t[]);
|
||||
YAPQuery(char *s);
|
||||
// YAPQuery(YAPTerm t);
|
||||
int next();
|
||||
void cut();
|
||||
void close();
|
||||
/// full constructor, is given a functor, module, and an array of terms that must hav at least
|
||||
/// the same arity as the functor.
|
||||
YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm t[]);
|
||||
YAPQuery(YAPFunctor f, YAPTerm t[]);
|
||||
YAPQuery(YAPPredicate p, YAPTerm t[]);
|
||||
YAPQuery(char *s);
|
||||
// YAPQuery(YAPTerm t);
|
||||
int next();
|
||||
void cut();
|
||||
void close();
|
||||
};
|
||||
|
||||
class YAPParams;
|
||||
|
||||
class YAP {
|
||||
/**
|
||||
* @brief YAP Constructor
|
||||
*
|
||||
*/
|
||||
class YAPEngine {
|
||||
public:
|
||||
YAP(YAPParams const& params);
|
||||
YAPEngine(YAPParams const& params);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Parameters for YAP Constructor
|
||||
*
|
||||
*/
|
||||
class YAPParams {
|
||||
friend YAP;
|
||||
YAP_init_args init_args;
|
||||
friend class YAPEngine;
|
||||
YAP_init_args init_args;
|
||||
public:
|
||||
YAPParams();
|
||||
// sets all the default values for each data member
|
||||
YAPParams& savedState( char * f);
|
||||
YAPParams& stackSize(size_t sz);
|
||||
YAPParams& trailSize(size_t sz);
|
||||
YAPParams& maxStackSize(size_t sz);
|
||||
YAPParams& maxTrailSize(size_t sz);
|
||||
YAPParams& libDir(char *p);
|
||||
YAPParams& bootFile(char *f);
|
||||
YAPParams& goal(char *g);
|
||||
YAPParams& topLevel(char *g);
|
||||
YAPParams& script(bool v);
|
||||
YAPParams& fastBoot(bool v);
|
||||
YAPParams();
|
||||
// sets all the default values for each data member
|
||||
YAPParams& savedState( char * f);
|
||||
YAPParams& stackSize(size_t sz);
|
||||
YAPParams& trailSize(size_t sz);
|
||||
YAPParams& maxStackSize(size_t sz);
|
||||
YAPParams& maxTrailSize(size_t sz);
|
||||
YAPParams& libDir(char *p);
|
||||
YAPParams& bootFile(char *f);
|
||||
YAPParams& goal(char *g);
|
||||
YAPParams& topLevel(char *g);
|
||||
YAPParams& script(bool v);
|
||||
YAPParams& fastBoot(bool v);
|
||||
};
|
||||
|
||||
inline YAPParams::YAPParams()
|
||||
|
@ -373,21 +373,21 @@ Yap_unify_constant(register Term a, register Term cons)
|
||||
return(FALSE);
|
||||
if (IsExtensionFunctor(f)) {
|
||||
switch((CELL)f) {
|
||||
case (CELL)FunctorDBRef:
|
||||
case db_ref_e:
|
||||
return(a == cons);
|
||||
case (CELL)FunctorLongInt:
|
||||
case long_int_e:
|
||||
{
|
||||
CELL d0 = RepAppl(a)[1];
|
||||
CELL d1 = RepAppl(cons)[1];
|
||||
return d0 == d1;
|
||||
}
|
||||
case (CELL)FunctorDouble:
|
||||
case double_e:
|
||||
{
|
||||
Float d0 = FloatOfTerm(a);
|
||||
Float d1 = FloatOfTerm(cons);
|
||||
return d0 == d1;
|
||||
}
|
||||
case (CELL)FunctorBigInt:
|
||||
case big_int_e:
|
||||
#ifdef USE_GMP
|
||||
return (Yap_gmp_tcmp_big_big(a, cons) == 0);
|
||||
#endif /* USE_GMP */
|
||||
|
@ -542,7 +542,7 @@ INSTALLED_PACKAGES= \
|
||||
@PKG_LIBARCHIVE@ \
|
||||
@PKG_LTX2HTM@ \
|
||||
@PKG_ODBC@ \
|
||||
@PKG_PLDOC@ \
|
||||
\
|
||||
@PKG_PLUNIT@ \
|
||||
@PKG_REAL@ \
|
||||
@PKG_RDF@ \
|
||||
@ -550,7 +550,7 @@ INSTALLED_PACKAGES= \
|
||||
@PKG_SGML@ \
|
||||
@PKG_SWIG@ \
|
||||
@PKG_WINCONSOLE@ \
|
||||
@PKG_ZLIB@
|
||||
@PKG_ZLIB@ # @PKG_PLDOC@
|
||||
|
||||
PACKAGES= \
|
||||
library \
|
||||
|
18
configure
vendored
18
configure
vendored
@ -651,7 +651,7 @@ LTLIBOBJS
|
||||
LIBOBJS
|
||||
RAPTOR_CPPFLAGS
|
||||
RAPTOR_LDFLAGS
|
||||
ENABLE_RAPTOR
|
||||
PKG_RAPTOR
|
||||
LTX_PL
|
||||
_ACJNI_JAVAC
|
||||
JAVADOC
|
||||
@ -13426,9 +13426,9 @@ fi
|
||||
|
||||
if test "$yap_cv_raptor" = no
|
||||
then
|
||||
ENABLE_RAPTOR="@# "
|
||||
PKG_RAPTOR=""
|
||||
else
|
||||
ENABLE_RAPTOR=""
|
||||
PKG_RAPTOR="packages/raptor"
|
||||
fi
|
||||
|
||||
if test "$yap_cv_raptor" != no; then
|
||||
@ -13536,7 +13536,7 @@ RAPTOR_LDFLAGS="$LIBS"
|
||||
|
||||
if test "$raptor_available" = no
|
||||
then
|
||||
ENABLE_RAPTOR="@# "
|
||||
PKG_RAPTOR=""
|
||||
cat << EOF
|
||||
##################################################################
|
||||
# ERROR: Could not find raptor library. Either I don't have the
|
||||
@ -13544,7 +13544,7 @@ then
|
||||
##################################################################
|
||||
EOF
|
||||
else
|
||||
ENABLE_RAPTOR=""
|
||||
PKG_RAPTOR="packages/raptor"
|
||||
fi
|
||||
|
||||
|
||||
@ -15364,13 +15364,14 @@ if test "$PKG_SWIG" != ""; then
|
||||
mkdir -p packages/swig/python
|
||||
mkdir -p packages/swig/R
|
||||
mkdir -p packages/swig/java
|
||||
mkdir -p packages/swig/android
|
||||
mkdir -p packages/swig/src
|
||||
mkdir -p packages/swig/jni
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ac_config_files="$ac_config_files packages/swig/Makefile"
|
||||
ac_config_files="$ac_config_files packages/swig/Makefile packages/swig/jni/Android.mk"
|
||||
|
||||
fi
|
||||
|
||||
@ -15483,7 +15484,7 @@ fi
|
||||
|
||||
if test -d /usr/local/include/gecode; then
|
||||
CFLAGS="$CFLAGS -I/usr/local/include"
|
||||
SHLIB_CXXFLAGS="$SHLIB_CXXFLAGS -I/usr/local/include"
|
||||
SHLIB_CXX_FLAGS="$SHLIB_CXX_FLAGS -I/usr/local/include"
|
||||
GECODE_EXTRALIBS="-L/usr/local/lib"
|
||||
fi
|
||||
|
||||
@ -16706,6 +16707,7 @@ do
|
||||
"library/matlab/Makefile") CONFIG_FILES="$CONFIG_FILES library/matlab/Makefile" ;;
|
||||
"packages/python/Makefile") CONFIG_FILES="$CONFIG_FILES packages/python/Makefile" ;;
|
||||
"packages/swig/Makefile") CONFIG_FILES="$CONFIG_FILES packages/swig/Makefile" ;;
|
||||
"packages/swig/jni/Android.mk") CONFIG_FILES="$CONFIG_FILES packages/swig/jni/Android.mk" ;;
|
||||
"packages/cuda/Makefile") CONFIG_FILES="$CONFIG_FILES packages/cuda/Makefile" ;;
|
||||
"packages/gecode/Makefile") CONFIG_FILES="$CONFIG_FILES packages/gecode/Makefile" ;;
|
||||
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
||||
|
552
docs/doxygen.rc
552
docs/doxygen.rc
File diff suppressed because it is too large
Load Diff
39
docs/yap.tex
39
docs/yap.tex
@ -8804,8 +8804,7 @@ show the debugger commands.
|
||||
@item ! Query
|
||||
execute a query. YAP will not show the result of the query.
|
||||
@item b - break
|
||||
break active execution and launch a break level. This is the same as @code{!
|
||||
break}.
|
||||
break active execution and launch a break level. This is the same as @code{!break}.
|
||||
@item + - spy this goal
|
||||
start spying the active goal. The same as @code{! spy G} where @var{G}
|
||||
is the active goal.
|
||||
@ -8997,10 +8996,22 @@ type_of_verb(rest,passive).
|
||||
@node C-Interface,YAPLibrary,Efficiency,Top
|
||||
@chapter C Language interface to YAP
|
||||
|
||||
YAP provides the user with the necessary facilities for writing
|
||||
predicates in a language other than Prolog. Since, under Unix systems,
|
||||
most language implementations are link-able to C, we will describe here
|
||||
only the YAP interface to the C language.
|
||||
YAP provides the user with three facilities for writing
|
||||
predicates in a language other than Prolog. Under Unix systems,
|
||||
most language implementations were linkable to @code{C}, and the first interface exported the YAP machinery to the C language. YAP also implements most of the SWI-Prolog foreign language interface.
|
||||
This gives portability with a number of SWI-Prolog packages. Last, a new C++ based interface is
|
||||
being designed to work with the swig (@url(www.swig.org}) interface compiler.
|
||||
|
||||
@ifplaintext
|
||||
<ul>
|
||||
<li> The original YAP C-interface exports the YAP engine.
|
||||
</li>
|
||||
<li>The @subpage swi-c-interface emulates Jan Wielemaker's SWI foreign language interface.
|
||||
</li>
|
||||
<li>The @subpage yap-cplus-interface is desiged to interface with Object-Oriented systems.
|
||||
</li>
|
||||
</ul>
|
||||
@end ifplaintext
|
||||
|
||||
Before describing in full detail how to interface to C code, we will examine
|
||||
a brief example.
|
||||
@ -10110,8 +10121,8 @@ such references.
|
||||
|
||||
If the argument of the predicate is a variable, the routine initializes the
|
||||
structure to be preserved across backtracking with the information
|
||||
required to provide the next solution, and exits by calling @code{
|
||||
continue_n100} to provide that solution.
|
||||
required to provide the next solution, and exits by calling
|
||||
@code{continue_n100} to provide that solution.
|
||||
|
||||
If the argument was not a variable, the routine then checks if it was an
|
||||
integer, and if so, if its value is positive and less than 100. In that
|
||||
@ -10785,8 +10796,9 @@ succeed. On backtracking, the system will retry
|
||||
generating integers for ever. Immediate semantics were used in C-Prolog.
|
||||
|
||||
With logical update semantics, any additions or deletions of clauses
|
||||
for a goal @emph{will not affect previous activations of the
|
||||
goal}. In the example, the call to @code{assertz/1} will not see the
|
||||
for a goal
|
||||
@emph{will not affect previous activations of the goal}. In the example,
|
||||
the call to @code{assertz/1} will not see the
|
||||
update performed by the @code{assertz/1}, and the query will have a
|
||||
single solution.
|
||||
|
||||
@ -10858,9 +10870,10 @@ database, and not "logical update semantics", as per the standard,
|
||||
Calling @code{set_prolog_flag(update_semantics,logical)} will switch
|
||||
YAP to use logical update semantics.
|
||||
|
||||
@item By default, YAP implements the @code{atom_chars/2}
|
||||
(@pxref{Testing Terms}), and @code{number_chars/2}, (@pxref{Testing
|
||||
Terms}), built-ins as per the original Quintus Prolog definition, and
|
||||
@item By default, YAP implements the
|
||||
@code{atom_chars/2}(@pxref{Testing Terms}), and
|
||||
@code{number_chars/2}, (@pxref{Testing Terms}),
|
||||
built-ins as per the original Quintus Prolog definition, and
|
||||
not as per the ISO definition.
|
||||
|
||||
Calling @code{set_prolog_flag(to_chars_mode,iso)} will switch
|
||||
|
@ -9,6 +9,27 @@
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @defgroup swi-c-interface SWI-Prolog Foreign Language Interface.
|
||||
*
|
||||
*
|
||||
* @tableofcontents
|
||||
*
|
||||
* A reimplementation of Jan Wielemaker's SWI-Prolog C-language interface, it supports
|
||||
* most of the functionality in the original implementation. It allows for:
|
||||
*
|
||||
* - Term Construction, Access, and Unification
|
||||
* - Manipulation of Atoms, Strings, Lists of Codes and Lists of Atoms
|
||||
* - Query evaluation
|
||||
* - Thread and Prolog engine management
|
||||
* - Data-Base Access
|
||||
*
|
||||
* In this interface, all Prolog data known by C is referenced through term references (term_t), hence
|
||||
* Prolog has all the information necessary to perform its memory management without special precautions
|
||||
* from the C programmer.
|
||||
*/
|
||||
|
||||
#define PL_KERNEL 1
|
||||
|
||||
//=== includes ===============================================================
|
||||
@ -34,6 +55,10 @@
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#if !HAVE_SNPRINTF
|
||||
#define snprintf(X,Y,Z,A) sprintf(X,Z,A)
|
||||
#endif
|
||||
|
||||
#define PL_KERNEL 1
|
||||
|
||||
#include <pl-shared.h>
|
||||
@ -127,16 +152,25 @@ UserCPredicate(char *a, CPredicate def, unsigned long int arity, Term mod, int f
|
||||
CurrentModule = cm;
|
||||
}
|
||||
|
||||
/* SWI: void PL_agc_hook(void) */
|
||||
/** @defgroup swi-ATOMS Atom Construction
|
||||
* @ingroup swi-c-interface
|
||||
* @{
|
||||
* */
|
||||
|
||||
|
||||
/* SWI: void PL_agc_hook(void) */
|
||||
/** @brief Atom garbage collection hook
|
||||
*
|
||||
*/
|
||||
X_API PL_agc_hook_t
|
||||
PL_agc_hook(PL_agc_hook_t entry)
|
||||
{
|
||||
return (PL_agc_hook_t)YAP_AGCRegisterHook((YAP_agc_hook)entry);
|
||||
}
|
||||
|
||||
/* SWI: char* PL_atom_chars(atom_t atom)
|
||||
YAP: char* AtomName(Atom) */
|
||||
/** @brief extract the text representation from atom
|
||||
*
|
||||
*/
|
||||
X_API char* PL_atom_chars(atom_t a) /* SAM check type */
|
||||
{
|
||||
Atom at = SWIAtomToAtom(a);
|
||||
@ -145,8 +179,9 @@ X_API char* PL_atom_chars(atom_t a) /* SAM check type */
|
||||
return RepAtom(at)->StrOfAE;
|
||||
}
|
||||
|
||||
/* SWI: char* PL_atom_chars(atom_t atom)
|
||||
YAP: char* AtomName(Atom) */
|
||||
/** @brief extract the text representation from atom, including its length
|
||||
*
|
||||
*/
|
||||
X_API char* PL_atom_nchars(atom_t a, size_t *len) /* SAM check type */
|
||||
{
|
||||
char *s = RepAtom(SWIAtomToAtom(a))->StrOfAE;
|
||||
@ -154,15 +189,25 @@ X_API char* PL_atom_nchars(atom_t a, size_t *len) /* SAM check type */
|
||||
return s;
|
||||
}
|
||||
|
||||
/* SWI: term_t PL_copy_term_ref(term_t from)
|
||||
YAP: NO EQUIVALENT */
|
||||
/* SAM TO DO */
|
||||
/** @}
|
||||
*
|
||||
* @defgroup swi-term_references Term References
|
||||
* @ingroup swi-c-interface
|
||||
* @{
|
||||
* */
|
||||
|
||||
/** @brief duplicate a term reference
|
||||
*
|
||||
*/
|
||||
X_API term_t PL_copy_term_ref(term_t from)
|
||||
{
|
||||
CACHE_REGS
|
||||
return Yap_InitSlot(Yap_GetFromSlot(from PASS_REGS) PASS_REGS);
|
||||
}
|
||||
|
||||
/** @brief create a new term reference
|
||||
*
|
||||
*/
|
||||
X_API term_t PL_new_term_ref(void)
|
||||
{
|
||||
|
||||
@ -171,6 +216,10 @@ X_API term_t PL_new_term_ref(void)
|
||||
return to;
|
||||
}
|
||||
|
||||
/** @brief create several new term references
|
||||
*
|
||||
* @par n is the number of references
|
||||
*/
|
||||
X_API term_t PL_new_term_refs(int n)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -178,6 +227,9 @@ X_API term_t PL_new_term_refs(int n)
|
||||
return to;
|
||||
}
|
||||
|
||||
/** @brief dispose of all term references created since after
|
||||
*
|
||||
*/
|
||||
X_API void PL_reset_term_refs(term_t after)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -185,10 +237,50 @@ X_API void PL_reset_term_refs(term_t after)
|
||||
Yap_RecoverSlots(after-new PASS_REGS);
|
||||
}
|
||||
|
||||
/* begin PL_get_* functions =============================*/
|
||||
/** @}
|
||||
* @defgroup swi-term_manipulation Term Manipulation
|
||||
* @ingroup swi-c-interface
|
||||
* */
|
||||
|
||||
/* SWI: int PL_get_arg(int index, term_t t, term_t a)
|
||||
YAP: YAP_Term YAP_ArgOfTerm(int argno, YAP_Term t)*/
|
||||
/**
|
||||
* @defgroup swi-get-operations Reading Terms
|
||||
* @ingroup swi-term_manipulation
|
||||
* @{
|
||||
* */
|
||||
|
||||
/** @brief *name is assigned the name and *arity the arity if term ts, or the operaton fails.
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_name_arity(term_t ts, atom_t *name, int *arity)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (IsAtomTerm(t)) {
|
||||
*name = AtomToSWIAtom(AtomOfTerm(t));
|
||||
*arity = 0;
|
||||
return 1;
|
||||
}
|
||||
if (YAP_IsApplTerm(t)) {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (IsExtensionFunctor(f)) {
|
||||
return 0;
|
||||
}
|
||||
*name = AtomToSWIAtom(NameOfFunctor(f));
|
||||
*arity = ArityOfFunctor(f);
|
||||
return 1;
|
||||
}
|
||||
if (YAP_IsPairTerm(t)) {
|
||||
*name = AtomToSWIAtom(AtomDot);
|
||||
*arity = 2;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** @brief a is assigned the argument index from term ts
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_arg(int index, term_t ts, term_t a)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -211,8 +303,9 @@ X_API int PL_get_arg(int index, term_t ts, term_t a)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_arg(int index, term_t t, term_t a)
|
||||
YAP: YAP_Term YAP_ArgOfTerm(int argno, YAP_Term t)*/
|
||||
/** @brief *ap is assigned the name and *ip the arity from term ts
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_compound_name_arity(term_t ts, atom_t *ap, int *ip)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -237,6 +330,158 @@ X_API int PL_get_compound_name_arity(term_t ts, atom_t *ap, int *ip)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @brief *a is assigned the atom in term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_atom(term_t ts, atom_t *a)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( !IsAtomTerm(t))
|
||||
return 0;
|
||||
*a = AtomToSWIAtom(AtomOfTerm(t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @brief *i is assigned the int in term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
/* SWI: int PL_get_integer(term_t t, int *i)
|
||||
YAP: long int YAP_IntOfTerm(Term) */
|
||||
X_API int PL_get_integer(term_t ts, int *i)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (IsVarTerm(t) || !IsIntegerTerm(t) )
|
||||
return 0;
|
||||
*i = (int)IntegerOfTerm(t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @brief *i is assigned the boolean atom `true` or `false` in term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_long(term_t ts, long *i)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (!YAP_IsIntTerm(t) ) {
|
||||
if (YAP_IsFloatTerm(t)) {
|
||||
double dbl = YAP_FloatOfTerm(t);
|
||||
if (dbl - (long)dbl == 0.0) {
|
||||
*i = (long)dbl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*i = YAP_IntOfTerm(t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_bool(term_t t, int *i)
|
||||
YAP: long int YAP_AtomOfTerm(Term) */
|
||||
X_API int PL_get_bool(term_t ts, int *i)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
Atom at;
|
||||
|
||||
if (!IsAtomTerm(t) )
|
||||
return 0;
|
||||
at = AtomOfTerm(t);
|
||||
if (at == AtomTrue) {
|
||||
*i = TRUE;
|
||||
return 1;
|
||||
}
|
||||
if (at == AtomFalse) {
|
||||
*i = FALSE;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @brief *a is assigned the int64 in term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_int64(term_t ts, int64_t *i)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (!YAP_IsIntTerm(t) ) {
|
||||
if (YAP_IsFloatTerm(t)) {
|
||||
double dbl = YAP_FloatOfTerm(t);
|
||||
if (dbl - (int64_t)dbl == 0.0) {
|
||||
*i = (int64_t)dbl;
|
||||
return 1;
|
||||
}
|
||||
#if SIZEOF_INT_P==4 && !USE_GMP
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
int64_t i;
|
||||
} udbi_;
|
||||
udbi_.d = YAP_FloatOfTerm(t);
|
||||
*i = udbi_.i;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#if USE_GMP
|
||||
else if (YAP_IsBigNumTerm(t)) {
|
||||
MP_INT g;
|
||||
char s[64];
|
||||
YAP_BigNumOfTerm(t, (void *)&g);
|
||||
if (mpz_sizeinbase(&g,2) > 64) {
|
||||
return 0;
|
||||
}
|
||||
mpz_get_str (s, 10, &g);
|
||||
#ifdef _WIN32
|
||||
sscanf(s, "%I64d", (long long int *)i);
|
||||
#else
|
||||
sscanf(s, "%lld", (long long int *)i);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
*i = YAP_IntOfTerm(t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @brief *a is assigned the intptr_t in term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_intptr(term_t ts, intptr_t *a)
|
||||
{
|
||||
CACHE_REGS
|
||||
Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( !IsIntegerTerm(t) )
|
||||
return 0;
|
||||
*a = (intptr_t)(IntegerOfTerm(t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @brief *a is assigned the uintptr_t in term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_uintptr(term_t ts, uintptr_t *a)
|
||||
{
|
||||
CACHE_REGS
|
||||
Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( !IsIntegerTerm(t) )
|
||||
return 0;
|
||||
*a = (uintptr_t)(IntegerOfTerm(t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @brief a is assigned the argument index from term ts
|
||||
*
|
||||
*/
|
||||
X_API int _PL_get_arg(int index, term_t ts, term_t a)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -256,47 +501,11 @@ X_API int _PL_get_arg(int index, term_t ts, term_t a)
|
||||
Yap_PutInSlot(a,ArgOfTerm(index, t) PASS_REGS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* SWI: int PL_get_atom(term_t t, YAP_Atom *a)
|
||||
YAP: YAP_Atom YAP_AtomOfTerm(Term) */
|
||||
X_API int PL_get_atom(term_t ts, atom_t *a)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( !IsAtomTerm(t))
|
||||
return 0;
|
||||
*a = AtomToSWIAtom(AtomOfTerm(t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_atom(term_t t, YAP_Atom *a)
|
||||
YAP: YAP_Atom YAP_AtomOfTerm(Term) */
|
||||
X_API int PL_get_intptr(term_t ts, intptr_t *a)
|
||||
{
|
||||
CACHE_REGS
|
||||
Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( !IsIntegerTerm(t) )
|
||||
return 0;
|
||||
*a = (intptr_t)(IntegerOfTerm(t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_atom(term_t t, YAP_Atom *a)
|
||||
YAP: YAP_Atom YAP_AtomOfTerm(Term) */
|
||||
X_API int PL_get_uintptr(term_t ts, uintptr_t *a)
|
||||
{
|
||||
CACHE_REGS
|
||||
Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( !IsIntegerTerm(t) )
|
||||
return 0;
|
||||
*a = (uintptr_t)(IntegerOfTerm(t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_atom_chars(term_t t, char **s)
|
||||
YAP: char* AtomName(Atom) */
|
||||
/** @brief *a is assigned the string representation of the atom in term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_atom_chars(term_t ts, char **a) /* SAM check type */
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -307,8 +516,9 @@ X_API int PL_get_atom_chars(term_t ts, char **a) /* SAM check type */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_atom_chars(term_t t, char **s)
|
||||
YAP: char* AtomName(Atom) */
|
||||
/** @brief *a is assigned the string representation of the atom in term ts, and *len its size, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_atom_nchars(term_t ts, size_t *len, char **s) /* SAM check type */
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -320,38 +530,38 @@ X_API int PL_get_atom_nchars(term_t ts, size_t *len, char **s) /* SAM check typ
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
int PL_get_chars(term_t +t, char **s, unsigned flags) Convert the
|
||||
argument term t to a 0-terminated C-string. flags is a bitwise
|
||||
disjunction from two groups of constants. The first specifies which
|
||||
term-types should converted and the second how the argument is
|
||||
stored. Below is a specification of these constants. BUF_RING
|
||||
implies, if the data is not static (as from an atom), the data is
|
||||
copied to the next buffer from a ring of sixteen (16) buffers. This is a
|
||||
convenient way of converting multiple arguments passed to a foreign
|
||||
predicate to C-strings. If BUF_MALLOC is used, the data must be
|
||||
freed using free() when not needed any longer.
|
||||
/** PL_get_chars converts a term t to a string.
|
||||
*
|
||||
* From the SWI manual:
|
||||
*
|
||||
* int PL_get_chars(term_t +t, char **s, unsigned flags) Convert the
|
||||
* argument term t to a 0-terminated C-string. flags is a bitwise
|
||||
* disjunction from two groups of constants. The first specifies which
|
||||
* term-types should converted and the second how the argument is
|
||||
* stored. Below is a specification of these constants. BUF_RING
|
||||
* implies, if the data is not static (as from an atom), the data is
|
||||
* copied to the next buffer from a ring of sixteen (16) buffers. This is a
|
||||
* convenient way of converting multiple arguments passed to a foreign
|
||||
* predicate to C-strings. If BUF_MALLOC is used, the data must be
|
||||
* freed using free() when not needed any longer.
|
||||
|
||||
CVT_ATOM Convert if term is an atom
|
||||
CVT_STRING Convert if term is a string
|
||||
CVT_LIST Convert if term is a list of integers between 1 and 255
|
||||
CVT_INTEGER Convert if term is an integer (using %d)
|
||||
CVT_FLOAT Convert if term is a float (using %f)
|
||||
CVT_NUMBER Convert if term is a integer or float
|
||||
CVT_ATOMIC Convert if term is atomic
|
||||
CVT_VARIABLE Convert variable to print-name
|
||||
CVT_ALL Convert if term is any of the above, except for variables
|
||||
BUF_DISCARDABLE Data must copied immediately
|
||||
BUF_RING Data is stored in a ring of buffers
|
||||
BUF_MALLOC Data is copied to a new buffer returned by malloc(3)
|
||||
- CVT_ATOM Convert if term is an atom
|
||||
- CVT_STRING Convert if term is a string
|
||||
- CVT_LIST Convert if term is a list of integers between 1 and 255
|
||||
- CVT_INTEGER Convert if term is an integer (using %d)
|
||||
- CVT_FLOAT Convert if term is a float (using %f)
|
||||
- CVT_NUMBER Convert if term is a integer or float
|
||||
- CVT_ATOMIC Convert if term is atomic
|
||||
- CVT_VARIABLE Convert variable to print-name
|
||||
- CVT_ALL Convert if term is any of the above, except for variables
|
||||
- BUF_DISCARDABLE Data must copied immediately
|
||||
- BUF_RING Data is stored in a ring of buffers
|
||||
- BUF_MALLOC Data is copied to a new buffer returned by malloc(3)
|
||||
*/
|
||||
|
||||
#if !HAVE_SNPRINTF
|
||||
#define snprintf(X,Y,Z,A) sprintf(X,Z,A)
|
||||
#endif
|
||||
|
||||
/* SWI: int PL_get_functor(term_t t, functor_t *f)
|
||||
YAP: YAP_Functor YAP_FunctorOfTerm(Term) */
|
||||
/** @brief *f is assigned the functor of term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_functor(term_t ts, functor_t *f)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -364,10 +574,11 @@ X_API int PL_get_functor(term_t ts, functor_t *f)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_float(term_t t, double *f)
|
||||
YAP: double YAP_FloatOfTerm(Term) */
|
||||
/** @brief *f is assigned the floating point number of term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_float(term_t ts, double *f) /* SAM type check*/
|
||||
{
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( IsFloatTerm(t)) {
|
||||
@ -384,6 +595,9 @@ X_API int PL_get_float(term_t ts, double *f) /* SAM type check*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @brief *s is assigned the string representation of the string in term ts, and *len its size, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_string_chars(term_t t, char **s, size_t *len)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -396,7 +610,26 @@ X_API int PL_get_string_chars(term_t t, char **s, size_t *len)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/** @brief h is assigned the head of the pair term ts, and tl its tail, or the operation fails
|
||||
*
|
||||
*/
|
||||
|
||||
X_API int PL_get_list(term_t ts, term_t h, term_t tl)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (IsVarTerm(t) || !IsPairTerm(t) ) {
|
||||
return 0;
|
||||
}
|
||||
Yap_PutInSlot(h,HeadOfTerm(t) PASS_REGS);
|
||||
Yap_PutInSlot(tl,TailOfTerm(t) PASS_REGS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** @brief h is assigned the head of the pair term ts, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_head(term_t ts, term_t h)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -408,102 +641,28 @@ X_API int PL_get_head(term_t ts, term_t h)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @brief *s is assigned the string representation of the term ts, and *len its size, or the operation fails
|
||||
*
|
||||
*/
|
||||
X_API int PL_get_string(term_t t, char **s, size_t *len)
|
||||
{
|
||||
return PL_get_string_chars(t, s, len);
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_integer(term_t t, int *i)
|
||||
YAP: long int YAP_IntOfTerm(Term) */
|
||||
X_API int PL_get_integer(term_t ts, int *i)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (IsVarTerm(t) || !IsIntegerTerm(t) )
|
||||
return 0;
|
||||
*i = (int)IntegerOfTerm(t);
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
* */
|
||||
|
||||
/* SWI: int PL_get_bool(term_t t, int *i)
|
||||
YAP: long int YAP_AtomOfTerm(Term) */
|
||||
X_API int PL_get_bool(term_t ts, int *i)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
Atom at;
|
||||
|
||||
if (!IsAtomTerm(t) )
|
||||
return 0;
|
||||
at = AtomOfTerm(t);
|
||||
if (at == AtomTrue) {
|
||||
*i = TRUE;
|
||||
return 1;
|
||||
}
|
||||
if (at == AtomFalse) {
|
||||
*i = FALSE;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
X_API int PL_get_long(term_t ts, long *i)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (!YAP_IsIntTerm(t) ) {
|
||||
if (YAP_IsFloatTerm(t)) {
|
||||
double dbl = YAP_FloatOfTerm(t);
|
||||
if (dbl - (long)dbl == 0.0) {
|
||||
*i = (long)dbl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*i = YAP_IntOfTerm(t);
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* @defgroup swi-unify-operations Unifying Terms
|
||||
* @ingroup swi-term_manipulation
|
||||
* @{
|
||||
* */
|
||||
|
||||
|
||||
X_API int PL_get_int64(term_t ts, int64_t *i)
|
||||
{
|
||||
#if SIZE_OF_INT_P==8
|
||||
return PL_get_long(ts, (long *)i);
|
||||
#else
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (!YAP_IsIntTerm(t) ) {
|
||||
if (YAP_IsFloatTerm(t)) {
|
||||
double dbl = YAP_FloatOfTerm(t);
|
||||
if (dbl - (int64_t)dbl == 0.0) {
|
||||
*i = (int64_t)dbl;
|
||||
return 1;
|
||||
}
|
||||
#if USE_GMP
|
||||
} else if (YAP_IsBigNumTerm(t)) {
|
||||
MP_INT g;
|
||||
char s[64];
|
||||
YAP_BigNumOfTerm(t, (void *)&g);
|
||||
if (mpz_sizeinbase(&g,2) > 64) {
|
||||
return 0;
|
||||
}
|
||||
mpz_get_str (s, 10, &g);
|
||||
#ifdef _WIN32
|
||||
sscanf(s, "%I64d", (long long int *)i);
|
||||
#else
|
||||
sscanf(s, "%lld", (long long int *)i);
|
||||
#endif
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*i = YAP_IntOfTerm(t);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @brief t unifies with the true/false value in a.
|
||||
*
|
||||
*/
|
||||
X_API int PL_unify_bool(term_t t, int a)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -550,18 +709,6 @@ X_API int PL_unify_mpq(term_t t, mpq_t mpq)
|
||||
|
||||
#endif
|
||||
|
||||
X_API int PL_get_list(term_t ts, term_t h, term_t tl)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (IsVarTerm(t) || !IsPairTerm(t) ) {
|
||||
return 0;
|
||||
}
|
||||
Yap_PutInSlot(h,HeadOfTerm(t) PASS_REGS);
|
||||
Yap_PutInSlot(tl,TailOfTerm(t) PASS_REGS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_module(term_t t, module_t *m) */
|
||||
X_API int PL_get_module(term_t ts, module_t *m)
|
||||
{
|
||||
@ -585,34 +732,6 @@ X_API module_t PL_new_module(atom_t swiat)
|
||||
return Yap_GetModuleEntry(t);
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_atom(term_t t, YAP_Atom *a)
|
||||
YAP: YAP_Atom YAP_AtomOfTerm(Term) */
|
||||
X_API int PL_get_name_arity(term_t ts, atom_t *name, int *arity)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if (IsAtomTerm(t)) {
|
||||
*name = AtomToSWIAtom(AtomOfTerm(t));
|
||||
*arity = 0;
|
||||
return 1;
|
||||
}
|
||||
if (YAP_IsApplTerm(t)) {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (IsExtensionFunctor(f)) {
|
||||
return 0;
|
||||
}
|
||||
*name = AtomToSWIAtom(NameOfFunctor(f));
|
||||
*arity = ArityOfFunctor(f);
|
||||
return 1;
|
||||
}
|
||||
if (YAP_IsPairTerm(t)) {
|
||||
*name = AtomToSWIAtom(AtomDot);
|
||||
*arity = 2;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_atom(term_t t, YAP_Atom *a)
|
||||
YAP: YAP_Atom YAP_AtomOfTerm(Term) */
|
||||
X_API int PL_get_nil(term_t ts)
|
||||
@ -913,7 +1032,18 @@ X_API int PL_put_int64(term_t t, int64_t n)
|
||||
Yap_PutInSlot(t,YAP_MkBigNumTerm((void *)&rop) PASS_REGS);
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
// use a double, but will mess up writing.
|
||||
Int x = n;
|
||||
if (x == n)
|
||||
return PL_put_integer(t, x);
|
||||
else {
|
||||
union {
|
||||
int64_t i;
|
||||
double d;
|
||||
} udi_;
|
||||
udi_.i = n;
|
||||
return PL_put_float(t, udi_.d);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1134,8 +1264,15 @@ X_API int PL_unify_int64(term_t t, int64_t n)
|
||||
#else
|
||||
if ((long)n == n)
|
||||
return PL_unify_integer(t, n);
|
||||
fprintf(stderr,"Error in PL_unify_int64: please install GMP\n");
|
||||
return FALSE;
|
||||
// use a double, but will mess up writing.
|
||||
else {
|
||||
union {
|
||||
int64_t i;
|
||||
double d;
|
||||
} udi_;
|
||||
udi_.i = n;
|
||||
return PL_unify_float(t, udi_.d);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@ -1492,8 +1629,21 @@ int PL_unify_termv(term_t l, va_list ap)
|
||||
*pt++ = YAP_MkBigNumTerm((void *)&rop);
|
||||
}
|
||||
#else
|
||||
fprintf(stderr, "PL_unify_term: PL_int64 not supported\n");
|
||||
exit(1);
|
||||
{
|
||||
int64_t i = (Int)va_arg(ap, int64_t);
|
||||
intptr_t x = i;
|
||||
if (x == i)
|
||||
*pt++ = MkIntegerTerm( x );
|
||||
else {
|
||||
// use a double, but will mess up writing.
|
||||
union {
|
||||
int64_t i;
|
||||
double d;
|
||||
} udi_;
|
||||
udi_.i = i;
|
||||
*pt++ = MkFloatTerm(udi_.d);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case PL_FUNCTOR:
|
||||
@ -2406,13 +2556,15 @@ X_API int PL_is_inf(term_t st)
|
||||
{
|
||||
CACHE_REGS
|
||||
Term t = Deref(Yap_GetFromSlot(st PASS_REGS));
|
||||
Float fl;
|
||||
if (IsVarTerm(t)) return FALSE;
|
||||
if (!IsFloatTerm(t)) return FALSE;
|
||||
fl = FloatOfTerm(t);
|
||||
#if HAVE_ISINF
|
||||
Float fl;
|
||||
fl = FloatOfTerm(t);
|
||||
return isinf(fl);
|
||||
#elif HAVE_FPCLASS
|
||||
Float fl;
|
||||
fl = FloatOfTerm(t);
|
||||
return (fpclass(fl) == FP_NINF || fpclass(fl) == FP_PINF);
|
||||
#else
|
||||
return FALSE;
|
||||
|
37
library/listing.yap
Normal file
37
library/listing.yap
Normal file
@ -0,0 +1,37 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: listing.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: listing a prolog program *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/*
|
||||
|
||||
emulates listing.pl, but just the interface for now.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
:- module(swi_listing,
|
||||
[ listing/0,
|
||||
listing/1,
|
||||
portray_clause/1, % +Clause
|
||||
portray_clause/2, % +Stream, +Clause
|
||||
portray_clause/3 % +Stream, +Clause, +Options
|
||||
]).
|
||||
|
||||
|
||||
:- meta_predicate portray_clause( +, + , : ).
|
||||
|
||||
portray_clause(Stream, Term, M:Options) :-
|
||||
portray_clause( Stream, Term ).
|
2055
os/pl-read.c
2055
os/pl-read.c
File diff suppressed because it is too large
Load Diff
14
os/pl-text.c
14
os/pl-text.c
@ -717,12 +717,21 @@ represented.
|
||||
|
||||
static int
|
||||
wctobuffer(wchar_t c, mbstate_t *mbs, Buffer buf)
|
||||
{ char b[PL_MB_LEN_MAX];
|
||||
{
|
||||
#if __ANDROID__
|
||||
// wcrtomb & friends seems broken in android, just copy
|
||||
if ( c < 256 ) {
|
||||
addBuffer(buf, c, char);
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
#else
|
||||
char b[PL_MB_LEN_MAX];
|
||||
size_t n;
|
||||
|
||||
if ( (n=wcrtomb(b, c, mbs)) != (size_t)-1 )
|
||||
{ size_t i;
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
addBuffer(buf, b[i], char);
|
||||
|
||||
@ -730,6 +739,7 @@ wctobuffer(wchar_t c, mbstate_t *mbs, Buffer buf)
|
||||
}
|
||||
|
||||
return FALSE; /* cannot represent */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,6 +48,7 @@ CWFLAGS=
|
||||
CMFLAGS=@SHLIB_CFLAGS@
|
||||
CIFLAGS=
|
||||
CFLAGS=$(COFLAGS) $(CWFLAGS) $(CMFLAGS) $(CIFLAGS) $(PKGCFLAGS) @DEFS@
|
||||
CXXFLAGS= $(COFLAGS) $(CWFLAGS) @SHLIB_CXXFLAGS@ $(CIFLAGS) $(PKGCFLAGS) @DEFS@
|
||||
|
||||
LDSOFLAGS=@LDFLAGS@ $(PKGLDFLAGS)
|
||||
LDFLAGS=$(PKGLDFLAGS)
|
||||
|
@ -28,7 +28,6 @@ if test ! "$yap_cv_cplint" = "no"
|
||||
SHLIB_SUFFIX="so"
|
||||
fi
|
||||
PKG_CPLINT="packages/cplint packages/cplint/splipcase packages/cplint/approx/simplecuddLPADs"
|
||||
AC_SUBST(PKG_CPLINT)
|
||||
AC_SUBST(CPLINT_LIBS)
|
||||
AC_SUBST(CPLINT_CFLAGS)
|
||||
AC_SUBST(CPLINT_LDFLAGS)
|
||||
@ -38,6 +37,8 @@ else
|
||||
PKG_CPLINT=""
|
||||
fi
|
||||
|
||||
AC_SUBST(PKG_CPLINT)
|
||||
|
||||
mkdir -p packages/cplint
|
||||
mkdir -p packages/cplint/approx
|
||||
mkdir -p packages/cplint/approx/simplecuddLPADs
|
||||
|
@ -62,7 +62,7 @@ memory.o: $(srcdir)/memory.cu $(srcdir)/pred.h
|
||||
@DO_SECOND_LD@cuda.@SO@: $(OBJS)
|
||||
@DO_SECOND_LD@ @CUDA_SHLIB_LD@ $(CUDA_LDFLAGS) -o cuda.@SO@ $(OBJS)
|
||||
|
||||
install: all install-exampleS
|
||||
install: all install-examples
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)
|
||||
for h in $(BDD_PROLOG); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR); done
|
||||
$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(YAPLIBDIR)
|
||||
|
@ -23,7 +23,7 @@ SHAREDIR=$(ROOTDIR)/share
|
||||
#
|
||||
#
|
||||
CXX=@CXX@
|
||||
CXXFLAGS= @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) -I. -I$(srcdir) -I../.. -I$(srcdir)/../../include -I$(srcdir)/../../os -I "@GECODE_INCLUDES@"
|
||||
CXXFLAGS= @SHLIB_CXX_FLAGS@ $(YAP_EXTRAS) $(DEFS) -I. -I$(srcdir) -I../.. -I$(srcdir)/../../include -I$(srcdir)/../../os -I "@GECODE_INCLUDES@"
|
||||
#
|
||||
#
|
||||
# You shouldn't need to change what follows.
|
||||
|
@ -7,7 +7,7 @@ AC_ARG_ENABLE(gecode,
|
||||
dnl gecode is usually in /usr/local
|
||||
if test -d /usr/local/include/gecode; then
|
||||
CFLAGS="$CFLAGS -I/usr/local/include"
|
||||
SHLIB_CXXFLAGS="$SHLIB_CXXFLAGS -I/usr/local/include"
|
||||
SHLIB_CXX_FLAGS="$SHLIB_CXX_FLAGS -I/usr/local/include"
|
||||
GECODE_EXTRALIBS="-L/usr/local/lib"
|
||||
fi
|
||||
|
||||
|
@ -736,10 +736,14 @@ init_myddas(void)
|
||||
}
|
||||
#endif
|
||||
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
||||
#define stringify(X) _stringify(X)
|
||||
#define _stringify(X) #X
|
||||
Yap_REGS.MYDDAS_GLOBAL_POINTER = NULL;
|
||||
Yap_PutValue(AtomMyddasVersionName,
|
||||
MkAtomTerm(Yap_LookupAtom(MYDDAS_VERSION)));
|
||||
MkAtomTerm(Yap_LookupAtom(stringify(MYDDAS_VERSION))));
|
||||
Yap_HaltRegisterHook((HaltHookFunc)Yap_MYDDAS_delete_all_myddas_structs,NULL);
|
||||
#undef stringify
|
||||
#undef _stringify
|
||||
Yap_MYDDAS_delete_all_myddas_structs();
|
||||
#endif
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 0f77a1e1b90b36bddb1844712380f4f3858123b7
|
||||
Subproject commit 2436b3e2d13d3ca20e8b3ad4db0825b413dc0ed2
|
@ -31,11 +31,11 @@ python/yap_wrap.o: python/yap_wrap.c
|
||||
java: java/libyap.@SO@ java/yap.java
|
||||
cd java ; $(JAVAC) *.java; $(JAR) cvf yap.jar *.class
|
||||
|
||||
java/libyap.@SO@: java/yap_wrap.o
|
||||
java/libyap.@SO@: jni/yap_wrap.o
|
||||
$(CXX) -shared $(LDSOFLAGS) -L ../.. -lYap -o java/libyap.@SO@ ../../yapi.o java/yap_wrap.o $(LIBS) @JPLLDFLAGS@ -L ../.. -lYap -lpthread
|
||||
|
||||
java/yap_wrap.c: $(srcdir)/yap.i
|
||||
$(SWIG) -c++ -java -outdir java -o $@ $(DEFS) $(CPPFLAGS) -Wall $<
|
||||
jni/yap_wrap.c: $(srcdir)/yap.i
|
||||
$(SWIG) -c++ -java -package pt.up.fc.dcc.yap -outdir src/pt/up/fc/dcc/yap -o $@ $(DEFS) $(CPPFLAGS) -Wall $<
|
||||
|
||||
java/yap_wrap.o: java/yap_wrap.c
|
||||
$(CXX) -c $(CXXFLAGS) @JPLCFLAGS@ $< -o $@
|
||||
|
@ -24,12 +24,13 @@ if test "$PKG_SWIG" != ""; then
|
||||
mkdir -p packages/swig/python
|
||||
mkdir -p packages/swig/R
|
||||
mkdir -p packages/swig/java
|
||||
mkdir -p packages/swig/android
|
||||
mkdir -p packages/swig/src
|
||||
mkdir -p packages/swig/jni
|
||||
|
||||
AC_SUBST(SWIG)
|
||||
AC_SUBST(SWIG_TARGET)
|
||||
AC_SUBST(PKG_SWIG)
|
||||
|
||||
AC_CONFIG_FILES([ packages/swig/Makefile ])
|
||||
AC_CONFIG_FILES([ packages/swig/Makefile packages/swig/jni/Android.mk ])
|
||||
fi
|
||||
|
||||
|
9
packages/swig/jni/Android.mk.in
Normal file
9
packages/swig/jni/Android.mk.in
Normal file
@ -0,0 +1,9 @@
|
||||
# File: Android.mk
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := yap
|
||||
LOCAL_SRC_FILES := yap_wrap.c
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
@ -2,7 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "YAPInterface.h"
|
||||
#include "YapInterface.h"
|
||||
|
||||
static void init_yap( void );
|
||||
int yap_prove_string(char *s);
|
||||
|
@ -251,6 +251,9 @@ load_files(Files,Opts) :-
|
||||
( Val == false -> true ;
|
||||
Val == true -> true ;
|
||||
'$do_error'(domain_error(unimplemented_option,register(Val)),Call) ).
|
||||
'$process_lf_opt'('$context_module', Val, Call) :-
|
||||
( atom(File) -> true ; '$do_error'(type_error(atom,File),Call) ).
|
||||
|
||||
|
||||
'$lf_default_opts'(I, LastOpt, _TOpts) :- I > LastOpt, !.
|
||||
'$lf_default_opts'(I, LastOpt, TOpts) :-
|
||||
@ -372,12 +375,20 @@ module(Mod, Decls) :-
|
||||
use_module(M,F,Is) :-
|
||||
'$use_module'(M,F,Is).
|
||||
|
||||
'$use_module'(M,F,Is) :-
|
||||
var(Is), !,
|
||||
'$use_module'(M,F,all).
|
||||
'$use_module'(M,F,Is) :- nonvar(M), !,
|
||||
recorded('$module','$module'(F1,M,_,_),_),
|
||||
'$load_files'(F1, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is)),
|
||||
( F1 = F -> true ; true ).
|
||||
(
|
||||
recorded('$module','$module'(F1,M,_,_),_)
|
||||
->
|
||||
'$load_files'(F1, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is))
|
||||
),
|
||||
strip_module(F, _, F0),
|
||||
(var(F0) -> F0 = F1 ; absolute_file_name( F1, F0, [file_type(prolog)] ) ).
|
||||
'$use_module'(M,F,Is) :-
|
||||
'$load_files'(F, [if(not_loaded),must_be_module(true),imports(Is)], use_module(M,F,Is)).
|
||||
strip_module(F, M0, F0),
|
||||
'$load_files'(F0, [if(not_loaded),'$context_module'(M0),must_be_module(true),imports(Is)], use_module(M,F,Is)).
|
||||
|
||||
'$csult'(Fs, M) :-
|
||||
'$extract_minus'(Fs, MFs), !,
|
||||
|
Reference in New Issue
Block a user