use of dyvilx.tools.compiler.ast.type.compound.TupleType in project Dyvil by Dyvil.
the class TupleExpr method getType.
@Override
public IType getType() {
if (this.tupleType != null) {
return this.tupleType;
}
final int arity = this.values.size();
final TupleType tupleType = new TupleType(arity);
final TypeList arguments = tupleType.getArguments();
for (int i = 0; i < arity; i++) {
arguments.add(this.values.get(i).getType());
}
return this.tupleType = tupleType;
}
use of dyvilx.tools.compiler.ast.type.compound.TupleType in project Dyvil by Dyvil.
the class CaseClassMetadata method getUnapplyReturnType.
private TupleType getUnapplyReturnType() {
final TupleType returnType = new TupleType();
final TypeList typeArgs = returnType.getArguments();
for (IParameter param : this.theClass.getParameters()) {
typeArgs.add(param.getType());
}
return returnType;
}
use of dyvilx.tools.compiler.ast.type.compound.TupleType in project Dyvil by Dyvil.
the class TupleSurrogate method getType.
@Override
public IType getType() {
if (this.tupleType != null) {
return this.tupleType;
}
final TupleType tupleType = new TupleType(this.patternCount);
final TypeList arguments = tupleType.getArguments();
for (int i = 0; i < this.patternCount; i++) {
arguments.add(this.patterns[i].getType());
}
return this.tupleType = tupleType;
}
use of dyvilx.tools.compiler.ast.type.compound.TupleType 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.TupleType in project Dyvil by Dyvil.
the class UnapplyPattern method writeJumpOnMismatch.
// Compilation
@Override
public void writeJumpOnMismatch(MethodWriter writer, int varIndex, Label target) throws BytecodeException {
Pattern.loadVar(writer, varIndex);
final int lineNumer = this.lineNumber();
final int tupleVarIndex = writer.localCount();
this.unapplyCall.writeExpression(writer, null);
final IType methodType = this.unapplyCall.getType();
final String internalType = methodType.getInternalName();
final TupleType tupleType = NullableType.unapply(methodType).extract(TupleType.class);
final TypeList typeArgs = tupleType.getArguments();
if (// nullable
methodType != tupleType) {
writer.visitInsn(Opcodes.DUP);
writer.visitVarInsn(Opcodes.ASTORE, tupleVarIndex);
writer.visitJumpInsn(Opcodes.IFNULL, target);
} else {
writer.visitVarInsn(Opcodes.ASTORE, tupleVarIndex);
}
for (int i = 0; i < this.patternCount; i++) {
if (this.patterns[i].isWildcard()) {
// Skip wildcard patterns
continue;
}
final IType targetType = typeArgs.get(i);
writer.visitVarInsn(Opcodes.ALOAD, tupleVarIndex);
// Get and cast the tuple element
// FIXME not ready for Tuple.OfN
writer.visitFieldInsn(Opcodes.GETFIELD, internalType, "_" + (i + 1), "Ljava/lang/Object;");
Types.OBJECT.writeCast(writer, targetType, lineNumer);
// Check the pattern
this.patterns[i].writeJumpOnMismatch(writer, -1, target);
}
}
Aggregations