diff --git a/C/c_interface.c b/C/c_interface.c index 0acfbbeb1..84ecd3929 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -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) { diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 8a51c1e37..d4af76497 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -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; diff --git a/CXX/yapi.hh b/CXX/yapi.hh index 8c122da2f..ba6ec0f16 100644 --- a/CXX/yapi.hh +++ b/CXX/yapi.hh @@ -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); } diff --git a/CXX/yapq.hh b/CXX/yapq.hh index 662cf50e5..112fff187 100644 --- a/CXX/yapq.hh +++ b/CXX/yapq.hh @@ -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; diff --git a/CXX/yapt.hh b/CXX/yapt.hh index 21e66bde4..c56562c8c 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -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 diff --git a/H/TermExt.h b/H/TermExt.h index f0975b063..bcbaf0e5b 100755 --- a/H/TermExt.h +++ b/H/TermExt.h @@ -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) { diff --git a/packages/swig/yap.i b/packages/swig/yap.i index 5f0390274..fca51c2b4 100644 --- a/packages/swig/yap.i +++ b/packages/swig/yap.i @@ -40,6 +40,7 @@ class YAPEngine; extern "C"{ #include "Yap.h" +X_API extern Term YAP_MkCharPTerm( char *n); #ifdef SWIGPYTHON