source: git/Singular/mpsr_Get.cc @ a492d2

spielwiese
Last change on this file since a492d2 was a492d2, checked in by Olaf Bachmann <obachman@…>, 27 years ago
Sat May 3 00:07:55 1997 Olaf Bachmann <obachman@ratchwum.mathematik.uni-kl.de (Olaf Bachmann)> * small mpsr Changes to reflect some name changes of MP Dicts * configure.in Makefile.in: new schem for updating Makefile mod2.h based on time-stamps git-svn-id: file:///usr/local/Singular/svn/trunk@232 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 22.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4
5/* $Id: mpsr_Get.cc,v 1.10 1997-05-02 22:09:27 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  Free(apint, sizeof(MP_INT));
178  mlv->lv = mpsr_InitLeftv(NUMBER_CMD, n);
179}
180
181inline void InitReal32Leftv(mpsr_leftv mlv, MPT_Arg_t r32)
182{
183  number n = (number) r32;
184//  n = Real32_2_Number(r32);
185
186  mlv->r = mpsr_rDefault(-1);
187  mlv->lv = mpsr_InitLeftv(NUMBER_CMD, n);
188}
189 
190inline void InitIdentifierLeftv(mpsr_leftv mlv, char *name, short quote)
191{
192  int pos;
193 
194  if (quote <= 0)
195  {
196    idhdl h = mpsr_FindIdhdl(name, mlv->r);
197
198    if (h != NULL)
199    {
200      mlv->lv = mpsr_InitLeftv(IDHDL, (void *) h);
201    }
202    else
203    {
204      poly p;
205     
206      pos = mpsr_rDefault(0, name, mlv->r);
207      mpsr_SetCurrRing(mlv->r, TRUE);
208      p = pOne();
209      p->exp[pos+1] = 1;
210      pSetm(p);
211      mlv->lv = mpsr_InitLeftv(POLY_CMD, (void *) p);
212    }
213    FreeL(name);
214  }
215  else
216  {
217    mlv->lv = mpsr_InitLeftv(DEF_CMD, NULL);
218    mlv->lv->name = name;
219  }
220}
221
222/* primitive mpsr_Get*Leftv functions */
223
224inline mpsr_Status_t mpsr_GetIntLeftv(MPT_Node_pt node, mpsr_leftv mlv)
225{
226  mpsr_assume(MP_IsFixedIntegerType(node->type));
227  mlv->lv = mpsr_InitLeftv(INT_CMD, node->nvalue);
228  return mpsr_Success;
229}
230
231inline mpsr_Status_t mpsr_GetReal32Leftv(MPT_Node_pt node, mpsr_leftv mlv) 
232{
233  mpsr_assume(node->type == MP_Real32Type);
234  InitReal32Leftv(mlv, node->nvalue);
235  return mpsr_Success;
236}
237
238inline mpsr_Status_t mpsr_GetApIntLeftv(MPT_Node_pt node, mpsr_leftv mlv)
239{
240  InitApIntLeftv(mlv, (mpz_ptr)  node->nvalue);
241  node->nvalue = NULL;
242  return mpsr_Success;
243}
244
245inline mpsr_Status_t mpsr_GetIdentifierLeftv(MPT_Node_pt node, mpsr_leftv mlv,
246                                             short quote)
247{
248  mpsr_assume(MP_IsIdType(node->type));
249  char *id;
250  MPT_Annot_pt proc_annot = MPT_FindAnnot(node, MP_SingularDict,
251                                          MP_AnnotSingularProcDef);
252
253  if (node->type == MP_CommonGreekIdentifierType ||
254      node->type == MP_CommonGreekIdentifierType)
255  {
256    id  = (char *) AllocL(2*sizeof(char));
257    id[1] = '\0';
258    id[0] = MP_UINT8_T(node->nvalue);
259  }
260  else
261  {
262    id = MP_STRING_T(node->nvalue);
263    node->nvalue = NULL;
264  }
265 
266  InitIdentifierLeftv(mlv, id, quote);
267
268  if (proc_annot != NULL) mlv->lv->rtyp = PROC_CMD;
269   
270  return mpsr_Success;
271}
272
273inline mpsr_Status_t mpsr_GetStringLeftv(MPT_Node_pt node, mpsr_leftv mlv)
274{
275  mpsr_assume(node->type == MP_StringType);
276  mlv->lv = mpsr_InitLeftv(STRING_CMD, MP_STRING_T(node->nvalue));
277  node->nvalue = NULL;
278  return mpsr_Success;
279}
280
281inline mpsr_Status_t GetQuitLeftv(mpsr_leftv mlv)
282{
283  mlv->lv = mpsr_InitLeftv(STRING_CMD, (void *) mstrdup(MPSR_QUIT_STRING));
284  return mpsr_Success;
285}
286
287/***************************************************************
288 *
289 * The top-level routine for getting a message
290 *
291 ***************************************************************/
292mpsr_Status_t mpsr_GetMsg(MP_Link_pt link, leftv &lv)
293{
294  mpsr_sleftv mlv, mlv1;
295  mpsr_Status_t status = mpsr_Success;
296  mlv.lv = NULL;
297  mlv.r = NULL;
298  mlv1.lv = NULL;
299  mlv1.r = NULL;
300
301  status = (MP_InitMsg(link) == MP_Success ? mpsr_Success : mpsr_MP_Failure);
302 
303  if (status == mpsr_Success && ! MP_TestEofMsg(link))
304    status = mpsr_GetLeftv(link, &mlv, 0);
305  else
306  {
307    lv = mpsr_InitLeftv(NONE, NULL);
308    return status;
309  }
310
311  // handle more than one leftv (ie. chains of leftv's)
312  while (status == mpsr_Success && ! MP_TestEofMsg(link))
313  {
314    // Get next leftv
315    status = mpsr_GetLeftv(link, &mlv1, 0);
316    if (status == mpsr_Success)
317      status = mpsr_MergeLeftv(&mlv, &mlv1);
318  }
319
320  if (status == mpsr_Success)
321  {
322    // Now mlv is our leftv -- check whether r has an ordering set
323    if (mlv.r != NULL && mlv.r->order[0] == ringorder_unspec)
324    {
325      ring r = rCopy(mlv.r);
326      r->order[0] = ringorder_lp;
327      mpsr_rSetOrdSgn(r);
328      mpsr_MapLeftv(mlv.lv, mlv.r, r);
329      rKill(mlv.r);
330      mlv.r = r;
331    }
332    mpsr_SetCurrRingHdl(mlv.r);
333
334    lv = mlv.lv;
335  }
336  else lv = mpsr_InitLeftv(NONE, NULL); 
337 
338  return status;
339}
340
341/***************************************************************
342 *
343 * Top-level routine for getting a mpsr_leftv
344 *
345 ***************************************************************/
346
347// if quote > 0, then identifiers are not tried to be resolved, or
348// converted into a ring variable
349mpsr_Status_t mpsr_GetLeftv(MP_Link_pt link, mpsr_leftv mlv, short quote)
350{
351  MPT_Node_pt node = NULL;
352  MP_NodeType_t type;
353  mlv->r = NULL;
354  mlv->lv = NULL;
355
356  mpt_failr(MPT_GetNode(link, &node));
357
358  type = node->type;
359
360  if (MP_IsFixedIntegerType(type))
361    failr(mpsr_GetIntLeftv(node, mlv));
362  else if (MP_IsIdType(type))
363    failr(mpsr_GetIdentifierLeftv(node, mlv, quote));
364  else
365  {
366    switch (node->type)
367    {
368        case MP_ApIntType:
369          failr(mpsr_GetApIntLeftv(node, mlv));
370          break;       
371
372        case MP_StringType:
373          failr(mpsr_GetStringLeftv(node, mlv));
374          break;       
375
376        case MP_Real32Type:
377          failr(mpsr_GetReal32Leftv(node, mlv));
378          break;       
379       
380        case MP_CommonOperatorType:
381          failr(mpsr_GetCommonOperatorLeftv(link, node, mlv, quote));
382          break;       
383
384        case MP_OperatorType:
385          failr(mpsr_GetOperatorLeftv(link, node, mlv, quote));
386          break;       
387
388        default:
389          MPT_DeleteNode(node);
390          return mpsr_SetError(mpsr_UnknownMPNodeType);
391    }
392  }
393 
394  // everything was ok
395  MPT_DeleteNode(node);
396  return mpsr_Success;
397}
398
399/***************************************************************
400 *
401 * mpsr_Get*Leftv
402 *
403 ***************************************************************/
404mpsr_Status_t mpsr_GetCommonOperatorLeftv(MP_Link_pt link,
405                                        MPT_Node_pt node,
406                                        mpsr_leftv mlv,
407                                        short quote)
408{
409  mpsr_assume(node->type == MP_CommonOperatorType);
410
411  // Check for Singular data types
412  // IntVec
413  if (IsIntVecNode(node))
414    return GetIntVecLeftv(link, node, mlv);
415  // IntMat
416  else if (IsIntMatNode(node))
417    return GetIntMatLeftv(link, node, mlv);
418  // Ring
419  else if (IsRingNode(node, mlv->r))
420    return GetRingLeftv(link, node, mlv);
421  // Poly
422  else if (IsPolyNode(node, mlv->r))
423    return GetPolyLeftv(link, node, mlv);
424  // PolyVector
425  else if (IsPolyVectorNode(node, mlv->r))
426    return GetPolyVectorLeftv(link, node, mlv);
427  // Ideal
428  else if (IsIdealNode(node, mlv->r))
429    return GetIdealLeftv(link, node, mlv);
430  // Module
431  else if (IsModuleNode(node, mlv->r))
432    return GetModuleLeftv(link, node, mlv);
433  // Matrix
434  else if (IsMatrixNode(node, mlv->r))
435    return GetMatrixLeftv(link, node, mlv);
436  else if (IsQuitNode(node))
437    return GetQuitLeftv(mlv);
438  // Map
439  else
440    // now it should be a command (which handles Proc, Map and List
441    // seperately)
442    return GetCopCommandLeftv(link, node, mlv, quote);
443}
444
445mpsr_Status_t mpsr_GetOperatorLeftv(MP_Link_pt link,
446                                  MPT_Node_pt node,
447                                  mpsr_leftv mlv,
448                                  short quote)
449{
450  mpsr_assume(node->type == MP_CommonOperatorType);
451  MP_NumChild_t nc = node->numchild, i;
452  mpsr_sleftv smlv1, *mlv1 = &smlv1;
453 
454
455  if (MPT_GetProtoTypespec(node) != NULL)
456    return mpsr_SetError(mpsr_CanNotHandlePrototype);
457
458  if (nc > 0)
459  {
460    failr(mpsr_GetLeftv(link, mlv, quote));
461    for (i=0; i<nc; i++)
462    {
463      failr(mpsr_GetLeftv(link, mlv1, quote));
464      failr(mpsr_MergeLeftv(mlv, mlv1));
465    }
466  }
467 
468  command cmd = (command) Alloc0(sizeof(sip_command));
469  cmd->op = PROC_CMD;
470  cmd->arg1.rtyp = STRING_CMD;
471  cmd->arg1.data = (void *) mstrdup(MP_STRING_T(node->nvalue));
472
473  if (node->numchild > 0)
474  {
475    cmd->argc = 2;
476    memcpy(&(cmd->arg2), mlv->lv, sizeof(sleftv));
477    Free(mlv->lv, sizeof(sleftv));
478  }
479  else cmd->argc = 1;
480
481  mlv->lv = mpsr_InitLeftv(COMMAND, (void *) cmd);
482  return mpsr_Success;
483}
484 
485/***************************************************************
486 *
487 * Get*Leftv routines
488 *
489 ***************************************************************/
490//
491// Get*Leftv routines
492//
493static mpsr_Status_t GetIntVecLeftv(MP_Link_pt link, MPT_Node_pt node,
494                                  mpsr_leftv mlv)
495{
496  intvec *iv = new intvec(node->numchild);
497  int *v = iv->ivGetVec();
498
499  mp_failr(IMP_GetSint32Vector(link, &v, node->numchild));
500  mlv->lv = mpsr_InitLeftv(INTVEC_CMD, (void *) iv);
501  return mpsr_Success;
502}
503
504static mpsr_Status_t GetIntMatLeftv(MP_Link_pt link, MPT_Node_pt node,
505                                  mpsr_leftv mlv)
506{
507  intvec *iv;
508  int row = node->numchild, col = 1, *v;
509  MPT_Annot_pt annot = MPT_FindAnnot(node, MP_MatrixDict,
510                                     MP_AnnotMatrixDimension);
511  if (annot != NULL &&
512      annot->value != NULL &&
513      annot->value->node->numchild == 2 &&
514      NodeCheck(annot->value->node, MP_CommonOperatorType, MP_BasicDict,
515                MP_CopBasicList))
516  {
517    MPT_Tree_pt *tarray = (MPT_Tree_pt *) annot->value->args;
518    if (tarray[0]->node->type == MP_Uint32Type &&
519        tarray[1]->node->type == MP_Uint32Type)
520    {
521      row = MP_UINT32_T(tarray[0]->node->nvalue);
522      col = MP_UINT32_T(tarray[1]->node->nvalue);
523    }
524  }
525
526  iv = new intvec(row, col, 0);
527  v = iv->ivGetVec();
528  mp_failr(IMP_GetSint32Vector(link, &v, node->numchild));
529  mlv->lv = mpsr_InitLeftv(INTMAT_CMD, (void *) iv);
530  return mpsr_Success;
531} 
532
533static mpsr_Status_t GetRingLeftv(MP_Link_pt link, MPT_Node_pt node,
534                                mpsr_leftv mlv)
535{
536  mpsr_assume(mlv->r != NULL);
537
538  if (node->numchild != 0) mpt_failr(MPT_SkipArgs(link, node));
539
540  mlv->lv = mpsr_InitLeftv(((mlv->r->qideal != NULL) ? (short) QRING_CMD :
541                            (short) RING_CMD),
542                           (void *) mlv->r);
543  mlv->r = NULL;
544  return mpsr_Success;
545}
546
547static mpsr_Status_t GetPolyLeftv(MP_Link_pt link, MPT_Node_pt node,
548                                mpsr_leftv mlv)
549{
550  poly p;
551
552  mpsr_assume(mlv->r != NULL);
553 
554  failr(mpsr_GetPoly(link, p, node->numchild, mlv->r));
555  mlv->lv = mpsr_InitLeftv(POLY_CMD, (void *) p);
556  return mpsr_Success;
557}
558
559static mpsr_Status_t GetPolyVectorLeftv(MP_Link_pt link, MPT_Node_pt node,
560                                      mpsr_leftv mlv)
561{
562  poly p;
563
564  mpsr_assume(mlv->r != NULL);
565 
566  failr(mpsr_GetPolyVector(link, p, node->numchild, mlv->r));
567  mlv->lv = mpsr_InitLeftv(VECTOR_CMD, (void *) p);
568  return mpsr_Success;
569}
570
571static mpsr_Status_t GetIdealLeftv(MP_Link_pt link, MPT_Node_pt node,
572                                 mpsr_leftv mlv)
573{
574  MP_NumChild_t nc = node->numchild, i;
575  ring r = mlv->r;
576  MP_Uint32_t nmon;
577
578  mpsr_assume(r != NULL);
579  ideal id = idInit(nc,1);
580  for (i=0; i<nc; i++)
581  {
582    mp_failr(IMP_GetUint32(link, &nmon));
583    failr(mpsr_GetPoly(link, id->m[i], nmon, r));
584  }
585 
586  mlv->lv = mpsr_InitLeftv(IDEAL_CMD, (void *) id);
587  return mpsr_Success;
588}
589
590static mpsr_Status_t GetModuleLeftv(MP_Link_pt link, MPT_Node_pt node,
591                                  mpsr_leftv mlv)
592{
593  MP_NumChild_t nc = node->numchild, i;
594  ring r = mlv->r;
595  MP_Uint32_t nmon;
596
597  mpsr_assume(r != NULL);
598  ideal id = idInit(nc,1);
599  for (i=0; i<nc; i++)
600  {
601    mp_failr(IMP_GetUint32(link, &nmon));
602    failr(mpsr_GetPolyVector(link, id->m[i], nmon, r));
603  }
604
605  mlv->lv = mpsr_InitLeftv(MODUL_CMD, (void *) id);
606  return mpsr_Success;
607}
608
609static mpsr_Status_t GetMatrixLeftv(MP_Link_pt link, MPT_Node_pt node,
610                                  mpsr_leftv mlv)
611{
612  MP_NumChild_t nc = node->numchild, row = nc, col = 1, i;
613  matrix mp;
614  MP_Uint32_t nmon;
615  MPT_Annot_pt annot = MPT_FindAnnot(node, MP_MatrixDict,
616                                     MP_AnnotMatrixDimension);
617  if (annot != NULL &&
618      annot->value != NULL &&
619      annot->value->node->numchild == 2 &&
620      NodeCheck(annot->value->node, MP_CommonOperatorType, MP_BasicDict,
621               MP_CopBasicList))
622  {
623    MPT_Tree_pt *tarray = (MPT_Tree_pt *) annot->value->args;
624    if (tarray[0]->node->type == MP_Uint32Type &&
625        tarray[1]->node->type == MP_Uint32Type)
626    {
627      row = MP_UINT32_T(tarray[0]->node->nvalue);
628      col = MP_UINT32_T(tarray[1]->node->nvalue);
629    }
630  }
631
632  mpsr_assume(mlv->r != NULL);
633  mp = mpNew(row, col);
634  for (i=0; i<nc; i++)
635  {
636    mp_failr(IMP_GetUint32(link, &nmon));
637    failr(mpsr_GetPoly(link, mp->m[i], nmon, mlv->r));
638  }
639
640  mlv->lv = mpsr_InitLeftv(MATRIX_CMD, (void *) mp);
641  return mpsr_Success;
642}
643
644static mpsr_Status_t GetMapLeftv(MP_Link_pt link, MPT_Node_pt node,
645                               mpsr_leftv mlv)
646{
647  mpsr_sleftv smlv1, smlv2, *mlv1 = &smlv1, *mlv2 = &smlv2;
648
649  if (node->numchild != 3)
650    return mpsr_SetError(mpsr_WrongNumofArgs);
651 
652  failr(mpsr_GetLeftv(link, mlv, 0));
653  failr(mpsr_GetLeftv(link, mlv1, 0));
654  failr(mpsr_GetLeftv(link, mlv2, 0));
655
656  if (mlv->lv->rtyp != RING_CMD ||
657      mlv1->lv->rtyp != STRING_CMD ||
658      mlv2->lv->rtyp != IDEAL_CMD)
659    return mpsr_SetError(mpsr_WrongArgumentType);
660
661  ring r = (ring) mlv->lv->data, r2;
662  char *name = (char *) mlv1->lv->data;
663  ideal id = (ideal) mlv2->lv->data;
664
665  idhdl h = mpsr_FindIdhdl(name, r2);
666  if (h == NULL || IDTYP(h) != RING_CMD || ! mpsr_RingEqual(IDRING(h), r))
667  {
668    h = mpsr_InitIdhdl(RING_CMD, r, name);
669    h->next = idroot;
670    idroot = h;
671  }
672
673  map m = (map) Alloc0(sizeof(sip_smap));
674  m->preimage = mstrdup(name);
675  m->m = id->m;
676  m->nrows = id->nrows;
677  m->ncols = id->ncols;
678
679  Free(mlv->lv, sizeof(sleftv));
680
681  FreeL(mlv1->lv->data);
682  Free(mlv1->lv, sizeof(sleftv));
683 
684  Free(id, sizeof(sip_sideal));
685  Free(mlv2->lv, sizeof(sleftv));
686
687  mlv->r = mlv2->r;
688  mlv->lv = mpsr_InitLeftv(MAP_CMD, (void *) m);
689
690  return mpsr_Success;
691}
692
693 
694static mpsr_Status_t GetCopCommandLeftv(MP_Link_pt link, MPT_Node_pt node,
695                                      mpsr_leftv mlv, short quote)
696{
697  short tok;
698  MP_NumChild_t nc = node->numchild, i;
699  mpsr_sleftv smlv1, *mlv1 = &smlv1;
700 
701 
702  failr(mpsr_mp2tok(node->dict, MP_COMMON_T(node->nvalue), &tok));
703
704  if (MPT_GetProtoTypespec(node) != NULL)
705    return mpsr_SetError(mpsr_CanNotHandlePrototype);
706
707  if (tok == MAP_CMD) return GetMapLeftv(link, node, mlv);
708 
709  if (nc > 0)
710  {
711    if (tok == '=') failr(mpsr_GetLeftv(link, mlv, quote + 1));
712    else failr(mpsr_GetLeftv(link, mlv, quote));
713  }
714
715  for (i=1; i<nc; i++)
716  {
717    failr(mpsr_GetLeftv(link, mlv1, quote));
718    failr(mpsr_MergeLeftv(mlv, mlv1));
719  }
720
721  command cmd = (command) Alloc0(sizeof(sip_command));
722  cmd->op = tok;
723  cmd->argc = nc;
724
725  if (nc >= 1)
726  {
727    memcpy(&(cmd->arg1), mlv->lv, sizeof(sleftv));
728    if (nc <= 3)
729    {
730      (cmd->arg1).next = NULL;
731      if (nc >= 2)
732      {
733        memcpy(&(cmd->arg2), mlv->lv->next, sizeof(sleftv));
734        (cmd->arg2).next = NULL;
735
736        if (nc == 3)
737        {
738          memcpy(&(cmd->arg3), mlv->lv->next->next, sizeof(sleftv));
739          Free(mlv->lv->next->next, sizeof(sleftv));
740        }
741        Free(mlv->lv->next, sizeof(sleftv));
742      }
743    }
744    Free(mlv->lv, sizeof(sleftv));
745  }
746  else
747  {
748    // Here we work around a Singular bug: It can not handle lists of 0 args
749    // so we construct them explicitely
750    if (tok == LIST_CMD)
751    {
752      lists l = (lists) Alloc(sizeof(slists));
753      l->Init(0);
754      mlv->lv = mpsr_InitLeftv(LIST_CMD, (void *) l);
755      return mpsr_Success;
756    }
757  }
758
759  mlv->lv = mpsr_InitLeftv(COMMAND, (void *) cmd);
760  return mpsr_Success;
761}
762
763 
764/***************************************************************
765 *
766 * The routine for Getting External Data
767 *
768 ***************************************************************/
769
770// this is all the data we want to have in directly when MPT_GetTree
771// is called, i.e. when the value of annots is read
772MPT_Status_t mpsr_GetExternalData(MP_Link_pt link,
773                                  MPT_Arg_t *odata,
774                                  MPT_Node_pt node)
775{
776  *odata = NULL;
777 
778  if (node->type == MP_CommonOperatorType)
779  {
780    mpsr_sleftv mlv;
781    mpsr_Status_t status;
782
783    // we would like to get polys and ideals directly
784    if (IsPolyNode(node, mlv.r))
785      status = GetPolyLeftv(link, node, &mlv);
786    // Ideal
787    else if (IsIdealNode(node, mlv.r))
788      status = GetIdealLeftv(link, node, &mlv);
789    else
790      return MPT_NotExternalData;
791
792    if (status == mpsr_Success)
793    {
794      mpsr_leftv mmlv = (mpsr_leftv) Alloc0(sizeof(mpsr_sleftv));
795      memcpy(mmlv, &mlv, sizeof(mpsr_sleftv));
796      *odata = (MPT_ExternalData_t) mmlv;
797      return MPT_Success;
798    }
799    else
800      return MPT_Failure;
801  }
802  else
803    return MPT_NotExternalData;
804}
805
806   
807/***************************************************************
808 * 
809 * A routine which gets the previous dump of Singular
810 *
811 ***************************************************************/
812
813mpsr_Status_t mpsr_GetDump(MP_Link_pt link)
814{
815  mpsr_sleftv mlv;
816  mpsr_Status_t status = mpsr_Success;
817
818  MP_SkipMsg(link);
819  while ((! MP_TestEofMsg(link)) && (status == mpsr_Success))
820  {
821    status=mpsr_GetLeftv(link, &mlv, 0);
822
823    if (status == mpsr_Success)
824    {
825#ifdef MPSR_DEBUG
826      command cmd = (command) mlv.lv->data;
827      Print("Dump got %s \n", cmd->arg1.name);
828#endif     
829      mpsr_SetCurrRingHdl(mlv.r);
830      if (mlv.lv != NULL)
831      {
832        mlv.lv->Eval();
833        mlv.lv->CleanUp();
834        Free(mlv.lv, sizeof(sleftv));
835      }
836    }
837    else
838      mpsr_PrintError(status);
839  }
840  return status;
841}
842#endif
Note: See TracBrowser for help on using the repository browser.