Hi,
Thanks to Martin for his explanation. Finally I also understood how this has to be treated in ST.
On Thu, 2019-06-13 at 12:36 +0200, Jan Holzweber wrote:
> Hello Martin!
>
> Please excuse my late reply.
> I will try to change my test according the information you gave me. I think i made some mistakes with the datatypes, as i thought of them more like c operators, as you mentioned. I will update you, if the tests do change.
I'm really looking forward to that. After Martins explanation I wanted to expand here on the big problem of the C/C++ and maybe the Lua treatment of logical
operators. Maybe this is clear for everybody, but for me it was a bit of an I opener and as it will affect our code generation I wanted to document it here:
If you take for example the following C/C++ code:
if(var1 > 5) && (var2 != 10)
This will get true when both conditions are fulfilled. However C/C++ defines a true condition of anything not 0. So it could be that based on the CPU
instructions used that the result of both conditions results not just in values 1 but some bit pattern with 1s when the conditions are fulfilled. Therefore for
simplifying the programming C introduced the logical operators.
If we now tak this to ST the condition would look like:
if (var1 > 5) AND (var2 <> 10) THEN
As ST only knows bitwise logical operators the AND would be a bitwise AND. However ST or to be more precise IEC 61131-3 has the data type BOOL which is the
result of both comparisons. As Bool can only have the value 0 or 1 bitwise from the IEC 61131-3 perspective is fine.
So a code generator either has to know that both sides are bool and use logical operators in the target language or it has to ensure that a bitwise comparison
is correct. For example the according C code for the ST above could then be:
if ((var1 > 5) ? 1 :0) & ((var2 != 10) ? 1 : 0) {
I'm not sure if I like this.
Cheers,
Alois
>
> Thank you and best regards,
> Jan
>
> Gesendet: Dienstag, 11. Juni 2019 um 22:25 Uhr
> Von: "Martin Melik-Merkumians" <Melik-Merkumians@xxxxxxxxxxxxxxxxx>
> An: "4diac developer discussions" <4diac-dev@xxxxxxxxxxx>
> Betreff: Re: [4diac-dev] [LUA] Dynamic type loader test evaluation
> Hi Jan,
>
> I have gone through your spreadsheet. Its great what you already analyzed since starting.
>
> I also have seen, that you differentiate between logical and bitwise operators (and/or/xor). Although such a distinction exists in C/C++ and LUA (as far as I remember), the IEC 61131 does not know this distinction, because there is a dedicated bool data type, which is part of the ANY_BIT types.
>
> Some examples to perhaps better visualize what I mean here.
> So a <WORD> AND <WORD> results in a <WORD> (abbreviated with => from now on)
> Resulting in a C-like bitwise AND operation
>
> <BOOL> AND <WORD> => <WORD> as the bool will be implicitly cast to the larger type
> Again resulting in a bitwise AND
>
> For <BOOL> AND <BOOL> => <BOOL> - this will produce a C-like logical AND
>
> So for e.g. an IF condition _expression_, the resulting type must always be a BOOL type in IEC 61131, which means the line “IF <BOOL> AND <WORD> THEN” is invalid code in the context of IEC 61131, where the same combination of types would be valid in C-like languages (with values different from zero treated as true, and false otherwise).
>
> So to make a long story short, in IEC 61131 there is no distinction between logical and bitwise operations, as all Boolean operations are always treated as bitwise, but with a distinct BOOL data type with no implicit or explicit casts to it. The only way to get a BOOL value is that the _expression_ must result in a BOOL.
>
> If there are further questions to that, feel free to contact me.
>
> Best regards,
> Martin
>
> --------------------------------------------------
> Dipl.-Ing. Martin Melik-Merkumians
> Advanced Mechatronic Systems
> Automation and Control Institute (ACIN)
> Vienna University of Technology
> DVR-Number: 0005886
>
> Gusshausstr. 27-29, room CA-05-38
> 1040 Vienna, Austria
> Phone: +43 (0)1 588 01 37688
> Fax: +43 (0)1 588 01 937688
> Email: melik-merkumians@xxxxxxxxxxxxxxxxx
>
http://www.acin.tuwien.ac.at/
> --------------------------------------------------
>
>
>
> Von: 4diac-dev-bounces@xxxxxxxxxxx <4diac-dev-bounces@xxxxxxxxxxx> Im Auftrag von Jan Holzweber
> Gesendet: Dienstag, 11. Juni 2019 15:57
> An: 4diac-dev@xxxxxxxxxxx
> Betreff: [4diac-dev] [LUA] Dynamic type loader test evaluation
>
> Hello!
>
> I finihsed the first evaluation of the tool. I summarized everything in the wiki and also in more detail in a google sheet.
> wiki: wiki
> google spread sheet: spreadsheet
>
> For question, as awlays, i am easily reachable on mattermost or here with the mailinglist.
>
> Cheers,
> Jan
> _______________________________________________ 4diac-dev mailing list 4diac-dev@xxxxxxxxxxx To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/4diac-dev
> _______________________________________________
> 4diac-dev mailing list
> 4diac-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>
https://www.eclipse.org/mailman/listinfo/4diac-dev
_______________________________________________
4diac-dev mailing list
4diac-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/4diac-dev