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