Skip to content

Commit

Permalink
Fix JavaNativeMethod#genericResult not being set
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed May 17, 2024
1 parent f9dafe8 commit 748ef20
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.openzen.zenscript.javabytecode.compiler.JavaMethodBytecodeCompiler.OBJECT_HASHCODE;

public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
private static final JavaNativeMethod MAP_PUT = JavaNativeMethod.getInterface(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
private static final JavaNativeMethod MAP_PUT = JavaNativeMethod.getInterface(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
private static final JavaNativeMethod ARRAY_NEWINSTANCE = JavaNativeMethod.getNativeStatic(JavaClass.ARRAY, "newInstance", "(Ljava/lang/Class;I)Ljava/lang/Object;");
private static final MethodID CONSTRUCTOR = MethodID.staticOperator(OperatorType.CONSTRUCTOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void visitIteratorIterator(Type targetType) {
javaWriter.dup();
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
javaWriter.ifEQ(endLabel);
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0, true));
javaWriter.checkCast(targetType);
final JavaLocalVariableInfo variable = javaWriter.getLocalVariable(statement.loopVariables[0].variable);
javaWriter.store(variable.type, variable.local);
Expand Down Expand Up @@ -120,7 +120,7 @@ public void visitCustomIterator() {
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
javaWriter.ifEQ(endLabel);
javaWriter.dup();
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0, true));

final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(statement.loopVariables[0].variable);
this.downCast(0, keyVariable.type);
Expand All @@ -138,7 +138,7 @@ public void visitAssocKeyIterator() {
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
javaWriter.ifEQ(endLabel);
javaWriter.dup();
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0, true));

final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(statement.loopVariables[0].variable);
this.downCast(0, keyVariable.type);
Expand All @@ -156,19 +156,19 @@ public void visitAssocKeyValueIterator() {
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
javaWriter.ifEQ(endLabel);
javaWriter.dup();
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0, true));
javaWriter.checkCast(Type.getType(Map.Entry.class));
javaWriter.dup(false);


final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(statement.loopVariables[0].variable);
final JavaLocalVariableInfo valueVariable = javaWriter.getLocalVariable(statement.loopVariables[1].variable);

javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.fromInternalName("java/util/Map$Entry", JavaClass.Kind.INTERFACE), "getKey", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.fromInternalName("java/util/Map$Entry", JavaClass.Kind.INTERFACE), "getKey", "()Ljava/lang/Object;", 0, true));
this.downCast(0, keyVariable.type);
javaWriter.store(keyVariable.type, keyVariable.local);

javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.fromInternalName("java/util/Map$Entry", JavaClass.Kind.INTERFACE), "getValue", "()Ljava/lang/Object;", 0));
javaWriter.invokeInterface(JavaNativeMethod.getVirtual(JavaClass.fromInternalName("java/util/Map$Entry", JavaClass.Kind.INTERFACE), "getValue", "()Ljava/lang/Object;", 0, true));
this.downCast(1, valueVariable.type);
javaWriter.store(valueVariable.type, valueVariable.local);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public class JavaMethodBytecodeCompiler implements JavaMethodCompiler<Void> {
private static final JavaNativeMethod STRING_CONTAINS = JavaNativeMethod.getNativeVirtual(JavaClass.STRING, "contains", "(Ljava/lang/CharSequence;)Z");
private static final JavaNativeMethod ENUM_COMPARETO = JavaNativeMethod.getNativeVirtual(JavaClass.ENUM, "compareTo", "(Ljava/lang/Enum;)I");
private static final JavaNativeMethod HASHMAP_INIT = JavaNativeMethod.getNativeConstructor(JavaClass.HASHMAP, "()V");
private static final JavaNativeMethod MAP_GET = JavaNativeMethod.getInterface(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
private static final JavaNativeMethod MAP_PUT = JavaNativeMethod.getInterface(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
private static final JavaNativeMethod MAP_GET = JavaNativeMethod.getInterface(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
private static final JavaNativeMethod MAP_PUT = JavaNativeMethod.getInterface(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
private static final JavaNativeMethod MAP_PUT_ALL = JavaNativeMethod.getInterface(JavaClass.MAP, "putAll", "(Ljava/util/Map;)V");
private static final JavaNativeMethod MAP_CONTAINS_KEY = JavaNativeMethod.getInterface(JavaClass.MAP, "containsKey", "(Ljava/lang/Object;)Z");
private static final JavaNativeMethod MAP_SIZE = JavaNativeMethod.getInterface(JavaClass.MAP, "size", "()I");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public class JavaBuiltinModule {
private static final JavaNativeMethod ENUM_NAME = JavaNativeMethod.getNativeVirtual(JavaClass.ENUM, "name", "()Ljava/lang/String;");
private static final JavaNativeMethod ENUM_ORDINAL = JavaNativeMethod.getNativeVirtual(JavaClass.ENUM, "ordinal", "()I");
private static final JavaNativeMethod HASHMAP_INIT = JavaNativeMethod.getNativeConstructor(JavaClass.HASHMAP, "()V");
private static final JavaNativeMethod MAP_GET = JavaNativeMethod.getInterface(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
private static final JavaNativeMethod MAP_PUT = JavaNativeMethod.getInterface(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
private static final JavaNativeMethod MAP_GET = JavaNativeMethod.getInterface(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
private static final JavaNativeMethod MAP_PUT = JavaNativeMethod.getInterface(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
private static final JavaNativeMethod MAP_PUT_ALL = JavaNativeMethod.getInterface(JavaClass.MAP, "putAll", "(Ljava/util/Map;)V");
private static final JavaNativeMethod MAP_CONTAINS_KEY = JavaNativeMethod.getInterface(JavaClass.MAP, "containsKey", "(Ljava/lang/Object;)Z");
private static final JavaNativeMethod MAP_SIZE = JavaNativeMethod.getInterface(JavaClass.MAP, "size", "()I");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,35 @@ public static JavaNativeMethod getDestructor(JavaClass cls, int modifiers) {
}

public static JavaNativeMethod getStatic(JavaClass cls, String name, String descriptor, int modifiers) {
return new JavaNativeMethod(cls, Kind.STATIC, name, true, descriptor, modifiers | JavaModifiers.STATIC, false);
return getStatic(cls, name, descriptor, modifiers, false);
}

public static JavaNativeMethod getStatic(JavaClass cls, String name, String descriptor, int modifiers, boolean genericResult) {
return new JavaNativeMethod(cls, Kind.STATIC, name, true, descriptor, modifiers | JavaModifiers.STATIC, genericResult);
}

public static JavaNativeMethod getNativeStatic(JavaClass cls, String name, String descriptor) {
return new JavaNativeMethod(cls, Kind.STATIC, name, false, descriptor, JavaModifiers.STATIC | JavaModifiers.PUBLIC, false);
}

public static JavaNativeMethod getVirtual(JavaClass cls, String name, String descriptor, int modifiers) {
return new JavaNativeMethod(cls, Kind.INSTANCE, name, true, descriptor, modifiers, false);
return getVirtual(cls, name, descriptor, modifiers, false);
}

public static JavaNativeMethod getVirtual(JavaClass cls, String name, String descriptor, int modifiers, boolean genericResult) {
return new JavaNativeMethod(cls, Kind.INSTANCE, name, true, descriptor, modifiers, genericResult);
}

public static JavaNativeMethod getNativeVirtual(JavaClass cls, String name, String descriptor) {
return new JavaNativeMethod(cls, Kind.INSTANCE, name, false, descriptor, JavaModifiers.PUBLIC, false);
}

public static JavaNativeMethod getInterface(JavaClass cls, String name, String descriptor) {
return new JavaNativeMethod(cls, Kind.INTERFACE, name, false, descriptor, JavaModifiers.PUBLIC, false);
return getInterface(cls, name, descriptor, false);
}

public static JavaNativeMethod getInterface(JavaClass cls, String name, String descriptor, boolean genericResult) {
return new JavaNativeMethod(cls, Kind.INTERFACE, name, false, descriptor, JavaModifiers.PUBLIC, genericResult);
}

public static JavaNativeMethod getNativeExpansion(JavaClass cls, String name, String descriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public Void visitFunction(FunctionDefinition definition) {
class_.compiled,
definition.name,
descriptor,
JavaModifiers.getJavaModifiers(definition.modifiers));
JavaModifiers.getJavaModifiers(definition.modifiers),
definition.header.getReturnType().isGeneric());
class_.addMethod(definition.caller, new JavaCompilingMethod(class_.compiled, method, signature));
return null;
}
Expand Down

0 comments on commit 748ef20

Please sign in to comment.