mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[Tolk] Compilation pipeline, register global symbols in advance
Since I've implemented AST, now I can drop forward declarations. Instead, I traverse AST of all files and register global symbols (functions, constants, global vars) as a separate step, in advance. That's why, while converting AST to Expr/Op, all available symbols are already registered. This greatly simplifies "intermediate state" of yet unknown functions and checking them afterward. Redeclaration of local variables (inside the same scope) is now also prohibited.
This commit is contained in:
parent
80001d1756
commit
5a3e3595d6
28 changed files with 1266 additions and 1134 deletions
|
@ -114,19 +114,16 @@ SymDef* lookup_symbol(sym_idx_t idx) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
SymDef* define_global_symbol(sym_idx_t name_idx, bool force_new, SrcLocation loc) {
|
||||
if (!name_idx) {
|
||||
return nullptr;
|
||||
SymDef* define_global_symbol(sym_idx_t name_idx, SrcLocation loc) {
|
||||
if (SymDef* found = G.global_sym_def[name_idx]) {
|
||||
return found; // found->value is filled; it means, that a symbol is redefined
|
||||
}
|
||||
auto found = G.global_sym_def[name_idx];
|
||||
if (found) {
|
||||
return force_new && found->value ? nullptr : found;
|
||||
}
|
||||
found = G.global_sym_def[name_idx] = new SymDef(0, name_idx, loc);
|
||||
|
||||
SymDef* registered = G.global_sym_def[name_idx] = new SymDef(0, name_idx, loc);
|
||||
#ifdef TOLK_DEBUG
|
||||
found->sym_name = found->name();
|
||||
registered->sym_name = registered->name();
|
||||
#endif
|
||||
return found;
|
||||
return registered; // registered->value is nullptr; it means, it's just created
|
||||
}
|
||||
|
||||
SymDef* define_symbol(sym_idx_t name_idx, bool force_new, SrcLocation loc) {
|
||||
|
@ -134,7 +131,7 @@ SymDef* define_symbol(sym_idx_t name_idx, bool force_new, SrcLocation loc) {
|
|||
return nullptr;
|
||||
}
|
||||
if (!G.scope_level) {
|
||||
return define_global_symbol(name_idx, force_new, loc);
|
||||
throw Fatal("unexpected scope_level = 0");
|
||||
}
|
||||
auto found = G.sym_def[name_idx];
|
||||
if (found) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue