[6ae4f5] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[341696] | 4 | /* $Id$ */ |
---|
[0e1846] | 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 | |
---|
[4a8d95] | 22 | #include"MPT.h" |
---|
[64c6d1] | 23 | #include"structs.h" |
---|
[a9a7be] | 24 | #include"subexpr.h" |
---|
[512a2b] | 25 | #include"omalloc.h" |
---|
[64c6d1] | 26 | #include"polys.h" |
---|
| 27 | #include"numbers.h" |
---|
[be0d84] | 28 | #include"ring.h" |
---|
[64c6d1] | 29 | |
---|
[0e1846] | 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(); |
---|
[286bd57] | 63 | extern void mpsr_PrintError(MP_Link_pt link); |
---|
| 64 | extern void mpsr_PrintError(mpsr_Status_t error, MP_Link_pt link); |
---|
[0e1846] | 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); |
---|
[286bd57] | 70 | extern mpsr_Status_t mpsr_GetDump(MP_Link_pt link); |
---|
[0e1846] | 71 | // from mpsr_Put.cc |
---|
| 72 | extern mpsr_Status_t mpsr_PutMsg(MP_Link_pt link, leftv lv); |
---|
[286bd57] | 73 | extern mpsr_Status_t mpsr_PutDump(MP_Link_pt link); |
---|
[0e1846] | 74 | |
---|
| 75 | |
---|
| 76 | /*************************************************************** |
---|
| 77 | * |
---|
| 78 | * Inline's |
---|
| 79 | * |
---|
| 80 | ***************************************************************/ |
---|
| 81 | inline leftv mpsr_InitLeftv(short tok, void *data) |
---|
| 82 | { |
---|
[c232af] | 83 | leftv lv = (leftv) omAlloc0Bin(sleftv_bin); |
---|
[0e1846] | 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 |
---|
[cf42ab1] | 99 | nSetChar(rg); |
---|
[0e1846] | 100 | #else |
---|
[cf42ab1] | 101 | nSetChar(rg); |
---|
[e9ad8a6] | 102 | #endif |
---|
[a9a7be] | 103 | rComplete(rg); |
---|
| 104 | pSetGlobals(rg); |
---|
[0e1846] | 105 | currRing = rg; |
---|
| 106 | currComplete = complete; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
[550b4c] | 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 | { |
---|
[e665360] | 118 | if (gTa != NULL) |
---|
[c232af] | 119 | omFreeSize(gTa, gTa_Length*sizeof(MP_Sint32_t)); |
---|
| 120 | gTa = (MP_Sint32_t *) omAlloc((length)*sizeof(MP_Sint32_t)); |
---|
[550b4c] | 121 | gTa_Length = length; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
[0e1846] | 125 | /*************************************************************** |
---|
| 126 | * |
---|
| 127 | * Macros |
---|
| 128 | * |
---|
| 129 | ***************************************************************/ |
---|
| 130 | |
---|
[2f2af5] | 131 | // is application specific Dictionary |
---|
[0e1846] | 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 |
---|
[feaddd] | 136 | #define MPSR_QUIT_STRING "MPtcp:quit" |
---|
[0e1846] | 137 | |
---|
[e9ad8a6] | 138 | // some handy Macros for error handlings |
---|
[0e1846] | 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 | { \ |
---|
[92e539] | 183 | Werror("mpt_failr violation in %s line %d:",__FILE__, __LINE__); \ |
---|
[0e1846] | 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) |
---|
[e9ad8a6] | 250 | #undef mpsr_assume |
---|
[0e1846] | 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 |
---|