Class CodeGenerator
java.lang.Object
org.mozilla.javascript.Icode
org.mozilla.javascript.CodeGenerator
Generates bytecode for the Interpreter.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ObjToIntMap
private CompilerEnvirons
private int
private static final int
private int
private long[]
private int
private int
private InterpreterData
private boolean
private boolean
private int[]
private int
private int
private ObjArray
private int
private static final int
private static final int
private ScriptNode
private int
private ObjToIntMap
Fields inherited from class Icode
Icode_CALLSPECIAL, Icode_CLOSURE_EXPR, Icode_CLOSURE_STMT, Icode_DEBUGGER, Icode_DELNAME, Icode_DUP, Icode_DUP2, Icode_ELEM_AND_THIS, Icode_ELEM_INC_DEC, Icode_ENTERDQ, Icode_GENERATOR, Icode_GENERATOR_END, Icode_GENERATOR_RETURN, Icode_GETVAR1, Icode_GOSUB, Icode_IFEQ_POP, Icode_INTNUMBER, Icode_LEAVEDQ, Icode_LINE, Icode_LITERAL_GETTER, Icode_LITERAL_NEW, Icode_LITERAL_SET, Icode_LITERAL_SETTER, Icode_LOCAL_CLEAR, Icode_NAME_AND_THIS, Icode_NAME_INC_DEC, Icode_ONE, Icode_POP, Icode_POP_RESULT, Icode_PROP_AND_THIS, Icode_PROP_INC_DEC, Icode_REF_INC_DEC, Icode_REG_BIGINT_C0, Icode_REG_BIGINT_C1, Icode_REG_BIGINT_C2, Icode_REG_BIGINT_C3, Icode_REG_BIGINT1, Icode_REG_BIGINT2, Icode_REG_BIGINT4, Icode_REG_IND_C0, Icode_REG_IND_C1, Icode_REG_IND_C2, Icode_REG_IND_C3, Icode_REG_IND_C4, Icode_REG_IND_C5, Icode_REG_IND1, Icode_REG_IND2, Icode_REG_IND4, Icode_REG_STR_C0, Icode_REG_STR_C1, Icode_REG_STR_C2, Icode_REG_STR_C3, Icode_REG_STR1, Icode_REG_STR2, Icode_REG_STR4, Icode_RETSUB, Icode_RETUNDEF, Icode_SCOPE_LOAD, Icode_SCOPE_SAVE, Icode_SETCONST, Icode_SETCONSTVAR, Icode_SETCONSTVAR1, Icode_SETVAR1, Icode_SHORTNUMBER, Icode_SPARE_ARRAYLIT, Icode_STARTSUB, Icode_SWAP, Icode_TAIL_CALL, Icode_TEMPLATE_LITERAL_CALLSITE, Icode_TYPEOFNAME, Icode_UNDEF, Icode_VALUE_AND_THIS, Icode_VAR_INC_DEC, Icode_YIELD_STAR, Icode_ZERO, MIN_ICODE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addBackwardGoto
(int gotoOp, int jumpPC) private void
private void
addExceptionHandler
(int icodeStart, int icodeEnd, int handlerStart, boolean isFinally, int exceptionObjectLocal, int scopeLocal) private void
private void
addGotoOp
(int gotoOp) private void
addIcode
(int icode) private void
addIndexOp
(int op, int index) private void
addIndexPrefix
(int index) private void
addInt
(int i) private void
addStringOp
(int op, String str) private void
addStringPrefix
(String str) private void
addToken
(int token) private void
addUint16
(int value) private void
addUint8
(int value) private void
addVarOp
(int op, int varIndex) private int
private static RuntimeException
compile
(CompilerEnvirons compilerEnv, ScriptNode tree, String encodedSource, boolean returnFunction) private void
private void
generateCallFunAndThis
(Node left) private void
private void
generateICodeFromTree
(Node tree) private void
private void
private void
private int
getDoubleIndex
(double num) private static int
getLocalBlockRef
(Node node) private int
getTargetLabel
(Node target) private byte[]
increaseICodeCapacity
(int extraSize) private void
markTargetLabel
(Node target) private void
releaseLocal
(int localSlot) private void
resolveForwardGoto
(int fromPC) private void
resolveGoto
(int fromPC, int jumpPC) private void
stackChange
(int change) private void
updateLineNumber
(Node node) private void
visitArrayComprehension
(Node node, Node initStmt, Node expr) private void
visitExpression
(Node node, int contextFlags) private void
visitIncDec
(Node node, Node child) private void
visitLiteral
(Node node, Node child) private void
visitStatement
(Node node, int initialStackDepth) private void
visitTemplateLiteral
(Node node) Methods inherited from class Icode
bytecodeName, validBytecode, validIcode, validTokenCode
-
Field Details
-
MIN_LABEL_TABLE_SIZE
private static final int MIN_LABEL_TABLE_SIZE- See Also:
-
MIN_FIXUP_TABLE_SIZE
private static final int MIN_FIXUP_TABLE_SIZE- See Also:
-
compilerEnv
-
itsInFunctionFlag
private boolean itsInFunctionFlag -
itsInTryFlag
private boolean itsInTryFlag -
itsData
-
scriptOrFn
-
iCodeTop
private int iCodeTop -
stackDepth
private int stackDepth -
lineNumber
private int lineNumber -
doubleTableTop
private int doubleTableTop -
strings
-
bigInts
-
localTop
private int localTop -
labelTable
private int[] labelTable -
labelTableTop
private int labelTableTop -
fixupTable
private long[] fixupTable -
fixupTableTop
private int fixupTableTop -
literalIds
-
exceptionTableTop
private int exceptionTableTop -
ECF_TAIL
private static final int ECF_TAIL- See Also:
-
-
Constructor Details
-
CodeGenerator
CodeGenerator()
-
-
Method Details
-
compile
public InterpreterData compile(CompilerEnvirons compilerEnv, ScriptNode tree, String encodedSource, boolean returnFunction) -
generateFunctionICode
private void generateFunctionICode() -
generateICodeFromTree
-
generateNestedFunctions
private void generateNestedFunctions() -
generateRegExpLiterals
private void generateRegExpLiterals() -
generateTemplateLiterals
private void generateTemplateLiterals() -
updateLineNumber
-
badTree
-
visitStatement
-
visitExpression
-
generateCallFunAndThis
-
visitIncDec
-
visitLiteral
-
visitTemplateLiteral
-
visitArrayComprehension
-
getLocalBlockRef
-
getTargetLabel
-
markTargetLabel
-
addGoto
-
fixLabelGotos
private void fixLabelGotos() -
addBackwardGoto
private void addBackwardGoto(int gotoOp, int jumpPC) -
resolveForwardGoto
private void resolveForwardGoto(int fromPC) -
resolveGoto
private void resolveGoto(int fromPC, int jumpPC) -
addToken
private void addToken(int token) -
addIcode
private void addIcode(int icode) -
addUint8
private void addUint8(int value) -
addUint16
private void addUint16(int value) -
addInt
private void addInt(int i) -
getDoubleIndex
private int getDoubleIndex(double num) -
addGotoOp
private void addGotoOp(int gotoOp) -
addVarOp
private void addVarOp(int op, int varIndex) -
addStringOp
-
addIndexOp
private void addIndexOp(int op, int index) -
addStringPrefix
-
addBigInt
-
addIndexPrefix
private void addIndexPrefix(int index) -
addExceptionHandler
private void addExceptionHandler(int icodeStart, int icodeEnd, int handlerStart, boolean isFinally, int exceptionObjectLocal, int scopeLocal) -
increaseICodeCapacity
private byte[] increaseICodeCapacity(int extraSize) -
stackChange
private void stackChange(int change) -
allocLocal
private int allocLocal() -
releaseLocal
private void releaseLocal(int localSlot)
-