Skip to content

Merge master#1668

Merged
EmelyanenkoK merged 12 commits intotestnetfrom
master
May 13, 2025
Merged

Merge master#1668
EmelyanenkoK merged 12 commits intotestnetfrom
master

Conversation

@EmelyanenkoK
Copy link
Member

No description provided.

EmelyanenkoK and others added 12 commits April 28, 2025 09:16
Now, only VarDescr::int_const represents whether it's a constant,
without being combined (and potentially become unsync) val bit.
Support declaring structures with arbitrary fields
and creating objects very similar to TS syntax.
Structs are actually tensors on a stack, and accessing their
fields behave exactly as accessing tensor's elements by index.
As a consequence, recurring struct fields doesn't work;
it will lead to infinity size.

All features of type system (nullables, unions) seamlessly
work with structures. A struct with 1 field has no extra
overhead, it's just a field on a stack.
Now fields can have default values, even complex ones:
> tensor: (int, coins) = (2, ton("0.05"))
Initial value must be a constant expression.

Global constants can also now be of any type,
including tensors and nullables.
Constant evaluator was almost dropped off, evaluation
is now done at IR (Ops) level.
Until this MR, parsing any type from tokens immediately
resulted in TypePtr.
This MR introduces an intermediate AST representation for types,
which are resolved at a later step.
It's a necessary refactoring towards generics.
Now structures can be generic: Container<T> and similar.
The same goes for type aliases: type A<T> = Container<T>.

Like generic functions, every struct is instantiated,
"Container<int>" and "Container<slice>" become different
symbols, and on instantiation they walk though the pipeline.
Type inferring and checking are done only upon instantiation.
This update greatly enhances reading Fift output:
1) stack comments are aligned
2) original lines from .tolk files are output as comments,
   grouping asm instructions

Internally, every AsmOp now has SrcLocation.
When outputting them one by one, an original .tolk line is
inserted if locations differ.
This can be optimized later by storing an index
to fast mapping of location (offset) into a line in a file.
In FunC, any function could be called `f(arg)` or `arg.f()`.
You had to call `cell.cell_hash()` / `slice.slice_hash()`:
these were two different global-scope functions.

Now, Tolk, as other languages, separates functions from methods.
It drops the ability to call a function via dot;
you can only call a method (for an object type).

> fun cell.hash(self): int ...
> fun slice.hash(self): int ...

With methods, stdlib functions became short:
`t.size()` instead of `t.tupleSize()`, and so on.

Methods can be declared for any type, including generics.
Calling a method, the compiler does type matching to detect
the only method from many equally named. This could be
generalized to functions overloading some day.
This is now valid:
> struct Container<T = int?> { item: T = null }
> Container{}   // does Container<int?>

Defaults for Ts work both for functions and structs.
Their main purpose is to have the `never` default:
> struct WithOptField<T = never> { f: T; }
I've added a rule that if a struct has the `never` field,
it can be missed out from a literal while creation
(like it doesn't exist at all).
This will be used in stdlib later.
This partially "reverts" the behavior of pragma
'compute-asm-ltr' from FunC, which was always on in Tolk.
Now, if it's safe, for asm functions with arg_order,
arguments are evaluated and placed onto the stack
in a desired order. When it's unsafe (the purpose
of this pragma, actually), arguments are evaluated
left-to-right.
Tolk v0.12: structures, generics, and methods
@EmelyanenkoK EmelyanenkoK merged commit b07d4a3 into testnet May 13, 2025
18 of 19 checks passed
Copy link

@Danyalkasiri Danyalkasiri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Danyalkasiri
Copy link

@Danyalkasiri #t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants