-
Notifications
You must be signed in to change notification settings - Fork 165
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] initial implementation #2362
[asr->python] initial implementation #2362
Conversation
We need to add tests for this, we can consider two kinds:
Both would be useful eventually to have. We can start with the first one, and later do the second one. |
Try this diff: --- a/src/libasr/codegen/asr_to_python.cpp
+++ b/src/libasr/codegen/asr_to_python.cpp
@@ -252,6 +252,10 @@ public:
s = r;
}
+ void visit_ExternalSymbol(const ASR::ExternalSymbol_t &x) {
+ visit_symbol(*x.m_external);
+ }
+
void visit_Print(const ASR::Print_t &x) {
std::string r;
r += "print("; Then a simple program works, the $ lpython --show-python examples/expr2.py
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 1845
return emit_python(arg_file, runtime_library_dir, compiler_options);
File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 429
LCompilers::Result<std::string> res = LCompilers::asr_to_lpython(al, *asr, diagnostics, compiler_options, color, indent);
File "/Users/ondrej/repos/lpython/src/libasr/codegen/asr_to_python.cpp", line 338
v.visit_TranslationUnit(asr);
File "/Users/ondrej/repos/lpython/src/libasr/codegen/asr_to_python.cpp", line 176
visit_symbol(*item.second);
File "../libasr/asr.h", line 5060
File "../libasr/asr.h", line 4774
File "/Users/ondrej/repos/lpython/src/libasr/codegen/asr_to_python.cpp", line 217
visit_symbol(*item.second);
File "../libasr/asr.h", line 5060
File "../libasr/asr.h", line 4778
File "/Users/ondrej/repos/lpython/src/libasr/codegen/asr_to_python.cpp", line 256
visit_symbol(*x.m_external);
File "../libasr/asr.h", line 5060
File "../libasr/asr.h", line 4775
File "/Users/ondrej/repos/lpython/src/libasr/codegen/asr_to_python.cpp", line 205
visit_body(x, r, true);
File "/Users/ondrej/repos/lpython/src/libasr/codegen/asr_to_python.cpp", line 120
visit_stmt(*x.m_body[i]);
File "../libasr/asr.h", line 5077
File "../libasr/asr.h", line 4811
File "../libasr/asr.h", line 5093
LCompilersException: visit_If() not implemented So just |
36f61f4
to
be0f8e3
Compare
Hi, @certik! The PR is ready for your review :-) Here's the output of the generated code: def test_boolOp():
a: bool
b: bool
a = False
b = True
a = a and b
b = a or True
a = a or b
a = a and (b == b)
a = a and (b != b)
a = b or b And here's the original code: def test_boolOp():
a: bool
b: bool
a = False
b = True
a = a and b
b = a or True
a = a or b
a = a and b == b
a = a and b != b
a = b or b I confirmed the generated and original codes are the same for other tests, too. Thanks! |
@certik, @Thirumalai-Shaktivel, this PR is ready to be merged. Gentle ping. Thanks! |
r.append(x.m_name); | ||
r += "("; | ||
for (size_t i = 0; i < x.n_args; i++) { | ||
visit_expr(*x.m_args[i]); |
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.
We have to specify the datatype of the argument here, right?
Something like:
def f(x: i32):
pass
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.
Yes! I'll work on this in a follow-up PR. I added a TODO remark so that we don't miss it in future.
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.
Otherwise, Looks great!
@@ -0,0 +1,9 @@ | |||
def if_check(): |
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.
It went unnoticed, expr17.py is not registered in tests.
You can submit a new PR for now.
Yay! Thanks for all your informative reviews, @certik & @Thirumalai-Shaktivel! |
No description provided.