Zhou Renjian or Udo,
Zhou Renjian, I have not heard from you in a long time. I hope you are well and in good spirits about J2S and still actively engaged in it. I realize you must have all sorts of other things that are at least important for you these days. I can never thank you enough for this contribution.
Can we discuss class instantiation and construction? Would you be interested in a Skype session with Udo and me? I have now got the PhET applets working in JavaScript, but it took some serious tricks, partially because I know I am working with an older version of the compiler. I know j2sSwingJS.js has diverged substantially from j2slib.js, so I do not want to presume that what I saw there is still an issue with j2slib. Still, I am interested in making sure I am doing this right, and there are things I don't understand. Some questions for you:
- I don't see why it is important for the compiler to split off the "prepareFields" business from the rest of the initialization. This is not what Java does. Why does J2S do it?
- Can you tell me if j2slib functions properly in cases where there are multiple abstract superclasses, some of which need to prepare fields? I had some problem with that and ended up handling it by forcing a default constructor in all classses that have fields to prepare. Maybe this is the simplest solution. Not sure.
- Is there a reason c$ is global? This caused a problem when a static definition used "new" to create an object, and in that object's constructor another class was loaded by reflection, thus changing c$ prior to returning. Wouldn't it be simpler to use a var c$ instead of a global c$, passing that as a variable to the Clazz.pu$h method? What am I missing? I do see in your latest version you are doing some additional local save/restore of that variable, but I don't think that really solves the problem. At least not for these PhET applets.
I have not implemented your changes from June, partially because I was so busy with my research group, partially because I am still using Eclipse Juno, and I think that was for Kepler or Luna, I can't remember. But I did look it over, and I have it installed now in Eclipse Mars.2 finally, so I can test that. I see that you implemented a new method, thisConstructor. I understand what that is there to address -- that "this()" must only access methods in its class, not the subclass. I solved the problem it addresses with just a few lines of code in what I am now calling j2sSwingJS.js using makeConstructor(), so I think if I do implement the latest compiler, I will just replace "thisConstructor" with "makeConstructor" using an Ant task.
One thing you may be interested in is that I have a decent solution to the signature problem. Like your solution, it still does not address numeric (int, float, decimal) overloading. It uses the fact that you can assign a field to the anonymous delegate function itself. So that means that once the correct method is found, it can be saved in the caller function to the delegate being run, and it never has to be found or checked again. This radically reduced the time in processing signatures and seems to work perfectly.
I also saw you addressing the explicit casting of class for objects, not just null. This is certainly interesting, and I don't have any other suggestion about that, but I am a bit concerned that it will reduce the performance considerably because it is creating new objects with every call to the function, and it seems to me it is doing it more often than it needs to. So I'm also not sure I want to implement that. Right now these PhET applets are at the limit for barely functional, and so I have to be very careful not to introduce anything that slows it done in a general sense.
Hoping this is the start of a conversation,
Bob
ps - The first flakes of snow fell today here in Minnesota, and a cold
wind is blowing. Winter is coming.... "around the corner" we say.
If you would like, I can submit more GitHub bug reports.
Bob