{"action":"created","issue":{"url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/52","repository_url":"https://api.github.com/repos/AssemblyScript/assemblyscript","labels_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/52/comments","events_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/52/events","html_url":"https://github.com/AssemblyScript/assemblyscript/issues/52","id":307606663,"number":52,"title":"Classes","user":{"login":"WolfieWerewolf","id":10762757,"avatar_url":"https://avatars0.githubusercontent.com/u/10762757?v=4","gravatar_id":"","url":"https://api.github.com/users/WolfieWerewolf","html_url":"https://github.com/WolfieWerewolf","followers_url":"https://api.github.com/users/WolfieWerewolf/followers","following_url":"https://api.github.com/users/WolfieWerewolf/following{/other_user}","gists_url":"https://api.github.com/users/WolfieWerewolf/gists{/gist_id}","starred_url":"https://api.github.com/users/WolfieWerewolf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WolfieWerewolf/subscriptions","organizations_url":"https://api.github.com/users/WolfieWerewolf/orgs","repos_url":"https://api.github.com/users/WolfieWerewolf/repos","events_url":"https://api.github.com/users/WolfieWerewolf/events{/privacy}","received_events_url":"https://api.github.com/users/WolfieWerewolf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-22T11:35:35Z","updated_at":"2018-03-22T12:00:12Z","closed_at":null,"author_association":"NONE","body":"Dear AssemblyScript contributors.  This is a fascinating project, well done.  I've read a great deal of your documentation, tickets and source code and I'm still getting a handle on Binaryen but wondered if I could ask for a little more detail on what \"Classes are still wonky when it comes to the details\" means at a lower level?  I appreciate this comment comes from the \"High Level Summary\".  I've attempted to compile a simple TS class and it fails so I wanted to troubleshoot it a bit.  If someone could point me to some existing work on this that would be a great help  Just a \"start here\" would be helpful... I will most certainly share anything that I learn with the community.  Many thanks and kind regards.\r\n/W"},"comment":{"url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/comments/375279716","html_url":"https://github.com/AssemblyScript/assemblyscript/issues/52#issuecomment-375279716","issue_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/52","id":375279716,"user":{"login":"dcodeIO","id":1136893,"avatar_url":"https://avatars0.githubusercontent.com/u/1136893?v=4","gravatar_id":"","url":"https://api.github.com/users/dcodeIO","html_url":"https://github.com/dcodeIO","followers_url":"https://api.github.com/users/dcodeIO/followers","following_url":"https://api.github.com/users/dcodeIO/following{/other_user}","gists_url":"https://api.github.com/users/dcodeIO/gists{/gist_id}","starred_url":"https://api.github.com/users/dcodeIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcodeIO/subscriptions","organizations_url":"https://api.github.com/users/dcodeIO/orgs","repos_url":"https://api.github.com/users/dcodeIO/repos","events_url":"https://api.github.com/users/dcodeIO/events{/privacy}","received_events_url":"https://api.github.com/users/dcodeIO/received_events","type":"User","site_admin":false},"created_at":"2018-03-22T12:00:12Z","updated_at":"2018-03-22T12:00:12Z","author_association":"OWNER","body":"To support working with classes as you would in TS it is necessary to support their creation with the `new` keyword. The current implementation, if working at all, is unfinished and simply allocates a region of memory for the instantiated class instance to utilize ([see](https://github.com/AssemblyScript/assemblyscript/blob/master/src/compiler.ts#L4906)). A memory allocator must be included in the project for this to work, i.e. through `import \"allocator/tlsf\";` in the entry file. Since garbage collection isn't yet implemented, its memory also isn't automatically deallocated but at this point requires manually 'free'ing it with `free_memory(changetype<usize>(classInstance))`.\r\n\r\nAdditionally, some details haven't been implemented or sufficiently tested, yet. The `implements` keyword, interfaces in general or `abstract` methods are not implemented. These will require indirect function calls on fields that store the respective implementing function's table index. The `extends` keyword is somewhat implemented but hasn't been extensively tested when it comes to specializing (overriding) existing fields or their types.\r\n\r\nInterally, memory allocators and standard library implementations use a special sort of *unmanaged* classes ([see](https://github.com/AssemblyScript/assemblyscript/blob/master/std/assembly/allocator/tlsf.ts#L59)). One can think of them as structs with methods, basically a lower level form of classes without automatic memory management, but these don't support some things a C struct does, for example static inclusion of other struct-like elements because all structures in AssemblyScript are referenced and not passed by value. Hence, these implementations use some tricks to mimic the behaviour by managing offsets manually ([see](https://github.com/AssemblyScript/assemblyscript/blob/master/std/assembly/allocator/tlsf.ts#L157)).\r\n\r\nIn short, full class support still requires some sort of GC, maybe some sort of finalizers (think arrays that also have to deallocate their member objects), posssibly some sort of *classId* stored alongside each instance (think `instanceof` checks) and compiler-level support of virtual members by utilizing the function table.\r\n\r\nHope this helps :)"}}
{"actor":{"display_login":"dcodeIO"}}