use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class IParameter method visitAnnotation.
default AnnotationVisitor visitAnnotation(String internalType) {
if (this.skipAnnotation(internalType, null)) {
return null;
}
IType type = new InternalType(internalType);
Annotation annotation = new ExternalAnnotation(type);
return new AnnotationReader(this, annotation);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class IParameter method writeDefaultValue.
default void writeDefaultValue(ClassWriter writer) {
final IValue value = this.getValue();
assert value != null;
final ICallableMember method = this.getMethod();
final IType type = this.getType();
final String name;
final int access;
if (method == null) {
name = "init$paramDefault$" + this.getInternalName();
access = Modifiers.STATIC;
} else {
name = method.getInternalName() + "$paramDefault$" + this.getInternalName();
access = (method.getAttributes().flags() & Modifiers.MEMBER_MODIFIERS) | Modifiers.STATIC;
}
final String desc = "()" + this.getDescriptor();
final String signature = "()" + this.getSignature();
final MethodWriter mw = new MethodWriterImpl(writer, writer.visitMethod(access, name, desc, signature, null));
mw.visitCode();
value.writeExpression(mw, type);
mw.visitEnd(type);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class NamedArgumentList method writeValues.
@Override
public void writeValues(MethodWriter writer, ParameterList parameters, int startIndex) throws BytecodeException {
if (this.hasParameterOrder()) {
super.writeValues(writer, parameters, startIndex);
return;
}
final int locals = writer.localCount();
final int paramCount = parameters.size() - startIndex;
// Step 1: Associate parameters to arguments
final IParameter[] params = new IParameter[this.size];
for (int i = 0; i < paramCount; i++) {
final IParameter param = parameters.get(i + startIndex);
final int argIndex = this.findIndex(i, param.getLabel());
if (argIndex >= 0) {
params[argIndex] = param;
}
}
// Save the local indices in the targets array for later use
// Maps parameter index -> local index of stored argument
final int[] targets = new int[paramCount];
// Fill the array with -1s to mark missing values
Arrays.fill(targets, -1);
// Step 2: Write all arguments that already have parameter order
int argStartIndex = 0;
for (int i = 0; i < this.size; i++) {
IParameter param = params[i];
if (param.getIndex() == startIndex + i) {
this.values[i].writeExpression(writer, param.getCovariantType());
targets[i] = -2;
argStartIndex = i + 1;
} else {
break;
}
}
if (argStartIndex < this.size) {
for (int i = argStartIndex; i < this.size; i++) {
final IParameter parameter = params[i];
final IType parameterType = parameter.getCovariantType();
final IValue value = this.values[i];
final int localIndex = value.writeStore(writer, parameterType);
targets[parameter.getIndex() - startIndex] = localIndex;
}
// Step 4: Load the local variables in order
for (int i = 0; i < paramCount; i++) {
final IParameter parameter = parameters.get(i + startIndex);
final int target = targets[parameter.getIndex() - startIndex];
switch(target) {
case -1:
case -2:
// Value for parameter was already written in Step 2
continue;
default:
// Value for parameter exists -> load the variable
writer.visitVarInsn(parameter.getCovariantType().getLoadOpcode(), target);
}
}
}
writer.resetLocals(locals);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class ParameterList method matches.
public boolean matches(ParameterList other) {
final int len = other.size();
if (len != this.size) {
return false;
}
for (int i = 0; i < len; i++) {
final IType thisParameterType = this.parameters[i].getType();
final IType otherParameterType = other.get(i).getType();
if (!Types.isSameType(thisParameterType, otherParameterType)) {
return false;
}
}
return true;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class InlineIntrinsicData method preWrite.
private void preWrite(MethodWriter writer, IValue instance, ArgumentList arguments, int localCount) {
if (!this.preProcessed) {
this.preProcessed = true;
this.preProcess();
}
for (int i = 0; i < this.storedParameters; i++) {
final IType type = IntrinsicData.writeArgument(writer, this.method, i, instance, arguments);
writer.visitVarInsn(type.getStoreOpcode(), localCount);
localCount = writer.localCount();
}
}
Aggregations