1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT: handling of leftv |
---|
6 | */ |
---|
7 | |
---|
8 | #include "kernel/mod2.h" |
---|
9 | #include "omalloc/omalloc.h" |
---|
10 | #include "misc/intvec.h" |
---|
11 | #include "misc/options.h" |
---|
12 | #include "coeffs/numbers.h" |
---|
13 | #include "coeffs/bigintmat.h" |
---|
14 | #include "coeffs/ffields.h" // nfShowMipo // minpoly printing... |
---|
15 | #include "polys/monomials/maps.h" |
---|
16 | #include "polys/matpol.h" |
---|
17 | #include "polys/monomials/ring.h" |
---|
18 | |
---|
19 | // #include "coeffs/longrat.h" |
---|
20 | |
---|
21 | #include "kernel/polys.h" |
---|
22 | #include "kernel/ideals.h" |
---|
23 | #include "kernel/GBEngine/kstd1.h" |
---|
24 | #include "kernel/GBEngine/syz.h" |
---|
25 | #include "kernel/oswrapper/timer.h" |
---|
26 | #include "Singular/tok.h" |
---|
27 | #include "Singular/ipid.h" |
---|
28 | #include "Singular/ipshell.h" |
---|
29 | #include "Singular/lists.h" |
---|
30 | #include "Singular/attrib.h" |
---|
31 | #include "Singular/links/silink.h" |
---|
32 | #include "Singular/attrib.h" |
---|
33 | #include "Singular/ipprint.h" |
---|
34 | #include "Singular/subexpr.h" |
---|
35 | #include "Singular/blackbox.h" |
---|
36 | #include "Singular/number2.h" |
---|
37 | |
---|
38 | #include <ctype.h> |
---|
39 | |
---|
40 | VAR omBin sSubexpr_bin = omGetSpecBin(sizeof(_ssubexpr)); |
---|
41 | VAR omBin sleftv_bin = omGetSpecBin(sizeof(sleftv)); |
---|
42 | VAR omBin procinfo_bin = omGetSpecBin(sizeof(procinfo)); |
---|
43 | VAR omBin libstack_bin = omGetSpecBin(sizeof(libstack)); |
---|
44 | STATIC_VAR omBin size_two_bin = omGetSpecBin(2); |
---|
45 | |
---|
46 | INST_VAR sleftv sLastPrinted; |
---|
47 | #ifdef SIQ |
---|
48 | VAR BOOLEAN siq=FALSE; |
---|
49 | #endif |
---|
50 | |
---|
51 | int sleftv::listLength() |
---|
52 | { |
---|
53 | int n = 1; |
---|
54 | leftv sl = next; |
---|
55 | while (sl!=NULL) |
---|
56 | { |
---|
57 | n++; |
---|
58 | sl=sl->next; |
---|
59 | } |
---|
60 | return n; |
---|
61 | } |
---|
62 | |
---|
63 | void sleftv::Print(leftv store, int spaces) |
---|
64 | { |
---|
65 | int t=Typ(); |
---|
66 | if (errorreported) return; |
---|
67 | #ifdef SIQ |
---|
68 | if (rtyp==COMMAND) |
---|
69 | { |
---|
70 | command c=(command)data; |
---|
71 | char ch[2]; |
---|
72 | ch[0]=c->op;ch[1]='\0'; |
---|
73 | const char *s=ch; |
---|
74 | if (c->op>127) s=iiTwoOps(c->op); |
---|
75 | ::Print("##command %d(%s), %d args\n", |
---|
76 | c->op, s, c->argc); |
---|
77 | if (c->argc>0) |
---|
78 | c->arg1.Print(NULL,spaces+2); |
---|
79 | if(c->argc<4) |
---|
80 | { |
---|
81 | if (c->argc>1) |
---|
82 | c->arg2.Print(NULL,spaces+2); |
---|
83 | if (c->argc>2) |
---|
84 | c->arg3.Print(NULL,spaces+2); |
---|
85 | } |
---|
86 | PrintS("##end"); |
---|
87 | } |
---|
88 | else |
---|
89 | #endif |
---|
90 | { |
---|
91 | const char *n=Name(); |
---|
92 | char *s; |
---|
93 | void *d=Data(); |
---|
94 | if (errorreported) return; |
---|
95 | |
---|
96 | switch (t /*=Typ()*/) |
---|
97 | { |
---|
98 | case CRING_CMD: |
---|
99 | crPrint((coeffs)d); |
---|
100 | break; |
---|
101 | #ifdef SINGULAR_4_2 |
---|
102 | case CNUMBER_CMD: |
---|
103 | n2Print((number2)d); |
---|
104 | break; |
---|
105 | case CPOLY_CMD: |
---|
106 | p2Print((poly2)d); |
---|
107 | break; |
---|
108 | case CMATRIX_CMD: // like BIGINTMAT |
---|
109 | #endif |
---|
110 | case BIGINTMAT_CMD: |
---|
111 | ((bigintmat *)d)->pprint(colmax); |
---|
112 | break; |
---|
113 | case BUCKET_CMD: |
---|
114 | { |
---|
115 | sBucket_pt b=(sBucket_pt)d; |
---|
116 | if ((e==NULL) |
---|
117 | && (TEST_V_QRING) |
---|
118 | &&(currRing->qideal!=NULL)) |
---|
119 | { |
---|
120 | poly p=pCopy(sBucketPeek(b)); |
---|
121 | p=jjNormalizeQRingP(p); |
---|
122 | PrintNSpaces(spaces); |
---|
123 | pWrite0(p); |
---|
124 | pDelete(&p); |
---|
125 | break; |
---|
126 | } |
---|
127 | else |
---|
128 | sBucketPrint(b); |
---|
129 | } |
---|
130 | break; |
---|
131 | case UNKNOWN: |
---|
132 | case DEF_CMD: |
---|
133 | PrintNSpaces(spaces); |
---|
134 | PrintS("`");PrintS(n);PrintS("`"); |
---|
135 | break; |
---|
136 | case PACKAGE_CMD: |
---|
137 | PrintNSpaces(spaces); |
---|
138 | paPrint(n,(package)d); |
---|
139 | break; |
---|
140 | case LIB_CMD: |
---|
141 | case NONE: |
---|
142 | return; |
---|
143 | case INTVEC_CMD: |
---|
144 | case INTMAT_CMD: |
---|
145 | ((intvec *)d)->show(t,spaces); |
---|
146 | break; |
---|
147 | case RING_CMD: |
---|
148 | { |
---|
149 | PrintNSpaces(spaces); |
---|
150 | const ring r = (const ring)d; |
---|
151 | rWrite(r, currRing == r); |
---|
152 | break; |
---|
153 | } |
---|
154 | case MATRIX_CMD: |
---|
155 | iiWriteMatrix((matrix)d,n,2, currRing, spaces); |
---|
156 | break; |
---|
157 | case SMATRIX_CMD: |
---|
158 | { |
---|
159 | matrix m = id_Module2Matrix(id_Copy((ideal)d,currRing),currRing); |
---|
160 | ipPrint_MA0(m, n); |
---|
161 | id_Delete((ideal *) &m,currRing); |
---|
162 | break; |
---|
163 | } |
---|
164 | case MODUL_CMD: |
---|
165 | case IDEAL_CMD: |
---|
166 | if ((TEST_V_QRING) &&(currRing->qideal!=NULL) |
---|
167 | &&(!hasFlag(this,FLAG_QRING))) |
---|
168 | { |
---|
169 | jjNormalizeQRingId(this); |
---|
170 | d=Data(); |
---|
171 | } |
---|
172 | // no break: |
---|
173 | case MAP_CMD: |
---|
174 | iiWriteMatrix((matrix)d,n,1, currRing, spaces); |
---|
175 | break; |
---|
176 | case POLY_CMD: |
---|
177 | case VECTOR_CMD: |
---|
178 | if ((e==NULL) |
---|
179 | && (TEST_V_QRING) |
---|
180 | &&(currRing->qideal!=NULL) |
---|
181 | &&(!hasFlag(this,FLAG_QRING))) |
---|
182 | { |
---|
183 | setFlag(this,FLAG_QRING); |
---|
184 | poly p=(poly)d; |
---|
185 | p=jjNormalizeQRingP(p); |
---|
186 | if (p!=(poly)d) |
---|
187 | { |
---|
188 | d=(void*)p; |
---|
189 | if ((rtyp==POLY_CMD)||(rtyp==VECTOR_CMD)) data=d; |
---|
190 | else if (rtyp==IDHDL) |
---|
191 | { |
---|
192 | idhdl h=(idhdl)data; |
---|
193 | IDPOLY(h)=p; |
---|
194 | setFlag(h,FLAG_QRING); |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | PrintNSpaces(spaces); |
---|
199 | pWrite0((poly)d); |
---|
200 | break; |
---|
201 | case RESOLUTION_CMD: |
---|
202 | { |
---|
203 | syStrategy tmp=(syStrategy)d; |
---|
204 | syPrint(tmp,IDID(currRingHdl)); |
---|
205 | break; |
---|
206 | } |
---|
207 | case STRING_CMD: |
---|
208 | PrintNSpaces(spaces); |
---|
209 | PrintS((char *)d); |
---|
210 | break; |
---|
211 | case INT_CMD: |
---|
212 | PrintNSpaces(spaces); |
---|
213 | ::Print("%d",(int)(long)d); |
---|
214 | break; |
---|
215 | case PROC_CMD: |
---|
216 | { |
---|
217 | procinfov pi=(procinfov)d; |
---|
218 | |
---|
219 | PrintNSpaces(spaces); |
---|
220 | PrintS("// libname : "); |
---|
221 | PrintS(piProcinfo(pi, "libname")); |
---|
222 | PrintLn(); |
---|
223 | |
---|
224 | PrintNSpaces(spaces); |
---|
225 | PrintS("// procname : "); |
---|
226 | PrintS(piProcinfo(pi, "procname")); |
---|
227 | PrintLn(); |
---|
228 | |
---|
229 | PrintNSpaces(spaces); |
---|
230 | PrintS("// type : "); |
---|
231 | PrintS(piProcinfo(pi, "type")); |
---|
232 | // ::Print("%-*.*s// ref : %s",spaces,spaces," ", |
---|
233 | // piProcinfo(pi, "ref")); |
---|
234 | break; |
---|
235 | } |
---|
236 | case LINK_CMD: |
---|
237 | { |
---|
238 | si_link l=(si_link)d; |
---|
239 | PrintNSpaces(spaces); |
---|
240 | ::Print("// type : %s\n", slStatus(l, "type")); |
---|
241 | PrintNSpaces(spaces); |
---|
242 | ::Print("// mode : %s\n", slStatus(l, "mode")); |
---|
243 | PrintNSpaces(spaces); |
---|
244 | ::Print("// name : %s\n", slStatus(l, "name")); |
---|
245 | PrintNSpaces(spaces); |
---|
246 | ::Print("// open : %s\n", slStatus(l, "open")); |
---|
247 | PrintNSpaces(spaces); |
---|
248 | ::Print("// read : %s\n", slStatus(l, "read")); |
---|
249 | PrintNSpaces(spaces); |
---|
250 | ::Print("// write: %s", slStatus(l, "write")); |
---|
251 | break; |
---|
252 | } |
---|
253 | case BIGINT_CMD: |
---|
254 | s=String(d); |
---|
255 | if (s==NULL) return; |
---|
256 | PrintNSpaces(spaces); |
---|
257 | PrintS(s); |
---|
258 | omFree((ADDRESS)s); |
---|
259 | break; |
---|
260 | case NUMBER_CMD: |
---|
261 | { |
---|
262 | number n=(number)d; |
---|
263 | nNormalize(n); |
---|
264 | if ((number)d !=n) |
---|
265 | { |
---|
266 | d=n; |
---|
267 | if (rtyp==IDHDL) IDNUMBER(((idhdl)data))=n; |
---|
268 | else if(rtyp==NUMBER_CMD) data=(void*)n; |
---|
269 | } |
---|
270 | s=String(d); |
---|
271 | if (s==NULL) return; |
---|
272 | PrintS(s); |
---|
273 | omFree((ADDRESS)s); |
---|
274 | break; |
---|
275 | } |
---|
276 | case LIST_CMD: |
---|
277 | { |
---|
278 | lists l=(lists)d; |
---|
279 | if (lSize(l)<0) |
---|
280 | { |
---|
281 | PrintNSpaces(spaces); |
---|
282 | PrintS("empty list\n"); |
---|
283 | } |
---|
284 | else |
---|
285 | { |
---|
286 | int i=0; |
---|
287 | for (;i<=l->nr;i++) |
---|
288 | { |
---|
289 | if (l->m[i].rtyp!=DEF_CMD) |
---|
290 | { |
---|
291 | PrintNSpaces(spaces); |
---|
292 | ::Print("[%d]:\n",i+1); |
---|
293 | l->m[i].Print(NULL,spaces+3); |
---|
294 | } |
---|
295 | } |
---|
296 | } |
---|
297 | break; |
---|
298 | } |
---|
299 | |
---|
300 | default: |
---|
301 | if (t>MAX_TOK) |
---|
302 | { |
---|
303 | blackbox * bb=getBlackboxStuff(t); |
---|
304 | PrintNSpaces(spaces); |
---|
305 | if (bb!=NULL) { bb->blackbox_Print(bb,d); } |
---|
306 | else { ::Print("Print: blackbox %d(bb=NULL)",t); } |
---|
307 | } |
---|
308 | else |
---|
309 | ::Print("Print:unknown type %s(%d)", Tok2Cmdname(t),t); |
---|
310 | } /* end switch: (Typ()) */ |
---|
311 | if ((store!=NULL)&&(store!=this)) |
---|
312 | store->CleanUp(); |
---|
313 | } |
---|
314 | if (next!=NULL) |
---|
315 | { |
---|
316 | if (t==COMMAND) PrintLn(); |
---|
317 | else if (t!=LIST_CMD) PrintS(" "); |
---|
318 | next->Print(NULL,spaces); |
---|
319 | } |
---|
320 | else if ((t!=LIST_CMD)&&(t!=SMATRIX_CMD)) |
---|
321 | { |
---|
322 | PrintLn(); |
---|
323 | } |
---|
324 | #ifdef SIQ |
---|
325 | if (rtyp!=COMMAND) |
---|
326 | #endif |
---|
327 | { |
---|
328 | if ((store!=NULL) |
---|
329 | && (store!=this)) |
---|
330 | { |
---|
331 | if((t/*Typ()*/!=LINK_CMD) |
---|
332 | && (t/*Typ()*/!=PACKAGE_CMD) |
---|
333 | && (t/*Typ()*/!=DEF_CMD) |
---|
334 | ) |
---|
335 | { |
---|
336 | store->rtyp=t/*Typ()*/; |
---|
337 | store->data=CopyD(); |
---|
338 | if(attribute!=NULL) |
---|
339 | { |
---|
340 | store->attribute=CopyA(); |
---|
341 | } |
---|
342 | store->flag=flag; |
---|
343 | } |
---|
344 | } |
---|
345 | } |
---|
346 | } |
---|
347 | |
---|
348 | void sleftv::CleanUp(ring r) |
---|
349 | { |
---|
350 | if (rtyp!=IDHDL) |
---|
351 | { |
---|
352 | if ((name!=NULL) && (name!=sNoName_fe) && (rtyp!=ALIAS_CMD)) |
---|
353 | { |
---|
354 | //::Print("free %x (%s)\n",name,name); |
---|
355 | omFree((ADDRESS)name); // may be larger >1000 char (large int) |
---|
356 | } |
---|
357 | //name=NULL; |
---|
358 | //flag=0; |
---|
359 | if (data!=NULL) |
---|
360 | { |
---|
361 | //if (rtyp==IDHDL) attribute=NULL; // is only a pointer to attribute of id |
---|
362 | s_internalDelete(rtyp,data,r); |
---|
363 | //data=NULL; // will be done by Init() at the end |
---|
364 | } |
---|
365 | if (attribute!=NULL) |
---|
366 | { |
---|
367 | switch (rtyp) |
---|
368 | { |
---|
369 | case PACKAGE_CMD: |
---|
370 | //case IDHDL: |
---|
371 | case ANY_TYPE: |
---|
372 | case VECHO: |
---|
373 | case VPRINTLEVEL: |
---|
374 | case VCOLMAX: |
---|
375 | case VTIMER: |
---|
376 | case VRTIMER: |
---|
377 | case VOICE: |
---|
378 | case VMAXDEG: |
---|
379 | case VMAXMULT: |
---|
380 | case TRACE: |
---|
381 | case VSHORTOUT: |
---|
382 | case VNOETHER: |
---|
383 | case VMINPOLY: |
---|
384 | case 0: |
---|
385 | //attribute=NULL; // will be done by Init() at the end |
---|
386 | break; |
---|
387 | default: |
---|
388 | { |
---|
389 | attribute->killAll(r); |
---|
390 | } |
---|
391 | } |
---|
392 | } |
---|
393 | } |
---|
394 | Subexpr h; |
---|
395 | while (e!=NULL) |
---|
396 | { |
---|
397 | h=e->next; |
---|
398 | omFreeBin((ADDRESS)e, sSubexpr_bin); |
---|
399 | e=h; |
---|
400 | } |
---|
401 | //rtyp=NONE; // will be done by Init() at the end |
---|
402 | if (next!=NULL) |
---|
403 | { |
---|
404 | leftv tmp_n; |
---|
405 | do |
---|
406 | { |
---|
407 | tmp_n=next->next; |
---|
408 | //next->name=NULL; |
---|
409 | next->next=NULL; |
---|
410 | next->CleanUp(r); |
---|
411 | omFreeBin((ADDRESS)next, sleftv_bin); |
---|
412 | next=tmp_n; |
---|
413 | } while (next!=NULL); |
---|
414 | } |
---|
415 | Init(); |
---|
416 | } |
---|
417 | |
---|
418 | BOOLEAN sleftv::RingDependend() |
---|
419 | { |
---|
420 | int rt=Typ(); |
---|
421 | if(::RingDependend(rt)) |
---|
422 | return TRUE; |
---|
423 | if (rt==LIST_CMD) |
---|
424 | return lRingDependend((lists)Data()); |
---|
425 | if (this->next!=NULL) |
---|
426 | return this->next->RingDependend(); |
---|
427 | return FALSE; |
---|
428 | } |
---|
429 | |
---|
430 | static inline void * s_internalCopy(const int t, void *d) |
---|
431 | { |
---|
432 | switch (t) |
---|
433 | { |
---|
434 | case CRING_CMD: |
---|
435 | { |
---|
436 | coeffs cf=(coeffs)d; |
---|
437 | cf->ref++; |
---|
438 | return (void*)d; |
---|
439 | } |
---|
440 | #ifdef SINGULAR_4_2 |
---|
441 | case CNUMBER_CMD: |
---|
442 | return (void*)n2Copy((number2)d); |
---|
443 | case CPOLY_CMD: |
---|
444 | return (void*)p2Copy((poly2)d); |
---|
445 | case CMATRIX_CMD: // like BIGINTMAT |
---|
446 | #endif |
---|
447 | case BIGINTMAT_CMD: |
---|
448 | return (void*)bimCopy((bigintmat *)d); |
---|
449 | case BUCKET_CMD: |
---|
450 | return (void*)sBucketCopy((sBucket_pt)d); |
---|
451 | case INTVEC_CMD: |
---|
452 | case INTMAT_CMD: |
---|
453 | return (void *)ivCopy((intvec *)d); |
---|
454 | case MATRIX_CMD: |
---|
455 | return (void *)mp_Copy((matrix)d, currRing); |
---|
456 | case SMATRIX_CMD: |
---|
457 | case IDEAL_CMD: |
---|
458 | case MODUL_CMD: |
---|
459 | return (void *)idCopy((ideal)d); |
---|
460 | case STRING_CMD: |
---|
461 | return (void *)omStrDup((char *)d); |
---|
462 | case PACKAGE_CMD: |
---|
463 | return (void *)paCopy((package) d); |
---|
464 | case PROC_CMD: |
---|
465 | return (void *)piCopy((procinfov) d); |
---|
466 | case POLY_CMD: |
---|
467 | case VECTOR_CMD: |
---|
468 | return (void *)pCopy((poly)d); |
---|
469 | case INT_CMD: |
---|
470 | return d; |
---|
471 | case NUMBER_CMD: |
---|
472 | return (void *)nCopy((number)d); |
---|
473 | case BIGINT_CMD: |
---|
474 | return (void *)n_Copy((number)d, coeffs_BIGINT); |
---|
475 | case MAP_CMD: |
---|
476 | return (void *)maCopy((map)d, currRing); |
---|
477 | case LIST_CMD: |
---|
478 | return (void *)lCopy((lists)d); |
---|
479 | case LINK_CMD: |
---|
480 | return (void *)slCopy((si_link) d); |
---|
481 | case RING_CMD: |
---|
482 | { |
---|
483 | ring r=(ring)d; |
---|
484 | if (r!=NULL) |
---|
485 | { |
---|
486 | r->ref++; |
---|
487 | //Print("s_internalCopy:+ ring %lx, ref %d\n",r,r->ref); |
---|
488 | } |
---|
489 | return d; |
---|
490 | } |
---|
491 | case RESOLUTION_CMD: |
---|
492 | return (void*)syCopy((syStrategy)d); |
---|
493 | case DEF_CMD: |
---|
494 | case NONE: |
---|
495 | case 0: /* type in error case */ |
---|
496 | break; /* error recovery: do nothing */ |
---|
497 | //case COMMAND: |
---|
498 | default: |
---|
499 | { |
---|
500 | if (t>MAX_TOK) |
---|
501 | { |
---|
502 | blackbox *b=getBlackboxStuff(t); |
---|
503 | if (b!=NULL) return b->blackbox_Copy(b,d); |
---|
504 | return NULL; |
---|
505 | } |
---|
506 | else |
---|
507 | Warn("s_internalCopy: cannot copy type %s(%d)", |
---|
508 | Tok2Cmdname(t),t); |
---|
509 | } |
---|
510 | } |
---|
511 | return NULL; |
---|
512 | } |
---|
513 | |
---|
514 | void s_internalDelete(const int t, void *d, const ring r) |
---|
515 | { |
---|
516 | assume(d!=NULL); |
---|
517 | switch (t) |
---|
518 | { |
---|
519 | case CRING_CMD: |
---|
520 | { |
---|
521 | coeffs cf=(coeffs)d; |
---|
522 | if ((cf->ref<1)&& |
---|
523 | ((cf->type <=n_GF) |
---|
524 | ||((cf->type >=n_long_C)&&(cf->type <=n_CF)))) |
---|
525 | { |
---|
526 | Warn("cannot kill `%s`",nCoeffName(cf)); |
---|
527 | } |
---|
528 | else // allow nKillChar for n_long_R, extensions, and user defined: |
---|
529 | nKillChar((coeffs)d); |
---|
530 | break; |
---|
531 | } |
---|
532 | #ifdef SINGULAR_4_2 |
---|
533 | case CNUMBER_CMD: |
---|
534 | { |
---|
535 | number2 n=(number2)d; |
---|
536 | n2Delete(n); |
---|
537 | break; |
---|
538 | } |
---|
539 | case CPOLY_CMD: |
---|
540 | { |
---|
541 | poly2 n=(poly2)d; |
---|
542 | p2Delete(n); |
---|
543 | break; |
---|
544 | } |
---|
545 | case CMATRIX_CMD: //like BIGINTMAT |
---|
546 | #endif |
---|
547 | case BIGINTMAT_CMD: |
---|
548 | { |
---|
549 | bigintmat *v=(bigintmat*)d; |
---|
550 | delete v; |
---|
551 | break; |
---|
552 | } |
---|
553 | case BUCKET_CMD: |
---|
554 | { |
---|
555 | sBucket_pt b=(sBucket_pt)d; |
---|
556 | sBucketDeleteAndDestroy(&b); |
---|
557 | break; |
---|
558 | } |
---|
559 | case INTVEC_CMD: |
---|
560 | case INTMAT_CMD: |
---|
561 | { |
---|
562 | intvec *v=(intvec*)d; |
---|
563 | delete v; |
---|
564 | break; |
---|
565 | } |
---|
566 | case MAP_CMD: |
---|
567 | { |
---|
568 | map m=(map)d; |
---|
569 | omFreeBinAddr((ADDRESS)m->preimage); |
---|
570 | m->preimage=NULL; |
---|
571 | /* no break: continue as IDEAL*/ |
---|
572 | } |
---|
573 | case SMATRIX_CMD: |
---|
574 | case MATRIX_CMD: |
---|
575 | case IDEAL_CMD: |
---|
576 | case MODUL_CMD: |
---|
577 | { |
---|
578 | ideal i=(ideal)d; |
---|
579 | id_Delete(&i,r); |
---|
580 | break; |
---|
581 | } |
---|
582 | case STRING_CMD: |
---|
583 | omFree(d); |
---|
584 | break; |
---|
585 | //case PACKAGE_CMD: |
---|
586 | // return (void *)paCopy((package) d); |
---|
587 | case PROC_CMD: |
---|
588 | piKill((procinfo*)d); |
---|
589 | break; |
---|
590 | case POLY_CMD: |
---|
591 | case VECTOR_CMD: |
---|
592 | { |
---|
593 | poly p=(poly)d; |
---|
594 | p_Delete(&p,r); |
---|
595 | break; |
---|
596 | } |
---|
597 | case NUMBER_CMD: |
---|
598 | { |
---|
599 | number n=(number)d; |
---|
600 | n_Delete(&n,r->cf); |
---|
601 | break; |
---|
602 | } |
---|
603 | case BIGINT_CMD: |
---|
604 | { |
---|
605 | number n=(number)d; |
---|
606 | n_Delete(&n,coeffs_BIGINT); |
---|
607 | break; |
---|
608 | } |
---|
609 | case LIST_CMD: |
---|
610 | { |
---|
611 | lists l=(lists)d; |
---|
612 | l->Clean(r); |
---|
613 | break; |
---|
614 | } |
---|
615 | case LINK_CMD: |
---|
616 | { |
---|
617 | si_link l=(si_link)d; |
---|
618 | slKill(l); |
---|
619 | break; |
---|
620 | } |
---|
621 | case RING_CMD: |
---|
622 | { |
---|
623 | ring R=(ring)d; |
---|
624 | if ((R!=currRing)||(R->ref>=0)) |
---|
625 | rKill(R); |
---|
626 | #ifdef TEST |
---|
627 | else |
---|
628 | Print("currRing? ref=%d\n",R->ref); |
---|
629 | #endif |
---|
630 | break; |
---|
631 | } |
---|
632 | case RESOLUTION_CMD: |
---|
633 | { |
---|
634 | syStrategy s=(syStrategy)d; |
---|
635 | if (s!=NULL) syKillComputation(s,r); |
---|
636 | break; |
---|
637 | } |
---|
638 | case COMMAND: |
---|
639 | { |
---|
640 | command cmd=(command)d; |
---|
641 | if (cmd->arg1.rtyp!=0) cmd->arg1.CleanUp(r); |
---|
642 | if (cmd->arg2.rtyp!=0) cmd->arg2.CleanUp(r); |
---|
643 | if (cmd->arg3.rtyp!=0) cmd->arg3.CleanUp(r); |
---|
644 | omFreeBin((ADDRESS)d, sip_command_bin); |
---|
645 | break; |
---|
646 | } |
---|
647 | case INT_CMD: |
---|
648 | case DEF_CMD: |
---|
649 | case ALIAS_CMD: |
---|
650 | case PACKAGE_CMD: |
---|
651 | case IDHDL: |
---|
652 | case NONE: |
---|
653 | case ANY_TYPE: |
---|
654 | case VECHO: |
---|
655 | case VPRINTLEVEL: |
---|
656 | case VCOLMAX: |
---|
657 | case VTIMER: |
---|
658 | case VRTIMER: |
---|
659 | case VOICE: |
---|
660 | case VMAXDEG: |
---|
661 | case VMAXMULT: |
---|
662 | case TRACE: |
---|
663 | case VSHORTOUT: |
---|
664 | case VNOETHER: |
---|
665 | case VMINPOLY: |
---|
666 | case 0: /* type in error case */ |
---|
667 | break; /* error recovery: do nothing */ |
---|
668 | //case COMMAND: |
---|
669 | //case COMMAND: |
---|
670 | default: |
---|
671 | { |
---|
672 | if (t>MAX_TOK) |
---|
673 | { |
---|
674 | blackbox *b=getBlackboxStuff(t); |
---|
675 | if (b!=NULL) b->blackbox_destroy(b,d); |
---|
676 | break; |
---|
677 | } |
---|
678 | else |
---|
679 | Warn("s_internalDelete: cannot delete type %s(%d)", |
---|
680 | Tok2Cmdname(t),t); |
---|
681 | } |
---|
682 | } |
---|
683 | } |
---|
684 | |
---|
685 | void sleftv::Copy(leftv source) |
---|
686 | { |
---|
687 | Init(); |
---|
688 | rtyp=source->Typ(); |
---|
689 | void *d=source->Data(); |
---|
690 | if(!errorreported) |
---|
691 | { |
---|
692 | if (rtyp==BUCKET_CMD) |
---|
693 | { |
---|
694 | rtyp=POLY_CMD; |
---|
695 | data=(void*)pCopy(sBucketPeek((sBucket_pt)d)); |
---|
696 | } |
---|
697 | else |
---|
698 | data=s_internalCopy(rtyp,d); |
---|
699 | if ((source->attribute!=NULL)||(source->e!=NULL)) |
---|
700 | attribute=source->CopyA(); |
---|
701 | flag=source->flag; |
---|
702 | if (source->next!=NULL) |
---|
703 | { |
---|
704 | next=(leftv)omAllocBin(sleftv_bin); |
---|
705 | next->Copy(source->next); |
---|
706 | } |
---|
707 | } |
---|
708 | } |
---|
709 | |
---|
710 | void * sleftv::CopyD(int t) |
---|
711 | { |
---|
712 | if ((rtyp!=IDHDL)&&(rtyp!=ALIAS_CMD)&&(e==NULL)) |
---|
713 | { |
---|
714 | if (iiCheckRing(t)) return NULL; |
---|
715 | void *x = data; |
---|
716 | if (rtyp==VNOETHER) x = (void *)pCopy((currRing->ppNoether)); |
---|
717 | else if ((rtyp==VMINPOLY) && nCoeff_is_algExt(currRing->cf) && (!nCoeff_is_GF(currRing->cf))) |
---|
718 | { |
---|
719 | const ring A = currRing->cf->extRing; |
---|
720 | |
---|
721 | assume( A != NULL ); |
---|
722 | assume( A->qideal != NULL ); |
---|
723 | |
---|
724 | x=(void *)p_Copy(A->qideal->m[0], A); |
---|
725 | } |
---|
726 | data=NULL; |
---|
727 | return x; |
---|
728 | } |
---|
729 | void *d=Data(); // will also do a iiCheckRing |
---|
730 | if ((!errorreported) && (d!=NULL)) return s_internalCopy(t,d); |
---|
731 | return NULL; |
---|
732 | } |
---|
733 | |
---|
734 | //void * sleftv::CopyD() |
---|
735 | //{ |
---|
736 | //if ((rtyp!=IDHDL)&&(e==NULL) |
---|
737 | //&&(rtyp!=VNOETHER)&&(rtyp!=VMINPOLY)) |
---|
738 | //{ |
---|
739 | // void *x=data; |
---|
740 | // data=NULL; |
---|
741 | // return x; |
---|
742 | //} |
---|
743 | // return CopyD(Typ()); |
---|
744 | //} |
---|
745 | |
---|
746 | attr sleftv::CopyA() |
---|
747 | { |
---|
748 | attr *a=Attribute(); |
---|
749 | if ((a!=NULL) && (*a!=NULL)) |
---|
750 | return (*a)->Copy(); |
---|
751 | return NULL; |
---|
752 | } |
---|
753 | |
---|
754 | char * sleftv::String(void *d, BOOLEAN typed, int dim) |
---|
755 | { |
---|
756 | #ifdef SIQ |
---|
757 | if (rtyp==COMMAND) |
---|
758 | { |
---|
759 | ::Print("##command %d\n",((command)data)->op); |
---|
760 | if (((command)data)->arg1.rtyp!=0) |
---|
761 | ((command)data)->arg1.Print(NULL,2); |
---|
762 | if (((command)data)->arg2.rtyp!=0) |
---|
763 | ((command)data)->arg2.Print(NULL,2); |
---|
764 | if (((command)data)->arg3.rtyp==0) |
---|
765 | ((command)data)->arg3.Print(NULL,2); |
---|
766 | PrintS("##end\n"); |
---|
767 | return omStrDup(""); |
---|
768 | } |
---|
769 | #endif |
---|
770 | if (d==NULL) d=Data(); |
---|
771 | if (!errorreported) |
---|
772 | { |
---|
773 | char *s; |
---|
774 | int t=Typ(); |
---|
775 | switch (t /*Typ()*/) |
---|
776 | { |
---|
777 | case INT_CMD: |
---|
778 | if (typed) |
---|
779 | { |
---|
780 | s=(char *)omAlloc(MAX_INT_LEN+7); |
---|
781 | sprintf(s,"int(%d)",(int)(long)d); |
---|
782 | } |
---|
783 | else |
---|
784 | { |
---|
785 | s=(char *)omAlloc(MAX_INT_LEN+2); |
---|
786 | sprintf(s,"%d",(int)(long)d); |
---|
787 | } |
---|
788 | return s; |
---|
789 | |
---|
790 | case STRING_CMD: |
---|
791 | if (d == NULL) |
---|
792 | { |
---|
793 | if (typed) return omStrDup("\"\""); |
---|
794 | return omStrDup(""); |
---|
795 | } |
---|
796 | if (typed) |
---|
797 | { |
---|
798 | s = (char*) omAlloc(strlen((char*) d) + 3); |
---|
799 | sprintf(s,"\"%s\"", (char*) d); |
---|
800 | return s; |
---|
801 | } |
---|
802 | else |
---|
803 | { |
---|
804 | return omStrDup((char*)d); |
---|
805 | } |
---|
806 | |
---|
807 | case POLY_CMD: |
---|
808 | case VECTOR_CMD: |
---|
809 | if (typed) |
---|
810 | { |
---|
811 | char* ps = pString((poly) d); |
---|
812 | s = (char*) omAlloc(strlen(ps) + 10); |
---|
813 | sprintf(s,"%s(%s)", (t /*Typ()*/ == POLY_CMD ? "poly" : "vector"), ps); |
---|
814 | omFree(ps); |
---|
815 | return s; |
---|
816 | } |
---|
817 | else |
---|
818 | return pString((poly)d); |
---|
819 | |
---|
820 | case CRING_CMD: |
---|
821 | return nCoeffString((coeffs)d); |
---|
822 | #ifdef SINGULAR_4_2 |
---|
823 | case CNUMBER_CMD: |
---|
824 | return n2String((number2)d,typed); |
---|
825 | case CMATRIX_CMD: |
---|
826 | { |
---|
827 | bigintmat *b=(bigintmat*)d; |
---|
828 | return b->String(); |
---|
829 | } |
---|
830 | #endif |
---|
831 | |
---|
832 | case NUMBER_CMD: |
---|
833 | StringSetS((char*) (typed ? "number(" : "")); |
---|
834 | if((rtyp==VMINPOLY)&&(rField_is_GF(currRing))) |
---|
835 | { |
---|
836 | nfShowMipo(currRing->cf); |
---|
837 | } |
---|
838 | else |
---|
839 | { |
---|
840 | nWrite((number)d); |
---|
841 | } |
---|
842 | StringAppendS((char*) (typed ? ")" : "")); |
---|
843 | return StringEndS(); |
---|
844 | |
---|
845 | case BIGINT_CMD: |
---|
846 | { |
---|
847 | StringSetS((char*) (typed ? "bigint(" : "")); |
---|
848 | number nl=(number)d; |
---|
849 | n_Write(nl,coeffs_BIGINT); |
---|
850 | StringAppendS((char*) (typed ? ")" : "")); |
---|
851 | return StringEndS(); |
---|
852 | } |
---|
853 | case BUCKET_CMD: |
---|
854 | return sBucketString((sBucket_pt)d); |
---|
855 | case MATRIX_CMD: |
---|
856 | s= iiStringMatrix((matrix)d,dim, currRing); |
---|
857 | if (typed) |
---|
858 | { |
---|
859 | char* ns = (char*) omAlloc(strlen(s) + 40); |
---|
860 | sprintf(ns, "matrix(ideal(%s),%d,%d)", s, |
---|
861 | ((ideal) d)->nrows, ((ideal) d)->ncols); |
---|
862 | omCheckAddr(ns); |
---|
863 | return ns; |
---|
864 | } |
---|
865 | else |
---|
866 | { |
---|
867 | return omStrDup(s); |
---|
868 | } |
---|
869 | |
---|
870 | case IDEAL_CMD: |
---|
871 | case MAP_CMD: |
---|
872 | case MODUL_CMD: |
---|
873 | case SMATRIX_CMD: |
---|
874 | s= iiStringMatrix((matrix)d,dim, currRing); |
---|
875 | if (typed) |
---|
876 | { |
---|
877 | char* ns = (char*) omAlloc(strlen(s) + 10); |
---|
878 | if ((t/*Typ()*/==IDEAL_CMD)||(t==MAP_CMD)) |
---|
879 | sprintf(ns, "ideal(%s)", s); |
---|
880 | else /*MODUL_CMD, SMATRIX_CMD */ |
---|
881 | sprintf(ns, "module(%s)", s); |
---|
882 | omFree(s); |
---|
883 | omCheckAddr(ns); |
---|
884 | return ns; |
---|
885 | } |
---|
886 | return s; |
---|
887 | |
---|
888 | case INTVEC_CMD: |
---|
889 | case INTMAT_CMD: |
---|
890 | { |
---|
891 | intvec *v=(intvec *)d; |
---|
892 | s = v->String(dim); |
---|
893 | if (typed) |
---|
894 | { |
---|
895 | char* ns; |
---|
896 | if (t/*Typ()*/ == INTMAT_CMD) |
---|
897 | { |
---|
898 | ns = (char*) omAlloc(strlen(s) + 40); |
---|
899 | sprintf(ns, "intmat(intvec(%s),%d,%d)", s, v->rows(), v->cols()); |
---|
900 | } |
---|
901 | else |
---|
902 | { |
---|
903 | ns = (char*) omAlloc(strlen(s) + 10); |
---|
904 | sprintf(ns, "intvec(%s)", s); |
---|
905 | } |
---|
906 | omCheckAddr(ns); |
---|
907 | omFree(s); |
---|
908 | return ns; |
---|
909 | } |
---|
910 | else |
---|
911 | return s; |
---|
912 | } |
---|
913 | case BIGINTMAT_CMD: |
---|
914 | { |
---|
915 | bigintmat *bim=(bigintmat*)d; |
---|
916 | s = bim->String(); |
---|
917 | if (typed) |
---|
918 | { |
---|
919 | char* ns = (char*) omAlloc0(strlen(s) + 40); |
---|
920 | sprintf(ns, "bigintmat(bigintvec(%s),%d,%d)", s, bim->rows(), bim->cols()); |
---|
921 | omCheckAddr(ns); |
---|
922 | return ns; |
---|
923 | } |
---|
924 | else |
---|
925 | return omStrDup(s); |
---|
926 | } |
---|
927 | |
---|
928 | case RING_CMD: |
---|
929 | s = rString((ring)d); |
---|
930 | |
---|
931 | if (typed) |
---|
932 | { |
---|
933 | char* ns; |
---|
934 | ring r=(ring)d; |
---|
935 | if (r->qideal!=NULL) |
---|
936 | { |
---|
937 | char* id = iiStringMatrix((matrix) ((ring) d)->qideal, dim, |
---|
938 | currRing); |
---|
939 | ns = (char*) omAlloc(strlen(s) + strlen(id) + 20); |
---|
940 | sprintf(ns, "\"%s\";%sideal(%s)", s,(dim == 2 ? "\n" : " "), id); |
---|
941 | } |
---|
942 | else |
---|
943 | { |
---|
944 | ns = (char*) omAlloc(strlen(s) + 4); |
---|
945 | sprintf(ns, "\"%s\"", s); |
---|
946 | } |
---|
947 | omFree(s); |
---|
948 | omCheckAddr(ns); |
---|
949 | return ns; |
---|
950 | } |
---|
951 | return s; |
---|
952 | case RESOLUTION_CMD: |
---|
953 | { |
---|
954 | lists l = syConvRes((syStrategy)d); |
---|
955 | s = lString(l, typed, dim); |
---|
956 | l->Clean(); |
---|
957 | return s; |
---|
958 | } |
---|
959 | |
---|
960 | case PROC_CMD: |
---|
961 | { |
---|
962 | procinfo* pi = (procinfo*) d; |
---|
963 | if((pi->language == LANG_SINGULAR) && (pi->data.s.body!=NULL)) |
---|
964 | s = (pi->data.s.body); |
---|
965 | else |
---|
966 | s = (char *)""; |
---|
967 | if (typed) |
---|
968 | { |
---|
969 | char* ns = (char*) omAlloc(strlen(s) + 4); |
---|
970 | sprintf(ns, "\"%s\"", s); |
---|
971 | omCheckAddr(ns); |
---|
972 | return ns; |
---|
973 | } |
---|
974 | return omStrDup(s); |
---|
975 | } |
---|
976 | |
---|
977 | case LINK_CMD: |
---|
978 | s = slString((si_link) d); |
---|
979 | if (typed) |
---|
980 | { |
---|
981 | char* ns = (char*) omAlloc(strlen(s) + 10); |
---|
982 | sprintf(ns, "link(\"%s\")", s); |
---|
983 | omFreeBinAddr(s); |
---|
984 | omCheckAddr(ns); |
---|
985 | return ns; |
---|
986 | } |
---|
987 | return s; |
---|
988 | |
---|
989 | case LIST_CMD: |
---|
990 | return lString((lists) d, typed, dim); |
---|
991 | |
---|
992 | default: |
---|
993 | if(t> MAX_TOK) |
---|
994 | { |
---|
995 | blackbox *bb=getBlackboxStuff(t); |
---|
996 | if (bb!=NULL) return bb->blackbox_String(bb,d); |
---|
997 | } |
---|
998 | } /* end switch: (Typ()) */ |
---|
999 | } |
---|
1000 | return omStrDup(""); |
---|
1001 | } |
---|
1002 | |
---|
1003 | |
---|
1004 | int sleftv::Typ() |
---|
1005 | { |
---|
1006 | if (e==NULL) |
---|
1007 | { |
---|
1008 | switch (rtyp) |
---|
1009 | { |
---|
1010 | case IDHDL: |
---|
1011 | return IDTYP((idhdl)data); |
---|
1012 | case ALIAS_CMD: |
---|
1013 | { |
---|
1014 | idhdl h=(idhdl)data; |
---|
1015 | return ((idhdl)h->data.ustring)->typ; |
---|
1016 | } |
---|
1017 | case VECHO: |
---|
1018 | case VPRINTLEVEL: |
---|
1019 | case VCOLMAX: |
---|
1020 | case VTIMER: |
---|
1021 | case VRTIMER: |
---|
1022 | case VOICE: |
---|
1023 | case VMAXDEG: |
---|
1024 | case VMAXMULT: |
---|
1025 | case TRACE: |
---|
1026 | case VSHORTOUT: |
---|
1027 | return INT_CMD; |
---|
1028 | case VMINPOLY: |
---|
1029 | data=NULL; |
---|
1030 | return NUMBER_CMD; |
---|
1031 | case VNOETHER: |
---|
1032 | data=NULL; |
---|
1033 | return POLY_CMD; |
---|
1034 | //case COMMAND: |
---|
1035 | // return COMMAND; |
---|
1036 | default: |
---|
1037 | return rtyp; |
---|
1038 | } |
---|
1039 | } |
---|
1040 | int r=0; |
---|
1041 | int t=rtyp; |
---|
1042 | void *d=data; |
---|
1043 | if (t==IDHDL) t=IDTYP((idhdl)d); |
---|
1044 | else if (t==ALIAS_CMD) |
---|
1045 | { idhdl h=(idhdl)IDDATA((idhdl)data); t=IDTYP(h);d=IDDATA(h); } |
---|
1046 | switch (t) |
---|
1047 | { |
---|
1048 | #ifdef SINGULAR_4_2 |
---|
1049 | case CMATRIX_CMD: |
---|
1050 | { |
---|
1051 | bigintmat *b=(bigintmat*)d; |
---|
1052 | if ((currRing!=NULL)&&(currRing->cf==b->basecoeffs())) |
---|
1053 | return NUMBER_CMD; |
---|
1054 | else |
---|
1055 | return CNUMBER_CMD; |
---|
1056 | } |
---|
1057 | #endif |
---|
1058 | case INTVEC_CMD: |
---|
1059 | case INTMAT_CMD: |
---|
1060 | r=INT_CMD; |
---|
1061 | break; |
---|
1062 | case BIGINTMAT_CMD: |
---|
1063 | r=BIGINT_CMD; |
---|
1064 | break; |
---|
1065 | case IDEAL_CMD: |
---|
1066 | case MATRIX_CMD: |
---|
1067 | case MAP_CMD: |
---|
1068 | case SMATRIX_CMD: |
---|
1069 | r=POLY_CMD; |
---|
1070 | break; |
---|
1071 | case MODUL_CMD: |
---|
1072 | r=VECTOR_CMD; |
---|
1073 | break; |
---|
1074 | case STRING_CMD: |
---|
1075 | r=STRING_CMD; |
---|
1076 | break; |
---|
1077 | default: |
---|
1078 | { |
---|
1079 | blackbox *b=NULL; |
---|
1080 | if (t>MAX_TOK) |
---|
1081 | { |
---|
1082 | b=getBlackboxStuff(t); |
---|
1083 | } |
---|
1084 | if ((t==LIST_CMD)||((b!=NULL)&&BB_LIKE_LIST(b))) |
---|
1085 | { |
---|
1086 | lists l; |
---|
1087 | if (rtyp==IDHDL) l=IDLIST((idhdl)d); |
---|
1088 | else l=(lists)d; |
---|
1089 | if ((0<e->start)&&(e->start<=l->nr+1)) |
---|
1090 | { |
---|
1091 | Subexpr tmp=l->m[e->start-1].e; |
---|
1092 | l->m[e->start-1].e=e->next; |
---|
1093 | r=l->m[e->start-1].Typ(); |
---|
1094 | e->next=l->m[e->start-1].e; |
---|
1095 | l->m[e->start-1].e=tmp; |
---|
1096 | } |
---|
1097 | else |
---|
1098 | { |
---|
1099 | //Warn("out of range: %d not in 1..%d",e->start,l->nr+1); |
---|
1100 | r=DEF_CMD; |
---|
1101 | } |
---|
1102 | } |
---|
1103 | else |
---|
1104 | Werror("cannot index type %s(%d)",Tok2Cmdname(t),t); |
---|
1105 | break; |
---|
1106 | } |
---|
1107 | } |
---|
1108 | return r; |
---|
1109 | } |
---|
1110 | |
---|
1111 | int sleftv::LTyp() |
---|
1112 | { |
---|
1113 | lists l=NULL; |
---|
1114 | int r; |
---|
1115 | if (rtyp==LIST_CMD) |
---|
1116 | l=(lists)data; |
---|
1117 | else if ((rtyp==IDHDL)&& (IDTYP((idhdl)data)==LIST_CMD)) |
---|
1118 | l=IDLIST((idhdl)data); |
---|
1119 | else |
---|
1120 | return Typ(); |
---|
1121 | //if (l!=NULL) |
---|
1122 | { |
---|
1123 | if ((e!=NULL) && (e->next!=NULL)) |
---|
1124 | { |
---|
1125 | if ((0<e->start)&&(e->start<=l->nr+1)) |
---|
1126 | { |
---|
1127 | l->m[e->start-1].e=e->next; |
---|
1128 | r=l->m[e->start-1].LTyp(); |
---|
1129 | l->m[e->start-1].e=NULL; |
---|
1130 | } |
---|
1131 | else |
---|
1132 | { |
---|
1133 | //Warn("out of range: %d not in 1..%d",e->start,l->nr+1); |
---|
1134 | r=NONE; |
---|
1135 | } |
---|
1136 | return r; |
---|
1137 | } |
---|
1138 | return LIST_CMD; |
---|
1139 | } |
---|
1140 | return Typ(); |
---|
1141 | } |
---|
1142 | |
---|
1143 | #ifdef SINGULAR_4_2 |
---|
1144 | STATIC_VAR snumber2 iiNumber2Data[4]; |
---|
1145 | STATIC_VAR int iiCmatrix_index=0; |
---|
1146 | #endif |
---|
1147 | void * sleftv::Data() |
---|
1148 | { |
---|
1149 | if ((rtyp!=IDHDL) && iiCheckRing(rtyp)) |
---|
1150 | return NULL; |
---|
1151 | if (e==NULL) |
---|
1152 | { |
---|
1153 | switch (rtyp) |
---|
1154 | { |
---|
1155 | case ALIAS_CMD: |
---|
1156 | { |
---|
1157 | idhdl h=(idhdl)data; |
---|
1158 | return ((idhdl)h->data.ustring)->data.ustring; |
---|
1159 | } |
---|
1160 | case VECHO: return (void *)(long)si_echo; |
---|
1161 | case VPRINTLEVEL:return (void *)(long)printlevel; |
---|
1162 | case VCOLMAX: return (void *)(long)colmax; |
---|
1163 | case VTIMER: return (void *)(long)getTimer(); |
---|
1164 | case VRTIMER: return (void *)(long)getRTimer(); |
---|
1165 | case VOICE: return (void *)(long)(myynest+1); |
---|
1166 | case VMAXDEG: return (void *)(long)Kstd1_deg; |
---|
1167 | case VMAXMULT: return (void *)(long)Kstd1_mu; |
---|
1168 | case TRACE: return (void *)(long)traceit; |
---|
1169 | case VSHORTOUT: return (void *)(long)(currRing != NULL ? currRing->ShortOut : 0); |
---|
1170 | case VMINPOLY: |
---|
1171 | if ( (currRing != NULL) && nCoeff_is_algExt(currRing->cf) && !nCoeff_is_GF(currRing->cf)) |
---|
1172 | { |
---|
1173 | /* Q(a), Fp(a), but not GF(q) */ |
---|
1174 | const ring A = currRing->cf->extRing; |
---|
1175 | |
---|
1176 | assume( A != NULL ); |
---|
1177 | assume( A->qideal != NULL ); |
---|
1178 | |
---|
1179 | return (void *)A->qideal->m[0]; |
---|
1180 | } |
---|
1181 | else |
---|
1182 | return (void *)nInit(0); |
---|
1183 | |
---|
1184 | case VNOETHER: return (void *) (currRing->ppNoether); |
---|
1185 | case IDHDL: |
---|
1186 | return IDDATA((idhdl)data); |
---|
1187 | case COMMAND: |
---|
1188 | //return NULL; |
---|
1189 | default: |
---|
1190 | return data; |
---|
1191 | } |
---|
1192 | } |
---|
1193 | /* e != NULL : */ |
---|
1194 | int t=rtyp; |
---|
1195 | void *d=data; |
---|
1196 | if (t==IDHDL) |
---|
1197 | { |
---|
1198 | t=((idhdl)data)->typ; |
---|
1199 | d=IDDATA((idhdl)data); |
---|
1200 | } |
---|
1201 | else if (t==ALIAS_CMD) |
---|
1202 | { |
---|
1203 | idhdl h=(idhdl)IDDATA((idhdl)data); |
---|
1204 | t=IDTYP(h); |
---|
1205 | d=IDDATA(h); |
---|
1206 | } |
---|
1207 | if (iiCheckRing(t)) |
---|
1208 | return NULL; |
---|
1209 | char *r=NULL; |
---|
1210 | int index=e->start; |
---|
1211 | switch (t) |
---|
1212 | { |
---|
1213 | case INTVEC_CMD: |
---|
1214 | { |
---|
1215 | intvec *iv=(intvec *)d; |
---|
1216 | if ((index<1)||(index>iv->length())) |
---|
1217 | { |
---|
1218 | if (!errorreported) |
---|
1219 | Werror("wrong range[%d] in intvec %s(%d)",index,this->Name(),iv->length()); |
---|
1220 | } |
---|
1221 | else |
---|
1222 | r=(char *)(long)((*iv)[index-1]); |
---|
1223 | break; |
---|
1224 | } |
---|
1225 | case INTMAT_CMD: |
---|
1226 | { |
---|
1227 | intvec *iv=(intvec *)d; |
---|
1228 | if ((index<1) |
---|
1229 | ||(index>iv->rows()) |
---|
1230 | ||(e->next->start<1) |
---|
1231 | ||(e->next->start>iv->cols())) |
---|
1232 | { |
---|
1233 | if (!errorreported) |
---|
1234 | Werror("wrong range[%d,%d] in intmat %s(%dx%d)",index,e->next->start, |
---|
1235 | this->Name(),iv->rows(),iv->cols()); |
---|
1236 | } |
---|
1237 | else |
---|
1238 | r=(char *)(long)(IMATELEM((*iv),index,e->next->start)); |
---|
1239 | break; |
---|
1240 | } |
---|
1241 | case BIGINTMAT_CMD: |
---|
1242 | { |
---|
1243 | bigintmat *m=(bigintmat *)d; |
---|
1244 | if ((index<1) |
---|
1245 | ||(index>m->rows()) |
---|
1246 | ||(e->next->start<1) |
---|
1247 | ||(e->next->start>m->cols())) |
---|
1248 | { |
---|
1249 | if (!errorreported) |
---|
1250 | Werror("wrong range[%d,%d] in bigintmat %s(%dx%d)",index,e->next->start, |
---|
1251 | this->Name(),m->rows(),m->cols()); |
---|
1252 | } |
---|
1253 | else |
---|
1254 | r=(char *)(BIMATELEM((*m),index,e->next->start)); |
---|
1255 | break; |
---|
1256 | } |
---|
1257 | #ifdef SINGULAR_4_2 |
---|
1258 | case CMATRIX_CMD: |
---|
1259 | { |
---|
1260 | bigintmat *m=(bigintmat *)d; |
---|
1261 | if ((index<1) |
---|
1262 | ||(index>m->rows()) |
---|
1263 | ||(e->next->start<1) |
---|
1264 | ||(e->next->start>m->cols())) |
---|
1265 | { |
---|
1266 | if (!errorreported) |
---|
1267 | Werror("wrong range[%d,%d] in matrix %s(%dx%d)",index,e->next->start, |
---|
1268 | this->Name(),m->rows(),m->cols()); |
---|
1269 | } |
---|
1270 | else |
---|
1271 | { |
---|
1272 | iiNumber2Data[iiCmatrix_index].cf=m->basecoeffs(); |
---|
1273 | iiNumber2Data[iiCmatrix_index].n=BIMATELEM((*m),index,e->next->start); |
---|
1274 | r=(char*)&iiNumber2Data[iiCmatrix_index]; |
---|
1275 | iiCmatrix_index=(iiCmatrix_index+1) % 4; |
---|
1276 | } |
---|
1277 | break; |
---|
1278 | } |
---|
1279 | #endif |
---|
1280 | case IDEAL_CMD: |
---|
1281 | case MODUL_CMD: |
---|
1282 | case MAP_CMD: |
---|
1283 | { |
---|
1284 | ideal I=(ideal)d; |
---|
1285 | if ((index<1)||(index>IDELEMS(I))) |
---|
1286 | { |
---|
1287 | if (!errorreported) |
---|
1288 | Werror("wrong range[%d] in ideal/module %s(%d)",index,this->Name(),IDELEMS(I)); |
---|
1289 | } |
---|
1290 | else |
---|
1291 | r=(char *)I->m[index-1]; |
---|
1292 | break; |
---|
1293 | } |
---|
1294 | case SMATRIX_CMD: |
---|
1295 | { |
---|
1296 | ideal I=(ideal)d; |
---|
1297 | int c; |
---|
1298 | sleftv tmp; |
---|
1299 | tmp.Init(); |
---|
1300 | tmp.rtyp=POLY_CMD; |
---|
1301 | if ((index>0)&& (index<=I->rank) |
---|
1302 | && (e->next!=NULL) |
---|
1303 | && ((c=e->next->start)>0) &&(c<=IDELEMS(I))) |
---|
1304 | { |
---|
1305 | r=(char*)SMATELEM(I,index-1,c-1,currRing); |
---|
1306 | } |
---|
1307 | else |
---|
1308 | { |
---|
1309 | r=NULL; |
---|
1310 | } |
---|
1311 | tmp.data=r; |
---|
1312 | if ((rtyp==IDHDL)||(rtyp==SMATRIX_CMD)) |
---|
1313 | { |
---|
1314 | tmp.next=next; next=NULL; |
---|
1315 | d=NULL; |
---|
1316 | CleanUp(); |
---|
1317 | memcpy(this,&tmp,sizeof(tmp)); |
---|
1318 | } |
---|
1319 | // and, remember, r is also the result... |
---|
1320 | else |
---|
1321 | { |
---|
1322 | // ??? |
---|
1323 | // here we still have a memory leak... |
---|
1324 | // example: list L="123","456"; |
---|
1325 | // L[1][2]; |
---|
1326 | // therefore, it should never happen: |
---|
1327 | assume(0); |
---|
1328 | // but if it happens: here is the temporary fix: |
---|
1329 | // omMarkAsStaticAddr(r); |
---|
1330 | } |
---|
1331 | break; |
---|
1332 | } |
---|
1333 | case STRING_CMD: |
---|
1334 | { |
---|
1335 | // this was a memory leak |
---|
1336 | // we evalute it, cleanup and replace this leftv by it's evalutated form |
---|
1337 | // the evalutated form will be build in tmp |
---|
1338 | sleftv tmp; |
---|
1339 | tmp.Init(); |
---|
1340 | tmp.rtyp=STRING_CMD; |
---|
1341 | r=(char *)omAllocBin(size_two_bin); |
---|
1342 | if ((index>0)&& (index<=(int)strlen((char *)d))) |
---|
1343 | { |
---|
1344 | r[0]=*(((char *)d)+index-1); |
---|
1345 | r[1]='\0'; |
---|
1346 | } |
---|
1347 | else |
---|
1348 | { |
---|
1349 | r[0]='\0'; |
---|
1350 | } |
---|
1351 | tmp.data=r; |
---|
1352 | if ((rtyp==IDHDL)||(rtyp==STRING_CMD)) |
---|
1353 | { |
---|
1354 | tmp.next=next; next=NULL; |
---|
1355 | //if (rtyp==STRING_CMD) { omFree((ADDRESS)data); } |
---|
1356 | //data=NULL; |
---|
1357 | d=NULL; |
---|
1358 | CleanUp(); |
---|
1359 | memcpy(this,&tmp,sizeof(tmp)); |
---|
1360 | } |
---|
1361 | // and, remember, r is also the result... |
---|
1362 | else |
---|
1363 | { |
---|
1364 | // ??? |
---|
1365 | // here we still have a memory leak... |
---|
1366 | // example: list L="123","456"; |
---|
1367 | // L[1][2]; |
---|
1368 | // therefore, it should never happen: |
---|
1369 | assume(0); |
---|
1370 | // but if it happens: here is the temporary fix: |
---|
1371 | // omMarkAsStaticAddr(r); |
---|
1372 | } |
---|
1373 | break; |
---|
1374 | } |
---|
1375 | case MATRIX_CMD: |
---|
1376 | { |
---|
1377 | if ((index<1) |
---|
1378 | ||(index>MATROWS((matrix)d)) |
---|
1379 | ||(e->next->start<1) |
---|
1380 | ||(e->next->start>MATCOLS((matrix)d))) |
---|
1381 | { |
---|
1382 | if (!errorreported) |
---|
1383 | Werror("wrong range[%d,%d] in matrix %s(%dx%d)", |
---|
1384 | index,e->next->start, |
---|
1385 | this->Name(), |
---|
1386 | MATROWS((matrix)d),MATCOLS((matrix)d)); |
---|
1387 | } |
---|
1388 | else |
---|
1389 | r=(char *)MATELEM((matrix)d,index,e->next->start); |
---|
1390 | break; |
---|
1391 | } |
---|
1392 | default: |
---|
1393 | { |
---|
1394 | blackbox *b=NULL; |
---|
1395 | if (t>MAX_TOK) |
---|
1396 | { |
---|
1397 | b=getBlackboxStuff(t); |
---|
1398 | } |
---|
1399 | if ((t==LIST_CMD)||((b!=NULL)&&(BB_LIKE_LIST(b)))) |
---|
1400 | { |
---|
1401 | lists l=(lists)d; |
---|
1402 | if ((0<index)&&(index<=l->nr+1)) |
---|
1403 | { |
---|
1404 | if ((e->next!=NULL) |
---|
1405 | && (l->m[index-1].rtyp==STRING_CMD)) |
---|
1406 | // string[..].Data() modifies sleftv, so let's do it ourself |
---|
1407 | { |
---|
1408 | char *dd=(char *)l->m[index-1].data; |
---|
1409 | int j=e->next->start-1; |
---|
1410 | r=(char *)omAllocBin(size_two_bin); |
---|
1411 | if ((j>=0) && (j<(int)strlen(dd))) |
---|
1412 | { |
---|
1413 | r[0]=*(dd+j); |
---|
1414 | r[1]='\0'; |
---|
1415 | } |
---|
1416 | else |
---|
1417 | { |
---|
1418 | r[0]='\0'; |
---|
1419 | } |
---|
1420 | } |
---|
1421 | else |
---|
1422 | { |
---|
1423 | Subexpr tmp=l->m[index-1].e; |
---|
1424 | l->m[index-1].e=e->next; |
---|
1425 | r=(char *)l->m[index-1].Data(); |
---|
1426 | e->next=l->m[index-1].e; |
---|
1427 | l->m[index-1].e=tmp; |
---|
1428 | } |
---|
1429 | } |
---|
1430 | else //if (!errorreported) |
---|
1431 | Werror("wrong range[%d] in list %s(%d)",index,this->Name(),l->nr+1); |
---|
1432 | } |
---|
1433 | else |
---|
1434 | Werror("cannot index %s of type %s(%d)",this->Name(),Tok2Cmdname(t),t); |
---|
1435 | break; |
---|
1436 | } |
---|
1437 | } |
---|
1438 | return r; |
---|
1439 | } |
---|
1440 | |
---|
1441 | attr * sleftv::Attribute() |
---|
1442 | { |
---|
1443 | if (e==NULL) return &attribute; |
---|
1444 | if ((rtyp==LIST_CMD) |
---|
1445 | ||((rtyp==IDHDL)&&(IDTYP((idhdl)data)==LIST_CMD)) |
---|
1446 | || (rtyp>MAX_TOK) |
---|
1447 | || ((rtyp==IDHDL)&&(IDTYP((idhdl)data)>MAX_TOK))) |
---|
1448 | { |
---|
1449 | leftv v=LData(); |
---|
1450 | return &(v->attribute); |
---|
1451 | } |
---|
1452 | return NULL; |
---|
1453 | } |
---|
1454 | |
---|
1455 | leftv sleftv::LData() |
---|
1456 | { |
---|
1457 | if (e!=NULL) |
---|
1458 | { |
---|
1459 | lists l=NULL; |
---|
1460 | blackbox *b=getBlackboxStuff(rtyp); |
---|
1461 | |
---|
1462 | if ((rtyp==LIST_CMD) |
---|
1463 | || ((b!=NULL)&&(BB_LIKE_LIST(b)))) |
---|
1464 | l=(lists)data; |
---|
1465 | else if ((rtyp==IDHDL)&& (IDTYP((idhdl)data)==LIST_CMD)) |
---|
1466 | l=IDLIST((idhdl)data); |
---|
1467 | else if ((rtyp==IDHDL)&& (IDTYP((idhdl)data)>MAX_TOK)) |
---|
1468 | { |
---|
1469 | b=getBlackboxStuff(IDTYP((idhdl)data)); |
---|
1470 | if (BB_LIKE_LIST(b)) l=IDLIST((idhdl)data); |
---|
1471 | } |
---|
1472 | else if (rtyp==ALIAS_CMD) |
---|
1473 | { |
---|
1474 | idhdl h=(idhdl)data; |
---|
1475 | l= (lists)(((idhdl)h->data.ustring)->data.ustring); |
---|
1476 | } |
---|
1477 | if (l!=NULL) |
---|
1478 | { |
---|
1479 | if ((0>=e->start)||(e->start>l->nr+1)) |
---|
1480 | return NULL; |
---|
1481 | if (e->next!=NULL) |
---|
1482 | { |
---|
1483 | l->m[e->start-1].e=e->next; |
---|
1484 | leftv r=l->m[e->start-1].LData(); |
---|
1485 | l->m[e->start-1].e=NULL; |
---|
1486 | return r; |
---|
1487 | } |
---|
1488 | return &(l->m[e->start-1]); |
---|
1489 | } |
---|
1490 | } |
---|
1491 | return this; |
---|
1492 | } |
---|
1493 | |
---|
1494 | #if 0 |
---|
1495 | leftv sleftv::LHdl() |
---|
1496 | { |
---|
1497 | if (e!=NULL) |
---|
1498 | { |
---|
1499 | lists l=NULL; |
---|
1500 | |
---|
1501 | if (rtyp==LIST_CMD) |
---|
1502 | l=(lists)data; |
---|
1503 | if ((rtyp==IDHDL)&& (IDTYP((idhdl)data)==LIST_CMD)) |
---|
1504 | l=IDLIST((idhdl)data); |
---|
1505 | if (l!=NULL) |
---|
1506 | { |
---|
1507 | if ((0>=e->start)||(e->start>l->nr+1)) |
---|
1508 | return NULL; |
---|
1509 | if (e->next!=NULL) |
---|
1510 | { |
---|
1511 | l->m[e->start-1].e=e->next; |
---|
1512 | leftv r=l->m[e->start-1].LHdl(); |
---|
1513 | l->m[e->start-1].e=NULL; |
---|
1514 | return r; |
---|
1515 | } |
---|
1516 | return &(l->m[e->start-1]); |
---|
1517 | } |
---|
1518 | } |
---|
1519 | return this; |
---|
1520 | } |
---|
1521 | #endif |
---|
1522 | |
---|
1523 | BOOLEAN assumeStdFlag(leftv h) |
---|
1524 | { |
---|
1525 | if (h->e!=NULL) |
---|
1526 | { |
---|
1527 | leftv hh=h->LData(); |
---|
1528 | if (h!=hh) return assumeStdFlag(h->LData()); |
---|
1529 | } |
---|
1530 | if (!hasFlag(h,FLAG_STD)) |
---|
1531 | { |
---|
1532 | if (!TEST_VERB_NSB) |
---|
1533 | { |
---|
1534 | if (TEST_V_ALLWARN) |
---|
1535 | Warn("%s is no standard basis in >>%s<<",h->Name(),my_yylinebuf); |
---|
1536 | else |
---|
1537 | Warn("%s is no standard basis",h->Name()); |
---|
1538 | } |
---|
1539 | return FALSE; |
---|
1540 | } |
---|
1541 | return TRUE; |
---|
1542 | } |
---|
1543 | |
---|
1544 | /*2 |
---|
1545 | * transforms a name (as an string created by omAlloc or omStrDup) |
---|
1546 | * into an expression (sleftv), deletes the string |
---|
1547 | * utility for grammar and iparith |
---|
1548 | */ |
---|
1549 | void syMake(leftv v,const char * id, package pa) |
---|
1550 | { |
---|
1551 | /* resolv an identifier: (to DEF_CMD, if siq>0) |
---|
1552 | * 1) reserved id: done by scanner |
---|
1553 | * 2) `basering` / 'Current` |
---|
1554 | * 3) existing identifier, local |
---|
1555 | * 4) ringvar, ringpar, local ring |
---|
1556 | * 5) existing identifier, global |
---|
1557 | * 6) monom (resp. number), local ring: consisting of: |
---|
1558 | * 6') ringvar, ringpar,global ring |
---|
1559 | * 6'') monom (resp. number), local ring |
---|
1560 | * 7) monom (resp. number), non-local ring |
---|
1561 | * 8) basering |
---|
1562 | * 9) `_` |
---|
1563 | * 10) everything else is of type 0 |
---|
1564 | */ |
---|
1565 | #ifdef TEST |
---|
1566 | if ((*id<' ')||(*id>(char)126)) |
---|
1567 | { |
---|
1568 | Print("wrong id :%s:\n",id); |
---|
1569 | } |
---|
1570 | #endif |
---|
1571 | idhdl save_ring=currRingHdl; |
---|
1572 | v->Init(); |
---|
1573 | if(pa != NULL) |
---|
1574 | { |
---|
1575 | v->req_packhdl = pa; |
---|
1576 | } |
---|
1577 | else v->req_packhdl = currPack; |
---|
1578 | // if (v->req_packhdl!=basePack) |
---|
1579 | // Print("search %s in %s\n",id,v->req_packhdl->libname); |
---|
1580 | idhdl h=NULL; |
---|
1581 | #ifdef SIQ |
---|
1582 | if (siq<=0) |
---|
1583 | #endif |
---|
1584 | { |
---|
1585 | if (strcmp(id,"basering")==0) |
---|
1586 | { |
---|
1587 | if (currRingHdl!=NULL) |
---|
1588 | { |
---|
1589 | if (id!=IDID(currRingHdl)) omFreeBinAddr((ADDRESS)id); |
---|
1590 | h=currRingHdl; |
---|
1591 | goto id_found; |
---|
1592 | } |
---|
1593 | else |
---|
1594 | { |
---|
1595 | v->name = id; |
---|
1596 | return; /* undefined */ |
---|
1597 | } |
---|
1598 | } |
---|
1599 | else if (strcmp(id,"Current")==0) |
---|
1600 | { |
---|
1601 | if (currPackHdl!=NULL) |
---|
1602 | { |
---|
1603 | omFreeBinAddr((ADDRESS)id); |
---|
1604 | h=currPackHdl; |
---|
1605 | goto id_found; |
---|
1606 | } |
---|
1607 | else |
---|
1608 | { |
---|
1609 | v->name = id; |
---|
1610 | return; /* undefined */ |
---|
1611 | } |
---|
1612 | } |
---|
1613 | if(v->req_packhdl!=currPack) |
---|
1614 | { |
---|
1615 | h=v->req_packhdl->idroot->get(id,myynest); |
---|
1616 | } |
---|
1617 | else |
---|
1618 | { |
---|
1619 | h=ggetid(id); |
---|
1620 | } |
---|
1621 | /* 3) existing identifier, local */ |
---|
1622 | if ((h!=NULL) && (IDLEV(h)==myynest)) |
---|
1623 | { |
---|
1624 | if (id!=IDID(h)) omFreeBinAddr((ADDRESS)id); /*assume strlen(id) <1000 */ |
---|
1625 | goto id_found; |
---|
1626 | } |
---|
1627 | if (yyInRingConstruction) |
---|
1628 | { |
---|
1629 | currRingHdl=NULL; |
---|
1630 | } |
---|
1631 | /* 4. local ring: ringvar */ |
---|
1632 | if ((currRingHdl!=NULL) && (IDLEV(currRingHdl)==myynest) |
---|
1633 | /*&& (!yyInRingConstruction)*/) |
---|
1634 | { |
---|
1635 | int vnr; |
---|
1636 | if ((vnr=r_IsRingVar(id, currRing->names,currRing->N))>=0) |
---|
1637 | { |
---|
1638 | poly p=pOne(); |
---|
1639 | pSetExp(p,vnr+1,1); |
---|
1640 | pSetm(p); |
---|
1641 | v->data = (void *)p; |
---|
1642 | v->name = id; |
---|
1643 | v->rtyp = POLY_CMD; |
---|
1644 | return; |
---|
1645 | } |
---|
1646 | if((n_NumberOfParameters(currRing->cf)>0) |
---|
1647 | &&((vnr=r_IsRingVar(id, (char**)n_ParameterNames(currRing->cf), |
---|
1648 | n_NumberOfParameters(currRing->cf))>=0))) |
---|
1649 | { |
---|
1650 | BOOLEAN ok=FALSE; |
---|
1651 | poly p = pmInit(id,ok); |
---|
1652 | if (ok && (p!=NULL)) |
---|
1653 | { |
---|
1654 | v->data = pGetCoeff(p); |
---|
1655 | pGetCoeff(p)=NULL; |
---|
1656 | pLmFree(p); |
---|
1657 | v->rtyp = NUMBER_CMD; |
---|
1658 | v->name = id; |
---|
1659 | return; |
---|
1660 | } |
---|
1661 | } |
---|
1662 | } |
---|
1663 | /* 5. existing identifier, global */ |
---|
1664 | if (h!=NULL) |
---|
1665 | { |
---|
1666 | if (id!=IDID(h)) omFreeBinAddr((ADDRESS)id); /*assume strlen(id) <1000 */ |
---|
1667 | goto id_found; |
---|
1668 | } |
---|
1669 | /* 6. local ring: number/poly */ |
---|
1670 | if ((currRingHdl!=NULL) && (IDLEV(currRingHdl)==myynest)) |
---|
1671 | { |
---|
1672 | BOOLEAN ok=FALSE; |
---|
1673 | /*poly p = (!yyInRingConstruction) ? pmInit(id,ok) : (poly)NULL;*/ |
---|
1674 | poly p = pmInit(id,ok); |
---|
1675 | if (ok) |
---|
1676 | { |
---|
1677 | if (p==NULL) |
---|
1678 | { |
---|
1679 | v->data = (void *)nInit(0); |
---|
1680 | v->rtyp = NUMBER_CMD; |
---|
1681 | #ifdef HAVE_PLURAL |
---|
1682 | // in this case we may have monomials equal to 0 in p_Read |
---|
1683 | v->name = id; |
---|
1684 | #else |
---|
1685 | omFreeBinAddr((ADDRESS)id); |
---|
1686 | #endif |
---|
1687 | } |
---|
1688 | else if (pIsConstant(p)) |
---|
1689 | { |
---|
1690 | v->data = pGetCoeff(p); |
---|
1691 | pGetCoeff(p)=NULL; |
---|
1692 | pLmFree(p); |
---|
1693 | v->rtyp = NUMBER_CMD; |
---|
1694 | v->name = id; |
---|
1695 | } |
---|
1696 | else |
---|
1697 | { |
---|
1698 | v->name = id; |
---|
1699 | #ifdef HAVE_SHIFTBBA |
---|
1700 | if ((currRing->isLPring!=0) |
---|
1701 | && (p_Totaldegree(p,currRing)>1)) |
---|
1702 | { |
---|
1703 | p_LmDelete(&p,currRing); |
---|
1704 | /* v->rtyp = UNKNOWN; - already set */ |
---|
1705 | return; /* error, report "unknown id" */ |
---|
1706 | } |
---|
1707 | #endif |
---|
1708 | v->data = p; |
---|
1709 | v->rtyp = POLY_CMD; |
---|
1710 | } |
---|
1711 | return; |
---|
1712 | } |
---|
1713 | } |
---|
1714 | /* 7. non-local ring: number/poly */ |
---|
1715 | { |
---|
1716 | BOOLEAN ok=FALSE; |
---|
1717 | poly p = ((currRing!=NULL) /* ring required */ |
---|
1718 | && (currRingHdl!=NULL) |
---|
1719 | /*&& (!yyInRingConstruction) - not in decl */ |
---|
1720 | && (IDLEV(currRingHdl)!=myynest)) /* already in case 4/6 */ |
---|
1721 | ? pmInit(id,ok) : (poly)NULL; |
---|
1722 | if (ok) |
---|
1723 | { |
---|
1724 | if (p==NULL) |
---|
1725 | { |
---|
1726 | v->data = (void *)nInit(0); |
---|
1727 | v->rtyp = NUMBER_CMD; |
---|
1728 | omFreeBinAddr((ADDRESS)id); |
---|
1729 | } |
---|
1730 | else |
---|
1731 | if (pIsConstant(p)) |
---|
1732 | { |
---|
1733 | v->data = pGetCoeff(p); |
---|
1734 | pGetCoeff(p)=NULL; |
---|
1735 | pLmFree(p); |
---|
1736 | v->rtyp = NUMBER_CMD; |
---|
1737 | v->name = id; |
---|
1738 | } |
---|
1739 | else |
---|
1740 | { |
---|
1741 | v->data = p; |
---|
1742 | v->rtyp = POLY_CMD; |
---|
1743 | v->name = id; |
---|
1744 | } |
---|
1745 | //if (TEST_V_ALLWARN /*&& (myynest>0)*/ |
---|
1746 | //&& ((r_IsRingVar(id, currRing->names,currRing->N)>=0) |
---|
1747 | // || ((n_NumberOfParameters(currRing->cf)>0) |
---|
1748 | // &&(r_IsRingVar(id, (char**)n_ParameterNames(currRing->cf), |
---|
1749 | // n_NumberOfParameters(currRing->cf))>=0)))) |
---|
1750 | //{ |
---|
1751 | //// WARNING: do not use ring variable names in procedures |
---|
1752 | // Warn("use of variable >>%s<< in a procedure in line %s",id,my_yylinebuf); |
---|
1753 | //} |
---|
1754 | return; |
---|
1755 | } |
---|
1756 | } |
---|
1757 | /* 8. basering ? */ |
---|
1758 | if ((myynest>1)&&(currRingHdl!=NULL)) |
---|
1759 | { |
---|
1760 | if (strcmp(id,IDID(currRingHdl))==0) |
---|
1761 | { |
---|
1762 | if (IDID(currRingHdl)!=id) omFreeBinAddr((ADDRESS)id); /*assume strlen (id) <1000 */ |
---|
1763 | h=currRingHdl; |
---|
1764 | goto id_found; |
---|
1765 | } |
---|
1766 | } |
---|
1767 | if((v->req_packhdl!=basePack) && (v->req_packhdl==currPack)) |
---|
1768 | { |
---|
1769 | h=basePack->idroot->get(id,myynest); |
---|
1770 | if (h!=NULL) |
---|
1771 | { |
---|
1772 | if (id!=IDID(h)) omFreeBinAddr((ADDRESS)id); /*assume strlen(id) <1000 */ |
---|
1773 | v->req_packhdl=basePack; |
---|
1774 | goto id_found; |
---|
1775 | } |
---|
1776 | } |
---|
1777 | } |
---|
1778 | #ifdef SIQ |
---|
1779 | else |
---|
1780 | v->rtyp=DEF_CMD; |
---|
1781 | #endif |
---|
1782 | /* 9: _ */ |
---|
1783 | if (strcmp(id,"_")==0) |
---|
1784 | { |
---|
1785 | omFreeBinAddr((ADDRESS)id); |
---|
1786 | v->Copy(&sLastPrinted); |
---|
1787 | } |
---|
1788 | else |
---|
1789 | { |
---|
1790 | /* 10: everything else */ |
---|
1791 | /* v->rtyp = UNKNOWN;*/ |
---|
1792 | v->name = id; |
---|
1793 | } |
---|
1794 | currRingHdl=save_ring; |
---|
1795 | return; |
---|
1796 | id_found: // we have an id (in h) found, to set the data in from h |
---|
1797 | if (IDTYP(h)!=ALIAS_CMD) |
---|
1798 | { |
---|
1799 | v->rtyp = IDHDL; |
---|
1800 | v->flag = IDFLAG(h); |
---|
1801 | v->attribute=IDATTR(h); |
---|
1802 | } |
---|
1803 | else |
---|
1804 | { |
---|
1805 | v->rtyp = ALIAS_CMD; |
---|
1806 | } |
---|
1807 | v->name = IDID(h); |
---|
1808 | v->data = (char *)h; |
---|
1809 | currRingHdl=save_ring; |
---|
1810 | } |
---|
1811 | |
---|
1812 | void syMakeMonom(leftv v,const char * id) |
---|
1813 | { |
---|
1814 | if (!isdigit(id[0])) |
---|
1815 | { |
---|
1816 | Print("non-digit:%s\n",id); |
---|
1817 | } |
---|
1818 | /* resolv an identifier: (to DEF_CMD, if siq>0) |
---|
1819 | * 6) monom (resp. number), local ring |
---|
1820 | * 7) monom (resp. number), non-local ring |
---|
1821 | * 10) everything else is of type 0 |
---|
1822 | */ |
---|
1823 | #ifdef TEST |
---|
1824 | if ((*id<' ')||(*id>(char)126)) |
---|
1825 | { |
---|
1826 | Print("wrong id :%s:\n",id); |
---|
1827 | } |
---|
1828 | #endif |
---|
1829 | idhdl save_ring=currRingHdl; |
---|
1830 | v->Init(); |
---|
1831 | v->req_packhdl = currPack; |
---|
1832 | idhdl h=NULL; |
---|
1833 | #ifdef SIQ |
---|
1834 | if (siq<=0) |
---|
1835 | #endif |
---|
1836 | { |
---|
1837 | /* 6. local ring: number/poly */ |
---|
1838 | BOOLEAN ok=FALSE; |
---|
1839 | poly p = pmInit(id,ok); |
---|
1840 | if (ok) |
---|
1841 | { |
---|
1842 | if (p==NULL) |
---|
1843 | { |
---|
1844 | v->data = (void *)nInit(0); |
---|
1845 | v->rtyp = NUMBER_CMD; |
---|
1846 | #ifdef HAVE_PLURAL |
---|
1847 | // in this case we may have monomials equal to 0 in p_Read |
---|
1848 | if (rIsPluralRing(currRing)) v->name = omStrDup(id); |
---|
1849 | #endif |
---|
1850 | } |
---|
1851 | else if (pIsConstant(p)) |
---|
1852 | { |
---|
1853 | v->data = pGetCoeff(p); |
---|
1854 | pGetCoeff(p)=NULL; |
---|
1855 | pLmFree(p); |
---|
1856 | v->rtyp = NUMBER_CMD; |
---|
1857 | } |
---|
1858 | else |
---|
1859 | { |
---|
1860 | v->name = omStrDup(id); |
---|
1861 | #ifdef HAVE_SHIFTBBA |
---|
1862 | if ((currRing->isLPring!=0) |
---|
1863 | && (p_Totaldegree(p,currRing)>1)) |
---|
1864 | { |
---|
1865 | p_LmDelete(&p,currRing); |
---|
1866 | /* v->rtyp = UNKNOWN; - already set */ |
---|
1867 | return; /* error, report "unknown id" */ |
---|
1868 | } |
---|
1869 | #endif |
---|
1870 | v->data = p; |
---|
1871 | v->rtyp = POLY_CMD; |
---|
1872 | } |
---|
1873 | return; |
---|
1874 | } |
---|
1875 | } |
---|
1876 | #ifdef SIQ |
---|
1877 | else |
---|
1878 | { |
---|
1879 | v->rtyp=DEF_CMD; |
---|
1880 | } |
---|
1881 | #endif |
---|
1882 | /* 9: _ */ |
---|
1883 | if (strcmp(id,"_")==0) |
---|
1884 | { |
---|
1885 | v->Copy(&sLastPrinted); |
---|
1886 | } |
---|
1887 | else |
---|
1888 | { |
---|
1889 | /* 10: everything else */ |
---|
1890 | /* v->rtyp = UNKNOWN;*/ |
---|
1891 | v->name = omStrDup(id); |
---|
1892 | } |
---|
1893 | currRingHdl=save_ring; |
---|
1894 | } |
---|
1895 | |
---|
1896 | int sleftv::Eval() |
---|
1897 | { |
---|
1898 | BOOLEAN nok=FALSE; |
---|
1899 | leftv nn=next; |
---|
1900 | next=NULL; |
---|
1901 | if(rtyp==IDHDL) |
---|
1902 | { |
---|
1903 | int t=Typ(); |
---|
1904 | if (t!=PROC_CMD) |
---|
1905 | { |
---|
1906 | void *d=CopyD(t); |
---|
1907 | data=d; |
---|
1908 | rtyp=t; |
---|
1909 | name=NULL; |
---|
1910 | e=NULL; |
---|
1911 | } |
---|
1912 | } |
---|
1913 | else if (rtyp==COMMAND) |
---|
1914 | { |
---|
1915 | command d=(command)data; |
---|
1916 | if(d->op==PROC_CMD) //assume d->argc==2 |
---|
1917 | { |
---|
1918 | char *what=(char *)(d->arg1.Data()); |
---|
1919 | idhdl h=ggetid(what); |
---|
1920 | if((h!=NULL)&&(IDTYP(h)==PROC_CMD)) |
---|
1921 | { |
---|
1922 | nok=d->arg2.Eval(); |
---|
1923 | if(!nok) |
---|
1924 | { |
---|
1925 | nok=iiMake_proc(h,req_packhdl,&d->arg2); |
---|
1926 | this->CleanUp(currRing); |
---|
1927 | if (!nok) |
---|
1928 | { |
---|
1929 | memcpy(this,&iiRETURNEXPR,sizeof(sleftv)); |
---|
1930 | memset(&iiRETURNEXPR,0,sizeof(sleftv)); |
---|
1931 | } |
---|
1932 | } |
---|
1933 | } |
---|
1934 | else nok=TRUE; |
---|
1935 | } |
---|
1936 | else if (d->op=='=') //assume d->argc==2 |
---|
1937 | { |
---|
1938 | if ((d->arg1.rtyp!=IDHDL)&&(d->arg1.rtyp!=DEF_CMD)) |
---|
1939 | { |
---|
1940 | nok=d->arg1.Eval(); |
---|
1941 | } |
---|
1942 | if (!nok) |
---|
1943 | { |
---|
1944 | const char *n=d->arg1.name; |
---|
1945 | nok=(n == NULL) || d->arg2.Eval(); |
---|
1946 | if (!nok) |
---|
1947 | { |
---|
1948 | int save_typ=d->arg1.rtyp; |
---|
1949 | omCheckAddr((ADDRESS)n); |
---|
1950 | if (d->arg1.rtyp!=IDHDL) |
---|
1951 | syMake(&d->arg1,n); |
---|
1952 | omCheckAddr((ADDRESS)d->arg1.name); |
---|
1953 | if (d->arg1.rtyp==IDHDL) |
---|
1954 | { |
---|
1955 | n=omStrDup(IDID((idhdl)d->arg1.data)); |
---|
1956 | killhdl((idhdl)d->arg1.data); |
---|
1957 | d->arg1.Init(); |
---|
1958 | //d->arg1.data=NULL; |
---|
1959 | d->arg1.name=n; |
---|
1960 | } |
---|
1961 | d->arg1.rtyp=DEF_CMD; |
---|
1962 | sleftv t; |
---|
1963 | if(save_typ!=PROC_CMD) save_typ=d->arg2.rtyp; |
---|
1964 | if (::RingDependend(d->arg2.rtyp)) |
---|
1965 | nok=iiDeclCommand(&t,&d->arg1,0,save_typ,&currRing->idroot); |
---|
1966 | else |
---|
1967 | nok=iiDeclCommand(&t,&d->arg1,0,save_typ,&IDROOT); |
---|
1968 | memcpy(&d->arg1,&t,sizeof(sleftv)); |
---|
1969 | omCheckAddr((ADDRESS)d->arg1.name); |
---|
1970 | nok=nok||iiAssign(&d->arg1,&d->arg2); |
---|
1971 | omCheckIf(d->arg1.name != NULL, // OB: ???? |
---|
1972 | omCheckAddr((ADDRESS)d->arg1.name)); |
---|
1973 | if (!nok) |
---|
1974 | { |
---|
1975 | memset(&d->arg1,0,sizeof(sleftv)); |
---|
1976 | this->CleanUp(); |
---|
1977 | rtyp=NONE; |
---|
1978 | } |
---|
1979 | } |
---|
1980 | } |
---|
1981 | else nok=TRUE; |
---|
1982 | } |
---|
1983 | else |
---|
1984 | { |
---|
1985 | sleftv tmp; tmp.Init(); |
---|
1986 | int toktype=iiTokType(d->op); |
---|
1987 | if ((toktype==CMD_M) |
---|
1988 | ||( toktype==ROOT_DECL_LIST) |
---|
1989 | ||( toktype==RING_DECL_LIST)) |
---|
1990 | { |
---|
1991 | if (d->argc <=3) |
---|
1992 | { |
---|
1993 | if (d->argc>=1) nok=d->arg1.Eval(); |
---|
1994 | if ((!nok) && (d->argc>=2)) |
---|
1995 | { |
---|
1996 | nok=d->arg2.Eval(); |
---|
1997 | d->arg1.next=(leftv)omAllocBin(sleftv_bin); |
---|
1998 | memcpy(d->arg1.next,&d->arg2,sizeof(sleftv)); |
---|
1999 | d->arg2.Init(); |
---|
2000 | } |
---|
2001 | if ((!nok) && (d->argc==3)) |
---|
2002 | { |
---|
2003 | nok=d->arg3.Eval(); |
---|
2004 | d->arg1.next->next=(leftv)omAllocBin(sleftv_bin); |
---|
2005 | memcpy(d->arg1.next->next,&d->arg3,sizeof(sleftv)); |
---|
2006 | d->arg3.Init(); |
---|
2007 | } |
---|
2008 | if (d->argc==0) |
---|
2009 | nok=nok||iiExprArithM(&tmp,NULL,d->op); |
---|
2010 | else |
---|
2011 | nok=nok||iiExprArithM(&tmp,&d->arg1,d->op); |
---|
2012 | } |
---|
2013 | else |
---|
2014 | { |
---|
2015 | nok=d->arg1.Eval(); |
---|
2016 | nok=nok||iiExprArithM(&tmp,&d->arg1,d->op); |
---|
2017 | } |
---|
2018 | } |
---|
2019 | else if (d->argc==1) |
---|
2020 | { |
---|
2021 | nok=d->arg1.Eval(); |
---|
2022 | nok=nok||iiExprArith1(&tmp,&d->arg1,d->op); |
---|
2023 | } |
---|
2024 | else if(d->argc==2) |
---|
2025 | { |
---|
2026 | nok=d->arg1.Eval(); |
---|
2027 | nok=nok||d->arg2.Eval(); |
---|
2028 | nok=nok||iiExprArith2(&tmp,&d->arg1,d->op,&d->arg2); |
---|
2029 | } |
---|
2030 | else if(d->argc==3) |
---|
2031 | { |
---|
2032 | nok=d->arg1.Eval(); |
---|
2033 | nok=nok||d->arg2.Eval(); |
---|
2034 | nok=nok||d->arg3.Eval(); |
---|
2035 | nok=nok||iiExprArith3(&tmp,d->op,&d->arg1,&d->arg2,&d->arg3); |
---|
2036 | } |
---|
2037 | else if(d->argc!=0) |
---|
2038 | { |
---|
2039 | nok=d->arg1.Eval(); |
---|
2040 | nok=nok||iiExprArithM(&tmp,&d->arg1,d->op); |
---|
2041 | } |
---|
2042 | else // d->argc == 0 |
---|
2043 | { |
---|
2044 | nok = iiExprArithM(&tmp, NULL, d->op); |
---|
2045 | } |
---|
2046 | this->CleanUp(); |
---|
2047 | memcpy(this,&tmp,sizeof(tmp)); |
---|
2048 | } |
---|
2049 | } |
---|
2050 | else if (((rtyp==0)||(rtyp==DEF_CMD)) |
---|
2051 | &&(name!=NULL)) |
---|
2052 | { |
---|
2053 | syMake(this,name); |
---|
2054 | } |
---|
2055 | #ifdef MDEBUG |
---|
2056 | switch(Typ()) |
---|
2057 | { |
---|
2058 | case NUMBER_CMD: |
---|
2059 | #ifdef LDEBUG |
---|
2060 | nTest((number)Data()); |
---|
2061 | #endif |
---|
2062 | break; |
---|
2063 | case BIGINT_CMD: |
---|
2064 | #ifdef LDEBUG |
---|
2065 | n_Test((number)Data(),coeffs_BIGINT); |
---|
2066 | #endif |
---|
2067 | break; |
---|
2068 | case POLY_CMD: |
---|
2069 | pTest((poly)Data()); |
---|
2070 | break; |
---|
2071 | case IDEAL_CMD: |
---|
2072 | case MODUL_CMD: |
---|
2073 | case MATRIX_CMD: |
---|
2074 | { |
---|
2075 | ideal id=(ideal)Data(); |
---|
2076 | omCheckAddrSize(id,sizeof(*id)); |
---|
2077 | int i=id->ncols*id->nrows-1; |
---|
2078 | for(;i>=0;i--) pTest(id->m[i]); |
---|
2079 | } |
---|
2080 | break; |
---|
2081 | } |
---|
2082 | #endif |
---|
2083 | if (nn!=NULL) nok=nok||nn->Eval(); |
---|
2084 | next=nn; |
---|
2085 | return nok; |
---|
2086 | } |
---|
2087 | |
---|
2088 | void * sattr::CopyA() |
---|
2089 | { |
---|
2090 | omCheckAddrSize(this,sizeof(sattr)); |
---|
2091 | return s_internalCopy(atyp,data); |
---|
2092 | } |
---|
2093 | |
---|