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