-
Notifications
You must be signed in to change notification settings - Fork 952
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
48 changed files
with
2,969 additions
and
2,461 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// A part of standard library for Tolk | ||
tolk 0.6 | ||
|
||
/** | ||
Gas and payment related primitives. | ||
*/ | ||
|
||
/// Returns amount of gas (in gas units) consumed in current Computation Phase. | ||
fun getGasConsumedAtTheMoment(): int | ||
asm "GASCONSUMED"; | ||
|
||
/// This function is required to be called when you process an external message (from an outer world) | ||
/// and "accept" it to blockchain. | ||
/// Without calling this function, an external message would be discarded. | ||
/// As an effect, the current smart contract agrees to buy some gas to finish the current transaction. | ||
/// For more details, check [accept_message effects](https://ton.org/docs/#/smart-contracts/accept). | ||
fun acceptExternalMessage(): void | ||
asm "ACCEPT"; | ||
|
||
/// When processing an internal message, by default, the limit of gas consumption is determined by incoming message. | ||
/// Functions [setGasLimit] and [setGasLimitToMaximum] allow you to change this behavior. | ||
/// Sets current gas limit `gl` to its maximal allowed value `gm`, and resets the gas credit `gc` to zero, | ||
/// decreasing the value of `gr` by `gc` in the process. | ||
fun setGasLimitToMaximum(): void | ||
asm "ACCEPT"; | ||
|
||
/// When processing an internal message, by default, the limit of gas consumption is determined by incoming message. | ||
/// Functions [setGasLimit] and [setGasLimitToMaximum] allow you to change this behavior. | ||
/// Sets current gas limit `gl` to the minimum of limit and `gm`, and resets the gas credit `gc` to zero. | ||
/// If the gas consumed so far (including the present instruction) exceeds the resulting value of `gl`, | ||
/// an (unhandled) out of gas exception is thrown before setting new gas limits. | ||
fun setGasLimit(limit: int): void | ||
asm "SETGASLIMIT"; | ||
|
||
/// Calculates fee (amount in nanotoncoins to be paid) for a transaction which consumed [gasUsed] gas units. | ||
fun calculateGasFee(workchain: int, gasUsed: int): int | ||
asm(gasUsed workchain) "GETGASFEE"; | ||
|
||
/// Same as [calculateGasFee], but without flat price (you have supposed to read https://docs.ton.org/develop/howto/fees-low-level) | ||
fun calculateGasFeeWithoutFlatPrice(workchain: int, gasUsed: int): int | ||
asm(gasUsed workchain) "GETGASFEESIMPLE"; | ||
|
||
/// Calculates amount of nanotoncoins you should pay for storing a contract of provided size for [seconds]. | ||
/// [bits] and [cells] represent contract state (code + data). | ||
fun calculateStorageFee(workchain: int, seconds: int, bits: int, cells: int): int | ||
asm(cells bits seconds workchain) "GETSTORAGEFEE"; | ||
|
||
/// Calculates amount of nanotoncoins you should pay to send a message of specified size. | ||
fun calculateMessageFee(workchain: int, bits: int, cells: int): int | ||
asm(cells bits workchain) "GETFORWARDFEE"; | ||
|
||
/// Same as [calculateMessageFee], but without lump price (you have supposed to read https://docs.ton.org/develop/howto/fees-low-level) | ||
fun calculateMessageFeeWithoutLumpPrice(workchain: int, bits: int, cells: int): int | ||
asm(cells bits workchain) "GETFORWARDFEESIMPLE"; | ||
|
||
/// Calculates fee that was paid by the sender of an incoming internal message. | ||
fun calculateOriginalMessageFee(workchain: int, incomingFwdFee: int): int | ||
asm(incomingFwdFee workchain) "GETORIGINALFWDFEE"; | ||
|
||
/// Returns the amount of nanotoncoins current contract debts for storage. ("due" and "debt" are synonyms) | ||
/// If it has no debt, `0` is returned. | ||
fun getMyStorageDuePayment(): int | ||
asm "DUEPAYMENT"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// A part of standard library for Tolk | ||
tolk 0.6 | ||
|
||
/** | ||
Lisp-style lists are nested 2-elements tuples: `(1, (2, (3, null)))` represents list `[1, 2, 3]`. | ||
Elements of a list can be of different types. | ||
Empty list is conventionally represented as TVM `null` value. | ||
*/ | ||
|
||
@pure | ||
fun createEmptyList(): tuple | ||
asm "PUSHNULL"; | ||
|
||
/// Adds an element to the beginning of lisp-style list. | ||
/// Note, that it does not mutate the list: instead, it returns a new one (it's a lisp pattern). | ||
@pure | ||
fun listPrepend<X>(head: X, tail: tuple): tuple | ||
asm "CONS"; | ||
|
||
/// Extracts the head and the tail of lisp-style list. | ||
@pure | ||
fun listSplit<X>(list: tuple): (X, tuple) | ||
asm "UNCONS"; | ||
|
||
/// Extracts the tail and the head of lisp-style list. | ||
@pure | ||
fun ~listNext<X>(list: tuple): (tuple, X) | ||
asm( -> 1 0) "UNCONS"; | ||
|
||
/// Returns the head of lisp-style list. | ||
@pure | ||
fun listGetHead<X>(list: tuple): X | ||
asm "CAR"; | ||
|
||
/// Returns the tail of lisp-style list. | ||
@pure | ||
fun listGetTail(list: tuple): tuple | ||
asm "CDR"; |
Oops, something went wrong.