Skip to content

Commit

Permalink
Fixed output through c_sym backend for test_gruntz.py (lcompilers#2454)
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Jan 10, 2024
1 parent 1652163 commit f9ab31e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ RUN(NAME symbolics_11 LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_12 LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_13 LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_14 LABELS cpython_sym llvm_sym NOFAST)
RUN(NAME test_gruntz LABELS cpython_sym llvm_sym NOFAST)
RUN(NAME test_gruntz LABELS cpython_sym c_sym llvm_sym NOFAST)

RUN(NAME sizeof_01 LABELS llvm c
EXTRAFILES sizeof_01b.c)
Expand Down
11 changes: 5 additions & 6 deletions src/libasr/codegen/asr_to_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,6 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
headers.insert("complex.h");
convert_variable_decl_util(v, is_array, declare_as_constant, use_ref, dummy,
force_declare, force_declare_name, n_dims, m_dims, v_m_type, dims, sub);
} else if (ASR::is_a<ASR::SymbolicExpression_t>(*v_m_type)) {
headers.insert("symengine/cwrapper.h");
std::string type_name = "basic";
std::string v_m_name = v.m_name;
sub = format_type_c("", type_name, v_m_name, use_ref, dummy);
} else if (ASRUtils::is_logical(*v_m_type)) {
convert_variable_decl_util(v, is_array, declare_as_constant, use_ref, dummy,
force_declare, force_declare_name, n_dims, m_dims, v_m_type, dims, sub);
Expand Down Expand Up @@ -529,7 +524,11 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
} else if (ASR::is_a<ASR::List_t>(*v_m_type)) {
ASR::List_t* t = ASR::down_cast<ASR::List_t>(v_m_type);
std::string list_type_c = c_ds_api->get_list_type(t);
sub = format_type_c("", list_type_c, v.m_name,
std::string name = v.m_name;
if (v.m_intent == ASRUtils::intent_out) {
name = "*" + name;
}
sub = format_type_c("", list_type_c, name,
false, false);
} else if (ASR::is_a<ASR::Tuple_t>(*v_m_type)) {
ASR::Tuple_t* t = ASR::down_cast<ASR::Tuple_t>(v_m_type);
Expand Down
23 changes: 22 additions & 1 deletion src/libasr/codegen/asr_to_c_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,15 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
|| param->m_intent == ASRUtils::intent_out)
&& !ASRUtils::is_aggregate_type(param->m_type))) {
args += "&" + src;
} else if (param->m_intent == ASRUtils::intent_out) {
if (ASR::is_a<ASR::List_t>(*param->m_type)) {
ASR::List_t* list_type = ASR::down_cast<ASR::List_t>(param->m_type);
if (list_type->m_type->type == ASR::ttypeType::CPtr){
args += "&" + src;
}
} else {
args += src;
}
} else {
args += src;
}
Expand Down Expand Up @@ -1367,7 +1376,19 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
if( is_target_list && is_value_list ) {
ASR::List_t* list_target = ASR::down_cast<ASR::List_t>(ASRUtils::expr_type(x.m_target));
std::string list_dc_func = c_ds_api->get_list_deepcopy_func(list_target);
src += indent + list_dc_func + "(&" + value + ", &" + target + ");\n\n";
if (ASR::is_a<ASR::Var_t>(*x.m_target)) {
ASR::symbol_t *target_sym = ASR::down_cast<ASR::Var_t>(x.m_target)->m_v;
if (ASR::is_a<ASR::Variable_t>(*target_sym)) {
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(target_sym);
if (v->m_intent == ASRUtils::intent_out) {
src += indent + list_dc_func + "(&" + value + ", " + target + ");\n\n";
} else {
src += indent + list_dc_func + "(&" + value + ", &" + target + ");\n\n";
}
}
} else {
src += indent + list_dc_func + "(&" + value + ", &" + target + ");\n\n";
}
} else if ( is_target_tup && is_value_tup ) {
ASR::Tuple_t* tup_target = ASR::down_cast<ASR::Tuple_t>(ASRUtils::expr_type(x.m_target));
std::string dc_func = c_ds_api->get_tuple_deepcopy_func(tup_target);
Expand Down

0 comments on commit f9ab31e

Please sign in to comment.