Skip to content

Commit ca2a79f

Browse files
authored
Merge pull request #1718 from ton-blockchain/master
Merge Tolk to testnet
2 parents 34cbbbb + 72056a2 commit ca2a79f

Some content is hidden

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

54 files changed

+3192
-261
lines changed

crypto/smartcont/tolk-stdlib/common.tolk

Lines changed: 316 additions & 65 deletions
Large diffs are not rendered by default.

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.13
2+
tolk 0.99
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.13
2+
tolk 0.99
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.13
2+
tolk 0.99
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.13
2+
tolk 0.99
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/calls-tests.tolk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ fun test8() {
150150
return (createTFrom(), createTFrom((5, (8, createTFrom().0))));
151151
}
152152

153+
fun int(initial: int) { return initial }
154+
fun int.create0() { return 0 }
155+
fun int.plus1(self) { return self + 1 }
156+
157+
@method_id(109)
158+
fun test9() {
159+
return int(10) + int(5).plus1() + int.create0() + int.create0().plus1();
160+
}
161+
153162
fun main() {}
154163

155164
/**
@@ -161,4 +170,5 @@ fun main() {}
161170
@testcase | 106 | 0 | 5 -5 50 -50 0
162171
@testcase | 107 | | 16 5
163172
@testcase | 108 | | [ 1 2 3 ] [ 5 8 1 ]
173+
@testcase | 109 | | 17
164174
*/

tolk-tester/tests/cells-slices.tolk

Lines changed: 189 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
fun builder.store_u32(mutate self, value: int): self {
22
return self.storeUint(value, 32);
33
}
4+
fun builder.storeMessageOp(mutate self, op: int): self
5+
asm(op self) "32 STU";
6+
fun builder.storeMessageQueryId(mutate self, queryId: int): self
7+
asm(queryId self) "64 STU";
48

59
fun slice.load_u32(mutate self): int {
610
return self.loadUint(32);
@@ -77,7 +81,8 @@ fun test5(): [int,int] {
7781

7882
@method_id(106)
7983
fun test6() {
80-
return beginCell().storeUint(1, 32).storeUint(2, 32).storeUint(3, 32);
84+
var st = beginCell().storeUint(1, 32).storeUint(2, 32).storeUint(3, 32).endCell().beginParse();
85+
return st.loadUint(96) == ((1 << 64) + (2 << 32) + 3);
8186
}
8287

8388
@method_id(107)
@@ -194,7 +199,6 @@ fun test111() {
194199
var q2 = s.loadMessageQueryId();
195200
s.skipBits(64);
196201
s.assertEnd();
197-
assert(isMessageBounced(0x001) && !isMessageBounced(0x002)) throw 444;
198202
return (op1, q1, op2, q2);
199203
}
200204

@@ -229,6 +233,96 @@ fun test16() {
229233
}
230234

231235

236+
@method_id(117)
237+
fun test17() {
238+
var b = beginCell().storeUint(1, 4).storeCoins(0).storeInt(123, 8);
239+
var s = b.endCell().beginParse();
240+
return (s.loadUint(4), s.loadCoins(), s.loadUint(8));
241+
}
242+
243+
@method_id(118)
244+
fun test18() {
245+
var x = 0;
246+
var b = beginCell();
247+
b = b.storeUint(x, 14);
248+
x += 12;
249+
if (10 > 3) { x += x; }
250+
if (true) {
251+
b.storeInt(x + 2, 8).storeUint(x = match (x) { 24 => 5, else => 0 }, 4);
252+
}
253+
var s = b.endCell().beginParse();
254+
return (s.loadUint(14), s.loadInt(8), s.loadUint(4));
255+
}
256+
257+
fun test19() {
258+
// numbers with potential overflow for STU are not joined, check via codegen
259+
var b = beginCell();
260+
b.storeInt(123, 4).storeUint(0xFF, 8).storeUint(0xFF, 8).storeInt(-1, 8);
261+
return b;
262+
}
263+
264+
@method_id(120)
265+
fun test20() {
266+
var x = false;
267+
var n = 4;
268+
var b = true ? beginCell() : null;
269+
b.storeBool(true).storeBool(x);
270+
b = b.storeBool(true).storeUint(0, n *= 2).storeBool(!!true).storeCoins(0);
271+
var s = b.endCell().beginParse();
272+
return (s.loadBool(), s.loadBool(), s.loadBool(), s.loadUint(8), s.loadBool(), s.loadCoins());
273+
}
274+
275+
fun test21(s: slice) {
276+
// successive skipBits are also joined
277+
var x = 8;
278+
s.skipBits(x);
279+
x -= 4;
280+
s = s.skipBits(x).skipBits(2);
281+
x *= 0;
282+
s = s.skipBits(x);
283+
return s;
284+
}
285+
286+
@method_id(122)
287+
fun test22() {
288+
// different builders aren't mixed, store inside them are joined independently
289+
var (b1, b2) = (beginCell(), beginCell());
290+
b1.storeUint(8, 16).storeUint(8, 8);
291+
b2.storeUint(8, 32).storeUint(1<<88, 100);
292+
return (
293+
b1.endCell().beginParse().remainingBitsCount(),
294+
b2.endCell().beginParse().skipBits(32).loadUint(100),
295+
);
296+
}
297+
298+
@method_id(123)
299+
fun test23(uns: bool) {
300+
// corner values, signed/unsigned 255/256
301+
var b = beginCell();
302+
if (uns) {
303+
b.storeUint(1, 100).storeUint(2, 100).storeInt(3, 55).storeInt(0, 1);
304+
b.storeUint(8, 256);
305+
} else {
306+
b.storeInt(1, 10).storeUint(2, 190).storeInt(3, 54).storeUint(1, 1);
307+
}
308+
return b.bitsCount();
309+
}
310+
311+
@method_id(124)
312+
fun test24(uns: bool) {
313+
// doesn't fit into a single STI/STU instruction, is splitted
314+
var b = beginCell();
315+
if (uns) {
316+
b.storeUint(1, 100).storeUint(2, 100)
317+
.storeInt(3, 100).storeInt(8, 19);
318+
return b.endCell().beginParse().skipBits(200+100).loadInt(19);
319+
} else {
320+
b.storeInt(1, 20).storeUint(2, 200).storeInt(3, 35)
321+
.storeUint(1, 1).storeUint(5, 5).storeUint(10, 10);
322+
return b.endCell().beginParse().skipBits(255+6).loadUint(10);
323+
}
324+
}
325+
232326
fun main(): int {
233327
return 0;
234328
}
@@ -239,6 +333,7 @@ fun main(): int {
239333
@testcase | 103 | 103 | 103
240334
@testcase | 104 | | [ 1 3 ]
241335
@testcase | 105 | | [ 210 1 ]
336+
@testcase | 106 | | -1
242337
@testcase | 107 | | 72 40 72
243338
@testcase | 108 | | 0 40 32
244339
@testcase | 110 | | 64 3 0 0 -1 0 100 -1
@@ -249,20 +344,102 @@ fun main(): int {
249344
@testcase | 114 | 0 | 0 0 0
250345
@testcase | 115 | | 123 456 123 456
251346
@testcase | 116 | | BC{00140008000000ff00000008}
347+
@testcase | 117 | | 1 0 123
348+
@testcase | 118 | | 0 26 5
349+
@testcase | 120 | | -1 0 -1 0 -1 0
350+
@testcase | 122 | | 24 309485009821345068724781056
351+
@testcase | 123 | -1 | 512
352+
@testcase | 123 | 0 | 255
353+
@testcase | 124 | -1 | 8
354+
@testcase | 124 | 0 | 10
355+
356+
We test that consequtive storeInt/storeUint with constants are joined into a single number
252357

253-
Note, that since 'compute-asm-ltr' became on be default, chaining methods codegen is not quite optimal.
254358
@fif_codegen
255359
"""
256360
test6 PROC:<{
257-
1 PUSHINT // '0=1
258-
NEWC // '0=1 '1
259-
32 STU // '1
260-
2 PUSHINT // '1 '4=2
261-
SWAP // '4=2 '1
262-
32 STU // '1
263-
3 PUSHINT // '1 '7=3
264-
SWAP // '7=3 '1
265-
32 STU // '1
361+
18446744082299486211 PUSHINT
362+
NEWC
363+
96 STU // '2
364+
ENDC // '11
365+
"""
366+
367+
@fif_codegen
368+
"""
369+
test17 PROC:<{
370+
4219 PUSHINT
371+
NEWC
372+
16 STU
373+
"""
374+
375+
@fif_codegen
376+
"""
377+
test18 PROC:<{
378+
421 PUSHINT
379+
NEWC
380+
26 STU
381+
"""
382+
383+
@fif_codegen
384+
"""
385+
test19 PROC:<{
386+
NEWC
387+
123 PUSHINT
388+
SWAP
389+
4 STI
390+
16 PUSHPOW2DEC
391+
16 STUR
392+
-1 PUSHINT
393+
SWAP
394+
8 STI
266395
}>
267396
"""
397+
398+
@fif_codegen
399+
"""
400+
test20 PROC:<{
401+
40976 PUSHINT
402+
NEWC
403+
16 STU
404+
"""
405+
406+
@fif_codegen
407+
"""
408+
test21 PROC:<{
409+
14 PUSHINT
410+
SDSKIPFIRST
411+
}>
412+
"""
413+
414+
@fif_codegen
415+
"""
416+
test22 PROC:<{
417+
NEWC // '2
418+
NEWC // b1 b2
419+
SWAP // b2 b1
420+
2056 PUSHINT
421+
24 STUR // b2 b1
422+
SWAP // b1 b2
423+
10141514286835656557042350424064 PUSHINTX
424+
132 STUR // b1 b2
425+
"""
426+
427+
@fif_codegen
428+
"""
429+
test23 PROC:<{
430+
NEWC
431+
SWAP
432+
IF:<{
433+
91343852333181432387730302044911803916571639814 PUSHINT
434+
256 STUR
435+
8 PUSHINT
436+
256 STUR
437+
}>ELSE<{
438+
56539106072908298546665520023773392506479484700019806659963456035401760775 PUSHINT
439+
255 STIR
440+
}>
441+
BBITS
442+
}>
443+
"""
444+
268445
*/

tolk-tester/tests/generics-2.tolk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,23 +451,23 @@ fun main(c: Wrapper<slice>, d: WrappedInt) {
451451
@testcase | 104 | | 11 11 13 13 13 2
452452
@testcase | 105 | 0 | 80
453453
@testcase | 105 | -1 | (null)
454-
@testcase | 106 | | (null) (null) 0 777 1 2 142
454+
@testcase | 106 | | (null) (null) 0 777 1 2 typeid-14
455455
@testcase | 107 | 5 | 20 20 5 5 20 777 (null) (null) (null) 0
456-
@testcase | 108 | 0 | 777 143 777 143
456+
@testcase | 108 | 0 | 777 typeid-15 777 typeid-15
457457
@testcase | 108 | -1 | 777 0 777 0
458458
@testcase | 109 | | 40 40 70
459459
@testcase | 110 | | 20 1 20 42
460-
@testcase | 111 | | 5 1 132 5 1 132 5 1 132 5 1 132
461-
@testcase | 112 | -1 | 10 1 777 10 1 133
462-
@testcase | 112 | 0 | 20 1 777 (null) 0 134
460+
@testcase | 111 | | 5 1 typeid-4 5 1 typeid-4 5 1 typeid-4 5 1 typeid-4
461+
@testcase | 112 | -1 | 10 1 777 10 1 typeid-5
462+
@testcase | 112 | 0 | 20 1 777 (null) 0 typeid-6
463463
@testcase | 113 | | 30 -1
464464
@testcase | 114 | | 999 (null) 2
465465
@testcase | 115 | | 10 0 200 1 -1 200 1 -1
466466
@testcase | 116 | | 1 2 3 4
467467
@testcase | 117 | | 100 123
468468
@testcase | 118 | | 123 1 777 123 1 -1 2
469469
@testcase | 119 | | 40 40 -1 -1 -1 -1
470-
@testcase | 120 | | (null) 137 777 (null) (null) 0 139 -1 -1
470+
@testcase | 120 | | (null) typeid-9 777 (null) (null) 0 typeid-11 -1 -1
471471
@testcase | 123 | | 10 10 10 10 10
472472

473473

tolk-tester/tests/generics-3.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fun main() {
130130
@testcase | 101 | -1 | 10
131131
@testcase | 101 | 0 | -1
132132
@testcase | 103 | | 10 -1 0
133-
@testcase | 104 | | 12 129 132 -1 -1 -1 0 0 -1 0 0
133+
@testcase | 104 | | 12 typeid-1 typeid-4 -1 -1 -1 0 0 -1 0 0
134134
@testcase | 105 | | -1 -1 -1 -1 0 0
135135
@testcase | 108 | | 50000000 (null) (null) 100000000 12 12 24
136136

tolk-tester/tests/generics-4.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fun main() {
172172
/**
173173
@testcase | 103 | | 10 20 30 777 40 40
174174
@testcase | 104 | | (null) (null) (null)
175-
@testcase | 105 | | -1 (null) 0 (null) 134 777 0 123 0 456 133
175+
@testcase | 105 | | -1 (null) 0 (null) typeid-6 777 0 123 0 456 typeid-5
176176
@testcase | 106 | | -1 0 -1 -1
177177
@testcase | 107 | | 1 10 110 117
178178
@testcase | 108 | | 10 (null) 20

0 commit comments

Comments
 (0)