This commit is contained in:
Vitor Santos Costa 2018-07-03 00:54:34 +01:00
parent fd492b5b16
commit 176dc4bfb5
7 changed files with 69 additions and 21 deletions

View File

@ -288,13 +288,23 @@ X_API Term YAP_MkIntTerm(Int n) {
}
X_API Term YAP_MkStringTerm(const char *n) {
CACHE_REGS
Term I;
BACKUP_H();
CACHE_REGS
Term I;
BACKUP_H();
I = MkStringTerm(n);
RECOVER_H();
return I;
I = MkStringTerm(n);
RECOVER_H();
return I;
}
X_API Term YAP_MkCharPTerm( char *n) {
CACHE_REGS
Term I;
BACKUP_H();
I = MkStringTerm(n);
RECOVER_H();
return I;
}
X_API Term YAP_MkUnsignedStringTerm(const unsigned char *n) {

View File

@ -189,14 +189,8 @@ YAPStringTerm::YAPStringTerm(char *s) { // build string
BACKUP_H();
CACHE_REGS
seq_tv_t inp, out;
inp.val.c = s;
inp.type = YAP_STRING_CHARS;
out.type = YAP_STRING_STRING;
if (Yap_CVT_Text(&inp, &out PASS_REGS))
mk(out.val.t);
else
t = 0L;
Term ts = MkStringTerm(s);
mk(ts);
RECOVER_H();
}
@ -708,6 +702,7 @@ bool YAPQuery::next() {
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
if (q_state == 0) {
//Yap_do_low_level_trace = 1;
result = (bool)YAP_EnterGoal(ap, nullptr, &q_h);
} else {
LOCAL_AllowRestart = q_open;

View File

@ -106,6 +106,7 @@ X_API extern void YAP_UserBackCutCPredicate(const char *name,
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
extern YAP_Term YAP_MkcharPTerm(char *s);
}

View File

@ -178,6 +178,7 @@ public:
// const std::string *s = new std::string("startup.yss");
Embedded = true;
install = false;
Yap_InitDefaults(this, nullptr, 0, nullptr);
#if YAP_PYTHON
Embedded = true;

View File

@ -27,6 +27,13 @@
class YAPError;
extern "C" {
X_API extern Term YAP_MkCharPTerm( char *n);
}
/**
* @brief Generic Prolog Term
*/
@ -39,7 +46,7 @@ class X_API YAPTerm {
friend class YAPApplTerm;
friend class YAPListTerm;
protected:
protected:
yhandle_t t; /// handle to term, equivalent to term_t
public:
@ -315,12 +322,18 @@ public:
RECOVER_MACHINE_REGS();
return tf;
};
void putArg(int i, YAPTerm t) {
BACKUP_MACHINE_REGS();
Term t0 = gt();
RepAppl(t0)[i] = t.term();
RECOVER_MACHINE_REGS();
};
void putArg(int i, Term targ) {
//BACKUP_MACHINE_REGS();
Term t0 = gt();
RepAppl(t0)[i] = Deref(targ);
//RECOVER_MACHINE_REGS();
};
void putArg(int i, YAPTerm t) {
//BACKUP_MACHINE_REGS();
Term t0 = gt();
RepAppl(t0)[i] = t.term();
//RECOVER_MACHINE_REGS();
};
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

View File

@ -288,6 +288,8 @@ INLINE_ONLY bool IsLongIntTerm(Term t) {
/* extern Functor FunctorString; */
#define MkStringTerm(i) __MkStringTerm((i)PASS_REGS)
INLINE_ONLY Term __MkStringTerm(const char *s USES_REGS);
@ -336,6 +338,31 @@ __MkUStringTerm(const unsigned char *s USES_REGS) {
return t;
}
#define MkCharPTerm(i) __MkCharPTerm((i)PASS_REGS)
INLINE_ONLY Term __MkCharPTerm(char *s USES_REGS);
INLINE_ONLY Term __MkCharPTerm(char *s USES_REGS) {
Term t = AbsAppl(HR);
size_t sz;
if ((s[0] == '\0')) {
sz = sizeof(CELL);
HR[0] = (CELL)FunctorString;
HR[1] = (CELL)sz;
HR[2] = 0;
} else {
sz = ALIGN_BY_TYPE(strlen((char *)s) + 1, CELL);
HR[0] = (CELL)FunctorString;
HR[1] = (CELL)sz;
strcpy((char *)(HR + 2), (const char *)s);
}
HR[2 + sz] = EndSpecials;
HR += 3 + sz;
return t;
}
INLINE_ONLY const unsigned char *UStringOfTerm(Term t);
INLINE_ONLY const unsigned char *UStringOfTerm(Term t) {

View File

@ -40,6 +40,7 @@ class YAPEngine;
extern "C"{
#include "Yap.h"
X_API extern Term YAP_MkCharPTerm( char *n);
#ifdef SWIGPYTHON