forked from parrot/parrot
/
iterator.t
1001 lines (881 loc) · 18.1 KB
/
iterator.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!perl
# Copyright (C) 2001-2008, Parrot Foundation.
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Test tests => 27;
=head1 NAME
t/pmc/iterator.t - Test the Iterator PMC
=head1 SYNOPSIS
% prove t/pmc/iterator.t
=head1 DESCRIPTION
Tests the C<Iterator> PMC.
=cut
# TT #1478: Split this test into aggregate specific one.
pasm_output_is( <<'CODE', <<'OUTPUT', "new iter" );
new P2, ['ResizablePMCArray']
iter P1, P2
print "ok 1\n"
end
CODE
ok 1
OUTPUT
pasm_output_is( <<'CODE', <<'OUTPUT', "new iter fails (init)" );
push_eh THROWN
new P0, ['ResizablePMCArray']
new P1, ['Iterator'], P0
print "not "
THROWN:
pop_eh
print "ok 1\n"
end
CODE
ok 1
OUTPUT
pasm_output_is( <<'CODE', <<'OUTPUT', "keyed access on String and Hash PMCs" );
new P0, ['String']
set P0, "I am a very long string."
new P2, ['Integer']
set P2, 1
iter P1, P0
set I0, P1[P2]
eq I0, 32, OK1
print "not "
OK1:print "ok 1\n"
set P2, 0
set I0, P1[P2]
eq I0, 73, OK2
print "not "
OK2:print "ok 2\n"
set P2, 5
set S0, P1[P2]
eq S0, 'a', OK3
print "not "
OK3:print "ok 3\n"
new P0, ['Hash']
set P0['derp'], 3.257
set P0['herp'], 2
iter P1, P0
set P2, 'herp'
set N0, P1[P2]
eq N0, 2, OK4
print "not "
OK4:print "ok 4\n"
set P2, 'derp'
set N0, P1[P2]
eq N0, 3.257, OK5
print "not "
OK5:print "ok 5\n"
end
CODE
ok 1
ok 2
ok 3
ok 4
ok 5
OUTPUT
pasm_output_is( <<'CODE', <<'OUTPUT', "keyed exist and defined on String and Hash PMCs" );
new P0, ['String']
set P0, 'somelongstring'
iter P1, P0
new P2, ['Integer']
set P2, 2
exists I0, P1[P2]
eq I0, 1, OK1
print "not "
OK1:print "ok 1\n"
set P2, 20
exists I0, P1[P2]
eq I0, 0, OK2
print "not "
OK2:print "ok 2\n"
defined I0, P1
eq I0, 1, OK3
print "not "
OK3:print "ok 3\n"
new P0, ['Hash']
set P0['something'], 'stringg'
set P0['nothing'], 'something'
iter P1, P0
set P2, 'something'
defined I0, P1[P2]
eq I0, 1, OK4
print "not "
OK4:print "ok 4\n"
set P2, 'somenothing'
defined I0, P1[P2]
eq I0, 0, OK5
print "not "
OK5:print "ok 5\n"
end
CODE
ok 1
ok 2
ok 3
ok 4
ok 5
OUTPUT
pasm_output_is( <<'CODE', <<'OUTPUT', "get_iter" );
new P0, ['ResizableIntegerArray']
push P0, 20
iter P1, P0
iter P2, P1
issame I0, P1, P2
eq I0, 1, OK
print "not "
OK: print "ok\n"
end
CODE
ok
OUTPUT
pir_output_is( <<'CODE', <<'OUTPUT', "next()" );
.sub _main
.local pmc str, str2, iterate
str = new ['String']
str = '0hey'
iterate = iter str
str2 = iterate.'next'()
eq str2, '0', OK1
print "not "
OK1:print "ok 1 - next returns first character\n"
eq str, '0hey', OK2
print "not "
OK2:print "ok 2 - does not touch input\n"
str2 = iterate.'next'()
eq str2, 'h', OK3
print "not "
OK3:print "ok 3 - next returns second character\n"
.end
CODE
ok 1 - next returns first character
ok 2 - does not touch input
ok 3 - next returns second character
OUTPUT
TODO: {
pir_output_is( <<'CODE', <<'OUTPUT', "custom subclass, set_integer_native", todo => "subclassing init VTABLE method is not properly overridden." );
.sub _main :main
.local pmc myiter, inst
myiter = subclass 'Iterator', 'MyIter'
#myiter = newclass 'MyIter'
inst = new ['MyIter']
push_eh THROWN
inst = 1
print "not "
THROWN:
pop_eh
print "ok\n"
.end
.namespace ["MyIter"]
.sub init :vtable
print "init\n"
.return()
.end
CODE
ok
OUTPUT
}
pasm_output_is( <<'CODE', <<'OUTPUT', "int test" );
.include "iterator.pasm"
new P0, ['ResizablePMCArray'] # empty array
new P2, ['ResizablePMCArray'] # array with 2 elements
push P2, 10
push P2, 20
set I0, P2
iter P1, P2
print "ok 1\n"
set I1, P1
eq I0, I1, ok2 # iter.length() == array.length()
print "not "
ok2: print "ok 2\n"
iter P1, P0
set P1, .ITERATE_FROM_START
print "ok 3\n"
unless P1, ok4 # if(iter) == false on empty
print "not "
ok4: print "ok 4\n"
iter P1, P2
set P1, .ITERATE_FROM_START
if P1, ok5 # if(iter) == true on non empty
print "not "
ok5: print "ok 5\n"
# now iterate over P2
# while (P1) { element = shift(P1) }
unless P1, nok6
shift I3, P1
eq I3, 10, ok6
nok6: print "not "
ok6: print "ok 6\n"
unless P1, nok7
shift I3, P1
eq I3, 20, ok7
nok7: print "not "
ok7: print "ok 7\n"
unless P1, ok8 # if(iter) == false after last
print "not "
ok8: print "ok 8\n"
# now iterate from end
set P1, .ITERATE_FROM_END
if P1, ok9 # if(iter) == true on non empty
print "not "
ok9: print "ok 9\n"
# while (P1) { element = pop(P1) }
unless P1, nok10
pop I3, P1
eq I3, 20, ok10
nok10: print "not "
ok10: print "ok 10\n"
unless P1, nok11
pop I3, P1
eq I3, 10, ok11
nok11: print "not "
ok11: print "ok 11\n"
unless P1, ok12 # if(iter) == false after last
print "not "
ok12: print "ok 12\n"
end
CODE
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
ok 10
ok 11
ok 12
OUTPUT
pasm_output_is( <<'CODE', <<'OUTPUT', "Hash iter 1" );
.include "iterator.pasm"
new P0, ['Hash'] # empty Hash
new P2, ['Hash'] # Hash with 2 elements
set P2["ab"], 100
set P2["xy"], "value"
set I0, P2
iter P1, P2
print "ok 1\n"
set I1, P1
eq I0, I1, ok2 # iter.length() == hash.length()
print "not "
ok2: print "ok 2\n"
iter P1, P0
set P1, .ITERATE_FROM_START
print "ok 3\n"
unless P1, ok4 # if(iter) == false on empty
print "not "
ok4: print "ok 4\n"
iter P1, P2
set P1, .ITERATE_FROM_START
if P1, ok5 # if(iter) == true on non empty
print "not "
ok5: print "ok 5\n"
# now iterate over P2
# while (P1) { key = shift(P1) }
unless P1, nok6
shift S3, P1 # get hash.key
eq S3, "ab", ok6
eq S3, "xy", ok6
nok6: print " not "
ok6: print "ok 6\n"
unless P1, nok7
shift S3, P1
eq S3, "ab", ok7
eq S3, "xy", ok7
nok7: print "not "
ok7: print "ok 7\n"
unless P1, ok8 # if(iter) == false after last
print "not "
ok8: print "ok 8\n"
end
CODE
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
OUTPUT
pasm_output_is( <<'CODE', <<'OUTPUT', "Hash iter 1" );
.include "iterator.pasm"
new P0, ['Hash'] # empty Hash
new P2, ['Hash'] # Hash with 2 elements
set P2["ab"], 100
set P2["xy"], "value"
set I0, P2
iter P1, P2
print "ok 1\n"
set I1, P1
eq I0, I1, ok2 # iter.length() == hash.length()
print "not "
ok2: print "ok 2\n"
iter P1, P0
set P1, .ITERATE_FROM_START
print "ok 3\n"
unless P1, ok4 # if(iter) == false on empty
print "not "
ok4: print "ok 4\n"
iter P1, P2
set P1, .ITERATE_FROM_START
if P1, ok5 # if(iter) == true on non empty
print "not "
ok5: print "ok 5\n"
# now iterate over P2
# while (P1) { key = shift(P1) }
unless P1, nok6
shift S3, P1 # get hash.key
eq S3, "ab", ok6
eq S3, "xy", ok6
nok6: print " not "
ok6: print "ok 6\n"
unless P1, nok7
shift S3, P1
eq S3, "ab", ok7
eq S3, "xy", ok7
nok7: print "not "
ok7: print "ok 7\n"
unless P1, ok8 # if(iter) == false after last
print "not "
ok8: print "ok 8\n"
end
CODE
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
OUTPUT
pasm_output_is( <<'CODE', <<'OUTPUT', "Hash iter 2" );
.include "iterator.pasm"
new P0, ['Hash'] # Hash for iteration
new P2, ['Hash'] # for test
set I0, 65
set I1, 35
set I10, I1
fill:
chr S0, I0
set P0[S0], I0
inc I0
dec I1
if I1, fill
iter P1, P0
set I0, P1
eq I0, I10, ok1
print "not "
ok1:
print "ok 1\n"
set P1, .ITERATE_FROM_START
get:
unless P1, done
shift S3, P1 # get hash.key
set I0, P0[S3] # and value
set P2[S3], I0
branch get
done:
set I0, P2
eq I0, I10, ok2
print "not "
ok2:
print "ok 2\n"
end
CODE
ok 1
ok 2
OUTPUT
pasm_output_is( <<'CODE', <<OUTPUT, "string iteration forward" );
.include "iterator.pasm"
new P2, ['String']
set P2, "parrot"
iter P1, P2
set P1, .ITERATE_FROM_START
iter_loop:
unless P1, iter_end # while (entries) ...
shift S1, P1
print S1
branch iter_loop
iter_end:
print "\n"
print P2
print "\n"
end
CODE
parrot
parrot
OUTPUT
pasm_output_is( <<'CODE', <<OUTPUT, "string iteration backward" );
.include "iterator.pasm"
new P2, ['String']
set P2, "parrot"
iter P1, P2
set P1, .ITERATE_FROM_END
iter_loop:
unless P1, iter_end # while (entries) ...
pop S1, P1
print S1
branch iter_loop
iter_end:
print "\n"
print P2
print "\n"
end
CODE
torrap
parrot
OUTPUT
pasm_output_is( <<'CODE', <<OUTPUT, "string iteration forward get ord" );
.include "iterator.pasm"
new P2, ['String']
set P2, "ABC"
iter P1, P2
set P1, .ITERATE_FROM_START
iter_loop:
unless P1, iter_end # while (entries) ...
shift I1, P1
print I1
branch iter_loop
iter_end:
print "\n"
print P2
print "\n"
end
CODE
656667
ABC
OUTPUT
pasm_output_is( <<'CODE', <<OUTPUT, "string iteration backward get ord" );
.include "iterator.pasm"
new P2, ['String']
set P2, "ABC"
iter P1, P2
set P1, .ITERATE_FROM_END
iter_loop:
unless P1, iter_end # while (entries) ...
pop I1, P1
print I1
branch iter_loop
iter_end:
print "\n"
print P2
print "\n"
end
CODE
676665
ABC
OUTPUT
pir_output_is( << 'CODE', << 'OUTPUT', "String iterator in PIR" );
.include "iterator.pasm"
.sub _main
.local pmc string_1
string_1 = new ['String']
string_1 = "abcd\x65\x66\x67"
print string_1
print "\n"
.local pmc iter_1
iter_1 = iter string_1
iter_1 = .ITERATE_FROM_START
.local int code_point_1
ITER_LOOP:
unless iter_1 goto ITER_END
shift code_point_1, iter_1
print code_point_1
print "\n"
branch ITER_LOOP
ITER_END:
print "reached end\n"
end
.end
CODE
abcdefg
97
98
99
100
101
102
103
reached end
OUTPUT
pir_output_is( <<'CODE', <<'OUTPUT', "Index access for Iterator on String" );
.include "iterator.pasm"
.sub _main
.local pmc string_1
string_1 = new ['String']
string_1 = "abcd\x65\x66\x67"
print 'String new: '
print string_1
print "\n"
.local pmc iter_1
iter_1 = iter string_1
iter_1 = .ITERATE_FROM_START
.local int code_point_1
.local num code_point_2
.local string code_point_3
.local pmc code_point_4
print 'Iterator shift_integer: '
shift code_point_1, iter_1
print code_point_1
print "\n"
print 'Iterator get_integer_keyed_int 2: '
code_point_1 = iter_1[2]
print code_point_1
print "\n"
print 'Iterator get_integer_keyed_int 0: '
code_point_1 = iter_1[0]
print code_point_1
print "\n"
print 'Iterator get_integer_keyed_int -1: '
code_point_1 = iter_1[-1]
print code_point_1
print "\n"
end
.end
CODE
String new: abcdefg
Iterator shift_integer: 97
Iterator get_integer_keyed_int 2: 100
Iterator get_integer_keyed_int 0: 98
Iterator get_integer_keyed_int -1: 97
OUTPUT
pir_output_is( << 'CODE', << 'OUTPUT', "Index access for Iterator on ResizablePMCArray" );
.include "iterator.pasm"
.sub _main
.local pmc array_1
array_1 = new ['ResizablePMCArray']
push array_1, 'a'
push array_1, 'b'
push array_1, 'c'
push array_1, 'd'
push array_1, 'e'
push array_1, 'f'
push array_1, '7'
push array_1, '-8.8'
print 'ResizablePMCArray get_string: '
print array_1
print "\n"
.local pmc iter_1
iter_1 = iter array_1
iter_1 = .ITERATE_FROM_START
.local string elem_1
print 'Iterator shift_string: '
shift elem_1, iter_1
print elem_1
print "\n"
print 'Iterator get_string_keyed_int 2: '
elem_1 = iter_1[2]
print elem_1
print "\n"
print 'Iterator get_string_keyed_int -1: '
elem_1 = iter_1[-1]
print elem_1
print "\n"
print 'Iterator get_string_keyed_int 0: '
elem_1 = iter_1[0]
print elem_1
print "\n"
print 'Iterator get_pmc_keyed_int 3: '
.local pmc elem_2
elem_2 = iter_1[3]
print elem_2
print "\n"
.local int flag
print 'Iterator exists_keyed_int 3: '
flag = exists iter_1[3]
print flag
print "\n"
print 'Iterator exists_keyed_int 28: '
flag = exists iter_1[28]
print flag
print "\n"
print 'Iterator defined_keyed_int 3: '
flag = defined iter_1[3]
print flag
print "\n"
print 'Iterator defined_keyed_int -1278: '
flag = defined iter_1[-1278]
print flag
print "\n"
.local pmc iter_2
iter_2 = iter array_1
iter_2 = .ITERATE_FROM_END
print 'Iterator shift_float: '
.local num felem_2
pop felem_2, iter_2
print felem_2
print "\n"
print 'Iterator get_integer: '
.local int elem_3
elem_3 = iter_2[-1]
print elem_3
print "\n"
end
.end
CODE
ResizablePMCArray get_string: 8
Iterator shift_string: a
Iterator get_string_keyed_int 2: d
Iterator get_string_keyed_int -1: a
Iterator get_string_keyed_int 0: b
Iterator get_pmc_keyed_int 3: e
Iterator exists_keyed_int 3: 1
Iterator exists_keyed_int 28: 0
Iterator defined_keyed_int 3: 1
Iterator defined_keyed_int -1278: 0
Iterator shift_float: -8.8
Iterator get_integer: 7
OUTPUT
TODO: {
pasm_output_is( <<'CODE', <<'OUTPUT', "shift + index access", todo => "N/Y: length of rest of array ");
.include "iterator.pasm"
new P2, ['ResizablePMCArray'] # array with 4 elements
push P2, 10
push P2, 20
push P2, 30
push P2, 40
iter P1, P2
set P1, .ITERATE_FROM_START
set I0, P1 # arr.length
eq I0, 4, ok1
print I0
print " not "
ok1: print "ok 1\n"
shift I0, P1 # get one
eq I0, 10, ok2
print "not "
ok2: print "ok 2\n"
shift I0, P1 # get one
eq I0, 20, ok3
print "not "
ok3: print "ok 3\n"
set I0, P1 # arr.length of rest
eq I0, 2, ok6
print I0
print " not "
ok6: print "ok 6\n"
print P1
end
CODE
ok 1
ok 2
ok 3
ok 6
2
OUTPUT
}
pasm_output_is( <<'CODE', <<'OUTPUT', "iter vtable" );
.include "iterator.pasm"
new P0, ['ResizablePMCArray']
push P0, 100
push P0, 200
push P0, 300
push P0, 400
push P0, 500
push P0, 600
push P0, 700
push P0, 800
iter P2, P0
print "ok 1\n"
lp:
unless P2, ex
shift I0, P2
print I0
print "\n"
branch lp
ex:
print "ok 2\n"
end
CODE
ok 1
100
200
300
400
500
600
700
800
ok 2
OUTPUT
pasm_output_is( <<'CODE', <<OUTPUT, "string iteration with get_iter" );
.include "iterator.pasm"
new P2, ['String']
set P2, "parrot"
iter P1, P2
iter_loop:
unless P1, iter_end # while (entries) ...
shift S1, P1
print S1
branch iter_loop
iter_end:
print "\n"
print P2
print "\n"
end
CODE
parrot
parrot
OUTPUT
TODO: {
local $TODO = "adding keys during iteration";
pir_output_is( << 'CODE', << 'OUTPUT', "adding keys during iteration" );
.sub main :main
.local pmc h, it, ar
.local string k
.local int i,v
h = new ['Hash']
i = 0
lp1:
$I0 = i + 65
k = chr $I0
h[k] = i
inc i
if i < 10 goto lp1
it = iter h
ar = new ['ResizablePMCArray']
i = 20
lp2:
unless it goto ex
k = shift it
v = h[k]
push ar, v
if i == 29 goto no_add
$I0 = i + 65
k = chr $I0
h[k] = i
inc i
no_add:
goto lp2
ex:
ar."sort"()
i = elements ar
lp3:
dec i
v = ar[i]
print v
print "_"
if i goto lp3
print "\n"
.end
# or some such output
CODE
29_28_27_26_25_24_23_22_21_20_9_8_7_6_5_4_3_2_1_0_
OUTPUT
}
pir_output_is( << 'CODE', << 'OUTPUT', "by default, iterate from start" );
.sub main :main
.local pmc ar, it
ar= new ['ResizablePMCArray']
push ar, 'pi'
push ar, 3
push ar, 6.28
it = iter ar
lp: unless it, ex
$P0 = shift it
print $P0
print "\n"
branch lp
ex:
.end
CODE
pi
3
6.28
OUTPUT
pir_output_is( << 'CODE', << 'OUTPUT', "iterator can be cloned" );
.sub main :main
.local pmc ar, i1, i2
ar = new ['ResizableIntegerArray']
push ar, 17
i1 = iter ar
clone i2, i1
.end
CODE
OUTPUT
pir_output_is( << 'CODE', << 'OUTPUT', "cloned iterator independent of original" );
.sub main :main
.local pmc ar, i1, i2
ar = new ['ResizableIntegerArray']
push ar, 17
push ar, 42
i1 = iter ar
clone i2, i1
.local pmc temp
shift temp, i1
unless temp == 17 goto fail
shift temp, i1
unless temp == 42 goto fail
shift temp, i2
unless temp == 17 goto fail
shift temp, i2
unless temp == 42 goto fail
say "ok"
end
fail:
say "not ok"
.end
CODE
ok
OUTPUT
pir_output_is( <<'CODE', <<'OUTPUT', "clone of partly-advanced iterator" );
.sub main :main
.local pmc ar, i1, i2
.local pmc temp
ar = new ['ResizableIntegerArray']
push ar, 1
push ar, 2
i1 = iter ar
shift temp, i1
unless temp == 1 goto fail
clone i2, i1
shift temp, i1
unless temp == 2 goto fail
shift temp, i2
unless temp == 2 goto fail
say "ok"
end
fail:
say "not ok"
.end
CODE
ok
OUTPUT
TODO: {
local $TODO = "cloned iterator doesn't copy the array to which it 'points'";
pir_output_is(
<<'CODE', <<'OUTPUT', "cloned iterator doesn't copy the array to which it 'points'" );
.sub main :main
.local pmc ar, i1, i2
.local pmc temp
temp = new ['Integer']
ar = new ['ResizableIntegerArray']
push ar, 1
i1 = iter ar
# i1 and i2 now "point" to the same element of the same array.
clone i2, i1
# Modify the array ...
temp = 17
i1 = temp
# Now read back the modified value ...
shift temp, i2
unless temp == 17 goto fail
say "ok"
end
fail:
say "not ok"
.end
CODE
ok
OUTPUT
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End: