3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-10-17 04:50:25 +00:00

More new OCaml API

This commit is contained in:
Christoph M. Wintersteiger 2016-02-14 19:56:22 +00:00
parent 824169da0a
commit b99fcb9c8a
6 changed files with 165 additions and 149 deletions

View file

@ -42,14 +42,14 @@ extern "C" {
CAMLxparam3(X6,X7,X8)
#define CAMLparam9(X1,X2,X3,X4,X5,X6,X7,X8,X9) \
CAMLparam5(X1,X2,X3,X4,X5); \
CAMLxparam4(X6,X7,X8,X9)
#define CAMLparam12(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12) \
CAMLparam5(X1,X2,X3,X4,X5); \
CAMLxparam5(X6,X7,X8,X9,X10); \
CAMLxparam4(X6,X7,X8,X9)
#define CAMLparam12(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12) \
CAMLparam5(X1,X2,X3,X4,X5); \
CAMLxparam5(X6,X7,X8,X9,X10); \
CAMLxparam2(X11,X12)
#define CAMLparam13(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13) \
CAMLparam5(X1,X2,X3,X4,X5); \
CAMLxparam5(X6,X7,X8,X9,X10); \
#define CAMLparam13(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13) \
CAMLparam5(X1,X2,X3,X4,X5); \
CAMLxparam5(X6,X7,X8,X9,X10); \
CAMLxparam3(X11,X12,X13)
@ -64,8 +64,15 @@ static struct custom_operations default_custom_ops = {
};
#define MK_CTX_OF(X) \
Z3_context_plus * n_context_of_ ## X(Z3_ ## X ## _plus * p) { return p->cp; }
#define MK_CTX_OF(X) \
CAMLprim DLL_PUBLIC value n_context_of_ ## X(value v) { \
CAMLparam1(v); \
CAMLlocal1(result); \
Z3_ ## X ## _plus * p = (Z3_ ## X ## _plus *) Data_custom_val(v); \
result = caml_alloc(sizeof(Z3_context_plus), 0); \
*(Z3_context_plus*)Data_custom_val(result) = *p->cp; \
CAMLreturn(result); \
}
// Context objects
@ -90,7 +97,10 @@ Z3_context Z3_context_plus_raw(Z3_context_plus * cp) {
void Z3_context_finalize(value v) {
Z3_context_plus * cp = (Z3_context_plus*)Data_custom_val(v);
printf("ctx--; cnt=%lu\n", cp->ast_count);
Z3_del_context(cp->ctx);
if (cp->ast_count == 0)
Z3_del_context(cp->ctx);
else
printf("Leaking the context; context_plus pointers now invalid. \n");
}
static struct custom_operations Z3_context_plus_custom_ops = {
@ -112,7 +122,7 @@ typedef struct {
} Z3_symbol_plus;
Z3_symbol_plus Z3_symbol_plus_mk(Z3_context_plus * cp, Z3_symbol s) {
Z3_symbol_plus r;
Z3_symbol_plus r;
r.cp = cp;
r.s = s;
return r;
@ -145,7 +155,7 @@ typedef struct {
Z3_ast_plus Z3_ast_plus_mk(Z3_context_plus * cp, Z3_ast a) {
Z3_ast_plus r;
r.cp = cp;
r.a = a;
r.a = a;
printf("++\n");
Z3_inc_ref(cp->ctx, a);
cp->ast_count++;
@ -207,6 +217,7 @@ static struct custom_operations Z3_ast_plus_custom_ops = {
MK_CTX_OF(ast)
// Constructor objects
typedef struct {
@ -300,39 +311,39 @@ static struct custom_operations Z3_rcf_num_plus_custom_ops = {
MK_CTX_OF(rcf_num)
#define MK_PLUS_OBJ(X) \
typedef struct { \
Z3_context_plus * cp; \
Z3_ ## X p; \
} Z3_ ## X ## _plus; \
\
#define MK_PLUS_OBJ(X) \
typedef struct { \
Z3_context_plus * cp; \
Z3_ ## X p; \
} Z3_ ## X ## _plus; \
\
Z3_ ## X ## _plus Z3_ ## X ## _plus_mk(Z3_context_plus * cp, Z3_ ## X p) { \
Z3_ ## X ## _plus r; \
r.cp = cp; \
r.p = p; \
Z3_ ## X ## _inc_ref(cp->ctx, p); \
return r; \
} \
\
Z3_ ## X Z3_ ## X ## _plus_raw(Z3_ ## X ## _plus * pp) { \
return pp->p; \
} \
\
void Z3_ ## X ## _finalize(value v) { \
Z3_ ## X ## _plus * pp = (Z3_ ## X ## _plus*)Data_custom_val(v); \
Z3_ ## X ## _dec_ref(pp->cp->ctx, pp->p); \
} \
\
static struct custom_operations Z3_ ## X ## _plus_custom_ops = { \
(char*) "Z3_" #X " ops", \
Z3_ ## X ## _finalize, \
custom_compare_default, \
custom_hash_default, \
custom_serialize_default, \
custom_deserialize_default, \
custom_compare_ext_default, \
}; \
\
Z3_ ## X ## _plus r; \
r.cp = cp; \
r.p = p; \
Z3_ ## X ## _inc_ref(cp->ctx, p); \
return r; \
} \
\
Z3_ ## X Z3_ ## X ## _plus_raw(Z3_ ## X ## _plus * pp) { \
return pp->p; \
} \
\
void Z3_ ## X ## _finalize(value v) { \
Z3_ ## X ## _plus * pp = (Z3_ ## X ## _plus*)Data_custom_val(v); \
Z3_ ## X ## _dec_ref(pp->cp->ctx, pp->p); \
} \
\
static struct custom_operations Z3_ ## X ## _plus_custom_ops = { \
(char*) "Z3_" #X " ops", \
Z3_ ## X ## _finalize, \
custom_compare_default, \
custom_hash_default, \
custom_serialize_default, \
custom_deserialize_default, \
custom_compare_ext_default, \
}; \
\
MK_CTX_OF(X)
MK_PLUS_OBJ(params)
@ -363,10 +374,9 @@ CAMLprim DLL_PUBLIC value n_is_null(value p) {
CAMLprim DLL_PUBLIC value n_mk_null( void ) {
CAMLparam0();
CAMLlocal1(result);
void * z3_result = 0;
result = caml_alloc_custom(&default_custom_ops, sizeof(void*), 0, 1);
memcpy( Data_custom_val(result), &z3_result, sizeof(void*));
CAMLlocal1(result);
result = caml_alloc(1, 0);
result = Val_int(0);
CAMLreturn (result);
}