use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method moduleBody.
private void moduleBody(Module node) {
MethodCode method = newMethod(node, ModuleName.Code);
ModuleCodeVisitor body = new ModuleCodeVisitor(method, node);
body.lineInfo(node);
body.begin();
body.enterScope(node);
Completion result = statements(node.getStatements(), body);
body.exitScope();
if (!result.isAbrupt()) {
// Completion values are currently ignored for module code.
body.loadUndefined();
body._return();
}
body.end();
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method generatorBody.
private boolean generatorBody(FunctionNode node) {
MethodCode method = newMethod(node, FunctionName.Code);
GeneratorCodeVisitor body = new GeneratorCodeVisitor(method, node);
body.lineInfo(node);
body.begin();
GeneratorState generatorState = body.generatorPrologue();
body.enterFunction(node);
Completion result = statements(node.getStatements(), body);
body.exitFunction();
if (!result.isAbrupt()) {
// fall-thru, return undefined from function
body.loadUndefined();
body._return();
}
body.generatorEpilogue(generatorState);
body.end();
return body.hasTailCalls();
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method publicStaticMethod.
private MethodCode publicStaticMethod(String methodName, MethodTypeDescriptor methodDescriptor) {
final int access = Modifier.PUBLIC | Modifier.STATIC;
MethodCode method = code.newMethod(access, methodName, methodDescriptor);
// System.out.printf("add <%s, %s>%n", methodName, method.classCode.className);
assert !methodClasses.containsKey(methodName) : String.format("method '%s' already compiled", methodName);
methodClasses.put(methodName, method.classCode.classType);
return method;
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class SwitchStatementGenerator method caseBlock.
/**
* Generates a case-block method.
*
* @param caseBlock
* the case-block
* @param mv
* the code visitor
* @return the outlined-call object
*/
private OutlinedCall caseBlock(SwitchStatementGenerator.CaseBlock caseBlock, CodeVisitor mv) {
SwitchClause firstClause = caseBlock.clauses.get(0);
MethodTypeDescriptor methodDescriptor = SwitchBlockCodeVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "case", methodDescriptor);
return outlined(new SwitchBlockCodeVisitor(firstClause, method, mv), body -> {
Variable<Integer> switchTarget = body.getSwitchTargetParameter();
List<SwitchClause> clauses = caseBlock.clauses;
int[] switchTargets = caseBlock.switchTargets;
int numTargets = caseBlock.numTargets();
Completion lastResult = Completion.Normal;
if (numTargets > 1) {
Jump[] labels = new Jump[numTargets];
for (int i = 0; i < labels.length; ++i) {
labels[i] = new Jump();
}
Jump defaultInstr = new Jump();
body.load(switchTarget);
body.tableswitch(1, numTargets, defaultInstr, labels);
body.mark(defaultInstr);
for (int i = 0, lastTarget = 0; i < clauses.size(); ++i) {
if (lastTarget != switchTargets[i]) {
lastTarget = switchTargets[i];
body.mark(labels[lastTarget - 1]);
}
lastResult = clauses.get(i).accept(this, body);
}
} else {
for (SwitchClause clause : clauses) {
lastResult = clause.accept(this, body);
}
}
return lastResult;
});
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class ClassPropertyGenerator method methodDefinitions.
private OutlinedCall methodDefinitions(MethodDefinitionsMethod node, CodeVisitor mv) {
MethodTypeDescriptor methodDescriptor = MethodDefinitionsCodeVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "mdef", methodDescriptor);
return outlined(new MethodDefinitionsCodeVisitor(node, method, mv), body -> {
Variable<OrdinaryConstructorFunction> function = body.getFunctionParameter();
Variable<OrdinaryObject> proto = body.getPrototypeParameter();
StoreToArray<Object> staticFields = this.staticFields.from(body.getStaticFieldsParameter());
StoreToArray<Object> instanceFields = this.instanceFields.from(body.getInstanceFieldsParameter());
StoreToArray<InstanceMethod> instanceMethods = this.instanceMethods.from(body.getInstanceMethodsParameter());
StoreToArray<Object> decorators = this.decorators.from(body.getDecoratorsParameter());
ClassPropertyEvaluation(codegen, classDefinition, node.getProperties(), function, proto, staticFields, instanceFields, instanceMethods, decorators, body);
return Completion.Normal;
});
}
Aggregations