1 | // File: countedref_s.tst |
---|
2 | // Tests for reference and shared data types |
---|
3 | LIB "tst.lib"; |
---|
4 | tst_init(); |
---|
5 | |
---|
6 | system("reference"); |
---|
7 | system("shared"); |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | // reference huhu=17; |
---|
13 | int koko=17; |
---|
14 | |
---|
15 | reference huhu=koko; |
---|
16 | // string(huhu); |
---|
17 | //string(huhu); |
---|
18 | int(huhu); |
---|
19 | //string(huhu); |
---|
20 | |
---|
21 | |
---|
22 | huhu; |
---|
23 | |
---|
24 | string(huhu); |
---|
25 | reference hihi = huhu; |
---|
26 | |
---|
27 | hihi; |
---|
28 | |
---|
29 | hihi; |
---|
30 | string(hihi); |
---|
31 | |
---|
32 | ring r=0,x,dp; |
---|
33 | |
---|
34 | number(hihi); |
---|
35 | int(hihi); |
---|
36 | |
---|
37 | hihi+huhu; |
---|
38 | hihi+huhu; |
---|
39 | hihi*hihi; |
---|
40 | |
---|
41 | hihi*12; |
---|
42 | huhu+10; |
---|
43 | hihi+10; |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | int obj =19; |
---|
48 | reference pobj = obj; |
---|
49 | //attrib(pobj, "huhu","qweqw"); |
---|
50 | |
---|
51 | //ython_run("def myprint(*args): print args"); |
---|
52 | //attrib(myprint); |
---|
53 | //attrib(myprint, "func_name"); |
---|
54 | |
---|
55 | kill obj, pobj; |
---|
56 | |
---|
57 | //attrib(myprint, "func_name", "byAnyOtherName"); |
---|
58 | //attrib(myprint, "func_name"); |
---|
59 | |
---|
60 | //list(huhu,huhu,hihi); |
---|
61 | |
---|
62 | "qwewqewqeqw"; |
---|
63 | |
---|
64 | huhu; |
---|
65 | hihi; |
---|
66 | "da"; |
---|
67 | huhu="qweeqw"; |
---|
68 | "hier"; |
---|
69 | huhu; |
---|
70 | hihi; |
---|
71 | |
---|
72 | typeof(huhu); |
---|
73 | |
---|
74 | int neunzehn = 19; |
---|
75 | reference ref1 =neunzehn; |
---|
76 | reference ref2 = ref1; |
---|
77 | def ref3=ref1; |
---|
78 | |
---|
79 | (ref1,ref2,ref3); |
---|
80 | //ref1=16; |
---|
81 | |
---|
82 | (ref1,ref2,ref3); |
---|
83 | list lllll = list(17,13); |
---|
84 | reference ref1 = lllll; |
---|
85 | ref2 = ref1; |
---|
86 | ref3=ref1; |
---|
87 | "huhu"; |
---|
88 | |
---|
89 | |
---|
90 | ref1;ref2;ref3; |
---|
91 | |
---|
92 | //ref2[1]=9; |
---|
93 | ref1;ref2;ref3; |
---|
94 | ref_extract(ref2); |
---|
95 | ref_extract(ref1); |
---|
96 | |
---|
97 | |
---|
98 | list lll = list(1,2); |
---|
99 | reference lref = lll; |
---|
100 | |
---|
101 | lref; |
---|
102 | "lref[2]:"; |
---|
103 | |
---|
104 | int elt = lref[2]; |
---|
105 | elt; |
---|
106 | lref[2]=3; |
---|
107 | |
---|
108 | lref; |
---|
109 | //Countedref::setitem(lref,2,3); |
---|
110 | lref; |
---|
111 | //lref[2]; |
---|
112 | "skip write";///lref[2]=8; |
---|
113 | //lref[2]; |
---|
114 | "huhu"; |
---|
115 | lref; |
---|
116 | "hihi"; |
---|
117 | list ll=(1,2,3); |
---|
118 | ll[2]; |
---|
119 | ll[2]=7; |
---|
120 | ll; |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | reference part = ll[2]; |
---|
125 | part; |
---|
126 | part=17; |
---|
127 | ll; |
---|
128 | |
---|
129 | typeof(part); |
---|
130 | |
---|
131 | |
---|
132 | ring r =0,(x,y,z),lp; |
---|
133 | |
---|
134 | poly p = x+y+z; |
---|
135 | |
---|
136 | reference pref = p; |
---|
137 | |
---|
138 | pref; |
---|
139 | |
---|
140 | ring q = 0,(x,y),lp; |
---|
141 | |
---|
142 | pref; |
---|
143 | |
---|
144 | |
---|
145 | setring(r); |
---|
146 | pref; |
---|
147 | poly ppp = 7; |
---|
148 | reference pppref = ppp; |
---|
149 | |
---|
150 | setring(q); |
---|
151 | poly pp=1; |
---|
152 | |
---|
153 | reference ppref = pp; |
---|
154 | |
---|
155 | |
---|
156 | pref + ppref; |
---|
157 | |
---|
158 | pref + pppref; |
---|
159 | |
---|
160 | setring(r); |
---|
161 | pref + pppref; |
---|
162 | kill pppref; |
---|
163 | ring r=0,(x,y,z),dp; |
---|
164 | poly f=x2+y2+z2+x+y+z; |
---|
165 | |
---|
166 | poly xp=x; |
---|
167 | poly yp=y; |
---|
168 | poly zp=z; |
---|
169 | reference fref = f; |
---|
170 | reference xref=xp; |
---|
171 | reference yref=yp; |
---|
172 | reference zref=zp; |
---|
173 | subst(f,x,link(yref),y,zp); |
---|
174 | subst(fref,x,yp,y,zp); |
---|
175 | subst(fref,x,yp,y,zref); |
---|
176 | |
---|
177 | ring r=0,(x,y,z),dp; |
---|
178 | poly p = x+y; |
---|
179 | reference ref7=p; |
---|
180 | ref7; |
---|
181 | ring q=0,(x,y),dp; |
---|
182 | ref7; |
---|
183 | poly p = x+y; |
---|
184 | ref7=p; |
---|
185 | ref7; |
---|
186 | |
---|
187 | newstruct("mystruct", "int i, int j"); |
---|
188 | |
---|
189 | mystruct stru; |
---|
190 | stru.i = 17; |
---|
191 | |
---|
192 | //stru.j =19; |
---|
193 | stru.i; |
---|
194 | //stru; |
---|
195 | |
---|
196 | //reference sref = stru; |
---|
197 | |
---|
198 | //sref; |
---|
199 | //sref.i=9; |
---|
200 | //sref; |
---|
201 | //stru; |
---|
202 | |
---|
203 | reference spart = stru.i; |
---|
204 | //spart; |
---|
205 | //spart; |
---|
206 | //spart; |
---|
207 | spart =12; |
---|
208 | spart; |
---|
209 | stru; |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | list listoflists = list(list(1,2,3)); |
---|
214 | |
---|
215 | reference lolref = listoflists; |
---|
216 | |
---|
217 | lolref[1]; |
---|
218 | |
---|
219 | lolref[1][2]; |
---|
220 | lolref[1][2]=9; |
---|
221 | listoflists; |
---|
222 | mystruct ms; |
---|
223 | |
---|
224 | ms.i=2; |
---|
225 | ms.j=3; |
---|
226 | list listofnewstr = list(ms); |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | reference lonren = listofnewstr; |
---|
231 | |
---|
232 | lonren[1]; |
---|
233 | listofnewstr[1].i;// doesn'nt work |
---|
234 | |
---|
235 | reference refelt = listofnewstr[1]; |
---|
236 | refelt.i = 7; |
---|
237 | |
---|
238 | lonren; |
---|
239 | listofnewstr; |
---|
240 | |
---|
241 | reference refelt2 =lonren[1]; |
---|
242 | refelt2.i = 17; |
---|
243 | listofnewstr; |
---|
244 | |
---|
245 | |
---|
246 | //reference rseq=(1,2,3); |
---|
247 | |
---|
248 | //rseq; |
---|
249 | |
---|
250 | |
---|
251 | def copyref = refelt2; |
---|
252 | |
---|
253 | copyref; |
---|
254 | typeof(copyref); |
---|
255 | |
---|
256 | list ll17=list(1,2,4); |
---|
257 | shared sh17 = list(1,2,4); |
---|
258 | |
---|
259 | sh17; |
---|
260 | sh17[1]=7; |
---|
261 | |
---|
262 | sh17; |
---|
263 | |
---|
264 | reference ref17 = sh17; |
---|
265 | |
---|
266 | ref17[2]=19; |
---|
267 | sh17; |
---|
268 | |
---|
269 | shared ll19=ref17; |
---|
270 | ll19[3]=9; |
---|
271 | |
---|
272 | sh17; |
---|
273 | |
---|
274 | |
---|
275 | typeof(link(sh17)); |
---|
276 | |
---|
277 | shared sh19 = list(7,8,9); |
---|
278 | |
---|
279 | sh19; |
---|
280 | |
---|
281 | sh19[2]=5; |
---|
282 | sh19; |
---|
283 | |
---|
284 | |
---|
285 | list ll23; |
---|
286 | reference ref23 =ll23; |
---|
287 | ref23; |
---|
288 | |
---|
289 | |
---|
290 | kill ll23; |
---|
291 | ref23; |
---|
292 | |
---|
293 | list ll24 = list(1,2,3); |
---|
294 | shared data = ll24[2]; |
---|
295 | shared dataA = data; |
---|
296 | data; |
---|
297 | typeof(data); |
---|
298 | data =17; |
---|
299 | typeof(data); |
---|
300 | |
---|
301 | data; |
---|
302 | dataA; |
---|
303 | |
---|
304 | |
---|
305 | typeof(link(data)); |
---|
306 | |
---|
307 | // list ll24 = list(1,2,3); |
---|
308 | ll24; |
---|
309 | |
---|
310 | shared data2 = ll24; |
---|
311 | typeof(link(data2)); |
---|
312 | data2; |
---|
313 | data2[2]; |
---|
314 | data2[2] =19; |
---|
315 | data2[2]; |
---|
316 | data2; |
---|
317 | |
---|
318 | |
---|
319 | shared data3 =12; |
---|
320 | data3; |
---|
321 | data3 =13; |
---|
322 | data3; |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | newstruct("teststruct","int i,int j"); |
---|
327 | |
---|
328 | teststruct ts; |
---|
329 | reference tsref =ts; |
---|
330 | |
---|
331 | tsref.i=17; |
---|
332 | ts; |
---|
333 | |
---|
334 | |
---|
335 | shared tssh=ts; |
---|
336 | |
---|
337 | tssh.j = 9; |
---|
338 | |
---|
339 | ts; |
---|
340 | tssh; |
---|
341 | |
---|
342 | int ival=17; |
---|
343 | shared iref =ival; |
---|
344 | shared iref2 =iref; |
---|
345 | |
---|
346 | iref2 = 19; |
---|
347 | |
---|
348 | iref; |
---|
349 | iref2; |
---|
350 | ival; |
---|
351 | |
---|
352 | |
---|
353 | list lval=list(56,9); |
---|
354 | shared lRef =lval; |
---|
355 | shared lref2 =lRef; |
---|
356 | |
---|
357 | lref2 = list(324,253); |
---|
358 | |
---|
359 | lRef; |
---|
360 | lref2; |
---|
361 | lval; |
---|
362 | |
---|
363 | // some debugging commands |
---|
364 | |
---|
365 | int db; int db2; |
---|
366 | reference dbref = db; |
---|
367 | reference dbref2 = dbref; |
---|
368 | reference dbref3 = db; |
---|
369 | |
---|
370 | system(dbref, count); |
---|
371 | system(dbref, same, dbref); |
---|
372 | system(dbref, same, dbref2); |
---|
373 | system(dbref, same, dbref3); |
---|
374 | system(dbref, same, db2); |
---|
375 | |
---|
376 | system(dbref, likewise, dbref); |
---|
377 | system(dbref, likewise, dbref2); |
---|
378 | system(dbref, likewise, dbref3); |
---|
379 | system(dbref, like, dbref); |
---|
380 | system(dbref, like, dbref2); |
---|
381 | system(dbref, like, dbref3); |
---|
382 | system(dbref, like, db); |
---|
383 | system(dbref, like, db2); |
---|
384 | |
---|
385 | system(dbref, "typeof"); |
---|
386 | system(dbref, "type"); |
---|
387 | |
---|
388 | system(dbref, name); |
---|
389 | system(dbref2, name); |
---|
390 | |
---|
391 | system(dbref, enumerate) == system(dbref2, enumerate); |
---|
392 | system(dbref, enumerate) == system(dbref, enumerate); |
---|
393 | system(dbref, enumerate) != system(dbref3, enumerate); |
---|
394 | |
---|
395 | |
---|
396 | shared mem = 17; |
---|
397 | shared mem2 = mem; |
---|
398 | shared mem3 = link(mem); |
---|
399 | |
---|
400 | system(mem, count); |
---|
401 | system(mem, same, mem); |
---|
402 | system(mem, same, mem2); |
---|
403 | system(mem, same, mem3); |
---|
404 | system(mem, same, db2); |
---|
405 | |
---|
406 | system(mem, likewise, mem); |
---|
407 | system(mem, likewise, mem2); |
---|
408 | system(mem, likewise, mem3); |
---|
409 | system(mem, like, mem); |
---|
410 | system(mem, like, mem2); |
---|
411 | system(mem, like, mem3); |
---|
412 | system(mem, like, db); |
---|
413 | system(mem, like, db2); |
---|
414 | |
---|
415 | system(mem, "typeof"); |
---|
416 | system(mem, "type"); |
---|
417 | |
---|
418 | system(mem, name) == system(mem2, name); |
---|
419 | |
---|
420 | system(mem, enumerate) == system(mem2, enumerate); |
---|
421 | system(mem, enumerate) == system(mem, enumerate); |
---|
422 | system(mem, enumerate) != system(mem3, enumerate); |
---|
423 | |
---|
424 | reference memref = mem; |
---|
425 | system(mem, same, memref); |
---|
426 | system(mem, likewise, memref); |
---|
427 | |
---|
428 | // subexpressions |
---|
429 | shared shll =19; |
---|
430 | list llsh; |
---|
431 | llsh [1] = shll; |
---|
432 | typeof(llsh[1]); |
---|
433 | llsh; |
---|
434 | |
---|
435 | shared shll2 =12; |
---|
436 | |
---|
437 | llsh[1] = shll2; |
---|
438 | |
---|
439 | llsh; |
---|
440 | |
---|
441 | shll; |
---|
442 | |
---|
443 | shared shll3 =llsh[1]; |
---|
444 | shll3 =14; |
---|
445 | |
---|
446 | |
---|
447 | llsh; |
---|
448 | |
---|
449 | shll; |
---|
450 | |
---|
451 | reference llshref = llsh[1]; |
---|
452 | llshref = 13; |
---|
453 | llsh; |
---|
454 | shll; |
---|
455 | |
---|
456 | typeof(llsh[1]); |
---|
457 | |
---|
458 | |
---|
459 | shared sh5=5; |
---|
460 | |
---|
461 | list ll5=list(sh5); |
---|
462 | |
---|
463 | ll5[2]= sh5; |
---|
464 | ll5[2]=7; |
---|
465 | ll5; |
---|
466 | sh5; |
---|
467 | |
---|
468 | |
---|
469 | def defed = sh5; |
---|
470 | typeof(defed); |
---|
471 | defed=17; |
---|
472 | |
---|
473 | sh5; |
---|
474 | |
---|
475 | shared shll6=list(); |
---|
476 | |
---|
477 | shared shll7=shll6; |
---|
478 | shll6[1]=17; |
---|
479 | |
---|
480 | shll7; |
---|
481 | |
---|
482 | |
---|
483 | newstruct("mystrsh", "int i"); |
---|
484 | |
---|
485 | mystrsh mystrval8; |
---|
486 | |
---|
487 | shared val8 = mystrval8; |
---|
488 | val8; |
---|
489 | |
---|
490 | shared val9= val8; |
---|
491 | val8.i=17; |
---|
492 | |
---|
493 | val9; |
---|
494 | |
---|
495 | newstruct("mystrsh2", "def sh"); |
---|
496 | |
---|
497 | mystrsh2 mystrval10; |
---|
498 | |
---|
499 | shared val17 = 17; |
---|
500 | mystrval10.sh = val17; |
---|
501 | mystrsh2 mystrval11 = mystrval10; |
---|
502 | |
---|
503 | mystrval10; |
---|
504 | mystrval11; |
---|
505 | |
---|
506 | shared ref10sh= mystrval10.sh; |
---|
507 | ref10sh=10; |
---|
508 | |
---|
509 | mystrval11; |
---|
510 | system(mystrval11.sh, name)==system(mystrval10.sh, name); |
---|
511 | shared val11 = mystrval11.sh; |
---|
512 | val11=9; |
---|
513 | mystrval11; |
---|
514 | mystrval10; |
---|
515 | |
---|
516 | |
---|
517 | shared(mystrval11.sh) = 11; |
---|
518 | |
---|
519 | |
---|
520 | |
---|
521 | mystrval10; |
---|
522 | system(mystrval11.sh, name)==system(mystrval10.sh, name);; |
---|
523 | |
---|
524 | shared myllsh= 19; |
---|
525 | list myllval; |
---|
526 | myllval[1]= myllsh; |
---|
527 | |
---|
528 | shared(myllval[1]) = 17; |
---|
529 | myllval; |
---|
530 | myllsh; |
---|
531 | |
---|
532 | shared(myllval[1]) = 18; |
---|
533 | myllval; |
---|
534 | myllsh; |
---|
535 | |
---|
536 | shared shvalOFmyllval_1 = myllval[1]; |
---|
537 | shvalOFmyllval_1 = 3; |
---|
538 | myllsh; |
---|
539 | typeof(myllval[1]); |
---|
540 | |
---|
541 | |
---|
542 | |
---|
543 | proc replace(def lhs, def rhs) { lhs = rhs; } |
---|
544 | |
---|
545 | replace(myllval[1], 14); |
---|
546 | |
---|
547 | myllval; |
---|
548 | myllsh; |
---|
549 | |
---|
550 | shared(myllval[1]) =15; |
---|
551 | typeof(myllval[1]); |
---|
552 | |
---|
553 | myllval; |
---|
554 | myllsh; |
---|
555 | |
---|
556 | myllval[1] =16; |
---|
557 | |
---|
558 | typeof(myllval[1]); |
---|
559 | myllval; |
---|
560 | myllsh; |
---|
561 | |
---|
562 | link(myllsh); |
---|
563 | |
---|
564 | |
---|
565 | shared val=1; |
---|
566 | val; |
---|
567 | list ll=list(val); |
---|
568 | ll; |
---|
569 | link(ll[1])=8; |
---|
570 | val; |
---|
571 | ll; |
---|
572 | shared vv =ll[1]; |
---|
573 | vv=9; |
---|
574 | ll; |
---|
575 | vv; |
---|
576 | val; |
---|
577 | reference vvv=ll[1]; |
---|
578 | vvv=9; |
---|
579 | ll; |
---|
580 | typeof(ll[1]); |
---|
581 | ll[1]=val; |
---|
582 | shared vv =ll[1]; |
---|
583 | |
---|
584 | |
---|
585 | |
---|
586 | |
---|
587 | |
---|
588 | ring r2=0,x,dp; |
---|
589 | |
---|
590 | poly p = x+1; |
---|
591 | |
---|
592 | shared p_sh =p; |
---|
593 | |
---|
594 | |
---|
595 | ring r3=0,x,dp; |
---|
596 | |
---|
597 | p_sh; |
---|
598 | |
---|
599 | setring(r2); |
---|
600 | |
---|
601 | p_sh; |
---|
602 | |
---|
603 | |
---|
604 | |
---|
605 | kill mem, mem2, mem3; |
---|
606 | shared mem = list(17); |
---|
607 | shared mem2 = mem; |
---|
608 | shared mem3 = link(mem); |
---|
609 | |
---|
610 | system(mem, count); |
---|
611 | system(mem, same, mem); |
---|
612 | system(mem, same, mem2); |
---|
613 | system(mem, same, mem3); |
---|
614 | system(mem, same, db2); |
---|
615 | system(mem, like, mem); |
---|
616 | system(mem, like, mem2); |
---|
617 | system(mem, like, mem3); |
---|
618 | system(mem, like, db2); |
---|
619 | |
---|
620 | |
---|
621 | shared llr = list(1,2,3); |
---|
622 | |
---|
623 | llr; |
---|
624 | ring r=0,x,dp; |
---|
625 | |
---|
626 | llr[1]=x+1; |
---|
627 | |
---|
628 | llr; |
---|
629 | |
---|
630 | ring q=0,y,dp; |
---|
631 | |
---|
632 | llr; |
---|
633 | |
---|
634 | setring(r); |
---|
635 | |
---|
636 | llr; |
---|
637 | |
---|
638 | |
---|
639 | shared sharedp =x; |
---|
640 | sharedp; |
---|
641 | setring q; |
---|
642 | sharedp; |
---|
643 | setring(r); |
---|
644 | sharedp; |
---|
645 | setring q; |
---|
646 | sharedp=y; |
---|
647 | sharedp; |
---|
648 | |
---|
649 | setring(r); |
---|
650 | sharedp; |
---|
651 | setring q; |
---|
652 | sharedp; |
---|
653 | |
---|
654 | setring(r); |
---|
655 | poly xpoly=x; |
---|
656 | reference refp =xpoly; |
---|
657 | refp; |
---|
658 | setring q; |
---|
659 | refp; |
---|
660 | setring(r); |
---|
661 | refp; |
---|
662 | setring q; |
---|
663 | refp=y; |
---|
664 | refp; |
---|
665 | |
---|
666 | setring(r); |
---|
667 | refp; |
---|
668 | setring q; |
---|
669 | refp; |
---|
670 | |
---|
671 | |
---|
672 | |
---|
673 | kill ll, r, q; |
---|
674 | |
---|
675 | shared ll =list(1,2,3); |
---|
676 | ring r=0,x,dp; |
---|
677 | ll[1] =x; |
---|
678 | ring q=0,y,dp; |
---|
679 | ll; |
---|
680 | ll[1]; |
---|
681 | ll; |
---|
682 | setring r; |
---|
683 | ll; |
---|
684 | setring q; |
---|
685 | ll[1]=y; |
---|
686 | ll; |
---|
687 | setring r; |
---|
688 | ll; |
---|
689 | ll[1]; |
---|
690 | setring q; |
---|
691 | ll[1]; |
---|
692 | |
---|
693 | "qewqe"; |
---|
694 | |
---|
695 | "qweewq"; |
---|
696 | |
---|
697 | shared llshort=list(1,2); |
---|
698 | |
---|
699 | llshort; |
---|
700 | llshort[3]=17; |
---|
701 | |
---|
702 | llshort; |
---|
703 | |
---|
704 | /// Pratical examples: cache |
---|
705 | echo=1; |
---|
706 | newstruct("sqcache", "shared table"); |
---|
707 | |
---|
708 | proc cached_square(sqcache cache, int arg) |
---|
709 | { |
---|
710 | if (arg == 0) { return (0); } |
---|
711 | shared value = cache.table[arg]; |
---|
712 | if (system(value, undef)) { value = arg^2; } |
---|
713 | return (int(value)); |
---|
714 | } |
---|
715 | |
---|
716 | system("install", "sqcache", "(", cached_square, 4); |
---|
717 | sqcache square; |
---|
718 | |
---|
719 | shared init = list(); |
---|
720 | square.table = init; |
---|
721 | |
---|
722 | int t=timer; |
---|
723 | int i, j,k,n; |
---|
724 | n = 100; |
---|
725 | init=(0:n); |
---|
726 | for( i = 0; i <n; i++) { |
---|
727 | k = square(i); |
---|
728 | } |
---|
729 | for( i = 0; i <n; i++) { |
---|
730 | k = square(i); |
---|
731 | } |
---|
732 | for( i = 0; i <n; i++) { |
---|
733 | k = square(i); |
---|
734 | } |
---|
735 | for( i = 0; i <n; i++) { |
---|
736 | k = square(i); |
---|
737 | } |
---|
738 | for( i = 0; i <n; i++) { |
---|
739 | k = square(i); |
---|
740 | } |
---|
741 | for( i = 0; i <n; i++) { |
---|
742 | k = square(i); |
---|
743 | } |
---|
744 | for( i = 0; i <n; i++) { |
---|
745 | k = square(i); |
---|
746 | } |
---|
747 | for( i = 0; i <n; i++) { |
---|
748 | k = square(i); |
---|
749 | } |
---|
750 | for( i = 0; i <n; i++) { |
---|
751 | k = square(i); |
---|
752 | } |
---|
753 | for( i = 0; i <n; i++) { |
---|
754 | k = square(i); |
---|
755 | } |
---|
756 | |
---|
757 | |
---|
758 | |
---|
759 | int time1 = timer -t; |
---|
760 | t=timer; |
---|
761 | list cll=(0:n+1); |
---|
762 | for( i = 1; i <=n; i++) { |
---|
763 | cll[i] = (i^2); |
---|
764 | } |
---|
765 | for( i = 1; i <=n; i++) { |
---|
766 | k = cll[i]; |
---|
767 | } |
---|
768 | for( i = 1; i <=n; i++) { |
---|
769 | k = cll[i]; |
---|
770 | } |
---|
771 | for( i = 1; i <=n; i++) { |
---|
772 | k = cll[i]; |
---|
773 | } |
---|
774 | for( i = 1; i <=n; i++) { |
---|
775 | k = cll[i]; |
---|
776 | } |
---|
777 | for( i = 1; i <=n; i++) { |
---|
778 | k = cll[i]; |
---|
779 | } |
---|
780 | for( i = 1; i <=n; i++) { |
---|
781 | k = cll[i]; |
---|
782 | } |
---|
783 | for( i = 1; i <=n; i++) { |
---|
784 | k = cll[i]; |
---|
785 | } |
---|
786 | for( i = 1; i <=n; i++) { |
---|
787 | k = cll[i]; |
---|
788 | } |
---|
789 | for( i = 1; i <=n; i++) { |
---|
790 | k = cll[i]; |
---|
791 | } |
---|
792 | |
---|
793 | |
---|
794 | |
---|
795 | |
---|
796 | |
---|
797 | int time2 = timer -t; |
---|
798 | |
---|
799 | |
---|
800 | |
---|
801 | |
---|
802 | //time1; |
---|
803 | //time2; |
---|
804 | |
---|
805 | |
---|
806 | newstruct("bdd", "int idx,shared high,shared low"); |
---|
807 | bdd diag; |
---|
808 | shared zero=0; |
---|
809 | diag.high=zero; |
---|
810 | diag.low=zero; |
---|
811 | diag.idx = 0; |
---|
812 | |
---|
813 | //for (i=0; i <=n; i++) |
---|
814 | n=20; |
---|
815 | proc chain(shared arg) |
---|
816 | { |
---|
817 | bdd diag; |
---|
818 | diag.idx = arg.idx+1; |
---|
819 | diag.high=arg; |
---|
820 | diag.low=arg; |
---|
821 | return (diag); |
---|
822 | } |
---|
823 | |
---|
824 | |
---|
825 | t=timer; |
---|
826 | for (i=0; i<=n; i++ ) |
---|
827 | { |
---|
828 | diag = chain(diag); |
---|
829 | } |
---|
830 | //timer-t; |
---|
831 | |
---|
832 | shared iter=diag; |
---|
833 | //while(int(iter.idx)) { |
---|
834 | // iter.idx; |
---|
835 | // iter = iter.high; |
---|
836 | //} |
---|
837 | |
---|
838 | proc print_bdd(shared iter) { |
---|
839 | string res = "("+string(iter.idx)+", "; |
---|
840 | shared it1=iter.high; |
---|
841 | shared it0=iter.low; |
---|
842 | |
---|
843 | if (int(iter.idx)) |
---|
844 | { |
---|
845 | res=res + print_bdd(it1) + " : "; |
---|
846 | res= res+ print_bdd(it0)+ ")"; |
---|
847 | } |
---|
848 | return (res);// print_bdd(iter.low); |
---|
849 | } |
---|
850 | shared iter2=diag; |
---|
851 | |
---|
852 | //print_bdd(iter2); |
---|
853 | |
---|
854 | newstruct("bdd0", "int idx,def high,def low"); |
---|
855 | bdd0 diag0; |
---|
856 | diag0.idx=0; |
---|
857 | diag0.high=0; |
---|
858 | diag0.low=0; |
---|
859 | |
---|
860 | |
---|
861 | proc chain0(bdd0 arg) |
---|
862 | { |
---|
863 | bdd0 diag; |
---|
864 | diag.idx = arg.idx+1; |
---|
865 | diag.high=arg; |
---|
866 | diag.low=arg; |
---|
867 | return (diag); |
---|
868 | } |
---|
869 | |
---|
870 | /// Deactivate "classical" way, take too long (many copies) |
---|
871 | n=0; |
---|
872 | t=timer; |
---|
873 | def val; |
---|
874 | for (i=0; i<=n; i++ ) |
---|
875 | { |
---|
876 | val =chain0(diag0); |
---|
877 | diag0=val; |
---|
878 | } |
---|
879 | //timer-t; |
---|
880 | |
---|
881 | proc print_bdd0(def iter) { |
---|
882 | string res = "("+string(iter.idx)+", "; |
---|
883 | def it1=iter.high; |
---|
884 | def it0=iter.low; |
---|
885 | |
---|
886 | if (int(iter.idx)) |
---|
887 | { |
---|
888 | res=res + print_bdd0(it1) + " : "; |
---|
889 | res= res+ print_bdd0(it0)+ ")"; |
---|
890 | } |
---|
891 | return (res);// print_bdd(iter.low); |
---|
892 | } |
---|
893 | |
---|
894 | |
---|
895 | //print_bdd0(diag0); |
---|
896 | |
---|
897 | //diag; |
---|
898 | |
---|
899 | kill sh17,sh18; |
---|
900 | bdd b01; |
---|
901 | |
---|
902 | (b01.idx)=0; |
---|
903 | shared sh17=17; |
---|
904 | shared sh18=18; |
---|
905 | b01.high = sh17; |
---|
906 | b01.low = sh18; |
---|
907 | |
---|
908 | |
---|
909 | b01.high; |
---|
910 | b01.low; |
---|
911 | |
---|
912 | def(b01.high) = 19; |
---|
913 | def(b01.low) = 20; |
---|
914 | |
---|
915 | b01.high; |
---|
916 | b01.low; |
---|
917 | |
---|
918 | sh17; |
---|
919 | sh18; |
---|
920 | kill ll; |
---|
921 | |
---|
922 | shared ll1=1; shared ll2=2; |
---|
923 | list ll=list(ll1, ll2); |
---|
924 | typeof(ll[1]); |
---|
925 | |
---|
926 | |
---|
927 | def(ll[1]) = 3; |
---|
928 | ll; |
---|
929 | ll1; |
---|
930 | typeof(ll[1]); |
---|
931 | |
---|
932 | |
---|
933 | shared(ll[1]) = 5; |
---|
934 | ll; |
---|
935 | ll1; |
---|
936 | typeof(ll[1]); |
---|
937 | |
---|
938 | |
---|
939 | shared ll3=2; |
---|
940 | |
---|
941 | ll[3]=ll3; |
---|
942 | |
---|
943 | typeof(ll[3]); |
---|
944 | ll; |
---|
945 | |
---|
946 | def(ll[3])=4; |
---|
947 | |
---|
948 | ll3; ll; |
---|
949 | typeof(ll[3]); |
---|
950 | |
---|
951 | ll[4]=1; |
---|
952 | |
---|
953 | ll[4] = ll3; |
---|
954 | ll; |
---|
955 | def(ll[4])=17; |
---|
956 | ll; |
---|
957 | |
---|
958 | |
---|
959 | bdd b02; |
---|
960 | |
---|
961 | b02.high; |
---|
962 | def(b02.high); |
---|
963 | def(b02.high)=9; |
---|
964 | |
---|
965 | b02.high; |
---|
966 | typeof(b02.high); |
---|
967 | |
---|
968 | kill ll; |
---|
969 | |
---|
970 | list ll; |
---|
971 | ll[1] = ll1; |
---|
972 | shared(ll[1]) = 3333; |
---|
973 | ll; |
---|
974 | |
---|
975 | |
---|
976 | |
---|
977 | kill ll; |
---|
978 | |
---|
979 | shared ll=list(); |
---|
980 | shared llsync=ll; |
---|
981 | def(ll[1])=list(3,4); |
---|
982 | ll; |
---|
983 | |
---|
984 | def(def(ll[1])[3])=list(5,6); |
---|
985 | ll; |
---|
986 | |
---|
987 | def(ll[1])[3]=list(8); |
---|
988 | ll; |
---|
989 | |
---|
990 | |
---|
991 | ll[1][3]=list(6); |
---|
992 | ll; |
---|
993 | llsync; |
---|
994 | |
---|
995 | kill sh; |
---|
996 | newstruct("bbx", "def i"); |
---|
997 | bbx box; |
---|
998 | |
---|
999 | shared sh=box; |
---|
1000 | sh; |
---|
1001 | sh.i =list(1,2); |
---|
1002 | sh; |
---|
1003 | |
---|
1004 | sh.i[2]=19; |
---|
1005 | |
---|
1006 | sh; |
---|
1007 | sh.i; |
---|
1008 | |
---|
1009 | system(sh, "help"); |
---|
1010 | |
---|
1011 | |
---|
1012 | kill i, iref; |
---|
1013 | int i =9; |
---|
1014 | shared iref = i; |
---|
1015 | link l1 = "ssi:fork"; open(l1); |
---|
1016 | write(l1, quote(list(iref, iref))); |
---|
1017 | |
---|
1018 | waitfirst(list(l1), 500); |
---|
1019 | def argi = read(l1); |
---|
1020 | argi; |
---|
1021 | typeof(argi[1]); |
---|
1022 | typeof(argi[2]); |
---|
1023 | |
---|
1024 | |
---|
1025 | //typeof(link(argi)); |
---|
1026 | close(l1); |
---|
1027 | |
---|
1028 | |
---|
1029 | kill i, iref,l1; |
---|
1030 | int i =9; |
---|
1031 | reference iref = i; |
---|
1032 | link l1 = "ssi:fork"; open(l1); |
---|
1033 | write(l1, quote(def(iref))); |
---|
1034 | |
---|
1035 | waitfirst(list(l1), 500); |
---|
1036 | def argi = read(l1); |
---|
1037 | argi; |
---|
1038 | typeof(argi); |
---|
1039 | typeof(link(argi)); |
---|
1040 | close(l1); |
---|
1041 | |
---|
1042 | i=10; |
---|
1043 | argi; |
---|
1044 | |
---|
1045 | shared backtest=list(17,9); |
---|
1046 | |
---|
1047 | backtest; |
---|
1048 | |
---|
1049 | shared backtest_1 = backtest[1]; |
---|
1050 | |
---|
1051 | backtest_1; |
---|
1052 | |
---|
1053 | backtest_1=6; |
---|
1054 | backtest; |
---|
1055 | kill backtest; |
---|
1056 | |
---|
1057 | backtest_1; |
---|
1058 | |
---|
1059 | backtest_1; |
---|
1060 | |
---|
1061 | kill i, ll; |
---|
1062 | int i = 17; |
---|
1063 | reference ref = i; |
---|
1064 | |
---|
1065 | ref; |
---|
1066 | ref + ref; // Automated 'dereferencing' |
---|
1067 | ref + 4; |
---|
1068 | 4 + ref; |
---|
1069 | |
---|
1070 | |
---|
1071 | list ll=(1,2,3,4,5); |
---|
1072 | ref=3; |
---|
1073 | ll[ref]; |
---|
1074 | |
---|
1075 | kill r; |
---|
1076 | ring r=0,(x,y,z),dp; |
---|
1077 | poly p = x+y+z; |
---|
1078 | shared xsh = x+1; |
---|
1079 | poly(xsh); |
---|
1080 | poly(xsh); |
---|
1081 | poly(xsh); |
---|
1082 | |
---|
1083 | |
---|
1084 | |
---|
1085 | // Checking side effects |
---|
1086 | list changeme; |
---|
1087 | changeme; |
---|
1088 | |
---|
1089 | proc setfirst(reference ll, def arg) { ll[1] = arg; } |
---|
1090 | |
---|
1091 | setfirst(changeme, 17); |
---|
1092 | changeme; |
---|
1093 | |
---|
1094 | // Checking differenct variants of list conversion |
---|
1095 | |
---|
1096 | shared shlist = list(1,2,3); |
---|
1097 | list thelist = shlist; |
---|
1098 | thelist; |
---|
1099 | list(shlist); |
---|
1100 | link(shlist); |
---|
1101 | |
---|
1102 | /// Checking that link deeply copies indeed |
---|
1103 | kill r, xsh, ll; |
---|
1104 | ring r = 0, (x,y,z), dp; |
---|
1105 | poly p = x + y + z; |
---|
1106 | shared xsh = x; |
---|
1107 | |
---|
1108 | subst(p, xsh,1, y,2, z,3); // fails |
---|
1109 | subst(p, poly(xsh),1, y,2, z,3); // good |
---|
1110 | subst(p, link(xsh),1, y,2, z,3); // fine |
---|
1111 | subst(p, link(xsh),1, y,2, z,3); // fine |
---|
1112 | subst(p, link(xsh),1, y,2, z,3); // fine |
---|
1113 | |
---|
1114 | list ll = list(xsh, xsh, xsh); |
---|
1115 | ll[1] = y; // replaced only first entry |
---|
1116 | ll; |
---|
1117 | shared(ll[2]) = z; // replaces the others |
---|
1118 | ll; |
---|
1119 | def(ll[2]) = x; // generic alternative |
---|
1120 | ll; |
---|
1121 | |
---|
1122 | // -------------------------------------------------------- |
---|
1123 | kill r, ref, ref2; |
---|
1124 | ring r;ideal I = maxideal(1);ideal J = I; |
---|
1125 | reference ref = I; |
---|
1126 | |
---|
1127 | attrib(ref, "huhu", 11); |
---|
1128 | |
---|
1129 | attrib(ref, "huhu"); |
---|
1130 | attrib(I, "huhu"); |
---|
1131 | |
---|
1132 | attrib(ref, "huhu", 111); |
---|
1133 | |
---|
1134 | attrib(ref, "huhu"); |
---|
1135 | attrib(I, "huhu"); |
---|
1136 | |
---|
1137 | |
---|
1138 | reference ref2= I; |
---|
1139 | attrib(ref2, "huhu"); |
---|
1140 | |
---|
1141 | attrib(ref, "hihi", 12); |
---|
1142 | |
---|
1143 | attrib(ref, "huhu"); |
---|
1144 | attrib(I, "huhu"); |
---|
1145 | attrib(ref, "hihi"); |
---|
1146 | attrib(I, "hihi"); |
---|
1147 | |
---|
1148 | attrib(ref2, "huhu"); |
---|
1149 | attrib(ref2, "hihi"); |
---|
1150 | |
---|
1151 | attrib(I, "isSB"); |
---|
1152 | attrib(ref2, "isSB"); |
---|
1153 | |
---|
1154 | attrib(ref2, "isSB", 0); |
---|
1155 | |
---|
1156 | attrib(I, "isSB"); |
---|
1157 | |
---|
1158 | |
---|
1159 | attrib(ref2, "isSB"); |
---|
1160 | |
---|
1161 | |
---|
1162 | |
---|
1163 | attrib(I, "isSB", 1); |
---|
1164 | attrib(I, "isSB"); |
---|
1165 | |
---|
1166 | attrib(ref2, "isSB"); |
---|
1167 | |
---|
1168 | shared shval= I; |
---|
1169 | // Ensure reloading does not damage something |
---|
1170 | system("reference"); |
---|
1171 | system("shared"); |
---|
1172 | reference refTwo = ref2; |
---|
1173 | shared shval2 = shval; |
---|
1174 | refTwo; |
---|
1175 | shval2[1] == shval[1]; |
---|
1176 | kill refTwo, shval2; |
---|
1177 | system("reference"); |
---|
1178 | system("shared"); |
---|
1179 | reference refTwo = ref2; |
---|
1180 | shared shval2 = shval; |
---|
1181 | refTwo; |
---|
1182 | shval2[1] == shval[1]; |
---|
1183 | kill refTwo, shval2; |
---|
1184 | |
---|
1185 | // -------------------------------------------------------- |
---|
1186 | tst_status(1);$ |
---|
1187 | |
---|