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);
}
Aggregations