1
1
// Standard library for Tolk (LGPL licence).
2
2
// It contains common functions that are available out of the box, the user doesn't have to import anything.
3
3
// More specific functions are required to be imported explicitly, like "@stdlib/tvm-dicts".
4
- tolk 0.6
4
+ tolk 0.7
5
5
6
6
/**
7
7
Tuple manipulation primitives.
@@ -17,17 +17,17 @@ fun createEmptyTuple(): tuple
17
17
/// Appends a value to tuple, resulting in `Tuple t' = (x1, ..., xn, value)`.
18
18
/// If its size exceeds 255, throws a type check exception.
19
19
@pure
20
- fun tuplePush<X >(mutate self: tuple, value: X ): void
20
+ fun tuplePush<T >(mutate self: tuple, value: T ): void
21
21
asm "TPUSH";
22
22
23
23
/// Returns the first element of a non-empty tuple.
24
24
@pure
25
- fun tupleFirst<X >(t: tuple): X
25
+ fun tupleFirst<T >(t: tuple): T
26
26
asm "FIRST";
27
27
28
28
/// Returns the [`index`]-th element of a tuple.
29
29
@pure
30
- fun tupleAt<X >(t: tuple, index: int): X
30
+ fun tupleAt<T >(t: tuple, index: int): T
31
31
builtin;
32
32
33
33
/// Returns the size of a tuple (elements count in it).
@@ -37,7 +37,7 @@ fun tupleSize(t: tuple): int
37
37
38
38
/// Returns the last element of a non-empty tuple.
39
39
@pure
40
- fun tupleLast(t: tuple): int
40
+ fun tupleLast<T> (t: tuple): T
41
41
asm "LAST";
42
42
43
43
@@ -205,7 +205,7 @@ fun stringHash(s: slice): int
205
205
/// That is, if [hash] is computed as the hash of some data, these data are hashed twice,
206
206
/// the second hashing occurring inside `CHKSIGNS`.
207
207
@pure
208
- fun isSignatureValid(hash: int, signature: slice, publicKey: int): int
208
+ fun isSignatureValid(hash: int, signature: slice, publicKey: int): bool
209
209
asm "CHKSIGNU";
210
210
211
211
/// Checks whether [signature] is a valid Ed25519-signature of the data portion of `slice data` using `publicKey`,
@@ -214,7 +214,7 @@ fun isSignatureValid(hash: int, signature: slice, publicKey: int): int
214
214
/// The verification of Ed25519 signatures is the standard one,
215
215
/// with sha256 used to reduce [data] to the 256-bit number that is actually signed.
216
216
@pure
217
- fun isSliceSignatureValid(data: slice, signature: slice, publicKey: int): int
217
+ fun isSliceSignatureValid(data: slice, signature: slice, publicKey: int): bool
218
218
asm "CHKSIGNS";
219
219
220
220
/// Generates a new pseudo-random unsigned 256-bit integer x.
@@ -259,14 +259,14 @@ fun randomizeByLogicalTime(): void
259
259
/// otherwise the computation is aborted before visiting the `(maxCells + 1)`-st cell and
260
260
/// a zero flag is returned to indicate failure. If [c] is `null`, returns `x = y = z = 0`.
261
261
@pure
262
- fun calculateCellSize(c: cell, maxCells: int): (int, int, int, int )
262
+ fun calculateCellSize(c: cell, maxCells: int): (int, int, int, bool )
263
263
asm "CDATASIZEQ NULLSWAPIFNOT2 NULLSWAPIFNOT";
264
264
265
265
/// Similar to [calculateCellSize], but accepting a `slice` [s] instead of a `cell`.
266
266
/// The returned value of `x` does not take into account the cell that contains the `slice` [s] itself;
267
267
/// however, the data bits and the cell references of [s] are accounted for in `y` and `z`.
268
268
@pure
269
- fun calculateSliceSize(s: slice, maxCells: int): (int, int, int, int )
269
+ fun calculateSliceSize(s: slice, maxCells: int): (int, int, int, bool )
270
270
asm "SDATASIZEQ NULLSWAPIFNOT2 NULLSWAPIFNOT";
271
271
272
272
/// A non-quiet version of [calculateCellSize] that throws a cell overflow exception (`8`) on failure.
@@ -306,11 +306,11 @@ fun getBuilderDepth(b: builder): int
306
306
*/
307
307
308
308
/// Dump a variable [x] to the debug log.
309
- fun debugPrint<X >(x: X ): void
309
+ fun debugPrint<T >(x: T ): void
310
310
builtin;
311
311
312
312
/// Dump a string [x] to the debug log.
313
- fun debugPrintString<X >(x: X ): void
313
+ fun debugPrintString<T >(x: T ): void
314
314
builtin;
315
315
316
316
/// Dumps the stack (at most the top 255 values) and shows the total stack depth.
@@ -382,7 +382,7 @@ fun loadCoins(mutate self: slice): int
382
382
383
383
/// Loads bool (-1 or 0) from a slice
384
384
@pure
385
- fun loadBool(mutate self: slice): int
385
+ fun loadBool(mutate self: slice): bool
386
386
asm( -> 1 0) "1 LDI";
387
387
388
388
/// Shifts a slice pointer to [len] bits forward, mutating the slice.
@@ -482,7 +482,7 @@ fun storeCoins(mutate self: builder, x: int): self
482
482
/// Stores bool (-1 or 0) into a builder.
483
483
/// Attention: true value is `-1`, not 1! If you pass `1` here, TVM will throw an exception.
484
484
@pure
485
- fun storeBool(mutate self: builder, x: int ): self
485
+ fun storeBool(mutate self: builder, x: bool ): self
486
486
asm(x self) "1 STI";
487
487
488
488
/// Stores dictionary (represented by TVM `cell` or `null`) into a builder.
@@ -529,22 +529,22 @@ fun getRemainingBitsAndRefsCount(self: slice): (int, int)
529
529
530
530
/// Checks whether a slice is empty (i.e., contains no bits of data and no cell references).
531
531
@pure
532
- fun isEndOfSlice(self: slice): int
532
+ fun isEndOfSlice(self: slice): bool
533
533
asm "SEMPTY";
534
534
535
535
/// Checks whether a slice has no bits of data.
536
536
@pure
537
- fun isEndOfSliceBits(self: slice): int
537
+ fun isEndOfSliceBits(self: slice): bool
538
538
asm "SDEMPTY";
539
539
540
540
/// Checks whether a slice has no references.
541
541
@pure
542
- fun isEndOfSliceRefs(self: slice): int
542
+ fun isEndOfSliceRefs(self: slice): bool
543
543
asm "SREMPTY";
544
544
545
545
/// Checks whether data parts of two slices coinside.
546
546
@pure
547
- fun isSliceBitsEqual(self: slice, b: slice): int
547
+ fun isSliceBitsEqual(self: slice, b: slice): bool
548
548
asm "SDEQ";
549
549
550
550
/// Returns the number of cell references already stored in a builder.
@@ -621,10 +621,10 @@ fun parseStandardAddress(s: slice): (int, int)
621
621
fun createAddressNone(): slice
622
622
asm "b{00} PUSHSLICE";
623
623
624
- /// Returns if a slice pointer contains an empty address (`-1` for true, `0` for false, as always) .
624
+ /// Returns if a slice pointer contains an empty address.
625
625
/// In other words, a slice starts with two `0` bits (TL addr_none$00).
626
626
@pure
627
- fun addressIsNone(s: slice): int
627
+ fun addressIsNone(s: slice): bool
628
628
asm "2 PLDU" "0 EQINT";
629
629
630
630
@@ -677,8 +677,8 @@ fun loadMessageFlags(mutate self: slice): int
677
677
/// Having msgFlags (4 bits), check that a message is bounced.
678
678
/// Effectively, it's `msgFlags & 1` (the lowest bit present).
679
679
@pure
680
- fun isMessageBounced(msgFlags: int): int
681
- asm "1 PUSHINT" "AND ";
680
+ fun isMessageBounced(msgFlags: int): bool
681
+ asm "2 PUSHINT" "MODR ";
682
682
683
683
/// Skip 0xFFFFFFFF prefix (when a message is bounced).
684
684
@pure
0 commit comments