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;
}
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);
}
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;
}
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);
}
}
}
Aggregations