1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

[Tolk] Support syntax tensorVar.0 and tupleVar.0

It works both for reading and writing:
> var t = (1, 2);
> t.0;      // 1
> t.0 = 5;
> t;        // (5, 2)

It also works for typed/untyped tuples, producing INDEX and SETINDEX.

Global tensors and tuples works. Nesting `t.0.1.2` works. `mutate` works.
Even mixing tuples inside tensors inside a global for writing works.
This commit is contained in:
tolk-vm 2025-01-27 10:29:17 +03:00
parent 565bc59735
commit 7a1602f591
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
42 changed files with 1119 additions and 338 deletions

View file

@ -14,13 +14,19 @@ fun getTwo<X>(): X { return 2 as X; }
fun takeInt(a: int) { return a; }
@method_id(102)
fun test102(): (int, int, int, [(int, int)]) {
fun test102(): (int, int, int, [int, int]) {
var a: int = getTwo();
var _: int = getTwo();
var b = getTwo() as int;
var c: int = 1 ? getTwo() : getTwo();
var c redef = getTwo();
return (eq1<int>(a), eq2<int>(b), takeInt(getTwo()), [(getTwo(), getTwo())]);
var ab_tens = (0, (1, 2));
ab_tens.0 = getTwo();
ab_tens.1.1 = getTwo();
var ab_tup = [0, [1, 2]];
ab_tup.0 = getTwo();
ab_tup.1.1 = getTwo();
return (eq1<int>(a), eq2<int>(b), takeInt(getTwo()), [getTwo(), ab_tens.1.1]);
}
@method_id(103)
@ -43,9 +49,9 @@ fun manyEq<T1, T2, T3>(a: T1, b: T2, c: T3): [T1, T2, T3] {
fun test104(f: int) {
var result = (
manyEq(1 ? 1 : 1, f ? 0 : null, !f ? getTwo() as int : null),
manyEq((f ? null as int : eq2(2), beginCell().storeBool(true).endCell().beginParse().loadBool()), 0, eq4(f))
manyEq(f ? null as int : eq2(2), beginCell().storeBool(true).endCell().beginParse().loadBool(), eq4(f))
);
__expect_type(result, "([int, int, int], [(int, bool), int, int])");
__expect_type(result, "([int, int, int], [int, bool, int])");
return result;
}
@ -74,7 +80,8 @@ fun test106() {
return [
abstractTransform(cellToSlice, calcLoad32, c),
abstractTransform(calcYPlus1<int>, calcYPlus1<int>, 0),
abstractTransform(calcTensorPlus1, calcTensorMul2, (2, 2))
abstractTransform(calcTensorPlus1, calcTensorMul2, (2, 2)).0,
abstractTransform(calcTensorPlus1, calcTensorMul2, (2, 2)).1
];
}
@ -135,7 +142,7 @@ fun main(x: int): (int, [[int, int]]) {
@testcase | 101 | 0 | 0 0 0 [ 0 0 ] 0 0 0 [ 0 0 ] 0 0 0 []
@testcase | 102 | | 2 2 2 [ 2 2 ]
@testcase | 103 | 0 | 0 100 100
@testcase | 104 | 0 | [ 1 (null) 2 ] [ 2 -1 0 0 ]
@testcase | 104 | 0 | [ 1 (null) 2 ] [ 2 -1 0 ]
@testcase | 105 | | 3
@testcase | 106 | | [ 106 2 6 6 ]
@testcase | 107 | | 6 6 1 1 6 6