Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Nov 23, 2024
1 parent 4ce5a49 commit 6c8636c
Show file tree
Hide file tree
Showing 24 changed files with 369 additions and 426 deletions.
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ tasks.withType<Jar> {
)
}

tasks.withType<JavaCompile> {
options.compilerArgs.add("-proc:none")
}

java {
if (hasJavadocJar.toBoolean()) withJavadocJar()
if (hasSourcesJar.toBoolean()) withSourcesJar()
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
136 changes: 48 additions & 88 deletions src/main/java/overrun/marshal/Downcall.java

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions src/main/java/overrun/marshal/DowncallFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.github.overrun.memstack.MemoryStack;
import overrun.marshal.gen.DowncallMethodParameter;
import overrun.marshal.gen.DowncallMethodType;
import overrun.marshal.gen.ConvertedClassType;
import overrun.marshal.gen.processor.ReturnValueTransformer;

import java.lang.invoke.*;
Expand Down Expand Up @@ -96,7 +97,7 @@ public static DowncallMethodParameter createDowncallMethodParameter(
MethodHandles.Lookup lookup,
String name,
Class<?> type,
Class<?> parameterType,
ConvertedClassType parameterType,
boolean byValue,
boolean ref,
long sized,
Expand All @@ -110,7 +111,7 @@ public static DowncallMethodType createDowncallMethodType(
MethodHandles.Lookup lookup,
String entrypoint,
Class<?> type,
Class<?> returnType,
ConvertedClassType returnType,
boolean byValue,
boolean critical,
boolean criticalAllowHeapAccess,
Expand All @@ -129,4 +130,14 @@ public static DowncallMethodType createDowncallMethodType(
charset,
canonicalType);
}

public static ConvertedClassType createExtendedClassType(
MethodHandles.Lookup lookup,
String name,
Class<?> type,
Class<?> javaClass,
Class<?> downcallClass
) {
return new ConvertedClassType(javaClass, downcallClass);
}
}
42 changes: 0 additions & 42 deletions src/main/java/overrun/marshal/DowncallMethodData.java

This file was deleted.

74 changes: 74 additions & 0 deletions src/main/java/overrun/marshal/gen/AsBool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* MIT License
*
* Copyright (c) 2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package overrun.marshal.gen;

import java.util.Locale;

/**
* Primitive types that are convertible with {@code boolean}.
*
* @author squid233
* @see Convert
* @since 0.1.0
*/
public enum AsBool {
/**
* {@code char} type
*/
CHAR(char.class),
/**
* {@code byte} type
*/
BYTE(byte.class),
/**
* {@code short} type
*/
SHORT(short.class),
/**
* {@code int} type
*/
INT(int.class),
/**
* {@code long} type
*/
LONG(long.class),
/**
* {@code float} type
*/
FLOAT(float.class),
/**
* {@code double} type
*/
DOUBLE(double.class),
;

private final Class<?> javaClass;

AsBool(Class<?> javaClass) {
this.javaClass = javaClass;
}

/// {@return the class of this type}
public Class<?> javaClass() {
return javaClass;
}

@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
}
}
8 changes: 3 additions & 5 deletions src/main/java/overrun/marshal/gen/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package overrun.marshal.gen;

import overrun.marshal.gen.processor.ProcessorType;

import java.lang.annotation.*;

/**
Expand All @@ -27,10 +25,10 @@
* The type of the marked element must be {@code boolean}; otherwise this annotation will be ignored.
* <h2>Example</h2>
* <pre>{@code
* @Convert(ProcessorType.BoolConvert.INT)
* @Convert(AsBool.INT)
* boolean returnInt();
*
* void acceptInt(@Convert(ProcessorType.BoolConvert.INT) boolean i);
* void acceptInt(@Convert(AsBool.INT) boolean i);
* }</pre>
*
* @author squid233
Expand All @@ -43,5 +41,5 @@
/**
* {@return the type to be converted}
*/
ProcessorType.BoolConvert value();
AsBool value();
}
80 changes: 80 additions & 0 deletions src/main/java/overrun/marshal/gen/ConvertedClassType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* MIT License
*
* Copyright (c) 2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package overrun.marshal.gen;

import overrun.marshal.internal.Constants;

import java.lang.constant.*;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Optional;

/**
* @author squid233
* @since 0.1.0
*/
public record ConvertedClassType(
Class<?> javaClass,
Class<?> downcallClass
) implements Constable {
public static ConvertedClassType returnType(Method method) {
return of(method, method.getReturnType());
}

public static ConvertedClassType parameterType(Parameter parameter) {
return of(parameter, parameter.getType());
}

private static ConvertedClassType of(AnnotatedElement element, Class<?> type) {
Convert convert = element.getAnnotation(Convert.class);
if (type == boolean.class && convert != null) {
return new ConvertedClassType(type, convert.value().javaClass());
}
return new ConvertedClassType(type, type);
}

@Override
public Optional<Desc> describeConstable() {
return Optional.of(new Desc(ClassDesc.ofDescriptor(javaClass.descriptorString()), ClassDesc.ofDescriptor(downcallClass.descriptorString())));
}

@Override
public String toString() {
if (javaClass == downcallClass) {
return javaClass.getSimpleName();
}
return downcallClass.getSimpleName() + "<from " + javaClass.getSimpleName() + ">";
}

public static final class Desc extends DynamicConstantDesc<ConvertedClassType> {
private final ClassDesc javaClass;
private final ClassDesc downcallClass;

public Desc(ClassDesc javaClass, ClassDesc downcallClass) {
super(Constants.BSM_DowncallFactory_createExtendedClassType, ConstantDescs.DEFAULT_NAME, Constants.CD_ConvertedClassType, javaClass, downcallClass);
this.javaClass = javaClass;
this.downcallClass = downcallClass;
}

@Override
public ConvertedClassType resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException {
return new ConvertedClassType(javaClass.resolveConstantDesc(lookup), downcallClass.resolveConstantDesc(lookup));
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/overrun/marshal/gen/DowncallMethodParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @since 0.1.0
*/
public record DowncallMethodParameter(
Class<?> type,
ConvertedClassType type,
boolean byValue,
boolean ref,
long sized,
Expand All @@ -41,7 +41,7 @@ public static DowncallMethodParameter of(Parameter parameter) {
Sized anSized = parameter.getDeclaredAnnotation(Sized.class);
StrCharset anStrCharset = parameter.getDeclaredAnnotation(StrCharset.class);

return new DowncallMethodParameter(parameter.getType(),
return new DowncallMethodParameter(ConvertedClassType.parameterType(parameter),
parameter.getDeclaredAnnotation(ByValue.class) != null,
parameter.getDeclaredAnnotation(Ref.class) != null,
anSized != null ? anSized.value() : -1,
Expand All @@ -51,7 +51,7 @@ public static DowncallMethodParameter of(Parameter parameter) {

@Override
public Optional<Desc> describeConstable() {
return Optional.of(new Desc(ClassDesc.ofDescriptor(type.descriptorString()), byValue, ref, sized, charset, canonicalType));
return Optional.of(new Desc(type.describeConstable().orElseThrow(), byValue, ref, sized, charset, canonicalType));
}

@Override
Expand All @@ -72,19 +72,19 @@ public String toString() {
if (charset != null) {
sb.append("[StrCharset=").append(charset).append(']');
}
sb.append(type.getSimpleName());
sb.append(type);
return sb.toString();
}

public static final class Desc extends DynamicConstantDesc<DowncallMethodParameter> {
private final ClassDesc type;
private final ConvertedClassType.Desc type;
private final boolean byValue;
private final boolean ref;
private final long sized;
private final String charset;
private final String canonicalType;

public Desc(ClassDesc type, boolean byValue, boolean ref, long sized, String charset, String canonicalType) {
public Desc(ConvertedClassType.Desc type, boolean byValue, boolean ref, long sized, String charset, String canonicalType) {
super(Constants.BSM_DowncallFactory_createDowncallMethodParameter,
ConstantDescs.DEFAULT_NAME,
Constants.CD_DowncallMethodParameter,
Expand Down
Loading

0 comments on commit 6c8636c

Please sign in to comment.