2024-10-31 07:03:33 +00:00
|
|
|
/*
|
|
|
|
This file is part of TON Blockchain Library.
|
|
|
|
|
|
|
|
TON Blockchain Library is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
TON Blockchain Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ast.h"
|
|
|
|
#include "platform-utils.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A module implementing base functionality of read-only traversing a vertex tree.
|
|
|
|
* Since a vertex in general doesn't store a vector of children, iterating is possible only for concrete node_type.
|
|
|
|
* E.g., for ast_if_statement, visit nodes cond, if-body and else-body. For ast_string_const, nothing. And so on.
|
|
|
|
* Visitors below are helpers to inherit from and handle specific vertex types.
|
|
|
|
*
|
|
|
|
* Note, that absence of "children" in ASTNodeBase is not a drawback. Instead, it encourages you to think
|
|
|
|
* about types and match the type system.
|
|
|
|
*
|
|
|
|
* The visitor is read-only, it does not modify visited nodes (except if you purposely call mutating methods).
|
|
|
|
* For example, if you want to replace "beginCell()" call with "begin_cell", a visitor isn't enough for you.
|
|
|
|
* To replace vertices, consider another API: ast-replacer.h.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace tolk {
|
|
|
|
|
|
|
|
class ASTVisitor {
|
|
|
|
protected:
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
GNU_ATTRIBUTE_ALWAYS_INLINE static void visit_children(const ASTExprLeaf* v) {
|
2024-10-31 07:03:33 +00:00
|
|
|
static_cast<void>(v);
|
|
|
|
}
|
|
|
|
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
GNU_ATTRIBUTE_ALWAYS_INLINE void visit_children(const ASTExprUnary* v) {
|
2024-10-31 07:03:33 +00:00
|
|
|
visit(v->child);
|
|
|
|
}
|
|
|
|
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
GNU_ATTRIBUTE_ALWAYS_INLINE void visit_children(const ASTExprBinary* v) {
|
2024-10-31 07:03:33 +00:00
|
|
|
visit(v->lhs);
|
|
|
|
visit(v->rhs);
|
|
|
|
}
|
|
|
|
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
GNU_ATTRIBUTE_ALWAYS_INLINE void visit_children(const ASTExprVararg* v) {
|
|
|
|
for (AnyExprV child : v->children) {
|
|
|
|
visit(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GNU_ATTRIBUTE_ALWAYS_INLINE void visit_children(const ASTStatementUnary* v) {
|
|
|
|
visit(v->child);
|
|
|
|
}
|
|
|
|
|
|
|
|
GNU_ATTRIBUTE_ALWAYS_INLINE void visit_children(const ASTStatementVararg* v) {
|
|
|
|
for (AnyV child : v->children) {
|
|
|
|
visit(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GNU_ATTRIBUTE_ALWAYS_INLINE static void visit_children(const ASTOtherLeaf* v) {
|
|
|
|
static_cast<void>(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
GNU_ATTRIBUTE_ALWAYS_INLINE void visit_children(const ASTOtherVararg* v) {
|
2024-10-31 07:03:33 +00:00
|
|
|
for (AnyV child : v->children) {
|
|
|
|
visit(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void visit(AnyV v) = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~ASTVisitor() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ASTVisitorFunctionBody : public ASTVisitor {
|
|
|
|
protected:
|
|
|
|
using parent = ASTVisitorFunctionBody;
|
|
|
|
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
virtual void visit(V<ast_empty_statement> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_empty_expression> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_parenthesized_expression> v) { return visit_children(v); }
|
2024-10-31 07:11:41 +00:00
|
|
|
virtual void visit(V<ast_tensor> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_tensor_square> v) { return visit_children(v); }
|
2024-10-31 07:03:33 +00:00
|
|
|
virtual void visit(V<ast_identifier> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_int_const> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_string_const> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_bool_const> v) { return visit_children(v); }
|
2024-10-31 07:11:41 +00:00
|
|
|
virtual void visit(V<ast_null_keyword> v) { return visit_children(v); }
|
2024-10-31 07:18:54 +00:00
|
|
|
virtual void visit(V<ast_self_keyword> v) { return visit_children(v); }
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
virtual void visit(V<ast_argument> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_argument_list> v) { return visit_children(v); }
|
2024-10-31 07:03:33 +00:00
|
|
|
virtual void visit(V<ast_function_call> v) { return visit_children(v); }
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
virtual void visit(V<ast_dot_method_call> v) { return visit_children(v); }
|
2024-10-31 07:03:33 +00:00
|
|
|
virtual void visit(V<ast_underscore> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_unary_operator> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_binary_operator> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_ternary_operator> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_return_statement> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_sequence> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_repeat_statement> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_while_statement> v) { return visit_children(v); }
|
2024-10-31 07:11:41 +00:00
|
|
|
virtual void visit(V<ast_do_while_statement> v) { return visit_children(v); }
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
virtual void visit(V<ast_throw_statement> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_assert_statement> v) { return visit_children(v); }
|
2024-10-31 07:03:33 +00:00
|
|
|
virtual void visit(V<ast_try_catch_statement> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_if_statement> v) { return visit_children(v); }
|
2024-10-31 07:11:41 +00:00
|
|
|
virtual void visit(V<ast_local_var> v) { return visit_children(v); }
|
|
|
|
virtual void visit(V<ast_local_vars_declaration> v) { return visit_children(v); }
|
2024-10-31 07:03:33 +00:00
|
|
|
virtual void visit(V<ast_asm_body> v) { return visit_children(v); }
|
|
|
|
|
|
|
|
void visit(AnyV v) final {
|
|
|
|
switch (v->type) {
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
case ast_empty_statement: return visit(v->as<ast_empty_statement>());
|
|
|
|
case ast_empty_expression: return visit(v->as<ast_empty_expression>());
|
|
|
|
case ast_parenthesized_expression: return visit(v->as<ast_parenthesized_expression>());
|
2024-10-31 07:11:41 +00:00
|
|
|
case ast_tensor: return visit(v->as<ast_tensor>());
|
|
|
|
case ast_tensor_square: return visit(v->as<ast_tensor_square>());
|
2024-10-31 07:03:33 +00:00
|
|
|
case ast_identifier: return visit(v->as<ast_identifier>());
|
|
|
|
case ast_int_const: return visit(v->as<ast_int_const>());
|
|
|
|
case ast_string_const: return visit(v->as<ast_string_const>());
|
|
|
|
case ast_bool_const: return visit(v->as<ast_bool_const>());
|
2024-10-31 07:11:41 +00:00
|
|
|
case ast_null_keyword: return visit(v->as<ast_null_keyword>());
|
2024-10-31 07:18:54 +00:00
|
|
|
case ast_self_keyword: return visit(v->as<ast_self_keyword>());
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
case ast_argument: return visit(v->as<ast_argument>());
|
|
|
|
case ast_argument_list: return visit(v->as<ast_argument_list>());
|
2024-10-31 07:03:33 +00:00
|
|
|
case ast_function_call: return visit(v->as<ast_function_call>());
|
2024-10-31 07:18:54 +00:00
|
|
|
case ast_dot_method_call: return visit(v->as<ast_dot_method_call>());
|
2024-10-31 07:03:33 +00:00
|
|
|
case ast_underscore: return visit(v->as<ast_underscore>());
|
|
|
|
case ast_unary_operator: return visit(v->as<ast_unary_operator>());
|
|
|
|
case ast_binary_operator: return visit(v->as<ast_binary_operator>());
|
|
|
|
case ast_ternary_operator: return visit(v->as<ast_ternary_operator>());
|
|
|
|
case ast_return_statement: return visit(v->as<ast_return_statement>());
|
|
|
|
case ast_sequence: return visit(v->as<ast_sequence>());
|
|
|
|
case ast_repeat_statement: return visit(v->as<ast_repeat_statement>());
|
|
|
|
case ast_while_statement: return visit(v->as<ast_while_statement>());
|
2024-10-31 07:11:41 +00:00
|
|
|
case ast_do_while_statement: return visit(v->as<ast_do_while_statement>());
|
|
|
|
case ast_throw_statement: return visit(v->as<ast_throw_statement>());
|
|
|
|
case ast_assert_statement: return visit(v->as<ast_assert_statement>());
|
2024-10-31 07:03:33 +00:00
|
|
|
case ast_try_catch_statement: return visit(v->as<ast_try_catch_statement>());
|
|
|
|
case ast_if_statement: return visit(v->as<ast_if_statement>());
|
2024-10-31 07:11:41 +00:00
|
|
|
case ast_local_var: return visit(v->as<ast_local_var>());
|
|
|
|
case ast_local_vars_declaration: return visit(v->as<ast_local_vars_declaration>());
|
2024-10-31 07:03:33 +00:00
|
|
|
case ast_asm_body: return visit(v->as<ast_asm_body>());
|
|
|
|
default:
|
|
|
|
throw UnexpectedASTNodeType(v, "ASTVisitorFunctionBody::visit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
virtual void start_visiting_function(V<ast_function_declaration> v_function) {
|
2024-10-31 07:03:33 +00:00
|
|
|
visit(v_function->get_body());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
template<class BodyVisitorT>
|
|
|
|
void visit_ast_of_all_functions(const AllSrcFiles& all_files) {
|
|
|
|
for (const SrcFile* file : all_files) {
|
|
|
|
for (AnyV v : file->ast->as<ast_tolk_file>()->get_toplevel_declarations()) {
|
2024-10-31 07:03:33 +00:00
|
|
|
if (auto v_func = v->try_as<ast_function_declaration>()) {
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
if (v_func->is_regular_function()) {
|
|
|
|
BodyVisitorT visitor;
|
|
|
|
visitor.start_visiting_function(v_func);
|
2024-10-31 07:03:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
}
|
2024-10-31 07:03:33 +00:00
|
|
|
|
|
|
|
} // namespace tolk
|