Search in sources :

Example 1 with LambdaType

use of dyvilx.tools.compiler.ast.type.compound.LambdaType in project Dyvil by Dyvil.

the class LambdaExpr method makeType.

@NonNull
private LambdaType makeType() {
    final int count = this.parameters.size();
    final LambdaType lambdaType = new LambdaType();
    final TypeList arguments = lambdaType.getArguments();
    for (int i = 0; i < count; i++) {
        arguments.add(this.parameters.get(i).getType());
    }
    arguments.add(this.returnType != null ? this.returnType : Types.UNKNOWN);
    this.flags |= LAMBDA_TYPE_INFERRED;
    return lambdaType;
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) TypeList(dyvilx.tools.compiler.ast.type.TypeList) NonNull(dyvil.annotation.internal.NonNull)

Example 2 with LambdaType

use of dyvilx.tools.compiler.ast.type.compound.LambdaType in project Dyvil by Dyvil.

the class InternalGenericType method resolveType.

@Override
public IType resolveType(MarkerList markers, IContext context) {
    this.arguments.resolveTypes(markers, context);
    if (this.internalName.startsWith("dyvil/tuple/Tuple$Of")) {
        return new TupleType(this.arguments);
    }
    if (this.internalName.startsWith("dyvil/function/Function$Of")) {
        return new LambdaType(this.arguments);
    }
    switch(this.internalName) {
        case "dyvil/ref/ObjectRef":
            return new ReferenceType(ReferenceType.LazyFields.OBJECT_REF_CLASS, this.arguments.get(0));
        case "dyvil/collection/Map":
            return MapType.base(this.arguments.get(0), this.arguments.get(1));
        case "dyvil/collection/MutableMap":
            return MapType.mutable(this.arguments.get(0), this.arguments.get(1));
        case "dyvil/collection/ImmutableMap":
            return MapType.immutable(this.arguments.get(0), this.arguments.get(1));
    }
    final IClass iclass = Package.rootPackage.resolveInternalClass(this.internalName);
    return new ClassGenericType(iclass, this.arguments);
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) TupleType(dyvilx.tools.compiler.ast.type.compound.TupleType) IClass(dyvilx.tools.compiler.ast.classes.IClass) ReferenceType(dyvilx.tools.compiler.ast.reference.ReferenceType)

Example 3 with LambdaType

use of dyvilx.tools.compiler.ast.type.compound.LambdaType 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 4 with LambdaType

use of dyvilx.tools.compiler.ast.type.compound.LambdaType in project Dyvil by Dyvil.

the class AbstractParameter method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context) {
    if (this.method != null && this.method.hasModifier(Modifiers.GENERATED)) {
        this.attributes.addFlag(Modifiers.GENERATED);
    }
    super.resolveTypes(markers, context);
    if (this.value != null) {
        this.value.resolveTypes(markers, context);
    }
    this.covariantType = null;
    final LambdaType functionType;
    if (this.type != null && (functionType = this.type.extract(LambdaType.class)) != null) {
        if (functionType.isExtension()) {
            this.attributes.addFlag(Modifiers.INFIX_FLAG);
        } else if (this.attributes.hasFlag(Modifiers.INFIX_FLAG)) {
            functionType.setExtension(true);
        }
    }
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType)

Aggregations

LambdaType (dyvilx.tools.compiler.ast.type.compound.LambdaType)4 NonNull (dyvil.annotation.internal.NonNull)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 LambdaExpr (dyvilx.tools.compiler.ast.expression.LambdaExpr)1 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)1 IMethod (dyvilx.tools.compiler.ast.method.IMethod)1 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)1 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)1 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)1 ReferenceType (dyvilx.tools.compiler.ast.reference.ReferenceType)1 TypeList (dyvilx.tools.compiler.ast.type.TypeList)1 TupleType (dyvilx.tools.compiler.ast.type.compound.TupleType)1