Search in sources :

Example 46 with Jump

use of com.github.anba.es6draft.compiler.assembler.Jump in project es6draft by anba.

the class SwitchStatementGenerator method emitGenericSwitch.

/**
     * <h3>Generic-switch</h3>
     * 
     * <pre>
     * switch (v) {
     * case key1: ...
     * case key2: ...
     * }
     * 
     * var $v = v;
     * if (strictEquals($v, key1)) goto L1
     * if (strictEquals($v, key2)) goto L2
     * goTo (default | break)
     * L1: ...
     * L2: ...
     * </pre>
     * 
     * @param clauses
     *            the switch clauses
     * @param labels
     *            the labels for each switch clause
     * @param defaultClause
     *            the label for the default clause
     * @param lblExit
     *            the exit label
     * @param switchValue
     *            the variable which holds the switch value
     * @param mv
     *            the code visitor
     */
private void emitGenericSwitch(List<SwitchClause> clauses, Jump[] labels, Jump defaultClause, Jump lblExit, Variable<?> switchValue, CodeVisitor mv) {
    assert switchValue.getType().equals(Types.Object);
    Jump switchDefault = defaultClause != null ? defaultClause : lblExit;
    int index = 0;
    for (SwitchClause switchClause : clauses) {
        Jump caseLabel = labels[index++];
        Expression expr = switchClause.getExpression();
        if (expr != null) {
            mv.load(switchValue);
            // 13.11.10 Runtime Semantics: CaseSelectorEvaluation
            expressionBoxed(expr, mv);
            invokeDynamicOperator(BinaryExpression.Operator.SHEQ, mv);
            mv.ifne(caseLabel);
        }
    }
    mv.goTo(switchDefault);
}
Also used : BinaryExpression(com.github.anba.es6draft.ast.BinaryExpression) UnaryExpression(com.github.anba.es6draft.ast.UnaryExpression) Expression(com.github.anba.es6draft.ast.Expression) SwitchClause(com.github.anba.es6draft.ast.SwitchClause) Jump(com.github.anba.es6draft.compiler.assembler.Jump)

Aggregations

Jump (com.github.anba.es6draft.compiler.assembler.Jump)46 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)14 Name (com.github.anba.es6draft.ast.scope.Name)10 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)9 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)9 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)8 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)7 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)7 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)7 ScriptName (com.github.anba.es6draft.compiler.CodeGenerator.ScriptName)6 BreakLabel (com.github.anba.es6draft.compiler.Labels.BreakLabel)6 TempLabel (com.github.anba.es6draft.compiler.Labels.TempLabel)6 Variable (com.github.anba.es6draft.compiler.assembler.Variable)6 EnvironmentRecord (com.github.anba.es6draft.runtime.EnvironmentRecord)6 ContinueLabel (com.github.anba.es6draft.compiler.Labels.ContinueLabel)5 Completion (com.github.anba.es6draft.compiler.StatementGenerator.Completion)5 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)4 FunctionDeclaration (com.github.anba.es6draft.ast.FunctionDeclaration)3 HoistableDeclaration (com.github.anba.es6draft.ast.HoistableDeclaration)3 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)3