source: git/Singular/mpsr_Get.cc @ 51c163

spielwiese
Last change on this file since 51c163 was 51c163, checked in by Olaf Bachmann <obachman@…>, 26 years ago
Wed Dec 3 16:14:51 1997 Olaf Bachmann <obachman@mathematik.uni-kl.de> * Many changes to prepare for implementation of fast comparison schemes: Here are only a few: - added file polys-impl.h which implements low-level poly stuff - removed file polys2.cc, added polys-impl.cc - added Singularp target to Make - prepared configure for setting of exponent type - got rid of as many direct p->exp[..] accesses as possible - added file spSpolyLoop.cc spSpolyLoop.h polys-comp.h * polys-impl.h: if you defined COMP_FAST, then fast polynomial comparsions are eanbled (still needs a lot of debugging) git-svn-id: file:///usr/local/Singular/svn/trunk@941 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 22.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4
5/* $Id: mpsr_Get.cc,v 1.14 1997-12-03 16:58:54 obachman Exp $ */
6/***************************************************************
7 *
8 * File:       mpsr_Get.cc
9 * Purpose:    definition of the main Get routine(s)
10 * Author:     Olaf Bachmann (10/95)
11 *
12 * Change History (most recent first):
13 *
14 ***************************************************************/
15
16#include "mod2.h"
17
18#ifdef HAVE_MPSR
19
20
21#include"mpsr_Get.h"
22#include"mpsr_Tok.h"
23
24#include "tok.h"
25#include "longrat.h"
26#include "ring.h"
27#include "intvec.h"
28#include "ideals.h"
29#include "matpol.h"
30#include "lists.h"
31#include "sing_mp.h"
32
33#include <limits.h>
34
35
36/***************************************************************
37 *
38 * prototypes
39 *
40 ***************************************************************/
41static mpsr_Status_t GetIntVecLeftv(MP_Link_pt link, MPT_Node_pt node,
42                                  mpsr_leftv mlv);
43static mpsr_Status_t GetIntMatLeftv(MP_Link_pt link, MPT_Node_pt node,
44                                  mpsr_leftv mlv);
45static mpsr_Status_t GetRingLeftv(MP_Link_pt link, MPT_Node_pt node,
46                                mpsr_leftv mlv);
47static mpsr_Status_t GetPolyLeftv(MP_Link_pt link, MPT_Node_pt node,
48                                mpsr_leftv mlv);
49static mpsr_Status_t GetPolyVectorLeftv(MP_Link_pt link, MPT_Node_pt node,
50                                      mpsr_leftv mlv);
51static mpsr_Status_t GetIdealLeftv(MP_Link_pt link, MPT_Node_pt node,
52                                 mpsr_leftv mlv);
53static mpsr_Status_t GetModuleLeftv(MP_Link_pt link, MPT_Node_pt node,
54                                  mpsr_leftv mlv);
55static mpsr_Status_t GetMatrixLeftv(MP_Link_pt link, MPT_Node_pt node,
56                                  mpsr_leftv mlv);
57static mpsr_Status_t GetMapLeftv(MP_Link_pt link, MPT_Node_pt node,
58                               mpsr_leftv mlv);
59static mpsr_Status_t GetCopCommandLeftv(MP_Link_pt link, MPT_Node_pt node,
60                                      mpsr_leftv mlv, short quote);
61
62/***************************************************************
63 *
64 * Inlines
65 *
66 ***************************************************************/
67
68//
69// Predicates which examine nodes for primitive Singular types
70//
71#define fr(cond)    if (! (cond)) return FALSE
72
73inline BOOLEAN IsIntVecNode(MPT_Node_pt node)
74{
75  fr(NodeCheck(node, MP_MatrixDict, MP_CopMatrixDenseVector));
76
77  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
78  return tree != NULL && NodeCheck(tree->node, MP_CommonMetaType,
79                                   MP_ProtoDict, MP_CmtProtoIMP_Sint32);
80}
81
82inline BOOLEAN IsIntMatNode(MPT_Node_pt node)
83{
84  fr(NodeCheck(node, MP_MatrixDict, MP_CopMatrixDenseMatrix));
85
86  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
87  return tree != NULL && NodeCheck(tree->node, MP_CommonMetaType,
88                                   MP_ProtoDict, MP_CmtProtoIMP_Sint32);
89}
90
91inline BOOLEAN IsRingNode(MPT_Node_pt node, ring &r)
92{
93  BOOLEAN mv;
94  return
95    NodeCheck(node, MP_PolyDict, MP_CopPolyRing) &&
96    mpsr_GetRingAnnots(node, r, mv) == MP_Success;
97}
98
99inline BOOLEAN IsPolyNode(MPT_Node_pt node, ring &r)
100{
101  BOOLEAN mv;
102 
103  //for the timne being, we only accept DDP's
104  return
105    NodeCheck(node, MP_PolyDict, MP_CopPolyDenseDistPoly) &&
106    MPT_FindAnnot(node, MP_PolyDict, MP_AnnotPolyModuleVector) == NULL &&
107    mpsr_GetRingAnnots(node, r, mv) == MP_Success;
108}
109
110inline BOOLEAN IsPolyVectorNode(MPT_Node_pt node, ring &r)
111{
112  BOOLEAN mv;
113 
114  //for the timne being, we only accept DDP's
115  return
116    NodeCheck(node, MP_PolyDict, MP_CopPolyDenseDistPoly) &&
117    MPT_FindAnnot(node, MP_PolyDict, MP_AnnotPolyModuleVector) != NULL &&
118    mpsr_GetRingAnnots(node, r, mv) == MP_Success;
119}
120
121inline BOOLEAN IsIdealNode(MPT_Node_pt node, ring &r)
122{
123  fr(NodeCheck(node, MP_PolyDict, MP_CopPolyIdeal));
124  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
125  fr(tree != NULL);
126  node = tree->node;
127  return
128    node->type == MP_CommonMetaOperatorType &&
129    node->numchild == 0 &&
130    IsPolyNode(node, r);
131}
132
133inline BOOLEAN IsModuleNode(MPT_Node_pt node, ring &r)
134{
135  fr(NodeCheck(node, MP_PolyDict, MP_CopPolyModule));
136  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
137  fr(tree != NULL);
138  node = tree->node;
139  return
140    node->type == MP_CommonMetaOperatorType &&
141    node->numchild == 0 &&
142    IsPolyVectorNode(node, r);
143}
144
145inline BOOLEAN IsMatrixNode(MPT_Node_pt node, ring &r)
146{
147  fr(NodeCheck(node, MP_MatrixDict, MP_CopMatrixDenseMatrix));
148  MPT_Tree_pt tree = MPT_GetProtoTypespec(node);
149  fr(tree != NULL);
150  node = tree->node;
151  return
152    node->type == MP_CommonMetaOperatorType &&
153    node->numchild == 0 &&
154    IsPolyNode(node, r);
155}
156
157inline BOOLEAN IsQuitNode(MPT_Node_pt node)
158{
159  return NodeCheck(node, MP_MpDict, MP_CopMpEndSession);
160}
161
162//
163// Init*Leftv functions
164//
165inline void InitIntLeftv(mpsr_leftv mlv, int i)
166{
167  mlv->lv = mpsr_InitLeftv(INT_CMD, (void *) i);
168}
169
170inline void InitApIntLeftv(mpsr_leftv mlv, mpz_ptr apint)
171{
172  number n = (number) Alloc(sizeof(rnumber));
173
174  mlv->r = mpsr_rDefault(0);
175  n->s = 3;
176  memcpy(&(n->z), apint, sizeof(MP_INT));
177  n = nlInit(n);
178  Free(apint, sizeof(MP_INT));
179  mlv->lv = mpsr_InitLeftv(NUMBER_CMD, n);
180}
181
182inline void InitReal32Leftv(mpsr_leftv mlv, MPT_Arg_t r32)
183{
184  number n = (number) r32;
185//  n = Real32_2_Number(r32);
186
187  mlv->r = mpsr_rDefault(-1);
188  mlv->lv = mpsr_InitLeftv(NUMBER_CMD, n);
189}
190 
191inline void InitIdentifierLeftv(mpsr_leftv mlv, char *name, short quote)
192{
193  int pos;
194 
195  if (quote <= 0)
196  {
197    idhdl h = mpsr_FindIdhdl(name, mlv->r);
198
199    if (h != NULL)
200    {
201      mlv->lv = mpsr_InitLeftv(IDHDL, (void *) h);
202    }
203    else
204    {
205      poly p;
206     
207      pos = mpsr_rDefault(0, name, mlv->r);
208      mpsr_SetCurrRing(mlv->r, TRUE);
209      p = pOne();
210      pSetExp(p,pos+1, 1);
211      pSetm(p);
212      mlv->lv = mpsr_InitLeftv(POLY_CMD, (void *) p);
213    }
214    FreeL(name);
215  }
216  else
217  {
218    mlv->lv = mpsr_InitLeftv(DEF_CMD, NULL);
219    mlv->lv->name = name;
220  }
221}
222
223/* primitive mpsr_Get*Leftv functions */
224
225inline mpsr_Status_t mpsr_GetIntLeftv(MPT_Node_pt node, mpsr_leftv mlv)
226{
227  mpsr_assume(MP_IsFixedIntegerType(node->type));
228  mlv->lv = mpsr_InitLeftv(INT_CMD, node->nvalue);
229  return mpsr_Success;
230}
231
232inline mpsr_Status_t mpsr_GetReal32Leftv(MPT_Node_pt node, mpsr_leftv mlv) 
233{
234  mpsr_assume(node->type == MP_Real32Type);
235  InitReal32Leftv(mlv, node->nvalue);
236  return mpsr_Success;
237}
238
239inline mpsr_Status_t mpsr_GetApIntLeftv(MPT_Node_pt node, mpsr_leftv mlv)
240{
241  InitApIntLeftv(mlv, (mpz_ptr)  node->nvalue);
242  node->nvalue = NULL;
243  return mpsr_Success;
244}
245
246inline mpsr_Status_t mpsr_GetIdentifierLeftv(MPT_Node_pt node, mpsr_leftv mlv,
247                                             short quote)
248{
249  mpsr_assume(MP_IsIdType(node->type));
250  char *id;
251  MPT_Annot_pt proc_annot = MPT_FindAnnot(node, MP_SingularDict,
252                                          MP_AnnotSingularProcDef);
253
254  if (node->type == MP_CommonGreekIdentifierType ||
255      node->type == MP_CommonGreekIdentifierType)
256  {
257    id  = (char *) AllocL(2*sizeof(char));
258    id[1] = '\0';
259    id[0] = MP_UINT8_T(node->nvalue);
260  }
261  else
262  {
263    id = MP_STRING_T(node->nvalue);
264    node->nvalue = NULL;
265  }
266 
267  InitIdentifierLeftv(mlv, id, quote);
268
269  if (proc_annot != NULL) mlv->lv->rtyp = PROC_CMD;
270   
271  return mpsr_Success;
272}
273
274inline mpsr_Status_t mpsr_GetStringLeftv(MPT_Node_pt node, mpsr_leftv mlv)
275{
276  mpsr_assume(node->type == MP_StringType);
277  mlv->lv = mpsr_InitLeftv(STRING_CMD, MP_STRING_T(node->nvalue));
278  node->nvalue = NULL;
279  return mpsr_Success;
280}
281
282inline mpsr_Status_t GetQuitLeftv(mpsr_leftv mlv)
283{
284  mlv->lv = mpsr_InitLeftv(STRING_CMD, (void *) mstrdup(MPSR_QUIT_STRING));
285  return mpsr_Success;
286}
287
288/***************************************************************
289 *
290 * The top-level routine for getting a message
291 *
292 ***************************************************************/
293mpsr_Status_t mpsr_GetMsg(MP_Link_pt link, leftv &lv)
294{
295  mpsr_sleftv mlv, mlv1;
296  mpsr_Status_t status = mpsr_Success;
297  mlv.lv = NULL;
298  mlv.r = NULL;
299  mlv1.lv = NULL;
300  mlv1.r = NULL;
301
302  status = (MP_InitMsg(link) == MP_Success ? mpsr_Success : mpsr_MP_Failure);
303 
304  if (status == mpsr_Success && ! MP_TestEofMsg(link))
305    status = mpsr_GetLeftv(link, &mlv, 0);
306  else
307  {
308    lv = mpsr_InitLeftv(NONE, NULL);
309    return status;
310  }
311
312  // handle more than one leftv (ie. chains of leftv's)
313  while (status == mpsr_Success && ! MP_TestEofMsg(link))
314  {
315    // Get next leftv
316    status = mpsr_GetLeftv(link, &mlv1, 0);
317    if (status == mpsr_Success)
318      status = mpsr_MergeLeftv(&mlv, &mlv1);
319  }
320
321  if (status == mpsr_Success)
322  {
323    // Now mlv is our leftv -- check whether r has an ordering set
324    if (mlv.r != NULL && mlv.r->order[0] == ringorder_unspec)
325    {
326      ring r = rCopy(mlv.r);
327      r->order[0] = ringorder_lp;
328      mpsr_rSetOrdSgn(r);
329      mpsr_MapLeftv(mlv.lv, mlv.r, r);
330      rKill(mlv.r);
331      mlv.r = r;
332    }
333    mpsr_SetCurrRingHdl(mlv.r);
334
335    lv = mlv.lv;
336  }
337  else lv = mpsr_InitLeftv(NONE, NULL); 
338 
339  return status;
340}
341
342/***************************************************************
343 *
344 * Top-level routine for getting a mpsr_leftv
345 *
346 ***************************************************************/
347
348// if quote > 0, then identifiers are not tried to be resolved, or
349// converted into a ring variable
350mpsr_Status_t mpsr_GetLeftv(MP_Link_pt link, mpsr_leftv mlv, short quote)
351{
352  MPT_Node_pt node = NULL;
353  MP_NodeType_t type;
354  mlv->r = NULL;
355  mlv->lv = NULL;
356
357  mpt_failr(MPT_GetNode(link, &node));
358
359  type = node->type;
360
361  if (MP_IsFixedIntegerType(type))
362    failr(mpsr_GetIntLeftv(node, mlv));
363  else if (MP_IsIdType(type))
364    failr(mpsr_GetIdentifierLeftv(node, mlv, quote));
365  else
366  {
367    switch (node->type)
368    {
369        case MP_ApIntType:
370          failr(mpsr_GetApIntLeftv(node, mlv));
371          break;       
372
373        case MP_StringType:
374          failr(mpsr_GetStringLeftv(node, mlv));
375          break;       
376
377        case MP_Real32Type:
378          failr(mpsr_GetReal32Leftv(node, mlv));
379          break;       
380       
381        case MP_CommonOperatorType:
382          failr(mpsr_GetCommonOperatorLeftv(link, node, mlv, quote));
383          break;       
384
385        case MP_OperatorType:
386          failr(mpsr_GetOperatorLeftv(link, node, mlv, quote));
387          break;       
388
389        default:
390          MPT_DeleteNode(node);
391          return mpsr_SetError(mpsr_UnknownMPNodeType);
392    }
393  }
394 
395  // everything was ok
396  MPT_DeleteNode(node);
397  return mpsr_Success;
398}
399
400/***************************************************************
401 *
402 * mpsr_Get*Leftv
403 *
404 ***************************************************************/
405mpsr_Status_t mpsr_GetCommonOperatorLeftv(MP_Link_pt link,
406                                        MPT_Node_pt node,
407                                        mpsr_leftv mlv,
408                                        short quote)
409{
410  mpsr_assume(node->type == MP_CommonOperatorType);
411
412  // Check for Singular data types
413  // IntVec
414  if (IsIntVecNode(node))
415    return GetIntVecLeftv(link, node, mlv);
416  // IntMat
417  else if (IsIntMatNode(node))
418    return GetIntMatLeftv(link, node, mlv);
419  // Ring
420  else if (IsRingNode(node, mlv->r))
421    return GetRingLeftv(link, node, mlv);
422  // Poly
423  else if (IsPolyNode(node, mlv->r))
424    return GetPolyLeftv(link, node, mlv);
425  // PolyVector
426  else if (IsPolyVectorNode(node, mlv->r))
427    return GetPolyVectorLeftv(link, node, mlv);
428  // Ideal
429  else if (IsIdealNode(node, mlv->r))
430    return GetIdealLeftv(link, node, mlv);
431  // Module
432  else if (IsModuleNode(node, mlv->r))
433    return GetModuleLeftv(link, node, mlv);
434  // Matrix
435  else if (IsMatrixNode(node, mlv->r))
436    return GetMatrixLeftv(link, node, mlv);
437  else if (IsQuitNode(node))
438    return GetQuitLeftv(mlv);
439  // Map
440  else
441    // now it should be a command (which handles Proc, Map and List
442    // seperately)
443    return GetCopCommandLeftv(link, node, mlv, quote);
444}
445
446mpsr_Status_t mpsr_GetOperatorLeftv(MP_Link_pt link,
447                                  MPT_Node_pt node,
448                                  mpsr_leftv mlv,
449                                  short quote)
450{
451  mpsr_assume(node->type == MP_OperatorType);
452  MP_NumChild_t nc = node->numchild, i;
453  mpsr_sleftv smlv1, *mlv1 = &smlv1;
454 
455
456  if (MPT_GetProtoTypespec(node) != NULL)
457    return mpsr_SetError(mpsr_CanNotHandlePrototype);
458
459  if (nc > 0)
460  {
461    failr(mpsr_GetLeftv(link, mlv, quote));
462    for (i=1; i<nc; i++)
463    {
464      failr(mpsr_GetLeftv(link, mlv1, quote));
465      failr(mpsr_MergeLeftv(mlv, mlv1));
466    }
467  }
468 
469  command cmd = (command) Alloc0(sizeof(sip_command));
470  cmd->op = PROC_CMD;
471  cmd->arg1.rtyp = STRING_CMD;
472  cmd->arg1.data = (void *) mstrdup(MP_STRING_T(node->nvalue));
473
474  if (node->numchild > 0)
475  {
476    cmd->argc = 2;
477    memcpy(&(cmd->arg2), mlv->lv, sizeof(sleftv));
478    Free(mlv->lv, sizeof(sleftv));
479  }
480  else cmd->argc = 1;
481
482  mlv->lv = mpsr_InitLeftv(COMMAND, (void *) cmd);
483  return mpsr_Success;
484}
485 
486/***************************************************************
487 *
488 * Get*Leftv routines
489 *
490 ***************************************************************/
491//
492// Get*Leftv routines
493//
494static mpsr_Status_t GetIntVecLeftv(MP_Link_pt link, MPT_Node_pt node,
495                                  mpsr_leftv mlv)
496{
497  intvec *iv = new intvec(node->numchild);
498  int *v = iv->ivGetVec();
499
500  mp_failr(IMP_GetSint32Vector(link, &v, node->numchild));
501  mlv->lv = mpsr_InitLeftv(INTVEC_CMD, (void *) iv);
502  return mpsr_Success;
503}
504
505static mpsr_Status_t GetIntMatLeftv(MP_Link_pt link, MPT_Node_pt node,
506                                  mpsr_leftv mlv)
507{
508  intvec *iv;
509  int row = node->numchild, col = 1, *v;
510  MPT_Annot_pt annot = MPT_FindAnnot(node, MP_MatrixDict,
511                                     MP_AnnotMatrixDimension);
512  if (annot != NULL &&
513      annot->value != NULL &&
514      annot->value->node->numchild == 2 &&
515      NodeCheck(annot->value->node, MP_CommonOperatorType, MP_BasicDict,
516                MP_CopBasicList))
517  {
518    MPT_Tree_pt *tarray = (MPT_Tree_pt *) annot->value->args;
519    if (tarray[0]->node->type == MP_Uint32Type &&
520        tarray[1]->node->type == MP_Uint32Type)
521    {
522      row = MP_UINT32_T(tarray[0]->node->nvalue);
523      col = MP_UINT32_T(tarray[1]->node->nvalue);
524    }
525  }
526
527  iv = new intvec(row, col, 0);
528  v = iv->ivGetVec();
529  mp_failr(IMP_GetSint32Vector(link, &v, node->numchild));
530  mlv->lv = mpsr_InitLeftv(INTMAT_CMD, (void *) iv);
531  return mpsr_Success;
532} 
533
534static mpsr_Status_t GetRingLeftv(MP_Link_pt link, MPT_Node_pt node,
535                                mpsr_leftv mlv)
536{
537  mpsr_assume(mlv->r != NULL);
538
539  if (node->numchild != 0) mpt_failr(MPT_SkipArgs(link, node));
540
541  mlv->lv = mpsr_InitLeftv(((mlv->r->qideal != NULL) ? (short) QRING_CMD :
542                            (short) RING_CMD),
543                           (void *) mlv->r);
544  mlv->r = NULL;
545  return mpsr_Success;
546}
547
548static mpsr_Status_t GetPolyLeftv(MP_Link_pt link, MPT_Node_pt node,
549                                mpsr_leftv mlv)
550{
551  poly p;
552
553  mpsr_assume(mlv->r != NULL);
554 
555  failr(mpsr_GetPoly(link, p, node->numchild, mlv->r));
556  mlv->lv = mpsr_InitLeftv(POLY_CMD, (void *) p);
557  return mpsr_Success;
558}
559
560static mpsr_Status_t GetPolyVectorLeftv(MP_Link_pt link, MPT_Node_pt node,
561                                      mpsr_leftv mlv)
562{
563  poly p;
564
565  mpsr_assume(mlv->r != NULL);
566 
567  failr(mpsr_GetPolyVector(link, p, node->numchild, mlv->r));
568  mlv->lv = mpsr_InitLeftv(VECTOR_CMD, (void *) p);
569  return mpsr_Success;
570}
571
572static mpsr_Status_t GetIdealLeftv(MP_Link_pt link, MPT_Node_pt node,
573                                 mpsr_leftv mlv)
574{
575  MP_NumChild_t nc = node->numchild, i;
576  ring r = mlv->r;
577  MP_Uint32_t nmon;
578
579  mpsr_assume(r != NULL);
580  ideal id = idInit(nc,1);
581  for (i=0; i<nc; i++)
582  {
583    mp_failr(IMP_GetUint32(link, &nmon));
584    failr(mpsr_GetPoly(link, id->m[i], nmon, r));
585  }
586 
587  mlv->lv = mpsr_InitLeftv(IDEAL_CMD, (void *) id);
588  return mpsr_Success;
589}
590
591static mpsr_Status_t GetModuleLeftv(MP_Link_pt link, MPT_Node_pt node,
592                                  mpsr_leftv mlv)
593{
594  MP_NumChild_t nc = node->numchild, i;
595  ring r = mlv->r;
596  MP_Uint32_t nmon;
597
598  mpsr_assume(r != NULL);
599  ideal id = idInit(nc,1);
600  for (i=0; i<nc; i++)
601  {
602    mp_failr(IMP_GetUint32(link, &nmon));
603    failr(mpsr_GetPolyVector(link, id->m[i], nmon, r));
604  }
605
606  mlv->lv = mpsr_InitLeftv(MODUL_CMD, (void *) id);
607  return mpsr_Success;
608}
609
610static mpsr_Status_t GetMatrixLeftv(MP_Link_pt link, MPT_Node_pt node,
611                                  mpsr_leftv mlv)
612{
613  MP_NumChild_t nc = node->numchild, row = nc, col = 1, i;
614  matrix mp;
615  MP_Uint32_t nmon;
616  MPT_Annot_pt annot = MPT_FindAnnot(node, MP_MatrixDict,
617                                     MP_AnnotMatrixDimension);
618  if (annot != NULL &&
619      annot->value != NULL &&
620      annot->value->node->numchild == 2 &&
621      NodeCheck(annot->value->node, MP_CommonOperatorType, MP_BasicDict,
622               MP_CopBasicList))
623  {
624    MPT_Tree_pt *tarray = (MPT_Tree_pt *) annot->value->args;
625    if (tarray[0]->node->type == MP_Uint32Type &&
626        tarray[1]->node->type == MP_Uint32Type)
627    {
628      row = MP_UINT32_T(tarray[0]->node->nvalue);
629      col = MP_UINT32_T(tarray[1]->node->nvalue);
630    }
631  }
632
633  mpsr_assume(mlv->r != NULL);
634  mp = mpNew(row, col);
635  for (i=0; i<nc; i++)
636  {
637    mp_failr(IMP_GetUint32(link, &nmon));
638    failr(mpsr_GetPoly(link, mp->m[i], nmon, mlv->r));
639  }
640
641  mlv->lv = mpsr_InitLeftv(MATRIX_CMD, (void *) mp);
642  return mpsr_Success;
643}
644
645static mpsr_Status_t GetMapLeftv(MP_Link_pt link, MPT_Node_pt node,
646                               mpsr_leftv mlv)
647{
648  mpsr_sleftv smlv1, smlv2, *mlv1 = &smlv1, *mlv2 = &smlv2;
649
650  if (node->numchild != 3)
651    return mpsr_SetError(mpsr_WrongNumofArgs);
652 
653  failr(mpsr_GetLeftv(link, mlv, 0));
654  failr(mpsr_GetLeftv(link, mlv1, 0));
655  failr(mpsr_GetLeftv(link, mlv2, 0));
656
657  if (mlv->lv->rtyp != RING_CMD ||
658      mlv1->lv->rtyp != STRING_CMD ||
659      mlv2->lv->rtyp != IDEAL_CMD)
660    return mpsr_SetError(mpsr_WrongArgumentType);
661
662  ring r = (ring) mlv->lv->data, r2;
663  char *name = (char *) mlv1->lv->data;
664  ideal id = (ideal) mlv2->lv->data;
665
666  idhdl h = mpsr_FindIdhdl(name, r2);
667  if (h == NULL || IDTYP(h) != RING_CMD || ! mpsr_RingEqual(IDRING(h), r))
668  {
669    h = mpsr_InitIdhdl(RING_CMD, r, name);
670    h->next = idroot;
671    idroot = h;
672  }
673
674  map m = (map) Alloc0(sizeof(sip_smap));
675  m->preimage = mstrdup(name);
676  m->m = id->m;
677  m->nrows = id->nrows;
678  m->ncols = id->ncols;
679
680  Free(mlv->lv, sizeof(sleftv));
681
682  FreeL(mlv1->lv->data);
683  Free(mlv1->lv, sizeof(sleftv));
684 
685  Free(id, sizeof(sip_sideal));
686  Free(mlv2->lv, sizeof(sleftv));
687
688  mlv->r = mlv2->r;
689  mlv->lv = mpsr_InitLeftv(MAP_CMD, (void *) m);
690
691  return mpsr_Success;
692}
693
694 
695static mpsr_Status_t GetCopCommandLeftv(MP_Link_pt link, MPT_Node_pt node,
696                                        mpsr_leftv mlv, short quote)
697{
698  short tok;
699  MP_NumChild_t nc = node->numchild, i;
700  mpsr_sleftv smlv1, *mlv1 = &smlv1;
701  MPT_Tree_pt typespec;
702 
703 
704  failr(mpsr_mp2tok(node->dict, MP_COMMON_T(node->nvalue), &tok));
705
706  if ((typespec = MPT_GetProtoTypespec(node)) &&
707      MPT_IsTrueProtoTypeSpec(typespec))
708    return mpsr_SetError(mpsr_CanNotHandlePrototype);
709
710  if (tok == MAP_CMD) return GetMapLeftv(link, node, mlv);
711 
712  if (nc > 0)
713  {
714    if (tok == '=') failr(mpsr_GetLeftv(link, mlv, quote + 1));
715    else failr(mpsr_GetLeftv(link, mlv, quote));
716  }
717
718  for (i=1; i<nc; i++)
719  {
720    failr(mpsr_GetLeftv(link, mlv1, quote));
721    failr(mpsr_MergeLeftv(mlv, mlv1));
722  }
723
724  command cmd = (command) Alloc0(sizeof(sip_command));
725  cmd->op = tok;
726  cmd->argc = nc;
727
728  // check that associative operators are binary
729  if (nc > 2 && (tok == '+' || tok == '*'))
730  {
731    leftv lv = mlv->lv, lv2;
732    command c = cmd, c2;
733
734    for (i=2; i<nc; i++)
735    {
736      c->op = tok;
737      c->argc = 2;
738      memcpy(&(c->arg1), lv, sizeof(sleftv));
739      c->arg1.next = NULL;
740
741      c2 = (command) Alloc0(sizeof(sip_command));
742      c->arg2.data = (void *) c2;
743      c->arg2.rtyp = COMMAND;
744      c = c2;
745      lv2 = lv->next;
746      Free(lv, sizeof(sleftv));
747      lv = lv2;
748    }
749    c->op = tok;
750    c->argc = 2;
751    memcpy(&(c->arg1), lv, sizeof(sleftv));
752    c->arg1.next = NULL;
753    memcpy(&(c->arg2), lv->next, sizeof(sleftv));
754    Free(lv->next, sizeof(sleftv));
755    Free(lv, sizeof(sleftv));
756  }
757  else if (nc >= 1)
758  {
759    memcpy(&(cmd->arg1), mlv->lv, sizeof(sleftv));
760    if (nc <= 3)
761    {
762      (cmd->arg1).next = NULL;
763      if (nc >= 2)
764      {
765        memcpy(&(cmd->arg2), mlv->lv->next, sizeof(sleftv));
766        (cmd->arg2).next = NULL;
767
768        if (nc == 3)
769        {
770          memcpy(&(cmd->arg3), mlv->lv->next->next, sizeof(sleftv));
771          Free(mlv->lv->next->next, sizeof(sleftv));
772        }
773        Free(mlv->lv->next, sizeof(sleftv));
774      }
775    }
776    Free(mlv->lv, sizeof(sleftv));
777  }
778
779  // Now we perform some tree manipulations
780  if (nc == 0 && tok == LIST_CMD)
781    // Here we work around a Singular bug: It can not handle lists of 0 args
782    // so we construct them explicitely
783  {
784    lists l = (lists) Alloc(sizeof(slists));
785    l->Init(0);
786    mlv->lv = mpsr_InitLeftv(LIST_CMD, (void *) l);
787    return mpsr_Success;
788  }
789  mlv->lv = mpsr_InitLeftv(COMMAND, (void *) cmd);
790  return mpsr_Success;
791}
792
793 
794/***************************************************************
795 *
796 * The routine for Getting External Data
797 *
798 ***************************************************************/
799
800// this is all the data we want to have in directly when MPT_GetTree
801// is called, i.e. when the value of annots is read
802MPT_Status_t mpsr_GetExternalData(MP_Link_pt link,
803                                  MPT_Arg_t *odata,
804                                  MPT_Node_pt node)
805{
806  *odata = NULL;
807 
808  if (node->type == MP_CommonOperatorType)
809  {
810    mpsr_sleftv mlv;
811    mpsr_Status_t status;
812
813    // we would like to get polys and ideals directly
814    if (IsPolyNode(node, mlv.r))
815      status = GetPolyLeftv(link, node, &mlv);
816    // Ideal
817    else if (IsIdealNode(node, mlv.r))
818      status = GetIdealLeftv(link, node, &mlv);
819    else
820      return MPT_NotExternalData;
821
822    if (status == mpsr_Success)
823    {
824      mpsr_leftv mmlv = (mpsr_leftv) Alloc0(sizeof(mpsr_sleftv));
825      memcpy(mmlv, &mlv, sizeof(mpsr_sleftv));
826      *odata = (MPT_ExternalData_t) mmlv;
827      return MPT_Success;
828    }
829    else
830      return MPT_Failure;
831  }
832  else
833    return MPT_NotExternalData;
834}
835
836   
837/***************************************************************
838 * 
839 * A routine which gets the previous dump of Singular
840 *
841 ***************************************************************/
842
843mpsr_Status_t mpsr_GetDump(MP_Link_pt link)
844{
845  mpsr_sleftv mlv;
846  mpsr_Status_t status = mpsr_Success;
847
848  MP_SkipMsg(link);
849  while ((! MP_TestEofMsg(link)) && (status == mpsr_Success))
850  {
851    status=mpsr_GetLeftv(link, &mlv, 0);
852
853    if (status == mpsr_Success)
854    {
855#ifdef MPSR_DEBUG
856      command cmd = (command) mlv.lv->data;
857      Print("Dump got %s \n", cmd->arg1.name);
858#endif     
859      mpsr_SetCurrRingHdl(mlv.r);
860      if (mlv.lv != NULL)
861      {
862        mlv.lv->Eval();
863        mlv.lv->CleanUp();
864        Free(mlv.lv, sizeof(sleftv));
865      }
866    }
867    else
868      mpsr_PrintError(status);
869  }
870  return status;
871}
872#endif
Note: See TracBrowser for help on using the repository browser.