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

fix(#3163): while logic is fixed #3166

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 4 additions & 11 deletions eo-runtime/src/main/eo/org/eolang/while.eo
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,15 @@
# While.
[condition body] > while
if. > @
condition.as-bool
start 0
(condition 0).as-bool
loop 0
false

# First loop iteration that does not check condition.
[index] > start
seq > @
*
^.body index
^.loop (index.plus 1)

# Recursive
# Recursive loop.
[index] > loop
^.body index > current
if. > @
^.condition.as-bool
(^.condition (index.plus 1)).as-bool
seq
*
current
Expand Down
27 changes: 19 additions & 8 deletions eo-runtime/src/test/eo/org/eolang/while-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@
+package org.eolang
+version 0.0.0

# Test.
[] > while-dataizes-only-first-cycle
eq. > @
0
malloc.for
42
[m]
while > @
i.eq 0 > [i]
m.put i > [i]

# Test.
[] > simple-while-with-false-first
not. > @
while > res
false
false > [i]
true > [i]

# Test.
Expand All @@ -40,7 +51,7 @@
true
[m]
while > @
m
m > [i]
m.put false > [i]
false

Expand All @@ -51,15 +62,15 @@
0
[m]
while > @
2.gt m
2.gt m > [i]
m.put (m.as-int.plus 1) > [i]
3

# Test.
[] > last-while-dataization-object-with-false-condition
not. > @
while
1.gt 2
1.gt 2 > [i]
true > [i]

# Test.
Expand All @@ -78,7 +89,7 @@
acc.as-int.plus
arr.at 0
while
max.gt iter
max.gt iter > [i]
[i]
seq > @
*
Expand All @@ -100,7 +111,7 @@
0
[iter]
while > @
max.gt iter
max.gt iter > [i]
[i]
seq > @
*
Expand All @@ -122,7 +133,7 @@
0
[iter]
while > @
[]
[i]
if. > @
max.gt iter
seq
Expand All @@ -149,7 +160,7 @@
0
[iter]
while > @
[]
[i]
if. > @
max.gt iter
seq
Expand Down
Loading