Description
Goal:
- Less work to patch the compiler
- OCaml Array is JS Array
Some 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)
So 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)
So 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.
for example
type u =
| B of int * int
|A of int * int * int
A (1,2,3)
will be encoded as Object.defineProperty([1,2,3], {'t', {'value', 1}}
B(1,2)
will be encoded as [1,2]