TGViewer
TOLK lang TOLK lang @tolk_lang Β· 847 subscribers
Post #32 414
🫧 Tolk v1.5: break/continue in loops, smarter compiler, and the road to v2.0

This release is not about one big feature.

It's about removing a lot of small restrictions left in the language because the compiler simply wasn't ready for them yet. Subtle, sometimes artificial, mostly unnoticeable β€” while the compiler underneath is getting more mature and complicated.

βœ… Notable changes in Tolk v1.5:

1. break/continue in loops β€” finally for TVM
2. @inline functions with multiple returns
3. Type aliases as directional subtypes
4. Reorganized purity concept and dead-code removal
5. Colorful compilation errors with multiple locations and hints
6. Preparing the kernel for Tolk v2.0

PR on GitHub with detailed info.

βœ” break/continue in loops

Looks and feels as expected:


while (true) {
val ch = bytes.loadUint(8);
if (ch == 0) {
break;
}
if (blacklisted.exists(ch)) {
continue;
}
bits += 8;
}


Both work in all loops, including nested ones. The compiler correctly tracks control-flow rejoins, stack layout, and other low-level details.

The most interesting part: break is SIMPLER than continue. TVM has machinery with RETALT in loop continuations, but provides nothing to emulate continue.

Instead, continue is implemented like another feature that seems to have nothing in common at first glance:

βœ” Inline with early/multiple returns

Since Tolk v1.0, the compiler supported auto-inlining simple functions, but capitulated on early returns:


// not inlined earlier
// inlined since Tolk v1.5
fun checkPositive(x: int) {
if (x <= 0) {
return; // this prevented inlining
}
...
}


Why? Because inlining returns-in-the-middle is hard. Even C++ compilers used to struggle with it.

The algorithm I developed transforms a function into if-else chains:


fun demo() {
if (cond1) { return }
if (cond2) { xxx; return }
else { yyy }
zzz
}


gets translated to


fun demo() {
if (cond1) { }
else { if (cond2) { xxx }
else { yyy; zzz } }
}


And now the surprise: not fun+return, but loop+continue β€” works exactly the same way!


loop {
if (cond1) { continue }
if (cond2) { xxx; continue }
else { yyy }
zzz
}


gets translated to :)


loop {
if (cond1) { }
else { if (cond2) { xxx }
else { yyy; zzz } }
}


βœ” Much better compilation errors

Errors can now point to multiple locations at once β€” the call site, declaration, type mismatch, inlining failure, and so on.

The compiler explains not only where something went wrong, but also why and what actions should be taken.


error: too many arguments in call to `calcSum`, expected 2, have 3
--> /some/file.tolk:6:30
| in function main
|
6 | return calcSum(100, 200, 300);
| ^^^

note: function declared here
--> /some/file.tolk:1:5
|
1 | fun calcSum(x: int, y: int) {
| ^^^^^^^


And they are now colorful!

βœ” A more predictable and mature compiler

Bug bounty hunters sent over 200+ tickets, which look lots of my time to analyze β€” only to turn out to be non-issues.

As a result, I had to reconsider some deep questions:
- directional subtypes in the type system
- user-written code removal by the optimizer
- purity concept and @pure keyword

You can read more in a traditionally detailed PR.

βš™οΈ Preparing for Tolk v2.0

This summer, I experimented with a new compiler backend (for Tolk v2.0). That backend will fully replace the old FunC kernel still living with us, and eliminate the need of Fift.

These experiments exposed a lot of places where the current compiler is still shaped around the old architecture.

🌳 Tolk v1.5 has removed most of this historical baggage. It was purely internal work β€” not affecting how you use Tolk today. But it's the part I like the most. It opens the road to Tolk v2.0: a new backend, a new assembler, and direct bytecode generation. This is what I am starting to work on now.
  • πŸ”₯ 11
  • 😱 5
  • πŸ‘ 3
  • ❀‍πŸ”₯ 2
  • πŸ“ 2
More from @tolk_lang
  1. Sep 23, 2026🫧 Introducing new tools beyond smart-contract development In May, we released Tolk v1.4 a…
  2. Jun 23, 2026🫧 Tolk v1.4.x: internal progress and maintenance Since the v1.4 release we've published T…
  3. May 11, 2026🫧 TON enters a new era of smart-contract development I promised this would happen in May.…
  4. Mar 27, 2026🫧 Tolk v1.3: moving toward a general-purpose language After the previous post, this relea…
  5. Mar 19, 2026🫧 Tolk v1.3... not released yet: what's happening inside I know it has been quiet. The la…
  6. Dec 5, 2025🫧 Tolk documentation β€” now complete and available for learning from scratch From now on,…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook β†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 β†’