lpython
lpython copied to clipboard
Doubt in Implementation of `visit_Raise`
Consider the following example
(lf) anutosh491@spbhat68:~/lpython/lpython$ cat examples/expr2.py
from lpython import i32
def main0():
x: i32
x = -1
if x < 0:
raise Exception("Sorry, no numbers below zero")
print(x)
(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython examples/expr2.py
ERROR STOP
Now if we see the AST and the implementation for visit_Raise
here
(Raise
(Call
(Name
Exception
Load
)
[(ConstantStr
"Sorry, no numbers below zero"
()
)]
[]
)
()
)
void visit_Raise(const AST::Raise_t &x) {
ASR::expr_t *code;
if (x.m_cause) {
visit_expr(*x.m_cause);
code = ASRUtils::EXPR(tmp);
} else {
code = nullptr;
}
tmp = ASR::make_ErrorStop_t(al, x.base.base.loc, code);
}
The string which we would like to make use lies in x.m_exc
but we check if x.m_cause
is a nullptr
or not. Hence any change we make in the Exception string won't make a difference as the x.m_cause
is empty in such cases. Is this intended behaviour ?
Nope, I think we have to re-design the handling. Currently, the following works:
def main0():
x: i32
x = -1
assert x < 0, "Sorry, no numbers below zero"
print(x)
Yes, the raise
must be fixed to error stop
with that string.
Hi, is this an issue a newcomer can work on? If yes I'll give it a try.
@haanhvu you can work on any issue you want.
(lf) anutosh491@spbhat68:~/lpython/lpython$ lpython examples/expr2.py
ERROR STOP
I want to test this with my change. How can I build lpython from my source code?
How can I build lpython from my source code?
You can follow the README.
If you have further questions, please ask at https://lfortran.zulipchat.com/#narrow/stream/311866-LPython.
You can follow the README.
Yeah, I followed the build process here. But after that, still:
(lp) admin1@admin1-U37VC:~/lpython$ lpython examples/expr2.py
Command 'lpython' not found
Do I need to do anything else to build lpython
from my forked repo?
I'll post this in chat room too.
Update: I figured it out. Thanks!
To fix this issue, I need to take the string from AST::Raise_t
and turn it into an ASR::expr_t
right? How can I do that?