rusty icon indicating copy to clipboard operation
rusty copied to clipboard

Language Feature: Properties

Open TheColonel2688 opened this issue 6 months ago • 2 comments

Properties are not part of the IEC 61131-3 Standard but are heavily used in Codesys and Codesys derivatives (Beckhoff etc).

I would argue they should be in the standard, but the standard is also pretty outdated and is slowing down the evolution of the Automation Software Industry.

If RuSTy wants to be compatible with Codesys, it needs Properties. VAR_INPUT and VAR_OUTPUT can't be added to Interfaces. Only Methods Declarations/Prototypes can be added. Properties are heavily used with Interfaces to allow for Polymorphism with data, and not just Methods.

Codesys does not have a Text-Only format defined for properties (as far as I know), so this is where it gets tricky, as RuSTy needs to define its own Text-Only format.

Edit: It sounds like Codesys Go! will have a Text Only format for all Structure Text, and such it will have a Text Only format for Property, but that format hasn't be published yet. End_Edit

This is one option for a text-only format

Property *ProperyName* : *Type*
    GET
    END_GET
    SET
    END_SET
END_PROPERTY

Get and Set are Special Methods. In codesys, the Value passed to a Set Method is accessed by using the Propertry's Name, and the Value to return from a Get Method is also the Propertry's Name.

Property PropFoo : DINT
    GET
        PropFoo := *SomeBackingVariable*;
    END_GET
    SET
        *SomeBackingVariable* := PropFoo;
    END_SET
END_PROPERTY

Problem: This is a bad syntax because it can accidentally be reversed;

This is compile-able (but nonsensical)

Property PropFoo : DINT
    GET
        *SomeBackingVariable* := PropFoo ;
    END_GET
    SET
       PropFoo :=  *SomeBackingVariable* ;
    END_SET
END_PROPERTY

This is also compile-able (not actually performing a get)

Property PropFoo : DINT
    GET
        *SomeBackingVariable* := PropFoo ;
    END_GET
    SET
       *SomeBackingVariable* := PropFoo ;
    END_SET
END_PROPERTY

This is also compile-able (not actually performing a set)

Property PropFoo : DINT
    GET
        PropFoo  := *SomeBackingVariable*;
    END_GET
    SET
       PropFoo  := *SomeBackingVariable*;
    END_SET
END_PROPERTY

The previous syntax should be allowed for compatibility with Codesys, but an alternate form should be allowed and should be the official syntax for RuSTY. This is how C# handles properties, and since many Codesys/Beckhoff Developers are also C# devs, it will feel natural.

Property PropFoo : DINT
    GET
       return *SomeBackingVariable*; 
    END_GET
    SET
       *SomeBackingVariable* := value ;
    END_SET
END_PROPERTY

TheColonel2688 avatar Feb 13 '24 16:02 TheColonel2688