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

Add "only when" #9

Closed
ReedOei opened this issue Jan 13, 2021 · 0 comments · Fixed by #17
Closed

Add "only when" #9

ReedOei opened this issue Jan 13, 2021 · 0 comments · Fixed by #17

Comments

@ReedOei
Copy link
Owner

ReedOei commented Jan 13, 2021

Transformers often have certain preconditions that need to be enforced. For this, it is convenient to have only when statements, such as:

only when x >= y

This is actually not difficult to implement, because of how flows work (specifically, how they fail when the desired values cannot be selected). So we can implement this by expanding it into:

x --[ y ]-> x

Similarly, we can expand a precondition like (where sender : address and owner : address):

only when sender = owner

into

sender --[ owner ]-> sender

Finally, we can expand compound preconditions like

only when P and Q

into

only when P
only when Q

then generating code as before. The full grammar, at least for the initial version, should be (where L is any locator; specifically, a source locator, but we can worry about that later):

Precondition ::= "only" "when" Pred
Pred ::= Pred "and" Pred | L Op L
Op ::= < | > | <= | >= | = | != | in

Ideally, we can also optimize the generate code so that no transfer actually needs to take place, and instead we can simply check the preconditions. This may require some changes to the compiler to make things work out nicely, but it is also likely that such changes will make implementing other features (such as consume) work out more nicely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant