Skip to main content
Tolk is more similar to TypeScript and Kotlin than to C or Lisp. It provides complete control over the TVM assembler, as it includes a FunC kernel within.

Declarations

  • fun declares a function.
  • get fun declares a get method.
  • var declares a variable.
  • val declares an immutable variable.
Types are written on the right. Parameter types are required; return and local variable types are inferred automatically. Specifiers such as inline_ref are written as @ attributes.
global storedV: int;

fun parseData(cs: slice): cell {
    var flags: int = cs.loadMessageFlags();
    // …
}

@inline
fun sum(a: int, b: int) {   // auto inferred int
    val both = a + b;       // same
    return both;
}

get fun currentCounter(): int { ... }

Syntax and semantics

  • No impure. All functions are treated as impure by default; the compiler does not remove user function calls.
  • Use onInternalMessage, onExternalMessage, and onBouncedMessage instead of recv_internal and recv_external.
  • 2+2 is 4, not an identifier. Identifiers are alphanumeric. Use const OP_INCREASE instead of const op::increase. cell and slice are valid identifiers; not keywords.
  • Logical operators AND &&, OR ||, NOT ! are supported.

Syntax improvements

  • ;; comment// comment
  • {- comment -}/* comment */
  • #includeimport; strict rule: import only what is used
  • ~ found!found; used for boolean values only (true is -1, as in FunC)
  • v = null()v = null
  • null?(v)v == null, similar for builder_null? and others
  • ~ null?(v)c != null
  • throw(excNo)throw excNo
  • catch(_, _)catch
  • catch(_, excNo)catch(excNo)
  • throw_unless(excNo, cond)assert(cond, excNo)
  • throw_if(excNo, cond)assert(!cond, excNo)
  • return ()return
  • do ... until (cond)do ... while (!cond)
  • elseifelse if
  • ifnot (cond)if (!cond)
  • "..."cstringCrc32("...") and other postfixes

Compilation model

  • Functions can be called before declaration.
  • Forward declarations are not required.
  • The compiler first parses and then resolves symbols, producing an AST representation of the source code.

Standard library

  • Standard library functions use clear, camelCase names.
  • The stdlib is embedded and split into multiple files.
  • Common functions are available; specialized ones can be imported. For example, import "@stdlib/tvm-dicts".
  • IDEs provide import suggestions.
  • See the FunC-Tolk stdlib mapping.

Language features

  • No ~ tilde methods. See mutability details.
  • Type mismatch errors are clear and readable.
  • The bool type is supported.
  • Indexed access tensorVar.0 and tupleVar.0 is supported.
  • Nullable types T?, null safety, smart casts, and the operator ! are supported.
  • Union types and pattern matching are supported for types and expressions, with switch-like behavior.
  • Type aliases are supported.
  • Structures are supported.
  • Generics are supported.
  • Methods as extension functions are supported.
  • Enums are supported.
  • Trailing comma is supported.
  • A semicolon after the last statement in a block is optional.
  • Fift output contains original .tolk lines as comments.
  • Auto-packing to and from cells is supported for all types.
  • Universal createMessage simplifies cell composition.
  • map<K, V> instead of low-level TVM dictionaries.
  • The compiler automatically detects and inlines functions.
  • Includes gas optimization improvements.

Tooling around

Gas benchmarks

The Tolk-bench repository contains contracts migrated from FunC to Tolk, with identical logic and passing the same tests.