-
Notifications
You must be signed in to change notification settings - Fork 171
Implementing for-else and while-else loops #2555
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
I think the tests which are failing have been updated in my pull request. |
Please mark this PR as ready for review once it is ready. |
Co-authored-by: Thirumalai Shaktivel <[email protected]>
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.
Looks great!
I have left minor formatting and tests improvements.
The tests fail because of reference not being updated. |
@Shaikh-Ubaid, do you see any design improvements in |
@Thirumalai-Shaktivel I have added all the suggested improvements. It is ready for review. |
tests/loop8.py
Outdated
nested_loop_for_for() | ||
nested_loop_for_while() | ||
nested_loop_while_for() | ||
nested_loop_while_while() |
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.
All the tests you have added in the tests
folder generates the runtime outputs, right?
Then, I think we have to move all these tests
into integration_tests
, register them in integration_tests/CMakeLists.txt
and test using integration_tests/run_tests.py
instead of adding them to tests.toml
We use tests.toml only when it generates the ASR but not runtime output or LLVM.
Also, I think one or two tests is enough. Move all the functions to one or two files.
Along with the print statements use assert statements as you did for loop_09.py
.
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.
I think you forgot to add the nested tests. You can submit a new PR for it.
def nested_loop_for_for():
i: i32
j: i32
for i in range(2):
print("outer: " + str(i))
for j in range(10, 20):
print(" inner: " + str(j))
break
else:
print("no break in outer loop")
def nested_loop_for_while():
i: i32
j: i32 = 10
for i in range(2):
print("outer: " + str(i))
while j < 20:
print(" inner: " + str(j))
break
else:
print("no break in outer loop")
def nested_loop_while_for():
i: i32 = 0
j: i32
while i < 2:
print("outer: " + str(i))
i += 1
for j in range(10, 20):
print(" inner: " + str(j))
break
else:
print("no break in outer loop")
def nested_loop_while_while():
i: i32 = 0
j: i32 = 10
while i < 2:
print("outer: " + str(i))
i += 1
while j < 20:
print(" inner: " + str(j))
break
else:
print("no break in outer loop")
nested_loop_for_for()
nested_loop_for_while()
nested_loop_while_for()
nested_loop_while_while()
Update the branch and resolve conflicts. |
I am not sure why tests are failing now. What is the issue? |
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.
LGTM, thank you!
For every main branch merge or rebase, we recommend a clean build and then update tests. I think the issue was related to that. We do: $ git merge lpython main
or
$ git rebase main
$ git clean -dfx
$ ./build.sh
$ ./run_tests.py -u |
Vec<ASR::stmt_t*> orelse; | ||
orelse.reserve(al, loop.n_orelse); | ||
for (size_t i = 0; i < loop.n_orelse; i++) | ||
orelse.push_back(al, loop.m_orelse[i]); | ||
ASR::stmt_t *while_loop_stmt = ASRUtils::STMT(ASR::make_WhileLoop_t(al, loc, | ||
loop.m_name, cond, body.p, body.size())); | ||
loop.m_name, cond, body.p, body.size(), orelse.p, orelse.size())); |
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.
Feels redundant. orelse
being pushed to a new memory location. Nothing else I think.
Adding support for for-else and while-else loops according to #2353 .
I have implemented a
while_else
pass which adds flag variables to all while else loops and adds an if check at the end of the loops.I have also added tests for the same.