Newer
Older
#define __STDC_LIMIT_MACROS
#define __STDC_FORMAT_MACROS
#include <utility> // for pair
#include <vector>
extern "C" {
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/custom.h>
}
#include "GMLMIP-0.1/onestep.h"
//
using namespace std;
extern "C" {
CAMLprim value gmlRules_stub(value modalities);
}
template<class T>
value set2CamlList(const set<T>& vec, value (*f)(const T&)) {
for (typename set<T>::const_reverse_iterator it = vec.rbegin();
it != vec.rend();
++it)
{
Store_field( cons, 0, f(*it) ); // head
Store_field( cons, 1, cli ); // tail
static CAMLprim value pair2caml(const int& t) {
bool neg = t < 0;
Store_field( abc, 0, Val_int(neg ?(-t) : t));
Store_field( abc, 1, Val_bool(!neg));
static CAMLprim value set2caml(const set<int>& vt) {
return set2CamlList(vt, pair2caml);
static CAMLprim value setset2caml(const set<set<int> >& vt) {
return set2CamlList(vt, set2caml);
}
CAMLprim value gmlRules_stub(value modalities) {
// parse caml-modalities to a C++ vector
CAMLparam1( modalities );
value block = modalities;
vector<pair<pair<bool,int>,int> > modvec;
while (Is_block(block)) {
CAMLlocal3( vpos, vcnt, vformula );
vpos = Field(Field(block, 0), 0);
vcnt = Field(Field(block, 0), 1);
vformula = Field(Field(block, 0), 2);
modvec.push_back(make_pair(make_pair(
Bool_val(vpos),
Int_val(vcnt)),
Int_val(vformula)));
}
// Do one rule step and save result in rulevec
GMLConclusion rulevec = gmlmip_onestep_gml(modvec);
// convert rulevec into ocaml list of pairs
CAMLlocal1( res );
res = set2CamlList(rulevec, setset2caml);