Bug 866 - Pywriter Bug with Dropped Brackets when Converting Pseudo-Code
Summary: Pywriter Bug with Dropped Brackets when Converting Pseudo-Code
Alias: None
Product: Libre-SOC's first SoC
Classification: Unclassified
Component: Source Code (show other bugs)
Version: unspecified
Hardware: PC Linux
: High enhancement
Assignee: Luke Kenneth Casson Leighton
Depends on:
Reported: 2022-06-22 15:13 BST by Andrey Miroshnikov
Modified: 2022-06-22 19:04 BST (History)
2 users (show)

See Also:
NLnet milestone: NLNet.2019.10.031.Video
total budget (EUR) for completion of task and all subtasks: 0
budget (EUR) for this task, excluding subtasks' budget: 0
parent task for budget allocation:
child tasks for budget allocation:
The table of payments (in EUR) for this task; TOML format:


Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Miroshnikov 2022-06-22 15:13:29 BST
Currently there's a bug with the pseudo-code to Python function generator, where extra brackets are dropped. 

This was noticed when adding the pseudo-code for the "cprop" instruction, and a temp variable was added to circumvent this issue:
Comment 1 Andrey Miroshnikov 2022-06-22 15:18:51 BST
Adding IRC log conversation:
Comment 2 Luke Kenneth Casson Leighton 2022-06-22 15:29:23 BST
binary operator precedence error.
unfortunately the fix of adding explicit brackets interferes
with the detection of patterns "[0]*4" which is Power ISA
pseudocode for "0b0000"
Comment 3 Jacob Lifshay 2022-06-22 19:04:26 BST
note that python operator precedence causes `(P | G) + G ^ P` to be correctly parsed as `((P | G) + G) ^ P`, so imho if that order of operations matches what pywriter wanted to generate, missing parenthesis is not a problem for the python interpreter (though imho it is a problem for readability -- but it's generated code so doesn't necessarily need to be read very often)
+ is higher precedence than ^