Implement Expression.fromstring
[linpy.git] / pypol / isl.py
1 import ctypes, ctypes.util
2
3 from . import _isl
4
5
6 libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
7
8 libisl.isl_printer_get_str.restype = ctypes.c_char_p
9 libisl.isl_dim_set = _isl.isl_dim_set
10
11
12 class IslObject:
13
14 __slots__ = ('_ptr')
15
16 def __init__(self, ptr):
17 self._ptr = ptr
18
19 @property
20 def _as_parameter_(self):
21 return self._ptr
22
23
24 class Context(IslObject):
25
26 def __init__(self):
27 ptr = libisl.isl_ctx_alloc()
28 super().__init__(ptr)
29
30 #comment out so does not delete itself after being created
31 #def __del__(self):
32 # libisl.isl_ctx_free(self)
33
34 def __eq__(self, other):
35 if not isinstance(other, Context):
36 return False
37 return self._ptr == other._ptr
38
39
40 class BasicSet(IslObject):
41
42 def __str__(self):
43 ls = libisl.isl_basic_set_get_local_space(self)
44 ctx = libisl.isl_local_space_get_ctx(ls)
45 p = libisl.isl_printer_to_str(ctx)
46 p = libisl.isl_printer_print_basic_set(p, self)
47 string = libisl.isl_printer_get_str(p).decode()
48 return string
49
50 def __del__(self):
51 libisl.isl_basic_set_free(self)