Skip to content

Commit 12ff28a

Browse files
committed
[Tolk] Completely rework stdlib: multiple files and renaming
- split stdlib.tolk into multiple files (tolk-stdlib/ folder) (the "core" common.tolk is auto-imported, the rest are needed to be explicitly imported like "@stdlib/tvm-dicts.tolk") - all functions were renamed to long and clear names - new naming is camelCase
1 parent e2edadb commit 12ff28a

Some content is hidden

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

48 files changed

+2969
-2461
lines changed

crypto/smartcont/mathlib.tolk

Lines changed: 0 additions & 1002 deletions
This file was deleted.

crypto/smartcont/stdlib.tolk

Lines changed: 0 additions & 1108 deletions
This file was deleted.

crypto/smartcont/tolk-stdlib/common.tolk

Lines changed: 766 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// A part of standard library for Tolk
2+
tolk 0.6
3+
4+
/**
5+
Gas and payment related primitives.
6+
*/
7+
8+
/// Returns amount of gas (in gas units) consumed in current Computation Phase.
9+
fun getGasConsumedAtTheMoment(): int
10+
asm "GASCONSUMED";
11+
12+
/// This function is required to be called when you process an external message (from an outer world)
13+
/// and "accept" it to blockchain.
14+
/// Without calling this function, an external message would be discarded.
15+
/// As an effect, the current smart contract agrees to buy some gas to finish the current transaction.
16+
/// For more details, check [accept_message effects](https://ton.org/docs/#/smart-contracts/accept).
17+
fun acceptExternalMessage(): void
18+
asm "ACCEPT";
19+
20+
/// When processing an internal message, by default, the limit of gas consumption is determined by incoming message.
21+
/// Functions [setGasLimit] and [setGasLimitToMaximum] allow you to change this behavior.
22+
/// Sets current gas limit `gl` to its maximal allowed value `gm`, and resets the gas credit `gc` to zero,
23+
/// decreasing the value of `gr` by `gc` in the process.
24+
fun setGasLimitToMaximum(): void
25+
asm "ACCEPT";
26+
27+
/// When processing an internal message, by default, the limit of gas consumption is determined by incoming message.
28+
/// Functions [setGasLimit] and [setGasLimitToMaximum] allow you to change this behavior.
29+
/// Sets current gas limit `gl` to the minimum of limit and `gm`, and resets the gas credit `gc` to zero.
30+
/// If the gas consumed so far (including the present instruction) exceeds the resulting value of `gl`,
31+
/// an (unhandled) out of gas exception is thrown before setting new gas limits.
32+
fun setGasLimit(limit: int): void
33+
asm "SETGASLIMIT";
34+
35+
/// Calculates fee (amount in nanotoncoins to be paid) for a transaction which consumed [gasUsed] gas units.
36+
fun calculateGasFee(workchain: int, gasUsed: int): int
37+
asm(gasUsed workchain) "GETGASFEE";
38+
39+
/// Same as [calculateGasFee], but without flat price (you have supposed to read https://docs.ton.org/develop/howto/fees-low-level)
40+
fun calculateGasFeeWithoutFlatPrice(workchain: int, gasUsed: int): int
41+
asm(gasUsed workchain) "GETGASFEESIMPLE";
42+
43+
/// Calculates amount of nanotoncoins you should pay for storing a contract of provided size for [seconds].
44+
/// [bits] and [cells] represent contract state (code + data).
45+
fun calculateStorageFee(workchain: int, seconds: int, bits: int, cells: int): int
46+
asm(cells bits seconds workchain) "GETSTORAGEFEE";
47+
48+
/// Calculates amount of nanotoncoins you should pay to send a message of specified size.
49+
fun calculateMessageFee(workchain: int, bits: int, cells: int): int
50+
asm(cells bits workchain) "GETFORWARDFEE";
51+
52+
/// Same as [calculateMessageFee], but without lump price (you have supposed to read https://docs.ton.org/develop/howto/fees-low-level)
53+
fun calculateMessageFeeWithoutLumpPrice(workchain: int, bits: int, cells: int): int
54+
asm(cells bits workchain) "GETFORWARDFEESIMPLE";
55+
56+
/// Calculates fee that was paid by the sender of an incoming internal message.
57+
fun calculateOriginalMessageFee(workchain: int, incomingFwdFee: int): int
58+
asm(incomingFwdFee workchain) "GETORIGINALFWDFEE";
59+
60+
/// Returns the amount of nanotoncoins current contract debts for storage. ("due" and "debt" are synonyms)
61+
/// If it has no debt, `0` is returned.
62+
fun getMyStorageDuePayment(): int
63+
asm "DUEPAYMENT";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// A part of standard library for Tolk
2+
tolk 0.6
3+
4+
/**
5+
Lisp-style lists are nested 2-elements tuples: `(1, (2, (3, null)))` represents list `[1, 2, 3]`.
6+
Elements of a list can be of different types.
7+
Empty list is conventionally represented as TVM `null` value.
8+
*/
9+
10+
@pure
11+
fun createEmptyList(): tuple
12+
asm "PUSHNULL";
13+
14+
/// Adds an element to the beginning of lisp-style list.
15+
/// Note, that it does not mutate the list: instead, it returns a new one (it's a lisp pattern).
16+
@pure
17+
fun listPrepend<X>(head: X, tail: tuple): tuple
18+
asm "CONS";
19+
20+
/// Extracts the head and the tail of lisp-style list.
21+
@pure
22+
fun listSplit<X>(list: tuple): (X, tuple)
23+
asm "UNCONS";
24+
25+
/// Extracts the tail and the head of lisp-style list.
26+
@pure
27+
fun ~listNext<X>(list: tuple): (tuple, X)
28+
asm( -> 1 0) "UNCONS";
29+
30+
/// Returns the head of lisp-style list.
31+
@pure
32+
fun listGetHead<X>(list: tuple): X
33+
asm "CAR";
34+
35+
/// Returns the tail of lisp-style list.
36+
@pure
37+
fun listGetTail(list: tuple): tuple
38+
asm "CDR";

0 commit comments

Comments
 (0)