C++ interface and ARM/Android
This commit is contained in:
parent
580bc9eb27
commit
6a0b6fad8b
@ -10,6 +10,18 @@
|
|||||||
#endif /* INDENT_CODE */
|
#endif /* INDENT_CODE */
|
||||||
|
|
||||||
BOp(call_cpred, Osbpp);
|
BOp(call_cpred, Osbpp);
|
||||||
|
#if __ANDROID__
|
||||||
|
char *s; Atom name;
|
||||||
|
if (PREG->y_u.Osbpp.p->ArityOfPE) {
|
||||||
|
Functor f = PREG->y_u.Osbpp.p->FunctorOfPred;
|
||||||
|
name = f->NameOfFE;
|
||||||
|
} else {
|
||||||
|
name = (Atom)(PREG->y_u.Osbpp.p->FunctorOfPred);
|
||||||
|
}
|
||||||
|
s = name->StrOfAE;
|
||||||
|
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAP", " %s ", s);
|
||||||
|
#endif
|
||||||
check_trail(TR);
|
check_trail(TR);
|
||||||
if (!(PREG->y_u.Osbpp.p->PredFlags & (SafePredFlag|NoTracePredFlag|HiddenPredFlag))) {
|
if (!(PREG->y_u.Osbpp.p->PredFlags & (SafePredFlag|NoTracePredFlag|HiddenPredFlag))) {
|
||||||
CACHE_Y_AS_ENV(YREG);
|
CACHE_Y_AS_ENV(YREG);
|
||||||
|
54
C/pl-yap.c
54
C/pl-yap.c
@ -929,33 +929,39 @@ char *
|
|||||||
Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags)
|
Yap_HandleToString(term_t l, size_t sz, size_t *length, int *encoding, int flags)
|
||||||
{
|
{
|
||||||
|
|
||||||
char *r, buf[4096];
|
char *buf;
|
||||||
|
|
||||||
int64_t size;
|
size_t size = 4096, total = size;
|
||||||
IOSTREAM *fd;
|
IOSTREAM *fd;
|
||||||
|
|
||||||
r = buf;
|
total = size;
|
||||||
fd = Sopenmem(&r, &sz, "w");
|
buf = malloc(total);
|
||||||
fd->encoding = ENC_UTF8;
|
while ( (fd = Sopenmem(&buf, &size, "w")) == NULL ||
|
||||||
if ( PL_write_term(fd, l, 1200, flags) &&
|
(( fd->encoding = ENC_UTF8) && FALSE) ||
|
||||||
Sputcode(EOS, fd) >= 0 &&
|
(PL_write_term(fd, l, 1200, flags) == 0) ||
|
||||||
Sflush(fd) >= 0 )
|
Sputcode(EOS, fd) < 0 ||
|
||||||
{
|
Sflush(fd) < 0 ) /* failure */
|
||||||
size = Stell64(fd);
|
{
|
||||||
*length = size-1;
|
#ifdef DEBUG
|
||||||
char *bf = malloc(*length+1);
|
{CACHE_REGS
|
||||||
if (!bf)
|
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text %p, %x buf=%s\n", fd, LOCAL_SlotBase[28], buf);}
|
||||||
return NULL;
|
#endif
|
||||||
strncpy(bf,buf,*length+1);
|
Sclose(fd);
|
||||||
Sclose(fd);
|
if (!fd)
|
||||||
r = bf;
|
return NULL;
|
||||||
return r;
|
total += size;
|
||||||
}
|
buf = realloc(buf, total);
|
||||||
/* failed */
|
if (!buf)
|
||||||
if ( r != buf ) {
|
return NULL;
|
||||||
Sfree(r);
|
Sclose(fd);
|
||||||
}
|
}
|
||||||
return NULL;
|
#ifdef DEBUG
|
||||||
|
{CACHE_REGS
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "text done %s", buf);}
|
||||||
|
#endif
|
||||||
|
Sclose(fd);
|
||||||
|
/* success */
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1189,19 +1189,18 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct write_globs wglb;
|
||||||
|
struct rewind_term rwt;
|
||||||
|
|
||||||
void Yap_plwrite(Term t, void *mywrite, int max_depth, int flags, int priority)
|
void Yap_plwrite(Term t, void *mywrite, int max_depth, int flags, int priority)
|
||||||
/* term to be written */
|
/* term to be written */
|
||||||
/* consumer */
|
/* consumer */
|
||||||
/* write options */
|
/* write options */
|
||||||
{
|
{
|
||||||
struct write_globs wglb;
|
|
||||||
struct rewind_term rwt;
|
|
||||||
|
|
||||||
if (!mywrite)
|
if (!mywrite)
|
||||||
wglb.stream = Serror;
|
wglb.stream = Serror;
|
||||||
else
|
else
|
||||||
wglb.stream = mywrite;
|
wglb.stream = mywrite;
|
||||||
|
|
||||||
wglb.lw = separator;
|
wglb.lw = separator;
|
||||||
wglb.last_atom_minus = FALSE;
|
wglb.last_atom_minus = FALSE;
|
||||||
wglb.Quote_illegal = flags & Quote_illegal_f;
|
wglb.Quote_illegal = flags & Quote_illegal_f;
|
||||||
|
42
CXX/yapi.cpp
42
CXX/yapi.cpp
@ -88,6 +88,7 @@ YAPStringTerm::YAPStringTerm(char *s, size_t len) { // build string
|
|||||||
BACKUP_H();
|
BACKUP_H();
|
||||||
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
seq_tv_t inp, out;
|
seq_tv_t inp, out;
|
||||||
inp.val.c = s;
|
inp.val.c = s;
|
||||||
inp.type = YAP_STRING_CHARS;
|
inp.type = YAP_STRING_CHARS;
|
||||||
@ -104,6 +105,7 @@ YAPStringTerm::YAPStringTerm(wchar_t *s): YAPTerm() { // build string
|
|||||||
BACKUP_H();
|
BACKUP_H();
|
||||||
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
seq_tv_t inp, out;
|
seq_tv_t inp, out;
|
||||||
inp.val.w = s;
|
inp.val.w = s;
|
||||||
inp.type = YAP_STRING_WCHARS;
|
inp.type = YAP_STRING_WCHARS;
|
||||||
@ -119,6 +121,7 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len) : YAPTerm() { // build stri
|
|||||||
BACKUP_H();
|
BACKUP_H();
|
||||||
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
seq_tv_t inp, out;
|
seq_tv_t inp, out;
|
||||||
inp.val.w = s;
|
inp.val.w = s;
|
||||||
inp.type = YAP_STRING_WCHARS;
|
inp.type = YAP_STRING_WCHARS;
|
||||||
@ -133,17 +136,24 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len) : YAPTerm() { // build stri
|
|||||||
|
|
||||||
|
|
||||||
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) : YAPTerm() {
|
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) : YAPTerm() {
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
UInt arity = ArityOfFunctor(f.f);
|
UInt arity = ArityOfFunctor(f.f);
|
||||||
mk ( Yap_MkApplTerm( f.f, arity, (Term *)ts) );
|
mk ( Yap_MkApplTerm( f.f, arity, (Term *)ts) );
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm() {
|
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm() {
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
UInt arity = ArityOfFunctor(f.f);
|
UInt arity = ArityOfFunctor(f.f);
|
||||||
mk ( Yap_MkNewApplTerm( f.f, arity) );
|
mk ( Yap_MkNewApplTerm( f.f, arity) );
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
YAPTerm YAPApplTerm::getArg(int arg) {
|
YAPTerm YAPApplTerm::getArg(int arg) {
|
||||||
return YAPTerm( ArgOfTerm(arg, gt() ) );
|
BACKUP_MACHINE_REGS();
|
||||||
|
YAPTerm to = YAPTerm( ArgOfTerm(arg, gt() ) );
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
YAPFunctor YAPApplTerm::getFunctor() {
|
YAPFunctor YAPApplTerm::getFunctor() {
|
||||||
@ -152,11 +162,15 @@ YAPFunctor YAPApplTerm::getFunctor() {
|
|||||||
|
|
||||||
YAPPairTerm::YAPPairTerm(YAPTerm th, YAPTerm tl) : YAPTerm() {
|
YAPPairTerm::YAPPairTerm(YAPTerm th, YAPTerm tl) : YAPTerm() {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
mk ( MkPairTerm( th.term(), tl.term() ) );
|
mk ( MkPairTerm( th.term(), tl.term() ) );
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
YAPPairTerm::YAPPairTerm() : YAPTerm() {
|
YAPPairTerm::YAPPairTerm() : YAPTerm() {
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
t = Yap_MkNewPairTerm( );
|
t = Yap_MkNewPairTerm( );
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void YAPTerm::mk(Term t0) { CACHE_REGS t = Yap_InitSlot( t0 PASS_REGS); }
|
void YAPTerm::mk(Term t0) { CACHE_REGS t = Yap_InitSlot( t0 PASS_REGS); }
|
||||||
@ -268,16 +282,24 @@ intptr_t YAPTerm::hashTerm(size_t sz, size_t depth, bool variant) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *YAPTerm::text() {
|
const char *YAPTerm::text() {
|
||||||
size_t sze = 4096, length;
|
size_t sze = 4096, length;
|
||||||
char *os;
|
char *os;
|
||||||
int enc;
|
int enc;
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
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))) {
|
if (!(os = Yap_HandleToString(t, sze, &length, &enc, 0))) {
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return (char *)NULL;
|
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();
|
RECOVER_MACHINE_REGS();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
@ -287,21 +309,19 @@ char *YAPQuery::text() {
|
|||||||
char *os;
|
char *os;
|
||||||
int enc;
|
int enc;
|
||||||
|
|
||||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "I LCL0+%p/t=(%d) %x", LCL0, *q_g, LCL0[-15]) ; }
|
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "I t=(%d) %lx", *q_g) ; }
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
if (!(os = Yap_HandleToString(*q_g, sze, &length, &enc, 0))) {
|
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;
|
||||||
}
|
}
|
||||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II LCL0+t=(%p) %x", LCL0, LCL0[-15]) ; }
|
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "II ") ; }
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YAPListTerm::nil() {
|
bool YAPListTerm::nil() {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d LCL0+t=(%p)", t, LCL0+t) ;
|
|
||||||
return gt() == TermNil;
|
return gt() == TermNil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,15 +347,15 @@ YAPTerm::YAPTerm(intptr_t i) { CACHE_REGS Term tn = MkIntegerTerm( i ); mk( tn )
|
|||||||
|
|
||||||
YAPTerm YAPListTerm::car()
|
YAPTerm YAPListTerm::car()
|
||||||
{
|
{
|
||||||
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d LCL0+t=(%p)", t, LCL0+t) ; }
|
|
||||||
Term to = gt();
|
Term to = gt();
|
||||||
|
{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "to=%d", to) ; }
|
||||||
if (IsPairTerm(to))
|
if (IsPairTerm(to))
|
||||||
return YAPTerm(HeadOfTerm(to));
|
return YAPTerm(HeadOfTerm(to));
|
||||||
else
|
else
|
||||||
return MkIntTerm(-1);
|
return MkIntTerm(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); }
|
YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); }
|
||||||
|
|
||||||
|
|
||||||
char *YAPAtom::getName(void) {
|
char *YAPAtom::getName(void) {
|
||||||
@ -602,8 +622,8 @@ YAPPredicate::YAPPredicate(YAPAtom at, arity_t arity) {
|
|||||||
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) ; }
|
{ 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;
|
||||||
outp = (Term *)NULL;
|
outp = (Term *)NULL;
|
||||||
|
118
CXX/yapt.hh
118
CXX/yapt.hh
@ -1,6 +1,8 @@
|
|||||||
#ifndef YAPT_HH
|
#ifndef YAPT_HH
|
||||||
#define YAPT_HH 1
|
#define YAPT_HH 1
|
||||||
|
|
||||||
|
class YAPAtomTerm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic Prolog Term
|
* @brief Generic Prolog Term
|
||||||
*/
|
*/
|
||||||
@ -9,7 +11,8 @@ class YAPTerm {
|
|||||||
friend class YAPPrologPredicate;
|
friend class YAPPrologPredicate;
|
||||||
friend class YAPQuery;
|
friend class YAPQuery;
|
||||||
friend class YAPModule;
|
friend class YAPModule;
|
||||||
friend class YAPModuleProp;
|
friend class YAPModuleProp;
|
||||||
|
friend class YAPApplTerm;
|
||||||
protected:
|
protected:
|
||||||
yhandle_t t; /// handle to term, equivalent to term_t
|
yhandle_t t; /// handle to term, equivalent to term_t
|
||||||
void mk(Term t0); /// internal method to convert from term to handle
|
void mk(Term t0); /// internal method to convert from term to handle
|
||||||
@ -37,33 +40,39 @@ public:
|
|||||||
bool unifiable(YAPTerm t1); /// we can unify t and t1
|
bool unifiable(YAPTerm t1); /// we can unify t and t1
|
||||||
bool variant(YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming
|
bool variant(YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming
|
||||||
intptr_t hashTerm(size_t sz, size_t depth, bool variant); /// term hash,
|
intptr_t hashTerm(size_t sz, size_t depth, bool variant); /// term hash,
|
||||||
bool isVar() { return IsVarTerm( gt() ); } /// type check for unbound
|
virtual bool isVar() { return IsVarTerm( gt() ); } /// type check for unbound
|
||||||
bool isAtom() { return IsAtomTerm( gt() ); } /// type check for atom
|
virtual bool isAtom() { return IsAtomTerm( gt() ); } /// type check for atom
|
||||||
bool isInteger() { return IsIntegerTerm( gt() ); } /// type check for integer
|
virtual bool isInteger() { return IsIntegerTerm( gt() ); } /// type check for integer
|
||||||
bool isFloat() { return IsFloatTerm( gt() ); } /// type check for floating-point
|
virtual bool isFloat() { return IsFloatTerm( gt() ); } /// type check for floating-point
|
||||||
bool isString() { return IsStringTerm( gt() ); } /// type check for a string " ... "
|
virtual bool isString() { return IsStringTerm( gt() ); } /// type check for a string " ... "
|
||||||
bool isCompound() { return !(IsVarTerm( gt() ) || IsNumTerm( gt() )); } /// is a primitive term
|
virtual bool isCompound() { return !(IsVarTerm( gt() ) || IsNumTerm( gt() )); } /// is a primitive term
|
||||||
bool isAppl() { return IsApplTerm( gt() ); } /// is a structured term
|
virtual bool isAppl() { return IsApplTerm( gt() ); } /// is a structured term
|
||||||
bool isPair() { return IsPairTerm( gt() ); } /// is a pair term
|
virtual bool isPair() { return IsPairTerm( gt() ); } /// is a pair term
|
||||||
bool isGround() { return Yap_IsGroundTerm( gt() ); } /// term is ground
|
virtual bool isGround() { return Yap_IsGroundTerm( gt() ); } /// term is ground
|
||||||
bool isList() { return Yap_IsListTerm( gt() ); } /// term is a list
|
virtual bool isList() { return Yap_IsListTerm( gt() ); } /// term is a list
|
||||||
|
|
||||||
/// extract the argument i of the term, where i in 1...arity
|
/// extract the argument i of the term, where i in 1...arity
|
||||||
inline YAPTerm getArg(int i) {
|
inline YAPTerm getArg(int i) {
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
Term t0 = gt();
|
Term t0 = gt();
|
||||||
|
YAPTerm tf;
|
||||||
if (IsApplTerm(t0))
|
if (IsApplTerm(t0))
|
||||||
return YAPTerm(ArgOfTerm(i, t0));
|
tf = YAPTerm(ArgOfTerm(i, t0));
|
||||||
else if (IsPairTerm(t0)) {
|
else if (IsPairTerm(t0)) {
|
||||||
if (i==1)
|
if (i==1)
|
||||||
return YAPTerm(HeadOfTerm(t0));
|
tf = YAPTerm(HeadOfTerm(t0));
|
||||||
if (i==2)
|
else if (i==2)
|
||||||
return YAPTerm(TailOfTerm(t0));
|
tf = YAPTerm(TailOfTerm(t0));
|
||||||
|
} else {
|
||||||
|
tf = YAPTerm((Term)0);
|
||||||
}
|
}
|
||||||
return YAPTerm((Term)0);
|
RECOVER_MACHINE_REGS();
|
||||||
|
//{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "after getArg H= %p, i=%d", HR, tf.gt()) ; }
|
||||||
|
return tf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return a string with a textual representation of the term
|
/// return a string with a textual representation of the term
|
||||||
char *text();
|
virtual const char *text();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,6 +87,44 @@ public:
|
|||||||
CELL *getVar() { return VarOfTerm( gt() ); }
|
CELL *getVar() { return VarOfTerm( gt() ); }
|
||||||
/// is the variable bound to another one
|
/// is the variable bound to another one
|
||||||
bool unbound() { return IsUnboundVar(VarOfTerm( gt() )); }
|
bool unbound() { return IsUnboundVar(VarOfTerm( gt() )); }
|
||||||
|
virtual bool isVar() { return true; } /// 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 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 false; } /// term is ground
|
||||||
|
virtual bool isList() { return false; } /// term is a list
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Atom Term
|
||||||
|
* Term Representation of an Atom
|
||||||
|
*/
|
||||||
|
class YAPAtomTerm: YAPTerm {
|
||||||
|
friend class YAPModule;
|
||||||
|
// Constructor: receives a C-atom;
|
||||||
|
YAPAtomTerm(Atom a) { mk( MkAtomTerm(a) ); }
|
||||||
|
YAPAtomTerm(Term t): YAPTerm(t) { IsAtomTerm(t); }
|
||||||
|
// Getter for Prolog atom
|
||||||
|
Term getTerm() { return t; }
|
||||||
|
public:
|
||||||
|
// 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);
|
||||||
|
// 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; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,6 +170,10 @@ public:
|
|||||||
/// Create a list term out of a standard term. Check if a valid operation.
|
/// Create a list term out of a standard term. Check if a valid operation.
|
||||||
///
|
///
|
||||||
/// @param[in] the term
|
/// @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 */ }
|
YAPListTerm(Term t0) { mk(t0); /* else type_error */ }
|
||||||
/* /// Create a list term out of an array of terms.
|
/* /// Create a list term out of an array of terms.
|
||||||
///
|
///
|
||||||
@ -145,8 +196,9 @@ public:
|
|||||||
Term to = gt();
|
Term to = gt();
|
||||||
if (IsPairTerm( to ))
|
if (IsPairTerm( to ))
|
||||||
return YAPListTerm(TailOfTerm( to ));
|
return YAPListTerm(TailOfTerm( to ));
|
||||||
else
|
else if ( to == TermNil)
|
||||||
return MkIntTerm(-1);
|
return YAPListTerm( );
|
||||||
|
/* error */;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the list is empty.
|
/// Check if the list is empty.
|
||||||
@ -171,32 +223,4 @@ public:
|
|||||||
const char *getString() { return StringOfTerm( gt() ); }
|
const char *getString() { return StringOfTerm( gt() ); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Atom Term
|
|
||||||
* Term Representation of an Atom
|
|
||||||
*/
|
|
||||||
class YAPAtomTerm: YAPTerm {
|
|
||||||
friend class YAPModule;
|
|
||||||
// Constructor: receives a C-atom;
|
|
||||||
YAPAtomTerm(Atom a) { mk( MkAtomTerm(a) ); }
|
|
||||||
YAPAtomTerm(Term t): YAPTerm(t) { IsAtomTerm(t); }
|
|
||||||
// Getter for Prolog atom
|
|
||||||
Term getTerm() { return t; }
|
|
||||||
public:
|
|
||||||
// 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);
|
|
||||||
// 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; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* YAPT_HH */
|
#endif /* YAPT_HH */
|
||||||
|
@ -262,8 +262,20 @@ writeTopTerm(term_t t, int prec, write_options *options)
|
|||||||
if (flags & PL_WRT_BLOB_PORTRAY)
|
if (flags & PL_WRT_BLOB_PORTRAY)
|
||||||
yap_flag |= Blob_Portray_f;
|
yap_flag |= Blob_Portray_f;
|
||||||
old_module = CurrentModule;
|
old_module = CurrentModule;
|
||||||
|
char * buf[1024];
|
||||||
|
size_t length;
|
||||||
|
int encode; Term tn;
|
||||||
|
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "Yap_REGS=%p\n", Yap_REGS);
|
||||||
CurrentModule = Yap_GetModuleFromEntry(options->module);
|
CurrentModule = Yap_GetModuleFromEntry(options->module);
|
||||||
Yap_plwrite(Yap_GetFromSlot(t PASS_REGS), options->out, options->max_depth, yap_flag, prec);
|
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "t=%d\n", t) ;
|
||||||
|
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "LOCAl_SlotBase[t]=%ld\n", LOCAL_SlotBase[t]);
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "LOCAl_SlotBase=%ld\n", Deref(LOCAL_SlotBase[t]));
|
||||||
|
|
||||||
|
|
||||||
|
Yap_plwrite(Yap_GetFromSlot(t PASS_REGS), options->out, options->max_depth, yap_flag, prec);
|
||||||
CurrentModule = old_module;
|
CurrentModule = old_module;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -554,7 +566,7 @@ pl_write_term(term_t term, term_t options)
|
|||||||
/** @pred write_term(+ _T_, + _Opts_) is iso
|
/** @pred write_term(+ _T_, + _Opts_) is iso
|
||||||
|
|
||||||
|
|
||||||
Displays term _T_ on the current output stream, according to the
|
Displays term _T_ on the current output stream, according to the
|
||||||
following options:
|
following options:
|
||||||
|
|
||||||
+ quoted(+ _Bool_) is iso
|
+ quoted(+ _Bool_) is iso
|
||||||
@ -609,7 +621,6 @@ PL_write_term(IOSTREAM *s, term_t term, int precedence, int flags)
|
|||||||
options.flags = flags;
|
options.flags = flags;
|
||||||
options.out = s;
|
options.out = s;
|
||||||
options.module = MODULE_user;
|
options.module = MODULE_user;
|
||||||
|
|
||||||
PutOpenToken(EOF, s); /* reset this */
|
PutOpenToken(EOF, s); /* reset this */
|
||||||
return writeTopTerm(term, precedence, &options);
|
return writeTopTerm(term, precedence, &options);
|
||||||
}
|
}
|
||||||
|
@ -116,8 +116,7 @@ android/jni/yap_wrap.cpp: $(YAP_SWIG_INTERFACE) android/AndroidManifest.xml
|
|||||||
$(SWIG) -c++ -java -I$(srcdir)/../../CXX -package pt.up.fc.dcc.yap -outdir android/src/pt/up/fc/dcc/yap -o $@ $<
|
$(SWIG) -c++ -java -I$(srcdir)/../../CXX -package pt.up.fc.dcc.yap -outdir android/src/pt/up/fc/dcc/yap -o $@ $<
|
||||||
|
|
||||||
install-android: android
|
install-android: android
|
||||||
adb uninstall pt.up.fc.dcc.yap
|
adb install -r android/bin/JavaYap-debug.apk
|
||||||
adb install android/bin/JavaYap-debug.apk
|
|
||||||
|
|
||||||
R:
|
R:
|
||||||
|
|
||||||
|
@ -53,180 +53,184 @@ class DoNotDeleteErrorHandler implements DatabaseErrorHandler {
|
|||||||
}
|
}
|
||||||
public class JavaYap extends Activity
|
public class JavaYap extends Activity
|
||||||
{
|
{
|
||||||
TextView outputText = null;
|
TextView outputText = null;
|
||||||
ScrollView scroller = null;
|
ScrollView scroller = null;
|
||||||
YAPEngine eng = null;
|
YAPEngine eng = null;
|
||||||
EditText text;
|
EditText text;
|
||||||
String str;
|
String str;
|
||||||
String buf;
|
String buf;
|
||||||
|
|
||||||
void runQuery(String str)
|
void runQuery(String str)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
YAPQuery q = eng.query( str );
|
YAPQuery q = eng.query( str );
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "onQueryButtonClick called");
|
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) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "q0=\n");
|
Log.i(TAG, "q0=\n");
|
||||||
}
|
}
|
||||||
if (q.next()) {
|
if (q.next()) {
|
||||||
outputText.append( "yes\n" );
|
outputText.append( "yes\n" );
|
||||||
} else {
|
} else {
|
||||||
outputText.append( "no\n" );
|
outputText.append( "no\n" );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int i=1;
|
int i=1;
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
//Log.i(TAG, "q1= "+vs0.text()+"\n");
|
//Log.i(TAG, "q1= "+vs0.text()+"\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
while (rc = q.next()) {
|
while (rc = q.next()) {
|
||||||
if (BuildConfig.DEBUG) {
|
YAPListTerm vs = vs0;
|
||||||
//Log.i(TAG, "q= "+vs0.text()+"\n");
|
while(!vs.nil()){
|
||||||
|
YAPTerm eq = vs.car();
|
||||||
}
|
if (BuildConfig.DEBUG) {
|
||||||
YAPListTerm vs = vs0;
|
Log.i(TAG, "q= "+vs0+"\n");
|
||||||
while(!vs.nil()){
|
}
|
||||||
YAPTerm eq = vs.car();
|
//outputText.append(Integer.toString(i) + ": " + eq.text() );
|
||||||
//outputText.append(Integer.toString(i) + ": " + eq.text() );
|
outputText.append(Integer.toString(i++));
|
||||||
outputText.append(Integer.toString(i++) + ":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" );
|
Log.i(TAG, "q= "+ eq.getArg(1)+"\n");
|
||||||
vs = vs.cdr();
|
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" );
|
||||||
q.close();
|
vs = vs.cdr();
|
||||||
} catch(Exception e){
|
}
|
||||||
outputText.append("Exception thrown :" + e);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
q.close();
|
||||||
|
} catch(Exception e){
|
||||||
|
outputText.append("Exception thrown :" + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
String s = null;
|
String s = null;
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PackageManager m = getPackageManager();
|
PackageManager m = getPackageManager();
|
||||||
s = getPackageName();
|
s = getPackageName();
|
||||||
PackageInfo p = m.getPackageInfo(s, 0);
|
PackageInfo p = m.getPackageInfo(s, 0);
|
||||||
//s = p.applicationInfo.dataDir;
|
//s = p.applicationInfo.dataDir;
|
||||||
AssetManager mgr = getResources().getAssets();
|
AssetManager mgr = getResources().getAssets();
|
||||||
Log.i(TAG, "mgr=" +mgr + " " + s);
|
Log.i(TAG, "mgr=" +mgr + " " + s);
|
||||||
load(mgr);
|
load(mgr);
|
||||||
} catch(NameNotFoundException e) {
|
} catch(NameNotFoundException e) {
|
||||||
Log.e(TAG, "Couldn't find package information in PackageManager", e);
|
Log.e(TAG, "Couldn't find package information in PackageManager", e);
|
||||||
}
|
}
|
||||||
Log.i(TAG, "mgr=" +mgr);
|
Log.i(TAG, "mgr=" +mgr);
|
||||||
|
|
||||||
text = (EditText)findViewById(R.id.EditText01);
|
text = (EditText)findViewById(R.id.EditText01);
|
||||||
outputText = (TextView)findViewById(R.id.OutputText);
|
outputText = (TextView)findViewById(R.id.OutputText);
|
||||||
outputText.setText("Application " + s + "\nPress 'Query' to start...\n");
|
outputText.setText("Application " + s + "\nPress 'Query' to start...\n");
|
||||||
outputText.setMovementMethod(new ScrollingMovementMethod());
|
outputText.setMovementMethod(new ScrollingMovementMethod());
|
||||||
scroller = (ScrollView)findViewById(R.id.Scroller);
|
scroller = (ScrollView)findViewById(R.id.Scroller);
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "window making done");
|
Log.i(TAG, "window making done");
|
||||||
}
|
}
|
||||||
eng = new YAPEngine( );
|
eng = new YAPEngine( );
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "engine done");
|
Log.i(TAG, "engine done");
|
||||||
}
|
}
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "onClearButtonClick called");
|
Log.i(TAG, "onClearButtonClick called");
|
||||||
}
|
}
|
||||||
JavaCallback callback = new JavaCallback( outputText );
|
JavaCallback callback = new JavaCallback( outputText );
|
||||||
// set the Java Callback
|
// set the Java Callback
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "before setting callback");
|
Log.i(TAG, "before setting callback");
|
||||||
}
|
}
|
||||||
eng.setYAPCallback(callback);
|
eng.setYAPCallback(callback);
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "callback done");
|
Log.i(TAG, "callback done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClearButtonClick(View view)
|
public void onClearButtonClick(View view)
|
||||||
{
|
{
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "onClearButtonClick called");
|
Log.i(TAG, "onClearButtonClick called");
|
||||||
}
|
}
|
||||||
// Ensure scroll to end of text
|
// Ensure scroll to end of text
|
||||||
scroller.post(new Runnable() {
|
scroller.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||||
text.setText("");
|
text.setText("");
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void onQueryButtonClick(View view)
|
public void onQueryButtonClick(View view)
|
||||||
{
|
{
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "onQueryButtonClick called");
|
Log.i(TAG, "onQueryButtonClick called");
|
||||||
}
|
}
|
||||||
// Ensure scroll to end of text
|
// Ensure scroll to end of text
|
||||||
scroller.post(new Runnable() {
|
scroller.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||||
str = text.getText().toString();
|
str = text.getText().toString();
|
||||||
outputText.append("?- " + str);
|
outputText.append("?- " + str);
|
||||||
Log.i(TAG, "onQueryButtonClick "+str + "\n");
|
Log.i(TAG, "onQueryButtonClick "+str + "\n");
|
||||||
runQuery(str);
|
runQuery(str);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void onQuerySelectionButtonClick(View view)
|
public void onQuerySelectionButtonClick(View view)
|
||||||
{
|
{
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "onQuerySelectionButtonClick called");
|
Log.i(TAG, "onQuerySelectionButtonClick called");
|
||||||
}
|
}
|
||||||
// Ensure scroll to end of text
|
// Ensure scroll to end of text
|
||||||
scroller.post(new Runnable() {
|
scroller.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||||
int startSelection = text.getSelectionStart();
|
int startSelection = text.getSelectionStart();
|
||||||
int endSelection = text.getSelectionEnd();
|
int endSelection = text.getSelectionEnd();
|
||||||
str = text.getText().toString().substring( startSelection, endSelection );
|
str = text.getText().toString().substring( startSelection, endSelection );
|
||||||
Log.i(TAG, "onQuerySelectionButtonClick "+str);
|
Log.i(TAG, "onQuerySelectionButtonClick "+str);
|
||||||
outputText.append("?- " + str + "\n");
|
outputText.append("?- " + str + "\n");
|
||||||
runQuery(str);
|
runQuery(str);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** static constructor */
|
/** static constructor */
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("android");
|
System.loadLibrary("android");
|
||||||
System.loadLibrary("log");
|
System.loadLibrary("log");
|
||||||
System.loadLibrary("gmp");
|
System.loadLibrary("gmp");
|
||||||
System.loadLibrary("sqliteX");
|
System.loadLibrary("sqliteX");
|
||||||
System.loadLibrary("example");
|
System.loadLibrary("example");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native void load(AssetManager mgr);
|
private static native void load(AssetManager mgr);
|
||||||
|
|
||||||
private AssetManager mgr;
|
private AssetManager mgr;
|
||||||
|
|
||||||
private static final String TAG = "JavaYap";
|
private static final String TAG = "JavaYap";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class JavaCallback extends YAPCallback
|
class JavaCallback extends YAPCallback
|
||||||
{
|
{
|
||||||
TextView output;
|
TextView output;
|
||||||
|
|
||||||
public JavaCallback( TextView outputText )
|
public JavaCallback( TextView outputText )
|
||||||
{
|
{
|
||||||
@ -238,15 +242,15 @@ class JavaCallback extends YAPCallback
|
|||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Log.i(TAG, "java callback ");
|
Log.i(TAG, "java callback ");
|
||||||
System.out.println("JavaCallback.run() ");
|
System.out.println("JavaCallback.run() ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(String s)
|
public void run(String s)
|
||||||
{
|
{
|
||||||
Log.i(TAG, "java callback ");
|
Log.i(TAG, "java callback ");
|
||||||
output.append(s);
|
output.append(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TAG = "JavaCallback";
|
private static final String TAG = "JavaCallback";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user