more C++/Android fixes
This commit is contained in:
parent
1caf68972f
commit
e06bcd659e
52
CXX/yapi.cpp
52
CXX/yapi.cpp
@ -272,10 +272,24 @@ char *YAPTerm::text(void) {
|
||||
char *os;
|
||||
int enc;
|
||||
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "I LCL0+%p/t=(%d) %x", LCL0, t, LCL0[-15]) ; }
|
||||
BACKUP_MACHINE_REGS();
|
||||
if (!(os = Yap_HandleToString(t, sze, &length, &enc, 0))) {
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "IIa LCL0+t=(%p) %x", LCL0, LCL0[-15]) ; }
|
||||
RECOVER_MACHINE_REGS();
|
||||
return (char *)NULL;
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return os;
|
||||
}
|
||||
|
||||
char *YAPQuery::text(void) {
|
||||
size_t sze = 4096, length;
|
||||
char *os;
|
||||
int enc;
|
||||
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "I LCL0+%p/t=(%d) %x", LCL0, *q_g, LCL0[-15]) ; }
|
||||
BACKUP_MACHINE_REGS();
|
||||
if (!(os = Yap_HandleToString(*q_g, sze, &length, &enc, 0))) {
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "IIa LCL0+t=(%p) %x oz=%p %s", LCL0, LCL0[-15], os, os) ; }
|
||||
RECOVER_MACHINE_REGS();
|
||||
return (char *)NULL;
|
||||
}
|
||||
@ -374,14 +388,13 @@ char *YAPAtom::getName(void) {
|
||||
}
|
||||
|
||||
|
||||
YAPPredicate::YAPPredicate(const char *s, Term **outp, YAPTerm &vnames) throw (int) {
|
||||
YAPPredicate::YAPPredicate(const char *s, Term* &outp, YAPTerm &vnames) throw (int) {
|
||||
CACHE_REGS
|
||||
vnames = Yap_NewSlots(1 PASS_REGS);
|
||||
Term t = Yap_StringToTerm(s, strlen(s)+1, Yap_GetFromSlot( vnames.t PASS_REGS));
|
||||
if (t == 0L)
|
||||
throw YAPError::YAP_SYNTAX_ERROR;
|
||||
ap = getPred( t, outp );
|
||||
//{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "OUT vnames=%d ap=%p LCL0=%p", vnames, ap, LCL0) ; }
|
||||
}
|
||||
|
||||
YAPPredicate::YAPPredicate(YAPAtom at) {
|
||||
@ -400,20 +413,21 @@ YAPPredicate::YAPPredicate(YAPAtom at, arity_t arity) {
|
||||
}
|
||||
|
||||
/// auxiliary routine to find a predicate in the current module.
|
||||
PredEntry *YAPPredicate::getPred( Term t, Term **outp ) {
|
||||
PredEntry *YAPPredicate::getPred( Term t, Term* &outp ) {
|
||||
CACHE_REGS
|
||||
Term m = CurrentModule ;
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "H= %p, outp=%p", HR, outp) ; }
|
||||
t = Yap_StripModule(t, &m);
|
||||
if (IsVarTerm(t) || IsNumTerm(t)) {
|
||||
ap = (PredEntry *)NULL;
|
||||
if (outp) *outp = (Term *)NULL;
|
||||
outp = (Term *)NULL;
|
||||
}
|
||||
if (IsAtomTerm(t)) {
|
||||
ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m));
|
||||
if (outp) *outp = (Term *)NULL;
|
||||
if (outp) outp = (Term *)NULL;
|
||||
} else if (IsPairTerm(t)) {
|
||||
ap = RepPredProp(PredPropByFunc(FunctorCsult, PROLOG_MODULE));
|
||||
if (outp) *outp = HR;
|
||||
outp = HR;
|
||||
HR[0] = RepPair(t)[0];
|
||||
HR[1] = m;
|
||||
HR+=2;
|
||||
@ -421,12 +435,14 @@ PredEntry *YAPPredicate::getPred( Term t, Term **outp ) {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (IsExtensionFunctor(f)) {
|
||||
ap = (PredEntry *)NULL;
|
||||
if (outp) *outp = (Term *)NULL;
|
||||
}
|
||||
outp = (Term *)NULL;
|
||||
} else {
|
||||
ap = RepPredProp(PredPropByFunc(f, m));
|
||||
if (outp) *outp = RepAppl(t)+1;
|
||||
outp = RepAppl(t)+1;
|
||||
}
|
||||
}
|
||||
return ap;
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "done H= %p, outp=%p", HR, outp) ; }
|
||||
return ap;
|
||||
}
|
||||
|
||||
YAPPredicate::YAPPredicate(YAPFunctor f) {
|
||||
@ -486,21 +502,23 @@ bool YAPQuery::next()
|
||||
{
|
||||
CACHE_REGS
|
||||
int result;
|
||||
if (this->q_open != 1) return false;
|
||||
if (q_open != 1) return false;
|
||||
if (setjmp(((YAPQuery *)LOCAL_execution)->q_env))
|
||||
return false;
|
||||
// don't forget, on success these guys must create slots
|
||||
if (this->q_state == 0) {
|
||||
if (q_state == 0) {
|
||||
// extern void toggle_low_level_trace(void);
|
||||
//toggle_low_level_trace();
|
||||
result = (bool)YAP_EnterGoal((YAP_PredEntryPtr)this->ap, this->q_g, &this->q_h);
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "next %p", HR) ; }
|
||||
result = (bool)YAP_EnterGoal((YAP_PredEntryPtr)ap, q_g, &q_h);
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "done") ; }
|
||||
} else {
|
||||
LOCAL_AllowRestart = this->q_open;
|
||||
result = (bool)YAP_RetryGoal(&this->q_h);
|
||||
result = (bool)YAP_RetryGoal(&q_h);
|
||||
}
|
||||
this->q_state = 1;
|
||||
if (!result) {
|
||||
YAP_LeaveGoal(FALSE, &this->q_h);
|
||||
YAP_LeaveGoal(FALSE, &q_h);
|
||||
this->q_open = 0;
|
||||
}
|
||||
return result;
|
||||
|
30
CXX/yapi.hh
30
CXX/yapi.hh
@ -355,19 +355,20 @@ private:
|
||||
PredEntry *ap;
|
||||
|
||||
/// auxiliary routine to find a predicate in the current module.
|
||||
PredEntry *getPred( Term t, Term **outp ) ;
|
||||
PredEntry *getPred( Term t, Term* &outp ) ;
|
||||
|
||||
/// String constructor for predicates
|
||||
///
|
||||
/// It also communicates the array of arguments t[] abd the array of variables
|
||||
/// back to yapquery
|
||||
YAPPredicate(const char *s, Term **outp, YAPTerm& vnames ) throw (int);
|
||||
YAPPredicate(const char *s, Term* &outp, YAPTerm& vnames ) throw (int);
|
||||
|
||||
/// Term constructor for predicates
|
||||
///
|
||||
/// It is just a call to getPred
|
||||
inline YAPPredicate(Term t) {
|
||||
ap = getPred( t , (Term **)NULL );
|
||||
CELL * v = NULL;
|
||||
ap = getPred( t , v );
|
||||
}
|
||||
|
||||
/// Cast constructor for predicates,
|
||||
@ -425,19 +426,20 @@ public:
|
||||
t = YAP_ReadBuffer(s,&tp);
|
||||
if (t == 0L)
|
||||
throw YAPError::YAP_SYNTAX_ERROR;
|
||||
ap = getPred( t, (Term **)NULL );
|
||||
CELL * v;
|
||||
ap = getPred( t, v);
|
||||
}
|
||||
|
||||
|
||||
/// String constructor for predicates, also keeps arguments in tp[]
|
||||
///
|
||||
/// String is a Prolog term, we extract the main functor after considering the module qualifiers.
|
||||
inline YAPPredicate(char *s, Term **outp) throw (int) {
|
||||
inline YAPPredicate(char *s, Term* &outp) throw (int) {
|
||||
Term t, tp;
|
||||
t = YAP_ReadBuffer(s,&tp);
|
||||
if (t == 0L)
|
||||
throw YAPError::YAP_SYNTAX_ERROR;
|
||||
ap = getPred( t, (Term **)NULL );
|
||||
ap = getPred( t, outp );
|
||||
}
|
||||
|
||||
/// meta-call this predicate, with arguments ts[]
|
||||
@ -508,23 +510,17 @@ public:
|
||||
///
|
||||
/// It is given a string, calls the parser and obtains a Prolog term that should be a callable
|
||||
/// goal. It does not ask for a list of variables.
|
||||
inline YAPQuery(char *s): YAPPredicate(s, &this->q_g)
|
||||
inline YAPQuery(char *s): YAPPredicate(s, q_g)
|
||||
{
|
||||
this->vnames = vnames;
|
||||
Term *ts = this->q_g;
|
||||
|
||||
initQuery( ts );
|
||||
initQuery( q_g );
|
||||
}
|
||||
/// string constructor with varnames
|
||||
///
|
||||
/// It is given a string, calls the parser and obtains a Prolog term that should be a callable
|
||||
/// goal and a list of variables. Useful for top-level simulation. Works within the current module.
|
||||
inline YAPQuery(char *s, YAPTerm &vnames): YAPPredicate(s, &this->q_g, vnames)
|
||||
inline YAPQuery(char *s, YAPTerm &vnames): YAPPredicate(s, q_g, vnames)
|
||||
{
|
||||
this->vnames = vnames;
|
||||
Term *ts = this->q_g;
|
||||
|
||||
initQuery( ts );
|
||||
initQuery( q_g );
|
||||
}
|
||||
/// set flags for query execution, currently only for exception handling
|
||||
void setFlag(int flag) {q_flags |= flag; }
|
||||
@ -537,6 +533,8 @@ public:
|
||||
/// ask for the next solution of the current query
|
||||
/// same call for every solution
|
||||
bool next();
|
||||
/// represent the top-goal
|
||||
char *text();
|
||||
/// remove alternatives in the current search space, and finish the current query
|
||||
void cut();
|
||||
/// finish the current query: undo all bindings.
|
||||
|
@ -150,7 +150,7 @@ typedef unsigned long uintptr_t;
|
||||
|
||||
#ifndef PL_HAVE_TERM_T
|
||||
#define PL_HAVE_TERM_Temacs
|
||||
typedef uintptr_t term_t;
|
||||
typedef intptr_t term_t;
|
||||
#endif
|
||||
typedef struct mod_entry *module_t;
|
||||
typedef struct DB_STRUCT *record_t;
|
||||
|
@ -87,11 +87,11 @@ android/jni/Application.mk: android/jni/Android.mk
|
||||
android/jni/Android.mk: android/AndroidManifest.xml
|
||||
cp $(srcdir)/android/JavaYap.java android/src/pt/up/fc/dcc/yap
|
||||
cp $(srcdir)/android/main.xml android/res/layout
|
||||
cp -r $(YAP_EXPORT_PLS) android/assets/share/Yap
|
||||
cp -r $(YAP_EXPORT_PLS)/* android/assets/share/Yap
|
||||
cp -r $(YAP_EXPORT_DLLS)/*.so android/jni
|
||||
cp -r $(YAP_EXPORT_SAVED_STATE) android/assets/lib/Yap
|
||||
cp -r $(JNI_SQLITE) android/jni
|
||||
cp -r $(JAVA_SQLITE) android/src
|
||||
cp -r $(PROSQLITE) android/assets/share/Yap
|
||||
cp Android.mk android/jni
|
||||
|
||||
android/AndroidManifest.xml: $(ANDROID_PKG)
|
||||
@ -99,9 +99,11 @@ android/AndroidManifest.xml: $(ANDROID_PKG)
|
||||
mkdir -p android/assets
|
||||
mkdir -p android/assets/share
|
||||
mkdir -p android/assets/share/Yap
|
||||
mkdir -p android/assets/lib
|
||||
mkdir -p android/assets/lib/Yap
|
||||
mkdir -p android/jni
|
||||
|
||||
android/jni/yap_wrap.cpp: $(srcdir)/yap.i android/AndroidManifest.xml
|
||||
android/jni/yap_wrap.cpp: $(srcdir)/yap.i $(srcdir)/../../CXX/yapi.hh $(srcdir)/../../CXX/yapi.cpp android/AndroidManifest.xml
|
||||
$(SWIG) -c++ -java -I$(srcdir)/../../CXX -package pt.up.fc.dcc.yap -outdir android/src/pt/up/fc/dcc/yap -o android/jni/yap_wrap.cpp $<
|
||||
|
||||
install-android: android
|
||||
|
@ -40,11 +40,17 @@ public class JavaYap extends Activity
|
||||
{
|
||||
YAPQuery q = eng.query( str );
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onQueryButtonClick called");
|
||||
}
|
||||
YAPListTerm vs0 = q.namedVars();
|
||||
Boolean rc;
|
||||
|
||||
// text.setText("");
|
||||
if (vs0.nil()) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "q=");
|
||||
}
|
||||
if (q.next()) {
|
||||
outputText.append( "yes\n" );
|
||||
} else {
|
||||
@ -52,8 +58,16 @@ public class JavaYap extends Activity
|
||||
}
|
||||
} else {
|
||||
int i=1;
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "q=");
|
||||
|
||||
}
|
||||
while (rc = q.next()) {
|
||||
YAPListTerm vs = vs0;
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "q=");
|
||||
|
||||
}
|
||||
YAPListTerm vs = vs0;
|
||||
while(!vs.nil()){
|
||||
YAPTerm eq = vs.car();
|
||||
//outputText.append(Integer.toString(i) + ": " + eq.text() );
|
||||
|
Reference in New Issue
Block a user