Skip to content

Commit 0a79bf5

Browse files
authored
Merge pull request #2438 from anutosh491/main
Fixed ASR for test_gruntz.py
2 parents 4150db6 + 085d66f commit 0a79bf5

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

src/libasr/pass/pass_utils.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,15 @@ namespace LCompilers {
831831
s_func_type->n_arg_types = arg_types.n;
832832
s_func_type->m_return_var_type = nullptr;
833833

834-
Vec<ASR::stmt_t*> func_body;
835-
func_body.reserve(al, x->n_body - 1);
836-
for (size_t i=0; i< x->n_body - 1; i++) {
837-
func_body.push_back(al, x->m_body[i]);
834+
if (ASR::is_a<ASR::Return_t>(*x->m_body[x->n_body - 1])) {
835+
Vec<ASR::stmt_t*> func_body;
836+
func_body.reserve(al, x->n_body - 1);
837+
for (size_t i=0; i< x->n_body - 1; i++) {
838+
func_body.push_back(al, x->m_body[i]);
839+
}
840+
x->m_body = func_body.p;
841+
x->n_body = func_body.n;
838842
}
839-
x->m_body = func_body.p;
840-
x->n_body = func_body.n;
841843
}
842844
}
843845
for (auto &item : x->m_symtab->get_scope()) {

src/libasr/pass/replace_symbolic.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,16 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
269269

270270
ASR::ttype_t* f_signature= xx.m_function_signature;
271271
ASR::FunctionType_t *f_type = ASR::down_cast<ASR::FunctionType_t>(f_signature);
272-
ASR::ttype_t *type1 = ASRUtils::TYPE(ASR::make_CPtr_t(al, xx.base.base.loc));
272+
ASR::ttype_t *CPtr_type = ASRUtils::TYPE(ASR::make_CPtr_t(al, xx.base.base.loc));
273273
for (size_t i = 0; i < f_type->n_arg_types; ++i) {
274274
if (f_type->m_arg_types[i]->type == ASR::ttypeType::SymbolicExpression) {
275-
f_type->m_arg_types[i] = type1;
275+
f_type->m_arg_types[i] = CPtr_type;
276+
} else if (f_type->m_arg_types[i]->type == ASR::ttypeType::List) {
277+
ASR::List_t* list = ASR::down_cast<ASR::List_t>(f_type->m_arg_types[i]);
278+
if (list->m_type->type == ASR::ttypeType::SymbolicExpression){
279+
ASR::ttype_t* list_type = ASRUtils::TYPE(ASR::make_List_t(al, xx.base.base.loc, CPtr_type));
280+
f_type->m_arg_types[i] = list_type;
281+
}
276282
}
277283
}
278284

@@ -592,6 +598,17 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
592598
ASR::expr_t* function_call = process_attributes(xx.base.base.loc, xx.m_test);
593599
xx.m_test = function_call;
594600
}
601+
} else if (ASR::is_a<ASR::LogicalNot_t>(*xx.m_test)) {
602+
ASR::LogicalNot_t* logical_not = ASR::down_cast<ASR::LogicalNot_t>(xx.m_test);
603+
if (ASR::is_a<ASR::IntrinsicScalarFunction_t>(*logical_not->m_arg)) {
604+
ASR::IntrinsicScalarFunction_t* intrinsic_func = ASR::down_cast<ASR::IntrinsicScalarFunction_t>(logical_not->m_arg);
605+
if (intrinsic_func->m_type->type == ASR::ttypeType::Logical) {
606+
ASR::expr_t* function_call = process_attributes(xx.base.base.loc, logical_not->m_arg);
607+
ASR::expr_t* new_logical_not = ASRUtils::EXPR(ASR::make_LogicalNot_t(al, xx.base.base.loc, function_call,
608+
logical_not->m_type, logical_not->m_value));
609+
xx.m_test = new_logical_not;
610+
}
611+
}
595612
}
596613
}
597614

0 commit comments

Comments
 (0)