| 1 |
/* |
| 2 |
* Complex assignments test. This tests side effects in the lvalue of a |
| 3 |
* compound assignment, to make sure that each lvalue subexpression is |
| 4 |
* only evaluated once and that the results are properly assigned. |
| 5 |
*/ |
| 6 |
#include <tads.h> |
| 7 |
#include <strbuf.h> |
| 8 |
|
| 9 |
obj: object |
| 10 |
p1 = ['v', 'w', 'x', 'y', 'z'] |
| 11 |
p2 = static [p1, p1, p1, p1, p1] |
| 12 |
; |
| 13 |
|
| 14 |
obj2: object |
| 15 |
p1 = obj |
| 16 |
; |
| 17 |
|
| 18 |
main(args) |
| 19 |
{ |
| 20 |
local i = 1, j = 1, k = 1; |
| 21 |
local l = ['a', 'b', 'c', 'd', 'e']; |
| 22 |
local l2 = [['a', 'b', 'c', 'd', 'e'], |
| 23 |
['f', 'g', 'h', 'i', 'j'], |
| 24 |
['k', 'l', 'm', 'n', 'o'], |
| 25 |
['p', 'q', 'r', 's', 't'], |
| 26 |
['u', 'v', 'w', 'x', 'y']]; |
| 27 |
local l3 = [l2, l2, l2, l2, l2]; |
| 28 |
|
| 29 |
l[i++] = 'A1'; |
| 30 |
"i=<<i>>, j=<<j>>, k=<<k>>, l = <<l.myjoin()>>\b"; |
| 31 |
|
| 32 |
l[i++] += 'B2'; |
| 33 |
"i=<<i>>, j=<<j>>, k=<<k>>, l = <<l.myjoin()>>\b"; |
| 34 |
|
| 35 |
l[++i] += 'C3'; |
| 36 |
"i=<<i>>, j=<<j>>, k=<<k>>, l = <<l.myjoin()>>\b"; |
| 37 |
|
| 38 |
i = j = k = 1; |
| 39 |
|
| 40 |
l2[i++][j++] = 'D4'; |
| 41 |
"i=<<i>>, j=<<j>>, k=<<k>>, l2 = <<l2.myjoin()>>\b"; |
| 42 |
|
| 43 |
l2[i++][j++] += 'E5'; |
| 44 |
"i=<<i>>, j=<<j>>, k=<<k>>, l2 = <<l2.myjoin()>>\b"; |
| 45 |
|
| 46 |
i = j = i = 1; |
| 47 |
"\b"; |
| 48 |
|
| 49 |
l3[i++][j++][k++] = 'F6'; |
| 50 |
"i=<<i>>, j=<<j>>, k=<<k>>, l3 = <<l3.myjoin()>>\b"; |
| 51 |
|
| 52 |
l3[i++][j++][k++] += 'G7'; |
| 53 |
"i=<<i>>, j=<<j>>, k=<<k>>, l3 = <<l3.myjoin()>>\b"; |
| 54 |
|
| 55 |
i = j = k = 1; |
| 56 |
|
| 57 |
obj.p1[i++] = 'M1'; |
| 58 |
"i=<<i>>, j=<<j>>, k=<<k>>, obj.p1 = <<obj.p1.myjoin()>>\b"; |
| 59 |
|
| 60 |
obj.p1[i++] += 'N2'; |
| 61 |
"i=<<i>>, j=<<j>>, k=<<k>>, obj.p1 = <<obj.p1.myjoin()>>\b"; |
| 62 |
|
| 63 |
i = j = k = 1; |
| 64 |
|
| 65 |
obj.p2[i++][j++] = 'O3'; |
| 66 |
"i=<<i>>, j=<<j>>, k=<<k>>, obj.p2 = <<obj.p2.myjoin()>>\b"; |
| 67 |
|
| 68 |
obj.p2[i++][j++] += 'P4'; |
| 69 |
"i=<<i>>, j=<<j>>, k=<<k>>, obj.p2 = <<obj.p2.myjoin()>>\b"; |
| 70 |
|
| 71 |
local a = obj; |
| 72 |
i = j = k = 1; |
| 73 |
a.p2[i++][j++] = 'Q5'; |
| 74 |
"i=<<i>>, j=<<j>>, k=<<k>>, obj.p2 = <<obj.p2.myjoin()>>\b"; |
| 75 |
|
| 76 |
local b = &p2; |
| 77 |
a.(b)[i++][j++] += 'R6'; |
| 78 |
"i=<<i>>, j=<<j>>, k=<<k>>, obj.p2 = <<obj.p2.myjoin()>>\b"; |
| 79 |
|
| 80 |
func1(obj2, 'obj2').(func1(&p1, 'p1')).(func1(&p2, 'p2')) |
| 81 |
[func1(3, 'idx 3')][func1(4, 'idx 4')] += func1('S8', 'val S8'); |
| 82 |
"i=<<i>>, j=<<j>>, k=<<k>>, obj.p2 = <<obj.p2.myjoin()>>\b"; |
| 83 |
} |
| 84 |
|
| 85 |
func1(x, desc) |
| 86 |
{ |
| 87 |
"→ This is func1(<<desc>>)!\n"; |
| 88 |
return x; |
| 89 |
} |
| 90 |
|
| 91 |
modify List |
| 92 |
myjoin(depth = 0) |
| 93 |
{ |
| 94 |
local s = new StringBuffer(); |
| 95 |
s.append('['); |
| 96 |
|
| 97 |
for (local i = 1, local len = length() ; i <= len ; ++i) |
| 98 |
{ |
| 99 |
if (i > 1) |
| 100 |
s.append(', '); |
| 101 |
|
| 102 |
local ele = self[i]; |
| 103 |
if (dataType(ele) == TypeList) |
| 104 |
s.append(ele.myjoin(depth + 1)); |
| 105 |
else |
| 106 |
s.append(ele); |
| 107 |
} |
| 108 |
|
| 109 |
s.append(']'); |
| 110 |
return toString(s); |
| 111 |
} |
| 112 |
; |