CozySynthesizer / cozy

The collection synthesizer
https://cozy.uwplse.org
Apache License 2.0
209 stars 18 forks source link

Need principled handling of "break" statements #4

Closed Calvin-L closed 7 years ago

Calvin-L commented 7 years ago

The code generation backend has a break statement (SBreak()), but it is not handled correctly. Furthermore, it would be difficult to handle correctly, since the code generation backend often compiles loop-like constructs to non-loop-like constructs (e.g. looping over a singleton list just executes the loop body once instead).

One possible fix is to remove SBreak and its uses and replace it with some kind of "escapable block" statement and a corresponding "escape" statement. An escapable block has a name, and an escape statement jumps to the end of the block it names. In C++ this would be implemented with goto:

{ ... goto label; ... }
label:

In Java, you can use labeled loops:

label: do { ... break label; ... } while (false);
Calvin-L commented 7 years ago

Fixed in 9b300922263634e248351e9a4d4d81ce4d55ccee.