Skip to content
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

Do_loop increment variable generalized #771

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/libasr/pass/pass_utils.cpp
Expand Up @@ -484,13 +484,16 @@ namespace LFortran {
ASR::stmt_t *inc_stmt = nullptr;
ASR::stmt_t *stmt1 = nullptr;
if( !a && !b && !c ) {
ASR::ttype_t *cond_type = LFortran::ASRUtils::TYPE(ASR::make_Logical_t(al, loc, 4, nullptr, 0));
ASR::expr_t *target = loop.m_head.m_v;
int mv_kind = ASRUtils::extract_kind_from_ttype_t(ASRUtils::expr_type(target));
ASR::ttype_t *cond_type = LFortran::ASRUtils::TYPE(ASR::make_Logical_t(al, loc, mv_kind, nullptr, 0));
cond = LFortran::ASRUtils::EXPR(ASR::make_LogicalConstant_t(al, loc, true, cond_type));
} else {
LFORTRAN_ASSERT(a);
LFORTRAN_ASSERT(b);
if (!c) {
ASR::ttype_t *type = LFortran::ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4, nullptr, 0));
int mv_kind = ASRUtils::extract_kind_from_ttype_t(ASRUtils::expr_type(c));
ASR::ttype_t *type = LFortran::ASRUtils::TYPE(ASR::make_Integer_t(al, loc, mv_kind, nullptr, 0));
c = LFortran::ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 1, type));
}
LFORTRAN_ASSERT(c);
Expand All @@ -510,7 +513,8 @@ namespace LFortran {
cmp_op = ASR::cmpopType::GtE;
}
ASR::expr_t *target = loop.m_head.m_v;
ASR::ttype_t *type = LFortran::ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4, nullptr, 0));
int mv_kind = ASRUtils::extract_kind_from_ttype_t(ASRUtils::expr_type(target));
ASR::ttype_t *type = LFortran::ASRUtils::TYPE(ASR::make_Integer_t(al, loc, mv_kind, nullptr, 0));
stmt1 = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, loc, target,
LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loc, a, ASR::binopType::Sub, c, type, nullptr)), nullptr));

Expand Down
4 changes: 2 additions & 2 deletions src/lpython/semantics/python_ast_to_asr.cpp
Expand Up @@ -2733,9 +2733,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
throw SemanticError("Only function call `range(..)` supported as for loop iteration for now",
x.base.base.loc);
}

int mv_kind = ASRUtils::extract_kind_from_ttype_t(ASRUtils::expr_type(target));
ASR::ttype_t *a_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc,
4, nullptr, 0));
mv_kind, nullptr, 0));
ASR::expr_t *constant_one = ASR::down_cast<ASR::expr_t>(ASR::make_IntegerConstant_t(
al, x.base.base.loc, 1, a_type));
make_BinOp_helper(loop_end, constant_one, ASR::binopType::Sub,
Expand Down