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.6
4+ tolk 0.7
55
66/**
77 Tuple manipulation primitives.
@@ -17,17 +17,17 @@ fun createEmptyTuple(): tuple
1717/// Appends a value to tuple, resulting in `Tuple t' = (x1, ..., xn, value)`.
1818/// If its size exceeds 255, throws a type check exception.
1919@pure
20- fun tuplePush<X >(mutate self: tuple, value: X ): void
20+ fun tuplePush<T >(mutate self: tuple, value: T ): void
2121 asm "TPUSH";
2222
2323/// Returns the first element of a non-empty tuple.
2424@pure
25- fun tupleFirst<X >(t: tuple): X
25+ fun tupleFirst<T >(t: tuple): T
2626 asm "FIRST";
2727
2828/// Returns the [`index`]-th element of a tuple.
2929@pure
30- fun tupleAt<X >(t: tuple, index: int): X
30+ fun tupleAt<T >(t: tuple, index: int): T
3131 builtin;
3232
3333/// Returns the size of a tuple (elements count in it).
@@ -37,7 +37,7 @@ fun tupleSize(t: tuple): int
3737
3838/// Returns the last element of a non-empty tuple.
3939@pure
40- fun tupleLast(t: tuple): int
40+ fun tupleLast<T> (t: tuple): T
4141 asm "LAST";
4242
4343
@@ -205,7 +205,7 @@ fun stringHash(s: slice): int
205205/// That is, if [hash] is computed as the hash of some data, these data are hashed twice,
206206/// the second hashing occurring inside `CHKSIGNS`.
207207@pure
208- fun isSignatureValid(hash: int, signature: slice, publicKey: int): int
208+ fun isSignatureValid(hash: int, signature: slice, publicKey: int): bool
209209 asm "CHKSIGNU";
210210
211211/// 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
214214/// The verification of Ed25519 signatures is the standard one,
215215/// with sha256 used to reduce [data] to the 256-bit number that is actually signed.
216216@pure
217- fun isSliceSignatureValid(data: slice, signature: slice, publicKey: int): int
217+ fun isSliceSignatureValid(data: slice, signature: slice, publicKey: int): bool
218218 asm "CHKSIGNS";
219219
220220/// Generates a new pseudo-random unsigned 256-bit integer x.
@@ -259,14 +259,14 @@ fun randomizeByLogicalTime(): void
259259/// otherwise the computation is aborted before visiting the `(maxCells + 1)`-st cell and
260260/// a zero flag is returned to indicate failure. If [c] is `null`, returns `x = y = z = 0`.
261261@pure
262- fun calculateCellSize(c: cell, maxCells: int): (int, int, int, int )
262+ fun calculateCellSize(c: cell, maxCells: int): (int, int, int, bool )
263263 asm "CDATASIZEQ NULLSWAPIFNOT2 NULLSWAPIFNOT";
264264
265265/// Similar to [calculateCellSize], but accepting a `slice` [s] instead of a `cell`.
266266/// The returned value of `x` does not take into account the cell that contains the `slice` [s] itself;
267267/// however, the data bits and the cell references of [s] are accounted for in `y` and `z`.
268268@pure
269- fun calculateSliceSize(s: slice, maxCells: int): (int, int, int, int )
269+ fun calculateSliceSize(s: slice, maxCells: int): (int, int, int, bool )
270270 asm "SDATASIZEQ NULLSWAPIFNOT2 NULLSWAPIFNOT";
271271
272272/// A non-quiet version of [calculateCellSize] that throws a cell overflow exception (`8`) on failure.
@@ -306,11 +306,11 @@ fun getBuilderDepth(b: builder): int
306306 */
307307
308308/// Dump a variable [x] to the debug log.
309- fun debugPrint<X >(x: X ): void
309+ fun debugPrint<T >(x: T ): void
310310 builtin;
311311
312312/// Dump a string [x] to the debug log.
313- fun debugPrintString<X >(x: X ): void
313+ fun debugPrintString<T >(x: T ): void
314314 builtin;
315315
316316/// 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
382382
383383/// Loads bool (-1 or 0) from a slice
384384@pure
385- fun loadBool(mutate self: slice): int
385+ fun loadBool(mutate self: slice): bool
386386 asm( -> 1 0) "1 LDI";
387387
388388/// Shifts a slice pointer to [len] bits forward, mutating the slice.
@@ -482,7 +482,7 @@ fun storeCoins(mutate self: builder, x: int): self
482482/// Stores bool (-1 or 0) into a builder.
483483/// Attention: true value is `-1`, not 1! If you pass `1` here, TVM will throw an exception.
484484@pure
485- fun storeBool(mutate self: builder, x: int ): self
485+ fun storeBool(mutate self: builder, x: bool ): self
486486 asm(x self) "1 STI";
487487
488488/// Stores dictionary (represented by TVM `cell` or `null`) into a builder.
@@ -529,22 +529,22 @@ fun getRemainingBitsAndRefsCount(self: slice): (int, int)
529529
530530/// Checks whether a slice is empty (i.e., contains no bits of data and no cell references).
531531@pure
532- fun isEndOfSlice(self: slice): int
532+ fun isEndOfSlice(self: slice): bool
533533 asm "SEMPTY";
534534
535535/// Checks whether a slice has no bits of data.
536536@pure
537- fun isEndOfSliceBits(self: slice): int
537+ fun isEndOfSliceBits(self: slice): bool
538538 asm "SDEMPTY";
539539
540540/// Checks whether a slice has no references.
541541@pure
542- fun isEndOfSliceRefs(self: slice): int
542+ fun isEndOfSliceRefs(self: slice): bool
543543 asm "SREMPTY";
544544
545545/// Checks whether data parts of two slices coinside.
546546@pure
547- fun isSliceBitsEqual(self: slice, b: slice): int
547+ fun isSliceBitsEqual(self: slice, b: slice): bool
548548 asm "SDEQ";
549549
550550/// Returns the number of cell references already stored in a builder.
@@ -621,10 +621,10 @@ fun parseStandardAddress(s: slice): (int, int)
621621fun createAddressNone(): slice
622622 asm "b{00} PUSHSLICE";
623623
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.
625625/// In other words, a slice starts with two `0` bits (TL addr_none$00).
626626@pure
627- fun addressIsNone(s: slice): int
627+ fun addressIsNone(s: slice): bool
628628 asm "2 PLDU" "0 EQINT";
629629
630630
@@ -677,8 +677,8 @@ fun loadMessageFlags(mutate self: slice): int
677677/// Having msgFlags (4 bits), check that a message is bounced.
678678/// Effectively, it's `msgFlags & 1` (the lowest bit present).
679679@pure
680- fun isMessageBounced(msgFlags: int): int
681- asm "1 PUSHINT" "AND ";
680+ fun isMessageBounced(msgFlags: int): bool
681+ asm "2 PUSHINT" "MODR ";
682682
683683/// Skip 0xFFFFFFFF prefix (when a message is bounced).
684684@pure
0 commit comments