T
TOLK lang
@tolk_lang
19.09.2025 09:12
🫧 Tolk v1.1: built-in map<K,V>, enums, private and readonly fields, method overloads

Two months have passed — maybe you even started to worry about the silence. The reason is simple: I worked on features that are "nice to have" but complex and time-consuming to implement — and they've only just been finished.

✅ Notable changes in Tolk v1.1:

1. map<K, V> — a convenient zero-overhead wrapper over TVM dictionaries
2. enum — group numeric constants into a distinct type
3. private and readonly fields in structures
4. Overload resolution and partial specialization

PR on GitHub with detailed info.

✔ Built-in maps

Forget about uDictSetBuilder, sDictGetFirstAsRef, and the endless boilerplate of low-level dict helpers. A universal map<K, V> now fully replaces them.


var m: map<int8, int32> = createEmptyMap();
m.set(1, 10);
m.addIfNotExists(9, -90);
m.delete(9); // now: [ 1 => 10 ]
m.exists(1); // true
m.isEmpty(); // false


Just m.get() — no need to care about cells and slices under the hood:

val r = m.get(1);
if (r.isFound) { // true
val v = r.loadValue(); // 10
}

// or if the key 100% exists
val v = m.mustGet(1); // 10


Easily iterate forward and backward:

var r = m.findFirst();
while (r.isFound) {
// use r.getKey() and r.loadValue()
r = m.iterateNext(r);
}


Any serializable keys and values — it just works:

map<address, Point>
map<Point, Cell<Extra>>
map<int32, map<int64, bool>>
...


All in all:
- self-explanatory methods, nicely suggested by IDEs
- DICTISETREF, DICTREPLACE, DICTUREPLACEGET, ... — 100+ asm instructions covered by the type system
- all deserialization to/from cells perfectly hidden by high-level API
- absolutely zero overhead compared to low-level TVM dictionaries

✔ Enums

A long-awaited syntax feature for grouping constants.


// will be 0 1 2
enum Color {
Red
Green
Blue
}


Being integers at runtime, enums have their own place in the type system. They resemble TypeScript/C++ enums. (Unlike Rust, where each variant may have its own shape. In Tolk we have union types — a more powerful solution)


struct Gradient {
from: Color
to: Color? = null
}

var g: Gradient = { from: Color.Blue };
g.from == Color.Red; // false


Compatible with all language features: auto-serialization, exhaustive pattern matching, generics, etc.

✔ Private and readonly fields

Fields can now have modifiers:
* private — accessible only within methods
* readonly — immutable after object creation


struct PosInTuple {
private readonly t: tuple
curIndex: int
}

fun PosInTuple.last(mutate self) {
// `t` is visible only in methods
// and cannot be modified
self.curIndex = self.t.size() - 1;
}


✔ Partial specialization

Now it's possible to overload methods for "more specific" implementations:


// general implementation
fun Iterator<T>.next(self) { ... }

// a more specific one
fun Iterator<Cell<T>>.next(self) { ... }


In complex scenarios, this feature lets you adjust the behavior of specific types while keeping a common interface. It "just works", but internally the compiler was enhanced with shape of types, structural depth, type dominators, and several heuristics.

🌳 After Tolk v1.0 release, many people and companies started migrating from FunC to Tolk. I have received a lot of feedback and requests (and almost zero bug reports, huh). Meanwhile, a bigger roadmap is already in motion. In the near future I'll also try to close long-standing questions around TypeScript wrappers, and deliver proper from-scratch documentation.
🔥 22
10
👏 5
❤‍🔥 3
23 4.5K

Обсуждение 0

Обсуждение не доступно в веб-версии. Чтобы написать комментарий, перейдите в приложение Telegram.

Обсудить в Telegram
T

TOLK lang

844
Channel devoted to TOLK — "next-generation FunC" — a language for writing smart contracts in TON
Открыть в Telegram