Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[asr->python] add complex visitors #2581

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/libasr/codegen/asr_to_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,36 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
s = r;
}

void visit_ComplexConstructor(const ASR::ComplexConstructor_t &x) {
visit_expr(*x.m_re);
std::string re = s;
visit_expr(*x.m_im);
std::string im = s;
s = "(" + re + ", " + im + ")";
khushi-411 marked this conversation as resolved.
Show resolved Hide resolved
}

void visit_ComplexBinOp(const ASR::ComplexBinOp_t &x) {
std::string r;
int current_precedence = last_expr_precedence;
visit_expr_with_precedence(*x.m_left, current_precedence);
r += s;
r += binop2str(x.m_op);
visit_expr_with_precedence(*x.m_right, current_precedence);
r += s;
last_expr_precedence = current_precedence;
s = r;
}

void visit_ComplexRe(const ASR::ComplexRe_t &x) {
visit_expr(*x.m_arg);
s = "real(" + s + ")";
khushi-411 marked this conversation as resolved.
Show resolved Hide resolved
}

void visit_ComplexIm(const ASR::ComplexIm_t &x) {
visit_expr(*x.m_arg);
s = "img(" + s + ")";
khushi-411 marked this conversation as resolved.
Show resolved Hide resolved
}

void visit_Assert(const ASR::Assert_t &x) {
std::string r = indent;
r += "assert ";
Expand Down
Loading