-
Notifications
You must be signed in to change notification settings - Fork 173
Improve complex binop and add .real, .imag attributes
#232
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
Conversation
| } else if (ASRUtils::is_complex(*left_type) && !ASRUtils::is_complex(*right_type)) { | ||
| if (ASRUtils::is_real(*right_type)) { | ||
| return ASR::down_cast<ASR::expr_t>(ASR::make_ImplicitCast_t( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change this to
| } else if (ASRUtils::is_complex(*left_type) && !ASRUtils::is_complex(*right_type)) { | |
| if (ASRUtils::is_real(*right_type)) { | |
| return ASR::down_cast<ASR::expr_t>(ASR::make_ImplicitCast_t( | |
| } else if (!is_assign && ASRUtils::is_complex(*left_type) && !ASRUtils::is_complex(*right_type)) { | |
| if (ASRUtils::is_real(*right_type)) { | |
| return ASR::down_cast<ASR::expr_t>(ASR::make_ImplicitCast_t( |
| } | ||
| if (ASR::is_a<ASR::Variable_t>(*t)) { | ||
| ASR::Variable_t *var = ASR::down_cast<ASR::Variable_t>(t); | ||
| LFORTRAN_ASSERT(var->m_value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presently this fails on the following check:
def test():
x: c64
x = 2 + 3j
a: f64
a = x.imagASR:
AssertFailed: var->m_value
This might be because we are keeping value as nullptr while creating a variable which I expect to be changed after the assignment. @certik What are your views/suggestions on this?
| 8, nullptr, 0)); | ||
| tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, val, type); | ||
| } else if (attr == "real") { | ||
| double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value)->m_im; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix this:
| double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value)->m_im; | |
| double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value)->m_re; |
|
Let's separate the two changes here into two PRs. I think you already have one PR for the implicit casting change. |
Fixes #229