kindlich 6 лет назад
Родитель
Сommit
05460bdf50
Не найден GPG ключ соответствующий данной подписи

+ 5
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaLocalVariableInfo.java Просмотреть файл

@@ -11,10 +11,14 @@ public class JavaLocalVariableInfo {
11 11
 	public Label end;
12 12
 
13 13
 	public JavaLocalVariableInfo(Type type, int local, Label start, String name) {
14
+		this(type, local, start, name, start);
15
+	}
16
+
17
+	public JavaLocalVariableInfo(Type type, int local, Label start, String name, Label end) {
14 18
 		this.type = type;
15 19
 		this.local = local;
16 20
 		this.start = start;
17
-		this.end = start;
21
+		this.end = end;
18 22
 		this.name = name;
19 23
 	}
20 24
 }

+ 135
- 10
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/ArrayInitializerHelper.java Просмотреть файл

@@ -3,9 +3,91 @@ package org.openzen.zenscript.javabytecode.compiler;
3 3
 
4 4
 import org.objectweb.asm.Label;
5 5
 import org.objectweb.asm.Type;
6
+import org.openzen.zenscript.codemodel.expression.Expression;
7
+import org.openzen.zenscript.codemodel.expression.FunctionExpression;
8
+import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
9
+import org.openzen.zenscript.codemodel.statement.ReturnStatement;
10
+
11
+import java.util.ArrayList;
12
+
13
+class ArrayInitializerHelper {
14
+
15
+	/**
16
+	 * creates an int[] with the given array size locations and writes the code that gets them in the generated file.
17
+	 * Uses an already present origin array (rectangular!)
18
+	 *
19
+	 * @param dimension           the array's dim
20
+	 * @param originArrayType     the type of the original array
21
+	 * @param originArrayLocation the location of the original array
22
+	 * @param javaWriter          the writer
23
+	 * @return the size locations
24
+	 */
25
+	static int[] getArraySizeLocationsProjected(int dimension, Type originArrayType, int originArrayLocation, JavaWriter javaWriter) {
26
+		int[] arraySizes;
27
+		final ArrayList<Integer> list = new ArrayList<>();
28
+		javaWriter.loadObject(originArrayLocation);
29
+		Type currentElementType = originArrayType;
30
+		for (int i = 0; i < dimension; i++) {
31
+			currentElementType = Type.getType(currentElementType.getDescriptor().substring(1));
32
+			final int location = javaWriter.local(int.class);
33
+			javaWriter.dup();
34
+			javaWriter.arrayLength();
35
+			javaWriter.storeInt(location);
36
+			list.add(location);
37
+
38
+			if (i < dimension - 1) {
39
+				javaWriter.iConst0();
40
+				javaWriter.arrayLoad(currentElementType);
41
+			}
42
+		}
43
+		javaWriter.pop();
44
+		arraySizes = new int[list.size()];
45
+		for (int i = 0; i < list.size(); i++) {
46
+			arraySizes[i] = list.get(i);
47
+		}
48
+		return arraySizes;
49
+	}
50
+
51
+	/**
52
+	 * Creates an int[] with the given array size locations and writes the code that gets them in the generated file
53
+	 * Uses the constructor arguments (sizes are expressions 0 .. dimension-1)
54
+	 *
55
+	 * @param dimension the array's dim
56
+	 * @param arguments the arguments form the constructor
57
+	 * @param visitor   the visitor visiting them
58
+	 * @return the size locations
59
+	 */
60
+	static int[] getArraySizeLocationsFromConstructor(int dimension, Expression[] arguments, JavaExpressionVisitor visitor) {
61
+		final ArrayList<Integer> list = new ArrayList<>();
62
+		for (int i = 0; i < dimension; i++) {
63
+			final int location = visitor.javaWriter.local(int.class);
64
+			arguments[i].accept(visitor);
65
+			visitor.javaWriter.storeInt(location);
66
+			list.add(location);
67
+		}
68
+		int[] arraySizes = new int[list.size()];
69
+		for (int i = 0; i < list.size(); i++) {
70
+			arraySizes[i] = list.get(i);
71
+		}
72
+		return arraySizes;
73
+	}
6 74
 
7
-public class ArrayInitializerHelper {
8
-	public static void visitProjected(JavaWriter javaWriter, int[] sizeLocations, int dim, int originArrayLocation, Type originArrayType, int functionLocation, Type functionType, Type currentArrayType) {
75
+	/**
76
+	 * Writes the code for visiting a multidimensional array that is projected from an origin array.
77
+	 * Accepts a function that will decide what to do with each value from the origin array
78
+	 * When the function is executed, the value from the origin array will be on top of the stack and when it is finished the value on top should be what will be inserted into the array.
79
+	 * After the function is completed the stack size must be the same as when it started (effectively replacing the item on top of the stack with the item that should be inserted.
80
+	 * The function should not modify the other stacks.
81
+	 *
82
+	 * @param javaWriter          the writer that will write the actual opcode
83
+	 * @param sizeLocations       the locations of the array dimension sizes sizeLocations.length == dim !!
84
+	 * @param dim                 the array's dimensions, reduced during the recursions of the loop to find the innermost loop
85
+	 * @param originArrayLocation The location of the origin array.
86
+	 * @param originArrayType     the type of the origin array. The element type needs to be assignable to the new array element type!
87
+	 * @param currentArrayType    The current type of the array, reduced during the recursions of the functions
88
+	 * @param innermostFunction   The function that will decide what to add to the array, needs to increase the stack size by one and may not touch the other stacks!
89
+	 */
90
+	static void visitProjected(JavaWriter javaWriter, int[] sizeLocations, int dim, int originArrayLocation, Type originArrayType, Type currentArrayType, InnermostFunction innermostFunction) {
9 91
 
10 92
 		visitMultiDimArray(javaWriter, sizeLocations, dim, currentArrayType, (elementType, counterLocations) -> {
11 93
 			//Load origin array
@@ -18,25 +100,68 @@ public class ArrayInitializerHelper {
18 100
 				javaWriter.arrayLoad(modifiedOriginArrayType = Type.getType(modifiedOriginArrayType.getDescriptor().substring(1)));
19 101
 			}
20 102
 
21
-			//Apply function here
22
-			//javaWriter.loadObject(functionLocation);
23
-			//javaWriter.swap();
103
+			innermostFunction.apply(elementType, counterLocations);
104
+
24 105
 
25
-			//TODO invoke?
26
-			//javaWriter.invokeVirtual(new JavaMethod(JavaClass.fromInternalName("lambda1", JavaClass.Kind.CLASS), JavaMethod.Kind.INSTANCE, "accept", true, "(Ljava/lang/String;)Ljava/lang/String;", 0, false));
27 106
 		});
28 107
 	}
29 108
 
30
-
31
-	public static void visitMultiDimArrayWithDefaultValue(JavaWriter javaWriter, int dim, int defaultLocation, Type currentArrayType, int[] sizeLocations) {
109
+	/**
110
+	 * Writes the code for visiting a multidimensional array with a default value.
111
+	 * The variable at defaultLocation needs to be of or assignable to the resulting array element type.
112
+	 *
113
+	 * @param javaWriter       the writer that will write the actual opcode
114
+	 * @param sizeLocations    the locations of the array dimension sizes sizeLocations.length == dim !!
115
+	 * @param dim              the array's dimensions, reduced during the recursions of the loop to find the innermost loop
116
+	 * @param currentArrayType The current type of the array, reduced during the recursions of the functions
117
+	 * @param defaultLocation  The location of the default value. Needs to be of or assignable to elementType!
118
+	 */
119
+	static void visitMultiDimArrayWithDefaultValue(JavaWriter javaWriter, int[] sizeLocations, int dim, Type currentArrayType, int defaultLocation) {
32 120
 		visitMultiDimArray(javaWriter, sizeLocations, new int[dim], dim, currentArrayType, (elementType, counterLocations) -> javaWriter.load(elementType, defaultLocation));
33 121
 	}
34 122
 
35
-	public static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction){
123
+	/**
124
+	 * Writes the code for visiting a multidimensional array.
125
+	 * Accepts a function that will decide what value to insert into the array slots.
126
+	 * When the function is finished, one additional item needs to have been added to the stack.
127
+	 * The already present stacks may not be touched!
128
+	 *
129
+	 * @param javaWriter        the writer that will write the actual opcode
130
+	 * @param sizeLocations     the locations of the array dimension sizes sizeLocations.length == dim !!
131
+	 * @param dim               the array's dimensions, reduced during the recursions of the loop to find the innermost loop
132
+	 * @param currentArrayType  The current type of the array, reduced during the recursions of the functions
133
+	 * @param innermostFunction The function that will decide what to add to the array, needs to increase the stack size by one and may not touch the other stacks!
134
+	 */
135
+	private static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction) {
36 136
 		visitMultiDimArray(javaWriter, sizeLocations, new int[dim], dim, currentArrayType, innermostFunction);
37 137
 	}
38 138
 
139
+	/**
140
+	 * Checks if an expression can be inlined
141
+	 *
142
+	 * @param expression Expression to check for.
143
+	 * @return can expression be inlined
144
+	 */
145
+	static boolean canBeInlined(Expression expression) {
146
+		while (expression instanceof StorageCastExpression)
147
+			expression = ((StorageCastExpression) expression).value;
148
+
149
+		return expression instanceof FunctionExpression && ((FunctionExpression) expression).body instanceof ReturnStatement;
150
+	}
39 151
 
152
+	/**
153
+	 * The function that is actually setting up the loops and naming the counter variables.
154
+	 * Private because the other static methods provide the new int[] sizeLocations.
155
+	 * Recursively creates a forLoop per array dimension and in the innermost loop, applies the given function.
156
+	 * That function needs to add one stack and may not touch the existing stacks.
157
+	 *
158
+	 * @param javaWriter        the writer that will write the actual opcode
159
+	 * @param sizeLocations     the locations of the array dimension sizes sizeLocations.length == dim !!
160
+	 * @param counterLocations  the locations of the for-Loop counter variables (will be filled by the function itself, counterLocations.length == dim !!
161
+	 * @param dim               the array's dimensions, reduced during the recursions of the loop to find the innermost loop
162
+	 * @param currentArrayType  The current type of the array, reduced during the recursions of the functions
163
+	 * @param innermostFunction The function that will decide what to add to the array, needs to increase the stack size by one and may not touch the other stacks!
164
+	 */
40 165
 	private static void visitMultiDimArray(JavaWriter javaWriter, int[] sizeLocations, int[] counterLocations, int dim, Type currentArrayType, InnermostFunction innermostFunction) {
41 166
 		final Label begin = new Label();
42 167
 		final Label end = new Label();

+ 61
- 71
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Просмотреть файл

@@ -9,6 +9,7 @@ import org.openzen.zenscript.codemodel.expression.*;
9 9
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
10 10
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
11 11
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
12
+import org.openzen.zenscript.codemodel.statement.ReturnStatement;
12 13
 import org.openzen.zenscript.codemodel.type.*;
13 14
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
14 15
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
@@ -21,7 +22,10 @@ import org.openzen.zenscript.javashared.*;
21 22
 import java.io.FileOutputStream;
22 23
 import java.io.IOException;
23 24
 import java.lang.reflect.Modifier;
24
-import java.util.*;
25
+import java.util.Arrays;
26
+import java.util.Comparator;
27
+import java.util.Objects;
28
+import java.util.StringJoiner;
25 29
 
26 30
 public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativeTranslator<Void> {
27 31
 	private static final JavaMethod BOOLEAN_PARSE = JavaMethod.getNativeStatic(JavaClass.BOOLEAN, "parseBoolean", "(Ljava/lang/String;)Z");
@@ -3055,13 +3059,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3055 3059
 			case ARRAY_CONSTRUCTOR_INITIAL_VALUE: {
3056 3060
 				ArrayTypeID type = (ArrayTypeID) expression.type.type;
3057 3061
 
3058
-				//D1Array = new T[arguments[0]];
3059
-				//value = arguments[last];
3060
-				//Arrays.fill(D1Array, value);
3061
-
3062
-				//D2Array = new T[arguments[1]][];
3063
-				//Arrays.fill(D2Array, D1Array);
3064
-
3065 3062
 				final Type ASMType = context.getType(expression.type);
3066 3063
 				final Type ASMElementType = context.getType(type.elementType);
3067 3064
 
@@ -3070,45 +3067,21 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3070 3067
 
3071 3068
 				javaWriter.label(begin);
3072 3069
 				final int defaultValueLocation = javaWriter.local(ASMElementType);
3070
+				javaWriter.addVariableInfo(new JavaLocalVariableInfo(ASMElementType, defaultValueLocation, begin, "defaultValue", end));
3071
+
3073 3072
 
3074 3073
 				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
3077
-					if (CompilerUtils.isPrimitive(type.elementType.type))
3078
-						if (type.elementType.type == BasicTypeID.FLOAT) javaWriter.constant(0f);
3079
-						else if (type.elementType.type == BasicTypeID.DOUBLE) javaWriter.constant(0D);
3080
-						else javaWriter.iConst0();
3081
-					else
3082
-						javaWriter.aConstNull();
3074
+					type.elementType.type.accept(JavaDefaultExpressionTypeVisitor.INSTANCE).accept(this);
3083 3075
 				} else {
3084 3076
 					expression.arguments.arguments[expression.arguments.arguments.length - 1].accept(this);
3085 3077
 				}
3086 3078
 				javaWriter.store(ASMElementType, defaultValueLocation);
3087 3079
 
3088 3080
 
3089
-				final int[] arraySizes;
3090
-				{
3091
-					final ArrayList<Integer> list = new ArrayList<>();
3092
-					for (int i = 0; i < type.dimension; i++) {
3093
-						final int location = javaWriter.local(int.class);
3094
-						expression.arguments.arguments[i].accept(this);
3095
-						javaWriter.storeInt(location);
3096
-						list.add(location);
3097
-					}
3098
-					arraySizes = new int[list.size()];
3099
-					for (int i = 0; i < list.size(); i++) {
3100
-						arraySizes[i] = list.get(i);
3101
-					}
3102
-				}
3103
-
3104
-
3105
-				ArrayInitializerHelper.visitMultiDimArrayWithDefaultValue(javaWriter, type.dimension, defaultValueLocation, ASMType, arraySizes);
3106
-
3081
+				final int[] arraySizes = ArrayInitializerHelper.getArraySizeLocationsFromConstructor(type.dimension, expression.arguments.arguments, this);
3082
+				ArrayInitializerHelper.visitMultiDimArrayWithDefaultValue(javaWriter, arraySizes, type.dimension, ASMType, defaultValueLocation);
3107 3083
 
3108 3084
 				javaWriter.label(end);
3109
-
3110
-				//naming the variables
3111
-				javaWriter.nameVariable(defaultValueLocation, "defaultValue", begin, end, ASMElementType);
3112 3085
 				return;
3113 3086
 			}
3114 3087
 			case ARRAY_CONSTRUCTOR_LAMBDA: {
@@ -3140,48 +3113,65 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3140 3113
 				final Type originArrayType = context.getType(expression.arguments.arguments[0].type);
3141 3114
 				final int originArrayLocation = javaWriter.local(originArrayType);
3142 3115
 				javaWriter.storeObject(originArrayLocation);
3143
-
3144
-
3145
-				expression.arguments.arguments[1].accept(this); //Projection Function
3146
-				final Type functionType = context.getType(expression.arguments.arguments[1].type);
3147
-				final int functionLocation = javaWriter.local(functionType);
3148
-				javaWriter.storeObject(functionLocation);
3149
-
3150 3116
 				Type destinationArrayType = context.getType(expression.type);
3151 3117
 
3152 3118
 
3153
-				final int[] arraySizes;
3154
-				{
3155
-					final ArrayList<Integer> list = new ArrayList<>();
3156
-					javaWriter.loadObject(originArrayLocation);
3157
-					Type currentElementType = originArrayType;
3158
-					for (int i = 0; i < type.dimension; i++) {
3159
-						currentElementType = Type.getType(currentElementType.getDescriptor().substring(1));
3160
-						final int location = javaWriter.local(int.class);
3161
-						javaWriter.dup();
3162
-						javaWriter.arrayLength();
3163
-						javaWriter.storeInt(location);
3164
-						list.add(location);
3165
-
3166
-						if (i < type.dimension - 1) {
3167
-							javaWriter.iConst0();
3168
-							javaWriter.arrayLoad(currentElementType);
3169
-						}
3170
-					}
3171
-					javaWriter.pop();
3172
-					arraySizes = new int[list.size()];
3173
-					for (int i = 0; i < list.size(); i++) {
3174
-						arraySizes[i] = list.get(i);
3175
-					}
3119
+				final boolean canBeInlined = ArrayInitializerHelper.canBeInlined(expression.arguments.arguments[1]);
3120
+				final Type functionType;    //Only used if not inline able
3121
+				final int functionLocation; //Only used if not inline able
3122
+				if (!canBeInlined) {
3123
+					expression.arguments.arguments[1].accept(this); //Projection Function
3124
+					functionType = context.getType(expression.arguments.arguments[1].type);
3125
+					functionLocation = javaWriter.local(functionType);
3126
+					javaWriter.storeObject(functionLocation);
3127
+					javaWriter.addVariableInfo(new JavaLocalVariableInfo(functionType, functionLocation, begin, "projectionFunction", end));
3176 3128
 				}
3177 3129
 
3130
+				final int[] arraySizes = ArrayInitializerHelper.getArraySizeLocationsProjected(type.dimension, originArrayType, originArrayLocation, javaWriter);
3131
+				ArrayInitializerHelper.visitProjected(javaWriter, arraySizes, type.dimension, originArrayLocation, originArrayType, destinationArrayType,
3132
+						(elementType, counterLocations) -> {
3133
+							if (canBeInlined) {
3134
+								Label inlineBegin = new Label();
3135
+								Label inlineEnd = new Label();
3136
+								javaWriter.label(inlineBegin);
3137
+								final Type projectedElementType = Type.getType(originArrayType.getDescriptor().substring(type.dimension));
3138
+								final int projectedElementLocal = javaWriter.local(projectedElementType);
3139
+								javaWriter.store(projectedElementType, projectedElementLocal);
3140
+
3141
+
3142
+								JavaExpressionVisitor visitor = new JavaExpressionVisitor(context, module, javaWriter) {
3143
+									@Override
3144
+									public Void visitGetFunctionParameter(GetFunctionParameterExpression expression) {
3145
+										javaWriter.load(projectedElementType, projectedElementLocal);
3146
+										return null;
3147
+									}
3148
+								};
3149
+
3150
+								Expression funcExpression = expression.arguments.arguments[1];
3151
+								while (funcExpression instanceof StorageCastExpression) {
3152
+									funcExpression = ((StorageCastExpression) funcExpression).value;
3153
+								}
3154
+
3155
+								if (funcExpression instanceof FunctionExpression && ((FunctionExpression) funcExpression).body instanceof ReturnStatement) {
3156
+									((ReturnStatement) ((FunctionExpression) funcExpression).body).value.accept(visitor);
3157
+									javaWriter.addVariableInfo(new JavaLocalVariableInfo(projectedElementType, projectedElementLocal, inlineBegin, ((FunctionExpression) funcExpression).header.parameters[0].name, inlineEnd));
3158
+								} else throw new IllegalStateException("Trying to inline a non-inlineable expression");
3159
+
3160
+
3161
+								javaWriter.label(inlineEnd);
3162
+							} else {
3163
+								//Apply function here
3164
+								//javaWriter.loadObject(functionLocation);
3165
+								//javaWriter.swap();
3166
+
3167
+								//TODO invoke?
3168
+								//javaWriter.invokeVirtual(new JavaMethod(JavaClass.fromInternalName("lambda1", JavaClass.Kind.CLASS), JavaMethod.Kind.INSTANCE, "accept", true, "(Ljava/lang/String;)Ljava/lang/String;", 0, false));
3169
+								throw new UnsupportedOperationException("Cannot use projection functions yet!");
3170
+							}
3171
+						});
3178 3172
 
3179
-				ArrayInitializerHelper.visitProjected(javaWriter, arraySizes, type.dimension, originArrayLocation, originArrayType, functionLocation, functionType, destinationArrayType);
3180 3173
 
3181 3174
 				javaWriter.label(end);
3182
-
3183
-				//naming the variables
3184
-				javaWriter.nameVariable(functionLocation, "projectionFunction", begin, end, functionType);
3185 3175
 				return;
3186 3176
 
3187 3177
 			}

+ 113
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaDefaultExpressionTypeVisitor.java Просмотреть файл

@@ -0,0 +1,113 @@
1
+package org.openzen.zenscript.javashared;
2
+
3
+import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zenscript.codemodel.expression.*;
5
+import org.openzen.zenscript.codemodel.type.*;
6
+
7
+public class JavaDefaultExpressionTypeVisitor implements TypeVisitor<Expression> {
8
+
9
+	public static final JavaDefaultExpressionTypeVisitor INSTANCE = new JavaDefaultExpressionTypeVisitor();
10
+
11
+	private JavaDefaultExpressionTypeVisitor(){}
12
+
13
+	@Override
14
+	public Expression visitBasic(BasicTypeID basic) {
15
+
16
+
17
+		if (basic == null)
18
+			throw new IllegalStateException("Null basic type!");
19
+
20
+		switch (basic) {
21
+			case UNDETERMINED:
22
+			case VOID:
23
+				throw new IllegalStateException("Void and Undetermined have no default type");
24
+			case NULL:
25
+				return new NullExpression(CodePosition.UNKNOWN);
26
+			case BOOL:
27
+				return new ConstantBoolExpression(CodePosition.UNKNOWN, false);
28
+			case BYTE:
29
+				return new ConstantByteExpression(CodePosition.UNKNOWN, 0);
30
+			case SBYTE:
31
+				return new ConstantSByteExpression(CodePosition.UNKNOWN, (byte) 0);
32
+			case SHORT:
33
+				return new ConstantShortExpression(CodePosition.UNKNOWN, (short) 0);
34
+			case USHORT:
35
+				return new ConstantUShortExpression(CodePosition.UNKNOWN, 0);
36
+			case INT:
37
+				return new ConstantIntExpression(CodePosition.UNKNOWN, 0);
38
+			case UINT:
39
+				return new ConstantUIntExpression(CodePosition.UNKNOWN, 0);
40
+			case LONG:
41
+				return new ConstantLongExpression(CodePosition.UNKNOWN, 0L);
42
+			case ULONG:
43
+				return new ConstantULongExpression(CodePosition.UNKNOWN, 0L);
44
+			case USIZE:
45
+				return new ConstantUSizeExpression(CodePosition.UNKNOWN, 0L);
46
+			case FLOAT:
47
+				return new ConstantFloatExpression(CodePosition.UNKNOWN, 0.0f);
48
+			case DOUBLE:
49
+				return new ConstantDoubleExpression(CodePosition.UNKNOWN, 0.0d);
50
+			case CHAR:
51
+				return new ConstantCharExpression(CodePosition.UNKNOWN, '\0');
52
+			default:
53
+				throw new IllegalStateException("Unknown basic type!");
54
+		}
55
+
56
+
57
+	}
58
+
59
+	@Override
60
+	public Expression visitString(StringTypeID string) {
61
+		return new NullExpression(CodePosition.UNKNOWN);
62
+	}
63
+
64
+	@Override
65
+	public Expression visitArray(ArrayTypeID array) {
66
+		return new NullExpression(CodePosition.UNKNOWN);
67
+	}
68
+
69
+	@Override
70
+	public Expression visitAssoc(AssocTypeID assoc) {
71
+		return new NullExpression(CodePosition.UNKNOWN);
72
+	}
73
+
74
+	@Override
75
+	public Expression visitGenericMap(GenericMapTypeID map) {
76
+		return new NullExpression(CodePosition.UNKNOWN);
77
+	}
78
+
79
+	@Override
80
+	public Expression visitIterator(IteratorTypeID iterator) {
81
+		return new NullExpression(CodePosition.UNKNOWN);
82
+	}
83
+
84
+	@Override
85
+	public Expression visitFunction(FunctionTypeID function) {
86
+		return new NullExpression(CodePosition.UNKNOWN);
87
+	}
88
+
89
+	@Override
90
+	public Expression visitDefinition(DefinitionTypeID definition) {
91
+		return new NullExpression(CodePosition.UNKNOWN);
92
+	}
93
+
94
+	@Override
95
+	public Expression visitGeneric(GenericTypeID generic) {
96
+		return new NullExpression(CodePosition.UNKNOWN);
97
+	}
98
+
99
+	@Override
100
+	public Expression visitRange(RangeTypeID range) {
101
+		return new NullExpression(CodePosition.UNKNOWN);
102
+	}
103
+
104
+	@Override
105
+	public Expression visitOptional(OptionalTypeID type) {
106
+		return new NullExpression(CodePosition.UNKNOWN);
107
+	}
108
+
109
+	@Override
110
+	public Expression visitInvalid(InvalidTypeID type) {
111
+		return new NullExpression(CodePosition.UNKNOWN);
112
+	}
113
+}

+ 25
- 20
ScriptingExample/scripts/arrays.zs Просмотреть файл

@@ -7,24 +7,24 @@
7 7
 //println(a[1]);
8 8
 ////
9 9
 ////
10
-//val multiDim = new int[,,](1,2,3, 130);
11
-//println(multiDim[0,1,2]);
10
+val multiDim = new int[,,](1,2,3, 130);
11
+println(multiDim[0,1,2]);
12
+
13
+val t = multiDim;
12 14
 //
13
-//val t = multiDim;
14
-////
15
-////
16
-//val b = new int[](3);
17
-//for i in b {
18
-//	println(i);
19
-//}
20 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]);
21 24
 //
22
-//val c = new int[,,](1,2,3);
23
-//println(c[0,1,2]);
24
-////
25
-////
26
-////val d = new string[,,](5,5,5, "HelloWorld");
27
-////println(d[2,2,2]);
25
+//
26
+//val d = new string[,,](5,5,5, "HelloWorld");
27
+//println(d[2,2,2]);
28 28
 //
29 29
 //
30 30
 ////val e = new int[](a, value => value);
@@ -37,13 +37,18 @@
37 37
 //val a = new string[](5, "HelloWorld");
38 38
 //val b = new string[]<string>(a, projection);
39 39
 
40
-val d = new string[,,](5,5,5, "HelloWorld");
40
+val d = new string[,,](3,4,5, "HelloWorld");
41
+
42
+val someString = "someString";
41 43
 
42 44
 var projection = (value => "" + value) as function(value as string`borrow) as string;
43
-val e = new string[,,]<string>(d, projection);
45
+val e = new string[,,]<string>(
46
+    d, 
47
+    (value => "137" + value + someString) as function(value as string`borrow) as string
48
+);
44 49
 
45 50
 
46
-val a = new string[](5, "HelloWorld");
47
-val b = new string[]<string>(a, projection);
51
+//val a = new string[](5, "HelloWorld");
52
+//val b = new string[]<string>(a, projection);
48 53
 
49
-println(e[0,0,0]);
54
+println(e[2,3,4]);

Загрузка…
Отмена
Сохранить