Skip to content

Commit

Permalink
add print visitor and fix program visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
khushi-411 committed Jan 20, 2024
1 parent a603db9 commit c2ab636
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/libasr/codegen/asr_to_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,10 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>

// Generate code for main function
inc_indent();
std::string r2;
for (auto &item : x.m_symtab->get_scope()) {
if (is_a<ASR::Variable_t>(*item.second)) {
ASR::Variable_t* v = ASR::down_cast<ASR::Variable_t>(item.second);
visit_Variable(*v);
r2 += s;
if (is_a<ASR::Function_t>(*item.second)) {
visit_symbol(*item.second);
r += s;
}
}
dec_indent();
Expand All @@ -254,6 +252,20 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
s = r;
}

void visit_Print(const ASR::Print_t &x) {
std::string r;
r += "print(";
for (size_t i = 0; i < x.n_values; i++) {
visit_expr(*x.m_values[i]);
r += s;
if (i < x.n_values-1)
r += ", ";
}
r += ")";
r += "\n";
s = r;
}

void visit_Assignment(const ASR::Assignment_t &x) {
std::string r = indent;
visit_expr(*x.m_target);
Expand Down

0 comments on commit c2ab636

Please sign in to comment.