use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method defaultConstructor.
private void defaultConstructor(MethodName superConstructor, MethodName runtimeInfo) {
MethodCode constructor = code.newConstructor(Modifier.PUBLIC, MethodDescriptors.DefaultConstructor);
InstructionVisitor mv = new InstructionVisitor(constructor);
mv.begin();
mv.loadThis();
mv.loadParameter(0, Types.Source);
mv.invoke(runtimeInfo);
mv.invoke(superConstructor);
mv._return();
mv.end();
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class ExpressionGenerator method expressionMethod.
private OutlinedCall expressionMethod(ExpressionMethod node, CodeVisitor mv) {
MethodTypeDescriptor methodDescriptor = ExpressionMethodVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "expr", methodDescriptor);
return outlined(new ExpressionMethodVisitor(node, method, mv), body -> {
ValType type = node.getExpression().accept(this, body);
assert type != ValType.Empty;
body.storeCompletionValue(type);
return Completion.Normal;
});
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class ExpressionGenerator method objectMethodDecorators.
private MethodName objectMethodDecorators(ObjectLiteral node, CodeVisitor parent) {
MethodTypeDescriptor descriptor = ObjectMethodDecoratorsVisitor.methodDescriptor();
MethodCode method = codegen.method(parent, "objectdecorators", descriptor);
ObjectMethodDecoratorsVisitor mv = new ObjectMethodDecoratorsVisitor(method);
mv.begin();
Variable<ExecutionContext> cx = mv.getExecutionContext();
Variable<OrdinaryObject> object = mv.getObject();
// List of <1..n callable, property key>.
Variable<Object[]> decorators = mv.getDecorators();
Variable<Object> propertyKey = mv.newVariable("propertyKey", Object.class);
Variable<Object> propertyDesc = mv.newVariable("propertyDesc", Object.class);
Variable<Object> result = mv.newVariable("result", Object.class);
int index = 0;
for (MethodDefinition methodDef : DecoratedMethods(node.getProperties())) {
List<Expression> decoratorsList = methodDef.getDecorators();
assert !decoratorsList.isEmpty();
mv.store(propertyKey, mv.arrayElement(decorators, index + decoratorsList.size(), Object.class));
mv.lineInfo(methodDef);
mv.invoke(Methods.DecoratorOperations_propertyDescriptor, object, propertyKey, cx);
mv.store(propertyDesc);
for (Expression decoratorExpr : decoratorsList) {
Value<Object> decorator = mv.arrayElement(decorators, index++, Object.class);
invokeDynamicCall(mv, decoratorExpr, decorator, cx, mv.undefinedValue(), object, propertyKey, propertyDesc);
mv.store(result);
Jump isObject = new Jump();
mv.invoke(Methods.Type_isObject, result);
mv.ifeq(isObject);
{
mv.store(propertyDesc, result);
}
mv.mark(isObject);
}
Jump isObject = new Jump();
mv.invoke(Methods.Type_isObject, propertyDesc);
mv.ifeq(isObject);
{
mv.lineInfo(methodDef);
mv.invoke(Methods.DecoratorOperations_defineProperty, object, propertyKey, propertyDesc, cx);
}
mv.mark(isObject);
// Skip over property key element.
index += 1;
}
mv._return();
mv.end();
return method.name();
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class ExpressionGenerator method templateLiteral.
private MethodName templateLiteral(TemplateLiteral node) {
MethodCode method = codegen.method("!template", Type.methodType(Types.String_));
InstructionVisitor body = new InstructionVisitor(method);
body.lineInfo(node);
body.begin();
List<TemplateCharacters> strings = TemplateStrings(node);
body.anewarray(strings.size() * 2, Types.String);
for (int i = 0, size = strings.size(); i < size; ++i) {
TemplateCharacters e = strings.get(i);
int index = i << 1;
body.astore(index, e.getValue());
body.astore(index + 1, e.getRawValue());
}
body._return();
body.end();
return method.name();
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class FunctionCodeGenerator method generateClassCall.
private void generateClassCall(ClassDefinition node) {
MethodDefinition constructor = node.getConstructor();
MethodDefinition callConstructor = node.getCallConstructor();
MethodCode method = codegen.newMethod(constructor, FunctionName.Call);
InstructionVisitor mv = new CallMethodGenerator(method, targetName(constructor), targetType(constructor));
mv.lineInfo(callConstructor);
mv.begin();
generateFunctionCall(callConstructor, OrdinaryConstructorFunction.class, mv);
mv.end();
}
Aggregations