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

continue-statement in for-loop doesn't run increment #90

Closed
phorward opened this issue Dec 5, 2022 · 0 comments
Closed

continue-statement in for-loop doesn't run increment #90

phorward opened this issue Dec 5, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@phorward
Copy link
Member

phorward commented Dec 5, 2022

This for-loop runs endless.

for i = 0; i < 10; i++ {
    if i == 5
        continue
}

This is because i is incremented until it reaches 5. The Op::Continue operation jumps directly to the loops start. This is a design problem with the current implementation, and not a direct bug which can be fixed easily.

VM state at the operation causing the bug:

__main__      ip = 22 state = Ok(Hold)
__main__      --- Code ---
__main__       000 Offset(Offset { offset: 8, row: 1, col: 9 })
__main__       001 Push0
__main__       002 Offset(Offset { offset: 4, row: 1, col: 5 })
__main__       003 StoreFast(0)
__main__       004 Loop(28)
__main__       005 Offset(Offset { offset: 11, row: 1, col: 12 })
__main__       006 LoadGlobal(0)
__main__       007 CallOrCopy
__main__       008 Offset(Offset { offset: 15, row: 1, col: 16 })
__main__       009 LoadStatic(1)
__main__       010 Offset(Offset { offset: 11, row: 1, col: 12 })
__main__       011 BinaryOp("lt")
__main__       012 ForwardIfTrue(2)
__main__       013 Break
__main__       014 Offset(Offset { offset: 32, row: 2, col: 8 })
__main__       015 LoadGlobal(0)
__main__       016 CallOrCopy
__main__       017 Offset(Offset { offset: 37, row: 2, col: 13 })
__main__       018 LoadStatic(2)
__main__       019 Offset(Offset { offset: 32, row: 2, col: 8 })
__main__       020 BinaryOp("eq")
__main__       021 ForwardIfFalse(3)
__main__      >022 Continue
__main__       023 Forward(2)
__main__       024 PushVoid
__main__       025 LoadGlobal(0)
__main__       026 Offset(Offset { offset: 19, row: 1, col: 20 })
__main__       027 Dup
__main__       028 Rot2
__main__       029 UnaryOp("iinc")
__main__       030 Drop
__main__       031 Continue
__main__      --- Stack ---
__main__       000 [55aca48eb218] 5 (0)
__main__       001 (empty)
__main__       002 (empty)
__main__      --- Frames ---
__main__       000 capture: 2, reader: 0, fuse: None
__main__       001 capture: 3, reader: 0, fuse: None
__main__       002 capture: 3, reader: 0, fuse: None
__main__       003 capture: 3, reader: 0, fuse: None
__main__       004 capture: 3, reader: 0, fuse: None

The frames also grow with every iteration. This is another bug to be fixed, IMHO be a complete re-design of loops and their internal execution.

@phorward phorward added the bug Something isn't working label Dec 5, 2022
@phorward phorward self-assigned this Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant