This commit is contained in:
Vitor Santos Costa
2017-11-11 03:05:36 +00:00
43 changed files with 22761 additions and 126 deletions

View File

@@ -42,7 +42,7 @@ INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/i
# LIBRARY DESTINATION ${PYTHON_MODULE_PATH}
# )
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/yap4py)
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/yap4py)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py)
endif()

View File

@@ -0,0 +1,93 @@
<center>
![The YAP Logo](docs/icons/yap_128x128x32.png)
</center>
NOTE: this version of YAP is still experimental, documentation may be out of date.
## Introduction
This document provides User information on version 6.3.4 of
YAP (<em>Yet Another Prolog</em>). The YAP Prolog System is a
high-performance Prolog compiler developed at Universidade do
Porto. YAP supports stream Input/Output, sockets, modules,
exceptions, Prolog debugger, C-interface, dynamic code, internal
database, DCGs, saved states, co-routining, arrays, threads.
We explicitly allow both commercial and non-commercial use of YAP.
YAP is based on the David H. D. Warren's WAM (Warren Abstract Machine),
with several optimizations for better performance. YAP follows the
Edinburgh tradition, and was originally designed to be largely
compatible with DEC-10 Prolog, Quintus Prolog, and especially with
C-Prolog. More recently, we have worked on being compatible with SICStus Prolog and with SWI-Prolog.
YAP implements most of the ISO-Prolog standard. We are striving at
full compatibility, and the manual describes what is still
missing.
The document is intended neither as an introduction to Prolog nor to the
implementation aspects of the compiler. A good introduction to
programming in Prolog is the book @cite TheArtOfProlog , by
L. Sterling and E. Shapiro, published by "The MIT Press, Cambridge
MA". Other references should include the classical @cite ProgrammingInProlog , by W.F. Clocksin and C.S. Mellish, published by
Springer-Verlag.
YAP 6.3.4 has been built with the gcc and clang compilers on Linux and OSX machines. We expect to recover support for WIN32 machines and
Android next.
We are happy to include in YAP several excellent packages developed
under separate licenses. Our thanks to the authors for their kind
authorization to include these packages.
The overall copyright and permission notice for YAP4.3 can be found in
the Artistic file in this directory. YAP follows the Perl Artistic
license, and it is thus non-copylefted freeware. Some components of YAP have been obtained from SWI Prolog and ciao, and have
different licenses.
If you have a question about this software, desire to add code, found a
bug, want to request a feature, or wonder how to get further assistance,
please send e-mail to <yap-users AT lists.sourceforge.net>. To
subscribe to the mailing list, visit the page
<https://lists.sourceforge.net/lists/listinfo/yap-users>.
On-line documentation is available for [YAP](http://www.dcc.fp.pt/~vsc/yap/)
The packages are, in alphabetical order:
+ The CHR package developed by Tom Schrijvers,
Christian Holzbaur, and Jan Wielemaker.
+ The CLP(BN) package and Horus toolkit developed by Tiago Gomes, and Vítor Santos Costa.
+ The CLP(R) package developed by Leslie De Koninck, Bart Demoen, Tom
Schrijvers, and Jan Wielemaker, based on the CLP(Q,R) implementation
by Christian Holzbaur.
+ The CPLint package developed by Fabrizio Riguzzi's research
laboratory at the [University of Ferrara](http://www.ing.unife.it/Docenti/FabrizioRiguzzi/)
+ The CUDA interface package developed by Carlos Martínez, Jorge
Buenabad, Inês Dutra and Vítor Santos Costa.
+ The [GECODE](http://www.gecode.org) interface package developed by Denys Duchier and Vítor Santos Costa.
+ The [JPL](http://www.swi-prolog.org/packages/jpl/) (Java-Prolog Library) package developed by .
The minisat SAT solver interface developed by Michael Codish,
Vitaly Lagoon, and Peter J. Stuckey.
+ The MYDDAS relational data-base interface developed at the
Universidade do Porto by Tiago Soares, Michel Ferreira, and Ricardo Rocha.
+ The [PRISM](http://rjida.meijo-u.ac.jp/prism/) logic-based
programming system for statistical modeling developed at the Sato
Research Laboratory, TITECH, Japan.
+ The ProbLog 1 system developed by the [ProbLog](https://dtai.cs.kuleuven.be/problog) team in the
DTAI group of KULeuven.
+ The [R](http://stoics.org.uk/~nicos/sware/packs/real/) interface package developed by Nicos Angelopoulos,
Vítor Santos Costa, João Azevedo, Jan Wielemaker, and Rui Camacho.

View File

@@ -35,7 +35,8 @@ completions(S, Self) :-
strip_final_tokens(['EOT'|Ts], Ts) :- !.
strip_final_tokens( Ts, Ts ).|_],
strip_final_tokens( Ts, Ts ).
complete([E,l,C,l,A|More],
isconsult(A),
%B = l,
@@ -80,22 +81,22 @@ isconsult( '[' ).
arg([']'|_]).
arg([l|_]).
fileerrors-or_library(F,C) :-
file_or_library(F,C) :-
libsym(C0),
atom_cooncat(F,C,Co).
fileerrors-or_library(F,C) :-
file_or_library(F,C) :-
check_file(F0,C).
check_file(F0,C) :-
atom_concat('\'',F,F0),
!,
absolute_file_name( F, FF, [access(none)] ),
atom_concat( F, '*' , Pat),
atom_concat( FF, '*' , Pat),
absolute_file_name( Pat, C0, [glob(true)] ),
atom_concat(Pat,C00,C0),
atom_conct(C00,'\'',C).
check_file(F0,C) :-
atom_concat( F, '*' , Pat),
atom_concat( F0, '*' , Pat),
absolute_file_name( Pat, C0, [glob(true)] ),
atom_concat(Pat,C,C0).
@@ -116,7 +117,7 @@ predicate(N,P,A) :-
current_predicate(P0/A),
atom_concat(N,P,P0).
cont(0, F, P, P0)- :-
atom_concat( F, P, PB ).
cont(0, F, P, P0):-
atom_concat( F, P, P0 ).
cont( _, F, P, PB ):-
atom_concat( [F, P, '('], PB ).

View File

@@ -63,8 +63,12 @@ if platform.system() == 'Windows':
local_libs = []
win_libs = ['wsock32','ws2_32']
my_extra_link_args = ['-Wl,-export-all-symbols']
else:
my_extra_link_args = ['-Wl,-rpath','-Wl,${libdir}']
elif platform.system() == 'Darwin':
my_extra_link_args = ['-L','..']
win_libs = []
local_libs = ['Py4YAP']
elif platform.system() == 'Linux':
my_extra_link_args = ['-L','..']
win_libs = []
local_libs = ['Py4YAP']

666
packages/python/swig/yap.i Normal file
View File

@@ -0,0 +1,666 @@
// supports Java and Python
/* example.i */
%module(directors = "1") yap
// Language independent exception handler
%include exception.i
%include stdint.i
%include std_string.i
%include std_vector.i
%feature("novaluewrapper") std::vector<Term>;
%ignore *::operator[];
class YAPAtom;
class YAPPredicate;
class YAPEngine;
%{
#include <cmath>
#include <gmpxx.h>
extern "C"{
#include "Yap.h"
#ifdef SWIGPYTHON
#include <py4yap.h>
extern inline PyObject *AtomToPy(const char *s) {
if (strcmp(s, "true") == 0)
return Py_True;
if (strcmp(s, "false") == 0)
return Py_False;
if (strcmp(s, "none") == 0)
return Py_None;
if (strcmp(s, "[]") == 0)
return PyList_New(0);
else if (strcmp(s, "{}") == 0)
return PyDict_New();
/* return __main__,s */
else if (PyObject_HasAttrString(py_Main, s)) {
return PyObject_GetAttrString(py_Main, s);
}
// no way to translate
return NULL;
}
#endif
}
%}
#ifdef SWIGPYTHON
%typemap(typecheck) Term* {
$1 = PySequence_Check($input);
}
// Map a Python sequence into any sized C double array
%typemap(in) Term* {
int i;
if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_TypeError,"Expecting a sequence");
$1 = nullptr;
} else {
int sz = PyObject_Length($input);
std::vector<Term> v(sz);
for (i =0; i < sz; i++) {
PyObject *o = PySequence_GetItem($input,i);
v[i] = Term(pythonToYAP(o));
//Py_DECREF(o);
}
$1 = &v[0];
}
}
//%typemap(check) YAPEngine::fun(Term) { $1 = 1; }
//%typemap(check) YAPEngine::fun(YAPTerm) { $1 = 0; }
%typemap(in) Int { if (PyLong_Check($input)) {
$1 = PyLong_AsLong($input);}
}
//%typemap(in) double { if (PyFloat_Check($input)) {
// $1 = PyFloat_AsDouble($input); } }
//%typemap(in) char const * { if (PyUnicode_Check($input)) {
// $1 = PyUnicode_AsUTF8($input); } }
//%typemap(in) YAPTerm { $1 = new YAPTerm(pythonToYAP($input)); PyErr_Clear(); }
%typemap(in) YAP_Term { $1 = pythonToYAP($input); PyErr_Clear(); }
%typemap(in) Term { $1 = pythonToYAP($input); PyErr_Clear(); }
%typemap(in) YAPTerm { YAPTerm(($1 = pythonToYAP($input))); PyErr_Clear(); }
%typecheck(2) Int { $1 = PyLong_Check($input); }
%typecheck(3) double { $1 = PyFloat_Check($input); }
%typecheck(2) const char * { $1 = PyUnicode_Check($input); }
%typecheck(1) Term { $1 = !PyUnicode_Check($input); }
%typecheck(1) YAP_Term { $1 = PyUnicode_Check($input); }
%typecheck(0) YAPTerm { $1 = !PyUnicode_Check($input); }
%typemap(out) YAP_Term { return $result = yap_to_python($1, false, 0, true); }
%typemap(out) Term { return $result = yap_to_python($1, false, 0, true); }
%typemap(out) std::vector<Term> {
size_t len = $1.size();
$result = PyList_New(len);
for (size_t i = 0; i< len; i++) {
PyObject *o = yap_to_python($1[i],false,0,true);
PyList_SetItem($result,i,o);
}
return $result; }
// Language independent exception handler
%exception next {
try {
$action
} catch (YAPError &e) {
yap_error_number en = e.getID();
PyObject *pyerr = PyExc_RuntimeError;
LOCAL_Error_TYPE = YAP_NO_ERROR;
switch (e.getErrorClass()) {
case YAPC_NO_ERROR:
break;
/// bad domain, "first argument often is the predicate.
case DOMAIN_ERROR: {
switch (en) {
case DOMAIN_ERROR_OUT_OF_RANGE:
pyerr = PyExc_GeneratorExit;
break;
case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
pyerr = PyExc_IndexError;
break;
case DOMAIN_ERROR_CLOSE_OPTION:
case DOMAIN_ERROR_ENCODING:
case DOMAIN_ERROR_PROLOG_FLAG:
case DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION:
case DOMAIN_ERROR_READ_OPTION:
case DOMAIN_ERROR_SET_STREAM_OPTION:
pyerr = PyExc_KeyError;
break;
case DOMAIN_ERROR_FILE_ERRORS:
case DOMAIN_ERROR_FILE_TYPE:
case DOMAIN_ERROR_IO_MODE:
case DOMAIN_ERROR_SOURCE_SINK:
case DOMAIN_ERROR_STREAM_POSITION:
pyerr = PyExc_IOError;
break;
default:
pyerr = PyExc_ValueError;
}
} break;
/// bad arithmetic
case EVALUATION_ERROR: {
switch (en) {
case EVALUATION_ERROR_FLOAT_OVERFLOW:
case EVALUATION_ERROR_INT_OVERFLOW:
pyerr = PyExc_OverflowError;
break;
case EVALUATION_ERROR_FLOAT_UNDERFLOW:
case EVALUATION_ERROR_UNDERFLOW:
case EVALUATION_ERROR_ZERO_DIVISOR:
pyerr = PyExc_ArithmeticError;
break;
default:
pyerr = PyExc_RuntimeError;
}
} break;
/// missing object (I/O mostly)
case EXISTENCE_ERROR:
pyerr = PyExc_NotImplementedError;
break;
/// should be bound
case INSTANTIATION_ERROR_CLASS:
pyerr = PyExc_RuntimeError;
break;
/// bad access, I/O
case PERMISSION_ERROR: {
switch (en) {
case PERMISSION_ERROR_INPUT_BINARY_STREAM:
case PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM:
case PERMISSION_ERROR_INPUT_STREAM:
case PERMISSION_ERROR_INPUT_TEXT_STREAM:
case PERMISSION_ERROR_OPEN_SOURCE_SINK:
case PERMISSION_ERROR_OUTPUT_BINARY_STREAM:
case PERMISSION_ERROR_REPOSITION_STREAM:
case PERMISSION_ERROR_OUTPUT_STREAM:
case PERMISSION_ERROR_OUTPUT_TEXT_STREAM:
pyerr = PyExc_OverflowError;
break;
default:
pyerr = PyExc_RuntimeError;
}
} break;
/// something that could not be represented into a type
case REPRESENTATION_ERROR:
pyerr = PyExc_RuntimeError;
break;
/// not enough ....
case RESOURCE_ERROR:
pyerr = PyExc_RuntimeError;
break;
/// bad text
case SYNTAX_ERROR_CLASS:
pyerr = PyExc_SyntaxError;
break;
/// OS or internal
case SYSTEM_ERROR_CLASS:
pyerr = PyExc_RuntimeError;
break;
/// bad typing
case TYPE_ERROR:
pyerr = PyExc_TypeError;
break;
/// should be unbound
case UNINSTANTIATION_ERROR_CLASS:
pyerr = PyExc_RuntimeError;
break;
/// escape hatch
default:
break;
}
PyErr_SetString(pyerr, e.text().c_str());
}
}
#else
%typemap(in) arity_t { (jlong)($input); }
%typecheck(2) Int { $1 = PyLong_Check($input); }
%typecheck(3) double { $1 = PyFloat_Check($input); }
%typecheck(2) const char * { $1 = PyUnicode_Check($input); }
%typecheck(1) Term { $1 = !PyUnicode_Check($input); }
%typecheck(1) YAP_Term { $1 = PyUnicode_Check($input); }
%typecheck(0) YAPTerm { $1 = !PyUnicode_Check($input); }
%typemap(in) jlong %{
$1 = (jlong)$input;
%}
%typemap(out) arity_t { *(jlong *)&$result = $1; }
// Language independent exception handler
// simplified version
%include <exception.i>
%exception {
try {
$action
} catch (const std::out_of_range& e) {
SWIG_exception(SWIG_IndexError, e.what());
} catch (const std::exception& e) {
SWIG_exception(SWIG_RuntimeError, e.what());
} catch (...) {
SWIG_exception(SWIG_RuntimeError, "unknown exception");
}
}
#endif
%{
/* Put header files here or function declarations like below */
#include "yapi.hh"
extern "C" {
#if THREADS
#define Yap_regp regcache
#endif
// we cannot consult YapInterface.h, that conflicts with what we
// declare, though
// it shouldn't
}
extern void init_sqlite();
%}
#define X_API
/* turn on director wrapping Callback */
//%feature("director") YAPCallback;
%include "yapa.hh"
%include "yapie.hh"
%include "yapt.hh"
%include "yapdb.hh"
%include "yapq.hh"
namespace std {
%template(TermVector) vector<Term>;
%feature("novaluewrapper") vector<Term>;
//%template(YAPTermVector) vector<YAPTerm>;
//%feature("novaluewrapper") vector<YAPTerm>;
};
%init %{
%}