A new version of Tolk was released several days ago. We're starting a way to eventually implement structures with auto packing to/from cells. This will take several steps (each publicly released), it's the first one.
✅ Notable changes in Tolk v0.8:
1. Syntax
tensorVar.0 and tupleVar.0, both for reading and writing2. Allow
cell, slice, etc. to be valid identifiersPR on GitHub with detailed info.
Using syntax `tensorVar.{i}` and `tupleVar.{i}`, you can access tensors/tuples by indices without unpacking them.
It works for tensors:
var t = (5, someSlice, someBuilder); // 3 stack slots
t.0 // 5
t.0 = 10; // t is now (10, ...)
t.0 += 1; // t is now (11, ...)
increment(mutate t.0); // t is now (12, ...)
t.0.increment(); // t is now (13, ...)
t.1 // slice
t.100500 // compilation error
It works for tuples (does asm INDEX/SETINDEX under the hood):
var t = [5, someSlice, someBuilder]; // 1 tuple on a stack with 3 items
t.0 // "0 INDEX", reads 5
t.0 = 10; // "0 SETINDEX", t is now [10, ...]
t.0 += 1; // "0 INDEX" to read 10, "0 SETINDEX" to write 11
increment(mutate t.0); // also, the same way
t.0.increment(); // also, the same way
t.1 // "1 INDEX", it's slice
t.100500 // compilation error
It works for nesting
var.{i}.{j}. It works for nested tensors, nested tuples, tuples nested into tensors. It works for mutate. It works for globals.Why is this essential?
In the future, we'll have structures, declared like this:
struct User {
id: int;
name: slice;
}
Structures will be stored like tensors on a stack:
var u: User = { id: 5, name: "" };
// u is actually 2 slots on a stack, the same as
var u: (int, slice) = (5, "");
fun getUser(): User { ... }
// on a stack, the same as
fun getUser(): (int, slice) { ... }
It means, that `obj.{field}` is exactly the same as `tensorVar.{i}`:
var u: User = ...; // u: (int, slice) = ...
u.id; // u.0
u.id = 10; // u.0 = 10
Same goes for nested objects:
struct Storage {
lastUpdated: int;
owner: User;
}
s.lastUpdated // s.0
s.owner.id // s.1.0
So, implementing indexed access for tensors/tuples covering all scenarios is a direct step towards structures.