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