Wand updates from Evgeny
[sxemacs] / modules / ase / ase.h
1 /*
2   ase.h -- Fancifying ENT a little
3   Copyright (C) 2006, 2007, 2008 Sebastian Freundt
4
5   Author:  Sebastian Freundt <hroptatyr@sxemacs.org>
6
7   * This file is part of SXEmacs.
8   * 
9   * Redistribution and use in source and binary forms, with or without
10   * modification, are permitted provided that the following conditions
11   * are met:
12   *
13   * 1. Redistributions of source code must retain the above copyright
14   *    notice, this list of conditions and the following disclaimer.
15   *
16   * 2. Redistributions in binary form must reproduce the above copyright
17   *    notice, this list of conditions and the following disclaimer in the
18   *    documentation and/or other materials provided with the distribution.
19   *
20   * 3. Neither the name of the author nor the names of any contributors
21   *    may be used to endorse or promote products derived from this
22   *    software without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
25   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33   * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34   * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35   */
36
37 /* Synched up with: Not in FSF. */
38
39 #ifndef INCLUDED_ase_h_
40 #define INCLUDED_ase_h_ 1
41
42 #include "semaphore.h"
43 #include <stdbool.h>
44
45 #ifdef ALL_DEBUG_FLAGS
46 #undef EMOD_ASE_DEBUG_FLAG
47 #define EMOD_ASE_DEBUG_FLAG
48 #endif
49
50 #define __EMOD_ASE_DEBUG__(args...)     fprintf(stderr, "emodule(ASE) " args)
51 #ifndef EMOD_ASE_DEBUG_FLAG
52 #define EMOD_ASE_DEBUG(args...)
53 #define EMOD_ASE_DEBUG_DMP(args...)
54 #else
55 #define EMOD_ASE_DEBUG(args...)         __EMOD_ASE_DEBUG__(args)
56 #define EMOD_ASE_DEBUG_DMP(args...)     fprintf(stderr, args)
57 #endif
58 #define EMOD_ASE_DEBUG_GC(args...)      EMOD_ASE_DEBUG("[GC]: " args)
59 #define EMOD_ASE_CRITICAL(args...)      __EMOD_ASE_DEBUG__("CRITICAL: " args)
60
61 #ifdef SXE_UNUSED
62 #elif defined(__GNUC__)
63 #  define SXE_UNUSED(x) UNUSED_ ## x __attribute__((unused))
64 #elif defined(__LCLINT__)
65 #  define SXE_UNUSED(x) /*@unused@*/ x
66 #else
67 #  define SXE_UNUSED(x) x
68 #endif
69
70 typedef long int Z_t;
71 typedef long unsigned int ase_hash_t;
72
73 #ifdef EMOD_ASE_MONOMOD
74 extern void ase_mono_LTX_init(void);
75 #endif
76 extern void ase_LTX_init(void);
77 extern void ase_LTX_reinit(void);
78 extern void ase_LTX_deinit(void);
79
80 \f
81 typedef int(*ase_relation_f)(Lisp_Object, Lisp_Object);
82 typedef int(*ase_c_relation_f)(Lisp_Object, Lisp_Object); /* compatible */
83 typedef int(*ase_r_relation_f)(Lisp_Object, Lisp_Object); /* reflexive */
84 typedef int(*ase_s_relation_f)(Lisp_Object, Lisp_Object); /* symmetric */
85 typedef int(*ase_t_relation_f)(Lisp_Object, Lisp_Object); /* transitive */
86 typedef int(*ase_cr_relation_f)(Lisp_Object, Lisp_Object);
87 typedef int(*ase_cs_relation_f)(Lisp_Object, Lisp_Object);
88 typedef int(*ase_ct_relation_f)(Lisp_Object, Lisp_Object);
89 typedef int(*ase_rs_relation_f)(Lisp_Object, Lisp_Object);
90 typedef int(*ase_rt_relation_f)(Lisp_Object, Lisp_Object);
91 typedef int(*ase_st_relation_f)(Lisp_Object, Lisp_Object);
92 typedef int(*ase_crs_relation_f)(Lisp_Object, Lisp_Object);
93 typedef int(*ase_crt_relation_f)(Lisp_Object, Lisp_Object);
94 typedef int(*ase_cst_relation_f)(Lisp_Object, Lisp_Object);
95 typedef int(*ase_equivalence_relation_f)(Lisp_Object, Lisp_Object); /* r+s+t */
96 typedef int(*ase_congruence_relation_f)(Lisp_Object, Lisp_Object); /* c+r+s+t */
97 typedef Lisp_Object(*ase_element_relation_f)(Lisp_Object, Lisp_Object);
98
99 typedef ase_t_relation_f ase_order_relation_f; /* special context! */
100
101 /* generic ase objects */
102 typedef struct ase_object_impl_s *ase_object_impl_t;
103 typedef void *ase_object_options_t;
104 typedef struct ase_object_s *ase_object_t;
105
106 typedef ase_object_t(*ase_object_constr_f)(ase_object_options_t opts, ...);
107 typedef void(*ase_object_destr_f)(ase_object_t);
108 typedef ase_hash_t(*ase_object_hash_f)(ase_object_t);
109 typedef struct ase_category_s *ase_category_t;
110 typedef long unsigned int ase_description_t;
111 typedef ase_description_t ase_object_d;
112
113 struct ase_object_impl_s {
114         ase_object_constr_f constrf;
115         ase_object_destr_f destrf;
116         ase_object_hash_f hashf;
117 };
118
119 struct ase_object_s {
120         /* the `capabilities' of the particular object */
121         ase_object_impl_t impl;
122         ase_object_options_t options;
123         /* the category of the object's world, i.e. where the object lives in */
124         ase_category_t category;
125         /* properties of this particular object
126          * these depend upon the world of the object */
127         ase_object_d properties;
128         sxe_mutex_t mtx;
129         ase_hash_t hash;
130 };
131
132 struct ase_category_s {
133         bool setoid_p:1;
134         bool magma_p:1;
135         bool algebra_p:1;
136         bool mapping_p:1;
137         bool relation_p:1;
138         bool orderable_p:1;
139 };
140
141 /* inline decls */
142 extern inline int
143 _ase_less_p(Lisp_Object, Lisp_Object);
144 extern inline int
145 _ase_greater_p(Lisp_Object, Lisp_Object);
146 extern inline int
147 _ase_equal_p(Lisp_Object, Lisp_Object);
148 extern inline int
149 _ase_lessequal_p(Lisp_Object, Lisp_Object);
150 extern inline int
151 _ase_greaterequal_p(Lisp_Object, Lisp_Object);
152 extern inline void
153 _ase_swap(Lisp_Object *args, int idx1, int idx2);
154
155 \f
156 extern inline int
157 _ase_less_p(Lisp_Object a, Lisp_Object b)
158 {
159         return ent_binrel(ASE_BINARY_REL_LESSP, a, b);
160 }
161 extern inline int
162 _ase_greater_p(Lisp_Object a, Lisp_Object b)
163 {
164         return ent_binrel(ASE_BINARY_REL_GREATERP, a, b);
165 }
166 extern inline int
167 _ase_equal_p(Lisp_Object a, Lisp_Object b)
168 {
169         return ent_binrel(ASE_BINARY_REL_EQUALP, a, b);
170 }
171 extern inline int
172 _ase_lessequal_p(Lisp_Object a, Lisp_Object b)
173 {
174         return ent_binrel2(ASE_BINARY_REL_LESSP,
175                            ASE_BINARY_REL_EQUALP, a, b);
176 }
177 extern inline int
178 _ase_greaterequal_p(Lisp_Object a, Lisp_Object b)
179 {
180         return ent_binrel2(ASE_BINARY_REL_GREATERP,
181                            ASE_BINARY_REL_EQUALP, a, b);
182 }
183
184 extern inline void
185 _ase_swap(Lisp_Object *args, int idx1, int idx2)
186 {
187         Lisp_Object foo = args[idx1];
188         args[idx1] = args[idx2];
189         args[idx2] = foo;
190         return;
191 }
192
193 #define DEFASETYPE_WITH_OPS(_tsym, _tstr)                       \
194         do {                                                    \
195                 defsymbol(&_tsym, _tstr);                       \
196                 ase_optable_add(_tsym);                         \
197         } while (0)
198
199 #endif  /* INCLUDED_ase_h_ */
200