indenting+python error hanadling
This commit is contained in:
parent
c0cf2b0b83
commit
1dec8f5a55
@ -150,19 +150,19 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o) {
|
|||||||
out = PyList_New(len);
|
out = PyList_New(len);
|
||||||
if (!out) {
|
if (!out) {
|
||||||
PL_reset_term_refs(tail);
|
PL_reset_term_refs(tail);
|
||||||
return CHECKNULL(t, Py_None);
|
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (!PL_get_list(t, arg, t)) {
|
if (!PL_get_list(t, arg, t)) {
|
||||||
PL_reset_term_refs(tail);
|
PL_reset_term_refs(tail);
|
||||||
return Py_None;
|
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
|
||||||
}
|
}
|
||||||
a = term_to_python(arg, eval, o);
|
a = term_to_python(arg, eval, o);
|
||||||
if (a) {
|
if (a) {
|
||||||
if (PyList_SetItem(out, i, a) < 0) {
|
if (PyList_SetItem(out, i, a) < 0) {
|
||||||
PL_reset_term_refs(tail);
|
PL_reset_term_refs(tail);
|
||||||
return Py_None;
|
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,11 +170,33 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o) {
|
|||||||
return CHECKNULL(t, out);
|
return CHECKNULL(t, out);
|
||||||
} else {
|
} else {
|
||||||
functor_t fun;
|
functor_t fun;
|
||||||
|
atom_t name;
|
||||||
|
int arity;
|
||||||
PyObject *rc;
|
PyObject *rc;
|
||||||
|
|
||||||
if (!PL_get_functor(t, &fun)) {
|
if (!PL_get_functor(t, &fun)) {
|
||||||
PL_reset_term_refs(tail);
|
PL_reset_term_refs(tail);
|
||||||
return CHECKNULL(t, Py_None);
|
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
|
||||||
|
}
|
||||||
|
AOK(PL_get_name_arity(t, &name, &arity), NULL);
|
||||||
|
if (name == ATOM_t) {
|
||||||
|
int i;
|
||||||
|
rc = PyTuple_New(arity);
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
term_t arg = PL_new_term_ref();
|
||||||
|
if (!PL_get_arg(i+1, t, arg)) {
|
||||||
|
PL_reset_term_refs(arg);
|
||||||
|
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "t(...)->python");
|
||||||
|
}
|
||||||
|
PyObject *a = term_to_python(arg, eval, o);
|
||||||
|
if (a) {
|
||||||
|
if (PyTuple_SetItem(rc, i, a) < 0) {
|
||||||
|
PL_reset_term_refs(arg);
|
||||||
|
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "t(...)->python");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PL_reset_term_refs(arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (eval)
|
if (eval)
|
||||||
rc = compound_to_pyeval(t, o);
|
rc = compound_to_pyeval(t, o);
|
||||||
@ -185,7 +207,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CHECKNULL(t, Py_None);
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o) {
|
PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o) {
|
||||||
@ -209,3 +231,7 @@ PyObject *deref_term_to_python(term_t t) {
|
|||||||
}
|
}
|
||||||
return term_to_python(t, false, NULL);
|
return term_to_python(t, false, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void YAPPy_ThrowError__(const char *file, const char *function, int lineno,
|
||||||
|
yap_error_number type, term_t where, ...);
|
||||||
|
@ -698,7 +698,7 @@ static PyObject *structseq_repr(PyObject *iobj) {
|
|||||||
|
|
||||||
PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
|
PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
|
||||||
PyObject *o;
|
PyObject *o;
|
||||||
#if PY_MAJOR_VERSION >= 30
|
#if PY_MAJOR_VERSION >= 3
|
||||||
PyTypeObject *typp;
|
PyTypeObject *typp;
|
||||||
PyObject *key = PyUnicode_FromString(s);
|
PyObject *key = PyUnicode_FromString(s);
|
||||||
if (py_F2P && PyDict_Contains(py_F2P, key)) {
|
if (py_F2P && PyDict_Contains(py_F2P, key)) {
|
||||||
@ -729,7 +729,6 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
|
|||||||
}
|
}
|
||||||
o = PyStructSequence_New(typp);
|
o = PyStructSequence_New(typp);
|
||||||
Py_INCREF(typp);
|
Py_INCREF(typp);
|
||||||
fprintf(stderr, "<<< %p\n",typp);
|
|
||||||
arity_t i;
|
arity_t i;
|
||||||
for (i = 0; i < arity; i++) {
|
for (i = 0; i < arity; i++) {
|
||||||
PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
|
PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
|
||||||
@ -750,7 +749,7 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *bip_range(term_t t) {
|
static PyObject *bip_range(term_t t) {
|
||||||
long ilow = 0, ihigh = 0, istep = 1;
|
long ilow = 0, ihigh = 0, istep = 1;
|
||||||
long bign;
|
long bign;
|
||||||
Py_ssize_t i, n;
|
Py_ssize_t i, n;
|
||||||
@ -805,9 +804,9 @@ static PyObject *bip_range(term_t t) {
|
|||||||
ilow += istep;
|
ilow += istep;
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
|
static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
|
||||||
bool eval) {
|
bool eval) {
|
||||||
PyObject *lhs, *rhs;
|
PyObject *lhs, *rhs;
|
||||||
term_t tleft = PL_new_term_ref(), tright = PL_new_term_ref();
|
term_t tleft = PL_new_term_ref(), tright = PL_new_term_ref();
|
||||||
@ -841,9 +840,9 @@ static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
|
|||||||
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
|
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
|
||||||
// Py_DECREF(lhs);
|
// Py_DECREF(lhs);
|
||||||
// Py_DECREF(rhs);
|
// Py_DECREF(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
|
PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
|
||||||
atom_t name;
|
atom_t name;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
@ -1016,9 +1015,9 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
|
|||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *compound_to_pytree(term_t t, PyObject *context) {
|
PyObject *compound_to_pytree(term_t t, PyObject *context) {
|
||||||
PyObject *o = py_Main, *no;
|
PyObject *o = py_Main, *no;
|
||||||
functor_t fun;
|
functor_t fun;
|
||||||
atom_t name;
|
atom_t name;
|
||||||
@ -1072,9 +1071,9 @@ PyObject *compound_to_pytree(term_t t, PyObject *context) {
|
|||||||
}
|
}
|
||||||
return term_to_nametuple(s, arity, out);
|
return term_to_nametuple(s, arity, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *compound_to_pyeval(term_t t, PyObject *context) {
|
PyObject *compound_to_pyeval(term_t t, PyObject *context) {
|
||||||
PyObject *o = NULL, *no;
|
PyObject *o = NULL, *no;
|
||||||
atom_t name;
|
atom_t name;
|
||||||
int arity;
|
int arity;
|
||||||
@ -1239,4 +1238,4 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
|
|||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user