Merge /home/vsc/github/yap-6.3

This commit is contained in:
Vitor Santos Costa
2017-07-25 01:11:16 +01:00
35 changed files with 1060 additions and 1008 deletions

View File

@@ -16,6 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=============================================================================
static YAP_Term gecode_RM_NONE;
static YAP_Term gecode_RM_CONSTANT;
static YAP_Term gecode_RM_LINEAR;
@@ -1397,33 +1398,29 @@ static YAP_Bool gecode_constraint_min_313(void)
static YAP_Bool gecode_constraint_when_456(void)
{
return YAP_Error("SYSTEN_ERROR", TermNil, "Unsupported"); /*
GenericSpace* space = gecode_Space_from_term(YAP_ARG1);
BoolVar X2 = gecode_BoolVar_from_term(space,YAP_ARG2);
std::function<void(Space&home)> X3 = gecode_std::function<void(Space&home)>_from_term(YAP_ARG3);
std::function<void(Space&home)> X3 = gecode_StdFunctionSpace_from_term(YAP_ARG3);
IntPropLevel X4 = gecode_IntPropLevel_from_term(YAP_ARG4);
when(*space,X2,X3,X4);
return TRUE; */
return false;
return TRUE;
}
static YAP_Bool gecode_constraint_when_457(void)
{
return YAP_Error("SYSTEN_ERROR", TermNil, "Unsupported"); /*
GenericSpace* space = gecode_Space_from_term(YAP_ARG1);
BoolVar X2 = gecode_BoolVar_from_term(space,YAP_ARG2);
std::function<void(Space&home)> X3 = gecode_std::function<void(Space&home)>_from_term(YAP_ARG3);
std::function<void(Space&home)> X4 = gecode_std::function<void(Space&home)>_from_term(YAP_ARG4);
std::function<void(Space&home)> X3 = gecode_StdFunctionSpace_from_term(YAP_ARG3);
std::function<void(Space&home)> X4 = gecode_StdFunctionSpace_from_term(YAP_ARG4);
when(*space,X2,X3,X4);
return TRUE;*/
return TRUE;
}
static YAP_Bool gecode_constraint_cardinality_71(void)
{
GenericSpace* space = gecode_Space_from_term(YAP_ARG1);
SetVarArgs X2 = gecode_SetVarArgs_from_term(space,YAP_ARG2);
int X3 = gecode_int_from_term(YAP_ARG3)289;
int X3 = gecode_int_from_term(YAP_ARG3);
int X4 = gecode_int_from_term(YAP_ARG4);
cardinality(*space,X2,X3,X4);
return TRUE;
@@ -2247,7 +2244,7 @@ static YAP_Bool gecode_constraint_when_455(void)
{
GenericSpace* space = gecode_Space_from_term(YAP_ARG1);
BoolVar X2 = gecode_BoolVar_from_term(space,YAP_ARG2);
std::function<void(Space&home)> X3 = gecode_std::function<void(Space&home)>_from_term(YAP_ARG3);
std::function<void(Space&home)> X3 = gecode_StdFunctionSpace_from_term(YAP_ARG3);
when(*space,X2,X3);
return TRUE;
}
@@ -2888,11 +2885,10 @@ static YAP_Bool gecode_constraint_channel_74(void)
static YAP_Bool gecode_constraint_when_458(void)
{
GenericSpace* space = gecode_Space_from_term(YAP_ARG1);
BoolVar X2 = gecode_BoolVar_from_term(space,YAP_ARG2);
std::function<void(Space&home)> X3 = gecode_std::function<void(Space&home)>_from_term(YAP_ARG3);
std::function<void(Space&home)> X4 = gecode_std::function<void(Space&home)>_from_term(YAP_ARG4);
std::function<void(Space&home)> X3 = gecode_StdFunctionSpace_from_term(YAP_ARG3);
std::function<void(Space&home)> X4 = gecode_StdFunctionSpace_from_term(YAP_ARG4);
IntPropLevel X5 = gecode_IntPropLevel_from_term(YAP_ARG5);
when(*space,X2,X3,X4,X5);
return TRUE;
@@ -3145,7 +3141,7 @@ static YAP_Bool gecode_constraint_binpacking_40(void)
static YAP_Bool gecode_constraint_branch_1(void)
{
GenericSpace* space = gecode_Space_from_term(YAP_ARG1);
std::function<void(Space&home)> X2 = gecode_std::function<void(Space&home)>_from_term(YAP_ARG2);
std::function<void(Space&home)> X2 = gecode_StdFunctionSpace_from_term(YAP_ARG2);
branch(*space,X2);
return TRUE;
}
@@ -5174,3 +5170,4 @@ static YAP_Bool gecode_constraint_ite_254(void)
ite(*space,X2,X3,X4,X5,X6);
return TRUE;
}

View File

@@ -554,7 +554,11 @@ class YAPEnumImpl(object):
print
def _generate_from_term(self):
print "static %s gecode_%s_from_term(YAP_Term X)" % (self.TYPE,self.TYPE)
if self.TYPE == "std::function<void(Space&home)>":
t2 = "StdFunctionSpace"
else:
t2 = self.TYPE
print "static %s gecode_%s_from_term(YAP_Term X)" % (self.TYPE,t2)
print "{"
for x in self.ENUM:
print " if (X==gecode_%s) return %s;" % (x,x)
@@ -563,11 +567,16 @@ class YAPEnumImpl(object):
print
def _generate_from_term_forward_decl(self):
print "static %s gecode_%s_from_term(YAP_Term);" % (self.TYPE,self.TYPE)
if self.TYPE == "std::function<void(Space&home)>":
t2 = "StdFunctionSpace"
else:
t2 = self.TYPE
print "static %s gecode_%s_from_term(YAP_Term);" % (self.TYPE,t2)
class YAPEnumImplGenerator(object):
def generate(self):
generate_space_function();
for c in enum_classes():
class C(c,YAPEnumImpl): pass
o = C()
@@ -576,6 +585,7 @@ class YAPEnumImplGenerator(object):
class YAPEnumForwardGenerator(object):
def generate(self):
generate_space_function_forward();
for c in enum_classes():
class C(c,YAPEnumImpl): pass
o = C()
@@ -642,12 +652,16 @@ class CCDescriptor(object):
has_space = True
else:
extra = ""
t2 = t
if t in ("IntVar","BoolVar","SetVar","FloatVar","IntVarArgs","BoolVarArgs","SetVarArgs","FloatVarArgs"):
extra = "space,"
if has_space == False:
print " GenericSpace* space = gecode_Space_from_term(%s);" % a
has_space = True
print " %s %s = gecode_%s_from_term(%s%s);" % (t,v,t,extra,a)
else:
if t == "std::function<void(Space&home)>":
t2 = "StdFunctionSpace"
print " %s %s = gecode_%s_from_term(%s%s);" % (t,v,t2,extra,a)
args.append(v)
i += 1
print " %s(%s);" % (self.name, ",".join(args))

View File

@@ -186,6 +186,18 @@ static inline BoolAssign&
return *(DFA *) YAP_OpaqueObjectFromTerm(t);
}
static inline Rnd&
gecode_Rnd_from_term(YAP_Term t)
{
return *(Rnd *) YAP_OpaqueObjectFromTerm(t);
}
static inline std::function<void(Space&home)>&
gecode_StdFunctionSpace_from_term(YAP_Term t)
{
return *(std::function<void(Space&home)> *) YAP_OpaqueObjectFromTerm(t);
}
static inline FloatNum
gecode_FloatNum_from_term(YAP_Term t)
{
@@ -379,6 +391,7 @@ static YAP_Term gecode_BOOL_VAR_RND;
static YAP_Term gecode_FLOAT_VAR_SIZE_MIN;
static YAP_Term gecode_FLOAT_VAR_SIZE_MAX;
static YAP_Term gecode_FLOAT_VAR_DEGREE_SIZE_MAX;
static YAP_Term gecode_FLOAT_VAR_DEGREE_SIZE_MIN;
static inline FloatVarBranch
gecode_FloatVarBranch_from_term(YAP_Term t)
@@ -386,7 +399,6 @@ static YAP_Term gecode_BOOL_VAR_RND;
if (YAP_IsAtomTerm(t)) {
if ( t == gecode_FLOAT_VAR_SIZE_MIN)
return FLOAT_VAR_SIZE_MIN();
static YAP_Term gecode_FLOAT_VAR_DEGREE_SIZE_MIN;
if ( t == gecode_FLOAT_VAR_SIZE_MAX)
return FLOAT_VAR_SIZE_MAX();
if ( t == gecode_FLOAT_VAR_NONE)

View File

@@ -1,5 +1,5 @@
The MYDDAS Data-base interface {#myddas}
===============================
## The MYDDAS Data-base interface {#myddas}
The MYDDAS database project was developed within a FCT project aiming at
the development of a highly efficient deductive database system, based
@@ -63,8 +63,8 @@ The MYDDAS Data-base interface {#myddas}
Prolog cut operator, which has exactly the same behaviour from
predicates defined in the Prolog program source code, or from predicates
defined in database as relations.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name = 'John Doe',
Number = 123456789 ?
yes
@@ -92,9 +92,6 @@ The MYDDAS Data-base interface {#myddas}
@pred db view(+,+,+).
@pred db view(+,+).
@@ -186,9 +183,6 @@ The MYDDAS Data-base interface {#myddas}
@pred db_sql(+,+,?).
@pred db_sql(+,?).
@@ -284,15 +278,7 @@ The MYDDAS Data-base interface {#myddas}
@pred db_get_attributes_types(+,+,?).
@pred db_get_attributes_types(+,?).
The prototype for this predicate is the following:
otype for this predicate is the following:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_get_attributes_types(Conn,RelationName,ListOfFields).
@@ -552,9 +538,6 @@ The MYDDAS Data-base interface {#myddas}
this by doing again `db_my_result_set(store_result)`.
@pred db_my_sql_mode(+Conn,?SQL_Mode).
@pred db_my_sql_mode(?SQL_Mode).
@@ -570,4 +553,4 @@ The MYDDAS Data-base interface {#myddas}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can see the available SQL Modes at the MySQL homepage at
<http://www.mysql.org>.
b

View File

@@ -32,7 +32,9 @@ static PyObject *s_to_python(const char *s, bool eval, PyObject *p0) {
Py_INCREF(o);
return CHECKNULL(YAP_MkStringTerm(s), o);
} else {
PyObject *pobj = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
//char *ns = Py_Malloc(strlen(s)+1);
///strcpy(ns,s);
PyObject *pobj = PyUnicode_FromString(s);
return pobj;
}
}
@@ -149,43 +151,65 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o) {
arg = tail;
out = PyList_New(len);
if (!out) {
PL_reset_term_refs(tail);
return CHECKNULL(t, Py_None);
PL_reset_term_refs(tail);
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
}
for (i = 0; i < len; i++) {
if (!PL_get_list(t, arg, t)) {
PL_reset_term_refs(tail);
return Py_None;
}
a = term_to_python(arg, eval, o);
if (a) {
if (PyList_SetItem(out, i, a) < 0) {
PL_reset_term_refs(tail);
return Py_None;
}
}
if (!PL_get_list(t, arg, t)) {
PL_reset_term_refs(tail);
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
}
a = term_to_python(arg, eval, o);
if (a) {
if (PyList_SetItem(out, i, a) < 0) {
PL_reset_term_refs(tail);
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "list->python");
}
}
}
PL_reset_term_refs(tail);
return CHECKNULL(t, out);
} else {
functor_t fun;
atom_t name;
int arity;
PyObject *rc;
if (!PL_get_functor(t, &fun)) {
PL_reset_term_refs(tail);
return CHECKNULL(t, Py_None);
PL_reset_term_refs(tail);
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)
rc = compound_to_pyeval(t, o);
rc = compound_to_pyeval(t, o);
else
rc = compound_to_pytree(t, o);
rc = compound_to_pytree(t, o);
PL_reset_term_refs(tail);
return rc;
}
}
}
return CHECKNULL(t, Py_None);
return Py_None;
}
PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o) {
@@ -209,3 +233,7 @@ PyObject *deref_term_to_python(term_t t) {
}
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, ...);

View File

@@ -698,7 +698,7 @@ static PyObject *structseq_repr(PyObject *iobj) {
PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
PyObject *o;
#if PY_MAJOR_VERSION >= 30
#if PY_MAJOR_VERSION >= 3
PyTypeObject *typp;
PyObject *key = PyUnicode_FromString(s);
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);
Py_INCREF(typp);
fprintf(stderr, "<<< %p\n",typp);
arity_t i;
for (i = 0; i < arity; i++) {
PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
@@ -750,493 +749,493 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
#endif
}
static PyObject *bip_range(term_t t) {
long ilow = 0, ihigh = 0, istep = 1;
long bign;
Py_ssize_t i, n;
int arity;
atom_t name;
term_t arg = PL_new_term_ref();
static PyObject *bip_range(term_t t) {
long ilow = 0, ihigh = 0, istep = 1;
long bign;
Py_ssize_t i, n;
int arity;
atom_t name;
term_t arg = PL_new_term_ref();
PyObject *v;
PyObject *v;
if (!PL_get_name_arity(t, &name, &arity))
return NULL;
AOK(PL_get_arg(1, t, arg), NULL);
ilow = get_int(arg, true);
if (arity == 1) {
ihigh = ilow;
ilow = 0;
} else {
AOK(PL_get_arg(2, t, arg), NULL);
ihigh = get_int(arg, true);
if (arity == 3) {
AOK(PL_get_arg(3, t, arg), NULL);
istep = get_int(arg, true);
}
}
if (istep == 0) {
PyErr_SetString(PyExc_ValueError, "range() step argument must not be zero");
return NULL;
}
if (istep > 0)
bign = get_len_of_range(ilow, ihigh, istep);
else
bign = get_len_of_range(ihigh, ilow, -istep);
n = (Py_ssize_t)bign;
AOK(((bign >= 0 && (long)n == bign) || "range() result has too many items"),
NULL);
v = PyList_New(n);
if (!PL_get_name_arity(t, &name, &arity))
return NULL;
AOK(PL_get_arg(1, t, arg), NULL);
ilow = get_int(arg, true);
if (arity == 1) {
ihigh = ilow;
ilow = 0;
} else {
AOK(PL_get_arg(2, t, arg), NULL);
ihigh = get_int(arg, true);
if (arity == 3) {
AOK(PL_get_arg(3, t, arg), NULL);
istep = get_int(arg, true);
}
}
if (istep == 0) {
PyErr_SetString(PyExc_ValueError, "range() step argument must not be zero");
return NULL;
}
if (istep > 0)
bign = get_len_of_range(ilow, ihigh, istep);
else
bign = get_len_of_range(ihigh, ilow, -istep);
n = (Py_ssize_t)bign;
AOK(((bign >= 0 && (long)n == bign) || "range() result has too many items"),
NULL);
v = PyList_New(n);
if (v == NULL)
return Py_None;
for (i = 0; i < n; i++) {
if (v == NULL)
return Py_None;
for (i = 0; i < n; i++) {
#if PY_MAJOR_VERSION < 3
PyObject *w = PyInt_FromLong(ilow);
PyObject *w = PyInt_FromLong(ilow);
#else
PyObject *w = PyLong_FromLong(ilow);
PyObject *w = PyLong_FromLong(ilow);
#endif
if (w == NULL) {
Py_DECREF(v);
return NULL;
}
PyList_SET_ITEM(v, i, w);
Py_INCREF(w);
ilow += istep;
}
return v;
}
if (w == NULL) {
Py_DECREF(v);
return NULL;
}
PyList_SET_ITEM(v, i, w);
Py_INCREF(w);
ilow += istep;
}
return v;
}
static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
bool eval) {
PyObject *lhs, *rhs;
term_t tleft = PL_new_term_ref(), tright = PL_new_term_ref();
static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
bool eval) {
PyObject *lhs, *rhs;
term_t tleft = PL_new_term_ref(), tright = PL_new_term_ref();
functor_t fun;
functor_t fun;
AOK(PL_get_functor(targ, &fun), false);
while (fun == FUNCTOR_comma2) {
AOK(PL_get_arg(1, targ, tleft), false);
if (!copy_to_dictionary(dict, tleft, taux, eval))
return false;
AOK(PL_get_arg(2, targ, targ), false);
return copy_to_dictionary(dict, tright, taux, eval);
}
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
// Py_DECREF(lhs);
// Py_DECREF(rhs);
AOK(PL_get_functor(targ, &fun), false);
while (fun == FUNCTOR_comma2) {
AOK(PL_get_arg(1, targ, tleft), false);
if (!copy_to_dictionary(dict, tleft, taux, eval))
return false;
AOK(PL_get_arg(2, targ, targ), false);
return copy_to_dictionary(dict, tright, taux, eval);
}
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
// Py_DECREF(lhs);
// Py_DECREF(rhs);
AOK(PL_get_arg(1, targ, tleft), false);
lhs = atom_to_python_string(tleft);
if (lhs == NULL) {
return FALSE;
}
AOK(PL_get_arg(2, targ, tright), false);
rhs = term_to_python(tright, eval, NULL);
if (rhs == NULL) {
PyErr_Print();
return false;
}
return PyDict_SetItem(dict, lhs, rhs) >= 0;
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
// Py_DECREF(lhs);
// Py_DECREF(rhs);
}
AOK(PL_get_arg(1, targ, tleft), false);
lhs = atom_to_python_string(tleft);
if (lhs == NULL) {
return FALSE;
}
AOK(PL_get_arg(2, targ, tright), false);
rhs = term_to_python(tright, eval, NULL);
if (rhs == NULL) {
PyErr_Print();
return false;
}
return PyDict_SetItem(dict, lhs, rhs) >= 0;
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
// Py_DECREF(lhs);
// Py_DECREF(rhs);
}
PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
atom_t name;
int len;
PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
atom_t name;
int len;
AOK(PL_get_name_arity(t, &name, &len), o);
AOK(PL_get_name_arity(t, &name, &len), o);
if (fun == FUNCTOR_pointer1) {
void *ptr;
if (fun == FUNCTOR_pointer1) {
void *ptr;
AOK(PL_get_arg(1, t, t), NULL);
AOK(PL_get_pointer(t, &ptr), NULL)
/* return __main__,s */
return (PyObject *)ptr;
}
if (name == ATOM_t) {
term_t targ = PL_new_term_ref();
PyObject *out;
int i;
AOK(PL_get_arg(1, t, t), NULL);
AOK(PL_get_pointer(t, &ptr), NULL)
/* return __main__,s */
return (PyObject *)ptr;
}
if (name == ATOM_t) {
term_t targ = PL_new_term_ref();
PyObject *out;
int i;
out = PyTuple_New(len);
DebugPrintf("Tuple %p\n", out);
out = PyTuple_New(len);
DebugPrintf("Tuple %p\n", out);
if (!out)
return NULL;
for (i = 0; i < len; i++) {
AOK(PL_get_arg(i + 1, t, targ), NULL);
PyErr_Clear();
PyObject *oa = term_to_python(targ, true, o);
bool rc = PyTuple_SET_ITEM(out, i, oa) == 0;
if (rc) {
PyErr_Print();
}
Py_INCREF(oa);
}
return out;
} else if (fun == FUNCTOR_div2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
if (!out)
return NULL;
for (i = 0; i < len; i++) {
AOK(PL_get_arg(i + 1, t, targ), NULL);
PyErr_Clear();
PyObject *oa = term_to_python(targ, true, o);
bool rc = PyTuple_SET_ITEM(out, i, oa) == 0;
if (rc) {
PyErr_Print();
}
Py_INCREF(oa);
}
return out;
} else if (fun == FUNCTOR_div2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
AOK(PL_get_arg(1, t, targ), NULL);
lhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(lhs))
return NULL;
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(rhs))
return NULL;
AOK(PL_get_arg(1, t, targ), NULL);
lhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(lhs))
return NULL;
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(rhs))
return NULL;
#if PY_MAJOR_VERSION < 3
return PyNumber_Divide(lhs, rhs);
return PyNumber_Divide(lhs, rhs);
#else
return PyNumber_TrueDivide(lhs, rhs);
return PyNumber_TrueDivide(lhs, rhs);
#endif
}
if (fun == FUNCTOR_sqbrackets2) {
term_t targ = PL_new_term_ref(), trhs = PL_new_term_ref();
PyObject *v;
Py_ssize_t min, max;
AOK(PL_get_arg(2, t, targ), NULL);
v = term_to_python(targ, true, o);
}
if (fun == FUNCTOR_sqbrackets2) {
term_t targ = PL_new_term_ref(), trhs = PL_new_term_ref();
PyObject *v;
Py_ssize_t min, max;
AOK(PL_get_arg(2, t, targ), NULL);
v = term_to_python(targ, true, o);
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_get_list(targ, trhs, targ), NULL);
if (PL_is_functor(trhs, FUNCTOR_colon2)) {
if (!PySequence_Check(v))
return NULL;
min = get_p_int(term_to_python(targ, true, NULL), 0);
AOK(PL_get_arg(1, trhs, targ), NULL);
if (PL_is_functor(targ, FUNCTOR_colon2)) {
return NULL;
}
max = get_p_int(term_to_python(targ, true, o), PyObject_Size(v));
return PySequence_GetSlice(v, min, max);
} else {
PyObject *ip = term_to_python(trhs, true, o);
if (PySequence_Check(v)) {
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_get_list(targ, trhs, targ), NULL);
if (PL_is_functor(trhs, FUNCTOR_colon2)) {
if (!PySequence_Check(v))
return NULL;
min = get_p_int(term_to_python(targ, true, NULL), 0);
AOK(PL_get_arg(1, trhs, targ), NULL);
if (PL_is_functor(targ, FUNCTOR_colon2)) {
return NULL;
}
max = get_p_int(term_to_python(targ, true, o), PyObject_Size(v));
return PySequence_GetSlice(v, min, max);
} else {
PyObject *ip = term_to_python(trhs, true, o);
if (PySequence_Check(v)) {
#if PY_MAJOR_VERSION < 3
if (PyLong_Check(ip) {
min = PyLong_AsLong(ip);
} else if (PyInt_Check(ip) {
min = PyInt_asInt(ip);
}
if (PyLong_Check(ip) {
min = PyLong_AsLong(ip);
} else if (PyInt_Check(ip) {
min = PyInt_asInt(ip);
}
#else
if (PyLong_Check(ip)) {
PyObject *o = PySequence_GetItem(v, PyLong_AsLong(ip));
if (o == NULL)
o = Py_None;
if (CHECKNULL(t, o) == NULL)
return NULL;
Py_INCREF(o);
return o;
}
if (PyLong_Check(ip)) {
PyObject *o = PySequence_GetItem(v, PyLong_AsLong(ip));
if (o == NULL)
o = Py_None;
if (CHECKNULL(t, o) == NULL)
return NULL;
Py_INCREF(o);
return o;
}
#endif
} else {
o = PyObject_GetItem(v, ip);
if (o == NULL)
o = Py_None;
Py_INCREF(o);
return o;
}
}
}
if (fun == FUNCTOR_dollar1) {
char *s = NULL;
term_t targ = PL_new_term_ref();
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_get_atom_chars(targ, &s), NULL);
/* return __main__,s */
PyObject *o = PyObject_GetAttrString(py_Main, s);
return o;
}
if (fun == FUNCTOR_brackets1) {
AOK(PL_get_arg(1, t, t), NULL);
return term_to_python(t, true, NULL);
}
if (fun == FUNCTOR_complex2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
double d1, d2;
} else {
o = PyObject_GetItem(v, ip);
if (o == NULL)
o = Py_None;
Py_INCREF(o);
return o;
}
}
}
if (fun == FUNCTOR_dollar1) {
char *s = NULL;
term_t targ = PL_new_term_ref();
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_get_atom_chars(targ, &s), NULL);
/* return __main__,s */
PyObject *o = PyObject_GetAttrString(py_Main, s);
return o;
}
if (fun == FUNCTOR_brackets1) {
AOK(PL_get_arg(1, t, t), NULL);
return term_to_python(t, true, NULL);
}
if (fun == FUNCTOR_complex2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
double d1, d2;
AOK(PL_get_arg(1, t, targ), NULL);
lhs = term_to_python(targ, true, NULL);
AOK(PyNumber_Check(lhs), NULL);
if (PyFloat_Check(lhs)) {
d1 = PyFloat_AsDouble(lhs);
} else if (PyLong_Check(lhs)) {
d1 = PyLong_AsLong(lhs);
AOK(PL_get_arg(1, t, targ), NULL);
lhs = term_to_python(targ, true, NULL);
AOK(PyNumber_Check(lhs), NULL);
if (PyFloat_Check(lhs)) {
d1 = PyFloat_AsDouble(lhs);
} else if (PyLong_Check(lhs)) {
d1 = PyLong_AsLong(lhs);
#if PY_MAJOR_VERSION < 3
} else if (PyInt_Check(lhs)) {
d1 = PyInt_AsLong(lhs);
} else if (PyInt_Check(lhs)) {
d1 = PyInt_AsLong(lhs);
#endif
} else {
return NULL;
}
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
AOK(PyNumber_Check(rhs), NULL);
if (PyFloat_Check(rhs)) {
d2 = PyFloat_AsDouble(rhs);
} else if (PyLong_Check(rhs)) {
d2 = PyLong_AsLong(rhs);
} else {
return NULL;
}
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
AOK(PyNumber_Check(rhs), NULL);
if (PyFloat_Check(rhs)) {
d2 = PyFloat_AsDouble(rhs);
} else if (PyLong_Check(rhs)) {
d2 = PyLong_AsLong(rhs);
#if PY_MAJOR_VERSION < 3
} else if (PyInt_Check(rhs)) {
d2 = PyInt_AsLong(rhs);
} else if (PyInt_Check(rhs)) {
d2 = PyInt_AsLong(rhs);
#endif
} else {
return NULL;
}
} else {
return NULL;
}
return PyComplex_FromDoubles(d1, d2);
}
if (fun == FUNCTOR_curly1) {
term_t targ = PL_new_term_ref(), taux = PL_new_term_ref();
PyObject *dict;
return PyComplex_FromDoubles(d1, d2);
}
if (fun == FUNCTOR_curly1) {
term_t targ = PL_new_term_ref(), taux = PL_new_term_ref();
PyObject *dict;
AOK(PL_get_arg(1, t, t), NULL);
if (!(dict = PyDict_New()))
return NULL;
DebugPrintf("Dict %p\n", dict);
AOK(PL_get_arg(1, t, t), NULL);
if (!(dict = PyDict_New()))
return NULL;
DebugPrintf("Dict %p\n", dict);
while (PL_is_functor(t, FUNCTOR_comma2)) {
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_is_functor(targ, FUNCTOR_colon2), NULL);
while (PL_is_functor(t, FUNCTOR_comma2)) {
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_is_functor(targ, FUNCTOR_colon2), NULL);
AOK(copy_to_dictionary(dict, targ, taux, true), NULL);
AOK(PL_get_arg(2, t, t), NULL);
}
AOK(copy_to_dictionary(dict, targ, taux, true), NULL);
AOK(PL_get_arg(2, t, t), NULL);
}
if (PL_is_functor(t, FUNCTOR_colon2)) {
AOK(copy_to_dictionary(dict, t, taux, true), NULL);
}
return dict;
}
return o;
}
if (PL_is_functor(t, FUNCTOR_colon2)) {
AOK(copy_to_dictionary(dict, t, taux, true), NULL);
}
return dict;
}
return o;
}
PyObject *compound_to_pytree(term_t t, PyObject *context) {
PyObject *o = py_Main, *no;
functor_t fun;
atom_t name;
int arity;
PyObject *compound_to_pytree(term_t t, PyObject *context) {
PyObject *o = py_Main, *no;
functor_t fun;
atom_t name;
int arity;
o = find_obj(context, t, false);
AOK(PL_get_name_arity(t, &name, &arity), NULL);
if (arity == 0)
return term_to_python(t, false, o);
AOK(PL_get_functor(t, &fun), NULL);
if ((no = compound_to_data(t, o, fun, false)) != o && no) {
return no;
}
if (!arity) {
char *s = NULL;
o = find_obj(context, t, false);
AOK(PL_get_name_arity(t, &name, &arity), NULL);
if (arity == 0)
return term_to_python(t, false, o);
AOK(PL_get_functor(t, &fun), NULL);
if ((no = compound_to_data(t, o, fun, false)) != o && no) {
return no;
}
if (!arity) {
char *s = NULL;
AOK(!PL_get_atom_chars(t, &s), NULL);
// this should never happen
return term_to_python(t, false, o);
} else {
const char *s;
if (!(s = PL_atom_chars(name))) {
return NULL;
}
term_t tleft;
int i;
PyObject *out = PyTuple_New(arity);
DebugPrintf("Tuple %p\n", o);
tleft = PL_new_term_ref();
for (i = 0; i < arity; i++) {
PyObject *pArg;
AOK(PL_get_arg(i + 1, t, tleft), NULL);
pArg = term_to_python(tleft, false, NULL);
if (pArg) {
/* pArg reference stolen here: */
PyTuple_SET_ITEM(out, i, pArg);
Py_INCREF(pArg);
}
}
if (CHECKNULL(t, out) == NULL) {
PyErr_Print();
return NULL;
}
PyObject *c = lookupPySymbol(s, o, NULL);
AOK(!PL_get_atom_chars(t, &s), NULL);
// this should never happen
return term_to_python(t, false, o);
} else {
const char *s;
if (!(s = PL_atom_chars(name))) {
return NULL;
}
term_t tleft;
int i;
PyObject *out = PyTuple_New(arity);
DebugPrintf("Tuple %p\n", o);
tleft = PL_new_term_ref();
for (i = 0; i < arity; i++) {
PyObject *pArg;
AOK(PL_get_arg(i + 1, t, tleft), NULL);
pArg = term_to_python(tleft, false, NULL);
if (pArg) {
/* pArg reference stolen here: */
PyTuple_SET_ITEM(out, i, pArg);
Py_INCREF(pArg);
}
}
if (CHECKNULL(t, out) == NULL) {
PyErr_Print();
return NULL;
}
PyObject *c = lookupPySymbol(s, o, NULL);
if (c && PyCallable_Check(c)) {
PyObject *n = PyTuple_New(arity);
PyTuple_SET_ITEM(n, 0, c);
PyTuple_SET_ITEM(n, 1, out);
return n;
}
return term_to_nametuple(s, arity, out);
}
}
if (c && PyCallable_Check(c)) {
PyObject *n = PyTuple_New(arity);
PyTuple_SET_ITEM(n, 0, c);
PyTuple_SET_ITEM(n, 1, out);
return n;
}
return term_to_nametuple(s, arity, out);
}
}
PyObject *compound_to_pyeval(term_t t, PyObject *context) {
PyObject *o = NULL, *no;
atom_t name;
int arity;
functor_t fun;
PyObject *compound_to_pyeval(term_t t, PyObject *context) {
PyObject *o = NULL, *no;
atom_t name;
int arity;
functor_t fun;
o = find_obj(context, t, true);
AOK(PL_get_name_arity(t, &name, &arity), NULL);
if (arity == 0)
return term_to_python(t, true, o);
if (!PL_get_functor(t, &fun))
return NULL;
if ((no = compound_to_data(t, o, fun, true)) != o && no) {
return no;
}
if (fun == FUNCTOR_abs1) {
return bip_abs(t);
} else if (fun == FUNCTOR_all1) {
return bip_all(t);
} else if (fun == FUNCTOR_any1) {
return bip_any(t);
} else if (fun == FUNCTOR_bin1) {
return bip_bin(t);
} else if (fun == FUNCTOR_ord1) {
return bip_ord(t);
} else if (fun == FUNCTOR_int1) {
return bip_int(t);
} else if (fun == FUNCTOR_long1) {
return bip_long(t);
} else if (fun == FUNCTOR_float1) {
return bip_float(t, true);
} else if (fun == FUNCTOR_iter1) {
return bip_iter(t);
} else if (fun == FUNCTOR_range1 || fun == FUNCTOR_range2 ||
fun == FUNCTOR_range3) {
return bip_range(t);
} else if (fun == FUNCTOR_sum1) {
return bip_sum(t);
}
if (fun == FUNCTOR_len1) {
term_t targ = PL_new_term_ref();
PyObject *ptr;
o = find_obj(context, t, true);
AOK(PL_get_name_arity(t, &name, &arity), NULL);
if (arity == 0)
return term_to_python(t, true, o);
if (!PL_get_functor(t, &fun))
return NULL;
if ((no = compound_to_data(t, o, fun, true)) != o && no) {
return no;
}
if (fun == FUNCTOR_abs1) {
return bip_abs(t);
} else if (fun == FUNCTOR_all1) {
return bip_all(t);
} else if (fun == FUNCTOR_any1) {
return bip_any(t);
} else if (fun == FUNCTOR_bin1) {
return bip_bin(t);
} else if (fun == FUNCTOR_ord1) {
return bip_ord(t);
} else if (fun == FUNCTOR_int1) {
return bip_int(t);
} else if (fun == FUNCTOR_long1) {
return bip_long(t);
} else if (fun == FUNCTOR_float1) {
return bip_float(t, true);
} else if (fun == FUNCTOR_iter1) {
return bip_iter(t);
} else if (fun == FUNCTOR_range1 || fun == FUNCTOR_range2 ||
fun == FUNCTOR_range3) {
return bip_range(t);
} else if (fun == FUNCTOR_sum1) {
return bip_sum(t);
}
if (fun == FUNCTOR_len1) {
term_t targ = PL_new_term_ref();
PyObject *ptr;
AOK(PL_get_arg(1, t, targ), NULL);
ptr = term_to_python(targ, true, NULL);
return PyLong_FromLong(PyObject_Length(ptr));
}
if (fun == FUNCTOR_dir1) {
term_t targ = PL_new_term_ref();
PyObject *ptr;
AOK(PL_get_arg(1, t, targ), NULL);
ptr = term_to_python(targ, true, NULL);
return PyLong_FromLong(PyObject_Length(ptr));
}
if (fun == FUNCTOR_dir1) {
term_t targ = PL_new_term_ref();
PyObject *ptr;
AOK(PL_get_arg(1, t, targ), NULL);
ptr = term_to_python(targ, true, NULL);
return PyObject_Dir(ptr);
AOK(PL_get_arg(1, t, targ), NULL);
ptr = term_to_python(targ, true, NULL);
return PyObject_Dir(ptr);
}
}
else if (fun == FUNCTOR_plus2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
else if (fun == FUNCTOR_plus2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
if (!PL_get_arg(1, t, targ))
return NULL;
lhs = term_to_python(targ, true, NULL);
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
if (PySequence_Check(lhs) && PySequence_Check(rhs)) {
return PySequence_Concat(lhs, rhs);
}
if (!PyNumber_Check(lhs))
return NULL;
if (!PyNumber_Check(rhs))
return NULL;
return PyNumber_Add(lhs, rhs);
} else if (fun == FUNCTOR_sub2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
if (!PL_get_arg(1, t, targ))
return NULL;
lhs = term_to_python(targ, true, NULL);
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
if (PySequence_Check(lhs) && PySequence_Check(rhs)) {
return PySequence_Concat(lhs, rhs);
}
if (!PyNumber_Check(lhs))
return NULL;
if (!PyNumber_Check(rhs))
return NULL;
return PyNumber_Add(lhs, rhs);
} else if (fun == FUNCTOR_sub2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
if (!PL_get_arg(1, t, targ))
return NULL;
lhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(lhs))
return NULL;
if (!PL_get_arg(2, t, targ))
return NULL;
rhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(rhs))
return NULL;
return PyNumber_Subtract(lhs, rhs);
} else if (fun == FUNCTOR_mul2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
if (!PL_get_arg(1, t, targ))
return NULL;
lhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(lhs))
return NULL;
if (!PL_get_arg(2, t, targ))
return NULL;
rhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(rhs))
return NULL;
return PyNumber_Subtract(lhs, rhs);
} else if (fun == FUNCTOR_mul2) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
AOK(PL_get_arg(1, t, targ), NULL);
(lhs = term_to_python(targ, true, NULL));
CHECKNULL(targ, lhs);
AOK(PL_get_arg(2, t, targ), NULL);
(rhs = term_to_python(targ, true, NULL));
CHECKNULL(targ, rhs);
if (PySequence_Check(lhs) && (
AOK(PL_get_arg(1, t, targ), NULL);
(lhs = term_to_python(targ, true, NULL));
CHECKNULL(targ, lhs);
AOK(PL_get_arg(2, t, targ), NULL);
(rhs = term_to_python(targ, true, NULL));
CHECKNULL(targ, rhs);
if (PySequence_Check(lhs) && (
#if PY_MAJOR_VERSION < 3
PyInt_Check(rhs) ||
PyInt_Check(rhs) ||
#endif
PyLong_Check(rhs))) {
return PySequence_Repeat(lhs, get_p_int(rhs, 0));
}
if (!PyNumber_Check(lhs) + !PyNumber_Check(rhs))
return NULL;
return PyNumber_Multiply(lhs, rhs);
}
if (!arity) {
char *s = NULL;
PyObject *pValue;
PyLong_Check(rhs))) {
return PySequence_Repeat(lhs, get_p_int(rhs, 0));
}
if (!PyNumber_Check(lhs) + !PyNumber_Check(rhs))
return NULL;
return PyNumber_Multiply(lhs, rhs);
}
if (!arity) {
char *s = NULL;
PyObject *pValue;
AOK(PL_get_atom_chars(t, &s), NULL);
pValue = PyObject_GetAttrString(o, s);
if (CHECKNULL(t, pValue) == NULL) {
PyErr_Print();
return NULL;
}
return pValue;
} else {
char *s = PL_atom_chars(name);
o = lookupPySymbol(s, o, NULL);
if (CHECKNULL(t, o) == NULL) {
PyErr_Print();
return NULL;
}
PyObject *pArgs = PyTuple_New(arity);
DebugPrintf("Tuple %p\n", pArgs);
int i;
term_t tleft = PL_new_term_ref();
for (i = 0; i < arity; i++) {
PyObject *pArg;
AOK(PL_get_arg(i + 1, t, tleft), NULL);
/* ignore (_) */
if (i == 0 && PL_is_variable(tleft)) {
pArg = Py_None;
} else {
pArg = term_to_python(tleft, true, NULL);
// PyObject_Print(pArg,fdopen(2,"w"),0);
if (pArg == NULL) {
pArg = Py_None;
}
/* pArg reference stolen here: */
Py_INCREF(pArg);
}
AOK(PL_get_atom_chars(t, &s), NULL);
pValue = PyObject_GetAttrString(o, s);
if (CHECKNULL(t, pValue) == NULL) {
PyErr_Print();
return NULL;
}
return pValue;
} else {
char *s = PL_atom_chars(name);
o = lookupPySymbol(s, o, NULL);
if (CHECKNULL(t, o) == NULL) {
PyErr_Print();
return NULL;
}
PyObject *pArgs = PyTuple_New(arity);
DebugPrintf("Tuple %p\n", pArgs);
int i;
term_t tleft = PL_new_term_ref();
for (i = 0; i < arity; i++) {
PyObject *pArg;
AOK(PL_get_arg(i + 1, t, tleft), NULL);
/* ignore (_) */
if (i == 0 && PL_is_variable(tleft)) {
pArg = Py_None;
} else {
pArg = term_to_python(tleft, true, NULL);
// PyObject_Print(pArg,fdopen(2,"w"),0);
if (pArg == NULL) {
pArg = Py_None;
}
/* pArg reference stolen here: */
Py_INCREF(pArg);
}
PyTuple_SetItem(pArgs, i, pArg);
}
if (!PyCallable_Check(o)) {
return term_to_nametuple(s, arity, pArgs);
}
PyObject *rc;
PyTuple_SetItem(pArgs, i, pArg);
}
if (!PyCallable_Check(o)) {
return term_to_nametuple(s, arity, pArgs);
}
PyObject *rc;
// PyObject_Print(pArgs, stderr, 0);
// PyObject_Print(o, stderr, 0);
CHECK_CALL(rc, t, PyObject_CallObject(o, pArgs));
Py_DECREF(pArgs);
Py_DECREF(o);
DebugPrintf("CallObject %p\n", rc);
// PyObject_Print(pArgs, stderr, 0);
// PyObject_Print(o, stderr, 0);
CHECK_CALL(rc, t, PyObject_CallObject(o, pArgs));
Py_DECREF(pArgs);
Py_DECREF(o);
DebugPrintf("CallObject %p\n", rc);
return rc;
}
}
return rc;
}
}

View File

@@ -24,78 +24,88 @@ SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES SWIG_MODULE_NAME yap)
if (WIN32)
set (SYS_DLLS ${GMP_LIBRARIES})
set (SYS_DLLS c:/msys64/mingw64/bin/libgmp-10.dll)
set (SYS_DLLS ${GMP_LIBRARIES} c:/msys64/mingw64/bin/libgmp-10.dll)
endif()
# inform we are compiling YAP
# s used in MSYS
#
#
# INSTALL ( TARGETS ${SWIG_MODULE_Py2YAP_REAL_NAME}
# RUNTIME DESTINATION ${PYTHON_MODULE_PATH}
# ARCHIVE DESTINATION ${PYTHON_MODULE_PATH}
# LIBRARY DESTINATION ${PYTHON_MODULE_PATH}
# )
# inform we are compiling YAP
# s used in MSYS
#
#
# INSTALL ( TARGETS ${SWIG_MODULE_Py2YAP_REAL_NAME}
# RUNTIME DESTINATION ${PYTHON_MODULE_PATH}
# ARCHIVE DESTINATION ${PYTHON_MODULE_PATH}
# LIBRARY DESTINATION ${PYTHON_MODULE_PATH}
# )
set (python_dlls $<TARGET_FILE:matrix>
set (python_dlls ${SYS_DLLS}
$<TARGET_FILE:matrix>
$<TARGET_FILE:regexp>
$<TARGET_FILE:yap_rl>
$<TARGET_FILE:tries>
$<TARGET_FILE:itries>
$<TARGET_FILE:sys>
$<TARGET_FILE:yap_random>
)
if (TARGET real)
)
if (TARGET real)
list(APPEND python_dlls $<TARGET_FILE:real>
)
)
endif()
if (NOT WIN32)
if (NOT WIN32)
list(APPEND python_dlls $<TARGET_FILE:YAP++> $<TARGET_FILE:Py4YAP>
)
endif()
)
endif()
set (PL ${pl_library} ${PROLOG_SOURCES} )
add_custom_target( YAP4PY_SETUP
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/packages/swig/yap.i ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/config.h ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/yap4py
COMMAND ${CMAKE_COMMAND} -E copy ${python_dlls} ${SYS_DLLS} ${CMAKE_BINARY_DIR}/libYap${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${PYTHON_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/yap4py
COMMAND ${CMAKE_COMMAND} -E copy ${PL} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog
COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/pl
COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/os
DEPENDS YAP4PY_SETUP_DIRS STARTUP ${python_dlls} ${PYTHON_SOURCES} ${PROLOG_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/setup.py ${SWIG_MODULE_Py2YAP_REAL_NAME} )
COMMAND ${CMAKE_COMMAND} -E copy ${python_dlls} yap4py
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/libYap${CMAKE_SHARED_LIBRARY_SUFFIX} yap4py
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${CMAKE_CURRENT_BINARY_DIR}/yap4py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS YAP4PY_SETUP_PL STARTUP ${python_dlls} libYap )
add_custom_target( YAP4PY_SETUP_PL
COMMAND ${CMAKE_COMMAND} -E copy ${PL} yap4py/prolog
COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} yap4py/prolog/pl
COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} yap4py/prolog/os
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/yap.i ${PYTHON_SOURCES} ${PL} ${pl_boot_library} ${pl_os_library} )
add_custom_target( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap.i
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/packages/swig/yap.i yap.i
COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_SOURCES} yap4py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS YAP4PY_SETUP_DIRS ${PYTHON_SOURCES} )
add_custom_target( YAP4PY_SETUP_DIRS
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/yap4py
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/pl
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/os
COMMAND ${CMAKE_COMMAND} -E make_directory yap4py
COMMAND ${CMAKE_COMMAND} -E make_directory yap4py/prolog
COMMAND ${CMAKE_COMMAND} -E make_directory yap4py/prolog/pl
COMMAND ${CMAKE_COMMAND} -E make_directory yap4py/prolog/os
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target( YAP4PY ALL
COMMAND ${PYTHON_EXECUTABLE} -m pip uninstall -y YAP4PY
add_custom_target( YAP4PY ALL
COMMAND ${PYTHON_EXECUTABLE} -m pip uninstall -y YAP4PY
COMMAND ${SWIG_EXECUTABLE} -python -modern -c++ -py3 -DX_API -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/OPTYap -I../../.. -o yap_wrap.cpp yap.i
COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS YAP4PY_SETUP)
install(CODE "execute_process(
COMMAND ${PYTHON_EXECUTABLE} -m pip install --force --no-index -f packages/python/swig/dist YAP4PY
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})"
DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${dlls} )
COMMAND ${PYTHON_EXECUTABLE} -m pip install --force --no-index -f packages/python/swig/dist YAP4PY
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})"
DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${dlls} )
install(FILES ${PROLOG_SOURCES} DESTINATION ${libpl})
if (WITH_DOCS AND DOXYGEN_FOUND)
if (WITH_DOCS AND DOXYGEN_FOUND)
set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
@@ -104,8 +114,8 @@ install(FILES ${PROLOG_SOURCES} DESTINATION ${libpl})
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile.xml
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers}
)
DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers}
)
# generate .i from doxygen .xml
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i

View File

@@ -3,6 +3,8 @@
See:
https://packaging.python.org/en/latest/distributing.html
https://github.com/pypa/sampleproject
"""
# Always prefer setuptools over distutils

View File

@@ -68,6 +68,8 @@ cplus = ['']
bpy2yap = []
native_sources = ['yap_wrap.cpp']
here = path.abspath(path.dirname(__file__))
gmp_dir = path.abspath(path.dirname("${GMP_LIBRARIES}"))
python_libdir = path.abspath(path.dirname("${PYTHON_LIBRARIES}"))
# Get the long description from the README file
@@ -79,14 +81,14 @@ extensions = [Extension('_yap', native_sources,
('_YAP_NOT_INSTALLED_', '1'),
('YAP_PYTHON', '1'),
('_GNU_SOURCE', '1')],
runtime_library_dirs=['yap4py', '${libdir}', '${bindir}'],
runtime_library_dirs=['yap4py', '${libdir}', '${bindir}', '${gmp_dir}', '${python_libdir}'],
swig_opts=['-modern', '-c++', '-py3',
'-DX_API', '-I${CMAKE_SOURCE_DIR}/CXX', '-I${CMAKE_SOURCE_DIR}/include',
'-I${CMAKE_SOURCE_DIR}/H', '-I${CMAKE_SOURCE_DIR}/H/generated',
'-I${CMAKE_SOURCE_DIR}/os', '-I${CMAKE_SOURCE_DIR}/OPTYap', '-I../../..'],
library_dirs=['../../..', '../../../CXX', '..', "${dlls}", "${bindir}", '.'],
extra_link_args=my_extra_link_args,
libraries=['Yap','${PYTHON_LIBRARIES}','${GMP_LIBRARIES}']+win_libs+local_libs,
libraries=['Yap','gmp']+win_libs+local_libs,
include_dirs=['../../..',
'${GMP_INCLUDE_DIRS}',
'${CMAKE_SOURCE_DIR}/H',

View File

@@ -36,7 +36,7 @@ class EngineArgs( YAPEngineArgs ):
def __init__(self, args=None,**kwargs):
super().__init__()
class Predicate( YAPPredicate ):
""" Interface to Generic Predicate"""
@@ -49,7 +49,7 @@ class Predicate:
else:
self.p = YAPPredicate( name, len(self) )
self.e = engine
def goals( self, engine):
self.e = engine
@@ -82,12 +82,12 @@ class PrologTableIter:
raise StopIteration()
class PrologPredicate( YAPPrologPredicate ):
""" Interface to Prolog Predicate"""
global engine, handler
yap_lib_path = os.path.dirname(__file__)
@@ -137,7 +137,7 @@ def answer(q):
return False
def query_prolog(engine, s):
import pdb; pdb.set_trace()
# import pdb; pdb.set_trace()
#
# construct a query from a one-line string
# q is opaque to Python
@@ -209,16 +209,8 @@ def live(**kwargs):
#
def boot_yap(**kwargs):
args = EngineArgs(**kwarg)
yap_lib_path = os.path.dirname(__file__)
args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
args.setYapLibDir(yap_lib_path)
args.setSavedState(os.path.join(yap_lib_path,"startup.yss"))
engine = YAPEngine(args)
engine.goal( set_prolog_flag('verbose', 'silent' ) )
engine.goal( use_module(library('yapi') ) )
return engine
return Engine(**kwargs)
if __name__ == "__main__":
engine = boot_yap()
handler = numbervars