Search in sources :

Example 26 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class CodeMethod method writeBridgeParameters.

private void writeBridgeParameters(MethodWriter methodWriter, IMethod overrideMethod) {
    final int lineNumber = this.lineNumber();
    final ParameterList overrideParameterList = overrideMethod.getParameters();
    for (int p = 0, count = overrideParameterList.size(); p < count; p++) {
        final IParameter overrideParameter = overrideParameterList.get(p);
        final IType parameterType = this.parameters.get(p).getCovariantType();
        final IType overrideParameterType = overrideParameter.getCovariantType();
        overrideParameter.writeParameter(methodWriter);
        methodWriter.visitVarInsn(overrideParameterType.getLoadOpcode(), overrideParameter.getLocalIndex());
        overrideParameterType.writeCast(methodWriter, parameterType, lineNumber);
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IType(dyvilx.tools.compiler.ast.type.IType)

Example 27 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class Closure method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (this.resolved) {
        return super.withType(type, typeContext, markers, context);
    }
    final IMethod functionalMethod = type.getFunctionalMethod();
    if (functionalMethod == null) {
        return null;
    }
    final ParameterList parameterList = functionalMethod.getParameters();
    final int parameterCount = parameterList.size();
    final IParameter[] parameters = new IParameter[parameterCount];
    for (int i = 0; i < parameterCount; i++) {
        parameters[i] = new CodeParameter(null, this.position, Name.fromRaw("$" + i), Types.UNKNOWN);
    }
    final LambdaType functionType = type.extract(LambdaType.class);
    if (functionType != null && functionType.isExtension() && parameterCount > 0) {
        this.implicitValue = new FieldAccess(parameters[0]);
    }
    final LambdaExpr lambdaExpr = new LambdaExpr(this.position, parameters, parameterCount);
    lambdaExpr.setValue(this);
    this.resolved = true;
    context = context.push(this);
    final IValue typedLambda = lambdaExpr.withType(type, typeContext, markers, context);
    context.pop();
    return typedLambda;
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) LambdaExpr(dyvilx.tools.compiler.ast.expression.LambdaExpr) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IMethod(dyvilx.tools.compiler.ast.method.IMethod) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter)

Example 28 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class IntrinsicData method writeArgument.

static IType writeArgument(MethodWriter writer, IMethod method, int index, IValue receiver, ArgumentList arguments) throws BytecodeException {
    final ParameterList params = method.getParameters();
    if (receiver == null || receiver.isIgnoredClassAccess()) {
        final IParameter parameter = params.get(index);
        arguments.writeValue(index, parameter, writer);
        return parameter.getCovariantType();
    }
    if (index == 0) {
        final IType type = method.hasModifier(INFIX) ? params.get(0).getCovariantType() : method.getReceiverType();
        receiver.writeExpression(writer, type);
        return type;
    }
    final IParameter parameter = params.get(method.hasModifier(INFIX) ? index : index - 1);
    arguments.writeValue(index - 1, parameter, writer);
    return parameter.getCovariantType();
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)28 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)12 IType (dyvilx.tools.compiler.ast.type.IType)11 IValue (dyvilx.tools.compiler.ast.expression.IValue)9 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 SourcePosition (dyvil.source.position.SourcePosition)5 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)5 IClass (dyvilx.tools.compiler.ast.classes.IClass)4 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)4 LambdaExpr (dyvilx.tools.compiler.ast.expression.LambdaExpr)3 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)3 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)3 Name (dyvil.lang.Name)2 AnnotationVisitor (dyvilx.tools.asm.AnnotationVisitor)2 FieldAssignment (dyvilx.tools.compiler.ast.expression.access.FieldAssignment)2 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)2 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 Reified (dyvil.annotation.Reified)1 MethodVisitor (dyvilx.tools.asm.MethodVisitor)1