The WyIL bytecode has traditionally used unstructured control flow which gives a lot of flexibility. However, the reality is that using a structured notion of control-flow would make life easier:
The plan is to exploit nested bytecode blocks to implement a more traditional structured form of bytecode. The rough sequence is something like this:
This refactoring follows on logically from #502 and is part of #563.
Question: why not simply encode a full Abstract Syntax Tree for a cut-down version of Whiley?
This is not crazy, but there are some possible answers:
Overall, (2) seems a bit questionable because, in the end, the number of constructs is not that much smaller. The main differences are:
But, that's it, right?
Some problems encountered in the translation so far:
Type Tests. These are problematic as, without a goto, there is no place to do the physical retyping. Currently, they are translated roughly like this:
if x is int && x < 0:
r1 = x is int
r3 = false
r2 = x < 0
r3 = true
Here, the effects of x is int are diminished. Of course, can just insert casts as necessa ry here, but it raises the question as to where they should go exactly.
x is int
If Statements. Translation of if statements. These seem to often degenerate into sequences which load either true or false into some target register. This is caused by logical connectors, but also quantifiers and other operations (e.g. type tests).
It's possible that a better translation of if statements would lead to more succinct bytecode. In particular, the handling of logical connectors seems questionable.
This finally landed today in develop, just for the record. It's been a tough ride by I think this represents an important step in the evolution of Whiley.