-
Notifications
You must be signed in to change notification settings - Fork 199
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
Inconsistent compiler generated code when 'repition index' is used in 'repeat-until' expression #958
Inconsistent compiler generated code when 'repition index' is used in 'repeat-until' expression #958
Comments
More serious errors resulting from repetition index
|
Previous behavior (everything with 1 in last column was fixed): |Language|Initial|Incremented|`_index` of first iteration |--------|-------|-----------|--------------------------- |C++ |0 |before |1 |C# |0 |before |1 |Go |1 |after |1 |Java |0 |before |1 |JS |0 |before |1 |Lua |0 |after |0 |Nim |0? |after |0 (variable declared without initializer) |Perl |- |- |- (variable was not declared) |PHP |0 |before |1 |Python |0 |after |0 |Ruby |0 |before |1 |Rust |0 |before |1 Fixes kaitai-io/kaitai_struct#958
Issue
I have a situation where there is a list of data types.
Before the list-entries (
entries
) are given, a maximum number of entries is given (max_num_entries
) at the head of the list.Additionally, any list entry may meet a condition which denotes it as the terminal entry - ending the list preemptively (before the max number of entries is reached).
Here is a minimal example of the phenomena
(Note that for this particular example there is a more elegant/proper solution; this is merely illustrating the problem).
Here, a
repeat-until
expression checks to see if either theterminal condition
_ == 0xFF
is met or if the_index
exceeds the max number of entries.The behavior of the
javascript
compiler (and kaitai IDE) is as expected.Here is the noteworthy piece of code generated:
Compare this to the
python
output of the compilerHopefully the problem here is apparent - the value of
i
is incremented before the loop check in the javascript code,while the value of
i
is incremented after the loop check in the python code.In order to achieve the same behavior for python, the
ksy
must be modified toProposed Fix
For each target language, ensure that the 'loop check' generated by a
repeat-until
expression isthe last thing to execute in its requisite repeat block.
I've searched the issues and haven't found anything similar,
however I may not have been using the appropriate keywords.
The text was updated successfully, but these errors were encountered: