Parcourir la source

WIP: Saving so that it is safe :smile:

kindlich il y a 5 ans
Parent
révision
10fc19cc9f
Aucune clé connue n'a été trouvée dans la base pour cette signature

+ 55
- 26
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java Voir le fichier

@@ -301,15 +301,24 @@ public class JavaNativeModule {
301 301
 		TypeVariableContext context = new TypeVariableContext();
302 302
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
303 303
 		TypeParameter[] typeParameters = new TypeParameter[cls.getTypeParameters().length];
304
+		definition.typeParameters = typeParameters;
305
+
304 306
 		for (int i = 0; i < javaTypeParameters.length; i++) {
307
+			//Put up here for nested parameters?
305 308
 			TypeVariable<Class<T>> typeVariable = javaTypeParameters[i];
306 309
 			TypeParameter parameter = new TypeParameter(CodePosition.NATIVE, typeVariable.getName());
310
+			typeParameters[i] = parameter;
311
+			context.put(typeVariable, parameter);
312
+		}
313
+
314
+		for (int i = 0; i < javaTypeParameters.length; i++) {
315
+			TypeVariable<Class<T>> typeVariable = javaTypeParameters[i];
316
+			TypeParameter parameter = typeParameters[i];
307 317
 			for (AnnotatedType bound : typeVariable.getAnnotatedBounds()) {
308 318
 				TypeID type = loadType(context, bound).type;
309 319
 				parameter.addBound(new ParameterTypeBound(CodePosition.NATIVE, type));
310 320
 			}
311 321
 			typeParameters[i] = parameter;
312
-			context.put(typeVariable, parameter);
313 322
 		}
314 323
 
315 324
 		if (definition instanceof ClassDefinition && cls.getAnnotatedSuperclass() != null && shouldLoadType(cls.getAnnotatedSuperclass().getType())) {
@@ -328,8 +337,7 @@ public class JavaNativeModule {
328 337
 				compiled.setImplementationInfo(member, new JavaImplementation(true, javaClass));
329 338
 			}
330 339
 		}
331
-		
332
-		definition.typeParameters = typeParameters;
340
+
333 341
 		compiled.setClassInfo(definition, javaClass);
334 342
 		
335 343
 		StoredType thisType = new StoredType(registry.getForMyDefinition(definition), AutoStorageTag.INSTANCE);
@@ -349,7 +357,7 @@ public class JavaNativeModule {
349 357
 		}
350 358
 		
351 359
 		boolean hasConstructor = false;
352
-		for (java.lang.reflect.Constructor constructor : cls.getConstructors()) {
360
+		for (java.lang.reflect.Constructor<?> constructor : cls.getConstructors()) {
353 361
 			ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor) constructor.getAnnotation(ZenCodeType.Constructor.class);
354 362
 			if (constructorAnnotation != null) {
355 363
 				ConstructorMember member = asConstructor(context, definition, constructor);
@@ -777,6 +785,23 @@ public class JavaNativeModule {
777 785
 			AnnotatedType[] exceptionTypes) {
778 786
 		StoredType returnType = javaReturnType == null ? BasicTypeID.VOID.stored : loadStoredType(context, javaReturnType);
779 787
 		
788
+
789
+		TypeParameter[] typeParameters = new TypeParameter[javaTypeParameters.length];
790
+		for (int i = 0; i < javaTypeParameters.length; i++) {
791
+			//Put up here for nested parameters?
792
+			TypeVariable<Method> typeVariable = javaTypeParameters[i];
793
+			TypeParameter parameter = new TypeParameter(CodePosition.NATIVE, typeVariable.getName());
794
+			typeParameters[i] = parameter;
795
+			context.put(typeVariable, parameter);
796
+		}
797
+
798
+		for (int i = 0; i < javaTypeParameters.length; i++) {
799
+			TypeVariable<Method> javaTypeParameter = javaTypeParameters[i];
800
+			
801
+			for (AnnotatedType bound : javaTypeParameter.getAnnotatedBounds())
802
+				typeParameters[i].addBound(new ParameterTypeBound(CodePosition.NATIVE, loadType(context, bound).type));
803
+		}
804
+
780 805
 		FunctionParameter[] parameters = new FunctionParameter[javaParameters.length];
781 806
 		for (int i = 0; i < parameters.length; i++) {
782 807
 			Parameter parameter = javaParameters[i];
@@ -787,16 +812,6 @@ public class JavaNativeModule {
787 812
 			parameters[i] = new FunctionParameter(type, parameter.getName(), defaultValue, parameter.isVarArgs());
788 813
 		}
789 814
 		
790
-		TypeParameter[] typeParameters = new TypeParameter[javaTypeParameters.length];
791
-		for (int i = 0; i < javaTypeParameters.length; i++) {
792
-			TypeVariable<Method> javaTypeParameter = javaTypeParameters[i];
793
-			typeParameters[i] = new TypeParameter(CodePosition.UNKNOWN, javaTypeParameter.getName());
794
-			context.put(javaTypeParameter, typeParameters[i]);
795
-			
796
-			for (AnnotatedType bound : javaTypeParameter.getAnnotatedBounds())
797
-				typeParameters[i].addBound(new ParameterTypeBound(CodePosition.NATIVE, loadType(context, bound).type));
798
-		}
799
-		
800 815
 		if (exceptionTypes.length > 1)
801 816
 			throw new IllegalArgumentException("A method can only throw a single exception type!");
802 817
 		
@@ -856,10 +871,15 @@ public class JavaNativeModule {
856 871
 				return typeByClass.get(classType).stored();
857 872
 			
858 873
 			HighLevelDefinition definition = addClass(classType);
859
-			return registry.getForDefinition(definition).stored();
874
+			final List<StoredType> s = new ArrayList<>();
875
+			for (TypeVariable<? extends Class<?>> typeParameter : classType.getTypeParameters()) {
876
+				s.add(registry.getGeneric(context.get(typeParameter)).stored());
877
+			}
878
+
879
+			return registry.getForDefinition(definition, s.toArray(StoredType.NONE)).stored();
860 880
 		} else if (type instanceof ParameterizedType) {
861 881
 			ParameterizedType parameterizedType = (ParameterizedType) type;
862
-			Class<?> rawType = (Class) parameterizedType.getRawType();
882
+			Class<?> rawType = (Class<?>) parameterizedType.getRawType();
863 883
 			if (rawType.isAnnotationPresent(FunctionalInterface.class))
864 884
 				return loadFunctionalInterface(context, rawType, (AnnotatedElement[]) parameterizedType.getActualTypeArguments());
865 885
 			
@@ -874,8 +894,8 @@ public class JavaNativeModule {
874 894
             
875 895
             HighLevelDefinition definition = addClass(rawType);
876 896
             return registry.getForDefinition(definition, codeParameters).stored();
877
-		} else if (type instanceof TypeVariable) {
878
-            TypeVariable variable = (TypeVariable) type;
897
+		} else if (type instanceof TypeVariable<?>) {
898
+            TypeVariable<?> variable = (TypeVariable<?>) type;
879 899
             return registry.getGeneric(context.get(variable)).stored();
880 900
         }else if(type instanceof AnnotatedType){
881 901
 		    final StoredType storedType;
@@ -891,11 +911,14 @@ public class JavaNativeModule {
891 911
                 if(rawType == Map.class) {
892 912
                     storedType = registry.getAssociative(codeParameters[0], codeParameters[1]).stored();
893 913
                 } else {
894
-                    HighLevelDefinition definition = addClass((Class<?>) rawType);
895
-                    storedType = registry.getForDefinition(definition, codeParameters).stored();
914
+                    storedType = loadType(context, (AnnotatedElement) rawType, unsigned);
896 915
                 }
897 916
             } else {
898
-		        storedType = loadType(context, (AnnotatedElement) ((AnnotatedType) type).getType(), unsigned);
917
+				if (((AnnotatedType) type).getType() instanceof WildcardType) {
918
+					storedType = BasicTypeID.UNDETERMINED.stored();
919
+				} else {
920
+					storedType = loadType(context, (AnnotatedElement) ((AnnotatedType) type).getType(), unsigned);
921
+				}
899 922
             }
900 923
             
901 924
 		    if(type.isAnnotationPresent(ZenCodeStorageTag.class)) {
@@ -918,7 +941,7 @@ public class JavaNativeModule {
918 941
 		
919 942
 		Map<TypeParameter, StoredType> mapping = new HashMap<>();
920 943
 		TypeVariable[] javaParameters = cls.getTypeParameters();
921
-		for (int i = 0; i < javaParameters.length; i++)
944
+		for (int i = 0; i < parameters.length; i++)
922 945
 			mapping.put(context.get(javaParameters[i]), loadType(loadContext, parameters[i], false, false));
923 946
 		
924 947
 		JavaMethod method = new JavaMethod(
@@ -937,16 +960,22 @@ public class JavaNativeModule {
937 960
 		TypeVariableContext context = new TypeVariableContext();
938 961
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
939 962
 		TypeParameter[] typeParameters = new TypeParameter[cls.getTypeParameters().length];
963
+
940 964
 		for (int i = 0; i < javaTypeParameters.length; i++) {
941 965
 			TypeVariable<Class<T>> typeVariable = javaTypeParameters[i];
942 966
 			TypeParameter parameter = new TypeParameter(CodePosition.NATIVE, typeVariable.getName());
943
-			for (AnnotatedType bound : typeVariable.getAnnotatedBounds()) {
944
-				TypeID type = loadType(context, bound).type;
945
-				parameter.addBound(new ParameterTypeBound(CodePosition.NATIVE, type));
946
-			}
947 967
 			typeParameters[i] = parameter;
968
+
969
+			//Put up here so that Nested Type parameters may work..?
948 970
 			context.put(typeVariable, parameter);
949 971
 		}
972
+
973
+		for (int i = 0; i < javaTypeParameters.length; i++) {
974
+			for (AnnotatedType bound : javaTypeParameters[i].getAnnotatedBounds()) {
975
+				TypeID type = loadType(context, bound).type;
976
+				typeParameters[i].addBound(new ParameterTypeBound(CodePosition.NATIVE, type));
977
+			}
978
+		}
950 979
 		return context;
951 980
 	}
952 981
 	

+ 8
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java Voir le fichier

@@ -85,6 +85,14 @@ public class ParsedExpressionFunction extends ParsedExpression {
85 85
 		if (!scope.genericInferenceMap.isEmpty()) {
86 86
 			// perform type parameter inference
87 87
 			StoredType returnType = statements.getReturnType();
88
+			if(returnType == null) {
89
+				throw new NullPointerException();
90
+			}
91
+
92
+			if(returnType.type == null) {
93
+				throw new NullPointerException();
94
+			}
95
+
88 96
 			Map<TypeParameter, StoredType> inferredTypes = returnType.type.inferTypeParameters(scope.getMemberCache(), genericHeader.getReturnType());
89 97
 			if (inferredTypes == null)
90 98
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");

+ 0
- 4
ScriptingExample/scripts/arithmetic.zs Voir le fichier

@@ -1,4 +0,0 @@
1
-var j = 0;
2
-println(j);
3
-j++;
4
-println(j);

+ 0
- 75
ScriptingExample/scripts/arrays.zs Voir le fichier

@@ -1,75 +0,0 @@
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]);
24
-//
25
-//
26
-//val d = new string[,,](5,5,5, "HelloWorld");
27
-//println(d[2,2,2]);
28
-//
29
-//
30
-////val e = new int[](a, value => value);
31
-//
32
-//
33
-//var projection = (value => value) as function(value as string`borrow) as string;
34
-//val e = new string[](5, "HelloWorld");
35
-//val f = new string[]<string>(e, projection);
36
-//var projection = (value => value) as function(value as string`borrow) as string;
37
-//val a = new string[](5, "HelloWorld");
38
-//val b = new string[]<string>(a, projection);
39
-
40
-val d = new string[,,](3,4,5, "HelloWorld");
41
-
42
-val someString = "someString";
43
-
44
-var projection = (value => "" + value) as function(value as string`borrow) as string;
45
-val e = new string[,,]<string>(
46
-    d, 
47
-    (value => "137" + value + someString) as function(value as string`borrow) as string
48
-);
49
-
50
-
51
-val aSomeArray = new string[](5, "HelloWorld");
52
-val bSomeArray = new string[]<string>(aSomeArray, projection);
53
-println("HelloWorldProjectedArray");
54
-println(bSomeArray[1]);
55
-
56
-println(e[2,3,4]);
57
-
58
-
59
-val constructorLambdaArray = new string[](5, i => "No" + i);
60
-println(constructorLambdaArray[1]);
61
-
62
-val constructorLambdaArrayMulti = new string[,](5, 5, (i1, i2) => "No" + i1 + i2);
63
-println(constructorLambdaArrayMulti[1, 2]);
64
-
65
-
66
-val testArray = new string[,](5, 5, "helloWorld");
67
-
68
-val indexedProjectionWithLambdaNonInlined = new string[,]<string>(testArray as string[,], (index1, index2, value) => {
69
-    return value + "" + index1 + index2;
70
-} as function(index1 as usize, index2 as usize, value as string`borrow) as string);
71
-
72
-val indexedProjectionWithLambdaInlined = new string[,]<string>(testArray, ((i as usize, j as usize, s as string`borrow) => (s + "" + i + j) as string) as function(i as usize, j as usize, s as string`borrow) as string);
73
-
74
-println(indexedProjectionWithLambdaNonInlined[1, 2]);
75
-println(indexedProjectionWithLambdaInlined[1, 2]);

+ 0
- 83
ScriptingExample/scripts/classes.zs Voir le fichier

@@ -1,83 +0,0 @@
1
-public class myTestClass {
2
-
3
-	var nonFinalInt as int = 10;
4
-	val finalInt as int = 20;
5
-
6
-	static var staticNonFinalInt as int = 10;
7
-
8
-	public this() {
9
-
10
-	}
11
-
12
-	public this(nonfinalInt as int) {
13
-		this.nonFinalInt = nonfinalInt;
14
-		println(nonfinalInt);
15
-	}
16
-
17
-	public test() as string {
18
-		return "TEST";
19
-	}
20
-}
21
-
22
-
23
-
24
-val tt = new myTestClass(666);
25
-println(tt.test());
26
-
27
-public interface myTestInterface {
28
-	test() as string;
29
-}
30
-
31
-
32
-public enum myTestEnum {
33
-	ADD(6),
34
-    SUB(6),
35
-    MUL(7),
36
-    DIV(7),
37
-    MOD(7),
38
-    CAT(6),
39
-    OR(4),
40
-    AND(4),
41
-    XOR(4),
42
-    NEG(8),
43
-    NOT(8),
44
-    INVERT(8),
45
-    CONTAINS(5),
46
-    COMPARE(5),
47
-    ASSIGN(0),
48
-    ADDASSIGN(0),
49
-    SUBASSIGN(0),
50
-    MULASSIGN(0),
51
-    DIVASSIGN(0),
52
-    MODASSIGN(0),
53
-    CATASSIGN(0),
54
-    ORASSIGN(0),
55
-    ANDASSIGN(0),
56
-    XORASSIGN(0),
57
-    ANDAND(3),
58
-    OROR(2),
59
-    TERNARY(1),
60
-    COALESCE(2),
61
-    INCREMENT(8),
62
-    DECREMENT(8),
63
-    MEMBER(9),
64
-    RANGE(9),
65
-    INDEX(9),
66
-    CALL(9),
67
-    CAST(9),
68
-    PRIMARY(10);
69
-
70
-	private val priority as int;
71
-	private val isCommutative as bool;
72
-
73
-	public static val test as int = 10;
74
-
75
-	this(i as int) {
76
-		this(i, false);
77
-	}
78
-
79
-	this(i as int, isCommutative as bool) {
80
-		this.priority = i;
81
-		this.isCommutative = isCommutative;
82
-		}
83
-}

+ 0
- 58
ScriptingExample/scripts/conditionals.zs Voir le fichier

@@ -1,58 +0,0 @@
1
-val ternaryOperation = true ? 100 : 222;
2
-
3
-println(ternaryOperation);
4
-
5
-
6
-
7
-var coalesce_one as string? = null;
8
-var coalesce_tow as string? = "test";
9
-
10
-
11
-var coalesce = coalesce_one ?? coalesce_tow;
12
-
13
-println(coalesce);
14
-
15
-
16
-//if(coalesce == "test123") {
17
-//	println("true");
18
-//}
19
-
20
-if 1 == 1 {
21
-	println("intCompareTrue");
22
-}
23
-
24
-//if(1 == "1") {
25
-//	println("well...");
26
-//}
27
-
28
-
29
-if "1" == 1 {
30
-	println("...");
31
-}
32
-
33
-
34
-//var coco as int? = 10;
35
-//var coal as int? = 1;
36
-//
37
-//println(coal ?? coco);
38
-
39
-
40
-println(".....");
41
-println(true ? "RR" : "TT");
42
-
43
-
44
-println((false && true && true) ? "true" : "false");
45
-println((true && true) ? "true" : "false");
46
-println((true && false) ? "true" : "false");
47
-println((false && false) ? "true" : "false");
48
-
49
-println("---");
50
-
51
-println((false || true) ? "true" : "false");
52
-println((true || true) ? "true" : "false");
53
-println((true || false) ? "true" : "false");
54
-println((false || false) ? "true" : "false");
55
-
56
-println(":::");
57
-
58
-println((1 <= 2) ? "true" : "false");

+ 0
- 17
ScriptingExample/scripts/functionalInterfaces.zs Voir le fichier

@@ -1,17 +0,0 @@
1
-//val x = ((a as string) => "hello" + a) as function`auto(a as string) as string`auto;
2
-//invokeFunctional(x);
3
-
4
-val y = (a as int, b as int) => a + b;
5
-
6
-
7
-//invokeFunctionalInt((a, b) => a + b);
8
-invokeFunctionalInt(y);
9
-
10
-
11
-println(((x as int) => x)(10));
12
-
13
-//TODO: Globals can't be "captured"
14
-//invokeFunctionalInt((a, b) => {
15
-//	println("a");
16
-//	return a + b;
17
-//});

+ 0
- 20
ScriptingExample/scripts/functions.zs Voir le fichier

@@ -1,20 +0,0 @@
1
-function test() as void {
2
-	println("functions.zs; test1");
3
-}
4
-
5
-
6
-
7
-function test2() as void {
8
-	println("functions.zs; test2");
9
-}
10
-
11
-
12
-test();
13
-test2();
14
-println(test3(1, 3));
15
-
16
-
17
-function test3(a as int, b as int) as int{
18
-	println(a+b);
19
-	return a + b;
20
-}

+ 0
- 19
ScriptingExample/scripts/functions2.zs Voir le fichier

@@ -1,19 +0,0 @@
1
-val outOfScope = 10;
2
-
3
-val fun = (a as int, b as int) as int => a + b * outOfScope;
4
-println(fun(30, 20));
5
-
6
-function apply_fn2(fn as function(value as int, othervalue as int) as int, value as int) as int {
7
-    return fn(value, value);
8
-}
9
-
10
-//function scale(value as int, scale as int) as int {
11
-
12
-//	val fun as function(value as int, othervalue as int) as int = ((v as int) as int => v * scale);
13
-//    return apply(fun, scale);
14
-//}
15
-
16
-apply_fn2(fun, 10);
17
-
18
-//println("Value: " + scale(10, 5));
19
-

+ 0
- 1
ScriptingExample/scripts/functions3.zs Voir le fichier

@@ -1 +0,0 @@
1
-function apply2(fn as function(value as int) as int, scale as int) as int {
    return fn(scale);
}

function scale2(value as int, scale as int) as int {
    return apply2(v => v * scale, value);
}

+ 0
- 22
ScriptingExample/scripts/functions_lambdas.zs Voir le fichier

@@ -1,22 +0,0 @@
1
-val outOfScope = 10;
2
-val fun1 = (a as int, b as int) as int => a + b * outOfScope;
3
-val fun2 = (a as int, c as int) as int => 13;
4
-
5
-
6
-
7
-function apply(fn as function(value as int) as int, scale as int) as int {
8
-    return fn(scale);
9
-}
10
-
11
-
12
-println(fun1(30, 20));
13
-println(fun2(30, 20));
14
-
15
-
16
-
17
-
18
-function scale(value as int, scale as int) as int {
19
-    return apply(v => v * scale, value);
20
-}
21
-
22
-println("Value: " + scale(10, 5));

+ 0
- 12
ScriptingExample/scripts/helloworld.zs Voir le fichier

@@ -1,12 +0,0 @@
1
-println("Hello \&copy; world!");
2
-println(5);
3
-println(2 + 5);
4
-println(1 - 2);
5
-println(1 + 3 as long);
6
-
7
-println(<hello world in bracket parser>);
8
-
9
-
10
-var a = null as string?;
11
-if (a == null)
12
-	println("A is null!");

+ 0
- 54
ScriptingExample/scripts/integration.zs Voir le fichier

@@ -1,54 +0,0 @@
1
-import example.TestClass;
2
-import example.TestInterface;
3
-
4
-val instance = new TestClass("Instance");
5
-println("Name: " + instance.name);
6
-instance.dump();
7
-instance.withDefaultParameter("Hello");
8
-instance.withDefaultParameter("Hello", "moon");
9
-
10
-var generated = instance.generate();
11
-println(generated.getValue());
12
-
13
-class TestOperators {
14
-	public (name as string) as void {
15
-		println("MyTestClass: " + name);
16
-	}
17
-	
18
-	//.(key as string) as string
19
-	//	=> "key " + key;
20
-}
21
-
22
-/*class TestImplementation {
23
-	public implements TestInterface {
24
-		interfaceMethod() => "TestImplementation";
25
-	}
26
-}*/
27
-
28
-val testInstance = new TestOperators();
29
-//testInstance("something");
30
-
31
-something.dump();
32
-
33
-val objects = makeArray(5);
34
-printMany(objects);
35
-
36
-
37
-println(<test string>);
38
-println(<test string>.name);
39
-println(<test string>.interfaceMethod());
40
-//println(new TestImplementation().interfaceMethod());
41
-
42
-var diamond = <item:minecraft:diamond>;
43
-var dirt = <item:minecraft:dirt>;
44
-addShapedRecipe("TestRecipe", diamond, [[dirt, dirt, dirt],[dirt, dirt, dirt],[dirt, dirt, dirt]]);
45
-
46
-var count = 10;
47
-floatMethod(5f * count);
48
-
49
-invokeFunctional(name => "Hello " + name);
50
-
51
-//val x = (a as string) => "hello" + a;
52
-//invokeFunctional(x);
53
-
54
-testOptional(value => value == null ? 0 : value.length as int);

+ 0
- 17
ScriptingExample/scripts/interfaces.zs Voir le fichier

@@ -1,17 +0,0 @@
1
-public interface MyInterface {
2
-	interfaceMethod() as string;
3
-}
4
-
5
-public class MyClass {
6
-	val name as string;
7
-	
8
-	public this(name as string) {
9
-		this.name = name;
10
-	}
11
-
12
-	public implements MyInterface {
13
-		interfaceMethod() => "InterfaceMethod " + name;
14
-	}
15
-}
16
-
17
-println(new MyClass("hello").interfaceMethod());

+ 0
- 94
ScriptingExample/scripts/moreHellos.zs Voir le fichier

@@ -1,94 +0,0 @@
1
-println("Hello world!");
2
-println(1 as string);
3
-
4
-
5
-var test = "test";
6
-println(test);
7
-
8
-
9
-test = "testMore";
10
-println(test);
11
-
12
-test = 13;
13
-println(test);
14
-
15
-val test2 = 14;
16
-println(test2);
17
-
18
-
19
-if true 
20
-    println("ifTest");
21
-else
22
-    println("elseTest");
23
-
24
-
25
-if false 
26
-    println("testIf");
27
-else
28
-    println("testElse");
29
-
30
-
31
-if (true) {
32
-
33
-    while :testLable true {
34
-        println("trueee");
35
-        if true
36
-            break testLable;
37
-        else
38
-            println("nobreak");
39
-    }
40
-    
41
-    
42
-    do {
43
-        println("tru"); 
44
-        if(false){
45
-        	println("brea");
46
-            continue;
47
-        }
48
-        else{
49
-            println("");
50
-            break;
51
-        }
52
-    } while true;
53
-}
54
-
55
-var testArray = ["1", "2", "3"];
56
-
57
-for item in testArray {
58
-	println("test");
59
-	println(item);
60
-}
61
-
62
-println("");
63
-
64
-var test3 = [1, 2, 3];
65
-
66
-for item in test3 {
67
-	println(item);
68
-}
69
-
70
-for i, item in ["5", "ttt"] {
71
-	println(item + i);
72
-}
73
-
74
-for i, item in [1, 5, 7] {
75
-	println(item + (i as int));
76
-}
77
-
78
-for myI in 10 .. 20 {
79
-	println(myI);
80
-}
81
-
82
-var lateInit as string;
83
-lateInit = "initialized later";
84
-println(lateInit);
85
-
86
-
87
-
88
-
89
-
90
-/*
91
-catch e as string {
92
-	println("noLuv");
93
-}
94
-*/

+ 0
- 3
ScriptingExample/scripts/scriptparameters.zs Voir le fichier

@@ -1,3 +0,0 @@
1
-println("Arguments:");
2
-for i, arg in args
3
-	println("- " + i + ": " + arg);

+ 0
- 2
ScriptingExample/scripts/statements.zs Voir le fichier

@@ -1,2 +0,0 @@
1
-//while true
2
-//	println("Hello!");

+ 0
- 18
ScriptingExample/scripts/switch.zs Voir le fichier

@@ -1,18 +0,0 @@
1
-val test as int = 10;
2
-
3
-
4
-switch test {
5
-	case 1 : println("yay"); break;
6
-	case 10 : println("yo");
7
-	case 100 : println("y");
8
-	default: println("yup");
9
-}
10
-
11
-
12
-val test2 as string = "hello";
13
-
14
-switch test2 {
15
-	case "bye" : println("hello");
16
-	case "hello" : println("goodbye");
17
-	default: println("hellogoodbye");
18
-}

+ 0
- 70
ScriptingExample/scripts/variants.zs Voir le fichier

@@ -1,70 +0,0 @@
1
-public variant Result<T, E> {
2
-    Ok(T),
3
-    Error(E),
4
-    Other(T, E);
5
-    
6
-    /*public then<R>(fn as function(result as T) as Result<R, E>) as Result<R, E> {
7
-        return match this {
8
-            Ok(result) => fn(result),
9
-            Error(error) => Error(error),
10
-			Other(result, error) => fn(result)
11
-        };
12
-    }*/
13
-    
14
-    //public handle<X>(handler as function(error as E) as Result<T, X>) as Result<T, X> {
15
-    //    return match this {
16
-    //        Ok(result) => Ok(result),
17
-    //        Error(error) => handler(error)
18
-    //    };
19
-    //}
20
-    
21
-    public expect() as T {
22
-        return match this {
23
-            Ok(result) => result,
24
-            Error(error) => panic "expect() called on an error value",
25
-			Other(result, error) => result
26
-        };
27
-    }
28
-    
29
-    public orElse(other as T) as T {
30
-        return match this {
31
-            Ok(result) => result,
32
-            Error(error) => other,
33
-			Other(result, error) => result
34
-        };
35
-    }
36
-    
37
-    public orElse(other as function(error as E) as T) as T {
38
-        return match this {
39
-            Ok(result) => result,
40
-            Error(error) => other(error),
41
-			Other(result, error) => result
42
-        };
43
-    }
44
-}
45
-
46
-
47
-
48
-function makeResult() as Result<string, string>
49
-    => Ok("10");
50
-
51
-
52
-function makeErrResult() as Result<string, string>
53
-    => Error("10");
54
-
55
-
56
-println(makeResult().orElse("Ten"));
57
-println(makeResult().expect());
58
-println(makeErrResult().orElse("Ten"));
59
-
60
-
61
-//CompileException [TYPE_ARGUMENTS_NOT_INFERRABLE] Could not infer generic type parameters [ParsedExpressionFunction.compile, line 75]
62
-//println(makeResult().then(tValue => Result<string, string>.Ok(tValue)).expect());
63
-
64
-//IllegalArgumentException: Cannot retrieve members of undetermined type [TypeMembers.<init>, line 71]
65
-//println(makeResult().then(a => Ok(a)).expect());
66
-//println(makeResult().then(a as string => Ok(a)).expect());
67
-
68
-//CompileException [UNEXPECTED_TOKEN] ) expected [LLparserTokenStream.required, line 97]
69
-//Wants to compile a call to function() instead of creating a lambda
70
-//println(makeResult().then((function (t as string) as Result<string, string>)(t => Ok(t))).expect());

Loading…
Annuler
Enregistrer