-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#14 Iterator support for collections of references
Fixes #14
- Loading branch information
1 parent
acfb9e6
commit a1ae49a
Showing
9 changed files
with
171 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
// Iterator assignments | ||
|
||
bool result : true | ||
bool result: true | ||
void fail(string msg): | ||
"tc_iterator01: FAIL: $msg" | ||
result = false | ||
|
||
array sarray: string, 1 | ||
sarray array1: "a" | ||
array{int32, 3} intArray: 1, 2, 3 | ||
sequence{int32} intSeq: 2, 3, 4 | ||
list{int32} intList: 3, 4, 5 | ||
|
||
iterator{int32} a : intArray | ||
iterator{int32} b : intSeq | ||
iterator{int32} c : intList | ||
|
||
var int32 total | ||
while a++: total += *a | ||
if total != 6: fail("total != 6 (array)") | ||
|
||
total = 0 | ||
while b++: total += *b | ||
if total != 9: fail("total != 9 (sequence)") | ||
|
||
iterator siter: string | ||
siter iter1 | ||
iter1 = array1 | ||
total = 0 | ||
while c++: total += *c | ||
if total != 12: fail("total != 12 (list)") | ||
|
||
iter1++ | ||
// Reassign iterator | ||
a = intSeq | ||
total = 0 | ||
while a++: total += *a | ||
if total != 9: fail("total != 6 (sequence #2)") | ||
|
||
if result: "$testname: OK" | ||
if result: "tc_iterator01: OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
bool result: true | ||
void fail(string msg): | ||
"tc_iterator02: FAIL: $msg" | ||
result = false | ||
|
||
struct Point:: x, y: int32 | ||
|
||
array{Point, 3} pArray: {1, 2}, {3, 4}, {5, 6} | ||
sequence{Point} pSeq: {3, 4}, {5, 6}, {7, 8} | ||
list{Point} pList: {5, 6}, {7, 8}, {9, 10} | ||
|
||
iterator{Point} a : pArray | ||
iterator{Point} b : pSeq | ||
iterator{Point} c : pList | ||
|
||
var Point total | ||
while a++: total[x, y] += *a[x, y] | ||
if total[x, y] != (9, 12): fail("total[x, y] != (9, 12) (array)") | ||
|
||
total = {0, 0} | ||
while b++: total[x, y] += *b[x, y] | ||
if total[x, y] != (15, 18): fail("total[x, y] != (15, 18) (sequence)") | ||
|
||
total = {0, 0} | ||
while c++: total[x, y] += *c[x, y] | ||
if total[x, y] != (21, 24): fail("total[x, y] != (21, 24) (list)") | ||
|
||
// Reassign iterator | ||
a = pSeq | ||
total = {0, 0} | ||
while a++: total[x, y] += *a[x, y] | ||
if total[x, y] != (15, 18): fail("total[x, y] != (15, 18) (sequence #2)") | ||
|
||
if result: "tc_iterator02: OK" |