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