Subj : Re: Adding 'goto' statement to Rhino To : Josh Gertzen From : Igor Bukanov Date : Wed Apr 07 2004 11:23 pm Josh Gertzen wrote: > Hi, > > The company I give blood to :) is in the process of revamping most of > there core technology, which currently includes a less-than-stellar > proprietary scripting language. I have successfully made the case > that Rhino can serve as a replacement for the in-house language as > well as provide the company with many additional benefits. > > However, since we have many scripts written in the in-house language, > a conversion process is being put together which will parse the old > scripts and write them out in JavaScript. (Obviously there is more to > it than that, but work with me here) > > Unfortunately, 'goto' statements are used excessively in the scripts. > Therefore, for the conversion to work I have to add 'goto' & 'label' > statement support to Rhino. Are you sure that is impossible to replace the goto with break? "break" in ECMAScript can be used outside loops as well so in many cases I think it should be possible to replace forward goto with label: { .... break label; .... } and a reasonable backward goto can be written as label: for(;;) { ... continue label; ... break; } If your conversion tool has to do some parsing it perhaps can generate such transformations automatically. > > So I opened up the Rhino code, but before I go any further I just > wanted to get some input from the group: > > 1. Has this already been done by someone? If so are the changes > available somewhere? > > 2. Since there is already support for loop labels and break's with > labels such as [restart: while(true) break restart;], could I simple > piggy-back on the interals of this? > > 3. What files/areas should I be looking to make such a change in? If it is really impossible to live without goto you may have a look at transformCompilationUnit_r method in org/mozilla/javascript/NodeTransformer.java that replaces break and continue parse nodes (Token.BREAK/Token.CONTINUE) with explicit jumps. Be aware that code assumes that label are always defined prior their usage so for goto support you have to add a forward label search. Also note that any jump accross try/catch or with blocks has to insert scope recovery code. Regards, Igor .