This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/swig/yap.i

182 lines
3.1 KiB
OpenEdge ABL
Raw Normal View History

2014-04-28 11:57:09 +01:00
/* example.i */
2016-07-31 17:36:51 +01:00
%module(directors="1") yap
2014-04-28 11:57:09 +01:00
2016-07-31 17:36:51 +01:00
// Language independent exception handler
2015-04-13 13:28:17 +01:00
%include exception.i
2016-07-31 17:36:51 +01:00
%include stdint.i
%ignore *::operator[];
class YAPPredicate;
class YAPEngine;
#define arity_t uintptr_t
#ifdef SWIGPYTHON
2016-07-31 17:36:51 +01:00
%typemap(out) YAPTerm {
if ($1.handle() == 0) {
return NULL;
}
}
%extend(out) YAPTerm {
YAPTerm & __getitem__ (size_t i) {
Term t0 = $self->term();
if (IsApplTerm(t0)) {
Functor f = FunctorOfTerm(t0);
if (!IsExtensionFunctor(f))
return *new YAPTerm(ArgOfTerm(i + 1, t0));
} else if (IsPairTerm(t0)) {
if (i==0)
return * new YAPTerm(HeadOfTerm(t0));
else if (i==1)
return * new YAPTerm(TailOfTerm(t0));
}
return * new YAPTerm();
}
}
%typemap(out) YAPIntegerTerm {
Term t = $1.term();
Int j = IntegerOfTerm(t);
#if PY_MAJOR_VERSION < 3
return PyInt_FromLong(j);
#else
return PyLong_FromLong(j);
#endif
}
%typemap(out) YAPFloatTerm {
Term t = $1.term();
Int double j = FloatOfTerm(t);
return PyFloat_FromDouble(j);
}
// translate well-known names and existing
// Python symbols
// Everthing else let wrapped.
// as a term
%typemap(out) YAPAtomTerm {
const char *s = RepAtom(AtomOfTerm($1.term()))->StrOfAE;
PyObject *p;
if ((p = AtomToPy( s))) {
return p;
}
}
// translate lists as Python Lists
// Python symbols
// Everthing else let wrapped.
// as a term
%typemap(out) YAPListTerm {
Term l =$1.term(), *end;
PyObject *list;
Int len = Yap_SkipList( & l, &end );
$result = list = PyList_New( len );
for (Int i = 0 ; i < len ; i++) {
Term a = HeadOfTerm(l);
YAPTerm *argp1 = new YAPTerm( a );
PyObject *obj0 =
SWIG_NewPointerObj(SWIG_as_voidptr(argp1), SWIGTYPE_p_YAPTerm, 0 | 0 );
l = TailOfTerm(l);
PyList_SetItem( list, i, obj0 );
}
return list;
}
%exception YAPPredicate {
2016-07-31 17:36:51 +01:00
try {
$action
} catch (...) {
PyErr_SetString(PyExc_SyntaxError, "syntax error");
return NULL;
}
}
#endif
2016-07-31 17:36:51 +01:00
%exception query {
2016-07-31 17:36:51 +01:00
try {
$action
}
catch (YAPError YAP_SYMTAX_ERROR) {
SWIG_exception(SWIG_SyntaxError,"Syntax Error exception");
}
catch (...) {
SWIG_exception(SWIG_RuntimeError,"Unknown exception");
}
}
%exception next {
2016-07-31 17:36:51 +01:00
try {
$action
}
catch (...) {
SWIG_exception(SWIG_RuntimeError,"Unknown exception");
}
}
2016-07-31 17:36:51 +01:00
%{
/* Put header files here or function declarations like below */
2015-04-13 13:28:17 +01:00
2014-06-11 19:31:24 +01:00
#define YAP_CPP_INTERFACE 1
2015-04-13 13:28:17 +01:00
2014-04-29 11:49:09 +01:00
#include "yapi.hh"
2014-04-28 11:57:09 +01:00
2015-02-07 01:11:52 +00:00
extern "C" {
2014-06-11 19:31:24 +01:00
#if THREADS
#define Yap_regp regcache
#endif
2016-07-31 17:36:51 +01:00
// we cannot consult YapInterface.h, that conflicts with what we declare, though
// it shouldn't
}
2014-06-11 19:31:24 +01:00
2016-07-31 17:36:51 +01:00
%}
2015-04-13 13:28:17 +01:00
2014-06-11 19:31:24 +01:00
/* turn on director wrapping Callback */
%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"
%include "yapie.hh"
%include "yapt.hh"
%include "yapdb.hh"
%include "yapq.hh"
2014-06-22 17:35:05 +01:00
#ifdef SWIGJAVA
%javaexception("java.text.ParseException") YAPPredicate {
try {
2016-07-31 17:36:51 +01:00
$action
} catch (YAPError::SYNTAX_ERROR &e) {
2014-06-22 17:35:05 +01:00
jclass clazz = jenv->FindClass("java/text/ParseException");
jenv->ThrowNew(clazz, "Syntax error");
return $null;
2016-07-31 17:36:51 +01:00
}
}
#endif
%init %{
#ifdef SWIGPYTHON
init_python();
2014-06-22 17:35:05 +01:00
#endif
2016-07-31 17:36:51 +01:00
%}