Android support,
This commit is contained in:
parent
c0cf2b0b83
commit
963752fa9c
@ -871,7 +871,7 @@ static int num_send_error_message(char s[]) {
|
||||
|
||||
#define number_overflow() \
|
||||
{ \
|
||||
size_t nsz = min(max_size * 2, max_size); \
|
||||
size_t nsz = Yap_Min(max_size * 2, max_size); \
|
||||
char *nbuf; \
|
||||
\
|
||||
if (buf == buf0) { \
|
||||
@ -1406,7 +1406,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
for (; chtype(ch) <= NU; ch = getchr(inp_stream)) {
|
||||
if (charp == TokImage + (sz - 1)) {
|
||||
unsigned char *p0 = TokImage;
|
||||
sz = min(sz * 2, sz + MBYTE);
|
||||
sz = Yap_Min(sz * 2, sz + MBYTE);
|
||||
TokImage = Realloc(p0, sz);
|
||||
if (TokImage == NULL) {
|
||||
return CodeSpaceError(t, p, l);
|
||||
@ -1560,7 +1560,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
|
||||
while (TRUE) {
|
||||
if (charp > TokImage + (sz - 1)) {
|
||||
TokImage = Realloc(TokImage, min(sz * 2, sz + MBYTE));
|
||||
TokImage = Realloc(TokImage, Yap_Min(sz * 2, sz + MBYTE));
|
||||
if (TokImage == NULL) {
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
@ -1735,7 +1735,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
add_ch_to_buff(och);
|
||||
for (; chtype(ch) == SY; ch = getchr(inp_stream)) {
|
||||
if (charp >= TokImage + (sz - 10)) {
|
||||
sz = min(sz * 2, sz + MBYTE);
|
||||
sz = Yap_Min(sz * 2, sz + MBYTE);
|
||||
TokImage = Realloc(TokImage, sz);
|
||||
if (!TokImage)
|
||||
return CodeSpaceError(t, p, l);
|
||||
|
@ -91,12 +91,12 @@ endif()
|
||||
|
||||
OPTION (WITH_SWIG " Enable SWIG interfaces to foreign languages" ON)
|
||||
|
||||
IF (WITH_SWIG)
|
||||
IF (WITH_SWIG OR ANDROID)
|
||||
find_host_package (SWIG)
|
||||
macro_log_feature (SWIG_FOUND "Swig"
|
||||
"Use SWIG Interface Generator "
|
||||
"http://www.swig.org" ON)
|
||||
ENDIF (WITH_SWIG)
|
||||
ENDIF (WITH_SWIG OR ANDROID)
|
||||
|
||||
option (WITH_PYTHON
|
||||
"Allow Python->YAP and YAP->Python" ON)
|
||||
@ -106,37 +106,20 @@ IF (WITH_PYTHON)
|
||||
ENDIF (WITH_PYTHON)
|
||||
|
||||
|
||||
IF (SWIG_FOUND)
|
||||
add_subDIRECTORY (packages/swig NO_POLICY_SCOPE)
|
||||
ENDIF(SWIG_FOUND)
|
||||
|
||||
|
||||
|
||||
if (ANDROID)
|
||||
|
||||
ADD_SUBDIRECTORY(os)
|
||||
ADD_SUBDIRECTORY(OPTYap)
|
||||
ADD_SUBDIRECTORY(packages/myddas)
|
||||
ADD_SUBDIRECTORY(utf8proc)
|
||||
ADD_SUBDIRECTORY(CXX)
|
||||
|
||||
|
||||
else()
|
||||
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:libOPTYap> )
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:libYAPOs> )
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:utf8proc> )
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:myddas> )
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:Yapsqlite3> )
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:libswi> )
|
||||
if (WIN32)
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:Yapsqlite3> )
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:YAP++> )
|
||||
if (WITH_PYTHON )
|
||||
List (APPEND YLIBS $<TARGET_OBJECTS:Obj4Py> )
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
@ -167,8 +150,6 @@ if (USE_READLINE)
|
||||
endif (USE_READLINE)
|
||||
|
||||
if (ANDROID)
|
||||
add_dependencies(libYap plmyddas )
|
||||
|
||||
target_link_libraries(libYap android log)
|
||||
|
||||
endif ()
|
||||
@ -192,4 +173,9 @@ if (PYTHONLIBS_FOUND AND SWIG_FOUND)
|
||||
ENDIF()
|
||||
endif()
|
||||
|
||||
|
||||
IF (SWIG_FOUND OR ANDROID)
|
||||
add_subDIRECTORY (packages/swig NO_POLICY_SCOPE)
|
||||
ENDIF()
|
||||
|
||||
include(Config NO_POLICY_SCOPE)
|
||||
|
96
CXX/yapi.cpp
96
CXX/yapi.cpp
@ -27,6 +27,8 @@ X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
|
||||
|
||||
}
|
||||
|
||||
static YAPEngine *curren;
|
||||
|
||||
YAPAtomTerm::YAPAtomTerm(char *s)
|
||||
{ // build string
|
||||
BACKUP_H();
|
||||
@ -187,6 +189,7 @@ YAPApplTerm::YAPApplTerm(std::string f, std::vector<YAPTerm> ts)
|
||||
mk(o);
|
||||
}
|
||||
|
||||
|
||||
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm()
|
||||
{
|
||||
BACKUP_H();
|
||||
@ -633,19 +636,19 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
|
||||
/* ignore flags for now */
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term *nts;
|
||||
Term goal;
|
||||
Term tgoal;
|
||||
|
||||
if ( ts) {
|
||||
|
||||
goal = YAPApplTerm(f, ts).term();
|
||||
nts = RepAppl(goal)+1;
|
||||
goal = new YAPApplTerm(f, ts);
|
||||
nts = RepAppl(goal->term())+1;
|
||||
|
||||
} else {
|
||||
goal = MkVarTerm();
|
||||
goal = new YAPVarTerm();
|
||||
nts = nullptr;
|
||||
}
|
||||
openQuery(goal, nts);
|
||||
names = YAPPairTerm( TermNil );
|
||||
openQuery(goal->term(), nts);
|
||||
names = new YAPPairTerm();
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
||||
@ -655,12 +658,13 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
CELL *nts;
|
||||
if (ts) {
|
||||
goal = YAPApplTerm(f, nts);
|
||||
tgoal = YAPApplTerm(f, nts);
|
||||
} else {
|
||||
goal = YAPVarTerm();
|
||||
tgoal = YAPVarTerm();
|
||||
nts = nullptr;
|
||||
}
|
||||
names = YAPPairTerm( TermNil );
|
||||
*names = new YAPPairTerm();
|
||||
*goal = new YAPTerm(tgoal);
|
||||
openQuery(goal.term(), nts);
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
@ -671,19 +675,19 @@ YAPQuery::YAPQuery(YAPTerm t) : YAPPredicate(t)
|
||||
BACKUP_MACHINE_REGS();
|
||||
CELL *nts;
|
||||
Term tt = t.term();
|
||||
goal = t;
|
||||
if (IsApplTerm(tt)) {
|
||||
Functor f = FunctorOfTerm(tt);
|
||||
if (IsExtensionFunctor(f))
|
||||
nts = nullptr;
|
||||
nts = RepAppl(goal.term())+1;
|
||||
nts = RepAppl(tt)+1;
|
||||
} else if (IsPairTerm(tt)) {
|
||||
nts = RepPair(tt);
|
||||
} else {
|
||||
nts = nullptr;
|
||||
}
|
||||
openQuery(tt, nts);
|
||||
names = YAPPairTerm( TermNil );
|
||||
names = new YAPPairTerm();
|
||||
goal = new YAPTerm(t);
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
||||
@ -692,15 +696,15 @@ YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
arity_t arity = p.ap->ArityOfPE;
|
||||
if (arity) {
|
||||
goal = YAPApplTerm(YAPFunctor(p.ap->FunctorOfPred), ts).term();
|
||||
for (arity_t i =0; i < arity; i++)
|
||||
goal = new YAPApplTerm(YAPFunctor(p.ap->FunctorOfPred), ts);
|
||||
for (arity_t i =0; i < arity; i++) {
|
||||
XREGS[i + 1] = ts[i].term();
|
||||
openQuery(goal.term(), nullptr);
|
||||
} else {
|
||||
goal = YAPAtomTerm((Atom)(p.ap->FunctorOfPred));
|
||||
openQuery(goal.term(), nullptr);
|
||||
}
|
||||
names = TermNil;
|
||||
} else {
|
||||
goal = new YAPAtomTerm((Atom)(p.ap->FunctorOfPred));
|
||||
}
|
||||
openQuery(goal->term(), nullptr);
|
||||
names = new YAPPairTerm();
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
||||
@ -709,6 +713,11 @@ bool YAPQuery::next()
|
||||
CACHE_REGS
|
||||
bool result = false;
|
||||
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();
|
||||
}
|
||||
@ -718,7 +727,7 @@ bool YAPQuery::next()
|
||||
BACKUP_MACHINE_REGS();
|
||||
if (!q_open)
|
||||
return false;
|
||||
if (sigsetjmp(q_env, false))
|
||||
if (false && sigsetjmp(q_env, false))
|
||||
{
|
||||
throw YAPError();
|
||||
}
|
||||
@ -736,8 +745,8 @@ bool YAPQuery::next()
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %ld",
|
||||
q_state, vnames.text(), LOCAL_CurSlot);
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "names %d %s %ld",
|
||||
q_state, names->text(), LOCAL_CurSlot);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -783,10 +792,10 @@ 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 = YAPApplTerm(FunctorUndefinedQuery, ts);
|
||||
goal = new YAPApplTerm(FunctorUndefinedQuery, ts);
|
||||
return ap = PredUndefinedQuery;
|
||||
}
|
||||
|
||||
@ -868,39 +877,6 @@ 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
|
||||
|
||||
|
||||
@ -913,11 +889,7 @@ void YAPEngine::doInit(YAP_file_type_t BootMode)
|
||||
/* Begin preprocessor code */
|
||||
/* live */
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "initialize_prolog");
|
||||
#if __ANDROID__
|
||||
Yap_AndroidBufp = (char *)malloc(Yap_AndroidMax = 4096);
|
||||
Yap_AndroidBufp[0] = '\0';
|
||||
Yap_AndroidSz = 0;
|
||||
#endif
|
||||
curren = this;
|
||||
//yerror = YAPError();
|
||||
#if YAP_PYTHON
|
||||
do_init_python();
|
||||
|
25
CXX/yapq.hh
25
CXX/yapq.hh
@ -41,8 +41,8 @@ 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 ;
|
||||
|
||||
@ -55,6 +55,8 @@ class X_API YAPQuery : public YAPPredicate
|
||||
q_p = P;
|
||||
q_cp = CP;
|
||||
// make sure this is safe
|
||||
names = new YAPPairTerm();
|
||||
goal = new YAPTerm();
|
||||
q_handles = LOCAL_CurSlot;
|
||||
};
|
||||
|
||||
@ -97,8 +99,7 @@ YAPQuery() {
|
||||
LOCAL_CurSlot);
|
||||
if (!ap)
|
||||
return;
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
|
||||
goal = YAPTerm(tgoal);
|
||||
__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);
|
||||
@ -108,7 +109,10 @@ YAPQuery() {
|
||||
qt = RepAppl(tgoal)+1;
|
||||
}
|
||||
}
|
||||
names = YAPPairTerm(tnames);
|
||||
names = new YAPPairTerm();
|
||||
goal = new YAPTerm(tgoal);
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "names %d %s %ld",
|
||||
q_state, names->text(), LOCAL_CurSlot);
|
||||
openQuery(tgoal, qt);
|
||||
};
|
||||
// inline YAPQuery() : YAPPredicate(s, tgoal, tnames)
|
||||
@ -117,7 +121,7 @@ YAPQuery() {
|
||||
// LOCAL_CurSlot);
|
||||
// if (!ap)
|
||||
// return;
|
||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
|
||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", names->text());
|
||||
// goal = YAPTerm(tgoal);
|
||||
// names = YAPPairTerm(tnames);
|
||||
// openQuery(tgoal);
|
||||
@ -143,17 +147,16 @@ bool next();
|
||||
bool deterministic();
|
||||
/// represent the top-goal
|
||||
const char *text();
|
||||
/// remove alternatives in the current search space, and finish the current
|
||||
/// 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(); };
|
||||
|
||||
Term namedVars() {return names->term(); };
|
||||
YAPPairTerm * namedYAPVars() {return names; };
|
||||
/// 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
|
||||
|
141
CXX/yapt.hh
141
CXX/yapt.hh
@ -38,11 +38,17 @@ class YAPError;
|
||||
*/
|
||||
class X_API YAPTerm {
|
||||
friend class YAPPredicate;
|
||||
|
||||
friend class YAPPrologPredicate;
|
||||
|
||||
friend class YAPQuery;
|
||||
|
||||
friend class YAPModule;
|
||||
|
||||
friend class YAPModuleProp;
|
||||
|
||||
friend class YAPApplTerm;
|
||||
|
||||
friend class YAPListTerm;
|
||||
|
||||
protected:
|
||||
@ -73,13 +79,16 @@ public:
|
||||
// t = Yap_InitSlot(tinp);
|
||||
//}
|
||||
#endif
|
||||
|
||||
/// private method to convert from Term (internal YAP representation) to
|
||||
/// YAPTerm
|
||||
// do nothing constructor
|
||||
YAPTerm() { t = 0; };
|
||||
|
||||
// YAPTerm(yhandle_t i) { t = i; };
|
||||
/// pointer to term
|
||||
YAPTerm(void *ptr);
|
||||
|
||||
/// parse string s and construct a term.
|
||||
YAPTerm(char *s) {
|
||||
Term tp;
|
||||
@ -87,6 +96,7 @@ public:
|
||||
}
|
||||
|
||||
#if 1
|
||||
|
||||
/// Term destructor, tries to recover slot
|
||||
virtual ~YAPTerm() {
|
||||
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
|
||||
@ -111,18 +121,24 @@ public:
|
||||
/// YAPTerm(YAPFunctor f, YAPTerm ts[]);
|
||||
/// extract the tag of a term, after dereferencing.
|
||||
YAP_tag_t tag();
|
||||
|
||||
/// copy the term ( term copy )
|
||||
Term deepCopy();
|
||||
|
||||
/// numbervars ( int start, bool process=false )
|
||||
intptr_t numberVars(intptr_t start, bool skip_singletons = false);
|
||||
|
||||
inline Term term() {
|
||||
return gt();
|
||||
} /// from YAPTerm to Term (internal YAP representation)
|
||||
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
|
||||
|
||||
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
||||
|
||||
/// from YAPTerm to Term (internal YAP representation)
|
||||
/// fetch a sub-term
|
||||
Term &operator[](arity_t n);
|
||||
|
||||
// const YAPTerm *vars();
|
||||
/// this term is == to t1
|
||||
virtual bool exactlyEqual(YAPTerm t1) {
|
||||
@ -169,6 +185,7 @@ public:
|
||||
RECOVER_MACHINE_REGS();
|
||||
return out;
|
||||
};
|
||||
|
||||
/// term hash,
|
||||
virtual bool isVar() { return IsVarTerm(gt()); } /// type check for unound
|
||||
virtual bool isAtom() { return IsAtomTerm(gt()); } /// type check for atom
|
||||
@ -189,6 +206,52 @@ public:
|
||||
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
|
||||
virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list
|
||||
|
||||
|
||||
std::vector<YAPTerm> YAPTermToJavaArray()
|
||||
{
|
||||
BACKUP_H();
|
||||
Term pt = gt();
|
||||
if (IsApplTerm(t)) {
|
||||
arity_t arity = ArityOfFunctor(FunctorOfTerm(pt));
|
||||
std::vector<YAPTerm> o = std::vector<YAPTerm>(arity);
|
||||
for (arity_t i=0; i < arity; i++) {
|
||||
o[i] = YAPTerm( ArgOfTerm(i+1, pt) );
|
||||
}
|
||||
return o;
|
||||
|
||||
}
|
||||
if (IsPairTerm(t)) {
|
||||
std::vector<YAPTerm> o = std::vector<YAPTerm>(2);
|
||||
o[0] = YAPTerm( HeadOfTerm(pt) );
|
||||
o[1] = YAPTerm( TailOfTerm(pt) );
|
||||
return o;
|
||||
|
||||
}
|
||||
return std::vector<YAPTerm>(0);
|
||||
}
|
||||
|
||||
std::vector<Term> YAPTermToVector()
|
||||
{
|
||||
BACKUP_H();
|
||||
Term pt = gt();
|
||||
if (IsApplTerm(t)) {
|
||||
arity_t arity = ArityOfFunctor(FunctorOfTerm(pt));
|
||||
std::vector<Term> o = std::vector<Term>(arity);
|
||||
for (arity_t i=0; i < arity; i++) {
|
||||
o[i] = ( ArgOfTerm(i+1, pt) );
|
||||
}
|
||||
return o;
|
||||
|
||||
}
|
||||
if (IsPairTerm(t)) {
|
||||
std::vector<Term> o = std::vector<Term>(2);
|
||||
o[0] = ( HeadOfTerm(pt) );
|
||||
o[1] = ( TailOfTerm(pt) );
|
||||
return o;
|
||||
|
||||
}
|
||||
return std::vector<Term>(0);
|
||||
}
|
||||
/// extract the argument i of the term, where i in 1...arity
|
||||
virtual Term getArg(arity_t i) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
@ -212,7 +275,9 @@ public:
|
||||
RECOVER_MACHINE_REGS();
|
||||
return tf;
|
||||
}
|
||||
|
||||
virtual YAPTerm getYAPArg(int i) {
|
||||
return YAPTerm(getArg((arity_t)i));
|
||||
}
|
||||
/// extract the arity of the term
|
||||
/// variables have arity 0
|
||||
virtual inline arity_t arity() {
|
||||
@ -261,10 +326,15 @@ public:
|
||||
*/
|
||||
class X_API YAPFunctor : public YAPProp {
|
||||
friend class YAPApplTerm;
|
||||
|
||||
friend class YAPTerm;
|
||||
|
||||
friend class YAPPredicate;
|
||||
|
||||
friend class YAPQuery;
|
||||
|
||||
Functor f;
|
||||
|
||||
/// Constructor: receives Prolog functor and casts it to YAPFunctor
|
||||
///
|
||||
/// Notice that this is designed for internal use only.
|
||||
@ -284,6 +354,7 @@ public:
|
||||
inline YAPFunctor(const char *s, uintptr_t arity, bool isutf8 = true) {
|
||||
f = Yap_MkFunctor(Yap_LookupAtom(s), arity);
|
||||
}
|
||||
|
||||
/// Constructor: receives name as a wide string plus arity
|
||||
///
|
||||
/// Notice that this is designed for UNICODE right now
|
||||
@ -293,6 +364,7 @@ public:
|
||||
inline YAPFunctor(const wchar_t *s, uintptr_t arity) {
|
||||
CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity);
|
||||
}
|
||||
|
||||
/// Getter: extract name of functor as an atom
|
||||
///
|
||||
/// this is for external usage.
|
||||
@ -312,16 +384,22 @@ class X_API YAPApplTerm : public YAPTerm {
|
||||
|
||||
public:
|
||||
YAPApplTerm(Term t0) { mk(t0); }
|
||||
|
||||
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(const std::string s, std::vector<YAPTerm> ts);
|
||||
|
||||
YAPApplTerm(YAPFunctor f);
|
||||
|
||||
inline Functor functor() { return FunctorOfTerm(gt()); }
|
||||
|
||||
inline YAPFunctor getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); }
|
||||
|
||||
Term getArg(arity_t i) {
|
||||
@ -332,6 +410,7 @@ public:
|
||||
RECOVER_MACHINE_REGS();
|
||||
return tf;
|
||||
};
|
||||
|
||||
virtual bool isVar() { return false; } /// type check for unbound
|
||||
virtual bool isAtom() { return false; } /// type check for atom
|
||||
virtual bool isInteger() { return false; } /// type check for integer
|
||||
@ -359,10 +438,23 @@ public:
|
||||
else
|
||||
Yap_ThrowError(TYPE_ERROR_LIST, t0, "YAPPairTerms");
|
||||
}
|
||||
|
||||
/// cons
|
||||
YAPPairTerm(YAPTerm hd, YAPTerm tl);
|
||||
|
||||
/// null constructor, or empty list
|
||||
YAPPairTerm();
|
||||
|
||||
bool empty() { return gt() == TermNil; }
|
||||
|
||||
Term getHead() { return (HeadOfTerm(gt())); }
|
||||
|
||||
Term getTail() { return (TailOfTerm(gt())); }
|
||||
|
||||
YAPTerm car() { return YAPTerm(HeadOfTerm(gt())); }
|
||||
|
||||
YAPPairTerm cdr() { return YAPPairTerm(TailOfTerm(gt())); }
|
||||
|
||||
std::vector<Term> listToArray() {
|
||||
Term *tailp;
|
||||
Term t1 = gt();
|
||||
@ -379,6 +471,23 @@ public:
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
std::vector<YAPTerm> listToYAPArray() {
|
||||
Term *tailp;
|
||||
Term t1 = gt();
|
||||
Int l = Yap_SkipList(&t1, &tailp);
|
||||
if (l < 0) {
|
||||
throw YAPError(TYPE_ERROR_LIST, YAPTerm(t), "");
|
||||
}
|
||||
std::vector<YAPTerm> o = std::vector<YAPTerm>(l);
|
||||
int i = 0;
|
||||
Term t = gt();
|
||||
while (t != TermNil) {
|
||||
o[i++] = YAPTerm(HeadOfTerm(t));
|
||||
t = TailOfTerm(t);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -388,6 +497,7 @@ public:
|
||||
class X_API YAPNumberTerm : public YAPTerm {
|
||||
public:
|
||||
YAPNumberTerm() {};
|
||||
|
||||
bool isTagged() { return IsIntTerm(gt()); }
|
||||
};
|
||||
|
||||
@ -398,6 +508,7 @@ public:
|
||||
class X_API YAPIntegerTerm : public YAPNumberTerm {
|
||||
public:
|
||||
YAPIntegerTerm(intptr_t i);
|
||||
|
||||
intptr_t getInteger() { return IntegerOfTerm(gt()); };
|
||||
};
|
||||
|
||||
@ -418,15 +529,18 @@ public:
|
||||
///
|
||||
/// @param[in] the term
|
||||
YAPListTerm() { mk(TermNil); /* else type_error */ }
|
||||
|
||||
/// Create an empty list term.
|
||||
///
|
||||
/// @param[in] the term
|
||||
YAPListTerm(Term t0) { mk(t0); /* else type_error */ }
|
||||
|
||||
/// Create a list term out of an array of terms.
|
||||
///
|
||||
/// @param[in] the array of terms
|
||||
/// @param[in] the length of the array
|
||||
YAPListTerm(YAPTerm ts[], size_t n);
|
||||
|
||||
// YAPListTerm( vector<YAPTerm> v );
|
||||
/// Return the number of elements in a list term.
|
||||
size_t length() {
|
||||
@ -434,12 +548,15 @@ public:
|
||||
Term t1 = gt();
|
||||
return Yap_SkipList(&t1, &tailp);
|
||||
}
|
||||
|
||||
/// Extract the nth element.
|
||||
Term &operator[](size_t n);
|
||||
|
||||
/// Extract the first element of a list.
|
||||
///
|
||||
/// @param[in] the list
|
||||
Term car();
|
||||
|
||||
/// Extract the tail elements of a list.
|
||||
///
|
||||
/// @param[in] the list
|
||||
@ -452,6 +569,7 @@ public:
|
||||
/* error */
|
||||
throw YAPError(TYPE_ERROR_LIST, YAPTerm(to), "");
|
||||
}
|
||||
|
||||
/// copy a list.
|
||||
///
|
||||
/// @param[in] the list
|
||||
@ -462,9 +580,7 @@ public:
|
||||
/// @param[in] the list
|
||||
inline bool nil() {
|
||||
return gt() == TermNil;
|
||||
}
|
||||
|
||||
;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
@ -474,12 +590,16 @@ class X_API YAPStringTerm : public YAPTerm {
|
||||
public:
|
||||
/// your standard constructor
|
||||
YAPStringTerm(char *s);
|
||||
|
||||
/// use this one to construct length limited strings
|
||||
YAPStringTerm(char *s, size_t len);
|
||||
|
||||
/// construct using wide chars
|
||||
YAPStringTerm(wchar_t *s);
|
||||
|
||||
/// construct using length-limited wide chars
|
||||
YAPStringTerm(wchar_t *s, size_t len);
|
||||
|
||||
const char *getString() { return StringOfTerm(gt()); }
|
||||
};
|
||||
|
||||
@ -489,21 +609,28 @@ public:
|
||||
*/
|
||||
class X_API YAPAtomTerm : public YAPTerm {
|
||||
friend class YAPModule;
|
||||
|
||||
// Constructor: receives a C-atom;
|
||||
YAPAtomTerm(Term t) : YAPTerm(t) { IsAtomTerm(t); }
|
||||
|
||||
public:
|
||||
YAPAtomTerm(Atom a) { mk(MkAtomTerm(a)); }
|
||||
|
||||
// Constructor: receives an atom;
|
||||
YAPAtomTerm(YAPAtom a) : YAPTerm() { mk(MkAtomTerm(a.a)); }
|
||||
|
||||
// Constructor: receives a sequence of ISO-LATIN1 codes;
|
||||
YAPAtomTerm(char s[]);
|
||||
|
||||
// Constructor: receives a sequence of up to n ISO-LATIN1 codes;
|
||||
YAPAtomTerm(char *s, size_t len);
|
||||
|
||||
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s);
|
||||
|
||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s, size_t len);
|
||||
|
||||
bool isVar() { return false; } /// type check for unbound
|
||||
bool isAtom() { return true; } /// type check for atom
|
||||
bool isInteger() { return false; } /// type check for integer
|
||||
@ -516,9 +643,11 @@ public:
|
||||
virtual bool isList() { return gt() == TermNil; } /// [] is a list
|
||||
// Getter: outputs the atom;
|
||||
YAPAtom getAtom() { return YAPAtom(AtomOfTerm(gt())); }
|
||||
|
||||
// Getter: outputs the name as a sequence of ISO-LATIN1 codes;
|
||||
const char *text() { return (const char *) AtomOfTerm(gt())->StrOfAE; }
|
||||
};
|
||||
|
||||
#endif /* YAPT_HH */
|
||||
|
||||
|
||||
@ -531,15 +660,19 @@ class X_API YAPVarTerm : public YAPTerm {
|
||||
public:
|
||||
/// constructor
|
||||
YAPVarTerm() { mk(MkVarTerm()); };
|
||||
|
||||
/// get the internal representation
|
||||
CELL *getVar() { return VarOfTerm(gt()); }
|
||||
|
||||
/// is the variable bound to another one
|
||||
YAPVarTerm(Term t) {
|
||||
if (IsVarTerm(t)) {
|
||||
mk(t);
|
||||
}
|
||||
}
|
||||
|
||||
bool unbound() { return IsUnboundVar(VarOfTerm(gt())); }
|
||||
|
||||
inline bool isVar() { return true; } /// type check for unbound
|
||||
inline bool isAtom() { return false; } /// type check for atom
|
||||
inline bool isInteger() { return false; } /// type check for integer
|
||||
|
@ -179,15 +179,15 @@ INLINE_ONLY inline EXTERN void Yap_PutInHandle__(yhandle_t slot,
|
||||
LOCAL_HandleBase[slot] = t;
|
||||
}
|
||||
|
||||
#ifndef max
|
||||
#define max(X, Y) (X > Y ? X : Y)
|
||||
#ifndef Yap_Max
|
||||
#define Yap_Max(X, Y) (X > Y ? X : Y)
|
||||
#endif
|
||||
|
||||
#define ensure_handles ensure_slots
|
||||
INLINE_ONLY inline EXTERN void ensure_slots(int N USES_REGS) {
|
||||
if (LOCAL_CurHandle + N >= LOCAL_NHandles) {
|
||||
size_t inc = max(16 * 1024, LOCAL_NHandles / 2); // measured in cells
|
||||
inc = max(inc, (size_t)N + 16); // measured in cells
|
||||
size_t inc = Yap_Max(16 * 1024, LOCAL_NHandles / 2); // measured in cells
|
||||
inc = Yap_Max(inc, (size_t)N + 16); // measured in cells
|
||||
LOCAL_HandleBase = (CELL *)realloc(LOCAL_HandleBase,
|
||||
(inc + LOCAL_NHandles) * sizeof(CELL));
|
||||
LOCAL_NHandles += inc;
|
||||
|
@ -59,8 +59,9 @@ extern int pop_text_stack(int lvl USES_REGS);
|
||||
extern void *protected_pop_text_stack(int lvl, void *safe, bool tmp,
|
||||
size_t sz USES_REGS);
|
||||
|
||||
#ifndef min
|
||||
#define min(x, y) (x < y ? x : y)
|
||||
#ifndef Yap_Min
|
||||
#define Yap_Min(x, y) (x < y ? x : y)
|
||||
|
||||
#endif
|
||||
|
||||
#define MBYTE (1024 * 1024)
|
||||
|
@ -8,6 +8,8 @@
|
||||
# GMP_LIBRARY_DLL - library DLL to install. Only available on WIN32.
|
||||
# GMP_LIBRARIES_DIR - the directory the library we link with is found in.
|
||||
|
||||
message( "xxxxx ${ANDROID_ABI} yyyyy ${CMAKE_CURRENT_DIR} zzzzzzzzzz" )
|
||||
|
||||
if (ANDROID)
|
||||
set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
|
||||
set (GMP_FOUND ON)
|
||||
@ -26,6 +28,7 @@ if(MSVC)
|
||||
${CMAKE_SOURCE_DIR}/../tools/mpird/lib
|
||||
${CMAKE_SOURCE_DIR}/../mpir/lib
|
||||
${CMAKE_SOURCE_DIR}/../mpird/lib
|
||||
|
||||
$ENV{PROGRAMFILES}/mpir/lib
|
||||
$ENV{PROGRAMFILES}/mpird/lib
|
||||
$ENV{HOME}/mpir/lib
|
||||
|
@ -7,7 +7,7 @@ if (POLICY CMP0042)
|
||||
cmake_policy( SET CMP0042 NEW)
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID_OLD)
|
||||
macro ( MY_add_custom_target)
|
||||
endmacro()
|
||||
else()
|
||||
@ -17,7 +17,7 @@ else()
|
||||
endif()
|
||||
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID_OLD)
|
||||
macro ( add_component arg1)
|
||||
foreach(item ${ARGN})
|
||||
get_filename_component(i ${item} ABSOLUTE)
|
||||
@ -41,7 +41,7 @@ else()
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID_OLD)
|
||||
macro ( MY_add_dependencies)
|
||||
endmacro()
|
||||
else()
|
||||
@ -50,7 +50,7 @@ else()
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID_OLD)
|
||||
macro ( MY_add_library)
|
||||
endmacro()
|
||||
else()
|
||||
@ -68,7 +68,7 @@ else()
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID_OLD)
|
||||
macro ( MY_include)
|
||||
endmacro()
|
||||
else()
|
||||
@ -86,7 +86,7 @@ else()
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID_OLD)
|
||||
macro ( MY_set_target_properties)
|
||||
endmacro()
|
||||
else()
|
||||
@ -95,7 +95,7 @@ else()
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID_OLD)
|
||||
macro ( MY_target_link_libraries)
|
||||
endmacro()
|
||||
else()
|
||||
|
@ -31,6 +31,8 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <encoding.h>
|
||||
|
||||
typedef struct {
|
||||
dev_t st_dev; /* ID of device containing file */
|
||||
mode_t st_mode; /* Mode of file (see below) */
|
||||
@ -47,6 +49,7 @@ typedef struct {
|
||||
#endif
|
||||
} vfs_stat;
|
||||
|
||||
|
||||
typedef enum vfs_flags {
|
||||
VFS_CAN_WRITE = 0x1, /// we can write to files in this space
|
||||
VFS_CAN_EXEC = 0x2, /// we can execute files in this space
|
||||
@ -62,7 +65,7 @@ typedef union {
|
||||
size_t sz;
|
||||
void *pt;
|
||||
uintptr_t scalar;
|
||||
#if __ANDROID__
|
||||
#if __ANDROID__0
|
||||
AAssetManager *mgr;
|
||||
AAsset *asset;
|
||||
#endif
|
||||
@ -108,6 +111,10 @@ typedef struct vfs {
|
||||
|
||||
extern VFS_t *GLOBAL_VFS;
|
||||
|
||||
extern void init_android_stream(void);
|
||||
|
||||
extern void Yap_InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp);
|
||||
|
||||
static inline VFS_t *vfs_owner(const char *fname) {
|
||||
VFS_t *me = GLOBAL_VFS;
|
||||
int d;
|
||||
|
12
libYap.cmake
12
libYap.cmake
@ -92,12 +92,12 @@ list(APPEND YAP_SYSTEM_OPTIONS "thread support")
|
||||
# we use the nice UTF-8 package
|
||||
#available at the Julia project
|
||||
|
||||
MY_ADD_SUBDIRECTORY ( os )
|
||||
MY_ADD_SUBDIRECTORY ( OPTYap )
|
||||
MY_ADD_SUBDIRECTORY ( packages/myddas )
|
||||
MY_ADD_SUBDIRECTORY ( utf8proc )
|
||||
MY_ADD_SUBDIRECTORY ( library/dialect/swi/fli )
|
||||
MY_ADD_SUBDIRECTORY ( CXX )
|
||||
ADD_SUBDIRECTORY ( os )
|
||||
ADD_SUBDIRECTORY ( OPTYap )
|
||||
ADD_SUBDIRECTORY ( packages/myddas )
|
||||
ADD_SUBDIRECTORY ( utf8proc )
|
||||
ADD_SUBDIRECTORY ( library/dialect/swi/fli )
|
||||
ADD_SUBDIRECTORY ( CXX )
|
||||
|
||||
if (READLINE_LIBS)
|
||||
target_link_libraries(libYap ${READLINE_LIBS} )
|
||||
|
@ -33,7 +33,7 @@ static char SccsId[] = "%W% %G%";
|
||||
// for native asset manager
|
||||
#include <sys/types.h>
|
||||
|
||||
#if __ANDROID__
|
||||
#if __ANDROID__0
|
||||
|
||||
|
||||
static AAssetManager * getMgr(struct vfs *me)
|
||||
@ -212,7 +212,7 @@ VFS_t *
|
||||
Yap_InitAssetManager(void)
|
||||
{
|
||||
|
||||
#if __ANDROID__
|
||||
#if __ANDROID__O
|
||||
VFS_t *me;
|
||||
/* init standard VFS */
|
||||
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
|
||||
|
16
os/iopreds.c
16
os/iopreds.c
@ -285,7 +285,7 @@ static void InitFileIO(StreamDesc *s) {
|
||||
Yap_DefaultStreamOps(s);
|
||||
}
|
||||
|
||||
static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, void *vfsp) {
|
||||
static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
|
||||
StreamDesc *s = &GLOBAL_Stream[sno];
|
||||
s->file = file;
|
||||
s->status = flags;
|
||||
@ -295,7 +295,15 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, void *vfsp) {
|
||||
s->vfs = vfsp;
|
||||
s->encoding = ENC_ISO_UTF8;
|
||||
INIT_LOCK(s->streamlock);
|
||||
if (vfsp != NULL) {
|
||||
s->u.private_data = vfsp->open(vfsp->name, (sno == StdInStream ? "read" : "write" ));
|
||||
if (s->u.private_data == NULL) {
|
||||
(PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkIntTerm(sno), "%s", vfsp->name));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
unix_upd_stream_info(s);
|
||||
}
|
||||
/* Getting streams to prompt is a mess because we need for cooperation
|
||||
between readers and writers to the stream :-(
|
||||
*/
|
||||
@ -326,6 +334,11 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, void *vfsp) {
|
||||
#endif /* HAVE_SETBUF */
|
||||
}
|
||||
|
||||
void Yap_InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
|
||||
InitStdStream(sno, flags, file, vfsp);
|
||||
}
|
||||
|
||||
|
||||
Term Yap_StreamUserName(int sno) {
|
||||
Term atname;
|
||||
StreamDesc *s = &GLOBAL_Stream[sno];
|
||||
@ -1070,6 +1083,7 @@ bool Yap_initStream(int sno, FILE *fd, const char *name, Term file_name,
|
||||
st->encoding = encoding;
|
||||
}
|
||||
|
||||
|
||||
if (name == NULL) {
|
||||
char buf[YAP_FILENAME_MAX + 1];
|
||||
name = Yap_guessFileName(fd, sno, buf, YAP_FILENAME_MAX);
|
||||
|
@ -281,7 +281,7 @@ has_reposition(int sno,
|
||||
}
|
||||
|
||||
char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
|
||||
size_t maxs = max(255, max);
|
||||
size_t maxs = Yap_Max(255, max);
|
||||
if (!nameb) {
|
||||
nameb = malloc(maxs + 1);
|
||||
}
|
||||
|
@ -685,7 +685,7 @@ void init_myddas(void) {
|
||||
#if defined MYDDAS_ODBC
|
||||
Yap_InitBackMYDDAS_ODBCPreds();
|
||||
#endif
|
||||
#if defined MYDDAS_SQLITE3
|
||||
#if WIN32
|
||||
Yap_InitBackMYDDAS_SQLITE3Preds();
|
||||
#endif
|
||||
#if defined USE_MYDDAS
|
||||
@ -697,7 +697,7 @@ void init_myddas(void) {
|
||||
#if defined MYDDAS_ODBC
|
||||
Yap_InitMYDDAS_ODBCPreds();
|
||||
#endif
|
||||
#if defined MYDDAS_SQLITE3
|
||||
#if WIN32
|
||||
Yap_InitMYDDAS_SQLITE3Preds();
|
||||
#endif
|
||||
#if defined USE_MYDDAS
|
||||
|
@ -39,11 +39,17 @@ function(cpp_compile output filename)
|
||||
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
|
||||
endfunction()
|
||||
|
||||
if (ANDROID)
|
||||
set (MYDDAS_PL_OUTDIR ${YAP_APP_DIR}/src/generated/assets/Yap} )
|
||||
else()
|
||||
set (MYDDAS_PL_OUTDIR ${CMAKE_CURRENT_BINARY_DIR} )
|
||||
endif()
|
||||
|
||||
function(cpp_driver output dbms filename)
|
||||
if (0)
|
||||
set(outfile ${libpl}/myddas_${dbms}.yap)
|
||||
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
|
||||
else()
|
||||
set(outfile ${CMAKE_CURRENT_BINARY_DIR}/myddas_${dbms}.yap)
|
||||
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
|
||||
endif()
|
||||
set(${output} ${${output}} ${outfile} PARENT_SCOPE)
|
||||
IF (MSVC)
|
||||
@ -74,3 +80,4 @@ add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP} )
|
||||
install(FILES ${MYDDAS_YAP}
|
||||
DESTINATION ${libpl}
|
||||
)
|
||||
|
||||
|
@ -40,14 +40,14 @@ src/Android/jni/sqlite/android_database_SQLiteConnection.cpp
|
||||
src/Android/jni/sqlite/android_database_SQLiteDebug.cpp
|
||||
src/Android/jni/sqlite/android_database_SQLiteGlobal.cpp
|
||||
src/Android/jni/sqlite/nativehelper/jni.h
|
||||
src/Android/jni/sqlite/nativehelper/jniConstants.h
|
||||
src/Android/jni/sqlite/nativehelper/JniConstants.h
|
||||
src/Android/jni/sqlite/nativehelper/JNIHelp.h
|
||||
src/Android/jni/sqlite/nativehelper/ScopedLocalRef.h
|
||||
)
|
||||
|
||||
endif (ANDROID)
|
||||
|
||||
add_component( Yapsqlite3
|
||||
add_library( Yapsqlite3 SHARED
|
||||
${YAPSQLITE3_SOURCES} )
|
||||
|
||||
MY_set_target_properties(Yapsqlite3
|
||||
@ -56,3 +56,9 @@ add_component( Yapsqlite3
|
||||
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
|
||||
POSITION_INDEPENDENT_CODE TRUE
|
||||
)
|
||||
|
||||
|
||||
if (ANDROID)
|
||||
target_link_libraries(Yapsqlite3 android log)
|
||||
|
||||
endif ()
|
@ -658,6 +658,17 @@ void init_sqlite3( void )
|
||||
Yap_InitBackMYDDAS_SQLITE3Preds();
|
||||
}
|
||||
|
||||
#if _ANDROID_
|
||||
JNIEXPORT void JNICALL
|
||||
lib_yap_up_pt_init_sqlite(JNIEnv *env);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
lib_yap_up_pt_init_sqlite(JNIEnv *env)
|
||||
{
|
||||
init_sqlite3();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
|
@ -360,23 +360,22 @@ static jlong nativePrepareStatement(JNIEnv *env, jclass clazz,
|
||||
int err = sqlite3_prepare16_v2(connection->db, sql, sqlLength * sizeof(jchar),
|
||||
&statement, NULL);
|
||||
env->ReleaseStringCritical(sqlString, sql);
|
||||
|
||||
#if 0
|
||||
if (err != SQLITE_OK) {
|
||||
// Error messages like 'near ")": syntax error' are not
|
||||
// always helpful enough, so construct an error string that
|
||||
// includes the query itself.
|
||||
const char *query = env->GetStringUTFChars(sqlString, NULL);
|
||||
char *message = (char *)malloc(strlen(query) + 50);
|
||||
char *message[512];
|
||||
if (message) {
|
||||
strcpy(message, ", while compiling: "); // less than 50 chars
|
||||
strcat(message, query);
|
||||
}
|
||||
env->ReleaseStringUTFChars(sqlString, query);
|
||||
throw_sqlite3_exception(env, connection->db, message);
|
||||
free(message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
ALOGV("Prepared statement %p on connection %p", statement, connection->db);
|
||||
return reinterpret_cast<jlong>(statement);
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ add_library (YAPPython SHARED pyload.c ${PYTHON_HEADERS} )
|
||||
if (WIN32)
|
||||
add_library (Py4YAP OBJECT ${PYTHON_SOURCES} ${PYTHON_HEADERS})
|
||||
|
||||
target_link_libraries(YAPPython libYap ${PYTHON_LIBRARIES})
|
||||
|
||||
else()
|
||||
add_library (Py4YAP SHARED ${PYTHON_SOURCES} ${PYTHON_HEADERS})
|
||||
|
||||
@ -21,7 +23,6 @@ add_library (Py4YAP SHARED ${PYTHON_SOURCES} ${PYTHON_HEADERS})
|
||||
set_property(TARGET Py4YAP PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES})
|
||||
target_link_libraries(YAPPython Py4YAP)
|
||||
|
||||
MY_install(TARGETS Py4YAP
|
||||
LIBRARY DESTINATION ${libdir}
|
||||
@ -33,7 +34,6 @@ endif()
|
||||
# arithmetic hassle.
|
||||
set_property(TARGET YAPPython PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_link_libraries(YAPPython libYap ${PYTHON_LIBRARIES})
|
||||
|
||||
set_property( SOURCE ${PYTHON_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 _GNU_SOURCE=1)
|
||||
|
||||
|
@ -20,6 +20,7 @@ else:
|
||||
dll = glob.glob(os.path.join(yap_lib_path,dll))[0]
|
||||
dll = os.path.abspath(dll)
|
||||
ctypes.CDLL(dll, mode=ctypes.RTLD_GLOBAL)
|
||||
if platform.system() == 'Apple'::
|
||||
load('libYap*')
|
||||
load('libYAP+*')
|
||||
load('libPy4YAP*')
|
||||
|
@ -8,12 +8,14 @@
|
||||
|
||||
# This is a CMake example for Python and Java
|
||||
|
||||
set (SOURCES yap.i)
|
||||
|
||||
INCLUDE(${SWIG_USE_FILE})
|
||||
|
||||
if (ANDROID)
|
||||
add_subdirectory(android)
|
||||
else(ANDROID)
|
||||
# add_subdirectory(java)
|
||||
add_subdirectory(java)
|
||||
endif(ANDROID)
|
||||
|
||||
set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS SWIGYAP=1)
|
||||
|
@ -1,21 +1,72 @@
|
||||
|
||||
# This is a CMake example for Python and Java
|
||||
# This is a CMake file for SWIG and Android
|
||||
|
||||
FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib )
|
||||
FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/assets)
|
||||
set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib )
|
||||
set( SWIG_MODULE_NAME pt.up.yap.lib )
|
||||
set ( pllib ${YAP_APP_DIR}/src/generated/assets/Yap )
|
||||
|
||||
set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/app/src/main/java/pt/up/yap/lib )
|
||||
|
||||
set ( SWIG_SOURCES ../yap.i )
|
||||
set ( SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i )
|
||||
SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON)
|
||||
|
||||
include_directories (
|
||||
${CMAKE_SOURCE_DIR}/CXX
|
||||
)
|
||||
set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
|
||||
set (GMP_INCLUDE_DIRS ${GMP_ROOT})
|
||||
set (GMP_LIBRARIES ${GMP_ROOT}/libgmp.so)
|
||||
|
||||
|
||||
add_custom_command (OUTPUT yap_swig.cpp
|
||||
COMMAND ${SWIG} -java -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_SOURCE_DIR}/CXX ${SWIG_SOURCES} -o yap_swig.cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}/pl
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}/os
|
||||
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${pl_library} ${pllib}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} ${pllib}/pl
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} ${pllib}/os
|
||||
COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_BINARY_DIR} -I${GMP_INCLUDE_DIRS} -DX_API="" -o yap_swig.cpp ${SWIG_SOURCES}
|
||||
DEPENDS ${SWIG_SOURCES} YAP++
|
||||
)
|
||||
|
||||
add_custom_target ( swig ALL
|
||||
DEPENDS yap_swig.cpp
|
||||
add_custom_command (OUTPUT swig_streamer.cpp
|
||||
COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_CURRENT_SOURCE_DIR} -o swig_streamer.cpp streamer.i
|
||||
DEPENDS streamer.i
|
||||
)
|
||||
|
||||
|
||||
# GMP_FOUND - true if GMP/MPIR was found
|
||||
# GMP_INCLUDE_DIRS - include search path
|
||||
# GMP_LIBRARIES - libraries to link with
|
||||
#config.h needs this (TODO: change in code latter)
|
||||
include_directories( .;${GMP_INCLUDE_DIRS};${CMAKE_SOURCE_DIR}/include;${CMAKE_SOURCE_DIR}/H;${CMAKE_SOURCE_DIR}/H/generated;${CMAKE_SOURCE_DIR}/os;${CMAKE_SOURCE_DIR}/OPTYap;${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} )
|
||||
|
||||
|
||||
|
||||
|
||||
add_library (YAPJava SHARED
|
||||
yap_swig.cpp swig_streamer.cpp streamer.cpp streamer.h
|
||||
)
|
||||
target_link_libraries(YAPJava ${GMP_LIBRARIES} )
|
||||
|
||||
|
||||
target_link_libraries( YAPJava YAP++ libYap android log)
|
||||
|
||||
if (FALSE)
|
||||
|
||||
set (SWIG_ADD_MODULE YAPJava SHARED CPLUPLUS ${SWIG_SOURCES} )
|
||||
# Define swig module with given name and specified language
|
||||
|
||||
|
||||
set (SWIG_LINK_LIBRARIES YAPJava YAP++ libYAP )
|
||||
#- Link libraries to swig module
|
||||
|
||||
|
||||
add_library (YAPJavaTop SHARED
|
||||
main.cpp main.h
|
||||
)
|
||||
|
||||
target_link_libraries( YAPJavaTop ${SWIG_MODULE_${YAPJava}_REAL_NAME} YAP++ libYap android)
|
||||
|
||||
endif()
|
||||
|
@ -92,7 +92,10 @@ class JavaYAP {
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
System.loadLibrary("Native");
|
||||
System.loadLibrary("gmp");
|
||||
System.loadLibrary("Yap");
|
||||
System.loadLibrary("YAP++");
|
||||
System.loadLibrary("JAVAYap");
|
||||
|
||||
JavaYAP y = new JavaYAP();
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
|
||||
// supports Java and Python
|
||||
|
||||
|
||||
%{
|
||||
|
||||
#include <cmath>
|
||||
#include <gmpxx.h>
|
||||
|
||||
extern "C"{
|
||||
#ifdef SWIGPYTHON
|
||||
#include <Python.h>
|
||||
@ -22,11 +23,7 @@
|
||||
%include std_string.i
|
||||
%include std_vector.i
|
||||
|
||||
namespace std {
|
||||
%template(vectort) vector<Term>;
|
||||
};
|
||||
|
||||
%feature("novaluewrapper") std::vector<Term>;
|
||||
|
||||
%ignore *::operator[];
|
||||
|
||||
@ -255,117 +252,41 @@ case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
||||
|
||||
#else
|
||||
|
||||
%typemap(in) arity_t { (jlong)($input); }
|
||||
|
||||
%typecheck(2) Int { $1 = PyLong_Check($input); }
|
||||
%typecheck(3) double { $1 = PyFloat_Check($input); }
|
||||
%typecheck(2) const char * { $1 = PyUnicode_Check($input); }
|
||||
|
||||
%typecheck(1) Term { $1 = !PyUnicode_Check($input); }
|
||||
%typecheck(1) YAP_Term { $1 = PyUnicode_Check($input); }
|
||||
|
||||
%typecheck(0) YAPTerm { $1 = !PyUnicode_Check($input); }
|
||||
|
||||
|
||||
%typemap(in) jlong %{
|
||||
$1 = (jlong)$input;
|
||||
%}
|
||||
|
||||
%typemap(out) arity_t { *(jlong *)&$result = $1; }
|
||||
|
||||
// Language independent exception handler
|
||||
%include exception.i
|
||||
// simplified version
|
||||
%include <exception.i>
|
||||
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch (YAPError e) {
|
||||
yap_error_number en = e.getID();
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
switch (e.getErrorClass()) {
|
||||
case YAPC_NO_ERROR:
|
||||
break;
|
||||
/// bad domain, "first argument often is the predicate.
|
||||
case DOMAIN_ERROR: {
|
||||
switch (en) {
|
||||
case DOMAIN_ERROR_OUT_OF_RANGE:
|
||||
case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
||||
SWIG_exception(SWIG_IndexError, e.text());
|
||||
break;
|
||||
case DOMAIN_ERROR_CLOSE_OPTION:
|
||||
case DOMAIN_ERROR_ENCODING:
|
||||
case DOMAIN_ERROR_PROLOG_FLAG:
|
||||
case DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION:
|
||||
case DOMAIN_ERROR_READ_OPTION:
|
||||
case DOMAIN_ERROR_SET_STREAM_OPTION:
|
||||
SWIG_exception(SWIG_AttributeError, e.text());
|
||||
break;
|
||||
case DOMAIN_ERROR_FILE_ERRORS:
|
||||
case DOMAIN_ERROR_FILE_TYPE:
|
||||
case DOMAIN_ERROR_IO_MODE:
|
||||
case DOMAIN_ERROR_SOURCE_SINK:
|
||||
case DOMAIN_ERROR_STREAM_POSITION:
|
||||
SWIG_exception(SWIG_IOError, e.text());
|
||||
break;
|
||||
default:
|
||||
SWIG_exception(SWIG_ValueError, e.text());
|
||||
}
|
||||
} break;
|
||||
/// bad arithmetic
|
||||
case EVALUATION_ERROR: {
|
||||
switch (en) {
|
||||
case EVALUATION_ERROR_FLOAT_OVERFLOW:
|
||||
case EVALUATION_ERROR_FLOAT_UNDERFLOW:
|
||||
case EVALUATION_ERROR_INT_OVERFLOW:
|
||||
case EVALUATION_ERROR_UNDERFLOW:
|
||||
SWIG_exception(SWIG_OverflowError, e.text());
|
||||
break;
|
||||
case EVALUATION_ERROR_ZERO_DIVISOR:
|
||||
SWIG_exception(SWIG_DivisionByZero, e.text());
|
||||
break;
|
||||
default:
|
||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
||||
}
|
||||
} break;
|
||||
/// missing object (I/O mostly)
|
||||
case EXISTENCE_ERROR:
|
||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
||||
break;
|
||||
/// should be bound
|
||||
case INSTANTIATION_ERROR_CLASS:
|
||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
||||
break;
|
||||
/// bad access, I/O
|
||||
case PERMISSION_ERROR: {
|
||||
switch (en) {
|
||||
case PERMISSION_ERROR_INPUT_BINARY_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_TEXT_STREAM:
|
||||
case PERMISSION_ERROR_OPEN_SOURCE_SINK:
|
||||
case PERMISSION_ERROR_OUTPUT_BINARY_STREAM:
|
||||
case PERMISSION_ERROR_REPOSITION_STREAM:
|
||||
case PERMISSION_ERROR_OUTPUT_STREAM:
|
||||
case PERMISSION_ERROR_OUTPUT_TEXT_STREAM:
|
||||
SWIG_exception(SWIG_OverflowError, e.text());
|
||||
break;
|
||||
default:
|
||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
||||
}
|
||||
} break;
|
||||
/// something that could not be represented into a type
|
||||
case REPRESENTATION_ERROR:
|
||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
||||
break;
|
||||
/// not enough ....
|
||||
case RESOURCE_ERROR:
|
||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
||||
break;
|
||||
/// bad text
|
||||
case SYNTAX_ERROR_CLASS:
|
||||
SWIG_exception(SWIG_SyntaxError, e.text());
|
||||
break;
|
||||
/// OS or internal
|
||||
case SYSTEM_ERROR_CLASS:
|
||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
||||
break;
|
||||
/// bad typing
|
||||
case TYPE_ERROR:
|
||||
SWIG_exception(SWIG_TypeError, e.text());
|
||||
break;
|
||||
/// should be unbound
|
||||
case UNINSTANTIATION_ERROR_CLASS:
|
||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
||||
break;
|
||||
/// escape hatch
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (const std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError, e.what());
|
||||
} catch (const std::exception& e) {
|
||||
SWIG_exception(SWIG_RuntimeError, e.what());
|
||||
} catch (...) {
|
||||
SWIG_exception(SWIG_RuntimeError, "unknown exception");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
%{
|
||||
@ -383,10 +304,13 @@ case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
||||
// it shouldn't
|
||||
}
|
||||
|
||||
extern void init_sqlite();
|
||||
|
||||
%}
|
||||
|
||||
|
||||
/* turn on director wrapping Callback */
|
||||
%feature("director") YAPCallback;
|
||||
//%feature("director") YAPCallback;
|
||||
|
||||
%include "yapa.hh"
|
||||
|
||||
@ -398,5 +322,17 @@ case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
||||
|
||||
%include "yapq.hh"
|
||||
|
||||
|
||||
|
||||
namespace std {
|
||||
|
||||
%template(TermVector) vector<Term>;
|
||||
%feature("novaluewrapper") vector<Term>;
|
||||
|
||||
//%template(YAPTermVector) vector<YAPTerm>;
|
||||
//%feature("novaluewrapper") vector<YAPTerm>;
|
||||
};
|
||||
|
||||
|
||||
%init %{
|
||||
%}
|
||||
|
@ -36,13 +36,7 @@ set (LIBRARY_PL
|
||||
dcg/basics.pl
|
||||
)
|
||||
|
||||
|
||||
if (ANDROID)
|
||||
file(INSTALL ${LIBRARY_PL} DESTINATION ${libpl})
|
||||
else()
|
||||
|
||||
install(FILES ${LIBRARY_PL}
|
||||
DESTINATION ${libpl}
|
||||
)
|
||||
|
||||
endif()
|
||||
|
Reference in New Issue
Block a user