Skip to content

Commit 5c95290

Browse files
committed
Fixed printing elements from a symbolic list
1 parent 8aaa4a7 commit 5c95290

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

integration_tests/symbolics_11.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ def test_extraction_of_elements():
1414
assert(ele3 == sin(x))
1515
assert(ele4 == Symbol("y"))
1616
print(ele1, ele2, ele3, ele4)
17+
print(l1[0], l1[1], l1[2], l1[3])
1718

1819
test_extraction_of_elements()

src/libasr/pass/replace_symbolic.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,24 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
11541154
sym, sym, call_args.p, call_args.n, ASRUtils::TYPE(ASR::make_Logical_t(al, x.base.base.loc, 4)), nullptr, nullptr));
11551155
print_tmp.push_back(function_call);
11561156
}
1157+
} else if (ASR::is_a<ASR::ListItem_t>(*val)) {
1158+
ASR::ListItem_t* list_item = ASR::down_cast<ASR::ListItem_t>(val);
1159+
if (list_item->m_type->type == ASR::ttypeType::SymbolicExpression) {
1160+
ASR::ttype_t *CPtr_type = ASRUtils::TYPE(ASR::make_CPtr_t(al, x.base.base.loc));
1161+
ASR::symbol_t* basic_str_sym = declare_basic_str_function(al, x.base.base.loc, module_scope);
1162+
1163+
Vec<ASR::call_arg_t> call_args;
1164+
call_args.reserve(al, 1);
1165+
ASR::call_arg_t call_arg;
1166+
call_arg.loc = x.base.base.loc;
1167+
call_arg.m_value = ASRUtils::EXPR(ASR::make_ListItem_t(al, x.base.base.loc, list_item->m_a,
1168+
list_item->m_pos, CPtr_type, nullptr));
1169+
call_args.push_back(al, call_arg);
1170+
ASR::expr_t* function_call = ASRUtils::EXPR(ASRUtils::make_FunctionCall_t_util(al, x.base.base.loc,
1171+
basic_str_sym, basic_str_sym, call_args.p, call_args.n,
1172+
ASRUtils::TYPE(ASR::make_Character_t(al, x.base.base.loc, 1, -2, nullptr)), nullptr, nullptr));
1173+
print_tmp.push_back(function_call);
1174+
}
11571175
} else {
11581176
print_tmp.push_back(x.m_values[i]);
11591177
}

0 commit comments

Comments
 (0)