-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute Token and Icode constants #1648
Conversation
|
||
// Stack: ... value2 value1 -> ... value2 value1 value2 value1 | ||
Icode_DUP2 = -2, | ||
Icode_DUP2 = Icode_DUP - 1, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Value -3
is unused
REGEXP = SHNE + 1, | ||
BINDNAME = REGEXP + 1, | ||
THROW = BINDNAME + 1, | ||
RETHROW = THROW + 1, // rethrow caught exception: catch (e if ) use it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When inserting new opcodes, only the line before and after the insertion point has to be changed
This is awfully clever -- I have not seen this before in Java and I'm wondering why not! I'll try it tonight. |
Does anyone else have a concern about this -- I'm having trouble seeing the downside and would like to merge it. |
LGTM (we use the same approach in JS running in Rhino works like a charm 🙂) |
+1 We use this pattern since years for JDBC index based access of result sets (sometimes using the index is a bit faster) |
The only downside is IMHO, you must understand the concept and add new constants the correct way (which should be more straight forward as before) |
One slightly different approachwe also use and that is imho easier to understand and less likely to go wrong when adding new codes (at the cost of declaring another (private) variable):
|
Unfortunately, this does not work here, as the result isn't computed at compile time, but on class instantiation. So these are no compile-time 'constants', that can be used in switch statements or annotations. |
K, similar stuff in JavaScript dus do the trick, but Java ain't JavaScript or vise versa 🙂 |
@rPraml thanks a lot for this |
This is an alternate approach for solving the problems mentioned here #1639
and should avoid large renumbering as you can see here: https://github.com/mozilla/rhino/pull/1593/files#diff-c1caeb9d13c1dceec5f4603f3836f3e227350ee1a57679238ce9a3a434601b60