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