keep working on C++ interface.
This commit is contained in:
parent
53bb9928eb
commit
a2e141482c
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()
|
||||
|
Reference in New Issue
Block a user