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