mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Token.ZERO and Token.ONE are used only by interpreter and moved to Interpreter as corresponding icode constants.
This commit is contained in:
parent
3ffab68246
commit
80b96958c9
@ -58,85 +58,91 @@ public class Interpreter
|
||||
// Stack: ... value2 value1 -> ... value1 value2
|
||||
Icode_SWAP = -3,
|
||||
|
||||
// Stack: ... value1 -> ...
|
||||
Icode_POP = -4,
|
||||
|
||||
// Store stack top into return register and then pop it
|
||||
Icode_POP_RESULT = -5,
|
||||
|
||||
// To jump conditionally and pop additional stack value
|
||||
Icode_IFEQ_POP = -4,
|
||||
Icode_IFEQ_POP = -6,
|
||||
|
||||
// various types of ++/--
|
||||
Icode_VAR_INC_DEC = -5,
|
||||
Icode_NAME_INC_DEC = -6,
|
||||
Icode_PROP_INC_DEC = -7,
|
||||
Icode_ELEM_INC_DEC = -8,
|
||||
Icode_REF_INC_DEC = -9,
|
||||
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,
|
||||
|
||||
// helper codes to deal with activation
|
||||
Icode_SCOPE = -10,
|
||||
Icode_TYPEOFNAME = -11,
|
||||
Icode_SCOPE = -12,
|
||||
Icode_TYPEOFNAME = -13,
|
||||
|
||||
// helper for function calls
|
||||
Icode_NAME_FAST_THIS = -12,
|
||||
Icode_NAME_SLOW_THIS = -13,
|
||||
Icode_PUSH_PARENT = -14,
|
||||
Icode_NAME_FAST_THIS = -14,
|
||||
Icode_NAME_SLOW_THIS = -15,
|
||||
Icode_PUSH_PARENT = -16,
|
||||
|
||||
// Create closure object for nested functions
|
||||
Icode_CLOSURE_EXPR = -15,
|
||||
Icode_CLOSURE_STMT = -16,
|
||||
Icode_CLOSURE_EXPR = -17,
|
||||
Icode_CLOSURE_STMT = -18,
|
||||
|
||||
// Special calls
|
||||
Icode_CALLSPECIAL = -17,
|
||||
Icode_CALLSPECIAL = -19,
|
||||
|
||||
// To return undefined value
|
||||
Icode_RETUNDEF = -18,
|
||||
Icode_RETUNDEF = -20,
|
||||
|
||||
// Exception handling implementation
|
||||
Icode_CATCH = -19,
|
||||
Icode_GOSUB = -20,
|
||||
Icode_RETSUB = -21,
|
||||
Icode_CATCH = -21,
|
||||
Icode_GOSUB = -22,
|
||||
Icode_RETSUB = -23,
|
||||
|
||||
// To indicating a line number change in icodes.
|
||||
Icode_LINE = -22,
|
||||
Icode_LINE = -24,
|
||||
|
||||
// To store shorts and ints inline
|
||||
Icode_SHORTNUMBER = -23,
|
||||
Icode_INTNUMBER = -24,
|
||||
Icode_SHORTNUMBER = -25,
|
||||
Icode_INTNUMBER = -26,
|
||||
|
||||
// To create and populate array to hold values for [] and {} literals
|
||||
Icode_LITERAL_NEW = -25,
|
||||
Icode_LITERAL_SET = -26,
|
||||
Icode_LITERAL_NEW = -27,
|
||||
Icode_LITERAL_SET = -28,
|
||||
|
||||
// Array literal with skipped index like [1,,2]
|
||||
Icode_SPARE_ARRAYLIT = -27,
|
||||
Icode_SPARE_ARRAYLIT = -29,
|
||||
|
||||
// Load index register to prepare for the following index operation
|
||||
Icode_REG_IND_C0 = -28,
|
||||
Icode_REG_IND_C1 = -29,
|
||||
Icode_REG_IND_C2 = -30,
|
||||
Icode_REG_IND_C3 = -31,
|
||||
Icode_REG_IND_C4 = -32,
|
||||
Icode_REG_IND_C5 = -33,
|
||||
Icode_REG_IND1 = -34,
|
||||
Icode_REG_IND2 = -35,
|
||||
Icode_REG_IND4 = -36,
|
||||
Icode_REG_IND_C0 = -30,
|
||||
Icode_REG_IND_C1 = -31,
|
||||
Icode_REG_IND_C2 = -32,
|
||||
Icode_REG_IND_C3 = -33,
|
||||
Icode_REG_IND_C4 = -34,
|
||||
Icode_REG_IND_C5 = -35,
|
||||
Icode_REG_IND1 = -36,
|
||||
Icode_REG_IND2 = -37,
|
||||
Icode_REG_IND4 = -38,
|
||||
|
||||
// Load string register to prepare for the following string operation
|
||||
Icode_REG_STR_C0 = -37,
|
||||
Icode_REG_STR_C1 = -38,
|
||||
Icode_REG_STR_C2 = -39,
|
||||
Icode_REG_STR_C3 = -40,
|
||||
Icode_REG_STR1 = -41,
|
||||
Icode_REG_STR2 = -42,
|
||||
Icode_REG_STR4 = -43,
|
||||
Icode_REG_STR_C0 = -39,
|
||||
Icode_REG_STR_C1 = -40,
|
||||
Icode_REG_STR_C2 = -41,
|
||||
Icode_REG_STR_C3 = -42,
|
||||
Icode_REG_STR1 = -43,
|
||||
Icode_REG_STR2 = -44,
|
||||
Icode_REG_STR4 = -45,
|
||||
|
||||
// Version of getvar/setvar that read var index directly from bytecode
|
||||
Icode_GETVAR1 = -44,
|
||||
Icode_SETVAR1 = -45,
|
||||
Icode_GETVAR1 = -46,
|
||||
Icode_SETVAR1 = -47,
|
||||
|
||||
Icode_UNDEF = -46,
|
||||
|
||||
Icode_POP = -47,
|
||||
Icode_POP_RESULT = -48,
|
||||
// Load unefined
|
||||
Icode_UNDEF = -48,
|
||||
Icode_ZERO = -49,
|
||||
Icode_ONE = -50,
|
||||
|
||||
// Last icode
|
||||
MIN_ICODE = -48;
|
||||
MIN_ICODE = -50;
|
||||
|
||||
static {
|
||||
// Checks for byte code consistencies, good compiler can eliminate them
|
||||
@ -171,6 +177,8 @@ public class Interpreter
|
||||
case Icode_DUP: return "DUP";
|
||||
case Icode_DUP2: return "DUP2";
|
||||
case Icode_SWAP: return "SWAP";
|
||||
case Icode_POP: return "POP";
|
||||
case Icode_POP_RESULT: return "POP_RESULT";
|
||||
case Icode_IFEQ_POP: return "IFEQ_POP";
|
||||
case Icode_VAR_INC_DEC: return "VAR_INC_DEC";
|
||||
case Icode_NAME_INC_DEC: return "NAME_INC_DEC";
|
||||
@ -214,8 +222,8 @@ public class Interpreter
|
||||
case Icode_GETVAR1: return "GETVAR1";
|
||||
case Icode_SETVAR1: return "SETVAR1";
|
||||
case Icode_UNDEF: return "UNDEF";
|
||||
case Icode_POP: return "POP";
|
||||
case Icode_POP_RESULT: return "POP_RESULT";
|
||||
case Icode_ZERO: return "ZERO";
|
||||
case Icode_ONE: return "ONE";
|
||||
}
|
||||
|
||||
// icode without name
|
||||
@ -986,32 +994,9 @@ public class Interpreter
|
||||
iCodeTop = visitIncDec(node, child, iCodeTop);
|
||||
break;
|
||||
|
||||
case Token.NUMBER: {
|
||||
double num = node.getDouble();
|
||||
int inum = (int)num;
|
||||
if (inum == num) {
|
||||
if (inum == 0) {
|
||||
iCodeTop = addToken(Token.ZERO, iCodeTop);
|
||||
// Check for negative zero
|
||||
if (1.0 / num < 0.0) {
|
||||
iCodeTop = addToken(Token.NEG, iCodeTop);
|
||||
}
|
||||
} else if (inum == 1) {
|
||||
iCodeTop = addToken(Token.ONE, iCodeTop);
|
||||
} else if ((short)inum == inum) {
|
||||
iCodeTop = addIcode(Icode_SHORTNUMBER, iCodeTop);
|
||||
iCodeTop = addShort(inum, iCodeTop);
|
||||
} else {
|
||||
iCodeTop = addIcode(Icode_INTNUMBER, iCodeTop);
|
||||
iCodeTop = addInt(inum, iCodeTop);
|
||||
}
|
||||
} else {
|
||||
int index = getDoubleIndex(num);
|
||||
iCodeTop = addIndexOp(Token.NUMBER, index, iCodeTop);
|
||||
}
|
||||
stackChange(1);
|
||||
case Token.NUMBER:
|
||||
iCodeTop = visitNumber(node, iCodeTop);
|
||||
break;
|
||||
}
|
||||
|
||||
case Token.CATCH_SCOPE:
|
||||
iCodeTop = visitExpression(child, iCodeTop);
|
||||
@ -1240,6 +1225,34 @@ public class Interpreter
|
||||
return iCodeTop;
|
||||
}
|
||||
|
||||
private int visitNumber(Node node, int iCodeTop)
|
||||
{
|
||||
double num = node.getDouble();
|
||||
int inum = (int)num;
|
||||
if (inum == num) {
|
||||
if (inum == 0) {
|
||||
iCodeTop = addIcode(Icode_ZERO, iCodeTop);
|
||||
// Check for negative zero
|
||||
if (1.0 / num < 0.0) {
|
||||
iCodeTop = addToken(Token.NEG, iCodeTop);
|
||||
}
|
||||
} else if (inum == 1) {
|
||||
iCodeTop = addIcode(Icode_ONE, iCodeTop);
|
||||
} else if ((short)inum == inum) {
|
||||
iCodeTop = addIcode(Icode_SHORTNUMBER, iCodeTop);
|
||||
iCodeTop = addShort(inum, iCodeTop);
|
||||
} else {
|
||||
iCodeTop = addIcode(Icode_INTNUMBER, iCodeTop);
|
||||
iCodeTop = addInt(inum, iCodeTop);
|
||||
}
|
||||
} else {
|
||||
int index = getDoubleIndex(num);
|
||||
iCodeTop = addIndexOp(Token.NUMBER, index, iCodeTop);
|
||||
}
|
||||
stackChange(1);
|
||||
return iCodeTop;
|
||||
}
|
||||
|
||||
private int visitLiteral(Node node, Node child, int iCodeTop)
|
||||
{
|
||||
int type = node.getType();
|
||||
@ -2715,12 +2728,12 @@ switch (op) {
|
||||
++pc;
|
||||
continue Loop;
|
||||
}
|
||||
case Token.ZERO :
|
||||
case Icode_ZERO :
|
||||
++stackTop;
|
||||
stack[stackTop] = DBL_MRK;
|
||||
sDbl[stackTop] = 0;
|
||||
continue Loop;
|
||||
case Token.ONE :
|
||||
case Icode_ONE :
|
||||
++stackTop;
|
||||
stack[stackTop] = DBL_MRK;
|
||||
sDbl[stackTop] = 1;
|
||||
|
@ -112,100 +112,98 @@ public class Token
|
||||
NAME = 38,
|
||||
NUMBER = 39,
|
||||
STRING = 40,
|
||||
ZERO = 41,
|
||||
ONE = 42,
|
||||
NULL = 43,
|
||||
THIS = 44,
|
||||
FALSE = 45,
|
||||
TRUE = 46,
|
||||
SHEQ = 47, // shallow equality (===)
|
||||
SHNE = 48, // shallow inequality (!==)
|
||||
REGEXP = 49,
|
||||
BINDNAME = 50,
|
||||
THROW = 51,
|
||||
IN = 52,
|
||||
INSTANCEOF = 53,
|
||||
LOCAL_SAVE = 54,
|
||||
LOCAL_LOAD = 55,
|
||||
GETVAR = 56,
|
||||
SETVAR = 57,
|
||||
CATCH_SCOPE = 58,
|
||||
ENUM_INIT = 59,
|
||||
ENUM_NEXT = 60,
|
||||
ENUM_ID = 61,
|
||||
THISFN = 62,
|
||||
RETURN_RESULT = 63, // to return prevoisly stored return result
|
||||
ARRAYLIT = 64, // array literal
|
||||
OBJECTLIT = 65, // object literal
|
||||
GET_REF = 66, // *reference
|
||||
SET_REF = 67, // *reference = something
|
||||
REF_CALL = 68, // f(args) = something or f(args)++
|
||||
SPECIAL_REF = 69, // reference for special properties like __proto
|
||||
GENERIC_REF = 70, // generic reference to generate runtime ref errors
|
||||
NULL = 41,
|
||||
THIS = 42,
|
||||
FALSE = 43,
|
||||
TRUE = 44,
|
||||
SHEQ = 45, // shallow equality (===)
|
||||
SHNE = 46, // shallow inequality (!==)
|
||||
REGEXP = 47,
|
||||
BINDNAME = 48,
|
||||
THROW = 49,
|
||||
IN = 50,
|
||||
INSTANCEOF = 51,
|
||||
LOCAL_SAVE = 52,
|
||||
LOCAL_LOAD = 53,
|
||||
GETVAR = 54,
|
||||
SETVAR = 55,
|
||||
CATCH_SCOPE = 56,
|
||||
ENUM_INIT = 57,
|
||||
ENUM_NEXT = 58,
|
||||
ENUM_ID = 59,
|
||||
THISFN = 60,
|
||||
RETURN_RESULT = 61, // to return prevoisly stored return result
|
||||
ARRAYLIT = 62, // array literal
|
||||
OBJECTLIT = 63, // object literal
|
||||
GET_REF = 64, // *reference
|
||||
SET_REF = 65, // *reference = something
|
||||
REF_CALL = 66, // f(args) = something or f(args)++
|
||||
SPECIAL_REF = 67, // reference for special properties like __proto
|
||||
GENERIC_REF = 68, // generic reference to generate runtime ref errors
|
||||
|
||||
LAST_BYTECODE_TOKEN = 70,
|
||||
LAST_BYTECODE_TOKEN = 68,
|
||||
// End of interpreter bytecodes
|
||||
|
||||
TRY = 71,
|
||||
SEMI = 72, // semicolon
|
||||
LB = 73, // left and right brackets
|
||||
RB = 74,
|
||||
LC = 75, // left and right curlies (braces)
|
||||
RC = 76,
|
||||
LP = 77, // left and right parentheses
|
||||
RP = 78,
|
||||
COMMA = 79, // comma operator
|
||||
ASSIGN = 80, // simple assignment (=)
|
||||
ASSIGNOP = 81, // assignment with operation (+= -= etc.)
|
||||
HOOK = 82, // conditional (?:)
|
||||
COLON = 83,
|
||||
OR = 84, // logical or (||)
|
||||
AND = 85, // logical and (&&)
|
||||
INC = 86, // increment/decrement (++ --)
|
||||
DEC = 87,
|
||||
DOT = 88, // member operator (.)
|
||||
FUNCTION = 89, // function keyword
|
||||
EXPORT = 90, // export keyword
|
||||
IMPORT = 91, // import keyword
|
||||
IF = 92, // if keyword
|
||||
ELSE = 93, // else keyword
|
||||
SWITCH = 94, // switch keyword
|
||||
CASE = 95, // case keyword
|
||||
DEFAULT = 96, // default keyword
|
||||
WHILE = 97, // while keyword
|
||||
DO = 98, // do keyword
|
||||
FOR = 99, // for keyword
|
||||
BREAK = 100, // break keyword
|
||||
CONTINUE = 101, // continue keyword
|
||||
VAR = 102, // var keyword
|
||||
WITH = 103, // with keyword
|
||||
CATCH = 104, // catch keyword
|
||||
FINALLY = 105, // finally keyword
|
||||
VOID = 106, // void keyword
|
||||
RESERVED = 107, // reserved keywords
|
||||
TRY = 69,
|
||||
SEMI = 70, // semicolon
|
||||
LB = 71, // left and right brackets
|
||||
RB = 72,
|
||||
LC = 73, // left and right curlies (braces)
|
||||
RC = 74,
|
||||
LP = 75, // left and right parentheses
|
||||
RP = 76,
|
||||
COMMA = 77, // comma operator
|
||||
ASSIGN = 78, // simple assignment (=)
|
||||
ASSIGNOP = 79, // assignment with operation (+= -= etc.)
|
||||
HOOK = 80, // conditional (?:)
|
||||
COLON = 81,
|
||||
OR = 82, // logical or (||)
|
||||
AND = 83, // logical and (&&)
|
||||
INC = 84, // increment/decrement (++ --)
|
||||
DEC = 85,
|
||||
DOT = 86, // member operator (.)
|
||||
FUNCTION = 87, // function keyword
|
||||
EXPORT = 88, // export keyword
|
||||
IMPORT = 89, // import keyword
|
||||
IF = 90, // if keyword
|
||||
ELSE = 91, // else keyword
|
||||
SWITCH = 92, // switch keyword
|
||||
CASE = 93, // case keyword
|
||||
DEFAULT = 94, // default keyword
|
||||
WHILE = 95, // while keyword
|
||||
DO = 96, // do keyword
|
||||
FOR = 97, // for keyword
|
||||
BREAK = 98, // break keyword
|
||||
CONTINUE = 99, // continue keyword
|
||||
VAR = 100, // var keyword
|
||||
WITH = 101, // with keyword
|
||||
CATCH = 102, // catch keyword
|
||||
FINALLY = 103, // finally keyword
|
||||
VOID = 104, // void keyword
|
||||
RESERVED = 105, // reserved keywords
|
||||
|
||||
EMPTY = 108,
|
||||
EMPTY = 106,
|
||||
|
||||
/* types used for the parse tree - these never get returned
|
||||
* by the scanner.
|
||||
*/
|
||||
|
||||
BLOCK = 109, // statement block
|
||||
LABEL = 110, // label
|
||||
TARGET = 111,
|
||||
LOOP = 112,
|
||||
EXPR_VOID = 113, // expression statement in functions
|
||||
EXPR_RESULT = 114, // expression statement in scripts
|
||||
JSR = 115,
|
||||
SCRIPT = 116, // top-level node for entire script
|
||||
TYPEOFNAME = 117, // for typeof(simple-name)
|
||||
USE_STACK = 118,
|
||||
SETPROP_OP = 119, // x.y op= something
|
||||
SETELEM_OP = 120, // x[y] op= something
|
||||
LOCAL_BLOCK = 121,
|
||||
SET_REF_OP = 122, // *reference op= something
|
||||
BLOCK = 107, // statement block
|
||||
LABEL = 108, // label
|
||||
TARGET = 109,
|
||||
LOOP = 110,
|
||||
EXPR_VOID = 111, // expression statement in functions
|
||||
EXPR_RESULT = 112, // expression statement in scripts
|
||||
JSR = 113,
|
||||
SCRIPT = 114, // top-level node for entire script
|
||||
TYPEOFNAME = 115, // for typeof(simple-name)
|
||||
USE_STACK = 116,
|
||||
SETPROP_OP = 117, // x.y op= something
|
||||
SETELEM_OP = 118, // x[y] op= something
|
||||
LOCAL_BLOCK = 119,
|
||||
SET_REF_OP = 120, // *reference op= something
|
||||
|
||||
LAST_TOKEN = 122;
|
||||
LAST_TOKEN = 120;
|
||||
|
||||
public static String name(int token)
|
||||
{
|
||||
@ -260,8 +258,6 @@ public class Token
|
||||
case NAME: return "NAME";
|
||||
case NUMBER: return "NUMBER";
|
||||
case STRING: return "STRING";
|
||||
case ZERO: return "ZERO";
|
||||
case ONE: return "ONE";
|
||||
case NULL: return "NULL";
|
||||
case THIS: return "THIS";
|
||||
case FALSE: return "FALSE";
|
||||
|
Loading…
Reference in New Issue
Block a user