source: git/Singular/mpsr.h @ 4e654a2

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