1dnl  -*- C++ -*-
2m4_divert(-1)
3
4This m4 file contains the program implementation code for generating the
5files ppl_ocaml_DOMAIN.cc for each interface domain DOMAIN
6in ppl_interface instantiations.m4.
7
8dnl Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
9dnl Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
10dnl
11dnl This file is part of the Parma Polyhedra Library (PPL).
12dnl
13dnl The PPL is free software; you can redistribute it and/or modify it
14dnl under the terms of the GNU General Public License as published by the
15dnl Free Software Foundation; either version 3 of the License, or (at your
16dnl option) any later version.
17dnl
18dnl The PPL is distributed in the hope that it will be useful, but WITHOUT
19dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20dnl FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21dnl for more details.
22dnl
23dnl You should have received a copy of the GNU General Public License
24dnl along with this program; if not, write to the Free Software Foundation,
25dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
26dnl
27dnl For the most up-to-date information see the Parma Polyhedra Library
28dnl site: http://bugseng.com/products/ppl/ .
29
30dnl No code is needed for these procedure schemas in the OCaml interface.
31dnl
32m4_define(`ppl_delete_@CLASS@_code', `')
33m4_define(`ppl_delete_@CLASS@_iterator_code', `')
34
35dnl There is no code at present for these procedures in the OCaml interface.
36dnl Remove the macro if its definition is added.
37
38m4_define(`m4_custom_operations_class_code',
39`dnl
40
41namespace Parma_Polyhedra_Library {
42
43namespace Interfaces {
44
45namespace OCaml {
46
47struct custom_operations m4_current_interface`'_custom_operations = {
48  "com.bugseng.ppl" "." PPL_VERSION "." "m4_current_interface"|COMMA|
49  custom_`'m4_current_interface`'_finalize|COMMA|
50  custom_compare_default|COMMA|
51  custom_hash_default|COMMA|
52  custom_serialize_default|COMMA|
53  custom_deserialize_default|COMMA|
54  custom_compare_ext_default
55};
56
57} // namespace OCaml
58
59} // namespace Interfaces
60
61} // namespace Parma_Polyhedra_Library
62
63')
64
65m4_define(`ppl_new_@TOPOLOGY@@CLASS@_from_space_dimension_code',
66`dnl
67extern "C"
68CAMLprim value
69ppl_new_@TOPOLOGY@@CLASS@_from_space_dimension(value d, value caml_de) try {
70  CAMLparam2(d, caml_de);
71  const dimension_type dd = value_to_ppl_dimension(d);
72  const Degenerate_Element ppl_de = build_ppl_Degenerate_Element(caml_de);
73  @TOPOLOGY@@CPP_CLASS@& ppl_value = *new @TOPOLOGY@@CPP_CLASS@(dd, ppl_de);
74  CAMLreturn(unregistered_value_p_@CLASS@(ppl_value));
75}
76CATCH_ALL
77
78')
79
80m4_define(`ppl_new_@TOPOLOGY@@CLASS@_from_@BUILD_REPRESENT@s_code',
81`dnl
82extern "C"
83CAMLprim value
84ppl_new_@TOPOLOGY@@CLASS@_from_@BUILD_REPRESENT@s(value cl) try {
85  CAMLparam1(cl);
86  @!BUILD_REPRESENT@_System cs = build_ppl_@!BUILD_REPRESENT@_System(cl);
87  @TOPOLOGY@@CPP_CLASS@& ppl_value = *new @TOPOLOGY@@CPP_CLASS@(cs);
88  CAMLreturn(unregistered_value_p_@CLASS@(ppl_value));
89}
90CATCH_ALL
91
92')
93
94m4_define(`ppl_@CLASS@_relation_with_@RELATION_REPRESENT@_code',
95`dnl
96extern "C"
97CAMLprim value
98ppl_@CLASS@_relation_with_@RELATION_REPRESENT@(value ph, value c) try {
99  CAMLparam2(ph, c);
100  const @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
101  @!RELATION_REPRESENT@ ppl_c = build_ppl_@!RELATION_REPRESENT@(c);
102  Poly_@!A_RELATION_REPRESENT@_Relation r = pph.relation_with(ppl_c);
103  CAMLreturn(build_ocaml_poly_@A_RELATION_REPRESENT@_relation(r));
104}
105CATCH_ALL
106
107')
108
109m4_define(`ppl_@CLASS@_@DIMENSION@_code',
110`dnl
111extern "C"
112CAMLprim value
113ppl_@CLASS@_@DIMENSION@(value ph) try {
114  CAMLparam1(ph);
115  const @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
116  dimension_type d = pph.@DIMENSION@();
117  CAMLreturn(ppl_dimension_to_value(d));
118}
119CATCH_ALL
120
121')
122
123m4_define(`ppl_@CLASS@_@HAS_PROPERTY@_code',
124`dnl
125extern "C"
126CAMLprim value
127ppl_@CLASS@_@HAS_PROPERTY@(value ph) try {
128  CAMLparam1(ph);
129  const @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
130  CAMLreturn(Val_bool(pph.@HAS_PROPERTY@()));
131}
132CATCH_ALL
133
134')
135
136m4_define(`ppl_@CLASS@_@SIMPLIFY@_code',
137`dnl
138extern "C"
139CAMLprim value
140ppl_@CLASS@_@SIMPLIFY@(value ph) try {
141  CAMLparam1(ph);
142  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
143  pph.@SIMPLIFY@();
144  CAMLreturn(Val_unit);
145}
146CATCH_ALL
147
148')
149
150m4_define(`ppl_@CLASS@_bounds_from_@ABOVEBELOW@_code',
151`dnl
152extern "C"
153CAMLprim value
154ppl_@CLASS@_bounds_from_@ABOVEBELOW@(value ph, value le) try {
155  CAMLparam2(ph, le);
156  const @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
157  Linear_Expression ple = build_ppl_Linear_Expression(le);
158  CAMLreturn(Val_bool(pph.bounds_from_@ABOVEBELOW@(ple)));
159}
160CATCH_ALL
161
162')
163
164m4_define(`ppl_@CLASS@_add_@CLASS_REPRESENT@_code',
165`dnl
166extern "C"
167CAMLprim value
168ppl_@CLASS@_add_@CLASS_REPRESENT@(value ph, value c) try {
169  CAMLparam2(ph, c);
170  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
171  @!CLASS_REPRESENT@ pc = build_ppl_@!CLASS_REPRESENT@(c);
172  pph.add_@CLASS_REPRESENT@(pc);
173  CAMLreturn(Val_unit);
174}
175CATCH_ALL
176
177')
178
179m4_define(`ppl_@CLASS@_add_@CLASS_REPRESENT@s_code',
180`dnl
181extern "C"
182CAMLprim value
183ppl_@CLASS@_add_@CLASS_REPRESENT@s(value ph, value cs) try {
184  CAMLparam2(ph, cs);
185  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
186  @!CLASS_REPRESENT@_System pcs = build_ppl_@!CLASS_REPRESENT@_System(cs);
187  pph.add_@CLASS_REPRESENT@s(pcs);
188  CAMLreturn(Val_unit);
189}
190CATCH_ALL
191
192')
193
194m4_define(`ppl_@CLASS@_refine_with_@REFINE_REPRESENT@_code',
195`dnl
196extern "C"
197CAMLprim value
198ppl_@CLASS@_refine_with_@REFINE_REPRESENT@(value ph, value c) try {
199  CAMLparam2(ph, c);
200  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
201  @!REFINE_REPRESENT@ pc = build_ppl_@!REFINE_REPRESENT@(c);
202  pph.refine_with_@REFINE_REPRESENT@(pc);
203  CAMLreturn(Val_unit);
204}
205CATCH_ALL
206
207')
208
209m4_define(`ppl_@CLASS@_refine_with_@REFINE_REPRESENT@s_code',
210`dnl
211extern "C"
212CAMLprim value
213ppl_@CLASS@_refine_with_@REFINE_REPRESENT@s(value ph, value cs) try {
214  CAMLparam2(ph, cs);
215  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
216  @!REFINE_REPRESENT@_System pcs = build_ppl_@!REFINE_REPRESENT@_System(cs);
217  pph.refine_with_@REFINE_REPRESENT@s(pcs);
218  CAMLreturn(Val_unit);
219}
220CATCH_ALL
221
222')
223
224m4_define(`ppl_@CLASS@_@COMPARISON@_@CLASS@_code',
225`dnl
226extern "C"
227CAMLprim value
228ppl_@CLASS@_@COMPARISON@_@CLASS@(value ph1, value ph2) try {
229  CAMLparam2(ph1, ph2);
230  const @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
231  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
232  CAMLreturn(Val_bool(pph1.@COMPARISON@(pph2)));
233}
234CATCH_ALL
235
236')
237
238m4_define(`ppl_@CLASS@_equals_@CLASS@_code',
239`dnl
240extern "C"
241CAMLprim value
242ppl_@CLASS@_equals_@CLASS@(value ph1, value ph2) try {
243  CAMLparam2(ph1, ph2);
244  const @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
245  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
246  CAMLreturn(Val_bool(pph1 == pph2));
247}
248CATCH_ALL
249
250')
251
252m4_define(`ppl_@CLASS@_@BINOP@_code',
253`dnl
254extern "C"
255CAMLprim value
256ppl_@CLASS@_@BINOP@(value ph1, value ph2) try {
257  CAMLparam2(ph1, ph2);
258  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
259  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
260  pph1.@BINOP@(pph2);
261  CAMLreturn(Val_unit);
262}
263CATCH_ALL
264
265')
266
267m4_define(`ppl_@CLASS@_positive_time_elapse_assign_code',
268`dnl
269extern "C"
270CAMLprim value
271ppl_@CLASS@_positive_time_elapse_assign(value ph1, value ph2) try {
272  CAMLparam2(ph1, ph2);
273  if (Interfaces::is_necessarily_closed_for_interfaces
274        (*p_Polyhedron_val(ph1))) {
275    C_Polyhedron& xx
276      = static_cast<C_Polyhedron&>(*p_Polyhedron_val(ph1));
277    const C_Polyhedron& yy
278      = static_cast<const C_Polyhedron&>(*p_Polyhedron_val(ph2));
279    xx.positive_time_elapse_assign(yy);
280  }
281  else {
282    NNC_Polyhedron& xx
283      = static_cast<NNC_Polyhedron&>(*p_Polyhedron_val(ph1));
284    const NNC_Polyhedron& yy
285      = static_cast<const NNC_Polyhedron&>(*p_Polyhedron_val(ph2));
286    xx.positive_time_elapse_assign(yy);
287  }
288  CAMLreturn(Val_unit);
289}
290CATCH_ALL
291
292')
293
294m4_define(`ppl_@CLASS@_simplify_using_context_assign_code',
295`dnl
296extern "C"
297CAMLprim value
298ppl_@CLASS@_simplify_using_context_assign(value ph1, value ph2) try {
299  CAMLparam2(ph1, ph2);
300  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
301  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
302  CAMLreturn(Val_bool(pph1.simplify_using_context_assign(pph2)));
303}
304CATCH_ALL
305
306')
307
308m4_define(`ppl_@CLASS@_add_space_dimensions_@EMBEDPROJECT@_code',
309`dnl
310extern "C"
311CAMLprim value
312ppl_@CLASS@_add_space_dimensions_@EMBEDPROJECT@
313(value ph, value d) try {
314  CAMLparam2(ph, d);
315  const dimension_type dd = value_to_ppl_dimension(d);
316  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
317  pph.add_space_dimensions_and_embed(dd);
318  CAMLreturn(Val_unit);
319}
320CATCH_ALL
321
322')
323
324m4_define(`ppl_@CLASS@_remove_space_dimensions_code',
325`dnl
326extern "C"
327CAMLprim value
328ppl_@CLASS@_remove_space_dimensions(value ph, value caml_vset) try {
329  CAMLparam2(ph, caml_vset);
330  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
331  pph.remove_space_dimensions(build_ppl_Variables_Set(caml_vset));
332  CAMLreturn(Val_unit);
333}
334CATCH_ALL
335
336')
337
338m4_define(`ppl_@CLASS@_remove_higher_space_dimensions_code',
339`dnl
340extern "C"
341CAMLprim value
342ppl_@CLASS@_remove_higher_space_dimensions(value ph, value d) try {
343  CAMLparam2(ph, d);
344  const dimension_type dd = value_to_ppl_dimension(d);
345  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
346  pph.remove_higher_space_dimensions(dd);
347  CAMLreturn(Val_unit);
348}
349CATCH_ALL
350
351')
352
353m4_define(`ppl_@CLASS@_fold_space_dimensions_code',
354`dnl
355extern "C"
356CAMLprim value
357ppl_@CLASS@_fold_space_dimensions
358(value ph, value caml_vset, value caml_dim) try {
359  CAMLparam1(ph);
360  const dimension_type ppl_dim = Int_val(caml_dim);
361  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
362  Variables_Set ppl_vset;
363  if (Int_val(caml_vset) == 0)
364    CAMLreturn(Val_unit);
365  while (true) {
366    ppl_vset.insert(Int_val(Field(caml_vset, 0)));
367    if (Int_val(Field(caml_vset, 1)) == 0)
368      break;
369    caml_vset = Field(caml_vset, 1);
370  }
371  pph.fold_space_dimensions(ppl_vset, Variable(ppl_dim));
372  CAMLreturn(Val_unit);
373}
374CATCH_ALL
375
376')
377
378m4_define(`ppl_@CLASS@_map_space_dimensions_code',
379`dnl
380extern "C"
381CAMLprim value
382ppl_@CLASS@_map_space_dimensions(value ph, value caml_mapped_dims) try {
383  CAMLparam2(ph, caml_mapped_dims);
384  CAMLlocal1(head);
385  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
386  Partial_Function pfunc;
387  while (caml_mapped_dims != Val_emptylist) {
388    head = Field(caml_mapped_dims, 0);
389    const dimension_type domain_dim = value_to_ppl_dimension(Field(head, 0));
390    const dimension_type codomain_dim = value_to_ppl_dimension(Field(head, 1));
391    pfunc.insert(domain_dim, codomain_dim);
392    caml_mapped_dims = Field(caml_mapped_dims, 1);
393  }
394  pph.map_space_dimensions(pfunc);
395  CAMLreturn(Val_unit);
396}
397CATCH_ALL
398
399')
400
401
402m4_define(`ppl_@CLASS@_expand_space_dimension_code',
403`dnl
404extern "C"
405CAMLprim value
406ppl_@CLASS@_expand_space_dimension
407(value ph, value var_index, value m) try {
408  CAMLparam3(ph, var_index, m);
409  const Variable var = build_ppl_Variable(var_index);
410  const dimension_type c_m = value_to_ppl_dimension(m);
411  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
412  pph.expand_space_dimension(var, c_m);
413  CAMLreturn(Val_unit);
414}
415CATCH_ALL
416
417')
418
419m4_define(`ppl_@CLASS@_drop_some_non_integer_points_code',
420`dnl
421extern "C"
422CAMLprim value
423ppl_@CLASS@_drop_some_non_integer_points
424(value ph, value caml_cc) try {
425  CAMLparam1(ph);
426  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
427  const Complexity_Class ppl_cc = build_ppl_Complexity_Class(caml_cc);
428  pph.drop_some_non_integer_points(ppl_cc);
429  CAMLreturn(Val_unit);
430}
431CATCH_ALL
432
433')
434
435m4_define(`ppl_@CLASS@_drop_some_non_integer_points_2_code',
436`dnl
437extern "C"
438CAMLprim value
439ppl_@CLASS@_drop_some_non_integer_points_2
440(value ph, value caml_vset, value caml_cc) try {
441  CAMLparam1(ph);
442  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
443  Variables_Set ppl_vset;
444  if (Int_val(caml_vset) == 0)
445    CAMLreturn(Val_unit);
446  while (true) {
447    ppl_vset.insert(Int_val(Field(caml_vset, 0)));
448    if (Int_val(Field(caml_vset, 1)) == 0)
449      break;
450    caml_vset = Field(caml_vset, 1);
451  }
452  const Complexity_Class ppl_cc = build_ppl_Complexity_Class(caml_cc);
453  pph.drop_some_non_integer_points(ppl_vset, ppl_cc);
454  CAMLreturn(Val_unit);
455}
456CATCH_ALL
457
458')
459
460m4_define(`ppl_@CLASS@_get_@CLASS_REPRESENT@s_code',
461`dnl
462extern "C"
463CAMLprim value
464ppl_@CLASS@_get_@CLASS_REPRESENT@s(value ph) try {
465  CAMLparam1(ph);
466  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
467  CAMLreturn(build_ocaml_@CLASS_REPRESENT@_system(pph.@CLASS_REPRESENT@s()));
468}
469CATCH_ALL
470
471')
472
473m4_define(`ppl_@CLASS@_get_minimized_@CLASS_REPRESENT@s_code',
474`dnl
475extern "C"
476CAMLprim value
477ppl_@CLASS@_get_minimized_@CLASS_REPRESENT@s(value ph) try {
478  CAMLparam1(ph);
479  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
480  CAMLreturn(build_ocaml_@CLASS_REPRESENT@_system(pph.minimized_@CLASS_REPRESENT@s()));
481}
482CATCH_ALL
483
484')
485
486m4_define(`ppl_@CLASS@_constrains_code',
487`dnl
488extern "C"
489CAMLprim value
490ppl_@CLASS@_constrains(value ph, value var) try {
491  CAMLparam2(ph, var);
492  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
493  CAMLreturn(Val_bool(pph.constrains(build_ppl_Variable(var))));
494}
495CATCH_ALL
496
497')
498
499m4_define(`ppl_@CLASS@_unconstrain_space_dimension_code',
500`dnl
501extern "C"
502CAMLprim value
503ppl_@CLASS@_unconstrain_space_dimension(value ph, value var) try {
504  CAMLparam2(ph, var);
505  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
506  pph.unconstrain(build_ppl_Variable(var));
507  CAMLreturn(Val_unit);
508}
509CATCH_ALL
510
511')
512
513m4_define(`ppl_@CLASS@_unconstrain_space_dimensions_code',
514`dnl
515extern "C"
516CAMLprim value
517ppl_@CLASS@_unconstrain_space_dimensions(value ph, value caml_vset) try {
518  CAMLparam2(ph, caml_vset);
519  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
520  pph.unconstrain(build_ppl_Variables_Set(caml_vset));
521  CAMLreturn(Val_unit);
522}
523CATCH_ALL
524
525')
526
527m4_define(`ppl_@CLASS@_bounded_@AFFIMAGE@_code',
528`dnl
529extern "C"
530CAMLprim value
531ppl_@CLASS@_bounded_@AFFIMAGE@(value ph, value var, value lb_expr,
532				    value ub_expr, value coeff) try {
533  CAMLparam5(ph, var, lb_expr, ub_expr, coeff);
534  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
535  pph.bounded_@AFFIMAGE@(build_ppl_Variable(var),
536			   build_ppl_Linear_Expression(lb_expr),
537 			   build_ppl_Linear_Expression(ub_expr),
538 			   build_ppl_Coefficient(coeff));
539  CAMLreturn(Val_unit);
540}
541CATCH_ALL
542
543')
544
545m4_define(`ppl_@CLASS@_@AFFIMAGE@_code',
546`dnl
547extern "C"
548CAMLprim value
549ppl_@CLASS@_@AFFIMAGE@
550(value ph, value var, value expr, value coeff) try {
551  CAMLparam4(ph, var, expr, coeff);
552  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
553  build_ppl_Linear_Expression(expr);
554  pph.@AFFIMAGE@(build_ppl_Variable(var),
555		   build_ppl_Linear_Expression(expr),
556		   build_ppl_Coefficient(coeff));
557  CAMLreturn(Val_unit);
558}
559CATCH_ALL
560
561')
562
563m4_define(`ppl_@CLASS@_generalized_@AFFIMAGE@_lhs_rhs_code',
564`dnl
565extern "C"
566CAMLprim value
567ppl_@CLASS@_generalized_@AFFIMAGE@1
568(value ph, value le1, value rel_sym, value le2) try {
569  CAMLparam4(ph, le1, rel_sym, le2);
570  build_ppl_relsym(rel_sym);
571  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
572  pph.generalized_@AFFIMAGE@(build_ppl_Linear_Expression(le1),
573			       build_ppl_relsym(rel_sym),
574			       build_ppl_Linear_Expression(le2));
575  CAMLreturn(Val_unit);
576}
577CATCH_ALL
578
579')
580
581m4_define(`ppl_@CLASS@_generalized_@AFFIMAGE@_code',
582`dnl
583extern "C"
584CAMLprim value
585ppl_@CLASS@_generalized_@AFFIMAGE@2
586(value ph, value int_val, value rel_sym, value le, value caml_coeff) try {
587  CAMLparam5(ph, int_val, rel_sym, le, caml_coeff);
588  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
589  pph.generalized_@AFFIMAGE@(build_ppl_Variable(int_val),
590			       build_ppl_relsym(rel_sym),
591			       build_ppl_Linear_Expression(le),
592			       build_ppl_Coefficient(caml_coeff));
593  CAMLreturn(Val_unit);
594}
595CATCH_ALL
596
597')
598
599m4_define(`ppl_@CLASS@_generalized_@AFFIMAGE@_with_congruence_code',
600`dnl
601extern "C"
602CAMLprim value
603ppl_@CLASS@_generalized_@AFFIMAGE@1_with_congruence
604(value ph, value int_val, value rel_sym, value le,
605 value caml_coeff, value caml_modulus) try {
606  CAMLparam5(ph, int_val, rel_sym, le, caml_coeff);
607  CAMLxparam1(caml_modulus);
608  build_ppl_relsym(rel_sym);
609  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
610  pph.generalized_@AFFIMAGE@(build_ppl_Variable(int_val),
611			       build_ppl_relsym(rel_sym),
612			       build_ppl_Linear_Expression(le),
613			       build_ppl_Coefficient(caml_coeff),
614			       build_ppl_Coefficient(caml_modulus));
615  CAMLreturn(Val_unit);
616}
617CATCH_ALL
618
619extern "C"
620CAMLprim value
621ppl_@CLASS@_generalized_@AFFIMAGE@1_with_congruence_bytecode
622(value* argv, int /*argn*/) try {
623  return ppl_@CLASS@_generalized_@AFFIMAGE@1_with_congruence
624    (argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
625}
626CATCH_ALL
627
628')
629
630m4_define(`ppl_@CLASS@_generalized_@AFFIMAGE@_lhs_rhs_with_congruence_code',
631`dnl
632extern "C"
633CAMLprim value
634ppl_@CLASS@_generalized_@AFFIMAGE@1_lhs_rhs_with_congruence
635(value ph, value le1, value rel_sym, value le2, value caml_modulus) try {
636  CAMLparam5(ph, le1, rel_sym, le2, caml_modulus);
637  build_ppl_relsym(rel_sym);
638  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
639  pph.generalized_@AFFIMAGE@(build_ppl_Linear_Expression(le1),
640			     build_ppl_relsym(rel_sym),
641			     build_ppl_Linear_Expression(le2),
642			     build_ppl_Coefficient(caml_modulus));
643  CAMLreturn(Val_unit);
644}
645CATCH_ALL
646
647')
648
649m4_define(`ppl_@CLASS@_@WIDEN@_widening_assign_code',
650`dnl
651extern "C"
652CAMLprim value
653ppl_@CLASS@_@WIDEN@_widening_assign(value ph1, value ph2) try {
654  CAMLparam2(ph1, ph2);
655  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
656  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
657  pph1.@WIDEN@_widening_assign(pph2);
658  CAMLreturn(Val_unit);
659}
660CATCH_ALL
661
662')
663
664
665m4_define(`ppl_@CLASS@_@WIDEN@_widening_assign_with_tokens_code',
666`dnl
667extern "C"
668CAMLprim value
669ppl_@CLASS@_@WIDEN@_widening_assign_with_tokens
670(value ph1, value ph2, value tokens) try {
671  CAMLparam3(ph1, ph2, tokens);
672  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
673  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
674  unsigned u_tokens = value_to_unsigned<unsigned>(tokens);
675  pph1.@WIDEN@_widening_assign(pph2, &u_tokens);
676  CAMLreturn(Val_long(u_tokens));
677}
678CATCH_ALL
679
680')
681
682m4_define(`ppl_@CLASS@_widening_assign_code',
683`dnl
684extern "C"
685CAMLprim value
686ppl_@CLASS@_widening_assign(value ph1, value ph2) try {
687  CAMLparam2(ph1, ph2);
688  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
689  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
690  pph1.widening_assign(pph2);
691  CAMLreturn(Val_unit);
692}
693CATCH_ALL
694
695')
696
697m4_define(`ppl_@CLASS@_widening_assign_with_tokens_code',
698`dnl
699extern "C"
700CAMLprim value
701ppl_@CLASS@_widening_assign_with_tokens
702(value ph1, value ph2, value tokens) try {
703  CAMLparam3(ph1, ph2, tokens);
704  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
705  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
706  unsigned u_tokens = value_to_unsigned<unsigned>(tokens);
707  pph1.widening_assign(pph2, &u_tokens);
708  CAMLreturn(Val_long(u_tokens));
709}
710CATCH_ALL
711
712')
713
714m4_define(`ppl_@CLASS@_@LIMITEDBOUNDED@_@WIDENEXPN@_extrapolation_assign_with_tokens_code',
715`dnl
716extern "C"
717CAMLprim value
718ppl_@CLASS@_@LIMITEDBOUNDED@_@WIDENEXPN@_extrapolation_assign_with_tokens
719(value ph1, value ph2, value caml_cs, value tokens) try {
720  CAMLparam4(ph1, ph2, caml_cs, tokens);
721  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
722  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
723  const @!CONSTRAINER@_System ppl_cs = build_ppl_@!CONSTRAINER@_System(caml_cs);
724  unsigned u_tokens = value_to_unsigned<unsigned>(tokens);
725  pph1.@LIMITEDBOUNDED@_@WIDENEXPN@_extrapolation_assign(pph2, ppl_cs,
726							 &u_tokens);
727  CAMLreturn(Val_long(u_tokens));
728}
729CATCH_ALL
730
731')
732
733m4_define(`ppl_@CLASS@_@LIMITEDBOUNDED@_@WIDENEXPN@_extrapolation_assign_code',
734`dnl
735extern "C"
736CAMLprim value
737ppl_@CLASS@_@LIMITEDBOUNDED@_@WIDENEXPN@_extrapolation_assign(value ph1,
738						   value ph2,
739						   value caml_cs) try {
740  CAMLparam3(ph1, ph2, caml_cs);
741  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
742  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
743  const @!CONSTRAINER@_System ppl_cs = build_ppl_@!CONSTRAINER@_System(caml_cs);
744  pph1.@LIMITEDBOUNDED@_@WIDENEXPN@_extrapolation_assign(pph2, ppl_cs);
745  CAMLreturn(Val_unit);
746}
747CATCH_ALL
748
749')
750
751m4_define(`ppl_@CLASS@_has_@UPPERLOWER@_bound_code',
752`dnl
753extern "C"
754CAMLprim value
755ppl_@CLASS@_has_@UPPERLOWER@_bound(value ph, value var) try {
756  CAMLparam2(ph, var);
757  CAMLlocal1(caml_return_value);
758  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
759  Variable vv = build_ppl_Variable(var);
760  PPL_DIRTY_TEMP_COEFFICIENT(num);
761  PPL_DIRTY_TEMP_COEFFICIENT(den);
762  bool is_closed = false;
763  bool ppl_return_value = pph.has_@UPPERLOWER@_bound(vv, num, den, is_closed);
764  caml_return_value = caml_alloc(4, 0);
765  Store_field(caml_return_value, 0, Val_bool(ppl_return_value));
766  Store_field(caml_return_value, 1, build_ocaml_coefficient(num));
767  Store_field(caml_return_value, 2, build_ocaml_coefficient(den));
768  Store_field(caml_return_value, 3, Val_bool(is_closed));
769  CAMLreturn(caml_return_value);
770}
771CATCH_ALL
772
773')
774
775m4_define(`ppl_@CLASS@_@MAXMIN@_code',
776`dnl
777extern "C"
778CAMLprim value
779ppl_@CLASS@_@MAXMIN@(value ph, value caml_le) try {
780  CAMLparam2(ph, caml_le);
781  CAMLlocal1(caml_return_value);
782  PPL_DIRTY_TEMP_COEFFICIENT(num);
783  PPL_DIRTY_TEMP_COEFFICIENT(den);
784  bool is_supremum = false;
785  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
786  bool ppl_return_value = pph.@MAXMIN@(build_ppl_Linear_Expression(caml_le),
787				      num, den, is_supremum);
788  caml_return_value = caml_alloc(4, 0);
789  Store_field(caml_return_value, 0, Val_bool(ppl_return_value));
790  Store_field(caml_return_value, 1, build_ocaml_coefficient(num));
791  Store_field(caml_return_value, 2, build_ocaml_coefficient(den));
792  Store_field(caml_return_value, 3, Val_bool(is_supremum));
793  CAMLreturn(caml_return_value);
794}
795CATCH_ALL
796
797')
798
799m4_define(`ppl_@CLASS@_@MAXMIN@_with_point_code',
800`dnl
801extern "C"
802CAMLprim value
803ppl_@CLASS@_@MAXMIN@_with_point(value ph, value caml_le) try {
804  CAMLparam2(ph, caml_le);
805  CAMLlocal1(caml_return_value);
806  PPL_DIRTY_TEMP_COEFFICIENT(num);
807  PPL_DIRTY_TEMP_COEFFICIENT(den);
808  bool is_supremum = false;
809  Generator g = point();
810  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
811  bool ppl_return_value = pph.@MAXMIN@(build_ppl_Linear_Expression(caml_le),
812				      num, den, is_supremum, g);
813  caml_return_value = caml_alloc(5, 0);
814  Store_field(caml_return_value, 0, Val_bool(ppl_return_value));
815  Store_field(caml_return_value, 1, build_ocaml_coefficient(num));
816  Store_field(caml_return_value, 2, build_ocaml_coefficient(den));
817  Store_field(caml_return_value, 3, Val_bool(is_supremum));
818  Store_field(caml_return_value, 4, build_ocaml_generator(g));
819  CAMLreturn(caml_return_value);
820}
821CATCH_ALL
822
823')
824
825m4_define(`ppl_@CLASS@_frequency_code',
826`dnl
827extern "C"
828CAMLprim value
829ppl_@CLASS@_frequency(value ph, value caml_le) try {
830  CAMLparam2(ph, caml_le);
831  CAMLlocal1(caml_return_value);
832  PPL_DIRTY_TEMP_COEFFICIENT(f_num);
833  PPL_DIRTY_TEMP_COEFFICIENT(f_den);
834  PPL_DIRTY_TEMP_COEFFICIENT(v_num);
835  PPL_DIRTY_TEMP_COEFFICIENT(v_den);
836  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
837  bool ppl_return_value = pph.frequency(build_ppl_Linear_Expression(caml_le),
838				        f_num, f_den, v_num, v_den);
839  caml_return_value = caml_alloc(5, 0);
840  Store_field(caml_return_value, 0, Val_bool(ppl_return_value));
841  Store_field(caml_return_value, 1, build_ocaml_coefficient(f_num));
842  Store_field(caml_return_value, 2, build_ocaml_coefficient(f_den));
843  Store_field(caml_return_value, 3, build_ocaml_coefficient(v_num));
844  Store_field(caml_return_value, 4, build_ocaml_coefficient(v_den));
845  CAMLreturn(caml_return_value);
846}
847CATCH_ALL
848
849')
850
851m4_define(`ppl_@CLASS@_OK_code',
852`dnl
853extern "C"
854CAMLprim value
855ppl_@CLASS@_OK(value ph) try {
856  CAMLparam1(ph);
857  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
858  CAMLreturn(Val_bool(pph.OK()));
859}
860CATCH_ALL
861
862')
863
864m4_define(`ppl_@CLASS@_@MEMBYTES@_code',
865`dnl
866extern "C"
867CAMLprim value
868ppl_@CLASS@_@MEMBYTES@(value ph) try {
869  CAMLparam1(ph);
870  const @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
871  CAMLreturn(Val_long(pph.@MEMBYTES@()));
872}
873CATCH_ALL
874
875 ')
876
877m4_define(`ppl_@CLASS@_swap_code',
878`dnl
879extern "C"
880CAMLprim value
881ppl_@CLASS@_swap(value ph1, value ph2) try {
882  CAMLparam2(ph1, ph2);
883  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
884  @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
885  swap(pph1, pph2);
886  CAMLreturn(Val_unit);
887}
888CATCH_ALL
889
890')
891
892m4_define(`ppl_new_@TOPOLOGY@@CLASS@_from_@FRIEND@_code',
893`dnl
894extern "C"
895CAMLprim value
896ppl_new_@TOPOLOGY@@CLASS@_from_@FRIEND@(value ph) try {
897  CAMLparam1(ph);
898  @B_FRIEND@& pph = *(reinterpret_cast<@B_FRIEND@*>(p_@A_FRIEND@_val(ph)));
899  const @CPP_CLASS@& ppl_value
900    = *(reinterpret_cast<@CPP_CLASS@*>(new @TOPOLOGY@@CPP_CLASS@(pph)));
901  CAMLreturn(unregistered_value_p_@CLASS@(ppl_value));
902}
903CATCH_ALL
904
905')
906
907m4_define(`ppl_new_@TOPOLOGY@@CLASS@_from_@FRIEND@_with_complexity_code',
908`dnl
909extern "C"
910CAMLprim value
911ppl_new_@TOPOLOGY@@CLASS@_from_@FRIEND@_with_complexity(value ph, value caml_cc) try {
912  CAMLparam1(ph);
913  @B_FRIEND@& pph = *(reinterpret_cast<@B_FRIEND@*>( p_@A_FRIEND@_val(ph)));
914  const Complexity_Class ppl_cc = build_ppl_Complexity_Class(caml_cc);
915  @CPP_CLASS@& ppl_value
916    = *(reinterpret_cast<@CPP_CLASS@*>(new @TOPOLOGY@@CPP_CLASS@(pph, ppl_cc)));
917  CAMLreturn(unregistered_value_p_@CLASS@(ppl_value));
918}
919CATCH_ALL
920
921')
922
923
924m4_define(`ppl_@CLASS@_@UB_EXACT@_code',
925`dnl
926extern "C"
927CAMLprim value
928ppl_@CLASS@_@UB_EXACT@(value ph1, value ph2) try {
929  CAMLparam2(ph1, ph2);
930`m4_ifelse(m4_current_interface, `Polyhedron',
931          `m4_ub_exact_for_polyhedron_domains',
932          `m4_ub_exact_for_non_polyhedron_domains')'dnl
933}
934CATCH_ALL
935
936')
937
938m4_define(`m4_ub_exact_for_polyhedron_domains',
939`dnl
940  if (Interfaces::is_necessarily_closed_for_interfaces
941        (*p_Polyhedron_val(ph1))) {
942    C_Polyhedron& xx
943      = static_cast<C_Polyhedron&>(*p_Polyhedron_val(ph1));
944    const C_Polyhedron& yy
945      = static_cast<const C_Polyhedron&>(*p_Polyhedron_val(ph2));
946    CAMLreturn(Val_bool(xx.upper_bound_assign_if_exact(yy)));
947  }
948  else {
949    NNC_Polyhedron& xx
950      = static_cast<NNC_Polyhedron&>(*p_Polyhedron_val(ph1));
951    const NNC_Polyhedron& yy
952      = static_cast<const NNC_Polyhedron&>(*p_Polyhedron_val(ph2));
953    CAMLreturn(Val_bool(xx.upper_bound_assign_if_exact(yy)));
954  }
955')
956
957m4_define(`m4_ub_exact_for_non_polyhedron_domains',
958`dnl
959  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
960  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
961
962  CAMLreturn(Val_bool(pph1.@UB_EXACT@(pph2)));
963')
964
965m4_define(`ppl_@CLASS@_@EXTRAPOLATION@_extrapolation_assign_code',
966`dnl
967extern "C"
968CAMLprim value
969ppl_@CLASS@_@EXTRAPOLATION@_extrapolation_assign
970(value ph1, value ph2) try {
971  CAMLparam2(ph1, ph2);
972  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
973  @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
974  pph1.@EXTRAPOLATION@_extrapolation_assign(pph2);
975  CAMLreturn(Val_unit);
976}
977CATCH_ALL
978
979')
980
981
982m4_define(`ppl_@CLASS@_@EXTRAPOLATION@_extrapolation_assign_with_tokens_code',
983`dnl
984extern "C"
985CAMLprim value
986ppl_@CLASS@_@EXTRAPOLATION@_extrapolation_assign_with_tokens
987(value ph1, value ph2, value tokens) try {
988  CAMLparam3(ph1, ph2, tokens);
989  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
990  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
991  unsigned u_tokens = value_to_unsigned<unsigned>(tokens);
992  pph1.@EXTRAPOLATION@_extrapolation_assign(pph2, &u_tokens);
993  CAMLreturn(Val_long(u_tokens));
994}
995CATCH_ALL
996
997')
998
999m4_define(`ppl_@CLASS@_@EXTRAPOLATION@_narrowing_assign_code',
1000`dnl
1001extern "C"
1002CAMLprim value
1003ppl_@CLASS@_@EXTRAPOLATION@_narrowing_assign(value ph1,
1004                                                       value ph2) try {
1005  CAMLparam2(ph1, ph2);
1006  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
1007  const @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
1008  pph1.@EXTRAPOLATION@_narrowing_assign(pph2);
1009  CAMLreturn(Val_unit);
1010}
1011CATCH_ALL
1012
1013')
1014
1015m4_define(`ppl_@CLASS@_@BEGINEND@_iterator_code',
1016`dnl
1017extern "C"
1018CAMLprim value
1019ppl_@CLASS@_@BEGINEND@_iterator(value t_pps) try {
1020  CAMLparam1(t_pps);
1021  @CPP_CLASS@& pps = *p_@CLASS@_val(t_pps);
1022  @CPP_CLASS@::iterator& ppl_value
1023    = *new @CPP_CLASS@::iterator(pps.@BEGINEND@());
1024  CAMLreturn(unregistered_value_p_@CLASS@_iterator(ppl_value));
1025}
1026CATCH_ALL
1027
1028')
1029
1030
1031m4_define(`ppl_@CLASS@_get_disjunct_code',
1032`dnl
1033extern "C"
1034CAMLprim value
1035ppl_@CLASS@_get_disjunct(value caml_it) try {
1036  CAMLparam1(caml_it);
1037  CAMLlocal1(caml_return_value);
1038  @CPP_CLASS@::iterator& cpp_it  = *p_@CLASS@_iterator_val(caml_it);
1039  const @DISJUNCT_TOPOLOGY@@A_DISJUNCT@& disjunct = cpp_it->pointset();
1040  caml_return_value = unregistered_value_p_@DISJUNCT@(disjunct);
1041  actual_p_@DISJUNCT@_val(caml_return_value)
1042    = const_cast<@DISJUNCT_TOPOLOGY@@A_DISJUNCT@*>(mark(&disjunct));
1043  CAMLreturn(caml_return_value);
1044}
1045CATCH_ALL
1046
1047')
1048
1049m4_define(`ppl_@CLASS@_add_disjunct_code',
1050`dnl
1051extern "C"
1052CAMLprim value
1053ppl_@CLASS@_add_disjunct(value t_pps, value caml_item_to_add) try {
1054  CAMLparam2(t_pps, caml_item_to_add);
1055  @CPP_CLASS@& pps = *p_@CLASS@_val(t_pps);
1056  @DISJUNCT_TOPOLOGY@@A_DISJUNCT@& item
1057    = *(reinterpret_cast<@DISJUNCT_TOPOLOGY@@A_DISJUNCT@*>
1058          (p_@DISJUNCT@_val(caml_item_to_add)));
1059  pps.add_disjunct(item);
1060  CAMLreturn(Val_unit);
1061}
1062CATCH_ALL
1063
1064')
1065
1066m4_define(`ppl_@CLASS@_drop_disjunct_code',
1067`dnl
1068extern "C"
1069CAMLprim value
1070ppl_@CLASS@_drop_disjunct(value t_pps, value caml_item_to_drop) try {
1071  CAMLparam2(t_pps, caml_item_to_drop);
1072  @CPP_CLASS@& pps = *p_@CLASS@_val(t_pps);
1073  @CPP_CLASS@::iterator& itr = *p_@CLASS@_iterator_val(caml_item_to_drop);
1074  itr = pps.drop_disjunct(itr);
1075  CAMLreturn(Val_unit);
1076}
1077CATCH_ALL
1078
1079')
1080
1081m4_define(`ppl_@CLASS@_drop_disjuncts_code',
1082`dnl
1083extern "C"
1084CAMLprim value
1085ppl_@CLASS@_drop_disjuncts
1086(value t_pps, value caml_item1_to_drop, value caml_item2_to_drop) try {
1087  CAMLparam3(t_pps, caml_item1_to_drop, caml_item2_to_drop);
1088  @CPP_CLASS@& pps = *p_@CLASS@_val(t_pps);
1089  @CPP_CLASS@::iterator& itr1 = *p_@CLASS@_iterator_val(caml_item1_to_drop);
1090  @CPP_CLASS@::iterator& itr2 = *p_@CLASS@_iterator_val(caml_item2_to_drop);
1091  pps.drop_disjuncts(itr1, itr2);
1092  CAMLreturn(Val_unit);
1093}
1094CATCH_ALL
1095
1096')
1097
1098m4_define(`ppl_new_@CLASS@_iterator_from_iterator_code',
1099`dnl
1100//! Give access to the embedded @CLASS@* in \p v.
1101inline @CPP_CLASS@::iterator*&
1102p_@CLASS@_iterator_val(value v) {
1103  return *reinterpret_cast<@CPP_CLASS@::iterator**>(Data_custom_val(v));
1104}
1105
1106void
1107custom_@CLASS@_iterator_finalize(value v) {
1108  delete p_@CLASS@_iterator_val(v);
1109}
1110
1111struct custom_operations @CLASS@_iterator_custom_operations = {
1112  "com.bugseng.ppl" "." PPL_VERSION "." "@CLASS@_iterator"|COMMA|
1113  custom_@CLASS@_iterator_finalize|COMMA|
1114  custom_compare_default|COMMA|
1115  custom_hash_default|COMMA|
1116  custom_serialize_default|COMMA|
1117  custom_deserialize_default|COMMA|
1118  custom_compare_ext_default
1119};
1120
1121inline value
1122unregistered_value_p_@CLASS@_iterator(const @CPP_CLASS@::iterator& ph) {
1123  value v = caml_alloc_custom(&@CLASS@_iterator_custom_operations,
1124                              sizeof(@CPP_CLASS@::iterator*), 0, 1);
1125  p_@CLASS@_iterator_val(v) = const_cast<@CPP_CLASS@::iterator*>(&ph);
1126  return v;
1127}
1128
1129extern "C"
1130CAMLprim value
1131ppl_new_@CLASS@_iterator_from_iterator(value y) try {
1132  CAMLparam1(y);
1133  @CPP_CLASS@::iterator& yy
1134    = *(reinterpret_cast<@CPP_CLASS@::iterator*>( p_@CLASS@_iterator_val(y)));
1135  @CPP_CLASS@::iterator& ppl_value
1136    = *(reinterpret_cast<@CPP_CLASS@::iterator*>(new @CPP_CLASS@::iterator(yy)));
1137  CAMLreturn(unregistered_value_p_@CLASS@_iterator(ppl_value));
1138}
1139CATCH_ALL
1140
1141')
1142
1143m4_define(`ppl_@CLASS@_@INCDEC@_iterator_code',
1144`dnl
1145extern "C"
1146CAMLprim value
1147ppl_@CLASS@_@INCDEC@_iterator(value caml_itr) try {
1148  CAMLparam1(caml_itr);
1149  @CPP_CLASS@::iterator& itr = *p_@CLASS@_iterator_val(caml_itr);
1150  m4_@INCDEC@_cpp_name()itr;
1151  CAMLreturn(Val_unit);
1152}
1153CATCH_ALL
1154
1155')
1156
1157m4_define(`m4_increment_cpp_name', `++')
1158m4_define(`m4_decrement_cpp_name', `--')
1159
1160m4_define(`ppl_@CLASS@_iterator_equals_iterator_code',
1161`dnl
1162extern "C"
1163CAMLprim value
1164ppl_@CLASS@_iterator_equals_iterator(value caml_itr1, value caml_itr2) try {
1165  CAMLparam2(caml_itr1, caml_itr2);
1166  @CPP_CLASS@::iterator& itr1 = *p_@CLASS@_iterator_val(caml_itr1);
1167  @CPP_CLASS@::iterator& itr2 = *p_@CLASS@_iterator_val(caml_itr2);
1168  if (itr1 == itr2)
1169    CAMLreturn(Val_bool(true));
1170  else
1171    CAMLreturn(Val_bool(false));
1172}
1173CATCH_ALL
1174
1175')
1176
1177
1178m4_define(`ppl_@CLASS@_BHZ03_@A_DISJUNCT_WIDEN@_@DISJUNCT_WIDEN@_widening_assign_code',
1179`dnl
1180extern "C"
1181CAMLprim value
1182ppl_@CLASS@_BHZ03_@A_DISJUNCT_WIDEN@_@DISJUNCT_WIDEN@_widening_assign
1183(value ph1, value ph2) try {
1184  CAMLparam2(ph1, ph2);
1185  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
1186  @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
1187  pph1.BHZ03_widening_assign<@A_DISJUNCT_WIDEN@_Certificate>
1188    (pph2,
1189     widen_fun_ref(&@DISJUNCT_TOPOLOGY@@A_DISJUNCT@::@DISJUNCT_WIDEN@_widening_assign));;
1190  CAMLreturn(Val_unit);
1191}
1192CATCH_ALL
1193
1194')
1195
1196m4_define(`ppl_@CLASS@_BGP99_@DISJUNCT_WIDEN@_extrapolation_assign_code',
1197`dnl
1198extern "C"
1199CAMLprim value
1200ppl_@CLASS@_BGP99_@DISJUNCT_WIDEN@_extrapolation_assign
1201(value ph1, value ph2, value max_disj) try {
1202  CAMLparam2(ph1, ph2);
1203  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
1204  @CPP_CLASS@& pph2 = *p_@CLASS@_val(ph2);
1205  unsigned cpp_max_disj
1206    = value_to_unsigned<unsigned>(max_disj);
1207  pph1.BGP99_extrapolation_assign
1208    (pph2,
1209     widen_fun_ref(&@DISJUNCT_TOPOLOGY@@A_DISJUNCT@::@DISJUNCT_WIDEN@_widening_assign),
1210     cpp_max_disj);
1211  CAMLreturn(Val_unit);
1212}
1213CATCH_ALL
1214
1215')
1216
1217
1218m4_define(`ppl_@CLASS@_ascii_dump_code',
1219`dnl
1220extern "C"
1221CAMLprim value
1222ppl_@CLASS@_ascii_dump(value ph1) try {
1223  CAMLparam1(ph1);
1224  @CPP_CLASS@& pph1 = *p_@CLASS@_val(ph1);
1225  std::ostringstream s;
1226  pph1.ascii_dump(s);
1227  CAMLreturn(caml_copy_string(s.str().c_str()));
1228}
1229CATCH_ALL
1230
1231')
1232
1233
1234m4_define(`ppl_@CLASS@_linear_@PARTITION@_code', `
1235extern "C"
1236CAMLprim value
1237ppl_@CLASS@_linear_@PARTITION@(value ph1, value ph2) try {
1238  CAMLparam2(ph1, ph2);
1239  CAMLlocal1(caml_return_value);
1240  @CPP_CLASS@* rfh;
1241  Pointset_Powerset<NNC_Polyhedron>* rsh;
1242`m4_ifelse(m4_current_interface, `Polyhedron',
1243           `m4_linear_partition_for_polyhedron_domains',
1244           `m4_linear_partition_for_non_polyhedron_domains')'dnl
1245  caml_return_value = caml_alloc(2, 0);
1246  Store_field(caml_return_value, 0,
1247              unregistered_value_p_@CLASS@(*rfh));
1248  Store_field(caml_return_value, 1,
1249              unregistered_value_p_Pointset_Powerset_NNC_Polyhedron(*rsh));
1250  CAMLreturn(caml_return_value);
1251}
1252CATCH_ALL
1253
1254')
1255
1256m4_define(`m4_linear_partition_for_polyhedron_domains',
1257`dnl
1258  if (Interfaces::is_necessarily_closed_for_interfaces
1259       (*p_Polyhedron_val(ph1))) {
1260    C_Polyhedron& pph1
1261      = reinterpret_cast<C_Polyhedron&>(*p_Polyhedron_val(ph1));
1262    C_Polyhedron& pph2
1263      = reinterpret_cast<C_Polyhedron&>(*p_Polyhedron_val(ph2));
1264    std::pair<C_Polyhedron|COMMA| Pointset_Powerset<NNC_Polyhedron> >
1265      r = linear_partition(pph1, pph2);
1266    rfh = new C_Polyhedron(0, EMPTY);
1267    rsh = new Pointset_Powerset<NNC_Polyhedron>(0, EMPTY);
1268    swap(*rfh, r.first);
1269    swap(*rsh, r.second);
1270  }
1271  else {
1272    NNC_Polyhedron& pph1
1273      = reinterpret_cast<NNC_Polyhedron&>(*p_Polyhedron_val(ph1));
1274    NNC_Polyhedron& pph2
1275      = reinterpret_cast<NNC_Polyhedron&>(*p_Polyhedron_val(ph2));
1276    std::pair<NNC_Polyhedron|COMMA| Pointset_Powerset<NNC_Polyhedron> >
1277      r = linear_partition(pph1, pph2);
1278    rfh = new NNC_Polyhedron(0, EMPTY);
1279    rsh = new Pointset_Powerset<NNC_Polyhedron>(0, EMPTY);
1280    swap(*rfh, r.first);
1281    swap(*rsh, r.second);
1282  }
1283')
1284
1285m4_define(`m4_linear_partition_for_non_polyhedron_domains',
1286`dnl
1287  @CPP_CLASS@& pph1
1288    = reinterpret_cast<@CPP_CLASS@&>(*p_@CLASS@_val(ph1));
1289  @CPP_CLASS@& pph2
1290    = reinterpret_cast<@CPP_CLASS@&>(*p_@CLASS@_val(ph2));
1291  std::pair<@CPP_CLASS@|COMMA| Pointset_Powerset<NNC_Polyhedron> >
1292    r = linear_partition(pph1, pph2);
1293  rfh = new @CPP_CLASS@(0, EMPTY);
1294  rsh = new Pointset_Powerset<NNC_Polyhedron>(0, EMPTY);
1295  swap(*rfh, r.first);
1296  swap(*rsh, r.second);
1297')
1298
1299m4_define(`ppl_@CLASS@_approximate_@PARTITION@_code', `
1300extern "C"
1301CAMLprim value
1302ppl_@CLASS@_approximate_@PARTITION@(value ph1, value ph2) try {
1303  CAMLparam2(ph1, ph2);
1304  CAMLlocal1(caml_return_value);
1305  @CPP_CLASS@& pph1
1306    = reinterpret_cast<@CPP_CLASS@&>(*p_@CPP_CLASS@_val(ph1));
1307  @CPP_CLASS@& pph2
1308    = reinterpret_cast<@CPP_CLASS@&>(*p_@CPP_CLASS@_val(ph2));
1309  bool is_finite = false;
1310  std::pair<@CPP_CLASS@|COMMA| Pointset_Powerset<Grid> >
1311    r = approximate_partition(pph1, pph2, is_finite);
1312  @CPP_CLASS@* rfh = new @CPP_CLASS@(0, EMPTY);
1313  Pointset_Powerset<Grid>* rsh = new Pointset_Powerset<Grid>(0, EMPTY);
1314  swap(*rfh, r.first);
1315  swap(*rsh, r.second);
1316  caml_return_value = caml_alloc(3, 0);
1317  Store_field(caml_return_value, 0,
1318              unregistered_value_p_@CLASS@(*rfh));
1319  Store_field(caml_return_value, 1,
1320              unregistered_value_p_Pointset_Powerset_Grid(*rsh));
1321  Store_field(caml_return_value, 2, Val_bool(is_finite));
1322  CAMLreturn(caml_return_value);
1323}
1324CATCH_ALL
1325
1326')
1327
1328m4_define(`ppl_termination_test_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_code',
1329`dnl
1330extern "C"
1331CAMLprim value
1332ppl_termination_test_@TERMINATION_ID@_@TOPOLOGY@@CLASS@(value pset) try {
1333  CAMLparam1(pset);
1334  const @TOPOLOGY@@CPP_CLASS@& ppset
1335     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset)));
1336  CAMLreturn(Val_bool(termination_test_@TERMINATION_ID@(ppset)));
1337}
1338CATCH_ALL
1339
1340')
1341
1342m4_define(`ppl_termination_test_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_2_code',
1343`dnl
1344extern "C"
1345CAMLprim value
1346  ppl_termination_test_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_2(value pset_before,
1347                                                            value pset_after)
1348  try {
1349    CAMLparam2(pset_before, pset_after);
1350  const @TOPOLOGY@@CPP_CLASS@& ppset_before
1351     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset_before)));
1352  const @TOPOLOGY@@CPP_CLASS@& ppset_after
1353     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset_after)));
1354  CAMLreturn(Val_bool(termination_test_@TERMINATION_ID@_2(ppset_before,
1355                                                          ppset_after)));
1356}
1357CATCH_ALL
1358
1359')
1360
1361m4_define(`ppl_one_affine_ranking_function_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_code',
1362`dnl
1363extern "C"
1364CAMLprim value
1365  ppl_one_affine_ranking_function_@TERMINATION_ID@_@TOPOLOGY@@CLASS@
1366    (value pset)
1367  try {
1368    CAMLparam1(pset);
1369    CAMLlocal1(caml_return_value);
1370  const @TOPOLOGY@@CPP_CLASS@& ppset
1371     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset)));
1372  Generator g(point());
1373  bool ppl_return_value = one_affine_ranking_function_@TERMINATION_ID@
1374    (ppset, g);
1375  caml_return_value = caml_alloc(2, 0);
1376  Store_field(caml_return_value, 0, Val_bool(ppl_return_value));
1377  Store_field(caml_return_value, 1, build_ocaml_generator(g));
1378  CAMLreturn(caml_return_value);
1379}
1380CATCH_ALL
1381
1382')
1383
1384m4_define(`ppl_one_affine_ranking_function_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_2_code',
1385`dnl
1386extern "C"
1387CAMLprim value
1388  ppl_one_affine_ranking_function_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_2
1389  (value pset_before, value pset_after)
1390  try {
1391    CAMLparam2(pset_before, pset_after);
1392    CAMLlocal1(caml_return_value);
1393  const @TOPOLOGY@@CPP_CLASS@& ppset_before
1394     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset_before)));
1395  const @TOPOLOGY@@CPP_CLASS@& ppset_after
1396     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset_after)));
1397  Generator g(point());
1398  bool ppl_return_value = one_affine_ranking_function_@TERMINATION_ID@_2
1399    (ppset_before, ppset_after, g);
1400  caml_return_value = caml_alloc(2, 0);
1401  Store_field(caml_return_value, 0, Val_bool(ppl_return_value));
1402  Store_field(caml_return_value, 1, build_ocaml_generator(g));
1403  CAMLreturn(caml_return_value);
1404}
1405CATCH_ALL
1406
1407')
1408
1409m4_define(`ppl_all_affine_ranking_functions_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_code',
1410`dnl
1411extern "C"
1412CAMLprim value
1413  ppl_all_affine_ranking_functions_@TERMINATION_ID@_@TOPOLOGY@@CLASS@
1414  (value pset)
1415  try {
1416    CAMLparam1(pset);
1417    CAMLlocal1(caml_return_value);
1418  const @TOPOLOGY@@CPP_CLASS@& ppset
1419     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset)));
1420  @A_TERMINATION_ID@Polyhedron* ph = new @A_TERMINATION_ID@Polyhedron();
1421  all_affine_ranking_functions_@TERMINATION_ID@(ppset, *ph);
1422  CAMLreturn(unregistered_value_p_Polyhedron(*ph));
1423}
1424CATCH_ALL
1425
1426')
1427
1428m4_define(`ppl_all_affine_ranking_functions_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_2_code',
1429`dnl
1430extern "C"
1431CAMLprim value
1432  ppl_all_affine_ranking_functions_@TERMINATION_ID@_@TOPOLOGY@@CLASS@_2
1433  (value pset_before, value pset_after)
1434  try {
1435    CAMLparam2(pset_before, pset_after);
1436    CAMLlocal1(caml_return_value);
1437  const @TOPOLOGY@@CPP_CLASS@& ppset_before
1438     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset_before)));
1439  const @TOPOLOGY@@CPP_CLASS@& ppset_after
1440     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset_after)));
1441  @A_TERMINATION_ID@Polyhedron* ph = new @A_TERMINATION_ID@Polyhedron();
1442  all_affine_ranking_functions_@TERMINATION_ID@_2(ppset_before, ppset_after, *ph);
1443  CAMLreturn(unregistered_value_p_Polyhedron(*ph));
1444}
1445CATCH_ALL
1446
1447')
1448
1449m4_define(`ppl_all_affine_quasi_ranking_functions_MS_@TOPOLOGY@@CLASS@_code',
1450`dnl
1451extern "C"
1452CAMLprim value
1453  ppl_all_affine_quasi_ranking_functions_MS_@TOPOLOGY@@CLASS@
1454  (value pset)
1455  try {
1456    CAMLparam1(pset);
1457    CAMLlocal1(caml_return_value);
1458  const @TOPOLOGY@@CPP_CLASS@& ppset
1459     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset)));
1460  C_Polyhedron* ph_decreasing = new C_Polyhedron();
1461  C_Polyhedron* ph_bounded = new C_Polyhedron();
1462  all_affine_quasi_ranking_functions_MS(ppset, *ph_decreasing, *ph_bounded);
1463  caml_return_value = caml_alloc(2, 0);
1464  Store_field(caml_return_value, 0,
1465              unregistered_value_p_Polyhedron(*ph_decreasing));
1466  Store_field(caml_return_value, 1,
1467              unregistered_value_p_Polyhedron(*ph_bounded));
1468  CAMLreturn(caml_return_value);
1469}
1470CATCH_ALL
1471
1472')
1473
1474m4_define(`ppl_all_affine_quasi_ranking_functions_MS_@TOPOLOGY@@CLASS@_2_code',
1475`dnl
1476extern "C"
1477CAMLprim value
1478  ppl_all_affine_quasi_ranking_functions_MS_@TOPOLOGY@@CLASS@_2
1479  (value pset_before, value pset_after)
1480  try {
1481    CAMLparam2(pset_before, pset_after);
1482    CAMLlocal1(caml_return_value);
1483  const @TOPOLOGY@@CPP_CLASS@& ppset_before
1484     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset_before)));
1485  const @TOPOLOGY@@CPP_CLASS@& ppset_after
1486     = *(reinterpret_cast<@TOPOLOGY@@CPP_CLASS@*>(p_@CLASS@_val(pset_after)));
1487  C_Polyhedron* ph_decreasing = new C_Polyhedron();
1488  C_Polyhedron* ph_bounded = new C_Polyhedron();
1489  all_affine_quasi_ranking_functions_MS_2(ppset_before, ppset_after,
1490                                          *ph_decreasing, *ph_bounded);
1491  caml_return_value = caml_alloc(2, 0);
1492  Store_field(caml_return_value, 0,
1493              unregistered_value_p_Polyhedron(*ph_decreasing));
1494  Store_field(caml_return_value, 1,
1495              unregistered_value_p_Polyhedron(*ph_bounded));
1496  CAMLreturn(caml_return_value);
1497}
1498CATCH_ALL
1499
1500')
1501
1502m4_define(`ppl_@CLASS@_wrap_assign_code',
1503`dnl
1504extern "C"
1505CAMLprim value
1506ppl_@CLASS@_wrap_assign_native
1507  (value ph, value caml_vset, value width, value rep, value oflow,
1508   value cs, value complexity, value wrap_ind) try {
1509  CAMLparam5(ph, caml_vset, width, rep, oflow);
1510  CAMLxparam3(cs, complexity, wrap_ind);
1511  @CPP_CLASS@& pph = *p_@CLASS@_val(ph);
1512  Variables_Set ppl_vset;
1513  if (Int_val(caml_vset) == 0)
1514    CAMLreturn(Val_unit);
1515  while (true) {
1516    ppl_vset.insert(Int_val(Field(caml_vset, 0)));
1517    if (Int_val(Field(caml_vset, 1)) == 0)
1518      break;
1519    caml_vset = Field(caml_vset, 1);
1520  }
1521  build_ppl_bounded_integer_type_representation(rep);
1522  build_ppl_bounded_integer_type_overflow(oflow);
1523  const Constraint_System ppl_cs = build_ppl_Constraint_System(cs);
1524  const unsigned ppl_complexity = value_to_unsigned<unsigned>(complexity);
1525  const bool ppl_wrap_ind = Bool_val(wrap_ind);
1526  pph.wrap_assign(ppl_vset,
1527                  build_ppl_bounded_integer_type_width(width),
1528                  build_ppl_bounded_integer_type_representation(rep),
1529                  build_ppl_bounded_integer_type_overflow(oflow),
1530                  &ppl_cs, ppl_complexity, ppl_wrap_ind);
1531  CAMLreturn(Val_unit);
1532}
1533CATCH_ALL
1534
1535extern "C"
1536CAMLprim value
1537ppl_@CLASS@_wrap_assign_bytecode(value * argv, int)
1538{
1539  return ppl_@CLASS@_wrap_assign_native(argv[0], argv[1], argv[2], argv[3],
1540                                        argv[4], argv[5], argv[6], argv[7]);
1541}
1542
1543')
1544
1545