1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id$ */ |
---|
5 | /*************************************************************** |
---|
6 | * |
---|
7 | * File: mpsr.h |
---|
8 | * Purpose: Global Header file for MP connection to Singular |
---|
9 | * Author: Olaf Bachmann (10/95) |
---|
10 | * |
---|
11 | * Change History (most recent first): |
---|
12 | * |
---|
13 | ***************************************************************/ |
---|
14 | #ifdef HAVE_MPSR |
---|
15 | |
---|
16 | #ifndef __MPSR__ |
---|
17 | #define __MPSR__ |
---|
18 | |
---|
19 | // now the MP include stuff (is surrounded by ifndef there) |
---|
20 | #include"MP.h" |
---|
21 | |
---|
22 | #include"MPT.h" |
---|
23 | #include <kernel/structs.h> |
---|
24 | #include"subexpr.h" |
---|
25 | #include <omalloc.h> |
---|
26 | #include <kernel/polys.h> |
---|
27 | #include <kernel/numbers.h> |
---|
28 | #include <kernel/ring.h> |
---|
29 | |
---|
30 | /*************************************************************** |
---|
31 | * |
---|
32 | * prototype declarations of routines we provide for the outer world |
---|
33 | * |
---|
34 | * |
---|
35 | ***************************************************************/ |
---|
36 | // from mpsr_Error.c |
---|
37 | typedef enum mpsr_Status_t |
---|
38 | { |
---|
39 | mpsr_Failure, |
---|
40 | mpsr_Success, |
---|
41 | mpsr_MP_Failure, |
---|
42 | mpsr_MPT_Failure, |
---|
43 | mpsr_UnknownLeftvType, |
---|
44 | mpsr_WrongLeftvType, |
---|
45 | mpsr_UnknownSingularToken, |
---|
46 | mpsr_UnknownDictionary, |
---|
47 | mpsr_UnkownOperator, |
---|
48 | mpsr_UnknownMPNodeType, |
---|
49 | mpsr_CanNotHandlePrototype, |
---|
50 | mpsr_WrongNumofArgs, |
---|
51 | mpsr_WrongArgumentType, |
---|
52 | mpsr_WrongNodeType, |
---|
53 | mpsr_ReqAnnotSkip, |
---|
54 | mpsr_WrongUnionDiscriminator, |
---|
55 | mpsr_UnknownCoeffDomain, |
---|
56 | mpsr_MaxError |
---|
57 | } mpsr_Status_t; |
---|
58 | |
---|
59 | extern mpsr_Status_t mpsr_SetError(mpsr_Status_t error); |
---|
60 | extern mpsr_Status_t mpsr_SetError(MP_Link_pt link); |
---|
61 | extern void mpsr_PrintError(mpsr_Status_t error); |
---|
62 | extern void mpsr_PrintError(); |
---|
63 | extern void mpsr_PrintError(MP_Link_pt link); |
---|
64 | extern void mpsr_PrintError(mpsr_Status_t error, MP_Link_pt link); |
---|
65 | extern mpsr_Status_t mpsr_GetError(); |
---|
66 | extern void mpsr_ClearError(); |
---|
67 | |
---|
68 | // from mpsr_Get.cc |
---|
69 | extern mpsr_Status_t mpsr_GetMsg(MP_Link_pt link, leftv &lv); |
---|
70 | extern mpsr_Status_t mpsr_GetDump(MP_Link_pt link); |
---|
71 | // from mpsr_Put.cc |
---|
72 | extern mpsr_Status_t mpsr_PutMsg(MP_Link_pt link, leftv lv); |
---|
73 | extern mpsr_Status_t mpsr_PutDump(MP_Link_pt link); |
---|
74 | |
---|
75 | |
---|
76 | /*************************************************************** |
---|
77 | * |
---|
78 | * Inline's |
---|
79 | * |
---|
80 | ***************************************************************/ |
---|
81 | inline leftv mpsr_InitLeftv(short tok, void *data) |
---|
82 | { |
---|
83 | leftv lv = (leftv) omAlloc0Bin(sleftv_bin); |
---|
84 | lv->data = data; |
---|
85 | lv->rtyp = tok; |
---|
86 | return lv; |
---|
87 | } |
---|
88 | |
---|
89 | // this is only for intermediate ring changes by mpsr |
---|
90 | // a "proper" setting of the global ring is done at the end of all the |
---|
91 | // getting |
---|
92 | extern BOOLEAN currComplete; |
---|
93 | |
---|
94 | inline void mpsr_SetCurrRing(ring rg, BOOLEAN complete) |
---|
95 | { |
---|
96 | if (currRing != rg || (complete && ! currComplete)) |
---|
97 | { |
---|
98 | #ifdef PDEBUG |
---|
99 | nSetChar(rg); |
---|
100 | #else |
---|
101 | nSetChar(rg); |
---|
102 | #endif |
---|
103 | rComplete(rg); |
---|
104 | pSetGlobals(rg); |
---|
105 | currRing = rg; |
---|
106 | currComplete = complete; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | extern MP_Sint32_t *gTa; |
---|
111 | extern MP_Sint32_t gTa_Length; |
---|
112 | |
---|
113 | |
---|
114 | inline void mpsr_InitTempArray(int length) |
---|
115 | { |
---|
116 | if (gTa_Length < length) |
---|
117 | { |
---|
118 | if (gTa != NULL) |
---|
119 | omFreeSize(gTa, gTa_Length*sizeof(MP_Sint32_t)); |
---|
120 | gTa = (MP_Sint32_t *) omAlloc((length)*sizeof(MP_Sint32_t)); |
---|
121 | gTa_Length = length; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | /*************************************************************** |
---|
126 | * |
---|
127 | * Macros |
---|
128 | * |
---|
129 | ***************************************************************/ |
---|
130 | |
---|
131 | // is application specific Dictionary |
---|
132 | #define MP_SingularDict 129 |
---|
133 | // remove this, once the Galois field stuff is done properly |
---|
134 | #define MP_AnnotSingularGalois 1 |
---|
135 | // String used to indicate the end of a communication |
---|
136 | #define MPSR_QUIT_STRING "MPtcp:quit" |
---|
137 | |
---|
138 | // some handy Macros for error handlings |
---|
139 | #ifdef MPSR_DEBUG |
---|
140 | |
---|
141 | #undef failr |
---|
142 | #define failr(x) \ |
---|
143 | do \ |
---|
144 | { \ |
---|
145 | mpsr_Status_t _status = x; \ |
---|
146 | if (_status != mpsr_Success) \ |
---|
147 | Werror("failr violation in %s line %d:",__FILE__, __LINE__); \ |
---|
148 | if (_status != mpsr_Success) return _status; \ |
---|
149 | } \ |
---|
150 | while (0) |
---|
151 | |
---|
152 | #undef mp_failr |
---|
153 | #define mp_failr(x) \ |
---|
154 | do \ |
---|
155 | { \ |
---|
156 | if (x != MP_Success) \ |
---|
157 | { \ |
---|
158 | Werror("mp_failr violation in %s line %d:",__FILE__, __LINE__); \ |
---|
159 | return mpsr_SetError(link); \ |
---|
160 | } \ |
---|
161 | } \ |
---|
162 | while (0) |
---|
163 | |
---|
164 | #undef mp_return |
---|
165 | #define mp_return(x) \ |
---|
166 | do \ |
---|
167 | { \ |
---|
168 | if (x != MP_Success) \ |
---|
169 | { \ |
---|
170 | Werror("mp_return violation in %s line %d:",__FILE__, __LINE__); \ |
---|
171 | return mpsr_SetError(link); \ |
---|
172 | } \ |
---|
173 | else return mpsr_Success; \ |
---|
174 | } \ |
---|
175 | while (0) |
---|
176 | |
---|
177 | #undef mpt_failr |
---|
178 | #define mpt_failr(x) \ |
---|
179 | do \ |
---|
180 | { \ |
---|
181 | if (x != MPT_Success) \ |
---|
182 | { \ |
---|
183 | Werror("mpt_failr violation in %s line %d:",__FILE__, __LINE__); \ |
---|
184 | return mpsr_SetError(mpsr_MPT_Failure); \ |
---|
185 | } \ |
---|
186 | } \ |
---|
187 | while (0) |
---|
188 | #undef mpt_return |
---|
189 | #define mpt_return(x) \ |
---|
190 | do \ |
---|
191 | { \ |
---|
192 | if (x != MPT_Success) \ |
---|
193 | { \ |
---|
194 | Werror("mpt_return violation in %s line %d:",__FILE__, __LINE__); \ |
---|
195 | return mpsr_SetError(mpsr_MPT_Failure); \ |
---|
196 | } \ |
---|
197 | else return mpsr_Success; \ |
---|
198 | } \ |
---|
199 | while (0) |
---|
200 | |
---|
201 | #undef mpsr_assume |
---|
202 | #define mpsr_assume(cond) \ |
---|
203 | do \ |
---|
204 | { \ |
---|
205 | if ( ! (cond)) \ |
---|
206 | Werror("mpsr_assume violation in %s line %d",__FILE__, __LINE__); \ |
---|
207 | } while (0) |
---|
208 | |
---|
209 | #else |
---|
210 | #undef failr |
---|
211 | #define failr(x) \ |
---|
212 | do \ |
---|
213 | { \ |
---|
214 | mpsr_Status_t _status = x; \ |
---|
215 | if (_status != mpsr_Success) return _status; \ |
---|
216 | } \ |
---|
217 | while (0) |
---|
218 | #undef mp_failr |
---|
219 | #define mp_failr(x) \ |
---|
220 | do \ |
---|
221 | { \ |
---|
222 | if (x != MP_Success) \ |
---|
223 | return mpsr_SetError(link); \ |
---|
224 | } \ |
---|
225 | while (0) |
---|
226 | #undef mp_return |
---|
227 | #define mp_return(x) \ |
---|
228 | do \ |
---|
229 | { \ |
---|
230 | if (x != MP_Success) return mpsr_SetError(link); \ |
---|
231 | else return mpsr_Success; \ |
---|
232 | } \ |
---|
233 | while (0) |
---|
234 | #undef mpt_failr |
---|
235 | #define mpt_failr(x) \ |
---|
236 | do \ |
---|
237 | { \ |
---|
238 | if (x != MPT_Success) \ |
---|
239 | return mpsr_SetError(mpsr_MPT_Failure); \ |
---|
240 | } \ |
---|
241 | while (0) |
---|
242 | #undef mpt_return |
---|
243 | #define mpt_return(x) \ |
---|
244 | do \ |
---|
245 | { \ |
---|
246 | if (x != MPT_Success) return mpsr_SetError(mpsr_MPT_Failure); \ |
---|
247 | else return mpsr_Success; \ |
---|
248 | } \ |
---|
249 | while (0) |
---|
250 | #undef mpsr_assume |
---|
251 | #define mpsr_assume(cond) ((void) 0) |
---|
252 | |
---|
253 | #endif // MPSR_DEBUG |
---|
254 | |
---|
255 | union nf |
---|
256 | { |
---|
257 | float _f; |
---|
258 | number _n; |
---|
259 | nf(float f) {_f = f;} |
---|
260 | nf(number n) {_n = n;} |
---|
261 | float F() const {return _f;} |
---|
262 | number N() const {return _n;} |
---|
263 | }; |
---|
264 | |
---|
265 | #define Real32_2_Number(r) nf(nf(r).F()).N() |
---|
266 | #define Number_2_Real32(n) nf(n).F() |
---|
267 | |
---|
268 | |
---|
269 | #endif |
---|
270 | #endif |
---|