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