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

For Loop Bug #189

Closed
Aldrin-John-Olaer-Manalansan opened this issue Apr 4, 2022 · 4 comments
Closed

For Loop Bug #189

Aldrin-John-Olaer-Manalansan opened this issue Apr 4, 2022 · 4 comments
Labels
priority:p2 Medium priority scope:compiler type:bug Something isn't working workaround-available Users can fix for themselves
Milestone

Comments

@Aldrin-John-Olaer-Manalansan

For Loop always guarantees one iteration when passing variables as its parameters

2@ = 0
for 0@ = 1 to 2@ // the same as: for 0@ = 1 to 0
	0AD1: show_formatted_text_highpriority "%d %d" time 2000 0@ 2@
end
1@ = 1
2@ = 0
for 0@ = 1@ to 2@ // the same as: for 0@ = 1 to 0
	0AD1: show_formatted_text_highpriority "%d %d" time 2000 0@ 2@
end

The For loop should not continue executing inside if its two parameters were out of bounds.

@Aldrin-John-Olaer-Manalansan
Copy link
Author

This is my workaround to fix this problem. I do hope for this to be implemented in the future.

For Loop(Incrementing)

  • High Level Normal Syntax:
For 0@ = 1@ to 2@ step 3@
    // ~~~~~~~~~~~~~~~~~~do something inside the for loop~~~~~~~~~~~~~~~~~~
end
  • High Level Counter Part:
0085: 0@ = 1@
while 002D: 2@ >= 0@
    // ~~~~~~~~~~~~~~~~~~do something inside the for loop~~~~~~~~~~~~~~~~~~
    005A: 0@ += 3@
end
  • Low Level Counter Part:
0085: 0@ = 1@ // (int)
:IterateForLoop
002D:   2@ >= 0@ // (int)
004D: jump_if_false @BreakForLoop
// ~~~~~~~~~~~~~~~~~~do something inside the for loop~~~~~~~~~~~~~~~~~~
005A: 0@ += 3@ // (int)
0002: jump @IterateForLoop
:BreakForLoop

For Loop(Decrementing)

  • High Level Normal Syntax:
For 0@ = 1@ downto 2@ step 3@
    // ~~~~~~~~~~~~~~~~~~do something inside the for loop~~~~~~~~~~~~~~~~~~
end
  • High Level Counter Part:
0085: 0@ = 1@ // (int)
while 002D: 0@ >= 2@ // (int)
    // ~~~~~~~~~~~~~~~~~~do something inside the for loop~~~~~~~~~~~~~~~~~~
    0062: 0@ -= 3@ // (int)
end
  • Low Level Counter Part:
0085: 0@ = 1@ // (int)
:IterateForLoop
002D: 0@ >= 2@ // (int)
004D: jump_if_false @BreakForLoop
// ~~~~~~~~~~~~~~~~~~do something inside the for loop~~~~~~~~~~~~~~~~~~
0062: 0@ -= 3@ // (int)
0002: jump @IterateForLoop
:BreakForLoop

@x87
Copy link
Collaborator

x87 commented Apr 5, 2022

thanks for reporting and a workaround. I think it makes sense !

@x87 x87 added type:bug Something isn't working priority:p2 Medium priority workaround-available Users can fix for themselves scope:compiler labels Apr 5, 2022
@x87 x87 mentioned this issue Aug 6, 2022
15 tasks
@x87
Copy link
Collaborator

x87 commented Aug 6, 2022

as of 3.8.1 compiler adds extra condition before the loop body to ensure the mix and max values for the counter are valid, otherwise skips the loop. this potentially is a breaking change if script relied on this undefined behavior, but I anticipate the impact to be minimal.

@x87 x87 added this to the Next milestone Aug 14, 2022
@x87
Copy link
Collaborator

x87 commented Sep 1, 2022

fixed in 3.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:p2 Medium priority scope:compiler type:bug Something isn't working workaround-available Users can fix for themselves
Projects
None yet
Development

No branches or pull requests

2 participants