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