Skip to content

Commit

Permalink
feat: support Tact 1.5.0 (#24)
Browse files Browse the repository at this point in the history
* feat: `asm` functions

* feat: `uint1-256` and `int1-257`

Without completions for those for now, since doing it naively would
introduce 500+ entries into the completions list, with each entry taking
6 lines. I'll take a look into using some Python code as part of the
plugin and Sublime APIs.

* feat: new builtin (comptime) and stdlib functions

* fix: tests and extra constant
  • Loading branch information
novusnota authored Sep 16, 2024
1 parent 440f907 commit 3b63bdf
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 8 deletions.
102 changes: 101 additions & 1 deletion package/Tact.sublime-completions
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"kind": ["function", "a", "Attribute"],
"details": "<a href=\"https://docs.tact-lang.org/book/contracts#interfaces\">Tact Docs</a>"
},
{
"trigger": "asm\tasm with optional arrangement (...)",
"contents": "asm $0",
"kind": ["function", "a", "Attribute"]
},

// Literals, Base trait and constants
{
Expand Down Expand Up @@ -100,6 +105,11 @@
"kind": ["variable", "c", "Constant"],
"details": "<a href=\"https://docs.tact-lang.org/book/message-mode#optional-flags\">Tact Docs</a>"
},
{
"trigger": "SendOnlyEstimateFee\tequal to 1024",
"contents": "SendOnlyEstimateFee",
"kind": ["variable", "c", "Constant"]
},
{
"trigger": "ReserveExact\tequal to 0",
"contents": "ReserveExact",
Expand Down Expand Up @@ -150,6 +160,16 @@
"kind": ["variable", "s", "Struct"],
"details": "<a href=\"https://docs.tact-lang.org/book/expressions#initof\">Tact Docs</a>"
},
{
"trigger": "StdAddress",
"contents": "StdAddress",
"kind": ["variable", "s", "Struct"]
},
{
"trigger": "VarAddress",
"contents": "VarAddress",
"kind": ["variable", "s", "Struct"]
},

// Built-in types and serialization options
{
Expand Down Expand Up @@ -607,6 +627,26 @@
"kind": "function",
"details": "<a href=\"https://docs.tact-lang.org/ref/core-comptime#ton\">Tact Docs</a>"
},
{
"trigger": "slice\tSlice from a BoC String at compile-time",
"contents": "slice(${1:bocBase64String})",
"kind": "function"
},
{
"trigger": "rawSlice\tSlice from a String at compile-time",
"contents": "rawSlice(${1:someString})",
"kind": "function"
},
{
"trigger": "ascii\tInt sum of ASCII values at compile-time",
"contents": "aslii(${1:asciiString})",
"kind": "function"
},
{
"trigger": "crc32\tCRC32 of a String at compile-time",
"contents": "crc32(${1:someString})",
"kind": "function"
},

// Core library: Debug
{
Expand Down Expand Up @@ -651,6 +691,16 @@
"kind": "function",
"details": "<a href=\"https://docs.tact-lang.org/ref/core-debug#nativethrowunless\">Tact Docs</a>"
},
{
"trigger": "parseStdAddress\tparse StdAddress from a Slice",
"contents": "parseStdAddress(${1:slice_Slice})",
"kind": "function"
},
{
"trigger": "parseVarAddress\tparse VarAddress from a Slice",
"contents": "parseVarAddress(${1:slice_Slice})",
"kind": "function"
},

// Core library: Random
{
Expand Down Expand Up @@ -823,11 +873,61 @@
"kind": "function",
"details": "<a href=\"https://docs.tact-lang.org/ref/core-advanced#nativesendmessage\">Tact Docs</a>"
},
{
"trigger": "nativeSendMessageReturnForwardFee\tsend message Cell with mode Int and get fees",
"contents": "nativeSendMessageReturnForwardFee(${1:cell}, ${2:mode_Int})",
"kind": "function"
},
{
"trigger": "nativeReserve\treserve nanoToncoin amount Int with mode Int",
"contents": "nativeReserve(${1:amount_Int}, ${2:mode_Int})",
"kind": "function",
"details": "<a href=\"https://docs.tact-lang.org/ref/core-advanced#nativereserve\">Tact Docs</a>"
}
},
{
"trigger": "nativeReserve\treserve nanoToncoin amount Int with mode Int",
"contents": "nativeReserve(${1:amount_Int}, ${2:mode_Int})",
"kind": "function"
},
{
"trigger": "gasConsumed\tget gas consumed so far",
"contents": "gasConsumed()",
"kind": "function"
},
{
"trigger": "getComputeFee\tcalc compute cost in nanoToncoins",
"contents": "getComputeFee(${1:gas_used_Int, ${2:is_masterchain_Bool})",
"kind": "function"
},
{
"trigger": "getStorageFee\tcalc storage fees in nanoToncoins",
"contents": "getStorageFee(${1:cells_Int, ${2:bits_Int}, ${3:seconds_Int}, ${4:is_masterchain_Bool})",
"kind": "function"
},
{
"trigger": "getForwardFee\tcalc forward fees in nanoToncoins",
"contents": "getForwardFee(${1:cells_Int, ${2:bits_Int}, ${3:is_masterchain_Bool})",
"kind": "function"
},
{
"trigger": "getSimpleComputeFee\tcalc extra compute cost in nanoToncoins",
"contents": "getSimpleComputeFee(${1:gas_used_Int, ${2:is_masterchain_Bool})",
"kind": "function"
},
{
"trigger": "getSimpleForwardFee\tcalc extra forward fees in nanoToncoins",
"contents": "getSimpleForwardFee(${1:cells_Int, ${2:bits_Int}, ${3:is_masterchain_Bool})",
"kind": "function"
},
{
"trigger": "getOriginalFwdFee\tcalc original fwd_fee in nanoToncoins",
"contents": "getOriginalFwdFee(${1:fwd_fee_Int, ${2:is_masterchain_Bool})",
"kind": "function"
},
{
"trigger": "myStorageDue\tstorage fee debt in nanoToncoins",
"contents": "myStorageDue(${1:fwd_fee_Int, ${2:is_masterchain_Bool})",
"kind": "function"
},
]
}
56 changes: 52 additions & 4 deletions package/Tact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,59 @@
</dict>
</dict>
</dict>
<dict>
<key>comment</key>
<string>Asm arrangements</string>
<key>begin</key>
<string>(?&lt;!\.)(asm)\s*(\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.other.attribute-name.tact</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.brackets.round.tact</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#variable</string>
</dict>
<dict>
<key>match</key>
<string>-&gt;</string>
<key>name</key>
<string>keyword.operator.mapsto.tact</string>
</dict>
<dict>
<key>match</key>
<string>\b([0-9]*)\b</string>
<key>name</key>
<string>constant.numeric.decimal.tact</string>
</dict>
</array>
<key>end</key>
<string>\)</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.brackets.round.tact</string>
</dict>
</dict>
</dict>
<dict>
<key>comment</key>
<string>Fallback match</string>
<key>match</key>
<string>(?&lt;!\.)\b(@name|@interface)\b</string>
<string>(?&lt;!\.)\b(@name|@interface|asm)\b</string>
<key>name</key>
<string>entity.other.attribute-name.tact</string>
</dict>
Expand Down Expand Up @@ -394,7 +442,7 @@
<key>comment</key>
<string>Other constants from the core library</string>
<key>match</key>
<string>(?&lt;!\.)\b(SendRemainingValue|SendRemainingBalance|SendPayGasSeparately|SendIgnoreErrors|SendBounceIfActionFail|SendDestroyIfZero|ReserveExact|ReserveAllExcept|ReserveAtMost|ReserveAddOriginalBalance|ReserveInvertSign|ReserveBounceIfActionFail)\b</string>
<string>(?&lt;!\.)\b(SendRemainingValue|SendRemainingBalance|SendPayGasSeparately|SendIgnoreErrors|SendBounceIfActionFail|SendDestroyIfZero|SendOnlyEstimateFee|ReserveExact|ReserveAllExcept|ReserveAtMost|ReserveAddOriginalBalance|ReserveInvertSign|ReserveBounceIfActionFail)\b</string>
<key>name</key>
<string>constant.other.builtin.tact</string>
</dict>
Expand Down Expand Up @@ -559,7 +607,7 @@
<array>
<dict>
<key>match</key>
<string>(?&lt;!\.)\b(as)\s+([a-zA-Z_][a-zA-Z0-9_]*)\b</string>
<string>(?&lt;!\.)\b(as)\s+(coins|remaining|bytes32|bytes64|int257|u?int(?:2[0-5][0-6]|1[0-9][0-9]|[1-9][0-9]?))\b</string>
<key>captures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -871,4 +919,4 @@
</dict>
</dict>
</dict>
</plist>
</plist>
37 changes: 34 additions & 3 deletions package/Tact.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,40 @@
}
}
},
{
"comment": "Asm arrangements",
"begin": "(?<!\\.)(asm)\\s*(\\()",
"beginCaptures": {
"1": {
"name": "entity.other.attribute-name.tact"
},
"2": {
"name": "punctuation.brackets.round.tact"
}
},
"patterns": [
{
"include": "#variable"
},
{
"match": "->",
"name": "keyword.operator.mapsto.tact"
},
{
"match": "\\b([0-9]*)\\b",
"name": "constant.numeric.decimal.tact"
}
],
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.brackets.round.tact"
}
}
},
{
"comment": "Fallback match",
"match": "(?<!\\.)\\b(@name|@interface)\\b",
"match": "(?<!\\.)\\b(@name|@interface|asm)\\b",
"name": "entity.other.attribute-name.tact"
}
]
Expand Down Expand Up @@ -256,7 +287,7 @@
},
{
"comment": "Other constants from the core library",
"match": "(?<!\\.)\\b(SendRemainingValue|SendRemainingBalance|SendPayGasSeparately|SendIgnoreErrors|SendBounceIfActionFail|SendDestroyIfZero|ReserveExact|ReserveAllExcept|ReserveAtMost|ReserveAddOriginalBalance|ReserveInvertSign|ReserveBounceIfActionFail)\\b",
"match": "(?<!\\.)\\b(SendRemainingValue|SendRemainingBalance|SendPayGasSeparately|SendIgnoreErrors|SendBounceIfActionFail|SendDestroyIfZero|SendOnlyEstimateFee|ReserveExact|ReserveAllExcept|ReserveAtMost|ReserveAddOriginalBalance|ReserveInvertSign|ReserveBounceIfActionFail)\\b",
"name": "constant.other.builtin.tact"
},
{
Expand Down Expand Up @@ -365,7 +396,7 @@
"comment": "Serialization",
"patterns": [
{
"match": "(?<!\\.)\\b(as)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b",
"match": "(?<!\\.)\\b(as)\\s+(coins|remaining|bytes32|bytes64|int257|u?int(?:2[0-5][0-6]|1[0-9][0-9]|[1-9][0-9]?))\\b",
"captures": {
"1": {
"name": "keyword.other.as.tact storage.modifier.tact"
Expand Down
2 changes: 2 additions & 0 deletions tests/syntax_test_const.tact
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ fun builtin() {
// <- constant.other.builtin.tact
SendDestroyIfZero;
// <- constant.other.builtin.tact
SendOnlyEstimateFee;
// <- constant.other.builtin.tact

ReserveExact;
// <- constant.other.builtin.tact
Expand Down
20 changes: 20 additions & 0 deletions tests/syntax_test_native.tact
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,23 @@ extends mutates native loadInt(self: Slice, l: Int, ): Int;
// ^ punctuation.colon.tact
// ^^^ entity.name.type.tact
// ^ punctuation.semi.tact

asm fun increase(): Int { INC }
// <- entity.other.attribute-name.tact
// ^^^ keyword.other.function.tact
// ^^^^^^^^ entity.name.function.tact
// ^^ punctuation.brackets.round.tact
// ^ punctuation.colon.tact
// ^^^ entity.name.type.tact
// ^ punctuation.brackets.curly.tact
// ^^^ constant.other.caps.tact
// ^ punctuation.brackets.curly.tact

asm(second first -> 0) fun addTwo(first: Int, second: Int): Int { SOMETHING SOMETHING }
// <- entity.other.attribute-name.tact
// ^ punctuation.brackets.round.tact
// ^^^^^^ variable.other.tact
// ^^^^^ variable.other.tact
// ^^ keyword.operator.mapsto.tact
// ^ constant.numeric.decimal.tact
// ^ punctuation.brackets.round.tact
36 changes: 36 additions & 0 deletions tests/syntax_test_struct.tact
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,39 @@ fun TestStruct() {
// ^ punctuation.brackets.curly.tact
// ^ punctuation.semi.tact
}

struct Serialization {
f1: Int as uint1;
// ^^^^^ entity.name.type.tact
f2: Int as int1;
// ^^^^ entity.name.type.tact
f3: Int as uint10;
// ^^^^^^ entity.name.type.tact
f4: Int as int10;
// ^^^^^ entity.name.type.tact
f5: Int as uint100;
// ^^^^^^^ entity.name.type.tact
f6: Int as int100;
// ^^^^^^ entity.name.type.tact
f7: Int as uint200;
// ^^^^^^^ entity.name.type.tact
f8: Int as int200;
// ^^^^^^ entity.name.type.tact
f9: Int as uint256;
// ^^^^^^^ entity.name.type.tact
f10: Int as int257;
// ^^^^^^ entity.name.type.tact
f9wrong: Int as uint257;
// ^^^^^^^ variable.other.tact
f10wrong: Int as int258;
// ^^^^^^ variable.other.tact

b32: Slice as bytes32;
// ^^^^^^^ entity.name.type.tact
b64: Slice as bytes64;
// ^^^^^^^ entity.name.type.tact
coin: Int as coins;
// ^^^^^ entity.name.type.tact
payload: Slice as remaining;
// ^^^^^^^^^ entity.name.type.tact
}

0 comments on commit 3b63bdf

Please sign in to comment.