Преглед изворни кода

Array initializers with and without default value

kindlich пре 6 година
родитељ
комит
4eaf29c967
No known key found for this signature in database

+ 1420
- 359
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 7
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java Прегледај датотеку

@@ -4,6 +4,8 @@ import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
4 4
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
5 5
 import org.openzen.zenscript.codemodel.type.*;
6 6
 
7
+import java.util.Arrays;
8
+
7 9
 public class JavaTypeDescriptorVisitor implements TypeVisitor<String> {
8 10
 	private final JavaTypeDescriptorVisitor forOptional;
9 11
 	private final JavaContext context;
@@ -85,8 +87,11 @@ public class JavaTypeDescriptorVisitor implements TypeVisitor<String> {
85 87
 			return "[B"; // instead of int[], save memory, save compatibility
86 88
 		else if (array.elementType.type == BasicTypeID.USHORT)
87 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 97
     @Override

+ 23
- 0
ScriptingExample/scripts/arrays.zs Прегледај датотеку

@@ -0,0 +1,23 @@
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…
Откажи
Сачувај