Merged
Conversation
Merge developing branch
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.