Skip to content

Commit 6eeae5d

Browse files
authored
Merge pull request #1545 from ton-blockchain/tolk-v0.9
Tolk v0.9: nullable types `T?`, null safety, control flow, smart casts
2 parents faf5811 + f67e9f4 commit 6eeae5d

File tree

110 files changed

+5722
-1821
lines changed

Some content is hidden

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

110 files changed

+5722
-1821
lines changed

crypto/smartcont/tolk-stdlib/common.tolk

+11-11
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.8
4+
tolk 0.9
55

66
/**
77
Tuple manipulation primitives.
@@ -139,7 +139,7 @@ fun getMyOriginalBalance(): int
139139
/// `int` — balance in nanotoncoins;
140140
/// `cell` — a dictionary with 32-bit keys representing the balance of "extra currencies".
141141
@pure
142-
fun getMyOriginalBalanceWithExtraCurrencies(): [int, cell]
142+
fun getMyOriginalBalanceWithExtraCurrencies(): [int, cell?]
143143
asm "BALANCE";
144144

145145
/// Returns the logical time of the current transaction.
@@ -154,7 +154,7 @@ fun getCurrentBlockLogicalTime(): int
154154

155155
/// Returns the value of the global configuration parameter with integer index `i` as a `cell` or `null` value.
156156
@pure
157-
fun getBlockchainConfigParam(x: int): cell
157+
fun getBlockchainConfigParam(x: int): cell?
158158
asm "CONFIGOPTPARAM";
159159

160160
/// Returns the persistent contract storage cell. It can be parsed or modified with slice and builder primitives later.
@@ -291,7 +291,7 @@ fun calculateSliceSizeStrict(s: slice, maxCells: int): (int, int, int)
291291
/// otherwise the returned value is one plus the maximum of depths of cells referred to from [c].
292292
/// If [c] is a `null` instead of a cell, returns zero.
293293
@pure
294-
fun getCellDepth(c: cell): int
294+
fun getCellDepth(c: cell?): int
295295
asm "CDEPTH";
296296

297297
/// Returns the depth of `slice` [s].
@@ -417,12 +417,12 @@ fun getLastBits(self: slice, len: int): slice
417417
/// Loads a dictionary (TL HashMapE structure, represented as TVM cell) from a slice.
418418
/// Returns `null` if `nothing` constructor is used.
419419
@pure
420-
fun loadDict(mutate self: slice): cell
420+
fun loadDict(mutate self: slice): cell?
421421
asm( -> 1 0) "LDDICT";
422422

423423
/// Preloads a dictionary (cell) from a slice.
424424
@pure
425-
fun preloadDict(self: slice): cell
425+
fun preloadDict(self: slice): cell?
426426
asm "PLDDICT";
427427

428428
/// Loads a dictionary as [loadDict], but returns only the remainder of the slice.
@@ -433,12 +433,12 @@ fun skipDict(mutate self: slice): self
433433
/// Loads (Maybe ^Cell) from a slice.
434434
/// In other words, loads 1 bit: if it's true, loads the first ref, otherwise returns `null`.
435435
@pure
436-
fun loadMaybeRef(mutate self: slice): cell
436+
fun loadMaybeRef(mutate self: slice): cell?
437437
asm( -> 1 0) "LDOPTREF";
438438

439439
/// Preloads (Maybe ^Cell) from a slice.
440440
@pure
441-
fun preloadMaybeRef(self: slice): cell
441+
fun preloadMaybeRef(self: slice): cell?
442442
asm "PLDOPTREF";
443443

444444
/// Loads (Maybe ^Cell), but returns only the remainder of the slice.
@@ -497,13 +497,13 @@ fun storeBool(mutate self: builder, x: bool): self
497497
/// Stores dictionary (represented by TVM `cell` or `null`) into a builder.
498498
/// In other words, stores a `1`-bit and a reference to [c] if [c] is not `null` and `0`-bit otherwise.
499499
@pure
500-
fun storeDict(mutate self: builder, c: cell): self
500+
fun storeDict(mutate self: builder, c: cell?): self
501501
asm(c self) "STDICT";
502502

503503
/// Stores (Maybe ^Cell) into a builder.
504504
/// In other words, if cell is `null`, store '0' bit; otherwise, store '1' and a ref to [c].
505505
@pure
506-
fun storeMaybeRef(mutate self: builder, c: cell): self
506+
fun storeMaybeRef(mutate self: builder, c: cell?): self
507507
asm(c self) "STOPTREF";
508508

509509
/// Concatenates two builders.
@@ -661,7 +661,7 @@ fun reserveToncoinsOnBalance(nanoTonCoins: int, reserveMode: int): void
661661

662662
/// Similar to [reserveToncoinsOnBalance], but also accepts a dictionary extraAmount (represented by a cell or null)
663663
/// with extra currencies. In this way currencies other than Toncoin can be reserved.
664-
fun reserveExtraCurrenciesOnBalance(nanoTonCoins: int, extraAmount: cell, reserveMode: int): void
664+
fun reserveExtraCurrenciesOnBalance(nanoTonCoins: int, extraAmount: cell?, reserveMode: int): void
665665
asm "RAWRESERVEX";
666666

667667

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A part of standard library for Tolk
2-
tolk 0.8
2+
tolk 0.9
33

44
/**
55
Gas and payment related primitives.

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A part of standard library for Tolk
2-
tolk 0.8
2+
tolk 0.9
33

44
/**
55
Lisp-style lists are nested 2-elements tuples: `(1, (2, (3, null)))` represents list `[1, 2, 3]`.
@@ -14,17 +14,18 @@ fun createEmptyList(): tuple
1414
/// Adds an element to the beginning of lisp-style list.
1515
/// Note, that it does not mutate the list: instead, it returns a new one (it's a lisp pattern).
1616
@pure
17-
fun listPrepend<X>(head: X, tail: tuple): tuple
17+
fun listPrepend<X>(head: X, tail: tuple?): tuple
1818
asm "CONS";
1919

2020
/// Extracts the head and the tail of lisp-style list.
2121
@pure
22-
fun listSplit<X>(list: tuple): (X, tuple)
22+
fun listSplit<X>(list: tuple): (X, tuple?)
2323
asm "UNCONS";
2424

2525
/// Extracts the tail and the head of lisp-style list.
26+
/// After extracting the last element, tuple is assigned to null.
2627
@pure
27-
fun listNext<X>(mutate self: tuple): X
28+
fun listNext<X>(mutate self: tuple?): X
2829
asm( -> 1 0) "UNCONS";
2930

3031
/// Returns the head of lisp-style list.
@@ -34,5 +35,5 @@ fun listGetHead<X>(list: tuple): X
3435

3536
/// Returns the tail of lisp-style list.
3637
@pure
37-
fun listGetTail(list: tuple): tuple
38+
fun listGetTail(list: tuple): tuple?
3839
asm "CDR";

0 commit comments

Comments
 (0)