use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method compile.
MethodName compile(MethodDefinitionsMethod node, boolean hasDecorators, CodeVisitor mv) {
if (!isCompiled(node)) {
MethodCode method = newMethod(node);
MethodDefinitionsCodeVisitor body = new MethodDefinitionsCodeVisitor(node, method, mv);
body.lineInfo(node);
body.begin();
Variable<OrdinaryConstructorFunction> function = body.getFunctionParameter();
Variable<OrdinaryObject> proto = body.getPrototypeParameter();
Variable<ArrayList<Object>> decorators = hasDecorators ? body.getDecoratorsParameter() : null;
ClassPropertyEvaluation(this, node.getProperties(), function, proto, decorators, body);
body._return();
body.end();
}
return methodDesc(node);
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class GlobalDeclarationInstantiationGenerator method generate.
void generate(Script script) {
MethodCode method = codegen.newMethod(script, ScriptName.Init);
InstructionVisitor mv = new GlobalDeclInitMethodGenerator(method);
mv.lineInfo(script);
mv.begin();
if (VarDeclaredNames(script).isEmpty() && LexicallyDeclaredNames(script).isEmpty() && !hasBlockFunctions(script)) {
mv._return();
} else {
generate(script, mv);
}
mv.end();
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class ExternConstantPool method newMethod.
private <T> ConstantClassAssembler newMethod(String methodName, TypeSpec<T> spec) {
int modifier = Modifier.PUBLIC | Modifier.STATIC;
MethodCode method = classCode.newMethod(modifier, methodName, spec.methodDescriptor, null, null);
return new ConstantClassAssembler(method);
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class SwitchStatementGenerator method caseSelect.
/**
* Generates a case-select method.
*
* @param caseBlock
* the case-block
* @param switchVarType
* the switch-var type
* @param mv
* the code visitor
* @return the outlined-call object
*/
private OutlinedCall caseSelect(SwitchStatementGenerator.CaseBlock caseBlock, Type switchVarType, CodeVisitor mv) {
SwitchClause firstClause = caseBlock.clauses.get(0);
MethodTypeDescriptor methodDescriptor = SwitchSelectCodeVisitor.methodDescriptor(switchVarType, mv);
MethodCode method = codegen.method(mv, "select", methodDescriptor);
return outlined(new SwitchSelectCodeVisitor(firstClause, method, mv), body -> {
Variable<?> switchValue = body.getSwitchValueParameter();
MutableValue<Integer> switchTarget = body.iarrayElement(body.getSwitchTargetParameter(), 0);
List<SwitchClause> clauses = caseBlock.clauses;
int[] switchTargets = caseBlock.switchTargets;
int numTargets = caseBlock.numTargets();
Jump[] targetLabels = new Jump[numTargets];
for (int i = 0; i < targetLabels.length; ++i) {
targetLabels[i] = new Jump();
}
Jump lblExit = new Jump();
Jump[] labels = new Jump[clauses.size()];
for (int i = 0; i < clauses.size(); ++i) {
labels[i] = targetLabels[switchTargets[i] - 1];
}
caseSelector(SwitchType.of(clauses)).select(clauses, switchValue, labels, lblExit, body);
Jump setSwitchTarget = new Jump();
for (int i = 0; i < targetLabels.length; ++i) {
// targetLabels[i] is not reachable if only used by the default clause.
if (targetLabels[i].isTarget()) {
body.mark(targetLabels[i]);
body.iconst(i + 1);
body.goTo(setSwitchTarget);
}
}
if (setSwitchTarget.isTarget()) {
// stack: [newSwitchTarget] -> []
body.mark(setSwitchTarget);
body.store(switchTarget);
}
body.mark(lblExit);
return Completion.Normal;
});
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class SwitchStatementGenerator method defaultCaseBlock.
/**
* Generates a case-block method.
*
* @param caseBlock
* the case-block
* @param mv
* the code visitor
* @return the outlined-call object
*/
private OutlinedCall defaultCaseBlock(SwitchStatementGenerator.CaseBlock caseBlock, CodeVisitor mv) {
SwitchClause firstClause = caseBlock.clauses.get(0);
MethodTypeDescriptor methodDescriptor = DefaultSwitchBlockCodeVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "case", methodDescriptor);
return outlined(new DefaultSwitchBlockCodeVisitor(firstClause, method, mv), body -> {
Completion lastResult = Completion.Normal;
for (SwitchClause clause : caseBlock.clauses) {
lastResult = clause.accept(this, body);
if (lastResult.isAbrupt()) {
break;
}
}
return lastResult;
});
}
Aggregations