mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[Tolk] Get rid of ~tilda with mutate
and self
methods
This is a very big change. If FunC has `.methods()` and `~methods()`, Tolk has only dot, one and only way to call a `.method()`. A method may mutate an object, or may not. It's a behavioral and semantic difference from FunC. - `cs.loadInt(32)` modifies a slice and returns an integer - `b.storeInt(x, 32)` modifies a builder - `b = b.storeInt()` also works, since it not only modifies, but returns - chained methods also work, they return `self` - everything works exactly as expected, similar to JS - no runtime overhead, exactly same Fift instructions - custom methods are created with ease - tilda `~` does not exist in Tolk at all
This commit is contained in:
parent
12ff28ac94
commit
d9dba320cc
85 changed files with 2710 additions and 1965 deletions
|
@ -17,6 +17,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "src-file.h"
|
||||
#include "type-expr.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
|
@ -25,14 +26,23 @@ namespace tolk {
|
|||
typedef int var_idx_t;
|
||||
typedef int sym_idx_t;
|
||||
|
||||
enum class SymValKind { _Param, _Var, _Func, _Typename, _GlobVar, _Const };
|
||||
enum class SymValKind { _Var, _Func, _GlobVar, _Const };
|
||||
|
||||
struct SymValBase {
|
||||
SymValKind kind;
|
||||
int idx;
|
||||
SymValBase(SymValKind kind, int idx) : kind(kind), idx(idx) {
|
||||
TypeExpr* sym_type;
|
||||
#ifdef TOLK_DEBUG
|
||||
std::string sym_name; // seeing symbol name in debugger makes it much easier to delve into Tolk sources
|
||||
#endif
|
||||
|
||||
SymValBase(SymValKind kind, int idx, TypeExpr* sym_type) : kind(kind), idx(idx), sym_type(sym_type) {
|
||||
}
|
||||
virtual ~SymValBase() = default;
|
||||
|
||||
TypeExpr* get_type() const {
|
||||
return sym_type;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -98,6 +108,7 @@ void close_scope();
|
|||
SymDef* lookup_symbol(sym_idx_t idx);
|
||||
|
||||
SymDef* define_global_symbol(sym_idx_t name_idx, SrcLocation loc = {});
|
||||
SymDef* define_parameter(sym_idx_t name_idx, SrcLocation loc);
|
||||
SymDef* define_symbol(sym_idx_t name_idx, bool force_new, SrcLocation loc);
|
||||
|
||||
} // namespace tolk
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue