Skip to content

Commit

Permalink
Compute Token and Icode constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rPraml authored and rbri committed Sep 25, 2024
1 parent a8e236f commit 1b11e69
Show file tree
Hide file tree
Showing 2 changed files with 258 additions and 257 deletions.
152 changes: 76 additions & 76 deletions rhino/src/main/java/org/mozilla/javascript/Icode.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,136 +15,136 @@ abstract class Icode {
Icode_DELNAME = 0,

// Stack: ... value1 -> ... value1 value1
Icode_DUP = -1,
Icode_DUP = Icode_DELNAME - 1,

// Stack: ... value2 value1 -> ... value2 value1 value2 value1
Icode_DUP2 = -2,
Icode_DUP2 = Icode_DUP - 1,

// Stack: ... value1 -> ...
Icode_POP = -4,
Icode_POP = Icode_DUP2 - 1,

// Store stack top into return register and then pop it
Icode_POP_RESULT = -5,
Icode_POP_RESULT = Icode_POP - 1,

// To jump conditionally and pop additional stack value
Icode_IFEQ_POP = -6,
Icode_IFEQ_POP = Icode_POP_RESULT - 1,

// various types of ++/--
Icode_VAR_INC_DEC = -7,
Icode_NAME_INC_DEC = -8,
Icode_PROP_INC_DEC = -9,
Icode_ELEM_INC_DEC = -10,
Icode_REF_INC_DEC = -11,
Icode_VAR_INC_DEC = Icode_IFEQ_POP - 1,
Icode_NAME_INC_DEC = Icode_VAR_INC_DEC - 1,
Icode_PROP_INC_DEC = Icode_NAME_INC_DEC - 1,
Icode_ELEM_INC_DEC = Icode_PROP_INC_DEC - 1,
Icode_REF_INC_DEC = Icode_ELEM_INC_DEC - 1,

// load/save scope from/to local
Icode_SCOPE_LOAD = -12,
Icode_SCOPE_SAVE = -13,
Icode_TYPEOFNAME = -14,
Icode_SCOPE_LOAD = Icode_REF_INC_DEC - 1,
Icode_SCOPE_SAVE = Icode_SCOPE_LOAD - 1,
Icode_TYPEOFNAME = Icode_SCOPE_SAVE - 1,

// helper for function calls
Icode_NAME_AND_THIS = -15,
Icode_PROP_AND_THIS = -16,
Icode_ELEM_AND_THIS = -17,
Icode_VALUE_AND_THIS = -18,
Icode_NAME_AND_THIS = Icode_TYPEOFNAME - 1,
Icode_PROP_AND_THIS = Icode_NAME_AND_THIS - 1,
Icode_ELEM_AND_THIS = Icode_PROP_AND_THIS - 1,
Icode_VALUE_AND_THIS = Icode_ELEM_AND_THIS - 1,

// Create closure object for nested functions
Icode_CLOSURE_EXPR = -19,
Icode_CLOSURE_STMT = -20,
Icode_CLOSURE_EXPR = Icode_VALUE_AND_THIS - 1,
Icode_CLOSURE_STMT = Icode_CLOSURE_EXPR - 1,

// Special calls
Icode_CALLSPECIAL = -21,
Icode_CALLSPECIAL = Icode_CLOSURE_STMT - 1,

// To return undefined value
Icode_RETUNDEF = -22,
Icode_RETUNDEF = Icode_CALLSPECIAL - 1,

// Exception handling implementation
Icode_GOSUB = -23,
Icode_STARTSUB = -24,
Icode_RETSUB = -25,
Icode_GOSUB = Icode_RETUNDEF - 1,
Icode_STARTSUB = Icode_GOSUB - 1,
Icode_RETSUB = Icode_STARTSUB - 1,

// To indicating a line number change in icodes.
Icode_LINE = -26,
Icode_LINE = Icode_RETSUB - 1,

// To store shorts and ints inline
Icode_SHORTNUMBER = -27,
Icode_INTNUMBER = -28,
Icode_SHORTNUMBER = Icode_LINE - 1,
Icode_INTNUMBER = Icode_SHORTNUMBER - 1,

// To create and populate array to hold values for [] and {} literals
Icode_LITERAL_NEW = -29,
Icode_LITERAL_SET = -30,
Icode_LITERAL_NEW = Icode_INTNUMBER - 1,
Icode_LITERAL_SET = Icode_LITERAL_NEW - 1,

// Array literal with skipped index like [1,,2]
Icode_SPARE_ARRAYLIT = -31,
Icode_SPARE_ARRAYLIT = Icode_LITERAL_SET - 1,

// Load index register to prepare for the following index operation
Icode_REG_IND_C0 = -32,
Icode_REG_IND_C1 = -33,
Icode_REG_IND_C2 = -34,
Icode_REG_IND_C3 = -35,
Icode_REG_IND_C4 = -36,
Icode_REG_IND_C5 = -37,
Icode_REG_IND1 = -38,
Icode_REG_IND2 = -39,
Icode_REG_IND4 = -40,
Icode_REG_IND_C0 = Icode_SPARE_ARRAYLIT - 1,
Icode_REG_IND_C1 = Icode_REG_IND_C0 - 1,
Icode_REG_IND_C2 = Icode_REG_IND_C1 - 1,
Icode_REG_IND_C3 = Icode_REG_IND_C2 - 1,
Icode_REG_IND_C4 = Icode_REG_IND_C3 - 1,
Icode_REG_IND_C5 = Icode_REG_IND_C4 - 1,
Icode_REG_IND1 = Icode_REG_IND_C5 - 1,
Icode_REG_IND2 = Icode_REG_IND1 - 1,
Icode_REG_IND4 = Icode_REG_IND2 - 1,

// Load string register to prepare for the following string operation
Icode_REG_STR_C0 = -41,
Icode_REG_STR_C1 = -42,
Icode_REG_STR_C2 = -43,
Icode_REG_STR_C3 = -44,
Icode_REG_STR1 = -45,
Icode_REG_STR2 = -46,
Icode_REG_STR4 = -47,
Icode_REG_STR_C0 = Icode_REG_IND4 - 1,
Icode_REG_STR_C1 = Icode_REG_STR_C0 - 1,
Icode_REG_STR_C2 = Icode_REG_STR_C1 - 1,
Icode_REG_STR_C3 = Icode_REG_STR_C2 - 1,
Icode_REG_STR1 = Icode_REG_STR_C3 - 1,
Icode_REG_STR2 = Icode_REG_STR1 - 1,
Icode_REG_STR4 = Icode_REG_STR2 - 1,

// Version of getvar/setvar that read var index directly from bytecode
Icode_GETVAR1 = -48,
Icode_SETVAR1 = -49,
Icode_GETVAR1 = Icode_REG_STR4 - 1,
Icode_SETVAR1 = Icode_GETVAR1 - 1,

// Load undefined
Icode_UNDEF = -50,
Icode_ZERO = -51,
Icode_ONE = -52,
Icode_UNDEF = Icode_SETVAR1 - 1,
Icode_ZERO = Icode_UNDEF - 1,
Icode_ONE = Icode_ZERO - 1,

// entrance and exit from .()
Icode_ENTERDQ = -53,
Icode_LEAVEDQ = -54,
Icode_TAIL_CALL = -55,
Icode_ENTERDQ = Icode_ONE - 1,
Icode_LEAVEDQ = Icode_ENTERDQ - 1,
Icode_TAIL_CALL = Icode_LEAVEDQ - 1,

// Clear local to allow GC its context
Icode_LOCAL_CLEAR = -56,
Icode_LOCAL_CLEAR = Icode_TAIL_CALL - 1,

// Literal get/set
Icode_LITERAL_GETTER = -57,
Icode_LITERAL_SETTER = -58,
Icode_LITERAL_GETTER = Icode_LOCAL_CLEAR - 1,
Icode_LITERAL_SETTER = Icode_LITERAL_GETTER - 1,

// const
Icode_SETCONST = -59,
Icode_SETCONSTVAR = -60,
Icode_SETCONSTVAR1 = -61,
Icode_SETCONST = Icode_LITERAL_SETTER - 1,
Icode_SETCONSTVAR = Icode_SETCONST - 1,
Icode_SETCONSTVAR1 = Icode_SETCONSTVAR - 1,

// Generator opcodes (along with Token.YIELD)
Icode_GENERATOR = -62,
Icode_GENERATOR_END = -63,
Icode_DEBUGGER = -64,
Icode_GENERATOR_RETURN = -65,
Icode_YIELD_STAR = -66,
Icode_GENERATOR = Icode_SETCONSTVAR1 - 1,
Icode_GENERATOR_END = Icode_GENERATOR - 1,
Icode_DEBUGGER = Icode_GENERATOR_END - 1,
Icode_GENERATOR_RETURN = Icode_DEBUGGER - 1,
Icode_YIELD_STAR = Icode_GENERATOR_RETURN - 1,

// Load BigInt register to prepare for the following BigInt operation
Icode_REG_BIGINT_C0 = -67,
Icode_REG_BIGINT_C1 = -68,
Icode_REG_BIGINT_C2 = -69,
Icode_REG_BIGINT_C3 = -70,
Icode_REG_BIGINT1 = -71,
Icode_REG_BIGINT2 = -72,
Icode_REG_BIGINT4 = -73,
Icode_REG_BIGINT_C0 = Icode_YIELD_STAR - 1,
Icode_REG_BIGINT_C1 = Icode_REG_BIGINT_C0 - 1,
Icode_REG_BIGINT_C2 = Icode_REG_BIGINT_C1 - 1,
Icode_REG_BIGINT_C3 = Icode_REG_BIGINT_C2 - 1,
Icode_REG_BIGINT1 = Icode_REG_BIGINT_C3 - 1,
Icode_REG_BIGINT2 = Icode_REG_BIGINT1 - 1,
Icode_REG_BIGINT4 = Icode_REG_BIGINT2 - 1,

// Call to GetTemplateLiteralCallSite
Icode_TEMPLATE_LITERAL_CALLSITE = -74,
Icode_LITERAL_KEYS = -75,
Icode_LITERAL_KEY_SET = -76,
Icode_TEMPLATE_LITERAL_CALLSITE = Icode_REG_BIGINT4 - 1,
Icode_LITERAL_KEYS = Icode_TEMPLATE_LITERAL_CALLSITE - 1,
Icode_LITERAL_KEY_SET = Icode_LITERAL_KEYS - 1,

// Last icode
MIN_ICODE = -76;
MIN_ICODE = Icode_LITERAL_KEY_SET;

static String bytecodeName(int bytecode) {
if (!validBytecode(bytecode)) {
Expand Down
Loading

0 comments on commit 1b11e69

Please sign in to comment.