{"action":"created","issue":{"url":"https://api.github.com/repos/expload/pravda/issues/153","repository_url":"https://api.github.com/repos/expload/pravda","labels_url":"https://api.github.com/repos/expload/pravda/issues/153/labels{/name}","comments_url":"https://api.github.com/repos/expload/pravda/issues/153/comments","events_url":"https://api.github.com/repos/expload/pravda/issues/153/events","html_url":"https://github.com/expload/pravda/issues/153","id":341012963,"node_id":"MDU6SXNzdWUzNDEwMTI5NjM=","number":153,"title":"C# classes translation","user":{"login":"vovapolu","id":4629312,"node_id":"MDQ6VXNlcjQ2MjkzMTI=","avatar_url":"https://avatars3.githubusercontent.com/u/4629312?v=4","gravatar_id":"","url":"https://api.github.com/users/vovapolu","html_url":"https://github.com/vovapolu","followers_url":"https://api.github.com/users/vovapolu/followers","following_url":"https://api.github.com/users/vovapolu/following{/other_user}","gists_url":"https://api.github.com/users/vovapolu/gists{/gist_id}","starred_url":"https://api.github.com/users/vovapolu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vovapolu/subscriptions","organizations_url":"https://api.github.com/users/vovapolu/orgs","repos_url":"https://api.github.com/users/vovapolu/repos","events_url":"https://api.github.com/users/vovapolu/events{/privacy}","received_events_url":"https://api.github.com/users/vovapolu/received_events","type":"User","site_admin":false},"labels":[{"id":939942122,"node_id":"MDU6TGFiZWw5Mzk5NDIxMjI=","url":"https://api.github.com/repos/expload/pravda/labels/.net","name":".net","color":"5057bf","default":false},{"id":939942461,"node_id":"MDU6TGFiZWw5Mzk5NDI0NjE=","url":"https://api.github.com/repos/expload/pravda/labels/translation","name":"translation","color":"5eedbd","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-13T13:09:45Z","updated_at":"2018-07-14T09:06:24Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"We plan to translate C# classes to `struct` [data format](https://github.com/expload/pravda/blob/master/doc/ref/vm/data.md) in our VM. \r\n\r\nHere are some important points of C# classes translation:\r\n1. Each such class must have `[Translated]` attribute (therefore only classes with `[Translated]` or `[Program]` attributes are allowed in sources files to be translated, `[Program]` attribute marks classes that will be translated to programs, `[Translated]` attribute marks inner data structures )\r\n2. Interfaces are not translated, they serve only as a compile-time entities, therefore they don't have to be marked with any attribute. \r\n3. We translate **all** (`private`, `protected`, `internal` and `public`) fields to `utf8(\"<field_name>\") -> <field_value>` pairs in `struct`. \r\n4. We translate **all** methods to `utf8(\"<method_name>_<args_types>\")` -> `utf8(\"<inner_function_name>\")`. The `<args_types>` prefix is needed to support overloading and `<inner_function_name>` means name of function that will be called for the `<method_name>` method. Overridden methods will point to different `<inner_function_name>`. \r\n5. We translate `static` fields to storage items with `utf8(\"<class_name>_<field_name>\")` keys. \r\n6. We translate `static` methods to regular functions with `<class_name>_<method_name>_<args_types>` names. \r\n7. Constructors will be translated to regular functions with `<class_name>_init_<args_types>` names. \r\n\r\n### Example:\r\nSuppose we have the following class definition in C#:\r\n```c#\r\ninterface Vehicle\r\n{\r\n  void ComeIn(String someone);\r\n}\r\n\r\n[Translated]\r\nclass Bicycle : Vehicle \r\n{\r\n  public String Owner = \"no one\"; \r\n\r\n  void ComeIn(String someone) {\r\n    Owner = someone; \r\n  }\r\n} \r\n\r\n[Translated]\r\nclass Car : Vehicle  \r\n{\r\n  static private bool isBearBurnedDown = false;\r\n  static public bool IsBearBurnedDown() \r\n  {\r\n    return Car.isBearBurnedDown; \r\n  }\r\n\r\n  public int NumberOfTires; \r\n\r\n  public Car(int tires)\r\n  {\r\n    NumberOfTires = tires. \r\n  }\r\n\r\n  void ComeIn(String someone)\r\n  {\r\n    if (someone == \"bear\") {\r\n      Car.isBearBurnedDown = true; \r\n    }\r\n  }\r\n}\r\n```\r\n\r\n- `interface Vehicle` won't be translated to anything\r\n- `Bicycle()` constructor will be translated to `Bicycle_init` function that creates `struct(utf8(\"Owner\") -> utf8(\"no one\"), utf8(\"ComeIn_String\") -> utf8(\"function1\")`\r\n- `Bicycle.ComeIn` will be translated to some function (let's call it `function1`) that changes `utf8(\"Owner\")` field in the given `struct`. \r\n- `Car(int)` constructor will be translated to `Car_init_int` function that creates `struct(utf8(\"NumberOfTires\") -> int32(<given_int>), utf8(\"ComeIn_String\") -> utf8(\"function2\"))`\r\n- `isBearBurnedDown` static field will be translated to `utf8(\"Car_isBearBurnedDown\") -> bool` storage item\r\n- `IsBearBurnedDown` static method will be translated to `Car_IsBearBurnedDown` function that reads `utf8(\"Car_isBearBurnedDown\")` storage key. \r\n- `Car.ComeIn` will be translated to some function (let's call it `function2`) that changes `utf8(\"Car_isBearBurnedDown\") -> bool` storage item according to the given `String` from the stack. "},"comment":{"url":"https://api.github.com/repos/expload/pravda/issues/comments/405010340","html_url":"https://github.com/expload/pravda/issues/153#issuecomment-405010340","issue_url":"https://api.github.com/repos/expload/pravda/issues/153","id":405010340,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTAxMDM0MA==","user":{"login":"fomkin","id":1021178,"node_id":"MDQ6VXNlcjEwMjExNzg=","avatar_url":"https://avatars2.githubusercontent.com/u/1021178?v=4","gravatar_id":"","url":"https://api.github.com/users/fomkin","html_url":"https://github.com/fomkin","followers_url":"https://api.github.com/users/fomkin/followers","following_url":"https://api.github.com/users/fomkin/following{/other_user}","gists_url":"https://api.github.com/users/fomkin/gists{/gist_id}","starred_url":"https://api.github.com/users/fomkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fomkin/subscriptions","organizations_url":"https://api.github.com/users/fomkin/orgs","repos_url":"https://api.github.com/users/fomkin/repos","events_url":"https://api.github.com/users/fomkin/events{/privacy}","received_events_url":"https://api.github.com/users/fomkin/received_events","type":"User","site_admin":false},"created_at":"2018-07-14T09:06:24Z","updated_at":"2018-07-14T09:06:24Z","author_association":"MEMBER","body":"Can we replace all this string concatenations with uint16 identifiers? This is important because final size of binary should be as small as possible."}}
{"actor":{"display_login":"fomkin"}}