support python interface.
This commit is contained in:
parent
5d6ff87d19
commit
b17f4967cb
@ -11,15 +11,18 @@ set (CXX_SOURCES
|
|||||||
|
|
||||||
list(APPEND LIBYAP_SOURCES ${CXX_SOURCES} PARENT_SCOPE)
|
list(APPEND LIBYAP_SOURCES ${CXX_SOURCES} PARENT_SCOPE)
|
||||||
|
|
||||||
if (ANDROID OR WIN32)
|
if ( WIN32)
|
||||||
add_component (Yap++ ${CXX_SOURCES} )
|
add_component (YAP++ ${CXX_SOURCES} )
|
||||||
else()
|
|
||||||
add_external (Yap++ ${CXX_SOURCES} )
|
|
||||||
MY_target_link_libraries(Yap++ ${CMAKE_DL_LIBS} libYap)
|
|
||||||
|
|
||||||
MY_install(TARGETS Yap++
|
set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE;YAP_KERNEL=1" )
|
||||||
LIBRARY DESTINATION ${libdir}
|
else()
|
||||||
ARCHIVE DESTINATION ${libdir}
|
add_external (YAP++ ${CXX_SOURCES} )
|
||||||
|
MY_target_link_libraries(YAP++ ${CMAKE_DL_LIBS} libYap)
|
||||||
|
|
||||||
|
MY_install(TARGETS YAP++
|
||||||
|
LIBRARY DESTINATION ${dlls}
|
||||||
|
RUNTIME DESTINATION ${dlls}
|
||||||
|
ARCHIVE DESTINATION ${dlls}
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -89,10 +89,11 @@ class YAPProp {
|
|||||||
PropTag tag( Prop p ) { return (PropTag)(p->KindOfPE); }
|
PropTag tag( Prop p ) { return (PropTag)(p->KindOfPE); }
|
||||||
public:
|
public:
|
||||||
/// get name of property
|
/// get name of property
|
||||||
virtual YAPAtom name() = 0;
|
// virtual YAPAtom name();
|
||||||
virtual ~YAPProp() {};
|
virtual ~YAPProp() {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* YAPA_HH */
|
#endif /* YAPA_HH */
|
||||||
|
|
||||||
|
19
CXX/yapdb.hh
19
CXX/yapdb.hh
@ -34,12 +34,12 @@ class YAPModule;
|
|||||||
*/
|
*/
|
||||||
class YAPModule : protected YAPAtomTerm {
|
class YAPModule : protected YAPAtomTerm {
|
||||||
friend class YAPPredicate;
|
friend class YAPPredicate;
|
||||||
|
friend class YAPModuleProp;
|
||||||
YAPModule(Term t) : YAPAtomTerm(t){};
|
YAPModule(Term t) : YAPAtomTerm(t){};
|
||||||
Term t() { return gt(); }
|
Term t() { return gt(); }
|
||||||
Term curModule() { CACHE_REGS return Yap_CurrentModule(); }
|
Term curModule() { CACHE_REGS return Yap_CurrentModule(); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~YAPModule(){};
|
|
||||||
YAPModule() : YAPAtomTerm(curModule()){};
|
YAPModule() : YAPAtomTerm(curModule()){};
|
||||||
YAPModule(YAPAtom t) : YAPAtomTerm(t){};
|
YAPModule(YAPAtom t) : YAPAtomTerm(t){};
|
||||||
};
|
};
|
||||||
@ -57,8 +57,8 @@ class YAPModuleProp : public YAPProp {
|
|||||||
YAPModuleProp(Term tmod) { m = Yap_GetModuleEntry(tmod); };
|
YAPModuleProp(Term tmod) { m = Yap_GetModuleEntry(tmod); };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
YAPModuleProp(YAPModule tmod) { m = Yap_GetModuleEntry(tmod.gt()); };
|
||||||
YAPModuleProp() { CACHE_REGS m = Yap_GetModuleEntry(Yap_CurrentModule()); };
|
YAPModuleProp() { CACHE_REGS m = Yap_GetModuleEntry(Yap_CurrentModule()); };
|
||||||
YAPModuleProp(YAPModule tmod);
|
|
||||||
virtual YAPModule module() { return YAPModule(m->AtomOfME); };
|
virtual YAPModule module() { return YAPModule(m->AtomOfME); };
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,7 +99,6 @@ public:
|
|||||||
inline YAPFunctor(const wchar_t *s, uintptr_t arity) {
|
inline YAPFunctor(const wchar_t *s, uintptr_t arity) {
|
||||||
CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity);
|
CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity);
|
||||||
}
|
}
|
||||||
~YAPFunctor(){};
|
|
||||||
/// 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.
|
||||||
@ -175,7 +174,6 @@ names = MkVarTerm ();
|
|||||||
inline YAPPredicate(PredEntry *pe) { ap = pe; }
|
inline YAPPredicate(PredEntry *pe) { ap = pe; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~YAPPredicate(){};
|
|
||||||
|
|
||||||
/// Functor constructor for predicates
|
/// Functor constructor for predicates
|
||||||
///
|
///
|
||||||
@ -256,6 +254,15 @@ public:
|
|||||||
return YAPAtom(NameOfFunctor(ap->FunctorOfPred));
|
return YAPAtom(NameOfFunctor(ap->FunctorOfPred));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// functor of predicate
|
||||||
|
///
|
||||||
|
/// onlu defined if arity >= 1
|
||||||
|
YAPFunctor functor() {
|
||||||
|
if (ap->ArityOfPE)
|
||||||
|
return YAPFunctor(ap->FunctorOfPred);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/// arity of predicate
|
/// arity of predicate
|
||||||
///
|
///
|
||||||
/// we return a positive number.
|
/// we return a positive number.
|
||||||
@ -273,10 +280,10 @@ public:
|
|||||||
YAPPrologPredicate(YAPTerm t) : YAPPredicate(t){};
|
YAPPrologPredicate(YAPTerm t) : YAPPredicate(t){};
|
||||||
YAPPrologPredicate(const char *s, arity_t arity) : YAPPredicate(s, arity){};
|
YAPPrologPredicate(const char *s, arity_t arity) : YAPPredicate(s, arity){};
|
||||||
/// add a new clause
|
/// add a new clause
|
||||||
void *assertClause(YAPTerm clause, bool last = true,
|
bool assertClause(YAPTerm clause, bool last = true,
|
||||||
YAPTerm source = YAPTerm());
|
YAPTerm source = YAPTerm());
|
||||||
/// add a new tuple
|
/// add a new tuple
|
||||||
void *assertFact(YAPTerm *tuple, bool last = true);
|
bool assertFact(YAPTerm *tuple, bool last = true);
|
||||||
/// retract at least the first clause matching the predicate.
|
/// retract at least the first clause matching the predicate.
|
||||||
void *retractClause(YAPTerm skeleton, bool all = false);
|
void *retractClause(YAPTerm skeleton, bool all = false);
|
||||||
/// return the Nth clause (if source is available)
|
/// return the Nth clause (if source is available)
|
||||||
|
518
CXX/yapi.cpp
518
CXX/yapi.cpp
File diff suppressed because it is too large
Load Diff
34
CXX/yapi.hh
34
CXX/yapi.hh
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <gmpxx.h>
|
#include <gmpxx.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
//! @{
|
//! @{
|
||||||
/**
|
/**
|
||||||
@ -67,38 +69,6 @@ extern "C" {
|
|||||||
// taken from yap_structs.h
|
// taken from yap_structs.h
|
||||||
#include "iopreds.h"
|
#include "iopreds.h"
|
||||||
|
|
||||||
#ifdef SWIGPYTHON
|
|
||||||
extern PyObject *yap_to_pythond(YAP_Term t, bool eval);
|
|
||||||
extern PyObject *term_to_python(yhandle_t t, bool eval);
|
|
||||||
extern PyObject *deref_term_to_python(yhandle_t t);
|
|
||||||
X_API bool init_python(void);
|
|
||||||
extern Term pythonToYAP(PyObject *p);
|
|
||||||
|
|
||||||
extern PyObject *py_Main;
|
|
||||||
|
|
||||||
extern inline PyObject *AtomToPy(const char *s) {
|
|
||||||
if (strcmp(s, "true") == 0)
|
|
||||||
return Py_True;
|
|
||||||
if (strcmp(s, "false") == 0)
|
|
||||||
return Py_False;
|
|
||||||
if (strcmp(s, "none") == 0)
|
|
||||||
return Py_None;
|
|
||||||
if (strcmp(s, "[]") == 0)
|
|
||||||
return PyList_New(0);
|
|
||||||
else if (strcmp(s, "{}") == 0)
|
|
||||||
return PyDict_New();
|
|
||||||
/* return __main__,s */
|
|
||||||
else if (PyObject_HasAttrString(py_Main, s)) {
|
|
||||||
return PyObject_GetAttrString(py_Main, s);
|
|
||||||
}
|
|
||||||
// no way to translate
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
X_API extern PyObject *yap_to_python(YAP_Term t, bool eval);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
|
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
|
||||||
|
|
||||||
/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity)
|
/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity)
|
||||||
|
13
CXX/yapie.hh
13
CXX/yapie.hh
@ -7,12 +7,17 @@ class YAPTerm;
|
|||||||
|
|
||||||
/// take information on a Prolog error:
|
/// take information on a Prolog error:
|
||||||
class YAPError {
|
class YAPError {
|
||||||
std::string name, errorClass, info;
|
yap_error_number ID;
|
||||||
|
std::string goal, info;
|
||||||
int swigcode;
|
int swigcode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// error handling when receiving the error term
|
YAPError(){
|
||||||
YAPError(){};
|
//ID = LOCAL_ActiveError->errorNo;
|
||||||
|
}
|
||||||
|
/// error handler object with initial data when receiving the error term
|
||||||
|
YAPError(yap_error_number id, YAPTerm culprit, std::string txt);
|
||||||
|
|
||||||
/// we just know the error number
|
/// we just know the error number
|
||||||
/// exact error ID
|
/// exact error ID
|
||||||
yap_error_number getID() { return LOCAL_ActiveError->errorNo; };
|
yap_error_number getID() { return LOCAL_ActiveError->errorNo; };
|
||||||
@ -27,7 +32,7 @@ public:
|
|||||||
/// the term that caused the bug
|
/// the term that caused the bug
|
||||||
// YAPTerm getCulprit(LOCAL_ActiveError->errorFile){};
|
// YAPTerm getCulprit(LOCAL_ActiveError->errorFile){};
|
||||||
/// text describing the Error
|
/// text describing the Error
|
||||||
const char *text();
|
std::string text();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
44
CXX/yapq.hh
44
CXX/yapq.hh
@ -13,12 +13,13 @@ class YAPPredicate;
|
|||||||
* interface to a YAP Query;
|
* interface to a YAP Query;
|
||||||
* uses an SWI-like status info internally.
|
* uses an SWI-like status info internally.
|
||||||
*/
|
*/
|
||||||
class YAPQuery : public YAPPredicate {
|
class YAPQuery : public YAPPredicate
|
||||||
|
{
|
||||||
bool q_open;
|
bool q_open;
|
||||||
int q_state;
|
int q_state;
|
||||||
yhandle_t q_g, q_handles;
|
yhandle_t q_g, q_handles;
|
||||||
struct yami *q_p, *q_cp;
|
struct yami *q_p, *q_cp;
|
||||||
jmp_buf q_env;
|
sigjmp_buf q_env;
|
||||||
int q_flags;
|
int q_flags;
|
||||||
YAP_dogoalinfo q_h;
|
YAP_dogoalinfo q_h;
|
||||||
YAPQuery *oq;
|
YAPQuery *oq;
|
||||||
@ -51,7 +52,8 @@ public:
|
|||||||
/// It is given a string, calls the parser and obtains a Prolog term that
|
/// It is given a string, calls the parser and obtains a Prolog term that
|
||||||
/// should be a callable
|
/// should be a callable
|
||||||
/// goal.
|
/// goal.
|
||||||
inline YAPQuery(const char *s) : YAPPredicate(s, goal, names) {
|
inline YAPQuery(const char *s) : YAPPredicate(s, goal, names)
|
||||||
|
{
|
||||||
BACKUP_H();
|
BACKUP_H();
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
|
||||||
LOCAL_CurSlot);
|
LOCAL_CurSlot);
|
||||||
@ -65,7 +67,8 @@ public:
|
|||||||
///
|
///
|
||||||
/// It is given an atom, and a Prolog term that should be a callable
|
/// It is given an atom, and a Prolog term that should be a callable
|
||||||
/// goal, say `main`, `init`, `live`.
|
/// goal, say `main`, `init`, `live`.
|
||||||
inline YAPQuery(YAPAtom g) : YAPPredicate(g) {
|
inline YAPQuery(YAPAtom g) : YAPPredicate(g)
|
||||||
|
{
|
||||||
goal = YAPAtomTerm(g).gt();
|
goal = YAPAtomTerm(g).gt();
|
||||||
names = TermNil;
|
names = TermNil;
|
||||||
openQuery();
|
openQuery();
|
||||||
@ -89,10 +92,10 @@ public:
|
|||||||
const char *text();
|
const char *text();
|
||||||
/// remove alternatives in the current search space, and finish the current
|
/// remove alternatives in the current search space, and finish the current
|
||||||
/// query
|
/// query
|
||||||
void cut();
|
|
||||||
/// finish the current query: undo all bindings.
|
/// finish the current query: undo all bindings.
|
||||||
void close();
|
void close();
|
||||||
/// query variables.
|
/// query variables.
|
||||||
|
void cut();
|
||||||
Term namedVars();
|
Term namedVars();
|
||||||
/// query variables, but copied out
|
/// query variables, but copied out
|
||||||
Term namedVarsCopy();
|
Term namedVarsCopy();
|
||||||
@ -101,7 +104,8 @@ public:
|
|||||||
/// simple YAP Query;
|
/// simple YAP Query;
|
||||||
/// just calls YAP and reports success or failure, Useful when we just
|
/// just calls YAP and reports success or failure, Useful when we just
|
||||||
/// want things done, eg YAPCommand("load_files(library(lists), )")
|
/// want things done, eg YAPCommand("load_files(library(lists), )")
|
||||||
inline bool command() {
|
inline bool command()
|
||||||
|
{
|
||||||
bool rc = next();
|
bool rc = next();
|
||||||
close();
|
close();
|
||||||
return rc;
|
return rc;
|
||||||
@ -113,7 +117,8 @@ public:
|
|||||||
/// This class implements a callback Prolog-side. It will be inherited by the
|
/// This class implements a callback Prolog-side. It will be inherited by the
|
||||||
/// Java or Python
|
/// Java or Python
|
||||||
/// class that actually implements the callback.
|
/// class that actually implements the callback.
|
||||||
class YAPCallback {
|
class YAPCallback
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~YAPCallback() {}
|
virtual ~YAPCallback() {}
|
||||||
virtual void run() { LOG("callback"); }
|
virtual void run() { LOG("callback"); }
|
||||||
@ -126,7 +131,8 @@ public:
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class YAPEngine {
|
class YAPEngine
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
YAPCallback *_callback;
|
YAPCallback *_callback;
|
||||||
YAP_init_args init_args;
|
YAP_init_args init_args;
|
||||||
@ -153,14 +159,16 @@ public:
|
|||||||
/// remove current callback
|
/// remove current callback
|
||||||
void delYAPCallback() { _callback = 0; }
|
void delYAPCallback() { _callback = 0; }
|
||||||
/// set a new callback
|
/// set a new callback
|
||||||
void setYAPCallback(YAPCallback *cb) {
|
void setYAPCallback(YAPCallback *cb)
|
||||||
|
{
|
||||||
delYAPCallback();
|
delYAPCallback();
|
||||||
_callback = cb;
|
_callback = cb;
|
||||||
}
|
}
|
||||||
/// execute the callback.
|
/// execute the callback.
|
||||||
////void run() { if (_callback) _callback->run(); }
|
////void run() { if (_callback) _callback->run(); }
|
||||||
/// execute the callback with a text argument.
|
/// execute the callback with a text argument.
|
||||||
void run(char *s) {
|
void run(char *s)
|
||||||
|
{
|
||||||
if (_callback)
|
if (_callback)
|
||||||
_callback->run(s);
|
_callback->run(s);
|
||||||
}
|
}
|
||||||
@ -178,22 +186,30 @@ public:
|
|||||||
/// current directory for the engine
|
/// current directory for the engine
|
||||||
bool call(YAPPredicate ap, YAPTerm ts[]);
|
bool call(YAPPredicate ap, YAPTerm ts[]);
|
||||||
/// current directory for the engine
|
/// current directory for the engine
|
||||||
bool goalt(YAPTerm t);
|
bool goalt(YAPTerm Yt) { return Yt.term(); };
|
||||||
/// current directory for the engine
|
/// current directory for the engine
|
||||||
bool goal(Term t);
|
bool mgoal(Term t, Term tmod);
|
||||||
|
/// current directory for the engine
|
||||||
|
|
||||||
|
bool goal(Term t)
|
||||||
|
{
|
||||||
|
return mgoal(t, CurrentModule);
|
||||||
|
}
|
||||||
/// reset Prolog state
|
/// reset Prolog state
|
||||||
void reSet();
|
void reSet();
|
||||||
/// release: assune that there are no stack pointers, just release memory
|
/// release: assune that there are no stack pointers, just release memory
|
||||||
// for last execution
|
// for last execution
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
const char *currentDir() {
|
const char *currentDir()
|
||||||
|
{
|
||||||
char dir[1024];
|
char dir[1024];
|
||||||
std::string s = Yap_getcwd(dir, 1024 - 1);
|
std::string s = Yap_getcwd(dir, 1024 - 1);
|
||||||
return s.c_str();
|
return s.c_str();
|
||||||
};
|
};
|
||||||
/// report YAP version as a string
|
/// report YAP version as a string
|
||||||
const char *version() {
|
const char *version()
|
||||||
|
{
|
||||||
std::string s = Yap_version();
|
std::string s = Yap_version();
|
||||||
return s.c_str();
|
return s.c_str();
|
||||||
};
|
};
|
||||||
|
79
CXX/yapt.hh
79
CXX/yapt.hh
@ -2,20 +2,9 @@
|
|||||||
#ifndef YAPT_HH
|
#ifndef YAPT_HH
|
||||||
#define YAPT_HH 1
|
#define YAPT_HH 1
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Term YAP_ReadBuffer(const char *s, Term *tp);
|
Term YAP_ReadBuffer(const char *s, Term *tp);
|
||||||
#if defined(SWIGPYTHON) && 0
|
}
|
||||||
#include <Python.h>
|
|
||||||
extern Term pythonToYAP(PyObject *inp);
|
|
||||||
#define YAPTerm _YAPTERM
|
|
||||||
#elifndef HAVE_PYTHON_H
|
|
||||||
typdef struct { int no_python; } PyObject;
|
|
||||||
#else
|
|
||||||
#include <Python.h>
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
class YAPError;
|
class YAPError;
|
||||||
|
|
||||||
@ -33,15 +22,8 @@ class YAPTerm {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
yhandle_t t; /// handle to term, equivalent to term_t
|
yhandle_t t; /// handle to term, equivalent to term_t
|
||||||
public:
|
|
||||||
virtual ~YAPTerm() {
|
|
||||||
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
|
|
||||||
// Yap_DebugPlWriteln(LOCAL_HandleBase[t]); }
|
|
||||||
// LOCAL_HandleBase[t] = TermFreeTerm;
|
|
||||||
// while ( LOCAL_HandleBase[LOCAL_CurSlot-1] == TermFreeTerm)
|
|
||||||
LOCAL_CurSlot--;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
public:
|
||||||
Term gt() {
|
Term gt() {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
// fprintf(stderr,"?%d,%lx,%p\n",t,LOCAL_HandleBase[t], HR);
|
// fprintf(stderr,"?%d,%lx,%p\n",t,LOCAL_HandleBase[t], HR);
|
||||||
@ -55,14 +37,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
YAPTerm(Term tn) { mk(tn); };
|
YAPTerm(Term tn) { mk(tn); };
|
||||||
YAPTerm(PyObject *inp) {
|
|
||||||
#ifdef SWIGPYTHON
|
#ifdef SWIGPYTHON
|
||||||
Term tinp = pythonToYAP(inp);
|
// YAPTerm(struct _object *inp) {
|
||||||
t = Yap_InitSlot(tinp);
|
// Term tinp = pythonToYAP(inp);
|
||||||
#else
|
// t = Yap_InitSlot(tinp);
|
||||||
t = 0;
|
//}
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
/// private method to convert from Term (internal YAP representation) to
|
/// private method to convert from Term (internal YAP representation) to
|
||||||
/// YAPTerm
|
/// YAPTerm
|
||||||
// do nothing constructor
|
// do nothing constructor
|
||||||
@ -75,6 +55,21 @@ public:
|
|||||||
Term tp;
|
Term tp;
|
||||||
mk(YAP_ReadBuffer(s, &tp));
|
mk(YAP_ReadBuffer(s, &tp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
/// Term destructor, tries to recover slot
|
||||||
|
virtual ~YAPTerm() {
|
||||||
|
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
|
||||||
|
if (!t)
|
||||||
|
return;
|
||||||
|
Yap_DebugPlWriteln(LOCAL_HandleBase[t]);
|
||||||
|
LOCAL_HandleBase[t] = TermFreeTerm;
|
||||||
|
while (LOCAL_HandleBase[LOCAL_CurSlot - 1] == TermFreeTerm) {
|
||||||
|
LOCAL_CurSlot--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/// construct a term out of an integer (if you know object type use
|
/// construct a term out of an integer (if you know object type use
|
||||||
/// YAPIntegerTerm)
|
/// YAPIntegerTerm)
|
||||||
/// YAPTerm(long int num) { mk(MkIntegerTerm(num)); }
|
/// YAPTerm(long int num) { mk(MkIntegerTerm(num)); }
|
||||||
@ -96,7 +91,7 @@ public:
|
|||||||
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
||||||
/// from YAPTerm to Term (internal YAP representation)
|
/// from YAPTerm to Term (internal YAP representation)
|
||||||
/// fetch a sub-term
|
/// fetch a sub-term
|
||||||
Term &operator[](size_t n);
|
Term &operator[](arity_t n);
|
||||||
// const YAPTerm *vars();
|
// const YAPTerm *vars();
|
||||||
/// this term is == to t1
|
/// this term is == to t1
|
||||||
virtual bool exactlyEqual(YAPTerm t1) {
|
virtual bool exactlyEqual(YAPTerm t1) {
|
||||||
@ -262,10 +257,15 @@ class YAPApplTerm : public YAPTerm {
|
|||||||
YAPApplTerm(Term t0) { mk(t0); }
|
YAPApplTerm(Term t0) { mk(t0); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~YAPApplTerm() {}
|
YAPApplTerm(Functor f, Term ts[]) {
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
|
Term t0 = Yap_MkApplTerm(f, f->ArityOfFE, ts);
|
||||||
|
mk(t0);
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
};
|
||||||
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
||||||
//YAPApplTerm(const char *s, std::vector<YAPTerm> ts);
|
YAPApplTerm(const std::string s, std::vector<YAPTerm> ts);
|
||||||
//YAPApplTerm(YAPFunctor f);
|
YAPApplTerm(YAPFunctor f);
|
||||||
YAPFunctor getFunctor();
|
YAPFunctor getFunctor();
|
||||||
Term getArg(arity_t i) {
|
Term getArg(arity_t i) {
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
@ -375,8 +375,7 @@ public:
|
|||||||
else if (to == TermNil)
|
else if (to == TermNil)
|
||||||
return TermNil;
|
return TermNil;
|
||||||
/* error */
|
/* error */
|
||||||
Yap_Error(TYPE_ERROR_LIST, t, 0);
|
throw YAPError(TYPE_ERROR_LIST, YAPTerm(to), "");
|
||||||
throw YAPError();
|
|
||||||
}
|
}
|
||||||
/// copy a list.
|
/// copy a list.
|
||||||
///
|
///
|
||||||
@ -430,14 +429,14 @@ public:
|
|||||||
YAPAtomTerm(wchar_t *s);
|
YAPAtomTerm(wchar_t *s);
|
||||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||||
YAPAtomTerm(wchar_t *s, size_t len);
|
YAPAtomTerm(wchar_t *s, size_t len);
|
||||||
virtual bool isVar() { return false; } /// type check for unbound
|
bool isVar() { return false; } /// type check for unbound
|
||||||
virtual bool isAtom() { return true; } /// type check for atom
|
bool isAtom() { return true; } /// type check for atom
|
||||||
virtual bool isInteger() { return false; } /// type check for integer
|
bool isInteger() { return false; } /// type check for integer
|
||||||
virtual bool isFloat() { return false; } /// type check for floating-point
|
bool isFloat() { return false; } /// type check for floating-point
|
||||||
virtual bool isString() { return false; } /// type check for a string " ... "
|
bool isString() { return false; } /// type check for a string " ... "
|
||||||
virtual bool isCompound() { return false; } /// is a primitive term
|
bool isCompound() { return false; } /// is a primitive term
|
||||||
virtual bool isAppl() { return false; } /// is a structured term
|
bool isAppl() { return false; } /// is a structured term
|
||||||
virtual bool isPair() { return false; } /// is a pair term
|
bool isPair() { return false; } /// is a pair term
|
||||||
virtual bool isGround() { return true; } /// term is ground
|
virtual bool isGround() { return true; } /// term is ground
|
||||||
virtual bool isList() { return gt() == TermNil; } /// [] is a list
|
virtual bool isList() { return gt() == TermNil; } /// [] is a list
|
||||||
// Getter: outputs the atom;
|
// Getter: outputs the atom;
|
||||||
|
Reference in New Issue
Block a user