Skip to content

Commit 14fcdab

Browse files
committed
Added Dict Return in C backend
1 parent 9c02482 commit 14fcdab

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ R"(#include <stdio.h>
442442
} else if (ASR::is_a<ASR::TypeParameter_t>(*return_var->m_type)) {
443443
has_typevar = true;
444444
return "";
445+
} else if (ASR::is_a<ASR::Dict_t>(*return_var->m_type)) {
446+
ASR::Dict_t* dict_type = ASR::down_cast<ASR::Dict_t>(return_var->m_type);
447+
sub = c_ds_api->get_dict_type(dict_type) + " ";
445448
} else {
446449
throw CodeGenError("Return type not supported in function '" +
447450
std::string(x.m_name) +
@@ -661,6 +664,16 @@ R"(#include <stdio.h>
661664
const_name + " = " + src + ";\n");
662665
src = const_name;
663666
return;
667+
} else if( ASR::is_a<ASR::Dict_t>(*x.m_type) ) {
668+
ASR::Dict_t* dict_type = ASR::down_cast<ASR::Dict_t>(x.m_type);
669+
const_name += std::to_string(const_vars_count);
670+
const_vars_count += 1;
671+
const_name = current_scope->get_unique_name(const_name);
672+
std::string indent(indentation_level*indentation_spaces, ' ');
673+
tmp_buffer_src.push_back(check_tmp_buffer() + indent + c_ds_api->get_dict_type(dict_type) +
674+
" " + const_name + " = " + src + ";\n");
675+
src = const_name;
676+
return;
664677
}
665678
src = check_tmp_buffer() + src;
666679
}
@@ -797,6 +810,9 @@ R"(#include <stdio.h>
797810
}
798811
src = check_tmp_buffer() + src_tmp;
799812
return;
813+
} else if (ASR::is_a<ASR::DictItem_t>(*x.m_target)) {
814+
self().visit_DictItem(*ASR::down_cast<ASR::DictItem_t>(x.m_target));
815+
target = src;
800816
} else {
801817
LCOMPILERS_ASSERT(false)
802818
}

0 commit comments

Comments
 (0)