int, intN, coins
- All numeric types are backed by TVM
INT. - Type
intNuses full 257-bit precision, so any integer value fits into it. Overflow occurs only during serialization.
bool
- The
booltype is backed by TVMINTwith value-1or0at runtime. - The unsafe cast
someBool as intis valid and produces-1or0.
address, any_address
- Both
addressandany_addressare backed by TVMSLICEvalues containing raw binary data. - A nullable
address?is represented as either TVMNULLorSLICE. - The unsafe cast
someAddr as sliceis valid and reversible.
cell
- The
celltype is backed by TVMCELL. - The unsafe cast
someCell as Cell<T>is valid.
Cell<T>
- The
Cell<T>type is also backed by TVMCELL. The type parameterTis compile‑time metadata.
slice
- Type
sliceis backed by TVMSLICE.
bitsN
- The
bitsNtype is backed by TVMSLICE. - The unsafe cast
someSlice as bitsNis valid and reversible.
RemainingBitsAndRefs
- The
RemainingBitsAndRefstype is backed TVMSLICE. It is an alias ofslicethat is handled specially during deserialization.
builder
- The
buildertype is backed by TVMBUILDER. Bits written to a builder cannot be read directly. Access to the data is possible only by converting thebuilderto aslice.
struct
Fields of a structure are placed sequentially on the stack. For example, Point occupies two stack slots, and Line occupies four:
Line value, four integers are placed onto the stack:
enum
- Every enum is backed by TVM
INT. Tolk supports integer enums only; for example, not addresses.
Nullable types T?
Primitive nullable types such as int?, address?, and cell? occupy a single stack slot. That slot holds either TVM NULL or the corresponding value.
Point or a tensor (bool, cell), occupy N + 1 stack slots. The last is used for “typeid”.
typeid; for example, 4567 for Point. The typeid is stored in an extra stack slot. The typeid value for null is 0. Expressions such as p == null or p is Point check the typeid slot.
The following structure, when nullable, requires an extra stack slot:
Union types T1 | T2 | ...
Union types are represented as tagged unions on the stack:
- each alternative type is assigned a unique
typeid; e.g., 1234 forint; - the union occupies N+1 stack slots, where N is the maximum size of
T_i; - the(N+1)-th slot contains the
typeidof the current value.
match is implemented as a comparison of the (N+1)-th slot, and passing or assigning a value involves stack rearrangement.
T | null is called nullable and optimized for atomic types: int? uses a single slot. Non-atomics are handled generally, with typeid=0.
Tensors (T1, T2, ...)
Tensor components are placed sequentially on the stack, identical to struct fields. For example, (coins, Point, int?) occupies 4 stack slots: INT (coins), INT (p.x), INT (p.y), INT/NULL.
tuple
- Type
tupleis backed by TVMTUPLEand occupies a single stack slot, regardless of the number of elements; up to 255.
Typed tuple [T1, T2, ...]
A typed tuple is backed by TVM TUPLE. Its structure is known at compile time; at runtime it is an ordinary TVM tuple.
map<K, V>
map<K, V>occupies a single stack slot: either TVMNULLorCELL.- Non-empty maps,
CELL, have a non-trivial bit-level layout.
Callables (...ArgsT) -> ResultT
- A callable and
continuationis backed by TVMCONT.
void, never
- Both represent the absence of a value and occupy zero stack slots. For example, a function with return type
voiddoes not place any value onto the stack.