2014-04-28 11:57:09 +01:00
|
|
|
/* example.i */
|
2016-09-21 20:29:31 +01:00
|
|
|
%module(directors = "1") yap
|
2014-04-28 11:57:09 +01:00
|
|
|
|
2016-12-10 07:01:10 +00:00
|
|
|
|
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
// Language independent exception handler
|
2016-09-27 18:28:54 +01:00
|
|
|
%include exception.i
|
2016-07-31 17:36:51 +01:00
|
|
|
%include stdint.i
|
|
|
|
|
|
|
|
|
2016-12-10 07:01:10 +00:00
|
|
|
%{
|
|
|
|
/* Put header files here or function declarations like below */
|
|
|
|
|
|
|
|
#define YAP_CPP_INTERFACE 1
|
|
|
|
|
|
|
|
#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
|
|
|
|
}
|
2016-07-31 17:36:51 +01:00
|
|
|
|
2016-12-10 07:01:10 +00:00
|
|
|
%}
|
2014-07-15 06:54:45 +01:00
|
|
|
|
|
|
|
#ifdef SWIGPYTHON
|
2016-07-31 17:36:51 +01:00
|
|
|
|
2016-12-10 07:01:10 +00:00
|
|
|
//include python/python.i
|
2016-09-21 20:29:31 +01:00
|
|
|
|
2016-07-31 17:36:51 +01:00
|
|
|
|
2016-09-27 18:28:54 +01:00
|
|
|
|
2016-12-10 07:01:10 +00:00
|
|
|
%inline %{
|
|
|
|
YAPTerm T(PyObject *input ) { return *new YAPTerm( pythonToYAP(input) ); }
|
|
|
|
%}
|
2016-09-27 18:28:54 +01:00
|
|
|
|
2016-12-10 07:01:10 +00:00
|
|
|
%typemap(in) YAPTerm { $1 = *new YAPTerm( pythonToYAP($input) ); }
|
2016-07-31 17:36:51 +01:00
|
|
|
|
2016-09-27 18:28:54 +01:00
|
|
|
|
2016-12-10 07:01:10 +00:00
|
|
|
%typemap(in) Term { $1 = pythonToYAP($input); }
|
2016-09-27 18:28:54 +01:00
|
|
|
|
|
|
|
|
2016-12-10 07:01:10 +00:00
|
|
|
%typemap(out) YAPTerm { return $result = yap_to_python($1.term(), false);}
|
|
|
|
%typemap(out) Term { return $result = yap_to_python($1, false);}
|
|
|
|
|
2014-07-15 06:54:45 +01:00
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
// Language independent exception handler
|
2016-07-31 17:36:51 +01:00
|
|
|
|
2016-09-23 03:53:42 +01:00
|
|
|
%exception next {
|
2016-07-31 17:36:51 +01:00
|
|
|
try {
|
|
|
|
$action
|
2016-09-23 03:53:42 +01:00
|
|
|
} catch (YAPError &e) {
|
|
|
|
yap_error_number en = e.getID();
|
|
|
|
PyObject *pyerr = PyExc_RuntimeError;
|
|
|
|
|
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
2016-09-21 20:29:31 +01:00
|
|
|
switch (e.getErrorClass()) {
|
|
|
|
case YAPC_NO_ERROR:
|
|
|
|
break;
|
2016-09-23 07:21:42 +01:00
|
|
|
/// bad domain, "first argument often is the predicate.
|
2016-09-21 20:29:31 +01:00
|
|
|
case DOMAIN_ERROR: {
|
|
|
|
switch (en) {
|
|
|
|
case DOMAIN_ERROR_OUT_OF_RANGE:
|
|
|
|
case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_IndexError;
|
2016-09-21 20:29:31 +01:00
|
|
|
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:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_KeyError;
|
2016-09-21 20:29:31 +01:00
|
|
|
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:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_IOError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_ValueError;
|
2016-07-31 17:36:51 +01:00
|
|
|
}
|
2016-09-21 20:29:31 +01:00
|
|
|
} break;
|
|
|
|
/// bad arithmetic
|
|
|
|
case EVALUATION_ERROR: {
|
|
|
|
switch (en) {
|
|
|
|
case EVALUATION_ERROR_FLOAT_OVERFLOW:
|
|
|
|
case EVALUATION_ERROR_INT_OVERFLOW:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_OverflowError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
case EVALUATION_ERROR_FLOAT_UNDERFLOW:
|
|
|
|
case EVALUATION_ERROR_UNDERFLOW:
|
|
|
|
case EVALUATION_ERROR_ZERO_DIVISOR:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_ArithmeticError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_RuntimeError;
|
2016-09-21 20:29:31 +01:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
/// missing object (I/O mostly)
|
|
|
|
case EXISTENCE_ERROR:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_NotImplementedError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
/// should be bound
|
|
|
|
case INSTANTIATION_ERROR_CLASS:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_RuntimeError;
|
2016-09-21 20:29:31 +01:00
|
|
|
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:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_OverflowError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_RuntimeError;
|
2016-09-21 20:29:31 +01:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
/// something that could not be represented into a type
|
|
|
|
case REPRESENTATION_ERROR:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_RuntimeError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
/// not enough ....
|
|
|
|
case RESOURCE_ERROR:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_RuntimeError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
/// bad text
|
|
|
|
case SYNTAX_ERROR_CLASS:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_SyntaxError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
/// OS or internal
|
|
|
|
case SYSTEM_ERROR_CLASS:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_RuntimeError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
/// bad typing
|
|
|
|
case TYPE_ERROR:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_TypeError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
/// should be unbound
|
|
|
|
case UNINSTANTIATION_ERROR_CLASS:
|
2016-09-23 03:53:42 +01:00
|
|
|
pyerr = PyExc_RuntimeError;
|
2016-09-21 20:29:31 +01:00
|
|
|
break;
|
|
|
|
/// escape hatch
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-09-23 03:53:42 +01:00
|
|
|
PyErr_SetString(pyerr, e.text());
|
2016-09-23 07:21:42 +01:00
|
|
|
}
|
2016-07-31 17:36:51 +01:00
|
|
|
}
|
2014-07-15 06:54:45 +01:00
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
#else
|
|
|
|
|
|
|
|
// Language independent exception handler
|
|
|
|
%include exception.i
|
|
|
|
|
|
|
|
%exception {
|
2016-07-31 17:36:51 +01:00
|
|
|
try {
|
|
|
|
$action
|
2016-09-21 20:29:31 +01:00
|
|
|
} catch (YAPError e) {
|
2016-09-23 03:53:42 +01:00
|
|
|
yap_error_number en = e.getID();
|
2016-09-27 18:28:54 +01:00
|
|
|
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
2016-09-21 20:29:31 +01:00
|
|
|
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:
|
|
|
|
case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
|
|
|
SWIG_exception(SWIG_IndexError, e.text());
|
|
|
|
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:
|
|
|
|
SWIG_exception(SWIG_AttributeError, e.text());
|
|
|
|
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:
|
|
|
|
SWIG_exception(SWIG_IOError, e.text());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SWIG_exception(SWIG_ValueError, e.text());
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
/// bad arithmetic
|
|
|
|
case EVALUATION_ERROR: {
|
|
|
|
switch (en) {
|
|
|
|
case EVALUATION_ERROR_FLOAT_OVERFLOW:
|
|
|
|
case EVALUATION_ERROR_FLOAT_UNDERFLOW:
|
|
|
|
case EVALUATION_ERROR_INT_OVERFLOW:
|
|
|
|
case EVALUATION_ERROR_UNDERFLOW:
|
|
|
|
SWIG_exception(SWIG_OverflowError, e.text());
|
|
|
|
break;
|
|
|
|
case EVALUATION_ERROR_ZERO_DIVISOR:
|
|
|
|
SWIG_exception(SWIG_DivisionByZero, e.text());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.text());
|
2016-07-31 17:36:51 +01:00
|
|
|
}
|
2016-09-21 20:29:31 +01:00
|
|
|
} break;
|
|
|
|
/// missing object (I/O mostly)
|
|
|
|
case EXISTENCE_ERROR:
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
|
|
break;
|
|
|
|
/// should be bound
|
|
|
|
case INSTANTIATION_ERROR_CLASS:
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
|
|
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:
|
|
|
|
SWIG_exception(SWIG_OverflowError, e.text());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
/// something that could not be represented into a type
|
|
|
|
case REPRESENTATION_ERROR:
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
|
|
break;
|
|
|
|
/// not enough ....
|
|
|
|
case RESOURCE_ERROR:
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
|
|
break;
|
|
|
|
/// bad text
|
|
|
|
case SYNTAX_ERROR_CLASS:
|
|
|
|
SWIG_exception(SWIG_SyntaxError, e.text());
|
|
|
|
break;
|
|
|
|
/// OS or internal
|
|
|
|
case SYSTEM_ERROR_CLASS:
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
|
|
break;
|
|
|
|
/// bad typing
|
|
|
|
case TYPE_ERROR:
|
|
|
|
SWIG_exception(SWIG_TypeError, e.text());
|
|
|
|
break;
|
|
|
|
/// should be unbound
|
|
|
|
case UNINSTANTIATION_ERROR_CLASS:
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
|
|
break;
|
|
|
|
/// escape hatch
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-07-31 17:36:51 +01:00
|
|
|
}
|
2014-07-15 06:54:45 +01:00
|
|
|
}
|
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
#endif
|
2014-07-15 06:54:45 +01:00
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
/* turn on director wrapping Callback */
|
2014-06-11 19:31:24 +01:00
|
|
|
%feature("director") YAPCallback;
|
2015-04-13 13:28:17 +01:00
|
|
|
|
2015-07-06 12:04:42 +01:00
|
|
|
// %include "yapi.hh"
|
2014-04-28 11:57:09 +01:00
|
|
|
|
2015-02-09 01:53:28 +00:00
|
|
|
%include "yapa.hh"
|
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
%include "yapie.hh"
|
2015-02-09 01:53:28 +00:00
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
%include "yapt.hh"
|
2016-07-31 17:36:51 +01:00
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
%include "yapdb.hh"
|
2016-07-31 17:36:51 +01:00
|
|
|
|
2016-09-21 20:29:31 +01:00
|
|
|
%include "yapq.hh"
|
2016-07-31 17:36:51 +01:00
|
|
|
|
|
|
|
%init %{
|
|
|
|
#ifdef SWIGPYTHON
|
|
|
|
init_python();
|
2014-06-22 17:35:05 +01:00
|
|
|
#endif
|
2016-09-21 20:29:31 +01:00
|
|
|
%}
|