This commit is contained in:
Vítor Santos Costa 2015-03-16 17:25:09 +00:00
parent 55bd75b8d8
commit 272d28ae5f
14 changed files with 351 additions and 251 deletions

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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,11 +335,11 @@ 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( ) ); }

View File

@ -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;
}
;
};
/**

View File

@ -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 */

View File

@ -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

View File

@ -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
/**
* @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
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)
).
/**
@}
*/

View File

@ -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

View File

@ -59,54 +59,67 @@ public class JavaYap extends Activity
EditText text;
String str;
String buf;
YAPQuery q;
Boolean running = false;
int i=1;
YAPListTerm vs0;
void runQuery(String str)
void runQuery(String str, Boolean more)
{
try
{
YAPQuery q = eng.query( str );
// 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;
Boolean rc = true;
// text.setText("");
if (vs0.nil()) {
if (BuildConfig.DEBUG) {
Log.i(TAG, "q0=\n");
}
if (q.next()) {
if (compute && q.next()) {
outputText.append( "yes\n" );
running = compute = more;
} else {
outputText.append( "no\n" );
running = false;
compute = false;
}
} else {
int i=1;
if (BuildConfig.DEBUG) {
//Log.i(TAG, "q1= "+vs0.text()+"\n");
Log.i(TAG, "q1= "+vs0.text()+"\n");
}
while (rc = q.next()) {
while (compute && (rc = q.next()) ) {
YAPListTerm vs = vs0;
while(!vs.nil()){
YAPTerm eq = vs.car();
if (BuildConfig.DEBUG) {
Log.i(TAG, "q= "+vs0+"\n");
Log.i(TAG, "q= "+vs0.text()+"\n");
}
YAPTerm eq = vs.car();
//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();
}
compute = more;
}
}
if ( !rc) {
q.close();
running = compute = false;
}
} catch(Exception e){
outputText.append("Exception thrown :" + e);
return;
@ -174,7 +187,7 @@ outputText.append(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n
});
}
public void onQueryButtonClick(View view)
public void onFirstButtonClick(View view)
{
if (BuildConfig.DEBUG) {
Log.i(TAG, "onQueryButtonClick called");
@ -184,33 +197,32 @@ outputText.append(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n
public void run() {
scroller.fullScroll(ScrollView.FOCUS_DOWN);
str = text.getText().toString();
outputText.append("?- " + str);
Log.i(TAG, "onQueryButtonClick "+str + "\n");
runQuery(str);
//outputText.append("?- " + str+"\n\n");
Log.i(TAG, "onQueryAnyButtonClick "+str + "\n");
runQuery(str, false);
}
});
}
public void onQuerySelectionButtonClick(View view)
public void onAllButtonClick(View view)
{
if (BuildConfig.DEBUG) {
Log.i(TAG, "onQuerySelectionButtonClick called");
Log.i(TAG, "onQueryButtonClick 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);
str = text.getText().toString();
outputText.append("?- " + str+"\n\n");
Log.i(TAG, "onAllButtonClick "+str + "\n");
runQuery(str, true);
}
});
}
/** static constructor */
static {
System.loadLibrary("android");

View File

@ -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>

View File

@ -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) :- !.
@ -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.
*/
@ -661,3 +660,5 @@ user:file_search_path(path, C) :-
),
lists:member(C, B)
).
%%@}