Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit fcff4bc

Browse files
committed
feat: Language->Reference, a big update!
WIP, but almost there.
1 parent ee7fe04 commit fcff4bc

23 files changed

+957
-204
lines changed

pages/book/config.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Each project is described by the following fields:
1515

1616
Tact support next parameters:
1717
* `debug: true`. Enables debug output of a contract. It is useful for debugging purposes. Enabling this contract would report that it was compiled in debug mode using the `supported_interfaces` method.
18-
* `masterchain: true`. Enables [masterchain support](/language/guides/masterchain) in the contract.
18+
* `masterchain: true`. Enables [masterchain support](/book/masterchain) in the contract.
1919

2020
## Example
2121

pages/book/import.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Callout } from 'nextra-theme-docs'
44

55
Tact allows you to import Tact and [FunC](https://docs.ton.org/develop/func/overview) code — any given `.tact` or `.fc`/`.func` file can be imported into your project using an `import{:tact}` keyword.
66

7-
Additionally, Tact compiler has a versatile set of standard libraries, which come bundled in, but not included right away, see [Language→Libs→Overview](/language/libs/overview).
7+
Additionally, Tact compiler has a versatile set of standard libraries, which come bundled in, but not included right away, see [Standard libraries overview](/ref/standard-libraries).
88

99
<Callout type="warning" emoji="⚠️">
1010
NOTE: All imported code is combined together with yours, so it's important to avoid name collisions and always double-check the sources!
@@ -36,7 +36,7 @@ import "./relative/path/to/the/target/func/file.fc";
3636
import "../subfolder/imported/func/file.fc";
3737
```
3838

39-
But in order to use functions from such file, one has to declare them as `native` functions first. For example, when standard library [@stdlib/dns](/language/libs/dns) uses a `dns.fc` FunC file, it maps FunC functions to Tact ones like so:
39+
But in order to use functions from such file, one has to declare them as `native` functions first. For example, when standard library [@stdlib/dns](/ref/stdlib-dns) uses a `dns.fc` FunC file, it maps FunC functions to Tact ones like so:
4040

4141
```tact
4242
// FunC code located in a file right next to the current Tact one:
@@ -49,4 +49,4 @@ native dnsStringToInternal(str: String): Slice?;
4949

5050
## Standard libraries
5151

52-
See [Language→Libs→Overview](/language/libs/overview).
52+
See [Standard libraries overview](/ref/standard-libraries).

pages/book/integers.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Use underscores (`_`) to improve readability: $\mathrm{0b111\_111\_111}$ is equa
4646

4747
For example, arithmetic with dollars requires two decimal places after the dot — those are used for the cents value. But how would we represent the number \$$1.25$ if we're only able to work with integers? The solution is to work with _cents_ directly. This way, \$$1.25$ becomes $125$ cents. We simply memorize that the two rightmost digits represent the numbers after the decimal point.
4848

49-
Similarly, working with Toncoins requires nine decimal places instead of the two. Therefore, the amount of $1.25$ TON, which can be represented in Tact as [`ton("1.25"){:tact}`](/language/ref/common#ton), is actually the number $1250000000$. We refer to such numbers as _nano-tons_ (or _nanoToncoins_) rather than _cents_.
49+
Similarly, working with Toncoins requires nine decimal places instead of the two. Therefore, the amount of $1.25$ TON, which can be represented in Tact as [`ton("1.25"){:tact}`](/ref/api-comptime#ton), is actually the number $1250000000$. We refer to such numbers as _nano-tons_ (or _nanoToncoins_) rather than _cents_.
5050

5151
## Serialization
5252

pages/book/operators.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This page lists all the operators in Tact in decreasing order of their [preceden
88

99
<Callout>
1010

11-
Note, that there are no implicit type conversions in Tact, so operators can't be used to, say, add values of different type or compare them in terms of equality without explicitly casting to the same type. That's done with certain functions from the standard library. See [`Int.toString(){:tact}`](/language/ref/strings#inttostring) for an example of such function.
11+
Note, that there are no implicit type conversions in Tact, so operators can't be used to, say, add values of different type or compare them in terms of equality without explicitly casting to the same type. That's done with certain functions from the standard library. See [`Int.toString(){:tact}`](/ref/api-strings#inttostring) for an example of such function.
1212

1313
</Callout>
1414

@@ -135,7 +135,7 @@ two % 1; // 1
135135
-1 % -5; // -1
136136
```
137137

138-
The simplest way to avoid confusion between the two is to prefer using positive values via [`abs(x: Int){:tact}`](/language/ref/math#abs):
138+
The simplest way to avoid confusion between the two is to prefer using positive values via [`abs(x: Int){:tact}`](/ref/api-math#abs):
139139

140140
```tact
141141
abs(-1) % abs(-5); // 1

pages/book/types.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Read more about them on the dedicated page: [Contracts](/book/contracts).
140140

141141
Tact doesn't support classical class inheritance, but instead introduces the concept of _traits_, which can be viewed as abstract contracts (like abstract classes in popular object-oriented languages). They have the same structure as [contracts](#contracts), but can't [initialize persistent state variables](/book/contracts#init-function), while allowing to override some of their behaviors.
142142

143-
Example of a trait [`Ownable`](/language/libs/ownable#ownable) from [`@stdlib/ownable`](/language/libs/ownable):
143+
Example of a trait [`Ownable{:tact}`](/ref/stdlib-ownable#ownable) from [`@stdlib/ownable`](/ref/stdlib-ownable):
144144

145145
```tact
146146
trait Ownable {
@@ -159,14 +159,14 @@ trait Ownable {
159159
}
160160
```
161161

162-
And the [contract](#contracts) that uses trait [`Ownable`](/language/libs/ownable#ownable):
162+
And the [contract](#contracts) that uses trait [`Ownable{:tact}`](/ref/stdlib-ownable#ownable):
163163

164164
```tact
165165
contract Treasure with Ownable {
166-
// persistent state variable, which MUST be defined in the contract
166+
// Persistent state variable, which MUST be defined in the contract
167167
owner: Address;
168168
169-
// constructor function init(), where all the variables are initialized
169+
// Constructor function init(), where all the variables are initialized
170170
init(owner: Address) {
171171
self.owner = owner;
172172
}

pages/cookbook/misc.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ nativeThrowUnless(39, number == 198);
2626
<Callout>
2727

2828
**Useful links:**\
29-
[`throw(){:tact}` in Language→Reference](/language/ref/advanced#throw)\
29+
[`throw(){:tact}` in API Reference](/ref/api-debug#throw)\
3030
[Errors in Tact-By-Example](https://tact-by-example.org/03-errors)
3131

3232
</Callout>

pages/cookbook/random.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ number = random(1, 12);
2020
<Callout>
2121

2222
**Useful links:**\
23-
[`randomInt(){:tact}` in Language→Reference](/language/ref/random#randomInt)\
24-
[`random(){:tact}` in Language→Reference](/language/ref/random#random)
23+
[`randomInt(){:tact}` in API Reference](/ref/api-random#randomInt)\
24+
[`random(){:tact}` in API Reference](/ref/api-random#random)
2525

2626
</Callout>
2727

pages/cookbook/single-communication.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ send(SendParameters{
9191
["Sending messages" in the Book](/book/send#send-message)\
9292
["Message `mode`" in the Book](/book/message-mode)
9393
[`StringBuilder{:tact}` in the Book](/book/types#primitive-types)\
94-
[`Cell{:tact}` in Language→Reference](/language/ref/cells)
94+
[`Cell{:tact}` in API Reference](/ref/api-cells)
9595

9696
</Callout>
9797

pages/cookbook/time.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (currentTime > 1672080143) {
1919
<Callout>
2020

2121
**Useful links:**\
22-
[`now(){:tact}` in Language→Reference](/language/ref/common#now)\
22+
[`now(){:tact}` in API Reference](/ref/api-common#now)\
2323
["Current Time" in Tact-By-Example](https://tact-by-example.org/04-current-time)
2424

2525
</Callout>

pages/cookbook/type-conversion.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ dump(coinsString); // "0.261119911"
6060
<Callout>
6161

6262
**Useful links:**\
63-
[`Int.toString(){:tact}` in Language→Reference](/language/ref/strings#inttostring)\
64-
[`Int.toFloatString(){:tact}` in Language→Reference](/language/ref/strings#inttofloatstring)\
65-
[`Int.toCoinsString(){:tact}` in Language→Reference](/language/ref/strings#inttocoinsstring)
63+
[`Int.toString(){:tact}` in API Reference](/ref/api-strings#inttostring)\
64+
[`Int.toFloatString(){:tact}` in API Reference](/ref/api-strings#inttofloatstring)\
65+
[`Int.toCoinsString(){:tact}` in API Reference](/ref/api-strings#inttocoinsstring)
6666

6767
</Callout>
6868

pages/index.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ For custom plugins for your favorite editor and other tooling see the [Tools](/e
109109
Alternatively, take a look at the following broader sections:
110110
* [Book](/book) helps you learn the language step-by-step
111111
* [Cookbook](/cookbook) gives you ready-made recipes of Tact code
112-
* [Language](/language) provides a complete reference of the standard library, grammar and evolution process
112+
* [Reference](/ref) provides a complete glossary of the standard library, grammar and evolution process
113113
* Finally, [Ecosystem](/ecosystem) describes "what's out there" in the Tacts' and TONs' ecosystems
114114

115115
<Cards>
@@ -120,13 +120,13 @@ Alternatively, take a look at the following broader sections:
120120
/>
121121
<Cards.Card
122122
icon="🍲 "
123-
title="Examine the Cookbook"
123+
title="Grind the Cookbook"
124124
href="/cookbook"
125125
/>
126126
<Cards.Card
127127
icon="🔬 "
128-
title="Study the Language"
129-
href="/language"
128+
title="Skim the Reference"
129+
href="/ref"
130130
/>
131131
<Cards.Card
132132
icon="🗺️ "

pages/ref/_meta.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ export default {
77
title: 'API Reference',
88
},
99
'api-base': 'Base trait',
10+
'api-common': 'Common',
1011
'api-comptime': 'Compile-time',
11-
'api-common': 'Common', // what does it mean???
12-
'api-strings': 'Strings', // text.tact + ...
12+
'api-debug': 'Debug',
1313
'api-random': 'Random',
1414
'api-math': 'Math',
15+
'api-strings': 'Strings and StringBuilders',
1516
'api-cells': 'Cells, Builders and Slices',
1617
'api-advanced': 'Advanced',
1718
'-- Stdlib': {

pages/ref/api-advanced.mdx

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Miscellaneous
1+
# Advanced
22

33
import { Callout } from 'nextra/components'
44

@@ -18,30 +18,6 @@ extends fun readForwardFee(self: Context): Int
1818

1919
Read and compute forward fee from the `Context{:tact}` and return it as `Int{:tact}` value in nanoToncoins (nano-tons).
2020

21-
## throw
22-
23-
```tact
24-
fun throw(code: Int);
25-
```
26-
27-
Throw an exception with error code equal `code`.
28-
29-
## nativeThrowWhen
30-
31-
```tact
32-
fun nativeThrowWhen(code: Int, condition: Bool);
33-
```
34-
35-
Throw an exception with error code equal to `code` when `condition` is equal to `true{:tact}`.
36-
37-
## nativeThrowUnless
38-
39-
```tact
40-
fun nativeThrowUnless(code: Int, condition: Bool);
41-
```
42-
43-
Throw an exception with error code equal to `code` when `condition` is equal to `false{:tact}`.
44-
4521
## getConfigParam
4622

4723
```tact
@@ -125,3 +101,19 @@ Function `raw_reserve` is roughly equivalent to creating an outbound message car
125101
<Callout type="warning" emoji="⚠️">
126102
Currently, `amount` must be a non-negative integer, and `mode` must be in the range 0..15, inclusive.
127103
</Callout>
104+
105+
---
106+
107+
TODO: remove
108+
109+
```tact
110+
@name(raw_reserve)
111+
native nativeReserve(amount: Int, mode: Int);
112+
113+
const ReserveExact: Int = 0;
114+
const ReserveAllExcept: Int = 1;
115+
const ReserveAtMost: Int = 2;
116+
const ReserveAddOriginalBalance: Int = 4;
117+
const ReserveInvertSign: Int = 8;
118+
const ReserveBounceIfActionFail: Int = 16;
119+
```

pages/ref/api-base.mdx

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,124 @@
22

33
import { Callout } from 'nextra-theme-docs'
44

5-
Every [contract](/book/contracts) and [trait](/book/types#traits) in Tact implicitly inherits the `Base{:tact}` trait, which contains a number of the most useful [internal functions (methods)](/book/contracts#internal-functions) for any kind of contract.
5+
Every [contract](/book/contracts) and [trait](/book/types#traits) in Tact implicitly inherits the `Base{:tact}` trait, which contains a number of the most useful [internal functions](/book/contracts#internal-functions) for any kind of contract, and a constant `storageReserve` aimed at advanced users of Tact.
66

7-
<Callout emoji="🚨">
7+
## Constants
88

9-
This page is a stub. [Contributions are welcome!](https://github.com/tact-lang/tact-docs/issues)
9+
### self.storageReserve [#self-storagereserve]
10+
11+
```tact
12+
virtual const storageReserve: Int = 0;
13+
```
14+
15+
Usage example:
16+
17+
```tact
18+
contract AllYourStorageBelongsToUs {
19+
// This would change the behaviour of self.reserve() function,
20+
// causing it to try reserving this amount of nanoToncoins before
21+
// forwarding a message with SendRemainingBalance mode
22+
override const storageReserve = ton("0.1");
23+
}
24+
```
25+
26+
## Functions
27+
28+
### self.reply [#self-reply]
29+
30+
```tact
31+
virtual fun reply(body: Cell?);
32+
```
33+
34+
An alias to calling the [`forward(){:tact}`](#self-forward) function with the following arguments:
35+
36+
```tact
37+
self.forward(sender(), body, true, null);
38+
// ↑ ↑ ↑ ↑
39+
// | | | init: StateInit?
40+
// | | bounce: Bool
41+
// | body: Cell?
42+
// to: Address
43+
```
44+
45+
Usage example:
46+
47+
```tact
48+
// This message can bounce back to us!
49+
self.reply("Beware, this is my reply to you!".asComment());
50+
```
51+
52+
### self.notify [#self-notify]
53+
54+
```tact
55+
virtual fun notify(body: Cell?);
56+
```
57+
58+
An alias to calling the [`forward(){:tact}`](#self-forward) function with the following arguments:
59+
60+
```tact
61+
self.forward(sender(), body, false, null);
62+
// ↑ ↑ ↑ ↑
63+
// | | | init: StateInit?
64+
// | | bounce: Bool
65+
// | body: Cell?
66+
// to: Address
67+
```
68+
69+
Usage example:
70+
71+
```tact
72+
// This message won't bounce!
73+
self.notify("Beware, this is my reply to you!".asComment());
74+
```
75+
76+
### self.forward [#self-forward]
77+
78+
```tact
79+
virtual fun forward(to: Address, body: Cell?, bounce: Bool, init: StateInit?);
80+
```
81+
82+
Sends a bounceable or non-bounceable message to the specified address `to`. Optionally, you may provide a `body` of the message and the [`init` package](/book/expressions#initof).
83+
84+
When [`storageReserve{:tact}`](#self-storagereserve) constant is overwritten to be $> 0$, before sending a message it also tries to reserve the `storageReserve{:tact}` amount of nanoToncoins from the remaining balance before making the send in the [`SendRemainingBalance{:tact}`](https://docs.tact-lang.org/book/message-mode#base-modes) ($128$) mode.
85+
86+
In case reservation attempt fails and in the default case without the attempt, the message is sent with the [`SendRemainingValue{:tact}`](https://docs.tact-lang.org/book/message-mode#base-modes) ($64$) mode instead.
87+
88+
<Callout>
89+
90+
Note, that `self.forward(){:tact}` never sends additional Toncoins on top of what's available on the balance.\
91+
To be able to send more Toncoins with a single message, use the the [`send(){:tact}`](/ref/api-common#send) function.
1092

1193
</Callout>
94+
95+
Usage example:
96+
97+
```tact
98+
import "@stdlib/ownable";
99+
100+
message PayoutOk {
101+
address: Address;
102+
value: Int as coins;
103+
}
104+
105+
contract Payout with Ownable {
106+
completed: Bool;
107+
owner: Address;
108+
109+
init(owner: Address) {
110+
self.owner = owner;
111+
self.completed = false;
112+
}
113+
114+
// ... some actions there ...
115+
116+
// Bounced receiver function, which is called when the specified outgoing message bounces back
117+
bounced(msg: bounced<PayoutOk>) {
118+
// Reset completed flag if our message bounced
119+
self.completed = false;
120+
121+
// Send a notification that the payout failed using the remaining funds for processing this send
122+
self.forward(self.owner, "Payout failed".asComment(), false, null);
123+
}
124+
}
125+
```

0 commit comments

Comments
 (0)