Skip to content

Commit

Permalink
Merge pull request lcompilers#2383 from anutosh491/fix_printing_symbo…
Browse files Browse the repository at this point in the history
…lic_lists

Fixed printing elements from a symbolic list
  • Loading branch information
certik committed Oct 17, 2023
2 parents d41216c + 5c95290 commit cba7320
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration_tests/symbolics_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ def test_extraction_of_elements():
assert(ele3 == sin(x))
assert(ele4 == Symbol("y"))
print(ele1, ele2, ele3, ele4)
print(l1[0], l1[1], l1[2], l1[3])

test_extraction_of_elements()
18 changes: 18 additions & 0 deletions src/libasr/pass/replace_symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,24 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
sym, sym, call_args.p, call_args.n, ASRUtils::TYPE(ASR::make_Logical_t(al, x.base.base.loc, 4)), nullptr, nullptr));
print_tmp.push_back(function_call);
}
} else if (ASR::is_a<ASR::ListItem_t>(*val)) {
ASR::ListItem_t* list_item = ASR::down_cast<ASR::ListItem_t>(val);
if (list_item->m_type->type == ASR::ttypeType::SymbolicExpression) {
ASR::ttype_t *CPtr_type = ASRUtils::TYPE(ASR::make_CPtr_t(al, x.base.base.loc));
ASR::symbol_t* basic_str_sym = declare_basic_str_function(al, x.base.base.loc, module_scope);

Vec<ASR::call_arg_t> call_args;
call_args.reserve(al, 1);
ASR::call_arg_t call_arg;
call_arg.loc = x.base.base.loc;
call_arg.m_value = ASRUtils::EXPR(ASR::make_ListItem_t(al, x.base.base.loc, list_item->m_a,
list_item->m_pos, CPtr_type, nullptr));
call_args.push_back(al, call_arg);
ASR::expr_t* function_call = ASRUtils::EXPR(ASRUtils::make_FunctionCall_t_util(al, x.base.base.loc,
basic_str_sym, basic_str_sym, call_args.p, call_args.n,
ASRUtils::TYPE(ASR::make_Character_t(al, x.base.base.loc, 1, -2, nullptr)), nullptr, nullptr));
print_tmp.push_back(function_call);
}
} else {
print_tmp.push_back(x.m_values[i]);
}
Expand Down

0 comments on commit cba7320

Please sign in to comment.