From 9b2d454c2e3885faf5270a8608c7d55a453c8d7e Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 9 May 2024 14:35:31 +0530 Subject: [PATCH] Add `TupleConstant` visitor --- src/libasr/codegen/asr_to_python.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libasr/codegen/asr_to_python.cpp b/src/libasr/codegen/asr_to_python.cpp index 204880be21..1852109543 100644 --- a/src/libasr/codegen/asr_to_python.cpp +++ b/src/libasr/codegen/asr_to_python.cpp @@ -150,6 +150,9 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor } case ASR::ttypeType::Logical : { r = "bool"; break; + } case ASR::ttypeType::Tuple : { + r = ASRUtils::type_to_str_python(t); + break; } default : { throw LCompilersException("The type `" + ASRUtils::type_to_str_python(t) + "` is not handled yet"); @@ -619,6 +622,23 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor s = r; } + void visit_TupleConstant(const ASR::TupleConstant_t &x) { + std::string r = ""; + r += "("; + size_t i = 0; + while (i < x.n_elements - 1) { + visit_expr(*x.m_elements[i]); + r += s; + r += ", "; + i++; + } + visit_expr(*x.m_elements[i]); + r += s; + r += ")"; + + s = r; + } + }; Result asr_to_python(Allocator& al, ASR::TranslationUnit_t &asr,