Selaa lähdekoodia

Array initializers with and without default value

kindlich 6 vuotta sitten
vanhempi
commit
4eaf29c967
No known key found for this signature in database

+ 1420
- 359
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
File diff suppressed because it is too large
Näytä tiedosto


+ 7
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java Näytä tiedosto

4
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
4
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
5
 import org.openzen.zenscript.codemodel.type.*;
5
 import org.openzen.zenscript.codemodel.type.*;
6
 
6
 
7
+import java.util.Arrays;
8
+
7
 public class JavaTypeDescriptorVisitor implements TypeVisitor<String> {
9
 public class JavaTypeDescriptorVisitor implements TypeVisitor<String> {
8
 	private final JavaTypeDescriptorVisitor forOptional;
10
 	private final JavaTypeDescriptorVisitor forOptional;
9
 	private final JavaContext context;
11
 	private final JavaContext context;
85
 			return "[B"; // instead of int[], save memory, save compatibility
87
 			return "[B"; // instead of int[], save memory, save compatibility
86
 		else if (array.elementType.type == BasicTypeID.USHORT)
88
 		else if (array.elementType.type == BasicTypeID.USHORT)
87
 			return "[S"; // instead of int[], save memory
89
 			return "[S"; // instead of int[], save memory
88
-		else
89
-			return "[" + this.context.getDescriptor(array.elementType);
90
+		else {
91
+			char[] arrayDepth = new char[array.dimension];
92
+			Arrays.fill(arrayDepth, '[');
93
+			return new String(arrayDepth) + this.context.getDescriptor(array.elementType);
94
+		}
90
     }
95
     }
91
 
96
 
92
     @Override
97
     @Override

+ 23
- 0
ScriptingExample/scripts/arrays.zs Näytä tiedosto

1
+val a  = new int[](3, 10);
2
+
3
+for i in a {
4
+	println(i);
5
+}
6
+
7
+println(a[1]);
8
+
9
+
10
+val multiDim = new int[,,](1,2,3, 130);
11
+println(multiDim[0,1,2]);
12
+
13
+val t = multiDim;
14
+
15
+
16
+val b = new int[](3);
17
+for i in b {
18
+	println(i);
19
+}
20
+
21
+
22
+val c = new int[,,](1,2,3);
23
+println(c[0,1,2]);

Loading…
Peruuta
Tallenna