This commit is contained in:
Vitor Santos Costa 2017-09-06 01:16:36 +01:00
parent b5bfb638a3
commit 02a2bb0b0b
5 changed files with 743 additions and 762 deletions

View File

@ -24,7 +24,7 @@
*
* In a nutshell:
* - YAPAtom serves as the gateway to the data-base;
*
*
* - YAProp abstracts most data-base objects.
*
* - PropTag allows distinguishing the different classes of YAPProp.
@ -41,12 +41,12 @@ enum PropTag {
ARITHMETIC_PROPERTY_TAG = ExpProperty, // 0xFFE0,
/// map the atom to an integer
TRANSLATION_TAG = TranslationProperty, // 0xFFF4,
/// ensure the atom may not be garbafe colected
HOLD_TAG = HoldProperty, // 0xFFF6
/// ensure the atom may not be garbafe colected
HOLD_TAG = HoldProperty, // 0xFFF6
/// named mutEX
MUTEX_TAG = MutexProperty, // 0xFFF6,
/// A typed array, may be in-db or in-stack deped
ARRAY_TAG = ArrayProperty, // 0xFFF7,
ARRAY_TAG = ArrayProperty, // 0xFFF7,
/// module
MODULE_TAG = ModProperty, // 0xFFFA,
/// the original SICStus blackboard
@ -57,8 +57,8 @@ enum PropTag {
GLOBAL_VAR_TAG = GlobalProperty, // 0xFFFD
/// SWI-STYLE ATOM Extension
BLOB_TAG = BlobProperty, // 0xFFFE,
/// Prolog operator,
OPERATOR_TAG = OpProperty, // 0xFFFF,
/// Prolog operator,
OPERATOR_TAG = OpProperty, // 0xFFFF,
};
/**
@ -94,7 +94,7 @@ public:
/// get name of (other way)
inline const char *text(void) { return getName(); } ;
/// get prop of type
Prop getProp( PropTag tag ) { return Yap_GetAProp( a , (PropFlags)tag ); }
Prop getProp( PropTag tag ) { return Yap_GetAProp( a , (PropFlags)tag ); }
};
/**
@ -115,10 +115,9 @@ public:
/// get name of property
// virtual YAPAtom name();
virtual ~YAPProp() {};
};
#endif /* YAPA_HH */
#endif /* YAPA_HH */
/// @}

View File

@ -27,14 +27,12 @@ X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
}
static YAPEngine *curren;
YAPAtomTerm::YAPAtomTerm(char *s)
{ // build string
BACKUP_H();
CACHE_REGS
seq_tv_t inp, out;
seq_tv_t inp, out;
inp.val.c = s;
inp.type = YAP_STRING_CHARS;
out.type = YAP_STRING_ATOM;
@ -189,7 +187,6 @@ YAPApplTerm::YAPApplTerm(std::string f, std::vector<YAPTerm> ts)
mk(o);
}
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm()
{
BACKUP_H();
@ -652,20 +649,20 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
/* ignore flags for now */
BACKUP_MACHINE_REGS();
Term *nts;
Term tgoal;
Term goal;
if ( ts) {
goal = new YAPApplTerm(f, ts);
nts = RepAppl(goal->term())+1;
goal = YAPApplTerm(f, ts).term();
nts = RepAppl(goal)+1;
} else {
goal = new YAPVarTerm();
goal = MkVarTerm();
nts = nullptr;
}
openQuery(goal->term(), nts);
names = new YAPPairTerm();
RECOVER_MACHINE_REGS();
openQuery( nts);
names = YAPPairTerm( TermNil );
RECOVER_MACHINE_REGS();
}
#if 0
@ -674,14 +671,13 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) {
BACKUP_MACHINE_REGS();
CELL *nts;
if (ts) {
tgoal = YAPApplTerm(f, nts);
goal = YAPApplTerm(f, nts);
} else {
tgoal = YAPVarTerm();
goal = YAPVarTerm();
nts = nullptr;
}
*names = new YAPPairTerm();
*goal = new YAPTerm(tgoal);
openQuery(goal.term(), nts);
names = YAPPairTerm( TermNil );
openQuery(term(), nts);
RECOVER_MACHINE_REGS();
}
#endif
@ -695,15 +691,15 @@ YAPQuery::YAPQuery(YAPTerm t) : YAPPredicate(t)
if (IsApplTerm(tt)) {
Functor f = FunctorOfTerm(tt);
if (IsExtensionFunctor(f))
nts = nullptr;
nts = RepAppl(tt)+1;
nts = nullptr;
nts = RepAppl(goal.term())+1;
} else if (IsPairTerm(tt)) {
nts = RepPair(tt);
} else {
nts = nullptr;
}
names = new YAPPairTerm();
goal = new YAPTerm(t);
openQuery( nts);
names = YAPPairTerm( TermNil );
RECOVER_MACHINE_REGS();
}
@ -712,14 +708,15 @@ YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) {
BACKUP_MACHINE_REGS();
arity_t arity = p.ap->ArityOfPE;
if (arity) {
goal = new YAPApplTerm(YAPFunctor(p.ap->FunctorOfPred), ts);
for (arity_t i =0; i < arity; i++) {
XREGS[i + 1] = ts[i].term();
}
goal = YAPApplTerm(YAPFunctor(p.ap->FunctorOfPred), ts).term();
for (arity_t i =0; i < arity; i++)
XREGS[i+1]=ts[i].term();
openQuery( nullptr);
} else {
goal = new YAPAtomTerm((Atom)(p.ap->FunctorOfPred)); }
openQuery(goal->term(), nullptr);
names = new YAPPairTerm();
goal = YAPAtomTerm((Atom)(p.ap->FunctorOfPred));
openQuery(nullptr);
}
names = TermNil;
RECOVER_MACHINE_REGS();
}
@ -729,21 +726,13 @@ bool YAPQuery::next()
bool result = false;
sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
Term terr;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "next %d %ld",
q_state, LOCAL_CurSlot);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "next %d %s %ld",
q_state, names->text(), LOCAL_CurSlot);
if (ap == NULL || ap->OpcodeOfPred == UNDEF_OPCODE) {
ap = rewriteUndefQuery();
}
LOCAL_RestartEnv = &q_env;
try
try
{
BACKUP_MACHINE_REGS();
if (!q_open)
return false;
if (false && sigsetjmp(q_env, false))
LOCAL_RestartEnv = &buf;
if (sigsetjmp(*LOCAL_RestartEnv, false))
{
//throw YAPError();
return false;
@ -762,58 +751,60 @@ bool YAPQuery::next()
}
if (result)
{
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "names %d %s %ld",
q_state, names->text(), LOCAL_CurSlot);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %ld",
q_state, vnames.text(), LOCAL_CurSlot);
}
else
{
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "fail");
}
{
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "fail");
}
q_state = 1;
if ((terr = Yap_GetException()))
{
if ((terr = Yap_GetException()))
{
if ((terr = Yap_GetException()))
{
throw YAPError();
}
LOCAL_RestartEnv = &buf;
throw YAPError();
}
}
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
if (!result)
{
YAP_LeaveGoal(false, &q_h);
Yap_CloseHandles(q_handles);
q_open = false;
}
{
YAP_LeaveGoal(false, &q_h);
Yap_CloseHandles(q_handles);
q_open = false;
}
else
{
q_handles = Yap_StartSlots();
}
{
q_handles = Yap_StartSlots();
}
RECOVER_MACHINE_REGS();
LOCAL_RestartEnv = oldp;
return result;
}
catch (YAPError e)
{
q_open = false;
Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
memset(LOCAL_ActiveError, 0, sizeof(*LOCAL_ActiveError));
YAP_LeaveGoal(false, &q_h);
Yap_CloseHandles(q_handles);
q_open = false;
std::cerr << "Exception received by " << __func__ << "( " << YAPTerm(terr).text() << ").\n Forwarded...\n\n";
throw e;
}
{
q_open = false;
Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
memset(LOCAL_ActiveError, 0, sizeof(*LOCAL_ActiveError));
YAP_LeaveGoal(false, &q_h);
Yap_CloseHandles(q_handles);
q_open = false;
std::cerr << "Exception received by " << __func__ << "( " << YAPTerm(terr).text() << ").\n Forwarded...\n\n";
LOCAL_RestartEnv = oldp;
throw e;
}
}
PredEntry *
YAPQuery::rewriteUndefQuery()
{
Term ts[3];
ARG1 = ts[0] = goal->term();
ARG1 = ts[0] = goal.term();
ARG2 = ts[1] = ap->ModuleOfPred;
ARG3 = ts[2] = Yap_cp_as_integer(B PASS_REGS);
goal = new YAPApplTerm(FunctorUndefinedQuery, ts);
goal = YAPApplTerm(FunctorUndefinedQuery, ts);
return ap = PredUndefinedQuery;
}
@ -895,6 +886,39 @@ JNIEXPORT jint JNICALL JNI_MySQLOnLoad(JavaVM *vm, void *reserved)
return JNI_VERSION_1_6;
}
char *Yap_AndroidBufp;
static size_t Yap_AndroidMax, Yap_AndroidSz;
extern void (*Yap_DisplayWithJava)(int c);
void Yap_displayWithJava(int c)
{
char *ptr = Yap_AndroidBufp;
if (!ptr)
ptr = Yap_AndroidBufp = (char *)malloc(Yap_AndroidSz);
ptr[Yap_AndroidSz++] = c;
if (Yap_AndroidMax - 1 == Yap_AndroidSz)
{
if (Yap_AndroidMax < 32 * 1024)
{
Yap_AndroidMax *= 2;
}
else
{
Yap_AndroidMax += 32 * 1024;
}
Yap_AndroidBufp = (char *)realloc(ptr, Yap_AndroidMax);
}
Yap_AndroidBufp[Yap_AndroidSz] = '\0';
if (c == '\n')
{
Yap_AndroidBufp[Yap_AndroidSz] = '\0';
curren->run(Yap_AndroidBufp);
Yap_AndroidSz = 0;
}
}
#endif
@ -908,18 +932,22 @@ void YAPEngine::doInit(YAP_file_type_t BootMode)
/* Begin preprocessor code */
/* live */
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "initialize_prolog");
curren = this;
#if __ANDROID__
Yap_AndroidBufp = (char *)malloc(Yap_AndroidMax = 4096);
Yap_AndroidBufp[0] = '\0';
Yap_AndroidSz = 0;
#endif
//yerror = YAPError();
#if YAP_PYTHON
do_init_python();
do_init_python();
#endif
YAP_PredEntryPtr p = YAP_AtomToPred( YAP_LookupAtom("initialize_prolog") );
YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr);
if (initq.next())
{
initq.cut();
}
CurrentModule = TermUser;
YAP_PredEntryPtr p = YAP_AtomToPred( YAP_LookupAtom("initialize_prolog") );
YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr);
if (initq.next())
{
initq.cut();
}
CurrentModule = TermUser;
}

View File

@ -6,13 +6,12 @@
*/
#define YAP_CPP_INTERFACE 1
#include <gmpxx.h>
#include <vector>
#include <string>
#include <iostream>
#include <string>
#include <vector>
/*!
*
@ -71,26 +70,31 @@ extern "C" {
#endif
#if _MSC_VER || defined(__MINGW32__)
//#include <windows.h>
//#include <windows.h>
#endif
// taken from yap_structs.h
// taken from yap_structs.h
#include "iopreds.h"
X_API extern void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
X_API extern void YAP_UserCPredicate(const char *, YAP_UserCPred,
YAP_Arity arity);
/* extern void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity)
*/
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity,
YAP_Term);
/* extern void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int
* arity)
*/
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
YAP_Arity, YAP_Term);
X_API extern void UserBackCPredicate(const char *name, int *init(), int *cont(),
int arity, int extra);
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
X_API extern void UserBackCPredicate(const char *name, int *init(), int *cont(), int
arity, int extra);
#if YAP_PYTHON
#include <Python.h>
extern bool python_in_python;
extern bool python_in_python;
#endif
}

View File

@ -9,8 +9,8 @@
*
* @{
*
* These classes wrap engine and query. An engine is an environment where we
* can rum Prolog, that is, where we can run queries.
* These classes wrap engine and query. An engine is an environment where we can rum
* Prolog, that is, where we can run queries.
*
* Also, supports callbacks and engine configuration.
*
@ -31,7 +31,8 @@ class X_API YAPPredicate;
* interface to a YAP Query;
* uses an SWI-like status info internally.
*/
class X_API YAPQuery : public YAPPredicate {
class X_API YAPQuery : public YAPPredicate
{
bool q_open;
int q_state;
yhandle_t q_g, q_handles;
@ -40,34 +41,33 @@ class X_API YAPQuery : public YAPPredicate {
int q_flags;
YAP_dogoalinfo q_h;
YAPQuery *oq;
YAPPairTerm *names;
YAPTerm *goal;
YAPPairTerm names;
YAPTerm goal;
// temporaries
Term tnames, tgoal;
Term tnames, tgoal ;
inline void setNext() { // oq = LOCAL_execution;
// LOCAL_execution = this;
q_open = true;
q_state = 0;
q_flags = true; // PL_Q_PASS_EXCEPTION;
inline void setNext() { // oq = LOCAL_execution;
// LOCAL_execution = this;
q_open = true;
q_state = 0;
q_flags = true; // PL_Q_PASS_EXCEPTION;
q_p = P;
q_cp = CP;
// make sure this is safe
names = new YAPPairTerm();
goal = new YAPTerm();
q_handles = LOCAL_CurSlot;
};
q_p = P;
q_cp = CP;
// make sure this is safe
q_handles = LOCAL_CurSlot;
};
void openQuery(Term *ts);
PredEntry *rewriteUndefQuery();
void openQuery( Term *ts);
PredEntry *rewriteUndefQuery();
public:
YAPQuery() {
goal = TermTrue;
openQuery(nullptr);
};
YAPQuery() {
goal = TermTrue;
openQuery( nullptr);
};
/// main constructor, uses a predicate and an array of terms
///
/// It is given a YAPPredicate _p_ , and an array of terms that must have at
@ -85,29 +85,32 @@ public:
///
/// It is given a functor, and an array of terms that must have at least
/// the same arity as the functor. Works within the current module.
// YAPQuery(YAPFunctor f, YAPTerm t[]);
//YAPQuery(YAPFunctor f, YAPTerm t[]);
/// string constructor without varnames
///
/// It is given a string, calls the parser and obtains a Prolog term that
/// should be a callable
/// goal.
inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, tnames) {
inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, tnames)
{
CELL *qt = nullptr;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
LOCAL_CurSlot);
if (!ap)
return;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "ŸAPQuery");
if (IsPairTerm(tgoal)) {
qt = RepPair(tgoal);
tgoal =
Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("consult"), 1), 1, qt);
} else if (IsApplTerm(tgoal)) {
Functor f = FunctorOfTerm(tgoal);
if (!IsExtensionFunctor(f)) {
qt = RepAppl(tgoal) + 1;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
LOCAL_CurSlot);
if (!ap)
return;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
goal = YAPTerm(tgoal);
if (IsPairTerm(tgoal)) {
qt = RepPair(tgoal);
tgoal = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("consult"), 1),1,qt);
} else if (IsApplTerm(tgoal)) {
Functor f = FunctorOfTerm(tgoal);
if (!IsExtensionFunctor(f)) {
qt = RepAppl(tgoal)+1;
}
}
}
names = YAPPairTerm(tnames);
openQuery(qt);
};
// inline YAPQuery() : YAPPredicate(s, tgoal, tnames)
// {
@ -115,7 +118,7 @@ public:
// LOCAL_CurSlot);
// if (!ap)
// return;
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", names->text());
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
// goal = YAPTerm(tgoal);
// names = YAPPairTerm(tnames);
// openQuery(tgoal);
@ -128,37 +131,40 @@ public:
/// set flags for query execution, currently only for exception handling
void setFlag(int flag) { q_flags |= flag; }
/// reset flags for query execution, currently only for exception handling
void resetFlag(int flag) { q_flags &= ~flag; }
/// first query
///
/// actually implemented by calling the next();
inline bool first() { return next(); }
/// ask for the next solution of the current query
/// same call for every solution
bool next();
/// does this query have open choice-points?
/// or is it deterministic?
bool deterministic();
/// represent the top-goal
const char *text();
/// remove alternatives in the current search space, and finish tnamedyaphe
/// current query finish the current query: undo all bindings.
void close();
/// query variables.
void cut();
Term namedVars() { return names->term(); };
YAPPairTerm *namedYAPVars() { return names; };
/// query variables, but copied out
YAPTerm getTerm(yhandle_t t);
/// simple YAP Query;
/// just calls YAP and reports success or failure, Useful when we just
/// want things done, eg YAPCommand("load_files(library(lists), )")
inline bool command() {
bool rc = next();
close();
return rc;
};
void resetFlag(int flag) { q_flags &= ~flag; }
/// first query
///
/// actually implemented by calling the next();
inline bool first() { return next(); }
/// ask for the next solution of the current query
/// same call for every solution
bool next();
/// does this query have open choice-points?
/// or is it deterministic?
bool deterministic();
/// represent the top-goal
const char *text();
/// remove alternatives in the current search space, and finish the current
/// query
/// finish the current query: undo all bindings.
void close();
/// query variables.
void cut();
Term namedVars() {return names.term(); };
/// query variables, but copied out
std::vector<Term> namedVarsVector() {
return names.listToArray(); };
/// convert a ref to a binding.
YAPTerm getTerm(yhandle_t t);
/// simple YAP Query;
/// just calls YAP and reports success or failure, Useful when we just
/// want things done, eg YAPCommand("load_files(library(lists), )")
inline bool command()
{
bool rc = next();
close();
return rc;
};
};
// Java support
@ -166,96 +172,170 @@ public:
/// This class implements a callback Prolog-side. It will be inherited by the
/// Java or Python
/// class that actually implements the callback.
class X_API YAPCallback {
class X_API YAPCallback
{
public:
virtual ~YAPCallback() {}
virtual void run() { LOG("callback"); }
virtual void run(char *s) {}
};
/// @brief Setup all arguments to a new engine
class X_API YAPEngineArgs {
public:
YAP_init_args init_args;
inline void setEmbedded(bool fl) { init_args.Embedded = fl; };
inline void setEmbedded( bool fl )
{
init_args.Embedded = fl;
};
inline bool getEmbedded() { return init_args.Embedded; };
inline bool getEmbedded( )
{
return init_args.Embedded;
};
inline void setStackSize(bool fl) { init_args.StackSize = fl; };
inline void setStackSize( bool fl )
{
init_args.StackSize = fl;
};
inline bool getStackSize() { return init_args.StackSize; };
inline bool getStackSize( )
{
return init_args.StackSize;
};
inline void setTrailSize(bool fl) { init_args.TrailSize = fl; };
inline void setTrailSize( bool fl )
{
init_args.TrailSize = fl;
};
inline bool getTrailSize() { return init_args.TrailSize; };
inline bool getTrailSize( )
{
return init_args.TrailSize;
};
inline bool getMStackSize() { return init_args.StackSize; };
inline bool getMStackSize( )
{
return init_args.StackSize;
};
inline void setMaxTrailSize(bool fl) { init_args.MaxTrailSize = fl; };
inline void setMaxTrailSize( bool fl )
{
init_args.MaxTrailSize = fl;
};
inline bool getMaxTrailSize() { return init_args.MaxTrailSize; };
inline bool getMaxTrailSize( )
{
return init_args.MaxTrailSize;
};
inline void setYapLibDir(const char *fl) {
init_args.YapLibDir = (const char *)malloc(strlen(fl) + 1);
inline void setYapLibDir( const char * fl )
{
init_args.YapLibDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapLibDir, fl);
};
inline const char *getYapLibDir() { return init_args.YapLibDir; };
inline const char * getYapLibDir( )
{
return init_args.YapLibDir;
};
inline void setYapShareDir(const char *fl) {
init_args.YapShareDir = (const char *)malloc(strlen(fl) + 1);
inline void setYapShareDir( const char * fl )
{
init_args.YapShareDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapShareDir, fl);
};
inline const char *getYapShareDir() { return init_args.YapShareDir; };
inline const char * getYapShareDir( )
{
return init_args.YapShareDir;
};
inline void setSavedState(const char *fl) {
init_args.SavedState = (const char *)malloc(strlen(fl) + 1);
inline void setSavedState( const char * fl )
{
init_args.SavedState = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.SavedState, fl);
};
inline const char *getSavedState() { return init_args.SavedState; };
inline void setYapPrologBootFile(const char *fl) {
init_args.YapPrologBootFile = (const char *)malloc(strlen(fl) + 1);
strcpy((char *)init_args.YapPrologBootFile, fl);
inline const char * getSavedState( )
{
return init_args.SavedState;
};
inline const char *getYapPrologBootFile() {
inline void setYapPrologBootFile( const char * fl )
{
init_args.YapPrologBootFile = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapPrologBootFile, fl);
};
inline const char * getYapPrologBootFile( )
{
return init_args.YapPrologBootFile;
};
inline void setYapPrologGoal(const char *fl) {
inline void setYapPrologGoal( const char * fl )
{
init_args.YapPrologGoal = fl;
};
inline const char *getYapPrologGoal() { return init_args.YapPrologGoal; };
inline const char * getYapPrologGoal( )
{
return init_args.YapPrologGoal;
};
inline void setYapPrologTopLevelGoal(const char *fl) {
inline void setYapPrologTopLevelGoal( const char * fl )
{
init_args.YapPrologTopLevelGoal = fl;
};
inline const char *getYapPrologTopLevelGoal() {
inline const char * getYapPrologTopLevelGoal( )
{
return init_args.YapPrologTopLevelGoal;
};
inline void setHaltAfterConsult(bool fl) { init_args.HaltAfterConsult = fl; };
inline void setHaltAfterConsult( bool fl )
{
init_args.HaltAfterConsult = fl;
};
inline bool getHaltAfterConsult() { return init_args.HaltAfterConsult; };
inline bool getHaltAfterConsult( )
{
return init_args.HaltAfterConsult;
};
inline void setFastBoot(bool fl) { init_args.FastBoot = fl; };
inline void setFastBoot( bool fl )
{
init_args.FastBoot = fl;
};
inline bool getFastBoot() { return init_args.FastBoot; };
inline bool getFastBoot( )
{
return init_args.FastBoot;
};
inline void setArgc(int fl) { init_args.Argc = fl; };
inline void setArgc( int fl )
{
init_args.Argc = fl;
};
inline int getArgc() { return init_args.Argc; };
inline int getArgc( )
{
return init_args.Argc;
};
inline void setArgv(char **fl) { init_args.Argv = fl; };
inline void setArgv( char ** fl )
{
init_args.Argv = fl;
};
inline char **getArgv() { return init_args.Argv; };
inline char ** getArgv( )
{
return init_args.Argv;
};
YAPEngineArgs() {
Yap_InitDefaults(&init_args, NULL, 0, NULL);
@ -266,13 +346,15 @@ public:
};
};
/**
* @brief YAP Engine: takes care of the execution environment
where we can go executing goals.
*
*
*/
class YAPEngine {
class YAPEngine
{
private:
YAPEngineArgs *engine_args;
YAPCallback *_callback;
@ -281,29 +363,32 @@ private:
YAP_dogoalinfo q;
PredEntry *rewriteUndefEngineQuery(PredEntry *ap, Term t, Term tmod);
public:
/// construct a new engine; may use a variable number of arguments
YAPEngine(YAPEngineArgs *cargs) {
public :
/// construct a new engine; may use a variable number of arguments
YAPEngine(YAPEngineArgs *cargs)
{
engine_args = cargs;
// doInit(cargs->init_args.boot_file_type);
//doInit(cargs->init_args.boot_file_type);
doInit(YAP_QLY);
}; /// construct a new engine, including aaccess to callbacks
/// construct a new engine using argc/argv list of arguments
YAPEngine(int argc, char *argv[],
YAPCallback *callback = (YAPCallback *)NULL);
YAPCallback *callback = (YAPCallback *)NULL);
/// kill engine
~YAPEngine() { delYAPCallback(); };
/// remove current callback
void delYAPCallback() { _callback = 0; };
/// set a new callback
void setYAPCallback(YAPCallback *cb) {
void setYAPCallback(YAPCallback *cb)
{
delYAPCallback();
_callback = cb;
};
/// execute the callback.
////void run() { if (_callback) _callback.run(); }
/// execute the callback with a text argument.
void run(char *s) {
void run(char *s)
{
if (_callback)
_callback->run(s);
}
@ -330,20 +415,25 @@ public:
bool mgoal(Term t, Term tmod);
/// current directory for the engine
bool goal(Term t) { return mgoal(t, CurrentModule); }
bool goal(Term t)
{
return mgoal(t, CurrentModule);
}
/// reset Prolog state
void reSet();
/// assune that there are no stack pointers, just release memory
// for last execution
void release();
const char *currentDir() {
const char *currentDir()
{
char dir[1024];
std::string s = Yap_getcwd(dir, 1024 - 1);
return s.c_str();
};
/// report YAP version as a string
const char *version() {
const char *version()
{
std::string s = Yap_version();
return s.c_str();
};
@ -355,15 +445,16 @@ public:
Term fun(YAPTerm t) { return fun(t.term()); };
//> set a StringFlag, usually a path
//>
bool setStringFlag(std::string arg, std::string path) {
return setYapFlag(MkAtomTerm(Yap_LookupAtom(arg.data())),
MkAtomTerm(Yap_LookupAtom(path.data())));
bool setStringFlag(std::string arg, std::string path)
{
return setYapFlag(MkAtomTerm(Yap_LookupAtom(arg.data())), MkAtomTerm(Yap_LookupAtom(path.data())));
};
Term top_level(std::string s);
Term next_answer(YAPQuery *&Q);
};
Term top_level( std::string s);
Term next_answer(YAPQuery * &Q);
};
#endif /* YAPQ_HH */
/// @}
/// @}

File diff suppressed because it is too large Load Diff