source: git/Singular/mpsr_Get.cc @ 3d124a7

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