Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4c86d28
[Tolk] Drop aux "lazy match", keep original ast_match_expression
tolk-vm Aug 14, 2026
9b19930
[Tolk] Drop aux "inMessage.field", keep original ast_dot_obj
tolk-vm Aug 14, 2026
33043c2
[Tolk] Support `@inline` functions with early returns
tolk-vm Aug 14, 2026
0d1bd2d
[Tolk] Preserve user code, don't drop even `@pure` calls
tolk-vm Aug 6, 2026
e6aeaef
[Tolk] Fix several bugs found by LLM
tolk-vm Aug 5, 2026
4e79c8b
[Tolk] Type aliases become directional subtypes
tolk-vm Aug 8, 2026
69b517e
[Tolk] Drop warnings emission from compiler
tolk-vm Aug 9, 2026
bcf5e5b
[Tolk] Get methods without body, for ABI only
tolk-vm Aug 10, 2026
48b934b
[Tolk] Drop `optimization_level` option, no way to disable peephole
tolk-vm Aug 10, 2026
c266030
[Tolk] Cache line_offsets in `SrcFile` for fift output
tolk-vm Aug 10, 2026
50f4eef
[Tolk] Deprecate function `ton` in favor of `grams`
tolk-vm Aug 10, 2026
a81a71d
[Tolk] Drop aux "lazy load vertices", build LazyLoadPlan
tolk-vm Aug 14, 2026
f343cb4
[Tolk] Support break/continue in loops
tolk-vm Aug 17, 2026
3c816ef
[Tolk] Move AST-level stmt_before_immediate_return to IR level
tolk-vm Aug 18, 2026
c9dab0d
[Tolk] Support secondary locations in compilation errors
tolk-vm Aug 19, 2026
c75f25b
[Tolk] Colorful compilation errors
tolk-vm Aug 20, 2026
76e0415
[Tolk] Refactor: rework built-ins, attach implementations to stdlib
tolk-vm Aug 6, 2026
489a7f9
[Tolk] Drop type `bytesN`, leave only `bitsN`
tolk-vm Aug 26, 2026
eb0633c
[Tolk] Fire an error on duplicate `enum` values
tolk-vm Aug 26, 2026
6de2b89
[Tolk] Calculate `requires_callxargs` on AST basis, not at codegen
tolk-vm Aug 21, 2026
950c424
[Tolk] Support `lazy f()` where f has only one trailing return
tolk-vm Aug 28, 2026
cb906ab
[Tolk] Bump version to v1.5
tolk-vm Sep 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 50 additions & 58 deletions crypto/smartcont/tolk-stdlib/common.tolk

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions crypto/smartcont/tolk-stdlib/exotic-cells.tolk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A part of standard library for Tolk
tolk 1.4.2
tolk 1.5

enum ExoticCellType: int8 {
Ordinary = -1
Expand Down Expand Up @@ -46,7 +46,6 @@ fun cell.loadSpecial(self): cell

/// Transforms an ordinary or exotic cell into a library reference
/// (into an exotic cell with contents "8 bits cell type" + "256 bits lib hash").
@pure
fun cell.toLibraryReference(self): cell {
return beginCell()
.storeInt(ExoticCellType.LibraryReference, 8)
Expand Down
2 changes: 1 addition & 1 deletion crypto/smartcont/tolk-stdlib/gas-payments.tolk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A part of standard library for Tolk
tolk 1.4.2
tolk 1.5

/**
Gas and payment related primitives.
Expand Down
12 changes: 3 additions & 9 deletions crypto/smartcont/tolk-stdlib/lisp-lists.tolk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A part of standard library for Tolk
tolk 1.4.2
tolk 1.5

/**
A lisp-style list is a set of nested 2-element TVM tuples:
Expand All @@ -21,15 +21,13 @@ tolk 1.4.2
```
*/

@pure
fun lisp_list<T>.isEmpty(self): bool {
return self.tvmTuple == null
}

/// Inserts an element an the front.
/// Before: `[a b c]`.
/// After: `[new a b c]`.
@pure
fun lisp_list<T>.prependHead(mutate self, value: T): void {
self.tvmTuple = [value, self.tvmTuple as unknown as lisp_list<T>];
}
Expand All @@ -38,7 +36,6 @@ fun lisp_list<T>.prependHead(mutate self, value: T): void {
/// Before: `[a b c]`.
/// After: `[b c]`, returns `a`.
/// Throws an exceptions if a list is empty.
@pure
fun lisp_list<T>.popHead(mutate self): T {
var [head, tail] = self.tvmTuple!;
self.tvmTuple = tail as unknown as [T, lisp_list<T>]?;
Expand All @@ -47,21 +44,18 @@ fun lisp_list<T>.popHead(mutate self): T {

/// Returns an element from the front: `a` for `[a b c]`.
/// Throws an exceptions if a list is empty.
@pure
fun lisp_list<T>.getHead(self): T {
return self.tvmTuple!.0
}

/// Returns all but the frontmost element: `[b c]` for `[a b c]`.
/// Throws an exceptions if a list is empty.
@pure
fun lisp_list<T>.getTail(self): lisp_list<T> {
return self.tvmTuple!.1
}

/// Calculates the size of a list by looping all the elements (there is no other way to do it).
/// The longer the list — the more gas consumption (O(N) complexity).
@pure
fun lisp_list<T>.calculateSize(self): int {
var size = 0;
var ptr = self;
Expand All @@ -74,7 +68,6 @@ fun lisp_list<T>.calculateSize(self): int {

/// Returns the list with elements in reversed order.
/// Given `[a b c]` returns `[c b a]`.
@pure
fun lisp_list<T>.calculateReversed(self): lisp_list<T> {
var reversed = [] as lisp_list<T>;
var ptr = self;
Expand All @@ -86,7 +79,6 @@ fun lisp_list<T>.calculateReversed(self): lisp_list<T> {

/// Returns the concatenation of two lists.
/// Given `[a b]` and `[c d]`, returns `[a b c d]`.
@pure
fun lisp_list<T>.calculateConcatenation(self, other: lisp_list<T>): lisp_list<T> {
var reversed = [] as lisp_list<T>;
var ptr = self;
Expand Down Expand Up @@ -118,6 +110,7 @@ fun createEmptyList<T>(): lisp_list<T>
/// `lisp_list<T>` can be serialized if `T` is serializable. It's encoded as reversed snake refs:
/// A list `[1 2 3]` (on a stack: `[1 [2 [3 null]]]`) is "3.ref(2.ref(1.ref(empty cell)))".
/// An empty list `[]` (on a stack: `null`) is "empty cell"
@inline
fun lisp_list<T>.packToBuilder(self, mutate b: builder): void {
var tail = createEmptyCell();
var ptr = self;
Expand All @@ -129,6 +122,7 @@ fun lisp_list<T>.packToBuilder(self, mutate b: builder): void {

/// Unserialize `lisp_list<T>` from snake refs:
/// From "3.ref(2.ref(1.ref(empty cell)))" get a list `[1 2 3]` (on a stack: `[1 [2 [3 null]]]`).
@inline
fun lisp_list<T>.unpackFromSlice(mutate s: slice): lisp_list<T> {
var result = [] as lisp_list<T>;
var head = s.loadRef().beginParse();
Expand Down
2 changes: 1 addition & 1 deletion crypto/smartcont/tolk-stdlib/reflection.tolk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A part of standard library for Tolk
tolk 1.4.2
tolk 1.5

/**
Reflection API.
Expand Down
5 changes: 1 addition & 4 deletions crypto/smartcont/tolk-stdlib/strings.tolk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A part of standard library for Tolk
tolk 1.4.2
tolk 1.5

/**
A string is a language primitive — a cell containing snake-formatted text data.
Expand All @@ -21,7 +21,6 @@ fun string.depth(self): int

/// Calculates length of a string in bytes (not unicode symbols, just bytes).
/// Since strings are stored in snake format (chain of cells), this requires traversing all cells.
@pure
@inline_ref
fun string.calculateLength(self): int {
var bits = 0;
Expand All @@ -38,7 +37,6 @@ fun string.calculateLength(self): int {
/// The hash is the same regardless of snake layout:
/// "abcd", "ab" + (ref "cd"), "a" + (ref "bcd" + (ref "")) all produce the same hash.
/// Uses FNV-1a hashing with standard 128-bit parameters.
@pure
@inline_ref
fun string.hash(self): uint256 {
val FNV_PRIME = 309485009821345068724781371;
Expand All @@ -59,7 +57,6 @@ fun string.hash(self): uint256 {

/// Compares two strings, considering snake cells.
/// For example, "abcd" is equal to "ab" + (ref "cd") is equal to "a" + (ref "bc" + (ref "d")).
@pure
fun string.equalTo(self, another: string): bool {
return self.depth() + another.depth() != 0
// some is snake, so we have "ab->cd" / "a->bc->d" / etc., do full traverse
Expand Down
2 changes: 1 addition & 1 deletion crypto/smartcont/tolk-stdlib/tvm-dicts.tolk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A part of standard library for Tolk
tolk 1.4.2
tolk 1.5

/**
Low-level API working with TVM dictionaries.
Expand Down
2 changes: 1 addition & 1 deletion crypto/smartcont/tolk-stdlib/tvm-lowlevel.tolk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A part of standard library for Tolk
tolk 1.4.2
tolk 1.5

/// Usually `c3` has a continuation initialized by the whole code of the contract. It is used for function calls.
/// The primitive returns the current value of `c3`.
Expand Down
47 changes: 47 additions & 0 deletions tolk-tester/tests/abi-tests.tolk
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ struct Defaults {
a: int = C
}

struct CalcSwapCostReply {
from: address
to: address
cost: coins
}

get fun calc_swap_cost(from: address): CalcSwapCostReply

/// @param precision number of decimal places
get fun pool_reserves(precision: uint8 = 9): (coins, coins);

/**
@testcase | 0 | 7 5 | 12

Expand Down Expand Up @@ -389,6 +400,42 @@ struct Defaults {
]
"""

@abi_json
"""
"name": "calc_swap_cost",
"parameters": [
{
"name": "from",
...
"""

@abi_json
"""
"name": "pool_reserves",
"parameters": [
{
"name": "precision",
...
"description": "number of decimal places",
"default_value": {
"kind": "int",
"v": "9"
}
}
],
"""

@abi_json
"""
"kind": "struct",
"name": "CalcSwapCostReply",
"""

@fif_codegen_avoid 86806 DECLMETHOD calc_swap_cost()
@fif_codegen_avoid 108535 DECLMETHOD pool_reserves()

@cmd_line_option --allow-empty-get-fun

@abi_json_avoid UnusedOutgoing
@abi_json_avoid ERR_UNUSED_ABI
*/
4 changes: 2 additions & 2 deletions tolk-tester/tests/arrays-tuples-tests.tolk
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fun test101() {

__expect_type((rand != 0 ? [1,2] : [3, null]) as array<int?>, "array<int?>");
__expect_type(rand != 0 ? [""] : [] as array<string>, "array<string>");
__expect_type(rand != 0 ? [] : [""] as tuple, "array<unknown>");
__expect_type(rand != 0 ? [] : [""] as tuple as array<unknown>, "array<unknown>");

__expect_type(array<int> [], "array<int>");
__expect_type(tuple [1, "aba", []], "tuple");
Expand All @@ -144,7 +144,7 @@ fun test101() {

__expect_type((rand != 0 ? array<int?> [1,2] : array<int?> [3, null]), "array<int?>");
__expect_type(rand != 0 ? [""] : array<string> [], "array<string>");
__expect_type(rand != 0 ? [] : tuple [""], "array<unknown>");
__expect_type(rand != 0 ? [] : array<unknown> [""], "array<unknown>");

t1.push(123);
t2.push(456);
Expand Down
7 changes: 3 additions & 4 deletions tolk-tester/tests/asm-arg-order.tolk
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ fun asmAPlus1TimesB(a: int, b: int): int
fun int.plus1TimesB(self, b: int): int
asm(b self) "1 ADDCONST MUL";

@pure
@noinline
fun get2Pure() { return 2; }
@pure
@noinline
fun get10Pure() { return 10; }

Expand Down Expand Up @@ -270,8 +268,9 @@ fun main() {
@fif_codegen
"""
test28() PROC:<{
get10Pure() CALLDICT
get2Pure() CALLDICT
get10Pure() CALLDICT
SWAP
1 ADDCONST MUL
}>
"""
Expand Down Expand Up @@ -316,5 +315,5 @@ fun main() {
}>
"""

@code_hash 98112237312599117361360505207413290833928615253348061305894339367683016107491
@code_hash 34599016008274478064245614023722066100591789877753712714557731858383043392662
*/
Loading
Loading