android
This commit is contained in:
parent
55bd75b8d8
commit
272d28ae5f
@ -10,7 +10,7 @@
|
||||
#endif /* INDENT_CODE */
|
||||
|
||||
BOp(call_cpred, Osbpp);
|
||||
#if __ANDROID__
|
||||
#if __ANDROID__ && STRONG_DEBUG
|
||||
char *s; Atom name;
|
||||
if (PREG->y_u.Osbpp.p->ArityOfPE) {
|
||||
Functor f = PREG->y_u.Osbpp.p->FunctorOfPred;
|
||||
|
9
C/init.c
9
C/init.c
@ -1125,12 +1125,21 @@ InitAtoms(void)
|
||||
HashChain[i].Entry = NIL;
|
||||
}
|
||||
NOfAtoms = 0;
|
||||
#if OLD_STYLE_INITIAL_ATOMS
|
||||
Yap_LookupAtomWithAddress("**",(AtomEntry *)&(SF_STORE->AtFoundVar));
|
||||
Yap_ReleaseAtom(AtomFoundVar);
|
||||
Yap_LookupAtomWithAddress("?",(AtomEntry *)&(SF_STORE->AtFreeTerm));
|
||||
Yap_ReleaseAtom(AtomFreeTerm);
|
||||
Yap_LookupAtomWithAddress("[]",(AtomEntry *)&(SF_STORE->AtNil));
|
||||
Yap_LookupAtomWithAddress(".",(AtomEntry *)&(SF_STORE->AtDot));
|
||||
#else
|
||||
SF_STORE->AtFoundVar = Yap_LookupAtom("**");
|
||||
Yap_ReleaseAtom(AtomFoundVar);
|
||||
SF_STORE->AtFreeTerm = Yap_LookupAtom("?");
|
||||
Yap_ReleaseAtom(AtomFreeTerm);
|
||||
SF_STORE->AtNil = Yap_LookupAtom("[]");
|
||||
SF_STORE->AtDot = Yap_LookupAtom(".");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -931,11 +931,16 @@ Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags
|
||||
|
||||
char *buf;
|
||||
|
||||
|
||||
size_t size = 4096, total = size;
|
||||
IOSTREAM *fd;
|
||||
|
||||
total = size;
|
||||
buf = malloc(total);
|
||||
#ifdef DEBUG
|
||||
{CACHE_REGS
|
||||
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %p \n", buf);}
|
||||
#endif
|
||||
while ( (fd = Sopenmem(&buf, &size, "w")) == NULL ||
|
||||
(( fd->encoding = ENC_UTF8) && FALSE) ||
|
||||
(PL_write_term(fd, l, 1200, flags) == 0) ||
|
||||
@ -944,7 +949,7 @@ Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags
|
||||
{
|
||||
#ifdef DEBUG
|
||||
{CACHE_REGS
|
||||
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %p, %x buf=%s\n", fd, LOCAL_SlotBase[28], buf);}
|
||||
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "fd %p, %x buf=%s\n", fd, LOCAL_SlotBase[28], buf);}
|
||||
#endif
|
||||
Sclose(fd);
|
||||
if (!fd)
|
||||
|
@ -2721,7 +2721,7 @@ p_yap_paths( USES_REGS1 ) {
|
||||
out2 = MkAtomTerm(Yap_LookupAtom(destdir));
|
||||
} else {
|
||||
#if __ANDROID__
|
||||
out2 = MkAtomTerm(Yap_LookupAtom("/assets/share"));
|
||||
out2 = MkAtomTerm(Yap_LookupAtom("/assets/share/Yap"));
|
||||
#else
|
||||
out2 = MkAtomTerm(Yap_LookupAtom(YAP_SHAREDIR));
|
||||
#endif
|
||||
|
23
CXX/yapi.cpp
23
CXX/yapi.cpp
@ -196,7 +196,7 @@ YAP_tag_t YAPTerm::tag() {
|
||||
return YAP_TAG_ATOM;
|
||||
return YAP_TAG_INT;
|
||||
} else {
|
||||
Functor f = FunctorOfTerm(tt);
|
||||
Functor f = FunctorOfTerm(tt);
|
||||
|
||||
if (IsExtensionFunctor(f)) {
|
||||
if (f == FunctorDBRef) {
|
||||
@ -288,18 +288,10 @@ const char *YAPTerm::text() {
|
||||
int enc;
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
#ifdef DEBUG
|
||||
{CACHE_REGS
|
||||
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %d, %x \n", t, LOCAL_SlotBase[t]);}
|
||||
#endif
|
||||
if (!(os = Yap_HandleToString(t, sze, &length, &enc, 0))) {
|
||||
RECOVER_MACHINE_REGS();
|
||||
return (char *)NULL;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
{CACHE_REGS
|
||||
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %d, %x %p\n", t, LOCAL_SlotBase[t], os);}
|
||||
#endif
|
||||
RECOVER_MACHINE_REGS();
|
||||
return os;
|
||||
}
|
||||
@ -315,16 +307,11 @@ char *YAPQuery::text() {
|
||||
RECOVER_MACHINE_REGS();
|
||||
return (char *)NULL;
|
||||
}
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II ") ; }
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II %s", os) ; }
|
||||
RECOVER_MACHINE_REGS();
|
||||
return os;
|
||||
}
|
||||
|
||||
bool YAPListTerm::nil() {
|
||||
CACHE_REGS
|
||||
return gt() == TermNil;
|
||||
}
|
||||
|
||||
|
||||
YAPIntegerTerm::YAPIntegerTerm(intptr_t i) { CACHE_REGS Term tn = MkIntegerTerm( i ); mk( tn ); }
|
||||
|
||||
@ -348,14 +335,14 @@ YAPTerm::YAPTerm(intptr_t i) { CACHE_REGS Term tn = MkIntegerTerm( i ); mk( tn )
|
||||
YAPTerm YAPListTerm::car()
|
||||
{
|
||||
Term to = gt();
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "to=%d", to) ; }
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "to=%p", to) ; }
|
||||
if (IsPairTerm(to))
|
||||
return YAPTerm(HeadOfTerm(to));
|
||||
else
|
||||
return MkIntTerm(-1);
|
||||
throw YAPError::YAP_DOMAIN_ERROR;
|
||||
}
|
||||
|
||||
YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); }
|
||||
YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); }
|
||||
|
||||
|
||||
char *YAPAtom::getName(void) {
|
||||
|
34
CXX/yapt.hh
34
CXX/yapt.hh
@ -121,10 +121,20 @@ public:
|
||||
YAPAtomTerm(wchar_t *s) ;
|
||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s, size_t len);
|
||||
virtual bool isVar() { return false; } /// type check for unbound
|
||||
virtual bool isAtom() { return true; } /// type check for atom
|
||||
virtual bool isInteger() { return false; } /// type check for integer
|
||||
virtual bool isFloat() { return false; } /// type check for floating-point
|
||||
virtual bool isString() { return false; } /// type check for a string " ... "
|
||||
virtual bool isCompound() { return false; } /// is a primitive term
|
||||
virtual bool isAppl() { return false; } /// is a structured term
|
||||
virtual bool isPair() { return false; } /// is a pair term
|
||||
virtual bool isGround() { return true; } /// term is ground
|
||||
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 *getName() { return AtomOfTerm( gt() )->StrOfAE; }
|
||||
const char *text() { return AtomOfTerm( gt() )->StrOfAE; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -139,6 +149,16 @@ public:
|
||||
YAPApplTerm(YAPFunctor f);
|
||||
YAPFunctor getFunctor();
|
||||
YAPTerm getArg(int i);
|
||||
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
|
||||
virtual bool isFloat() { return false; } /// type check for floating-point
|
||||
virtual bool isString() { return false; } /// type check for a string " ... "
|
||||
virtual bool isCompound() { return true; } /// is a primitive term
|
||||
virtual bool isAppl() { return true; } /// is a structured term
|
||||
virtual bool isPair() { return false; } /// is a pair term
|
||||
virtual bool isGround() { return true; } /// term is ground
|
||||
virtual bool isList() { return false; } /// [] is a list
|
||||
};
|
||||
|
||||
/**
|
||||
@ -158,14 +178,14 @@ public:
|
||||
* @brief Integer Term
|
||||
*/
|
||||
|
||||
class YAPIntegerTerm: private YAPTerm {
|
||||
class YAPIntegerTerm: YAPTerm {
|
||||
public:
|
||||
YAPIntegerTerm(intptr_t i);
|
||||
intptr_t getInteger() { return IntegerOfTerm( gt() ); }
|
||||
bool isTagged() { return IsIntTerm( gt() ); }
|
||||
};
|
||||
|
||||
class YAPListTerm: private YAPTerm {
|
||||
class YAPListTerm: public YAPTerm {
|
||||
public:
|
||||
/// Create a list term out of a standard term. Check if a valid operation.
|
||||
///
|
||||
@ -204,7 +224,13 @@ public:
|
||||
/// Check if the list is empty.
|
||||
///
|
||||
/// @param[in] the list
|
||||
bool nil();
|
||||
inline bool nil() {
|
||||
CACHE_REGS
|
||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II %x %x", gt(), TermNil) ; }
|
||||
return gt() == TermNil;
|
||||
}
|
||||
|
||||
;
|
||||
};
|
||||
|
||||
/**
|
||||
|
17
H/TermExt.h
17
H/TermExt.h
@ -32,16 +32,21 @@ language. Next, we discuss support to the most important ones.
|
||||
#define SF_STORE ((special_functors *)HEAP_INIT_BASE)
|
||||
#endif
|
||||
|
||||
#ifdef USE_OFFSETS
|
||||
#if defined(USE_OFFSETS)
|
||||
#define AtomFoundVar ((Atom)(&(((special_functors *)(NULL))->AtFoundVar)))
|
||||
#define AtomFreeTerm ((Atom)(&(((special_functors *)(NULL))->AtFreeTerm)))
|
||||
#define AtomNil ((Atom)(&(((special_functors *)(NULL))->AtNil)))
|
||||
#define AtomDot ((Atom)(&(((special_functors *)(NULL))->AtDot)))
|
||||
#else
|
||||
#elif OLD_STYLE_INITIAL_ATOMS
|
||||
#define AtomFoundVar AbsAtom((AtomEntry *)&(SF_STORE->AtFoundVar))
|
||||
#define AtomFreeTerm AbsAtom((AtomEntry *)&(SF_STORE->AtFreeTerm))
|
||||
#define AtomNil AbsAtom((AtomEntry *)&(SF_STORE->AtNil))
|
||||
#define AtomDot AbsAtom((AtomEntry *)&(SF_STORE->AtDot))
|
||||
#else
|
||||
#define AtomFoundVar AbsAtom(SF_STORE->AtFoundVar)
|
||||
#define AtomFreeTerm AbsAtom(SF_STORE->AtFreeTerm)
|
||||
#define AtomNil AbsAtom(SF_STORE->AtNil)
|
||||
#define AtomDot AbsAtom(SF_STORE->AtDot)
|
||||
#endif
|
||||
|
||||
#define TermFoundVar MkAtomTerm(AtomFoundVar)
|
||||
@ -164,10 +169,18 @@ exts;
|
||||
in the heap when we start the system */
|
||||
typedef struct special_functors_struct
|
||||
{
|
||||
|
||||
#if 0
|
||||
struct ExtraAtomEntryStruct AtFoundVar;
|
||||
struct ExtraAtomEntryStruct AtFreeTerm;
|
||||
struct ExtraAtomEntryStruct AtNil;
|
||||
struct ExtraAtomEntryStruct AtDot;
|
||||
#else
|
||||
struct AtomEntryStruct *AtFoundVar;
|
||||
struct AtomEntryStruct *AtFreeTerm;
|
||||
struct AtomEntryStruct *AtNil;
|
||||
struct AtomEntryStruct *AtDot;
|
||||
#endif
|
||||
}
|
||||
special_functors;
|
||||
#endif /* YAP_H */
|
||||
|
@ -625,9 +625,12 @@ libYap.a: $(LIB_OBJECTS) yapi.o
|
||||
adb shell mkdir -p /data/yap
|
||||
adb shell mkdir -p /data/yap/pl
|
||||
adb shell mkdir -p /data/yap/swi/library
|
||||
adb shell mkdir -p /data/yap/packages
|
||||
adb shell mkdir -p /data/yap/packages/chr
|
||||
adb shell mkdir -p /data/yap/packages/clib
|
||||
adb shell mkdir -p /data/yap/packages/myddas
|
||||
adb shell mkdir -p /data/yap/assets/myddas
|
||||
adb shell mkdir -p /data/yap/assets/lib
|
||||
adb shell mkdir -p /data/yap/assets/share
|
||||
adb push yap /data/yap/
|
||||
adb push @DYNYAPLIB@ /data/yap/
|
||||
for p in $(EXTRAYAPLIBS); do \
|
||||
@ -639,6 +642,9 @@ libYap.a: $(LIB_OBJECTS) yapi.o
|
||||
adb push $(srcdir)/swi/library /data/yap/swi/library
|
||||
adb push $(srcdir)/pl /data/yap/pl/
|
||||
adb push $(srcdir)/library /data/yap/library/
|
||||
adb push $(srcdir)/packages/myddas /data/yap/packages/myddas/
|
||||
adb push $(srcdir)/packages/chr /data/yap/packages/chr/
|
||||
adb push $(srcdir)/packages/clib /data/yap/packages/clib/
|
||||
adb shell "echo \"bootstrap('/data/yap/pl/init.yap'). module(user). qsave_program('/data/yap/startup.yss').\" | LD_LIBRARY_PATH=/data/yap /data/yap/yap@EXEC_SUFFIX@ -b /data/yap/pl/boot.yap"
|
||||
adb pull /data/yap/startup.yss
|
||||
#adb shell rm -rf /data/yap
|
||||
|
@ -15,6 +15,7 @@
|
||||
copy_line/2,
|
||||
filter/3,
|
||||
file_filter/3,
|
||||
file_select/2,
|
||||
file_filter_with_initialization/5,
|
||||
process/2
|
||||
]).
|
||||
@ -297,15 +298,22 @@ process(StreamInp, Command) :-
|
||||
fail
|
||||
).
|
||||
|
||||
/**
|
||||
* @pred file_filter(+ _FileIn_, + _FileOut_, + _Goal_) is meta
|
||||
*
|
||||
* @param _FileIn_ File to process
|
||||
* @param _FileOut_ Output file, often user_error
|
||||
* @param _Goal_ to be metacalled, receives FileIn and FileOut as
|
||||
* extra arguments
|
||||
*
|
||||
* @return succeeds
|
||||
|
||||
/** @pred file_filter(+ _FileIn_, + _FileOut_, + _Goal_) is meta
|
||||
For every line _LineIn_ in file _FileIn_, execute
|
||||
`call(Goal,LineIn,LineOut)`, and output _LineOut_ to file
|
||||
_FileOut_.
|
||||
|
||||
For every line _LineIn_ in file _FileIn_, execute
|
||||
`call(Goal,LineIn,LineOut)`, and output _LineOut_ to file
|
||||
_FileOut_.
|
||||
|
||||
The input stream is accessible through the alias `filter_input`, and the output
|
||||
stream is accessible through `filter_output`.
|
||||
The input stream is accessible through the alias `filter_input`, and
|
||||
the output stream is accessible through `filter_output`.
|
||||
*/
|
||||
file_filter(Inp, Out, Command) :-
|
||||
open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||
@ -327,6 +335,37 @@ file_filter_with_initialization(Inp, Out, Command, FormatString, Parameters) :-
|
||||
filter(StreamInp, StreamOut, Command),
|
||||
close(StreamInp),
|
||||
close(StreamOut).
|
||||
|
||||
|
||||
/**
|
||||
* @pred file_select(+ _FileIn_, + _Goal_) is meta
|
||||
*
|
||||
* @param _FileIn_ File to process
|
||||
* @param _Goal_ to be metacalled, receives FileIn as
|
||||
* extra arguments
|
||||
*
|
||||
* @return bindings to arguments of _Goal_.
|
||||
|
||||
For every line _LineIn_ in file _FileIn_, execute
|
||||
`call(`Goal,LineIn)`.
|
||||
|
||||
The input stream is accessible through the alias `filter_input`, and
|
||||
the output stream is accessible through `filter_output`.
|
||||
*/
|
||||
file_select(Inp, Command) :-
|
||||
open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||
repeat,
|
||||
read_line_to_codes(StreamInp, Line),
|
||||
(
|
||||
Line == end_of_file
|
||||
->
|
||||
close(StreamInp),
|
||||
!,
|
||||
fail
|
||||
;
|
||||
call(Command, Line)
|
||||
).
|
||||
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
|
@ -1550,7 +1550,7 @@ to be implemented directly. What about other Unixes?
|
||||
#endif
|
||||
|
||||
#if __ANDROID__
|
||||
if (LOCAL_InAssetDir) {
|
||||
if (LOCAL_InAssetDir ) {
|
||||
rval = strncpy(buf, LOCAL_InAssetDir, sizeof(buf));
|
||||
} else
|
||||
#endif
|
||||
@ -1676,7 +1676,7 @@ ChDir(const char *path)
|
||||
size_t sz = strlen(ospath)+1;
|
||||
AAssetDir_close(dir);
|
||||
LOCAL_InAssetDir = (char *)malloc(sz);
|
||||
strncpy(LOCAL_InAssetDir, ospath, sz-1);
|
||||
strncpy(LOCAL_InAssetDir, ospath, sz);
|
||||
succeed;
|
||||
} else {
|
||||
fail;
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 36f99e3c3c978fef25f899dc4fab1ffee334d73c
|
||||
Subproject commit b36fdac2281b7eef141095375d81456410dbcd2f
|
@ -1,27 +1,27 @@
|
||||
package pt.up.fc.dcc.yap;
|
||||
|
||||
/**** using sqlite
|
||||
For example,the following:
|
||||
For example,the following:
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
should be replaced with:
|
||||
should be replaced with:
|
||||
|
||||
import org.sqlite.database.sqlite.SQLiteDatabase;
|
||||
import org.sqlite.database.sqlite.SQLiteDatabase;
|
||||
|
||||
As well as replacing all uses of the classes in the android.database.sqlite.* namespace, the application must also be sure to use the following two:
|
||||
As well as replacing all uses of the classes in the android.database.sqlite.* namespace, the application must also be sure to use the following two:
|
||||
|
||||
org.sqlite.database.SQLException
|
||||
org.sqlite.database.DatabaseErrorHandler
|
||||
org.sqlite.database.SQLException
|
||||
org.sqlite.database.DatabaseErrorHandler
|
||||
|
||||
instead of:
|
||||
instead of:
|
||||
|
||||
android.database.SQLException
|
||||
android.database.DatabaseErrorHandler
|
||||
android.database.SQLException
|
||||
android.database.DatabaseErrorHandler
|
||||
|
||||
Aside from namespace changes, there are other differences from the stock Android interface that applications need to be aware of:
|
||||
Aside from namespace changes, there are other differences from the stock Android interface that applications need to be aware of:
|
||||
|
||||
The SQLiteStatement.simpleQueryForBlobFileDescriptor() API is not available. The collation sequence "UNICODE" is not available. The collation sequence "LOCALIZED", which normally changes with the system's current locale, is always equivalent to SQLite's built in collation BINARY.
|
||||
The SQLiteStatement.simpleQueryForBlobFileDescriptor() API is not available. The collation sequence "UNICODE" is not available. The collation sequence "LOCALIZED", which normally changes with the system's current locale, is always equivalent to SQLite's built in collation BINARY.
|
||||
|
||||
****/
|
||||
|
||||
@ -33,7 +33,7 @@ import android.widget.ScrollView;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.util.Log;
|
||||
import android.content.res.AssetManager;
|
||||
import android.widget.EditText;
|
||||
@ -46,212 +46,224 @@ import org.sqlite.database.sqlite.SQLiteOpenHelper;
|
||||
import org.sqlite.database.SQLException;
|
||||
import org.sqlite.database.DatabaseErrorHandler;
|
||||
class DoNotDeleteErrorHandler implements DatabaseErrorHandler {
|
||||
private static final String TAG = "DoNotDeleteErrorHandler";
|
||||
public void onCorruption(SQLiteDatabase dbObj) {
|
||||
Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath());
|
||||
}
|
||||
private static final String TAG = "DoNotDeleteErrorHandler";
|
||||
public void onCorruption(SQLiteDatabase dbObj) {
|
||||
Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath());
|
||||
}
|
||||
}
|
||||
public class JavaYap extends Activity
|
||||
{
|
||||
TextView outputText = null;
|
||||
ScrollView scroller = null;
|
||||
YAPEngine eng = null;
|
||||
EditText text;
|
||||
String str;
|
||||
String buf;
|
||||
TextView outputText = null;
|
||||
ScrollView scroller = null;
|
||||
YAPEngine eng = null;
|
||||
EditText text;
|
||||
String str;
|
||||
String buf;
|
||||
YAPQuery q;
|
||||
Boolean running = false;
|
||||
int i=1;
|
||||
YAPListTerm vs0;
|
||||
|
||||
void runQuery(String str)
|
||||
{
|
||||
try
|
||||
{
|
||||
YAPQuery q = eng.query( str );
|
||||
void runQuery(String str, Boolean more)
|
||||
{
|
||||
try
|
||||
{
|
||||
// check if at initial query
|
||||
if (!running) {
|
||||
q = eng.query( str );
|
||||
// get the uninstantiated query variables.
|
||||
vs0 = q.namedVars();
|
||||
running = true;
|
||||
}
|
||||
// start computing
|
||||
Boolean compute = true;
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onQueryButtonClick called");
|
||||
}
|
||||
YAPListTerm vs0 = q.namedVars();
|
||||
Boolean rc;
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onQueryButtonClick called");
|
||||
}
|
||||
|
||||
// text.setText("");
|
||||
if (vs0.nil()) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "q0=\n");
|
||||
}
|
||||
if (q.next()) {
|
||||
outputText.append( "yes\n" );
|
||||
} else {
|
||||
outputText.append( "no\n" );
|
||||
}
|
||||
} else {
|
||||
int i=1;
|
||||
if (BuildConfig.DEBUG) {
|
||||
//Log.i(TAG, "q1= "+vs0.text()+"\n");
|
||||
Boolean rc = true;
|
||||
|
||||
}
|
||||
while (rc = q.next()) {
|
||||
YAPListTerm vs = vs0;
|
||||
while(!vs.nil()){
|
||||
YAPTerm eq = vs.car();
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "q= "+vs0+"\n");
|
||||
}
|
||||
//outputText.append(Integer.toString(i) + ": " + eq.text() );
|
||||
outputText.append(Integer.toString(i++));
|
||||
Log.i(TAG, "q= "+ eq.getArg(1)+"\n");
|
||||
Log.i(TAG, "q= "+ eq.getArg(2)+"\n");
|
||||
Log.i(TAG, "q= "+ eq.getArg(1).text()+"\n");
|
||||
Log.i(TAG, "q= "+ eq.getArg(2).text()+"\n");
|
||||
outputText.append(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" );
|
||||
vs = vs.cdr();
|
||||
}
|
||||
}
|
||||
}
|
||||
q.close();
|
||||
} catch(Exception e){
|
||||
outputText.append("Exception thrown :" + e);
|
||||
return;
|
||||
// text.setText("");
|
||||
if (vs0.nil()) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "q0=\n");
|
||||
}
|
||||
if (compute && q.next()) {
|
||||
outputText.append( "yes\n" );
|
||||
running = compute = more;
|
||||
} else {
|
||||
outputText.append( "no\n" );
|
||||
running = false;
|
||||
compute = false;
|
||||
}
|
||||
} else {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "q1= "+vs0.text()+"\n");
|
||||
}
|
||||
while (compute && (rc = q.next()) ) {
|
||||
YAPListTerm vs = vs0;
|
||||
while(!vs.nil()){
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "q= "+vs0.text()+"\n");
|
||||
}
|
||||
YAPTerm eq = vs.car();
|
||||
//outputText.append(Integer.toString(i) + ": " + eq.text() );
|
||||
outputText.append(Integer.toString(i++));
|
||||
outputText.append(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" );
|
||||
vs = vs.cdr();
|
||||
}
|
||||
compute = more;
|
||||
}
|
||||
}
|
||||
if ( !rc) {
|
||||
q.close();
|
||||
running = compute = false;
|
||||
}
|
||||
} catch(Exception e){
|
||||
outputText.append("Exception thrown :" + e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
String s = null;
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
try {
|
||||
PackageManager m = getPackageManager();
|
||||
s = getPackageName();
|
||||
PackageInfo p = m.getPackageInfo(s, 0);
|
||||
//s = p.applicationInfo.dataDir;
|
||||
AssetManager mgr = getResources().getAssets();
|
||||
Log.i(TAG, "mgr=" +mgr + " " + s);
|
||||
load(mgr);
|
||||
} catch(NameNotFoundException e) {
|
||||
Log.e(TAG, "Couldn't find package information in PackageManager", e);
|
||||
}
|
||||
Log.i(TAG, "mgr=" +mgr);
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
String s = null;
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
text = (EditText)findViewById(R.id.EditText01);
|
||||
outputText = (TextView)findViewById(R.id.OutputText);
|
||||
outputText.setText("Application " + s + "\nPress 'Query' to start...\n");
|
||||
outputText.setMovementMethod(new ScrollingMovementMethod());
|
||||
scroller = (ScrollView)findViewById(R.id.Scroller);
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "window making done");
|
||||
}
|
||||
eng = new YAPEngine( );
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "engine done");
|
||||
}
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onClearButtonClick called");
|
||||
}
|
||||
JavaCallback callback = new JavaCallback( outputText );
|
||||
// set the Java Callback
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "before setting callback");
|
||||
}
|
||||
eng.setYAPCallback(callback);
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "callback done");
|
||||
}
|
||||
}
|
||||
try {
|
||||
PackageManager m = getPackageManager();
|
||||
s = getPackageName();
|
||||
PackageInfo p = m.getPackageInfo(s, 0);
|
||||
//s = p.applicationInfo.dataDir;
|
||||
AssetManager mgr = getResources().getAssets();
|
||||
Log.i(TAG, "mgr=" +mgr + " " + s);
|
||||
load(mgr);
|
||||
} catch(NameNotFoundException e) {
|
||||
Log.e(TAG, "Couldn't find package information in PackageManager", e);
|
||||
}
|
||||
Log.i(TAG, "mgr=" +mgr);
|
||||
|
||||
public void onClearButtonClick(View view)
|
||||
{
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onClearButtonClick called");
|
||||
}
|
||||
// Ensure scroll to end of text
|
||||
scroller.post(new Runnable() {
|
||||
public void run() {
|
||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
text.setText("");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onQueryButtonClick(View view)
|
||||
{
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onQueryButtonClick called");
|
||||
}
|
||||
// Ensure scroll to end of text
|
||||
scroller.post(new Runnable() {
|
||||
public void run() {
|
||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
str = text.getText().toString();
|
||||
outputText.append("?- " + str);
|
||||
Log.i(TAG, "onQueryButtonClick "+str + "\n");
|
||||
runQuery(str);
|
||||
}
|
||||
});
|
||||
}
|
||||
text = (EditText)findViewById(R.id.EditText01);
|
||||
outputText = (TextView)findViewById(R.id.OutputText);
|
||||
outputText.setText("Application " + s + "\nPress 'Query' to start...\n");
|
||||
outputText.setMovementMethod(new ScrollingMovementMethod());
|
||||
scroller = (ScrollView)findViewById(R.id.Scroller);
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "window making done");
|
||||
}
|
||||
eng = new YAPEngine( );
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "engine done");
|
||||
}
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onClearButtonClick called");
|
||||
}
|
||||
JavaCallback callback = new JavaCallback( outputText );
|
||||
// set the Java Callback
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "before setting callback");
|
||||
}
|
||||
eng.setYAPCallback(callback);
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "callback done");
|
||||
}
|
||||
}
|
||||
|
||||
public void onQuerySelectionButtonClick(View view)
|
||||
{
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onQuerySelectionButtonClick called");
|
||||
}
|
||||
// Ensure scroll to end of text
|
||||
scroller.post(new Runnable() {
|
||||
public void run() {
|
||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
int startSelection = text.getSelectionStart();
|
||||
int endSelection = text.getSelectionEnd();
|
||||
str = text.getText().toString().substring( startSelection, endSelection );
|
||||
Log.i(TAG, "onQuerySelectionButtonClick "+str);
|
||||
outputText.append("?- " + str + "\n");
|
||||
runQuery(str);
|
||||
}
|
||||
});
|
||||
}
|
||||
public void onClearButtonClick(View view)
|
||||
{
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onClearButtonClick called");
|
||||
}
|
||||
// Ensure scroll to end of text
|
||||
scroller.post(new Runnable() {
|
||||
public void run() {
|
||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
text.setText("");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onFirstButtonClick(View view)
|
||||
{
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onQueryButtonClick called");
|
||||
}
|
||||
// Ensure scroll to end of text
|
||||
scroller.post(new Runnable() {
|
||||
public void run() {
|
||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
str = text.getText().toString();
|
||||
//outputText.append("?- " + str+"\n\n");
|
||||
Log.i(TAG, "onQueryAnyButtonClick "+str + "\n");
|
||||
runQuery(str, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onAllButtonClick(View view)
|
||||
{
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onQueryButtonClick called");
|
||||
}
|
||||
// Ensure scroll to end of text
|
||||
scroller.post(new Runnable() {
|
||||
public void run() {
|
||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
str = text.getText().toString();
|
||||
outputText.append("?- " + str+"\n\n");
|
||||
Log.i(TAG, "onAllButtonClick "+str + "\n");
|
||||
runQuery(str, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/** static constructor */
|
||||
static {
|
||||
System.loadLibrary("android");
|
||||
System.loadLibrary("log");
|
||||
System.loadLibrary("gmp");
|
||||
System.loadLibrary("sqliteX");
|
||||
System.loadLibrary("example");
|
||||
}
|
||||
|
||||
private static native void load(AssetManager mgr);
|
||||
/** static constructor */
|
||||
static {
|
||||
System.loadLibrary("android");
|
||||
System.loadLibrary("log");
|
||||
System.loadLibrary("gmp");
|
||||
System.loadLibrary("sqliteX");
|
||||
System.loadLibrary("example");
|
||||
}
|
||||
|
||||
private AssetManager mgr;
|
||||
private static native void load(AssetManager mgr);
|
||||
|
||||
private static final String TAG = "JavaYap";
|
||||
private AssetManager mgr;
|
||||
|
||||
private static final String TAG = "JavaYap";
|
||||
|
||||
}
|
||||
|
||||
class JavaCallback extends YAPCallback
|
||||
{
|
||||
TextView output;
|
||||
|
||||
public JavaCallback( TextView outputText )
|
||||
{
|
||||
super();
|
||||
output = outputText;
|
||||
Log.i(TAG, "java callback init");
|
||||
}
|
||||
TextView output;
|
||||
|
||||
public JavaCallback( TextView outputText )
|
||||
{
|
||||
super();
|
||||
output = outputText;
|
||||
Log.i(TAG, "java callback init");
|
||||
}
|
||||
|
||||
|
||||
public void run()
|
||||
{
|
||||
Log.i(TAG, "java callback ");
|
||||
System.out.println("JavaCallback.run() ");
|
||||
}
|
||||
|
||||
public void run(String s)
|
||||
{
|
||||
Log.i(TAG, "java callback ");
|
||||
output.append(s);
|
||||
}
|
||||
|
||||
private static final String TAG = "JavaCallback";
|
||||
public void run()
|
||||
{
|
||||
Log.i(TAG, "java callback ");
|
||||
System.out.println("JavaCallback.run() ");
|
||||
}
|
||||
|
||||
public void run(String s)
|
||||
{
|
||||
Log.i(TAG, "java callback ");
|
||||
output.append(s);
|
||||
}
|
||||
|
||||
private static final String TAG = "JavaCallback";
|
||||
|
||||
}
|
||||
|
@ -9,12 +9,16 @@
|
||||
android:lines="6" />
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="wrap_content" android:layout_height="fill_parent">
|
||||
<Button android:id="@+id/QueryButton" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:text="Query..."
|
||||
android:onClick="onQueryButtonClick" />
|
||||
<Button android:id="@+id/QuerySelectionButton"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:text="Select" android:onClick="onQuerySelectionButtonClick" />
|
||||
<Button android:id="@+id/FirstButton"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="First..."
|
||||
android:onClick="onFirstButtonClick" />
|
||||
<Button android:id="@+id/AllButton"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="All..."
|
||||
android:onClick="onAllButtonClick" />
|
||||
<Button android:id="@+id/ClearButton" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:text="Reset"
|
||||
android:onClick="onClearButtonClick" />
|
||||
@ -27,5 +31,3 @@
|
||||
<!-- Set MaxLegth EditText -->
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
19
pl/absf.yap
19
pl/absf.yap
@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
@ -124,9 +124,8 @@ absolute_file_name(File,Opts,TrueFileName) :-
|
||||
/**
|
||||
@pred absolute_file_name(+Name:atom,+Path:atom) is nondet
|
||||
|
||||
11 Converts the given file specification into an absolute path, using default options. See absolute_file_name/3 for details on the options.
|
||||
Converts the given file specification into an absolute path, using default options. See absolute_file_name/3 for details on the options.
|
||||
*/
|
||||
|
||||
absolute_file_name(V,Out) :- var(V), !, % absolute_file_name needs commenting.
|
||||
'$do_error'(instantiation_error, absolute_file_name(V, Out)).
|
||||
absolute_file_name(user,user) :- !.
|
||||
@ -288,7 +287,7 @@ absolute_file_name(File0,File) :-
|
||||
(
|
||||
'$absolute_file_name'(File,ExpFile)
|
||||
->
|
||||
'$swi_set_prolog_flag'(file_name_variables, OldF)
|
||||
'$swi_set_prolog_flag'(file_name_variables, OldF)
|
||||
;
|
||||
'$swi_set_prolog_flag'(file_name_variables, OldF),
|
||||
fail
|
||||
@ -499,7 +498,7 @@ remove_from_path(New) :- '$check_path'(New,Path),
|
||||
`library( _File_ )` are searched by the predicates consult/1,
|
||||
reconsult/1, use_module/1, ensure_loaded/1, and load_files/2.
|
||||
|
||||
This directory is initialized s a rule that calls the system predicate
|
||||
This directory is initialized by a rule that calls the system predicate
|
||||
system_library/1.
|
||||
*/
|
||||
|
||||
@ -508,10 +507,10 @@ remove_from_path(New) :- '$check_path'(New,Path),
|
||||
:- dynamic user:library_directory/1.
|
||||
|
||||
%% user:library_directory( ?Dir )
|
||||
% Specifies the set of directories where
|
||||
% one can find Prolog libraries.
|
||||
%
|
||||
% 1. honor YAPSHAREDIR
|
||||
% Specifies the set of directories where
|
||||
% one can find Prolog libraries.
|
||||
%
|
||||
% 1. honor YAPSHAREDIR
|
||||
user:library_directory( Dir ) :-
|
||||
getenv( 'YAPSHAREDIR', Dir0),
|
||||
absolute_file_name( Dir0, [file_type(directory), expand(true)], Dir ).
|
||||
@ -661,3 +660,5 @@ user:file_search_path(path, C) :-
|
||||
),
|
||||
lists:member(C, B)
|
||||
).
|
||||
|
||||
%%@}
|
Reference in New Issue
Block a user