Package org.htmlunit.corejs.javascript
Class CodeGenerator
- java.lang.Object
-
- org.htmlunit.corejs.javascript.Icode
-
- org.htmlunit.corejs.javascript.CodeGenerator
-
class CodeGenerator extends Icode
Generates bytecode for the Interpreter.
-
-
Field Summary
Fields Modifier and Type Field Description private ObjToIntMapbigIntsprivate CompilerEnvironscompilerEnvprivate intdoubleTableTopprivate static intECF_TAILprivate intexceptionTableTopprivate long[]fixupTableprivate intfixupTableTopprivate intiCodeTopprivate InterpreterDataitsDataprivate booleanitsInFunctionFlagprivate booleanitsInTryFlagprivate int[]labelTableprivate intlabelTableTopprivate intlineNumberprivate ObjArrayliteralIdsprivate intlocalTopprivate static intMIN_FIXUP_TABLE_SIZEprivate static intMIN_LABEL_TABLE_SIZEprivate ScriptNodescriptOrFnprivate intstackDepthprivate ObjToIntMapstrings-
Fields inherited from class org.htmlunit.corejs.javascript.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 Constructor Description CodeGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddBackwardGoto(int gotoOp, int jumpPC)private voidaddBigInt(java.math.BigInteger n)private voidaddExceptionHandler(int icodeStart, int icodeEnd, int handlerStart, boolean isFinally, int exceptionObjectLocal, int scopeLocal)private voidaddGoto(Node target, int gotoOp)private voidaddGotoOp(int gotoOp)private voidaddIcode(int icode)private voidaddIndexOp(int op, int index)private voidaddIndexPrefix(int index)private voidaddInt(int i)private voidaddStringOp(int op, java.lang.String str)private voidaddStringPrefix(java.lang.String str)private voidaddToken(int token)private voidaddUint16(int value)private voidaddUint8(int value)private voidaddVarOp(int op, int varIndex)private intallocLocal()private static java.lang.RuntimeExceptionbadTree(Node node)InterpreterDatacompile(CompilerEnvirons compilerEnv, ScriptNode tree, java.lang.String encodedSource, boolean returnFunction)private voidfixLabelGotos()private voidgenerateCallFunAndThis(Node left)private voidgenerateFunctionICode()private voidgenerateICodeFromTree(Node tree)private voidgenerateNestedFunctions()private voidgenerateRegExpLiterals()private voidgenerateTemplateLiterals()private intgetDoubleIndex(double num)private static intgetLocalBlockRef(Node node)private intgetTargetLabel(Node target)private byte[]increaseICodeCapacity(int extraSize)private voidmarkTargetLabel(Node target)private voidreleaseLocal(int localSlot)private voidresolveForwardGoto(int fromPC)private voidresolveGoto(int fromPC, int jumpPC)private voidstackChange(int change)private voidupdateLineNumber(Node node)private voidvisitArrayComprehension(Node node, Node initStmt, Node expr)private voidvisitExpression(Node node, int contextFlags)private voidvisitIncDec(Node node, Node child)private voidvisitLiteral(Node node, Node child)private voidvisitStatement(Node node, int initialStackDepth)private voidvisitTemplateLiteral(Node node)-
Methods inherited from class org.htmlunit.corejs.javascript.Icode
bytecodeName, validBytecode, validIcode, validTokenCode
-
-
-
-
Field Detail
-
MIN_LABEL_TABLE_SIZE
private static final int MIN_LABEL_TABLE_SIZE
- See Also:
- Constant Field Values
-
MIN_FIXUP_TABLE_SIZE
private static final int MIN_FIXUP_TABLE_SIZE
- See Also:
- Constant Field Values
-
compilerEnv
private CompilerEnvirons compilerEnv
-
itsInFunctionFlag
private boolean itsInFunctionFlag
-
itsInTryFlag
private boolean itsInTryFlag
-
itsData
private InterpreterData itsData
-
scriptOrFn
private ScriptNode scriptOrFn
-
iCodeTop
private int iCodeTop
-
stackDepth
private int stackDepth
-
lineNumber
private int lineNumber
-
doubleTableTop
private int doubleTableTop
-
strings
private ObjToIntMap strings
-
bigInts
private ObjToIntMap bigInts
-
localTop
private int localTop
-
labelTable
private int[] labelTable
-
labelTableTop
private int labelTableTop
-
fixupTable
private long[] fixupTable
-
fixupTableTop
private int fixupTableTop
-
literalIds
private ObjArray literalIds
-
exceptionTableTop
private int exceptionTableTop
-
ECF_TAIL
private static final int ECF_TAIL
- See Also:
- Constant Field Values
-
-
Method Detail
-
compile
public InterpreterData compile(CompilerEnvirons compilerEnv, ScriptNode tree, java.lang.String encodedSource, boolean returnFunction)
-
generateFunctionICode
private void generateFunctionICode()
-
generateICodeFromTree
private void generateICodeFromTree(Node tree)
-
generateNestedFunctions
private void generateNestedFunctions()
-
generateRegExpLiterals
private void generateRegExpLiterals()
-
generateTemplateLiterals
private void generateTemplateLiterals()
-
updateLineNumber
private void updateLineNumber(Node node)
-
badTree
private static java.lang.RuntimeException badTree(Node node)
-
visitStatement
private void visitStatement(Node node, int initialStackDepth)
-
visitExpression
private void visitExpression(Node node, int contextFlags)
-
generateCallFunAndThis
private void generateCallFunAndThis(Node left)
-
visitTemplateLiteral
private void visitTemplateLiteral(Node node)
-
getLocalBlockRef
private static int getLocalBlockRef(Node node)
-
getTargetLabel
private int getTargetLabel(Node target)
-
markTargetLabel
private void markTargetLabel(Node target)
-
addGoto
private void addGoto(Node target, int gotoOp)
-
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
private void addStringOp(int op, java.lang.String str)
-
addIndexOp
private void addIndexOp(int op, int index)
-
addStringPrefix
private void addStringPrefix(java.lang.String str)
-
addBigInt
private void addBigInt(java.math.BigInteger n)
-
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)
-
-