Przeglądaj źródła

WIP Array initializers; moved size variable naming to multiArray function

kindlich 6 lat temu
rodzic
commit
280df6c5c0
Nie znaleziono w bazie danych klucza dla tego podpisu

+ 14
- 6
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/ArrayInitializerHelper.java Wyświetl plik

@@ -5,9 +5,9 @@ import org.objectweb.asm.Label;
5 5
 import org.objectweb.asm.Type;
6 6
 
7 7
 public class ArrayInitializerHelper {
8
-	public static void visitProjected(JavaWriter javaWriter, int[] sizeLocations, int[] counterLocations, int dim, int originArrayLocation, Type originArrayType, int functionLocation, Type functionType, Type currentArrayType) {
8
+	public static void visitProjected(JavaWriter javaWriter, int[] sizeLocations, int dim, int originArrayLocation, Type originArrayType, int functionLocation, Type functionType, Type currentArrayType) {
9 9
 
10
-		visitMultiDimArray(javaWriter, sizeLocations, counterLocations, dim, currentArrayType, (elementType1, counterLocations1, sizeLocations1) -> {
10
+		visitMultiDimArray(javaWriter, sizeLocations, dim, currentArrayType, (elementType, counterLocations) -> {
11 11
 			//Load origin array
12 12
 			javaWriter.loadObject(originArrayLocation);
13 13
 
@@ -29,11 +29,15 @@ public class ArrayInitializerHelper {
29 29
 
30 30
 
31 31
 	public static void visitMultiDimArrayWithDefaultValue(JavaWriter javaWriter, int dim, int defaultLocation, Type currentArrayType, int[] sizeLocations) {
32
-		visitMultiDimArray(javaWriter, sizeLocations, new int[dim], dim, currentArrayType, (elementType, counterLocations, sizeLocations1) -> javaWriter.load(elementType, defaultLocation));
32
+		visitMultiDimArray(javaWriter, sizeLocations, new int[dim], dim, currentArrayType, (elementType, counterLocations) -> javaWriter.load(elementType, defaultLocation));
33
+	}
34
+
35
+	public static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction){
36
+		visitMultiDimArray(javaWriter, sizeLocations, new int[dim], dim, currentArrayType, innermostFunction);
33 37
 	}
34 38
 
35 39
 
36
-	public static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int[] counterLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction) {
40
+	private static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int[] counterLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction) {
37 41
 		final Label begin = new Label();
38 42
 		final Label end = new Label();
39 43
 		javaWriter.label(begin);
@@ -63,7 +67,7 @@ public class ArrayInitializerHelper {
63 67
 		javaWriter.dup();
64 68
 		javaWriter.loadInt(forLoopCounter);
65 69
 		if (dim == 1) {
66
-			innermostFunction.apply(elementType, counterLocations, sizeLocations);
70
+			innermostFunction.apply(elementType, counterLocations);
67 71
 		} else {
68 72
 			visitMultiDimArray(javaWriter, sizeLocations, counterLocations, dim - 1, elementType, innermostFunction);
69 73
 		}
@@ -79,11 +83,15 @@ public class ArrayInitializerHelper {
79 83
 		javaWriter.nameVariable(forLoopCounter, "i" + dim, loopStart, loopEnd, Type.getType(int.class));
80 84
 
81 85
 		javaWriter.label(end);
86
+
87
+		for (int i = 0; i < sizeLocations.length; i++) {
88
+			javaWriter.nameVariable(sizeLocations[i], "size" + (sizeLocations.length - i), begin, end, Type.getType(int.class));
89
+		}
82 90
 	}
83 91
 
84 92
 	@FunctionalInterface
85 93
 	public interface InnermostFunction {
86
-		void apply(Type elementType, int[] counterLocations, int[] sizeLocations);
94
+		void apply(Type elementType, int[] counterLocations);
87 95
 	}
88 96
 }
89 97
 

+ 4
- 14
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Wyświetl plik

@@ -3062,12 +3062,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3062 3062
 				//D2Array = new T[arguments[1]][];
3063 3063
 				//Arrays.fill(D2Array, D1Array);
3064 3064
 
3065
-				final Type ASMType;
3066
-				{
3067
-					final char[] chars = new char[type.dimension];
3068
-					Arrays.fill(chars, '[');
3069
-					ASMType = Type.getType(new String(chars) + context.getDescriptor(type.elementType));
3070
-				}
3065
+				final Type ASMType = context.getType(expression.type);
3071 3066
 				final Type ASMElementType = context.getType(type.elementType);
3072 3067
 
3073 3068
 				final Label begin = new Label();
@@ -3077,6 +3072,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3077 3072
 				final int defaultValueLocation = javaWriter.local(ASMElementType);
3078 3073
 
3079 3074
 				if (builtin == BuiltinID.ARRAY_CONSTRUCTOR_SIZED) {
3075
+					//TODO type.elementType.type.accept(JavaDefaultExpressionVisitor.Instance).accept(this);
3076
+					//TODO I still need to write that one, I guess
3080 3077
 					if (CompilerUtils.isPrimitive(type.elementType.type))
3081 3078
 						if (type.elementType.type == BasicTypeID.FLOAT) javaWriter.constant(0f);
3082 3079
 						else if (type.elementType.type == BasicTypeID.DOUBLE) javaWriter.constant(0D);
@@ -3112,9 +3109,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3112 3109
 
3113 3110
 				//naming the variables
3114 3111
 				javaWriter.nameVariable(defaultValueLocation, "defaultValue", begin, end, ASMElementType);
3115
-				for (int i = 0; i < arraySizes.length; i++) {
3116
-					javaWriter.nameVariable(arraySizes[i], "size" + (arraySizes.length - i), begin, end, Type.getType(int.class));
3117
-				}
3118 3112
 				return;
3119 3113
 			}
3120 3114
 			case ARRAY_CONSTRUCTOR_LAMBDA: {
@@ -3153,7 +3147,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3153 3147
 				final int functionLocation = javaWriter.local(functionType);
3154 3148
 				javaWriter.storeObject(functionLocation);
3155 3149
 
3156
-				int[] variableCounterLocations = new int[type.dimension];
3157 3150
 				Type destinationArrayType = context.getType(expression.type);
3158 3151
 
3159 3152
 
@@ -3183,15 +3176,12 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3183 3176
 				}
3184 3177
 
3185 3178
 
3186
-				ArrayInitializerHelper.visitProjected(javaWriter, arraySizes, variableCounterLocations, type.dimension, originArrayLocation, originArrayType, functionLocation, functionType, destinationArrayType);
3179
+				ArrayInitializerHelper.visitProjected(javaWriter, arraySizes, type.dimension, originArrayLocation, originArrayType, functionLocation, functionType, destinationArrayType);
3187 3180
 
3188 3181
 				javaWriter.label(end);
3189 3182
 
3190 3183
 				//naming the variables
3191 3184
 				javaWriter.nameVariable(functionLocation, "projectionFunction", begin, end, functionType);
3192
-				for (int i = 0; i < arraySizes.length; i++) {
3193
-					javaWriter.nameVariable(arraySizes[i], "size" + (arraySizes.length - i), begin, end, Type.getType(int.class));
3194
-				}
3195 3185
 				return;
3196 3186
 
3197 3187
 			}

Ładowanie…
Anuluj
Zapisz