Skip to content

Commit

Permalink
Fixed computation of initial values and compile time initial values
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Jun 20, 2022
1 parent 068f76a commit 28259e1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,11 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {

ASR::expr_t *value = nullptr;
ASR::expr_t *init_expr = nullptr;
tmp = nullptr;
if (x.m_value) {
this->visit_expr(*x.m_value);
}
if (tmp) {
value = ASRUtils::EXPR(tmp);
value = cast_helper(type, value, true);
if (!ASRUtils::check_equal_type(type, ASRUtils::expr_type(value))) {
Expand All @@ -1336,6 +1339,7 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
throw SemanticAbort();
}
init_expr = value;
value = ASRUtils::expr_value(value);
}
ASR::intentType s_intent = ASRUtils::intent_local;
ASR::storage_typeType storage_type =
Expand Down Expand Up @@ -2861,8 +2865,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
if (ASRUtils::expr_value(left) != nullptr &&
ASRUtils::expr_value(right) != nullptr) {
if (ASRUtils::is_integer(*source_type)) {
ASR::expr_t* left_value_expr = ASRUtils::expr_value(left);
int64_t left_value = ASR::down_cast<ASR::IntegerConstant_t>(
ASRUtils::expr_value(left))
left_value_expr)
->m_n;
int64_t right_value = ASR::down_cast<ASR::IntegerConstant_t>(
ASRUtils::expr_value(right))
Expand Down

0 comments on commit 28259e1

Please sign in to comment.