Skip to content

Commit e5feb76

Browse files
authored
Merge pull request #1503 from ton-blockchain/tolk-v0.8
Tolk v0.8: preparation for structures; indexed access `var.0`
2 parents b1c9466 + e9d8f16 commit e5feb76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1368
-586
lines changed

crypto/smartcont/tolk-stdlib/common.tolk

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Standard library for Tolk (LGPL licence).
22
// It contains common functions that are available out of the box, the user doesn't have to import anything.
33
// More specific functions are required to be imported explicitly, like "@stdlib/tvm-dicts".
4-
tolk 0.7
4+
tolk 0.8
55

66
/**
77
Tuple manipulation primitives.
@@ -21,23 +21,32 @@ fun tuplePush<T>(mutate self: tuple, value: T): void
2121
asm "TPUSH";
2222

2323
/// Returns the first element of a non-empty tuple.
24+
/// `t.0` is actually the same as `t.tupleFirst()`
2425
@pure
25-
fun tupleFirst<T>(t: tuple): T
26+
fun tupleFirst<T>(self: tuple): T
2627
asm "FIRST";
2728

2829
/// Returns the [`index`]-th element of a tuple.
30+
/// `t.i` is actually the same as `t.tupleAt(i)`
2931
@pure
30-
fun tupleAt<T>(t: tuple, index: int): T
32+
fun tupleAt<T>(self: tuple, index: int): T
33+
builtin;
34+
35+
/// Sets the [`index`]-th element of a tuple to a specified value
36+
/// (element with this index must already exist, a new element isn't created).
37+
/// `t.i = value` is actually the same as `t.tupleSetAt(value, i)`
38+
@pure
39+
fun tupleSetAt<T>(mutate self: tuple, value: T, index: int): void
3140
builtin;
3241

3342
/// Returns the size of a tuple (elements count in it).
3443
@pure
35-
fun tupleSize(t: tuple): int
44+
fun tupleSize(self: tuple): int
3645
asm "TLEN";
3746

3847
/// Returns the last element of a non-empty tuple.
3948
@pure
40-
fun tupleLast<T>(t: tuple): T
49+
fun tupleLast<T>(self: tuple): T
4150
asm "LAST";
4251

4352

crypto/smartcont/tolk-stdlib/gas-payments.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A part of standard library for Tolk
2-
tolk 0.7
2+
tolk 0.8
33

44
/**
55
Gas and payment related primitives.

crypto/smartcont/tolk-stdlib/lisp-lists.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A part of standard library for Tolk
2-
tolk 0.7
2+
tolk 0.8
33

44
/**
55
Lisp-style lists are nested 2-elements tuples: `(1, (2, (3, null)))` represents list `[1, 2, 3]`.

crypto/smartcont/tolk-stdlib/tvm-dicts.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A part of standard library for Tolk
2-
tolk 0.7
2+
tolk 0.8
33

44
/**
55
Dictionaries are represented as `cell` data type (cells can store anything, dicts in particular).

crypto/smartcont/tolk-stdlib/tvm-lowlevel.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A part of standard library for Tolk
2-
tolk 0.7
2+
tolk 0.8
33

44
/// Usually `c3` has a continuation initialized by the whole code of the contract. It is used for function calls.
55
/// The primitive returns the current value of `c3`.

tolk-tester/tests/a10.tolk

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ fun testStartBalanceCodegen2() {
7878
return first;
7979
}
8080

81+
global cur: [int, int, int];
82+
global next: [int, int, int];
83+
84+
@method_id(95)
85+
fun test95() {
86+
cur = [1, 2, 3];
87+
next = [2, 3, 4];
88+
(cur, next) = (next, [3, 4, 5]);
89+
return (cur, next);
90+
}
91+
8192
/**
8293
method_id | in | out
8394
@testcase | 0 | 101 15 | 100 1
@@ -90,6 +101,7 @@ fun testStartBalanceCodegen2() {
90101
@testcase | 89 | 4 | 1 4 1 4
91102
@testcase | 91 | | 10
92103
@testcase | 92 | | 10 32
104+
@testcase | 95 | | [ 2 3 4 ] [ 3 4 5 ]
93105

94106
@fif_codegen
95107
"""
@@ -104,9 +116,9 @@ fun testStartBalanceCodegen2() {
104116
testDumpDontPolluteStack PROC:<{
105117
...
106118
DUMPSTK
107-
x{6d79} PUSHSLICE // f s _9
119+
x{6d79} PUSHSLICE // f s '5
108120
STRDUMP DROP
109-
SBITS // f _11
121+
SBITS // f '6
110122
}>
111123
"""
112124

@@ -127,4 +139,20 @@ fun testStartBalanceCodegen2() {
127139
FIRST // first
128140
}>
129141
"""
142+
143+
@fif_codegen
144+
"""
145+
test95 PROC:<{
146+
...
147+
next GETGLOB // '10
148+
3 PUSHINT // '10 '12=3
149+
4 PUSHINT // '10 '12=3 '13=4
150+
5 PUSHINT // '10 '12=3 '13=4 '14=5
151+
TRIPLE // '15 '16
152+
next SETGLOB
153+
cur SETGLOB
154+
cur GETGLOB // '17
155+
next GETGLOB // '17 '18
156+
}>
157+
"""
130158
*/

tolk-tester/tests/a6.tolk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
fun f(a: int, b: int, c: int, d: int, e: int, f: int): (int, int) {
22
// solve a 2x2 linear equation
33
var D: int = a*d - b*c;;;; var Dx: int = e*d-b*f ;;;; var Dy: int = a * f - e * c;
4+
__expect_type(D, "int");
5+
__expect_type(D*D, "int");
6+
__expect_type(calc_phi, "() -> int");
47
return (Dx/D,Dy/D);
58
};;;;
69

tolk-tester/tests/a6_1.tolk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fun main(a: int, b: int, c: int, d: int, e: int, f: int): (int, int) {
77

88
@method_id(101)
99
fun testDivMod(x: int, y: int) {
10-
return [divMod(x, y), modDiv(x, y), mulDivMod(x, y, 10)];
10+
return (divMod(x, y), modDiv(x, y), mulDivMod(x, y, 10));
1111
}
1212

1313
/**
@@ -18,5 +18,5 @@ fun testDivMod(x: int, y: int) {
1818
@testcase | 0 | 448 -433 -444 792 150012 -356232 | -218 -572
1919
@testcase | 0 | -40 -821 433 -734 -721629 -741724 | -206 889
2020
@testcase | 0 | -261 -98 -494 868 -166153 733738 | 263 995
21-
@testcase | 101 | 112 3 | [ 37 1 1 37 33 6 ]
21+
@testcase | 101 | 112 3 | 37 1 1 37 33 6
2222
*/

tolk-tester/tests/allow_post_modification.tolk

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ fun test_if_else(x: int): (int, int, int, int, int) {
8989

9090
@method_id(21)
9191
fun test_assign_with_inner(x: int) {
92-
return (x, x += 10, [(x, x += 20, eq(x -= 50), x)], eq2((x, x *= eq(x /= 2))));
92+
var result = (x, x += 10, [x, x += 20, eq(x -= 50), x], eq2((x, x *= eq(x /= 2))));
93+
return result;
9394
}
9495

9596
@method_id(22)
9697
fun test_assign_with_mutate(x: int) {
97-
return (x, mul2(mutate x, x += 5), x.`~inc`(mul2(mutate x, x)), x);
98+
var (result, _) = ((x, mul2(mutate x, x += 5), x.`~inc`(mul2(mutate x, x)), x), 0);
99+
return result;
98100
}
99101

100102
@method_id(23)
@@ -138,5 +140,12 @@ fun main() {
138140
inc CALLDICT // self newY
139141
}>
140142
"""
143+
144+
@fif_codegen
145+
"""
146+
test_assign_tensor_global PROC:<{
147+
// x.0 x.1
148+
"""
149+
141150
@code_hash 7627024945492125068389905298530400936797031708759561372406088054030801992712
142151
*/

tolk-tester/tests/assignment-tests.tolk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ fun autoInferIntNull(x: int) {
1414
return x;
1515
}
1616

17+
fun typesAsIdentifiers(builder: builder) {
18+
var int = 1;
19+
var cell = builder.endCell();
20+
var slice = cell.beginParse();
21+
{
22+
var cell: cell = cell;
23+
var tuple: tuple = createEmptyTuple();
24+
var bool: bool = tuple.tupleAt<int>(0) > 0;
25+
}
26+
return int;
27+
}
28+
1729
fun main(value: int) {
1830
var (x: int, y) = (autoInferIntNull(value), autoInferIntNull(value * 2));
1931
if (x == null && y == null) { return null; }

0 commit comments

Comments
 (0)