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