This commit is contained in:
Vítor Santos Costa 2019-04-03 10:39:22 +01:00
parent 03232f53ce
commit 134288da68
5 changed files with 50 additions and 7 deletions

View File

@ -94,7 +94,9 @@ public:
/// get name of (other way) /// get name of (other way)
inline const char *text(void) { return getName(); } ; inline const char *text(void) { return getName(); } ;
/// get prop of type /// get prop of type
Prop getProp( PropTag tag ) { return Yap_GetAProp( a , (PropFlags)tag ); } Prop getProp( PropTag tag ) { return Yap_GetAProp( a , (PropFlags)tag ); };
/// as Atom
Atom asAtom() { return a; };
}; };
/** /**
@ -158,12 +160,15 @@ public:
/// Getter: extract name of functor as an atom /// Getter: extract name of functor as an atom
/// ///
/// this is for external usage. /// this is for external usage.
YAPAtom name(void) { return YAPAtom(NameOfFunctor(f)); } inline YAPAtom name() { return YAPAtom(NameOfFunctor(f)); };
/// Getter: extract arity of functor as an unsigned integer /// Getter: extract arity of functor as an unsigned integer
/// ///
/// this is for external usage. /// this is for external usage.
uintptr_t arity(void) { return ArityOfFunctor(f); } inline arity_t arity() { return ArityOfFunctor(f); };
/// Getter: extract functor as C pointer
///
/// inline Functor functor() { return f; };
}; };

View File

@ -744,6 +744,27 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
} }
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, Term ts[])
: YAPPredicate(f, mod) {
/* ignore flags for now */
BACKUP_MACHINE_REGS();
Term goal;
if (ts) {
size_t arity = f.arity();
goal = Yap_MkApplTerm(Yap_MkFunctor(f.name().asAtom(),arity), arity, ts);
nts = RepAppl(goal) + 1;
for (arity_t i = 0; i < arity; i++)
XREGS[i + 1] = ts[i];
} else {
goal = MkVarTerm();
}
openQuery();
names = YAPPairTerm(TermNil);
RECOVER_MACHINE_REGS();
}
#if 0 #if 0
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) { YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) {
/* ignore flags for now */ /* ignore flags for now */

View File

@ -76,6 +76,7 @@ public:
/// least /// least
/// the same arity as the functor. /// the same arity as the functor.
YAPQuery(YAPPredicate p, YAPTerm t[]); YAPQuery(YAPPredicate p, YAPTerm t[]);
///
/// full constructor, /// full constructor,
/// ///
/// ///
@ -83,6 +84,9 @@ public:
/// least /// least
/// the same arity as the functor. /// the same arity as the functor.
YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm t[]); YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm t[]);
/// often, this is more efficient
///
YAPQuery(YAPFunctor f, YAPTerm mod, Term t[]);
/// functor/term constructor, /// functor/term constructor,
/// ///
/// It is given a functor, and an array of terms that must have at least /// It is given a functor, and an array of terms that must have at least

View File

@ -57,9 +57,8 @@ setup_args = dict(
'Intended Audience :: Developers', 'Intended Audience :: Developers',
'Intended Audience :: System Administrators', 'Intended Audience :: System Administrators',
'Intended Audience :: Science/Research', 'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License', 'License :: OSI Approved :: Perl License',
'Programming Language :: Prolog', 'Programming Language :: Prolog',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
], ],
) )
@ -83,4 +82,5 @@ if 'setuptools' in sys.modules:
setup_args.update(setuptools_args) setup_args.update(setuptools_args)
if __name__ == '__main__': if __name__ == '__main__':
sys.path += ['../swig']
setup(**setup_args) setup(**setup_args)

View File

@ -40,7 +40,7 @@ public:
if (q) { if (q) {
q->close(); q->close();
q = NULL; q = nullptr;
} }
std::vector<Term> args = std::vector<Term>(); std::vector<Term> args = std::vector<Term>();
yhandle_t sls = Yap_NewHandles(sexps.length()); yhandle_t sls = Yap_NewHandles(sexps.length());
@ -49,8 +49,21 @@ public:
return false; return false;
args.push_back( Yap_GetFromSlot(sls+i) ); args.push_back( Yap_GetFromSlot(sls+i) );
} }
YAPTerm qt = YAPApplTerm(p_name,args); if (i==0) {
YAPTerm qt = YAPAtomTerm(p_name);
q = new YAPQuery(qt); q = new YAPQuery(qt);
} else {
YAPFunctor f= YAPFunctor(p_name, args.length());
YAPAtomTerm mod = YAPAtomTerm(p_module);
q = new YAPQuery(f,mod,args.data());
}
if (q == nullptr)
return false;
bool rc = q->next();
if (!rc) {
failed = true;
q = nullptr;
}
return true; return true;
} }