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