source: git/Singular/mpsr.h @ 6ce030f

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