-
Notifications
You must be signed in to change notification settings - Fork 170
Import Global statements #1617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import Global statements #1617
Conversation
f359618
to
2eec664
Compare
TODO
|
2eec664
to
d965240
Compare
if( init_expr && (current_body || ASR::is_a<ASR::List_t>(*type)) && | ||
(is_runtime_expression || !is_variable_const)) { | ||
ASR::expr_t* v_expr = ASRUtils::EXPR(ASR::make_Var_t(al, loc, v_sym)); | ||
cast_helper(v_expr, init_expr, true); | ||
ASR::asr_t* assign = ASR::make_Assignment_t(al, loc, v_expr, | ||
init_expr, nullptr); | ||
current_body->push_back(al, ASRUtils::STMT(assign)); | ||
if (current_body) { | ||
current_body->push_back(al, ASRUtils::STMT(assign)); | ||
} else if (ASR::is_a<ASR::List_t>(*type)) { | ||
global_init.push_back(al, assign); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed current_body
contains true
value only when create_add_variable_to_scope
(this function) is visited inside the Function
or Program
nodes. In the module or global scope, current_body
would be nullptr
.
So, I have added a check for global_lists
.
Have I handled this correctly? @czgdp1807
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense to me.
This PR is ready for review. |
Please resolve the conflicts. |
515bae5
to
d83022f
Compare
Done! |
l_2: list[i32] | ||
l_2 = populate_lists() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to add an assignment statement for the initializer. Instead of adding a new test, I just used the existing one 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend to have both tests, initialiser and assignment statement for the initialiser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I will update the tests.
@@ -206,47 +203,6 @@ void SymbolTable::move_symbols_from_global_scope(Allocator &al, | |||
es->m_parent_symtab = module_scope; | |||
ASR::symbol_t *s = ASRUtils::symbol_get_past_external(a.second); | |||
LCOMPILERS_ASSERT(s); | |||
if (ASR::is_a<ASR::Variable_t>(*s)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the initializers of list types are moved into the global_initializer, so I removed all the changes which do the same thing.
d83022f
to
f01fa62
Compare
- Each module contains two functions: `global_statements` and `global_initializer`. - `global_statements` contains all the global statements in the module. - `global_initializer` contains the assign statements that are used to initialize the list or other types that cannot be handled in LLVM's global scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good to me. Thanks @Thirumalai-Shaktivel !
No description provided.