jup
This commit is contained in:
parent
562e9e5af3
commit
0c950ce5b3
101
CXX/yapt.hh
101
CXX/yapt.hh
@ -29,9 +29,7 @@ class YAPError;
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
X_API extern Term YAP_MkCharPTerm( char *n);
|
X_API extern Term YAP_MkCharPTerm(char *n);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +44,7 @@ class X_API YAPTerm {
|
|||||||
friend class YAPApplTerm;
|
friend class YAPApplTerm;
|
||||||
friend class YAPListTerm;
|
friend class YAPListTerm;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
yhandle_t t; /// handle to term, equivalent to term_t
|
yhandle_t t; /// handle to term, equivalent to term_t
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -93,7 +91,7 @@ public:
|
|||||||
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
|
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
|
||||||
/* if (!t)
|
/* if (!t)
|
||||||
return;
|
return;
|
||||||
Yap_DebugPlWriteln(LOCAL_HandleBase[t]);
|
// Yap_DebugPlWriteln(LOCAL_HandleBase[t]);
|
||||||
LOCAL_HandleBase[t] = TermFreeTerm;
|
LOCAL_HandleBase[t] = TermFreeTerm;
|
||||||
while (LOCAL_HandleBase[LOCAL_CurSlot - 1] == TermFreeTerm) {
|
while (LOCAL_HandleBase[LOCAL_CurSlot - 1] == TermFreeTerm) {
|
||||||
LOCAL_CurSlot--;
|
LOCAL_CurSlot--;
|
||||||
@ -119,18 +117,18 @@ public:
|
|||||||
inline Term term() {
|
inline Term term() {
|
||||||
return Deref(gt());
|
return Deref(gt());
|
||||||
} /// from YAPTerm to Term (internal YAP representation)
|
} /// from YAPTerm to Term (internal YAP representation)
|
||||||
YAPTerm arg(int i) {
|
YAPTerm arg(int i) {
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term t0 = gt();
|
Term t0 = gt();
|
||||||
YAPTerm tf;
|
YAPTerm tf;
|
||||||
if (!IsApplTerm(t0) && !IsPairTerm(t))
|
if (!IsApplTerm(t0) && !IsPairTerm(t))
|
||||||
return (Term)0;
|
return (Term)0;
|
||||||
tf = YAPTerm(ArgOfTerm(i, t0) );
|
tf = YAPTerm(ArgOfTerm(i, t0));
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return tf;
|
return tf;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
|
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
|
||||||
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
||||||
/// from YAPTerm to Term (internal YAP representation)
|
/// from YAPTerm to Term (internal YAP representation)
|
||||||
/// fetch a sub-term
|
/// fetch a sub-term
|
||||||
@ -201,9 +199,10 @@ public:
|
|||||||
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
|
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
|
||||||
virtual 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...arityvoid *Yap_RepStreamFromId(int sno)
|
/// extract the argument i of the term, where i in 1...arityvoid
|
||||||
|
/// *Yap_RepStreamFromId(int sno)
|
||||||
virtual Term getArg(arity_t i);
|
virtual Term getArg(arity_t i);
|
||||||
|
|
||||||
/// extract the arity of the term
|
/// extract the arity of the term
|
||||||
/// variables have arity 0
|
/// variables have arity 0
|
||||||
virtual inline arity_t arity() {
|
virtual inline arity_t arity() {
|
||||||
@ -226,7 +225,7 @@ public:
|
|||||||
char *os;
|
char *os;
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
if (!(os = Yap_TermToBuffer(Yap_GetFromSlot(t), Handle_vars_f))) {
|
if (!(os = Yap_TermToBuffer(Yap_GetFromSlot(t), Handle_vars_f))) {
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -292,7 +291,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Compound Term
|
* @brief Compound Term
|
||||||
*/
|
*/
|
||||||
class X_API YAPApplTerm : public YAPTerm {
|
class X_API YAPApplTerm : public YAPTerm {
|
||||||
friend class YAPTerm;
|
friend class YAPTerm;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -304,33 +303,36 @@ public:
|
|||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
};
|
};
|
||||||
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
||||||
YAPApplTerm(const std::string s, unsigned int arity) { mk(Yap_MkNewApplTerm(Yap_MkFunctor(Yap_LookupAtom(s.c_str()), arity), arity)); };
|
YAPApplTerm(const std::string s, unsigned int arity) {
|
||||||
YAPApplTerm(const std::string s, std::vector<YAPTerm> ts);
|
mk(Yap_MkNewApplTerm(Yap_MkFunctor(Yap_LookupAtom(s.c_str()), arity),
|
||||||
|
arity));
|
||||||
|
};
|
||||||
|
YAPApplTerm(const std::string s, std::vector<YAPTerm> ts);
|
||||||
YAPApplTerm(YAPFunctor f);
|
YAPApplTerm(YAPFunctor f);
|
||||||
inline Functor functor() { return FunctorOfTerm(gt()); }
|
inline Functor functor() { return FunctorOfTerm(gt()); }
|
||||||
inline YAPFunctor getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); }
|
inline YAPFunctor getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); }
|
||||||
|
|
||||||
Term getArg(arity_t i) {
|
Term getArg(arity_t i) {
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term t0 = gt();
|
Term t0 = gt();
|
||||||
Term tf;
|
Term tf;
|
||||||
tf = ArgOfTerm(i, t0);
|
tf = ArgOfTerm(i, t0);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return tf;
|
return tf;
|
||||||
};
|
};
|
||||||
void putArg(int i, Term targ) {
|
void putArg(int i, Term targ) {
|
||||||
//BACKUP_MACHINE_REGS();
|
// BACKUP_MACHINE_REGS();
|
||||||
Term t0 = gt();
|
Term t0 = gt();
|
||||||
RepAppl(t0)[i] = Deref(targ);
|
RepAppl(t0)[i] = Deref(targ);
|
||||||
//RECOVER_MACHINE_REGS();
|
// RECOVER_MACHINE_REGS();
|
||||||
};
|
};
|
||||||
void putArg(int i, YAPTerm t) {
|
void putArg(int i, YAPTerm t) {
|
||||||
//BACKUP_MACHINE_REGS();
|
// BACKUP_MACHINE_REGS();
|
||||||
Term t0 = gt();
|
Term t0 = gt();
|
||||||
RepAppl(t0)[i] = t.term();
|
RepAppl(t0)[i] = t.term();
|
||||||
//RECOVER_MACHINE_REGS();
|
// RECOVER_MACHINE_REGS();
|
||||||
};
|
};
|
||||||
virtual bool isVar() { return false; } /// type check for unbound
|
virtual bool isVar() { return false; } /// type check for unbound
|
||||||
virtual bool isAtom() { return false; } /// type check for atom
|
virtual bool isAtom() { return false; } /// type check for atom
|
||||||
virtual bool isInteger() { return false; } /// type check for integer
|
virtual bool isInteger() { return false; } /// type check for integer
|
||||||
virtual bool isFloat() { return false; } /// type check for floating-point
|
virtual bool isFloat() { return false; } /// type check for floating-point
|
||||||
@ -465,7 +467,7 @@ public:
|
|||||||
* Term Representation of an Atom
|
* Term Representation of an Atom
|
||||||
*/
|
*/
|
||||||
class X_API YAPAtomTerm : public YAPTerm {
|
class X_API YAPAtomTerm : public YAPTerm {
|
||||||
friend class YAPModule;
|
friend class YAPModule;
|
||||||
// Constructor: receives a C-atom;
|
// Constructor: receives a C-atom;
|
||||||
YAPAtomTerm(Term t) : YAPTerm(t) { IsAtomTerm(t); }
|
YAPAtomTerm(Term t) : YAPTerm(t) { IsAtomTerm(t); }
|
||||||
|
|
||||||
@ -479,11 +481,12 @@ public:
|
|||||||
YAPAtomTerm(char *s, size_t len);
|
YAPAtomTerm(char *s, size_t len);
|
||||||
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
||||||
YAPAtomTerm(wchar_t *s);
|
YAPAtomTerm(wchar_t *s);
|
||||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||||
YAPAtomTerm(wchar_t *s, size_t len);
|
YAPAtomTerm(wchar_t *s, size_t len);
|
||||||
// Constructor: receives a std::string;
|
// Constructor: receives a std::string;
|
||||||
// YAPAtomTerm(std::string s) { mk(MkAtomTerm(Yap_LookupAtom(s.c_str()))); };
|
// YAPAtomTerm(std::string s) { mk(MkAtomTerm(Yap_LookupAtom(s.c_str())));
|
||||||
bool isVar() { return false; } /// type check for unbound
|
// };
|
||||||
|
bool isVar() { return false; } /// type check for unbound
|
||||||
bool isAtom() { return true; } /// type check for atom
|
bool isAtom() { return true; } /// type check for atom
|
||||||
bool isInteger() { return false; } /// type check for integer
|
bool isInteger() { return false; } /// type check for integer
|
||||||
bool isFloat() { return false; } /// type check for floating-point
|
bool isFloat() { return false; } /// type check for floating-point
|
||||||
|
821
os/readterm.c
821
os/readterm.c
File diff suppressed because it is too large
Load Diff
@ -92,8 +92,9 @@ static Term readFromBuffer(const char *s, Term opts) {
|
|||||||
Term rval;
|
Term rval;
|
||||||
int sno;
|
int sno;
|
||||||
encoding_t enc = ENC_ISO_UTF8;
|
encoding_t enc = ENC_ISO_UTF8;
|
||||||
sno = Yap_open_buf_read_stream((char *)s, strlen_utf8((unsigned char *)s),
|
sno = Yap_open_buf_read_stream(
|
||||||
&enc, MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix((char *)s,16)), TermNone);
|
(char *)s, strlen_utf8((unsigned char *)s), &enc, MEM_BUF_USER,
|
||||||
|
Yap_LookupAtom(Yap_StrPrefix((char *)s, 16)), TermNone);
|
||||||
|
|
||||||
rval = Yap_read_term(sno, opts, 3);
|
rval = Yap_read_term(sno, opts, 3);
|
||||||
Yap_CloseStream(sno);
|
Yap_CloseStream(sno);
|
||||||
@ -593,7 +594,6 @@ static Int writeln(USES_REGS1) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "writeln/2");
|
int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "writeln/2");
|
||||||
fprintf(stderr, "writeln %d\n", output_stream);
|
|
||||||
if (output_stream < 0) {
|
if (output_stream < 0) {
|
||||||
free(args);
|
free(args);
|
||||||
return false;
|
return false;
|
||||||
@ -692,8 +692,8 @@ static Int term_to_atom(USES_REGS1) {
|
|||||||
Term t2 = Deref(ARG2), ctl, rc = false;
|
Term t2 = Deref(ARG2), ctl, rc = false;
|
||||||
Atom at;
|
Atom at;
|
||||||
if (IsVarTerm(t2)) {
|
if (IsVarTerm(t2)) {
|
||||||
const char *s = Yap_TermToBuffer(Deref(ARG1),
|
const char *s =
|
||||||
Quote_illegal_f | Handle_vars_f);
|
Yap_TermToBuffer(Deref(ARG1), Quote_illegal_f | Handle_vars_f);
|
||||||
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
|
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, t2,
|
Yap_Error(RESOURCE_ERROR_HEAP, t2,
|
||||||
"Could not get memory from the operating system");
|
"Could not get memory from the operating system");
|
||||||
@ -711,9 +711,9 @@ static Int term_to_atom(USES_REGS1) {
|
|||||||
Yap_unify(rc, ARG1);
|
Yap_unify(rc, ARG1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Yap_TermToBuffer(Term t, int flags) {
|
char *Yap_TermToBuffer(Term t, int flags) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno = Yap_open_buf_write_stream(LOCAL_encoding,flags);
|
int sno = Yap_open_buf_write_stream(LOCAL_encoding, flags);
|
||||||
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
|
|
||||||
#include "py4yap.h"
|
#include "py4yap.h"
|
||||||
|
|
||||||
@ -51,7 +51,6 @@ static PyObject *s_to_python(const char *s, bool eval, PyObject *p0) {
|
|||||||
*/
|
*/
|
||||||
X_API PyObject *string_to_python(const char *s, bool eval, PyObject *p0) {
|
X_API PyObject *string_to_python(const char *s, bool eval, PyObject *p0) {
|
||||||
|
|
||||||
|
|
||||||
char *buf = malloc(strlen(s) + 1), *child;
|
char *buf = malloc(strlen(s) + 1), *child;
|
||||||
while ((child = strchr(s, '.')) != NULL) {
|
while ((child = strchr(s, '.')) != NULL) {
|
||||||
size_t len = child - s;
|
size_t len = child - s;
|
||||||
@ -108,9 +107,8 @@ static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
|
|||||||
* @return a Python object descriptor or NULL if failed
|
* @return a Python object descriptor or NULL if failed
|
||||||
*/
|
*/
|
||||||
PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
||||||
// o≈
|
//
|
||||||
YAP_Term yt = YAP_GetFromSlot(t);
|
YAP_Term yt = YAP_GetFromSlot(t);
|
||||||
Yap_DebugPlWriteln(yt);
|
|
||||||
switch (PL_term_type(t)) {
|
switch (PL_term_type(t)) {
|
||||||
case PL_VARIABLE: {
|
case PL_VARIABLE: {
|
||||||
if (yt == 0) {
|
if (yt == 0) {
|
||||||
@ -137,7 +135,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
o = PyUnicode_FromString(s);
|
o = PyUnicode_FromString(s);
|
||||||
}
|
}
|
||||||
if (o) {
|
if (o) {
|
||||||
//PyDict_SetItemString(py_Atoms, s, Py_None);
|
// PyDict_SetItemString(py_Atoms, s, Py_None);
|
||||||
Py_INCREF(o);
|
Py_INCREF(o);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@ -149,20 +147,20 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
} else if (YAP_IsStringTerm(yt)) {
|
} else if (YAP_IsStringTerm(yt)) {
|
||||||
s = YAP_StringOfTerm(yt);
|
s = YAP_StringOfTerm(yt);
|
||||||
} else {
|
} else {
|
||||||
return CHECKNULL(t, NULL);
|
return CHECKNULL(t, NULL);
|
||||||
}
|
}
|
||||||
PyObject *pobj = PyUnicode_FromString(s);
|
PyObject *pobj = PyUnicode_FromString(s);
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION < 3
|
#if PY_MAJOR_VERSION < 3
|
||||||
if (proper_ascii_string(s)) {
|
if (proper_ascii_string(s)) {
|
||||||
PyObject *o = PyString_FromStringAndSize(s, strlen(s));
|
PyObject *o = PyString_FromStringAndSize(s, strlen(s));
|
||||||
return CHECKNULL(t, o);
|
return CHECKNULL(t, o);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// char *p = malloc(strlen(s)+1);
|
// char *p = malloc(strlen(s)+1);
|
||||||
// strcpy(p, s);
|
// strcpy(p, s);
|
||||||
Py_IncRef(pobj);
|
Py_IncRef(pobj);
|
||||||
return CHECKNULL(t, pobj);
|
return CHECKNULL(t, pobj);
|
||||||
} break;
|
} break;
|
||||||
case PL_INTEGER: {
|
case PL_INTEGER: {
|
||||||
int64_t j;
|
int64_t j;
|
||||||
@ -189,21 +187,21 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
if (PL_is_pair(t)) {
|
if (PL_is_pair(t)) {
|
||||||
Term t0 = Yap_GetFromHandle(t);
|
Term t0 = Yap_GetFromHandle(t);
|
||||||
Term *tail;
|
Term *tail;
|
||||||
size_t len,i;
|
size_t len, i;
|
||||||
if ((len = Yap_SkipList(&t0, &tail))>=0 && *tail == TermNil) {
|
if ((len = Yap_SkipList(&t0, &tail)) >= 0 && *tail == TermNil) {
|
||||||
PyObject *out, *a;
|
PyObject *out, *a;
|
||||||
|
|
||||||
out = PyList_New(len);
|
out = PyList_New(len);
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
Term ai = HeadOfTerm(t0);
|
Term ai = HeadOfTerm(t0);
|
||||||
a = term_to_python(Yap_InitHandle(ai), eval, o, cvt);
|
a = term_to_python(Yap_InitHandle(ai), eval, o, cvt);
|
||||||
if (a) {
|
if (a) {
|
||||||
if (PyList_SetItem(out, i, a) < 0) {
|
if (PyList_SetItem(out, i, a) < 0) {
|
||||||
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
|
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t0 = TailOfTerm(t0);
|
t0 = TailOfTerm(t0);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
} else {
|
} else {
|
||||||
@ -256,11 +254,11 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
PyObject *ip = term_to_python(trhs, eval, o, cvt);
|
PyObject *ip = term_to_python(trhs, eval, o, cvt);
|
||||||
if (PySequence_Check(v)) {
|
if (PySequence_Check(v)) {
|
||||||
#if PY_MAJOR_VERSION < 3
|
#if PY_MAJOR_VERSION < 3
|
||||||
if (PyLong_Check(ip)) {
|
if (PyLong_Check(ip)) {
|
||||||
min = PyLong_AsLong(ip);
|
min = PyLong_AsLong(ip);
|
||||||
} else if (PyInt_Check(ip)) {
|
} else if (PyInt_Check(ip)) {
|
||||||
min = PyInt_asInt(ip);
|
min = PyInt_asInt(ip);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (PyLong_Check(ip)) {
|
if (PyLong_Check(ip)) {
|
||||||
PyObject *o = PySequence_GetItem(v, PyLong_AsLong(ip));
|
PyObject *o = PySequence_GetItem(v, PyLong_AsLong(ip));
|
||||||
@ -337,7 +335,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
AOK(PL_get_arg(1, t, t), NULL);
|
AOK(PL_get_arg(1, t, t), NULL);
|
||||||
if (!(dict = PyDict_New()))
|
if (!(dict = PyDict_New()))
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(dict);
|
Py_INCREF(dict);
|
||||||
DebugPrintf("Dict %p\n", dict);
|
DebugPrintf("Dict %p\n", dict);
|
||||||
|
|
||||||
while (PL_is_functor(t, FUNCTOR_comma2)) {
|
while (PL_is_functor(t, FUNCTOR_comma2)) {
|
||||||
|
@ -953,12 +953,11 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
|
|||||||
|
|
||||||
if (!PL_get_arg(1, t, targ))
|
if (!PL_get_arg(1, t, targ))
|
||||||
return NULL;
|
return NULL;
|
||||||
// Yap_DebugPlWriteln(YAP_GetFromSlot(t));
|
// Yap_DebugPlWriteln(YAP_GetFromSlot(t));
|
||||||
lhs = term_to_python(targ, true, NULL, true);
|
lhs = term_to_python(targ, true, NULL, true);
|
||||||
AOK(PL_get_arg(2, t, targ), NULL);
|
AOK(PL_get_arg(2, t, targ), NULL);
|
||||||
rhs = term_to_python(targ, true, NULL, true);
|
rhs = term_to_python(targ, true, NULL, true);
|
||||||
Yap_DebugPlWriteln(YAP_GetFromSlot(targ));
|
if (PySequence_Check(lhs) && PySequence_Check(rhs)) {
|
||||||
if (PySequence_Check(lhs) && PySequence_Check(rhs)) {
|
|
||||||
return PySequence_Concat(lhs, rhs);
|
return PySequence_Concat(lhs, rhs);
|
||||||
}
|
}
|
||||||
if (!PyNumber_Check(lhs))
|
if (!PyNumber_Check(lhs))
|
||||||
@ -1036,11 +1035,12 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
|
|||||||
PyDict_SetItem(pyDict, key, val);
|
PyDict_SetItem(pyDict, key, val);
|
||||||
} else {
|
} else {
|
||||||
indict = false;
|
indict = false;
|
||||||
pArgs = PyTuple_New(i);
|
pArgs = PyTuple_New(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr,"Tuple %p: %s\n", pyDict, PyUnicode_AsUTF8(PyObject_Str(pyDict)));
|
fprintf(stderr, "Tuple %p: %s\n", pyDict,
|
||||||
if (!indict) {
|
PyUnicode_AsUTF8(PyObject_Str(pyDict)));
|
||||||
|
if (!indict) {
|
||||||
if (PL_is_variable(tleft)) {
|
if (PL_is_variable(tleft)) {
|
||||||
pArg = Py_None;
|
pArg = Py_None;
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
YAP_Term TermErrStream, TermOutStream;
|
YAP_Term TermErrStream, TermOutStream;
|
||||||
|
|
||||||
|
|
||||||
static void pyflush(StreamDesc *st) {
|
static void pyflush(StreamDesc *st) {
|
||||||
#if 0
|
#if 0
|
||||||
st->u.w_irl.ptr[0] = '\0';
|
st->u.w_irl.ptr[0] = '\0';
|
||||||
@ -75,8 +74,7 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
|
|||||||
}
|
}
|
||||||
StreamDesc *st = YAP_RepStreamFromId(sno);
|
StreamDesc *st = YAP_RepStreamFromId(sno);
|
||||||
st->name = YAP_LookupAtom(name);
|
st->name = YAP_LookupAtom(name);
|
||||||
if (strcmp(name, "sys.stdout") == 0 ||
|
if (strcmp(name, "sys.stdout") == 0 || strcmp(name, "sys.stderr") == 0 ||
|
||||||
strcmp(name, "sys.stderr") == 0 ||
|
|
||||||
strcmp(name, "input") == 0) {
|
strcmp(name, "input") == 0) {
|
||||||
st->status |= Tty_Stream_f;
|
st->status |= Tty_Stream_f;
|
||||||
}
|
}
|
||||||
@ -131,20 +129,23 @@ static bool py_close(int sno) {
|
|||||||
|
|
||||||
static bool getLine(StreamDesc *rl_iostream, int sno) {
|
static bool getLine(StreamDesc *rl_iostream, int sno) {
|
||||||
char *myrl_line = NULL;
|
char *myrl_line = NULL;
|
||||||
term_t ctk = python_acquire_GIL();
|
// term_t ctk = python_acquire_GIL();
|
||||||
|
PyObject_Print(rl_iostream->u.private_data, stderr, 0);
|
||||||
/* window of vulnerability opened */
|
/* window of vulnerability opened */
|
||||||
myrl_line = PyUnicode_AsUTF8(PyObject_CallFunctionObjArgs(rl_iostream->u.private_data, NULL));
|
PyObject *readl =
|
||||||
python_release_GIL(ctk);
|
PyObject_GetAttrString(rl_iostream->u.private_data, "readline");
|
||||||
|
PyObject_Print(readl, stderr, 0);
|
||||||
|
|
||||||
|
myrl_line = PyUnicode_AsUTF8(
|
||||||
|
PyObject_CallFunctionObjArgs(readl, rl_iostream->u.private_data, NULL));
|
||||||
|
// python_release_GIL(ctk);
|
||||||
PyObject *err;
|
PyObject *err;
|
||||||
if ((err = PyErr_Occurred())) {
|
if ((err = PyErr_Occurred())) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(err, "Error in getLine\n");
|
||||||
err,
|
|
||||||
"Error in getLine\n");
|
|
||||||
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
|
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
|
||||||
}
|
}
|
||||||
size_t size = strlen (myrl_line)+1;
|
size_t size = strlen(myrl_line) + 1;
|
||||||
rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf =
|
rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf =
|
||||||
(const unsigned char *)malloc(size);
|
(const unsigned char *)malloc(size);
|
||||||
memmove((void *)rl_iostream->u.irl.buf, myrl_line, size);
|
memmove((void *)rl_iostream->u.irl.buf, myrl_line, size);
|
||||||
return true;
|
return true;
|
||||||
|
@ -79,11 +79,7 @@ close_esh( _Engine , Stream ) :-
|
|||||||
p3_message( _Severity, Engine, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
p3_message( _Severity, Engine, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
||||||
python_clear_errors,
|
python_clear_errors,
|
||||||
!,
|
!,
|
||||||
writeln(E),
|
Engine.errors := [t(Cause,LN,CharPos,Details)]+Engine.errors.
|
||||||
NE := [t(Cause,LN,CharPos,Details)]+Engine.errors,
|
|
||||||
writeln(E),
|
|
||||||
writeln(NE),
|
|
||||||
Engine.errors := NE.
|
|
||||||
p3_message(error, Engine, E) :-
|
p3_message(error, Engine, E) :-
|
||||||
python_clear_errors,
|
python_clear_errors,
|
||||||
!.
|
!.
|
||||||
@ -181,4 +177,3 @@ p3_message(error, Engine, E) :-
|
|||||||
%% Self.errors := [t(C,L,N,A)] + Self.errors,
|
%% Self.errors := [t(C,L,N,A)] + Self.errors,
|
||||||
%% fail.
|
%% fail.
|
||||||
%% close_events( _ ).
|
%% close_events( _ ).
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ ypp_file(File,PPFile):-
|
|||||||
% Cmdline
|
% Cmdline
|
||||||
defines2string(Defs),ypp_extcmd(Cmd),
|
defines2string(Defs),ypp_extcmd(Cmd),
|
||||||
atom_concat([Cmd,' ',PPFile,' ',Defs,' ',File],Cmdline),
|
atom_concat([Cmd,' ',PPFile,' ',Defs,' ',File],Cmdline),
|
||||||
write(Cmdline),nl,
|
% write(Cmdline),nl,
|
||||||
% current_module(M1,M2),
|
% current_module(M1,M2),
|
||||||
% write(M1:M2),nl,
|
% write(M1:M2),nl,
|
||||||
system(Cmdline),
|
system(Cmdline),
|
||||||
|
Reference in New Issue
Block a user