cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 160 forks source link

Track implementation type during transpiler substitution #548

Open iffyio opened 4 years ago

iffyio commented 4 years ago

Hi!

Creating this issue as a result of the discussion here - about having knowledge of an expression's implementation type at least during methodInvocation substitution.

I bring it up since I think it's a requirement in order to generate any implementation specific code - e.g in the TreeMap example compared to a Hashmap. Maybe this isn't the case to begin with and there are other ways that involve a less invasive path?

We would need - to enable this - to store the map's kind into a field on the underlying JS object at instantiation time

@lgrignon do you mean having something similar to this done for declared classes?

    quickstart.QuickStart = QuickStart;
    QuickStart["__class"] = "quickstart.QuickStart";

Would this require that e.g a map be transpiled to a an indirect JS object that nests the actual dictionary similar to m.entries? e.g Map<String,..> m = new HashMap() => let m = { x: { object info }, y: { actual map } } as opposed to currently which is let m = { actual map }. One disadvantage with this approach is that it adds an extra layer of logic/memory for all operations on maps and this won't be necessary in almost all cases (SortedMaps are used a lot less frequently than HashMaps for example)

Let me know what you think!

lgrignon commented 4 years ago

It seems to me that it would be a good idea to store the map type into the original object, maybe not by changing native structure, which would require too much changes to JSweet (what you proposed with { x: { object info }, y: { actual map } }), I would rather go for something like { original map, __special_key_for_extraInfos: {} } :)

Also, it should only reside in the RemoveJavaDependencyAdapter.

Are you still willing to contribute to make JSweet a greater tool? :)

FYI, chances are we (maintainers) will be working more on this project in the near future