source: git/Tst/Short/countedref_s.tst @ 1427f62

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