{"action":"created","issue":{"url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/24","repository_url":"https://api.github.com/repos/bloomberg/ocamlscript","labels_url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/24/comments","events_url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/24/events","html_url":"https://github.com/bloomberg/ocamlscript/issues/24","id":127433113,"number":24,"title":"Rethink about the runtime encoding of ocaml values in javascript","user":{"login":"bobzhang","id":747051,"avatar_url":"https://avatars.githubusercontent.com/u/747051?v=3","gravatar_id":"","url":"https://api.github.com/users/bobzhang","html_url":"https://github.com/bobzhang","followers_url":"https://api.github.com/users/bobzhang/followers","following_url":"https://api.github.com/users/bobzhang/following{/other_user}","gists_url":"https://api.github.com/users/bobzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/bobzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bobzhang/subscriptions","organizations_url":"https://api.github.com/users/bobzhang/orgs","repos_url":"https://api.github.com/users/bobzhang/repos","events_url":"https://api.github.com/users/bobzhang/events{/privacy}","received_events_url":"https://api.github.com/users/bobzhang/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bloomberg/ocamlscript/labels/discussion","name":"discussion","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2016-01-19T12:16:00Z","updated_at":"2016-02-09T19:51:03Z","closed_at":null,"body":"Goal:\r\n\r\n1. Less work to patch the compiler\r\n2. OCaml Array is JS Array\r\n\r\nSome documentation about the current encoding is [https://github.com/bloomberg/ocamlscript/blob/master/docs%2Fffi.md] here, there is a problem with this encoding is that `Pfield i` is no longer the same as `Parrayref`, while the internal OCaml compiler think it is the same, for example `stdlib/camlinternalOO.ml`,  `bytecomp/translobj.ml`, `bytecomp/translclass.ml` there might be some other files I am missing. (Recent changes in the trunk of `stdlib/camlinternalOO` requires us to sync up the change)\r\n\r\nSo I am thinking of that `Obj.tag` is not used in too much in the compiler itself(except the GC, which is not relevant in js backend)\r\n\r\nSo I am proposing that `blocks with tag zero` is encoded as array, blocks with tag non zero (mostly normal variants) will be encoded as  array plus an extra property via `Object.defineProperty` so that they are polymorphic. and `Pfield`, `Parrayref` will behave the same.\r\n\r\nfor example \r\n\r\n```\r\ntype u = \r\n| B of int * int\r\n|A of int * int * int \r\n```\r\n\r\n`A (1,2,3)` will be encoded as `Object.defineProperty([1,2,3], {'t', {'value', 1}}`\r\n`B(1,2)` will be encoded as `[1,2]`\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/comments/182031498","html_url":"https://github.com/bloomberg/ocamlscript/issues/24#issuecomment-182031498","issue_url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/24","id":182031498,"user":{"login":"bobzhang","id":747051,"avatar_url":"https://avatars.githubusercontent.com/u/747051?v=3","gravatar_id":"","url":"https://api.github.com/users/bobzhang","html_url":"https://github.com/bobzhang","followers_url":"https://api.github.com/users/bobzhang/followers","following_url":"https://api.github.com/users/bobzhang/following{/other_user}","gists_url":"https://api.github.com/users/bobzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/bobzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bobzhang/subscriptions","organizations_url":"https://api.github.com/users/bobzhang/orgs","repos_url":"https://api.github.com/users/bobzhang/repos","events_url":"https://api.github.com/users/bobzhang/events{/privacy}","received_events_url":"https://api.github.com/users/bobzhang/received_events","type":"User","site_admin":false},"created_at":"2016-02-09T19:51:03Z","updated_at":"2016-02-09T19:51:03Z","body":"note that the reason that  `lazy` is broken  is also due to ocaml compiler internally treat object and array in a uniform way"}}