source: git/Singular/mpsr.h @ 634dab0

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