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

How to handle loops for creating the stateMachine? #19

Open
ozgunozerk opened this issue Jun 27, 2022 · 1 comment
Open

How to handle loops for creating the stateMachine? #19

ozgunozerk opened this issue Jun 27, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@ozgunozerk
Copy link
Owner

Imagine below:

#[freezable]
fn my_func() {
    loop {
        let a = 3;
        freeze!()
        let b = a + 2;
        let user_input = take_user_input_here();
        if user_input == b { break }
    }
}

with our current approach, we are creating a new state after each freeze!(). However, in the above code, there are indefinite amount of freeze!()s. That means, we have to create an enum with infinite states, which is not possible.

@ozgunozerk ozgunozerk added the question Further information is requested label Jun 27, 2022
@ozgunozerk
Copy link
Owner Author

ozgunozerk commented Jun 27, 2022

Currently, our approach is to parse the function, create the statemachine, and get rid of the function. The whole thing will turn into an enum representing the statemachine, and this very enum will implement the freezable trait and its methods. This approach clearly does not work if the freezable content is inside a loop.

Instead, we can do the following:

  1. locate the code block(s) that contains freeze!() statement(s)
  2. turn these code blocks into the statemachines
  3. locate the outer code block, and turn them into statemachines as well, which can work like this:
    • storing the innerStateMachine (which is the inner block StateMachine enum) as one of the states
    • other states should be Next and LoopFinished
    • when innerStateMachine is Finished, proceed into Next state
    • Next state checks whether the loop should continue or is it finished
    • if loop should continue, set innerStateMachine to its beginning state, and switch to innerStateMachine
    • if loop should finish, proceed to LoopFinished state

@ozgunozerk ozgunozerk added enhancement New feature or request wontfix This will not be worked on labels Aug 19, 2022
@ozgunozerk ozgunozerk removed this from the Improve `freezable-macro` milestone Aug 19, 2022
@ozgunozerk ozgunozerk removed the question Further information is requested label Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants