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 | |
---|
570 | shared vv =ll[1]; |
---|
571 | vv=9; |
---|
572 | ll; |
---|
573 | vv; |
---|
574 | val; |
---|
575 | reference vvv=ll[1]; |
---|
576 | vvv=9; |
---|
577 | ll; |
---|
578 | typeof(ll[1]); |
---|
579 | ll[1]=val; |
---|
580 | shared vv =ll[1]; |
---|
581 | |
---|
582 | |
---|
583 | |
---|
584 | |
---|
585 | |
---|
586 | ring r2=0,x,dp; |
---|
587 | |
---|
588 | poly p = x+1; |
---|
589 | |
---|
590 | shared p_sh =p; |
---|
591 | |
---|
592 | |
---|
593 | ring r3=0,x,dp; |
---|
594 | |
---|
595 | p_sh; |
---|
596 | |
---|
597 | setring(r2); |
---|
598 | |
---|
599 | p_sh; |
---|
600 | |
---|
601 | |
---|
602 | |
---|
603 | kill mem, mem2, mem3; |
---|
604 | shared mem = list(17); |
---|
605 | shared mem2 = mem; |
---|
606 | shared mem3 = link(mem); |
---|
607 | |
---|
608 | system(mem, count); |
---|
609 | system(mem, same, mem); |
---|
610 | system(mem, same, mem2); |
---|
611 | system(mem, same, mem3); |
---|
612 | system(mem, same, db2); |
---|
613 | system(mem, like, mem); |
---|
614 | system(mem, like, mem2); |
---|
615 | system(mem, like, mem3); |
---|
616 | system(mem, like, db2); |
---|
617 | |
---|
618 | |
---|
619 | shared llr = list(1,2,3); |
---|
620 | |
---|
621 | llr; |
---|
622 | ring r=0,x,dp; |
---|
623 | |
---|
624 | llr[1]=x+1; |
---|
625 | |
---|
626 | llr; |
---|
627 | |
---|
628 | ring q=0,y,dp; |
---|
629 | |
---|
630 | llr; |
---|
631 | |
---|
632 | setring(r); |
---|
633 | |
---|
634 | llr; |
---|
635 | |
---|
636 | |
---|
637 | shared sharedp =x; |
---|
638 | sharedp; |
---|
639 | setring q; |
---|
640 | sharedp; |
---|
641 | setring(r); |
---|
642 | sharedp; |
---|
643 | setring q; |
---|
644 | sharedp=y; |
---|
645 | sharedp; |
---|
646 | |
---|
647 | setring(r); |
---|
648 | sharedp; |
---|
649 | setring q; |
---|
650 | sharedp; |
---|
651 | |
---|
652 | setring(r); |
---|
653 | poly xpoly=x; |
---|
654 | reference refp =xpoly; |
---|
655 | refp; |
---|
656 | setring q; |
---|
657 | refp; |
---|
658 | setring(r); |
---|
659 | refp; |
---|
660 | setring q; |
---|
661 | refp=y; |
---|
662 | refp; |
---|
663 | |
---|
664 | setring(r); |
---|
665 | refp; |
---|
666 | setring q; |
---|
667 | refp; |
---|
668 | |
---|
669 | |
---|
670 | |
---|
671 | kill ll, r, q; |
---|
672 | |
---|
673 | shared ll =list(1,2,3); |
---|
674 | ring r=0,x,dp; |
---|
675 | ll[1] =x; |
---|
676 | ring q=0,y,dp; |
---|
677 | ll; |
---|
678 | ll[1]; |
---|
679 | ll; |
---|
680 | setring r; |
---|
681 | ll; |
---|
682 | setring q; |
---|
683 | ll[1]=y; |
---|
684 | ll; |
---|
685 | setring r; |
---|
686 | ll; |
---|
687 | ll[1]; |
---|
688 | setring q; |
---|
689 | ll[1]; |
---|
690 | |
---|
691 | "qewqe"; |
---|
692 | |
---|
693 | "qweewq"; |
---|
694 | |
---|
695 | shared llshort=list(1,2); |
---|
696 | |
---|
697 | llshort; |
---|
698 | llshort[3]=17; |
---|
699 | |
---|
700 | llshort; |
---|
701 | |
---|
702 | /// Pratical examples: cache |
---|
703 | echo=1; |
---|
704 | newstruct("sqcache", "shared table"); |
---|
705 | |
---|
706 | proc cached_square(sqcache cache, int arg) |
---|
707 | { |
---|
708 | if (arg == 0) { return (0); } |
---|
709 | shared value = cache.table[arg]; |
---|
710 | if (system(value, undef)) { value = arg^2; } |
---|
711 | return (int(value)); |
---|
712 | } |
---|
713 | |
---|
714 | system("install", "sqcache", "(", cached_square, 4); |
---|
715 | sqcache square; |
---|
716 | |
---|
717 | shared init = list(); |
---|
718 | square.table = init; |
---|
719 | |
---|
720 | int t=timer; |
---|
721 | int i, j,k,n; |
---|
722 | n = 100; |
---|
723 | init=(0:n); |
---|
724 | for( i = 0; i <n; i++) { |
---|
725 | k = square(i); |
---|
726 | } |
---|
727 | for( i = 0; i <n; i++) { |
---|
728 | k = square(i); |
---|
729 | } |
---|
730 | for( i = 0; i <n; i++) { |
---|
731 | k = square(i); |
---|
732 | } |
---|
733 | for( i = 0; i <n; i++) { |
---|
734 | k = square(i); |
---|
735 | } |
---|
736 | for( i = 0; i <n; i++) { |
---|
737 | k = square(i); |
---|
738 | } |
---|
739 | for( i = 0; i <n; i++) { |
---|
740 | k = square(i); |
---|
741 | } |
---|
742 | for( i = 0; i <n; i++) { |
---|
743 | k = square(i); |
---|
744 | } |
---|
745 | for( i = 0; i <n; i++) { |
---|
746 | k = square(i); |
---|
747 | } |
---|
748 | for( i = 0; i <n; i++) { |
---|
749 | k = square(i); |
---|
750 | } |
---|
751 | for( i = 0; i <n; i++) { |
---|
752 | k = square(i); |
---|
753 | } |
---|
754 | |
---|
755 | |
---|
756 | |
---|
757 | int time1 = timer -t; |
---|
758 | t=timer; |
---|
759 | list cll=(0:n+1); |
---|
760 | for( i = 1; i <=n; i++) { |
---|
761 | cll[i] = (i^2); |
---|
762 | } |
---|
763 | for( i = 1; i <=n; i++) { |
---|
764 | k = cll[i]; |
---|
765 | } |
---|
766 | for( i = 1; i <=n; i++) { |
---|
767 | k = cll[i]; |
---|
768 | } |
---|
769 | for( i = 1; i <=n; i++) { |
---|
770 | k = cll[i]; |
---|
771 | } |
---|
772 | for( i = 1; i <=n; i++) { |
---|
773 | k = cll[i]; |
---|
774 | } |
---|
775 | for( i = 1; i <=n; i++) { |
---|
776 | k = cll[i]; |
---|
777 | } |
---|
778 | for( i = 1; i <=n; i++) { |
---|
779 | k = cll[i]; |
---|
780 | } |
---|
781 | for( i = 1; i <=n; i++) { |
---|
782 | k = cll[i]; |
---|
783 | } |
---|
784 | for( i = 1; i <=n; i++) { |
---|
785 | k = cll[i]; |
---|
786 | } |
---|
787 | for( i = 1; i <=n; i++) { |
---|
788 | k = cll[i]; |
---|
789 | } |
---|
790 | |
---|
791 | |
---|
792 | |
---|
793 | |
---|
794 | |
---|
795 | int time2 = timer -t; |
---|
796 | |
---|
797 | |
---|
798 | |
---|
799 | |
---|
800 | //time1; |
---|
801 | //time2; |
---|
802 | |
---|
803 | |
---|
804 | newstruct("bdd", "int idx,shared high,shared low"); |
---|
805 | bdd diag; |
---|
806 | shared zero=0; |
---|
807 | diag.high=zero; |
---|
808 | diag.low=zero; |
---|
809 | diag.idx = 0; |
---|
810 | |
---|
811 | //for (i=0; i <=n; i++) |
---|
812 | n=20; |
---|
813 | proc chain(shared arg) |
---|
814 | { |
---|
815 | bdd diag; |
---|
816 | diag.idx = arg.idx+1; |
---|
817 | diag.high=arg; |
---|
818 | diag.low=arg; |
---|
819 | return (diag); |
---|
820 | } |
---|
821 | |
---|
822 | |
---|
823 | t=timer; |
---|
824 | for (i=0; i<=n; i++ ) |
---|
825 | { |
---|
826 | diag = chain(diag); |
---|
827 | } |
---|
828 | //timer-t; |
---|
829 | |
---|
830 | shared iter=diag; |
---|
831 | //while(int(iter.idx)) { |
---|
832 | // iter.idx; |
---|
833 | // iter = iter.high; |
---|
834 | //} |
---|
835 | |
---|
836 | proc print_bdd(shared iter) { |
---|
837 | string res = "("+string(iter.idx)+", "; |
---|
838 | shared it1=iter.high; |
---|
839 | shared it0=iter.low; |
---|
840 | |
---|
841 | if (int(iter.idx)) |
---|
842 | { |
---|
843 | res=res + print_bdd(it1) + " : "; |
---|
844 | res= res+ print_bdd(it0)+ ")"; |
---|
845 | } |
---|
846 | return (res);// print_bdd(iter.low); |
---|
847 | } |
---|
848 | shared iter2=diag; |
---|
849 | |
---|
850 | //print_bdd(iter2); |
---|
851 | |
---|
852 | newstruct("bdd0", "int idx,def high,def low"); |
---|
853 | bdd0 diag0; |
---|
854 | diag0.idx=0; |
---|
855 | diag0.high=0; |
---|
856 | diag0.low=0; |
---|
857 | |
---|
858 | |
---|
859 | proc chain0(bdd0 arg) |
---|
860 | { |
---|
861 | bdd0 diag; |
---|
862 | diag.idx = arg.idx+1; |
---|
863 | diag.high=arg; |
---|
864 | diag.low=arg; |
---|
865 | return (diag); |
---|
866 | } |
---|
867 | |
---|
868 | /// Deactivate "classical" way, take too long (many copies) |
---|
869 | n=0; |
---|
870 | t=timer; |
---|
871 | def val; |
---|
872 | for (i=0; i<=n; i++ ) |
---|
873 | { |
---|
874 | val =chain0(diag0); |
---|
875 | diag0=val; |
---|
876 | } |
---|
877 | //timer-t; |
---|
878 | |
---|
879 | proc print_bdd0(def iter) { |
---|
880 | string res = "("+string(iter.idx)+", "; |
---|
881 | def it1=iter.high; |
---|
882 | def it0=iter.low; |
---|
883 | |
---|
884 | if (int(iter.idx)) |
---|
885 | { |
---|
886 | res=res + print_bdd0(it1) + " : "; |
---|
887 | res= res+ print_bdd0(it0)+ ")"; |
---|
888 | } |
---|
889 | return (res);// print_bdd(iter.low); |
---|
890 | } |
---|
891 | |
---|
892 | |
---|
893 | //print_bdd0(diag0); |
---|
894 | |
---|
895 | //diag; |
---|
896 | |
---|
897 | kill sh17,sh18; |
---|
898 | bdd b01; |
---|
899 | |
---|
900 | (b01.idx)=0; |
---|
901 | shared sh17=17; |
---|
902 | shared sh18=18; |
---|
903 | b01.high = sh17; |
---|
904 | b01.low = sh18; |
---|
905 | |
---|
906 | |
---|
907 | b01.high; |
---|
908 | b01.low; |
---|
909 | |
---|
910 | def(b01.high) = 19; |
---|
911 | def(b01.low) = 20; |
---|
912 | |
---|
913 | b01.high; |
---|
914 | b01.low; |
---|
915 | |
---|
916 | sh17; |
---|
917 | sh18; |
---|
918 | kill ll; |
---|
919 | |
---|
920 | shared ll1=1; shared ll2=2; |
---|
921 | list ll=list(ll1, ll2); |
---|
922 | typeof(ll[1]); |
---|
923 | |
---|
924 | |
---|
925 | def(ll[1]) = 3; |
---|
926 | ll; |
---|
927 | ll1; |
---|
928 | typeof(ll[1]); |
---|
929 | |
---|
930 | |
---|
931 | shared(ll[1]) = 5; |
---|
932 | ll; |
---|
933 | ll1; |
---|
934 | typeof(ll[1]); |
---|
935 | |
---|
936 | |
---|
937 | shared ll3=2; |
---|
938 | |
---|
939 | ll[3]=ll3; |
---|
940 | |
---|
941 | typeof(ll[3]); |
---|
942 | ll; |
---|
943 | |
---|
944 | def(ll[3])=4; |
---|
945 | |
---|
946 | ll3; ll; |
---|
947 | typeof(ll[3]); |
---|
948 | |
---|
949 | ll[4]=1; |
---|
950 | |
---|
951 | ll[4] = ll3; |
---|
952 | ll; |
---|
953 | def(ll[4])=17; |
---|
954 | ll; |
---|
955 | |
---|
956 | |
---|
957 | bdd b02; |
---|
958 | |
---|
959 | b02.high; |
---|
960 | def(b02.high); |
---|
961 | def(b02.high)=9; |
---|
962 | |
---|
963 | b02.high; |
---|
964 | typeof(b02.high); |
---|
965 | |
---|
966 | kill ll; |
---|
967 | |
---|
968 | list ll; |
---|
969 | ll[1] = ll1; |
---|
970 | shared(ll[1]) = 3333; |
---|
971 | ll; |
---|
972 | |
---|
973 | |
---|
974 | |
---|
975 | kill ll; |
---|
976 | |
---|
977 | shared ll=list(); |
---|
978 | shared llsync=ll; |
---|
979 | def(ll[1])=list(3,4); |
---|
980 | ll; |
---|
981 | |
---|
982 | def(def(ll[1])[3])=list(5,6); |
---|
983 | ll; |
---|
984 | |
---|
985 | def(ll[1])[3]=list(8); |
---|
986 | ll; |
---|
987 | |
---|
988 | |
---|
989 | ll[1][3]=list(6); |
---|
990 | ll; |
---|
991 | llsync; |
---|
992 | |
---|
993 | kill sh; |
---|
994 | newstruct("bbx", "def i"); |
---|
995 | bbx box; |
---|
996 | |
---|
997 | shared sh=box; |
---|
998 | sh; |
---|
999 | sh.i =list(1,2); |
---|
1000 | sh; |
---|
1001 | |
---|
1002 | sh.i[2]=19; |
---|
1003 | |
---|
1004 | sh; |
---|
1005 | sh.i; |
---|
1006 | |
---|
1007 | system(sh, "help"); |
---|
1008 | |
---|
1009 | |
---|
1010 | kill i, iref; |
---|
1011 | int i =9; |
---|
1012 | shared iref = i; |
---|
1013 | link l1 = "ssi:fork"; open(l1); |
---|
1014 | write(l1, quote(list(iref, iref))); |
---|
1015 | |
---|
1016 | waitfirst(list(l1), 500); |
---|
1017 | def argi = read(l1); |
---|
1018 | argi; |
---|
1019 | typeof(argi[1]); |
---|
1020 | typeof(argi[2]); |
---|
1021 | |
---|
1022 | |
---|
1023 | //typeof(link(argi)); |
---|
1024 | close(l1); |
---|
1025 | |
---|
1026 | |
---|
1027 | kill i, iref,l1; |
---|
1028 | int i =9; |
---|
1029 | reference iref = i; |
---|
1030 | link l1 = "ssi:fork"; open(l1); |
---|
1031 | write(l1, quote(def(iref))); |
---|
1032 | |
---|
1033 | waitfirst(list(l1), 500); |
---|
1034 | def argi = read(l1); |
---|
1035 | argi; |
---|
1036 | typeof(argi); |
---|
1037 | typeof(link(argi)); |
---|
1038 | close(l1); |
---|
1039 | |
---|
1040 | i=10; |
---|
1041 | argi; |
---|
1042 | |
---|
1043 | shared backtest=list(17,9); |
---|
1044 | |
---|
1045 | backtest; |
---|
1046 | |
---|
1047 | shared backtest_1 = backtest[1]; |
---|
1048 | |
---|
1049 | backtest_1; |
---|
1050 | |
---|
1051 | backtest_1=6; |
---|
1052 | backtest; |
---|
1053 | kill backtest; |
---|
1054 | |
---|
1055 | backtest_1; |
---|
1056 | |
---|
1057 | backtest_1; |
---|
1058 | |
---|
1059 | kill i, ll; |
---|
1060 | int i = 17; |
---|
1061 | reference ref = i; |
---|
1062 | |
---|
1063 | ref; |
---|
1064 | ref + ref; // Automated 'dereferencing' |
---|
1065 | ref + 4; |
---|
1066 | 4 + ref; |
---|
1067 | |
---|
1068 | |
---|
1069 | list ll=(1,2,3,4,5); |
---|
1070 | ref=3; |
---|
1071 | ll[ref]; |
---|
1072 | |
---|
1073 | kill r; |
---|
1074 | ring r=0,(x,y,z),dp; |
---|
1075 | poly p = x+y+z; |
---|
1076 | shared xsh = x+1; |
---|
1077 | poly(xsh); |
---|
1078 | poly(xsh); |
---|
1079 | poly(xsh); |
---|
1080 | |
---|
1081 | |
---|
1082 | |
---|
1083 | // Checking side effects |
---|
1084 | list changeme; |
---|
1085 | changeme; |
---|
1086 | |
---|
1087 | proc setfirst(reference ll, def arg) { ll[1] = arg; } |
---|
1088 | |
---|
1089 | setfirst(changeme, 17); |
---|
1090 | changeme; |
---|
1091 | |
---|
1092 | // Checking differenct variants of list conversion |
---|
1093 | |
---|
1094 | shared shlist = list(1,2,3); |
---|
1095 | list thelist = shlist; |
---|
1096 | thelist; |
---|
1097 | list(shlist); |
---|
1098 | link(shlist); |
---|
1099 | |
---|
1100 | /// Checking that link deeply copies indeed |
---|
1101 | kill r, xsh, ll; |
---|
1102 | ring r = 0, (x,y,z), dp; |
---|
1103 | poly p = x + y + z; |
---|
1104 | shared xsh = x; |
---|
1105 | |
---|
1106 | subst(p, xsh,1, y,2, z,3); // fails |
---|
1107 | subst(p, poly(xsh),1, y,2, z,3); // good |
---|
1108 | subst(p, link(xsh),1, y,2, z,3); // fine |
---|
1109 | subst(p, link(xsh),1, y,2, z,3); // fine |
---|
1110 | subst(p, link(xsh),1, y,2, z,3); // fine |
---|
1111 | |
---|
1112 | list ll = list(xsh, xsh, xsh); |
---|
1113 | ll[1] = y; // replaced only first entry |
---|
1114 | ll; |
---|
1115 | shared(ll[2]) = z; // replaces the others |
---|
1116 | ll; |
---|
1117 | def(ll[2]) = x; // generic alternative |
---|
1118 | ll; |
---|
1119 | |
---|
1120 | // -------------------------------------------------------- |
---|
1121 | kill r, ref, ref2; |
---|
1122 | ring r;ideal I = maxideal(1);ideal J = I; |
---|
1123 | reference ref = I; |
---|
1124 | |
---|
1125 | attrib(ref, "huhu", 11); |
---|
1126 | |
---|
1127 | attrib(ref, "huhu"); |
---|
1128 | attrib(I, "huhu"); |
---|
1129 | |
---|
1130 | attrib(ref, "huhu", 111); |
---|
1131 | |
---|
1132 | attrib(ref, "huhu"); |
---|
1133 | attrib(I, "huhu"); |
---|
1134 | |
---|
1135 | |
---|
1136 | reference ref2= I; |
---|
1137 | attrib(ref2, "huhu"); |
---|
1138 | |
---|
1139 | attrib(ref, "hihi", 12); |
---|
1140 | |
---|
1141 | attrib(ref, "huhu"); |
---|
1142 | attrib(I, "huhu"); |
---|
1143 | attrib(ref, "hihi"); |
---|
1144 | attrib(I, "hihi"); |
---|
1145 | |
---|
1146 | attrib(ref2, "huhu"); |
---|
1147 | attrib(ref2, "hihi"); |
---|
1148 | |
---|
1149 | attrib(I, "isSB"); |
---|
1150 | attrib(ref2, "isSB"); |
---|
1151 | |
---|
1152 | attrib(ref2, "isSB", 0); |
---|
1153 | |
---|
1154 | attrib(I, "isSB"); |
---|
1155 | |
---|
1156 | |
---|
1157 | attrib(ref2, "isSB"); |
---|
1158 | |
---|
1159 | |
---|
1160 | |
---|
1161 | attrib(I, "isSB", 1); |
---|
1162 | attrib(I, "isSB"); |
---|
1163 | |
---|
1164 | attrib(ref2, "isSB"); |
---|
1165 | |
---|
1166 | shared shval= I; |
---|
1167 | // Ensure reloading does not damage something |
---|
1168 | system("reference"); |
---|
1169 | system("shared"); |
---|
1170 | reference refTwo = ref2; |
---|
1171 | shared shval2 = shval; |
---|
1172 | refTwo; |
---|
1173 | shval2[1] == shval[1]; |
---|
1174 | kill refTwo, shval2; |
---|
1175 | system("reference"); |
---|
1176 | system("shared"); |
---|
1177 | reference refTwo = ref2; |
---|
1178 | shared shval2 = shval; |
---|
1179 | refTwo; |
---|
1180 | shval2[1] == shval[1]; |
---|
1181 | kill refTwo, shval2; |
---|
1182 | |
---|
1183 | // -------------------------------------------------------- |
---|
1184 | tst_status(1);$ |
---|
1185 | |
---|