Browse Source

Merge remote-tracking branch 'kindlich/development' into development

Jared 5 years ago
parent
commit
eaa9db6cad
No account linked to committer's email address
40 changed files with 641 additions and 845 deletions
  1. 4
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeDefinitionAnnotation.java
  2. 6
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialGlobalExpression.java
  3. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BlockStatement.java
  4. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java
  5. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  6. 44
    30
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  7. 5
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunUnit.java
  8. 3
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  9. 18
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  10. 11
    5
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  11. 7
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  12. 251
    206
      JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java
  13. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java
  14. 10
    4
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java
  15. 124
    0
      Parser/src/main/java/org/openzen/zenscript/parser/EscapableBracketParser.java
  16. 19
    9
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java
  17. 0
    4
      ScriptingExample/scripts/arithmetic.zs
  18. 0
    75
      ScriptingExample/scripts/arrays.zs
  19. 0
    83
      ScriptingExample/scripts/classes.zs
  20. 0
    58
      ScriptingExample/scripts/conditionals.zs
  21. 0
    17
      ScriptingExample/scripts/functionalInterfaces.zs
  22. 0
    20
      ScriptingExample/scripts/functions.zs
  23. 0
    19
      ScriptingExample/scripts/functions2.zs
  24. 0
    1
      ScriptingExample/scripts/functions3.zs
  25. 0
    22
      ScriptingExample/scripts/functions_lambdas.zs
  26. 0
    12
      ScriptingExample/scripts/helloworld.zs
  27. 0
    54
      ScriptingExample/scripts/integration.zs
  28. 0
    17
      ScriptingExample/scripts/interfaces.zs
  29. 0
    94
      ScriptingExample/scripts/moreHellos.zs
  30. 0
    3
      ScriptingExample/scripts/scriptparameters.zs
  31. 0
    2
      ScriptingExample/scripts/statements.zs
  32. 0
    18
      ScriptingExample/scripts/switch.zs
  33. 0
    70
      ScriptingExample/scripts/variants.zs
  34. 4
    0
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Globals.java
  35. 19
    7
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  36. 24
    0
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/EventManager.java
  37. 41
    0
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/IEvent.java
  38. 4
    0
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/SomeMCEvent.java
  39. 25
    0
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/impl/CTStringedEvent.java
  40. 12
    0
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/impl/StringedEvent.java

+ 4
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeDefinitionAnnotation.java View File

40
 	public void serialize(CodeSerializationOutput output, HighLevelDefinition definition, TypeContext context) {
40
 	public void serialize(CodeSerializationOutput output, HighLevelDefinition definition, TypeContext context) {
41
 		output.writeString(identifier);
41
 		output.writeString(identifier);
42
 	}
42
 	}
43
+
44
+	public String getIdentifier() {
45
+		return identifier;
46
+	}
43
 }
47
 }

+ 6
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialGlobalExpression.java View File

9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
-import org.openzen.zenscript.codemodel.expression.CallArguments;
13
-import org.openzen.zenscript.codemodel.expression.Expression;
14
-import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
15
-import org.openzen.zenscript.codemodel.expression.GlobalExpression;
12
+import org.openzen.zenscript.codemodel.expression.*;
16
 import org.openzen.zenscript.codemodel.scope.TypeScope;
13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
17
 import org.openzen.zenscript.codemodel.GenericName;
14
 import org.openzen.zenscript.codemodel.GenericName;
18
 import org.openzen.zenscript.codemodel.type.StoredType;
15
 import org.openzen.zenscript.codemodel.type.StoredType;
63
 	public StoredType[] getTypeArguments() {
60
 	public StoredType[] getTypeArguments() {
64
 		return typeArguments;
61
 		return typeArguments;
65
 	}
62
 	}
63
+
64
+	@Override
65
+	public IPartialExpression capture(CodePosition position, LambdaClosure closure) {
66
+		return this;
67
+	}
66
 }
68
 }

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BlockStatement.java View File

7
 
7
 
8
 import java.util.Arrays;
8
 import java.util.Arrays;
9
 import java.util.List;
9
 import java.util.List;
10
+import java.util.Objects;
10
 import java.util.function.Consumer;
11
 import java.util.function.Consumer;
11
 import java.util.stream.Collectors;
12
 import java.util.stream.Collectors;
12
 
13
 
96
 	public StoredType getReturnType() {
97
 	public StoredType getReturnType() {
97
 		final List<StoredType> collect = Arrays.stream(statements)
98
 		final List<StoredType> collect = Arrays.stream(statements)
98
 				.map(Statement::getReturnType)
99
 				.map(Statement::getReturnType)
100
+				.filter(Objects::nonNull)
99
 				.distinct()
101
 				.distinct()
100
 				.collect(Collectors.toList());
102
 				.collect(Collectors.toList());
101
 		if(collect.isEmpty())
103
 		if(collect.isEmpty())

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java View File

11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
12
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
14
 import org.openzen.zenscript.codemodel.type.StoredType;
15
 import org.openzen.zenscript.codemodel.type.StoredType;
15
 
16
 
16
 /**
17
 /**
28
 	
29
 	
29
 	@Override
30
 	@Override
30
 	public StoredType getReturnType() {
31
 	public StoredType getReturnType() {
31
-		return value.type;
32
+		return value != null ? value.type : BasicTypeID.VOID.stored();
32
 	}
33
 	}
33
 	
34
 	
34
 	@Override
35
 	@Override

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
+import java.util.Collection;
8
 import java.util.HashMap;
9
 import java.util.HashMap;
9
 import java.util.Map;
10
 import java.util.Map;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
110
 			return id;
111
 			return id;
111
 		}
112
 		}
112
 	}
113
 	}
114
+
115
+	public Collection<DefinitionTypeID> getDefinitions() {
116
+		return definitionTypes.keySet();
117
+	}
113
 }
118
 }

+ 44
- 30
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java View File

11
 import org.openzen.zenscript.codemodel.CompareType;
11
 import org.openzen.zenscript.codemodel.CompareType;
12
 import org.openzen.zenscript.codemodel.GenericName;
12
 import org.openzen.zenscript.codemodel.GenericName;
13
 import org.openzen.zenscript.codemodel.OperatorType;
13
 import org.openzen.zenscript.codemodel.OperatorType;
14
-import org.openzen.zenscript.codemodel.expression.CallArguments;
15
-import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
16
-import org.openzen.zenscript.codemodel.expression.Expression;
17
-import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
18
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
19
-import org.openzen.zenscript.codemodel.expression.NullExpression;
20
-import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
21
-import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
22
-import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
14
+import org.openzen.zenscript.codemodel.expression.*;
23
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
15
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
16
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
25
 import org.openzen.zenscript.codemodel.member.InnerDefinition;
17
 import org.openzen.zenscript.codemodel.member.InnerDefinition;
26
-import org.openzen.zenscript.codemodel.member.ref.CasterMemberRef;
27
-import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
28
-import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
29
-import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
30
-import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
31
-import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
32
-import org.openzen.zenscript.codemodel.member.ref.ImplementationMemberRef;
33
-import org.openzen.zenscript.codemodel.member.ref.IteratorMemberRef;
34
-import org.openzen.zenscript.codemodel.member.ref.SetterMemberRef;
35
-import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
36
-import org.openzen.zenscript.codemodel.partial.IPartialExpression;
37
-import org.openzen.zenscript.codemodel.partial.PartialMemberGroupExpression;
38
-import org.openzen.zenscript.codemodel.partial.PartialStaticMemberGroupExpression;
39
-import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
40
-import org.openzen.zenscript.codemodel.partial.PartialVariantOptionExpression;
18
+import org.openzen.zenscript.codemodel.member.ref.*;
19
+import org.openzen.zenscript.codemodel.partial.*;
41
 import org.openzen.zenscript.codemodel.scope.TypeScope;
20
 import org.openzen.zenscript.codemodel.scope.TypeScope;
42
 import org.openzen.zenscript.codemodel.type.*;
21
 import org.openzen.zenscript.codemodel.type.*;
43
 
22
 
44
-import java.util.ArrayList;
45
-import java.util.HashMap;
46
-import java.util.List;
47
-import java.util.Map;
48
-import java.util.Set;
23
+import java.util.*;
49
 
24
 
50
 /**
25
 /**
51
  *
26
  *
81
 	
56
 	
82
 	public boolean extendsOrImplements(TypeID other) {
57
 	public boolean extendsOrImplements(TypeID other) {
83
 		other = other.getNormalized();
58
 		other = other.getNormalized();
59
+		checkBoundaries:
60
+		if(this.type.type instanceof DefinitionTypeID && other instanceof DefinitionTypeID) {
61
+			DefinitionTypeID thisTypeId = (DefinitionTypeID) this.type.type;
62
+			DefinitionTypeID otherTypeId = (DefinitionTypeID) other;
63
+
64
+			if(thisTypeId.definition != otherTypeId.definition){
65
+				break checkBoundaries;
66
+			}
67
+
68
+			if(thisTypeId.definition.typeParameters.length != otherTypeId.typeArguments.length){
69
+				break checkBoundaries;
70
+			}
71
+
72
+			for (int i = 0; i < thisTypeId.definition.typeParameters.length; i++) {
73
+				final TypeID type = otherTypeId.typeArguments[i].type;
74
+				if (type == BasicTypeID.UNDETERMINED) {
75
+					continue;
76
+				}
77
+				if (type instanceof InvalidTypeID && ((InvalidTypeID) type).code == CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE) {
78
+					continue;
79
+				}
80
+				if (thisTypeId.definition.typeParameters[i].matches(cache, type)) {
81
+					continue;
82
+				}
83
+				break checkBoundaries;
84
+			}
85
+			return true;
86
+		}
87
+
88
+
84
 		TypeID superType = type.type.getSuperType(cache.getRegistry());
89
 		TypeID superType = type.type.getSuperType(cache.getRegistry());
85
 		if (superType != null) {
90
 		if (superType != null) {
86
 			if (superType == other)
91
 			if (superType == other)
430
    
435
    
431
 		if( getImplicitCaster(toType) != null || extendsOrImplements(toType.type))
436
 		if( getImplicitCaster(toType) != null || extendsOrImplements(toType.type))
432
 		    return true;
437
 		    return true;
433
-		
438
+
439
+		if(type.type.isGeneric() && type.type instanceof GenericTypeID) {
440
+			final GenericTypeID genericTypeID = (GenericTypeID) type.type;
441
+			if(genericTypeID.parameter.matches(cache, toType.type)) {
442
+				return true;
443
+			}
444
+		}
445
+
446
+
434
         final StoredType accept = type.type.accept(new TagRemovingTypeVisitor(cache));
447
         final StoredType accept = type.type.accept(new TagRemovingTypeVisitor(cache));
448
+
435
         if(!this.type.type.equals(accept.type) && cache.get(accept).canCastImplicit(toType)){
449
         if(!this.type.type.equals(accept.type) && cache.get(accept).canCastImplicit(toType)){
436
             return true;
450
             return true;
437
         }
451
         }

+ 5
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunUnit.java View File

92
 			directory.mkdirs();
92
 			directory.mkdirs();
93
 
93
 
94
 		for (Map.Entry<String, byte[]> classEntry : classes.entrySet()) {
94
 		for (Map.Entry<String, byte[]> classEntry : classes.entrySet()) {
95
-			File output = new File(directory, classEntry.getKey() + ".class");
95
+			File output = new File(directory, classEntry.getKey().replace('.', File.separatorChar) + ".class");
96
+			if (!output.getParentFile().exists() && !output.getParentFile().mkdirs()) {
97
+				//Throw error?
98
+				continue;
99
+			}
96
 			try (FileOutputStream outputStream = new FileOutputStream(output)) {
100
 			try (FileOutputStream outputStream = new FileOutputStream(output)) {
97
 				outputStream.write(classEntry.getValue());
101
 				outputStream.write(classEntry.getValue());
98
 			} catch (IOException ex) {
102
 			} catch (IOException ex) {

+ 3
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java View File

48
 		context.addModule(module.module, target);
48
 		context.addModule(module.module, target);
49
 		
49
 		
50
 		for (HighLevelDefinition definition : module.definitions.getAll()) {
50
 		for (HighLevelDefinition definition : module.definitions.getAll()) {
51
-			String filename = getFilename(definition) + "_" + (definition.name == null ? "generated" : definition.name) + "_" + expansionCounter++;
52
-			JavaPrepareDefinitionVisitor definitionPreparer = new JavaPrepareDefinitionVisitor(context, target, filename, null);
51
+			final String className = getFilename(definition);
52
+			String filename = className + "_" + (definition.name == null ? "generated" : definition.name) + "_" + expansionCounter++;
53
+			JavaPrepareDefinitionVisitor definitionPreparer = new JavaPrepareDefinitionVisitor(context, target, filename, null, className);
53
 			definition.accept(definitionPreparer);
54
 			definition.accept(definitionPreparer);
54
 		}
55
 		}
55
 		
56
 		

+ 18
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

159
     private final JavaBoxingTypeVisitor boxingTypeVisitor;
159
     private final JavaBoxingTypeVisitor boxingTypeVisitor;
160
     private final JavaUnboxingTypeVisitor unboxingTypeVisitor;
160
     private final JavaUnboxingTypeVisitor unboxingTypeVisitor;
161
     private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
161
     private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
162
-    private final JavaBytecodeContext context;
163
-    private final JavaCompiledModule module;
162
+    final JavaBytecodeContext context;
163
+    final JavaCompiledModule module;
164
 
164
 
165
 	public JavaExpressionVisitor(JavaBytecodeContext context, JavaCompiledModule module, JavaWriter javaWriter) {
165
 	public JavaExpressionVisitor(JavaBytecodeContext context, JavaCompiledModule module, JavaWriter javaWriter) {
166
 		this.javaWriter = javaWriter;
166
 		this.javaWriter = javaWriter;
1961
 		final String signature;
1961
 		final String signature;
1962
 		final String[] interfaces;
1962
 		final String[] interfaces;
1963
 		final String className = context.getLambdaCounter();
1963
 		final String className = context.getLambdaCounter();
1964
+		final String descriptor;
1964
 		
1965
 		
1965
 		{//Fill the info above
1966
 		{//Fill the info above
1966
 			final StorageTag actualStorage = expression.type.getActualStorage();
1967
 			final StorageTag actualStorage = expression.type.getActualStorage();
1970
 				
1971
 				
1971
 				//Should be the same, should it not?
1972
 				//Should be the same, should it not?
1972
 				signature = context.getMethodSignature(expression.header);
1973
 				signature = context.getMethodSignature(expression.header);
1974
+				descriptor = context.getMethodDescriptor(expression.header);
1973
 				interfaces = new String[]{Type.getInternalName(functionalInterfaceMethod.getDeclaringClass())};
1975
 				interfaces = new String[]{Type.getInternalName(functionalInterfaceMethod.getDeclaringClass())};
1974
 			} else {
1976
 			} else {
1975
 				//Normal way, no casting to functional interface
1977
 				//Normal way, no casting to functional interface
1976
 				signature = context.getMethodSignature(expression.header);
1978
 				signature = context.getMethodSignature(expression.header);
1979
+				descriptor = context.getMethodDescriptor(expression.header);
1977
 				interfaces = new String[]{context.getInternalName(new FunctionTypeID(null, expression.header).stored(UniqueStorageTag.INSTANCE))};
1980
 				interfaces = new String[]{context.getInternalName(new FunctionTypeID(null, expression.header).stored(UniqueStorageTag.INSTANCE))};
1978
 			}
1981
 			}
1979
 		}
1982
 		}
1989
 		final JavaWriter functionWriter;
1992
 		final JavaWriter functionWriter;
1990
 		
1993
 		
1991
 		//Bridge method!!!
1994
 		//Bridge method!!!
1992
-		if (!Objects.equals(methodInfo.descriptor, signature)) {
1995
+		if (!Objects.equals(methodInfo.descriptor, descriptor)) {
1993
 			final JavaMethod bridgeMethodInfo = new JavaMethod(methodInfo.cls, methodInfo.kind, methodInfo.name, methodInfo.compile, methodInfo.descriptor, methodInfo.modifiers | JavaModifiers.BRIDGE | JavaModifiers.SYNTHETIC, methodInfo.genericResult, methodInfo.typeParameterArguments);
1996
 			final JavaMethod bridgeMethodInfo = new JavaMethod(methodInfo.cls, methodInfo.kind, methodInfo.name, methodInfo.compile, methodInfo.descriptor, methodInfo.modifiers | JavaModifiers.BRIDGE | JavaModifiers.SYNTHETIC, methodInfo.genericResult, methodInfo.typeParameterArguments);
1994
 			final JavaWriter bridgeWriter = new JavaWriter(expression.position, lambdaCW, bridgeMethodInfo, null, methodInfo.descriptor, null, "java/lang/Override");
1997
 			final JavaWriter bridgeWriter = new JavaWriter(expression.position, lambdaCW, bridgeMethodInfo, null, methodInfo.descriptor, null, "java/lang/Override");
1995
 			bridgeWriter.start();
1998
 			bridgeWriter.start();
2016
 			
2019
 			
2017
 			
2020
 			
2018
 			
2021
 			
2019
-			final JavaMethod actualMethod = new JavaMethod(methodInfo.cls, methodInfo.kind, methodInfo.name, methodInfo.compile, signature, methodInfo.modifiers, methodInfo.genericResult, methodInfo.typeParameterArguments);
2022
+			final JavaMethod actualMethod = new JavaMethod(methodInfo.cls, methodInfo.kind, methodInfo.name, methodInfo.compile, context.getMethodDescriptor(expression.header), methodInfo.modifiers, methodInfo.genericResult, methodInfo.typeParameterArguments);
2020
 			//No @Override
2023
 			//No @Override
2021
 			functionWriter = new JavaWriter(expression.position, lambdaCW, actualMethod, null, signature, null);
2024
 			functionWriter = new JavaWriter(expression.position, lambdaCW, actualMethod, null, signature, null);
2022
 		} else {
2025
 		} else {
2061
 		final JavaStatementVisitor CSV = new JavaStatementVisitor(context, new JavaExpressionVisitor(context, module, functionWriter) {
2064
 		final JavaStatementVisitor CSV = new JavaStatementVisitor(context, new JavaExpressionVisitor(context, module, functionWriter) {
2062
 			@Override
2065
 			@Override
2063
 			public Void visitGetLocalVariable(GetLocalVariableExpression varExpression) {
2066
 			public Void visitGetLocalVariable(GetLocalVariableExpression varExpression) {
2067
+				final JavaLocalVariableInfo localVariable = functionWriter.tryGetLocalVariable(varExpression.variable.variable);
2068
+				if(localVariable != null) {
2069
+					final Label label = new Label();
2070
+					localVariable.end = label;
2071
+					functionWriter.label(label);
2072
+					functionWriter.load(localVariable);
2073
+					return null;
2074
+				}
2075
+
2076
+
2077
+
2064
 				final int position = calculateMemberPosition(varExpression, expression);
2078
 				final int position = calculateMemberPosition(varExpression, expression);
2065
 				functionWriter.loadObject(0);
2079
 				functionWriter.loadObject(0);
2066
 				functionWriter.getField(className, "captured" + position, context.getDescriptor(varExpression.variable.type));
2080
 				functionWriter.getField(className, "captured" + position, context.getDescriptor(varExpression.variable.type));

+ 11
- 5
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java View File

16
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
16
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
17
     private final JavaWriter javaWriter;
17
     private final JavaWriter javaWriter;
18
 	final JavaBytecodeContext context;
18
 	final JavaBytecodeContext context;
19
-    public JavaExpressionVisitor expressionVisitor;
20
-	public JavaNonPushingExpressionVisitor nonPushingExpressionVisitor;
19
+    public final JavaExpressionVisitor expressionVisitor;
20
+	public final JavaNonPushingExpressionVisitor nonPushingExpressionVisitor;
21
 
21
 
22
     /**
22
     /**
23
      * @param javaWriter the method writer that compiles the statement
23
      * @param javaWriter the method writer that compiles the statement
26
         this.javaWriter = javaWriter;
26
         this.javaWriter = javaWriter;
27
 		this.context = context;
27
 		this.context = context;
28
         this.expressionVisitor = new JavaExpressionVisitor(context, module, javaWriter);
28
         this.expressionVisitor = new JavaExpressionVisitor(context, module, javaWriter);
29
-		nonPushingExpressionVisitor = new JavaNonPushingExpressionVisitor(context, module, javaWriter, expressionVisitor);
29
+		this.nonPushingExpressionVisitor = new JavaNonPushingExpressionVisitor(context, module, javaWriter, expressionVisitor);
30
     }
30
     }
31
 
31
 
32
     public JavaStatementVisitor(JavaBytecodeContext context, JavaExpressionVisitor expressionVisitor) {
32
     public JavaStatementVisitor(JavaBytecodeContext context, JavaExpressionVisitor expressionVisitor) {
33
         this.javaWriter = expressionVisitor.getJavaWriter();
33
         this.javaWriter = expressionVisitor.getJavaWriter();
34
 		this.context = context;
34
 		this.context = context;
35
         this.expressionVisitor = expressionVisitor;
35
         this.expressionVisitor = expressionVisitor;
36
+		this.nonPushingExpressionVisitor = new JavaNonPushingExpressionVisitor(expressionVisitor.context, expressionVisitor.module, expressionVisitor.javaWriter, expressionVisitor);
36
     }
37
     }
37
 
38
 
38
 	@Override
39
 	@Override
189
 	@Override
190
 	@Override
190
 	public Boolean visitReturn(ReturnStatement statement) {
191
 	public Boolean visitReturn(ReturnStatement statement) {
191
     	javaWriter.position(statement.position.fromLine);
192
     	javaWriter.position(statement.position.fromLine);
192
-		statement.value.accept(expressionVisitor);
193
-		javaWriter.returnType(context.getType(statement.value.type));
193
+    	if(statement.value == null) {
194
+    		javaWriter.ret();
195
+		} else {
196
+			statement.value.accept(expressionVisitor);
197
+			javaWriter.returnType(context.getType(statement.value.type));
198
+		}
199
+
194
 		return true;
200
 		return true;
195
 	}
201
 	}
196
 
202
 

+ 7
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java View File

11
 import org.openzen.zenscript.javashared.JavaMethod;
11
 import org.openzen.zenscript.javashared.JavaMethod;
12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
13
 
13
 
14
+import javax.lang.model.element.VariableElement;
14
 import java.util.ArrayList;
15
 import java.util.ArrayList;
15
 import java.util.HashMap;
16
 import java.util.HashMap;
16
 import java.util.List;
17
 import java.util.List;
85
 	public void setLocalVariable(VariableID variable, JavaLocalVariableInfo info) {
86
 	public void setLocalVariable(VariableID variable, JavaLocalVariableInfo info) {
86
 		localVariables.put(variable, info);
87
 		localVariables.put(variable, info);
87
 	}
88
 	}
88
-	
89
+
90
+	public JavaLocalVariableInfo tryGetLocalVariable(VariableID variable) {
91
+		return localVariables.get(variable);
92
+	}
93
+
89
 	public JavaLocalVariableInfo getLocalVariable(VariableID variable) {
94
 	public JavaLocalVariableInfo getLocalVariable(VariableID variable) {
90
-		JavaLocalVariableInfo result = localVariables.get(variable);
95
+		JavaLocalVariableInfo result = tryGetLocalVariable(variable);
91
 		if (result == null)
96
 		if (result == null)
92
 			throw new IllegalStateException("Local variable unknown");
97
 			throw new IllegalStateException("Local variable unknown");
93
 		
98
 		

+ 251
- 206
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java View File

10
 import org.openzen.zencode.shared.LiteralSourceFile;
10
 import org.openzen.zencode.shared.LiteralSourceFile;
11
 import org.openzen.zenscript.codemodel.*;
11
 import org.openzen.zenscript.codemodel.*;
12
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13
+import org.openzen.zenscript.codemodel.annotations.DefinitionAnnotation;
14
+import org.openzen.zenscript.codemodel.annotations.NativeDefinitionAnnotation;
13
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
15
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
14
 import org.openzen.zenscript.codemodel.context.FileResolutionContext;
16
 import org.openzen.zenscript.codemodel.context.FileResolutionContext;
15
 import org.openzen.zenscript.codemodel.context.ModuleTypeResolutionContext;
17
 import org.openzen.zenscript.codemodel.context.ModuleTypeResolutionContext;
16
-import org.openzen.zenscript.codemodel.definition.ClassDefinition;
17
-import org.openzen.zenscript.codemodel.definition.EnumDefinition;
18
-import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19
-import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
20
-import org.openzen.zenscript.codemodel.definition.StructDefinition;
21
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
22
-import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
23
-import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
24
-import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
25
-import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
26
-import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
27
-import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
28
-import org.openzen.zenscript.codemodel.expression.ConstantShortExpression;
29
-import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
30
-import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
31
-import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
32
-import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
33
-import org.openzen.zenscript.codemodel.expression.Expression;
34
-import org.openzen.zenscript.codemodel.expression.ExpressionSymbol;
35
-import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
36
-import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
18
+import org.openzen.zenscript.codemodel.definition.*;
19
+import org.openzen.zenscript.codemodel.expression.*;
37
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
20
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
38
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
21
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
39
-import org.openzen.zenscript.codemodel.member.CasterMember;
40
-import org.openzen.zenscript.codemodel.member.ConstructorMember;
41
-import org.openzen.zenscript.codemodel.member.FieldMember;
42
-import org.openzen.zenscript.codemodel.member.GetterMember;
43
-import org.openzen.zenscript.codemodel.member.ImplementationMember;
44
-import org.openzen.zenscript.codemodel.member.MethodMember;
45
-import org.openzen.zenscript.codemodel.member.OperatorMember;
46
-import org.openzen.zenscript.codemodel.member.SetterMember;
22
+import org.openzen.zenscript.codemodel.member.*;
47
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
23
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
48
 import org.openzen.zenscript.codemodel.partial.PartialStaticMemberGroupExpression;
24
 import org.openzen.zenscript.codemodel.partial.PartialStaticMemberGroupExpression;
49
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
25
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
56
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
32
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
57
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
33
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
58
 import org.openzen.zenscript.javashared.*;
34
 import org.openzen.zenscript.javashared.*;
59
-import org.openzen.zenscript.lexer.*;
35
+import org.openzen.zenscript.lexer.ParseException;
36
+import org.openzen.zenscript.lexer.ZSTokenParser;
60
 import org.openzen.zenscript.parser.BracketExpressionParser;
37
 import org.openzen.zenscript.parser.BracketExpressionParser;
61
 import org.openzen.zenscript.parser.expression.ParsedExpression;
38
 import org.openzen.zenscript.parser.expression.ParsedExpression;
62
 import org.openzen.zenscript.parser.type.IParsedType;
39
 import org.openzen.zenscript.parser.type.IParsedType;
77
 	private final GlobalTypeRegistry registry;
54
 	private final GlobalTypeRegistry registry;
78
 	private final PackageDefinitions definitions = new PackageDefinitions();
55
 	private final PackageDefinitions definitions = new PackageDefinitions();
79
 	private final JavaCompiledModule compiled;
56
 	private final JavaCompiledModule compiled;
80
-	
57
+
81
 	private final Map<Class<?>, HighLevelDefinition> definitionByClass = new HashMap<>();
58
 	private final Map<Class<?>, HighLevelDefinition> definitionByClass = new HashMap<>();
82
 	private final Map<Class<?>, TypeID> typeByClass = new HashMap<>();
59
 	private final Map<Class<?>, TypeID> typeByClass = new HashMap<>();
83
 	private final Map<Class<?>, TypeID> unsignedByClass = new HashMap<>();
60
 	private final Map<Class<?>, TypeID> unsignedByClass = new HashMap<>();
84
-	
61
+	private final TypeVariableContext context = new TypeVariableContext();
62
+
85
 	public final Map<String, ISymbol> globals = new HashMap<>();
63
 	public final Map<String, ISymbol> globals = new HashMap<>();
86
 	private BracketExpressionParser bep;
64
 	private BracketExpressionParser bep;
87
 
65
 
95
 		this.basePackage = basePackage;
73
 		this.basePackage = basePackage;
96
 		module = new Module(name);
74
 		module = new Module(name);
97
 		this.registry = registry;
75
 		this.registry = registry;
98
-		
76
+
99
 		for (JavaNativeModule dependency : dependencies) {
77
 		for (JavaNativeModule dependency : dependencies) {
100
 			definitionByClass.putAll(dependency.definitionByClass);
78
 			definitionByClass.putAll(dependency.definitionByClass);
101
 		}
79
 		}
102
-		
80
+
103
 		compiled = new JavaCompiledModule(module, FunctionParameter.NONE);
81
 		compiled = new JavaCompiledModule(module, FunctionParameter.NONE);
104
-		
82
+
105
 		typeByClass.put(void.class, BasicTypeID.VOID);
83
 		typeByClass.put(void.class, BasicTypeID.VOID);
106
 		typeByClass.put(boolean.class, BasicTypeID.BOOL);
84
 		typeByClass.put(boolean.class, BasicTypeID.BOOL);
107
 		typeByClass.put(byte.class, BasicTypeID.SBYTE);
85
 		typeByClass.put(byte.class, BasicTypeID.SBYTE);
118
 		typeByClass.put(Long.class, registry.getOptional(BasicTypeID.LONG));
96
 		typeByClass.put(Long.class, registry.getOptional(BasicTypeID.LONG));
119
 		typeByClass.put(Float.class, registry.getOptional(BasicTypeID.FLOAT));
97
 		typeByClass.put(Float.class, registry.getOptional(BasicTypeID.FLOAT));
120
 		typeByClass.put(Double.class, registry.getOptional(BasicTypeID.DOUBLE));
98
 		typeByClass.put(Double.class, registry.getOptional(BasicTypeID.DOUBLE));
121
-		
99
+
122
 		unsignedByClass.put(byte.class, BasicTypeID.BYTE);
100
 		unsignedByClass.put(byte.class, BasicTypeID.BYTE);
123
 		unsignedByClass.put(short.class, BasicTypeID.USHORT);
101
 		unsignedByClass.put(short.class, BasicTypeID.USHORT);
124
 		unsignedByClass.put(int.class, BasicTypeID.UINT);
102
 		unsignedByClass.put(int.class, BasicTypeID.UINT);
128
 		unsignedByClass.put(Integer.class, registry.getOptional(BasicTypeID.INT));
106
 		unsignedByClass.put(Integer.class, registry.getOptional(BasicTypeID.INT));
129
 		unsignedByClass.put(Long.class, registry.getOptional(BasicTypeID.LONG));
107
 		unsignedByClass.put(Long.class, registry.getOptional(BasicTypeID.LONG));
130
 	}
108
 	}
131
-	
109
+
132
 	public SemanticModule toSemantic(ModuleSpace space) {
110
 	public SemanticModule toSemantic(ModuleSpace space) {
133
 		return new SemanticModule(
111
 		return new SemanticModule(
134
 				module,
112
 				module,
144
 				space.getAnnotations(),
122
 				space.getAnnotations(),
145
 				space.getStorageTypes());
123
 				space.getStorageTypes());
146
 	}
124
 	}
147
-	
125
+
148
 	public JavaCompiledModule getCompiled() {
126
 	public JavaCompiledModule getCompiled() {
149
 		return compiled;
127
 		return compiled;
150
 	}
128
 	}
151
-	
129
+
152
 	public HighLevelDefinition addClass(Class<?> cls) {
130
 	public HighLevelDefinition addClass(Class<?> cls) {
153
-		if (definitionByClass.containsKey(cls))
131
+		if (definitionByClass.containsKey(cls)) {
154
 			return definitionByClass.get(cls);
132
 			return definitionByClass.get(cls);
155
-        
133
+		}
156
         return convertClass(cls);
134
         return convertClass(cls);
157
 	}
135
 	}
158
-	
136
+
159
 	public void addGlobals(Class<?> cls) {
137
 	public void addGlobals(Class<?> cls) {
160
 		HighLevelDefinition definition = new ClassDefinition(CodePosition.NATIVE, module, pkg, "__globals__", Modifiers.PUBLIC);
138
 		HighLevelDefinition definition = new ClassDefinition(CodePosition.NATIVE, module, pkg, "__globals__", Modifiers.PUBLIC);
161
 		JavaClass jcls = JavaClass.fromInternalName(getInternalName(cls), JavaClass.Kind.CLASS);
139
 		JavaClass jcls = JavaClass.fromInternalName(getInternalName(cls), JavaClass.Kind.CLASS);
162
 		compiled.setClassInfo(definition, jcls);
140
 		compiled.setClassInfo(definition, jcls);
163
 		StoredType thisType = registry.getForMyDefinition(definition).stored();
141
 		StoredType thisType = registry.getForMyDefinition(definition).stored();
164
-		TypeVariableContext context = new TypeVariableContext();
165
-		
142
+		//TypeVariableContext context = new TypeVariableContext();
143
+
166
 		for (Field field : cls.getDeclaredFields()) {
144
 		for (Field field : cls.getDeclaredFields()) {
167
 			if (!field.isAnnotationPresent(ZenCodeGlobals.Global.class))
145
 			if (!field.isAnnotationPresent(ZenCodeGlobals.Global.class))
168
 				continue;
146
 				continue;
169
 			if (!isStatic(field.getModifiers()))
147
 			if (!isStatic(field.getModifiers()))
170
 				continue;
148
 				continue;
171
-			
149
+
172
 			ZenCodeGlobals.Global global = field.getAnnotation(ZenCodeGlobals.Global.class);
150
 			ZenCodeGlobals.Global global = field.getAnnotation(ZenCodeGlobals.Global.class);
173
 			StoredType type = loadStoredType(context, field.getAnnotatedType());
151
 			StoredType type = loadStoredType(context, field.getAnnotatedType());
174
 			String name = global.value().isEmpty() ? field.getName() : global.value();
152
 			String name = global.value().isEmpty() ? field.getName() : global.value();
179
 			compiled.setFieldInfo(fieldMember.autoGetter, javaField);
157
 			compiled.setFieldInfo(fieldMember.autoGetter, javaField);
180
 			globals.put(name, new ExpressionSymbol((position, scope) -> new StaticGetterExpression(CodePosition.BUILTIN, fieldMember.autoGetter.ref(thisType, GenericMapper.EMPTY))));
158
 			globals.put(name, new ExpressionSymbol((position, scope) -> new StaticGetterExpression(CodePosition.BUILTIN, fieldMember.autoGetter.ref(thisType, GenericMapper.EMPTY))));
181
 		}
159
 		}
182
-		
160
+
183
 		for (Method method : cls.getDeclaredMethods()) {
161
 		for (Method method : cls.getDeclaredMethods()) {
184
 			if (!method.isAnnotationPresent(ZenCodeGlobals.Global.class))
162
 			if (!method.isAnnotationPresent(ZenCodeGlobals.Global.class))
185
 				continue;
163
 				continue;
186
 			if (!isStatic(method.getModifiers()))
164
 			if (!isStatic(method.getModifiers()))
187
 				continue;
165
 				continue;
188
-			
166
+
189
 			ZenCodeGlobals.Global global = method.getAnnotation(ZenCodeGlobals.Global.class);
167
 			ZenCodeGlobals.Global global = method.getAnnotation(ZenCodeGlobals.Global.class);
190
 			String name = global.value().isEmpty() ? method.getName() : global.value();
168
 			String name = global.value().isEmpty() ? method.getName() : global.value();
191
 			MethodMember methodMember = new MethodMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, name, getHeader(context, method), null);
169
 			MethodMember methodMember = new MethodMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, name, getHeader(context, method), null);
192
 			definition.addMember(methodMember);
170
 			definition.addMember(methodMember);
193
-			
171
+
194
 			boolean isGenericResult = methodMember.header.getReturnType().isGeneric();
172
 			boolean isGenericResult = methodMember.header.getReturnType().isGeneric();
195
 			compiled.setMethodInfo(methodMember, new JavaMethod(jcls, JavaMethod.Kind.STATIC, method.getName(), false, getMethodDescriptor(method), method.getModifiers(), isGenericResult));
173
 			compiled.setMethodInfo(methodMember, new JavaMethod(jcls, JavaMethod.Kind.STATIC, method.getName(), false, getMethodDescriptor(method), method.getModifiers(), isGenericResult));
196
 			globals.put(name, new ExpressionSymbol((position, scope) -> {
174
 			globals.put(name, new ExpressionSymbol((position, scope) -> {
199
 			}));
177
 			}));
200
 		}
178
 		}
201
 	}
179
 	}
202
-	
180
+
203
 	public FunctionalMemberRef loadStaticMethod(Method method) {
181
 	public FunctionalMemberRef loadStaticMethod(Method method) {
204
 		if (!isStatic(method.getModifiers()))
182
 		if (!isStatic(method.getModifiers()))
205
 			throw new IllegalArgumentException("Method \"" + method.toString() + "\" is not static");
183
 			throw new IllegalArgumentException("Method \"" + method.toString() + "\" is not static");
206
-		
184
+
207
 		HighLevelDefinition definition = addClass(method.getDeclaringClass());
185
 		HighLevelDefinition definition = addClass(method.getDeclaringClass());
208
 		JavaClass jcls = JavaClass.fromInternalName(getInternalName(method.getDeclaringClass()), JavaClass.Kind.CLASS);
186
 		JavaClass jcls = JavaClass.fromInternalName(getInternalName(method.getDeclaringClass()), JavaClass.Kind.CLASS);
209
-		
210
-		TypeVariableContext context = new TypeVariableContext();
187
+
188
+		//TypeVariableContext context = new TypeVariableContext();
211
 		MethodMember methodMember = new MethodMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, method.getName(), getHeader(context, method), null);
189
 		MethodMember methodMember = new MethodMember(CodePosition.NATIVE, definition, Modifiers.PUBLIC | Modifiers.STATIC, method.getName(), getHeader(context, method), null);
212
 		definition.addMember(methodMember);
190
 		definition.addMember(methodMember);
213
 		boolean isGenericResult = methodMember.header.getReturnType().isGeneric();
191
 		boolean isGenericResult = methodMember.header.getReturnType().isGeneric();
218
 	private boolean isInBasePackage(String className) {
196
 	private boolean isInBasePackage(String className) {
219
 		return className.startsWith(basePackage + ".");
197
 		return className.startsWith(basePackage + ".");
220
 	}
198
 	}
221
-	
199
+
222
 	private ZSPackage getPackage(String className) {
200
 	private ZSPackage getPackage(String className) {
223
 		//TODO validate
201
 		//TODO validate
224
 		if(this.basePackage == null || this.basePackage.isEmpty())
202
 		if(this.basePackage == null || this.basePackage.isEmpty())
226
 		//TODO make a lang package?
204
 		//TODO make a lang package?
227
 		if (!className.contains(".") || className.startsWith("java.lang"))
205
 		if (!className.contains(".") || className.startsWith("java.lang"))
228
 			return pkg;
206
 			return pkg;
229
-		
207
+
230
 		if (className.startsWith("."))
208
 		if (className.startsWith("."))
231
 			className = className.substring(1);
209
 			className = className.substring(1);
232
 		else if (className.startsWith(basePackage + "."))
210
 		else if (className.startsWith(basePackage + "."))
233
 			className = className.substring(basePackage.length() + 1);
211
 			className = className.substring(basePackage.length() + 1);
234
 		else
212
 		else
235
             throw new IllegalArgumentException("Invalid class name: \"" + className + "\" not in the given base package: \"" + basePackage + "\"");
213
             throw new IllegalArgumentException("Invalid class name: \"" + className + "\" not in the given base package: \"" + basePackage + "\"");
236
-		
214
+
237
 		String[] classNameParts = Strings.split(className, '.');
215
 		String[] classNameParts = Strings.split(className, '.');
238
 		ZSPackage classPkg = pkg;
216
 		ZSPackage classPkg = pkg;
239
 		for (int i = 0; i < classNameParts.length - 1; i++)
217
 		for (int i = 0; i < classNameParts.length - 1; i++)
240
 			classPkg = classPkg.getOrCreatePackage(classNameParts[i]);
218
 			classPkg = classPkg.getOrCreatePackage(classNameParts[i]);
241
-		
219
+
242
 		return classPkg;
220
 		return classPkg;
243
 	}
221
 	}
244
-	
222
+
223
+	private <T> HighLevelDefinition checkRegistry(Class<T> cls) {
224
+		String name = cls.getCanonicalName();
225
+		if (!name.startsWith("java.lang.") && !name.startsWith("java.util.")) {
226
+			return null;
227
+		}
228
+
229
+		name = name.substring("java.lang.".length());
230
+		for (DefinitionTypeID definition : registry.getDefinitions()) {
231
+			final HighLevelDefinition highLevelDefinition = definition.definition;
232
+			for (DefinitionAnnotation annotation : highLevelDefinition.annotations) {
233
+				if (annotation instanceof NativeDefinitionAnnotation) {
234
+					final String identifier = ((NativeDefinitionAnnotation) annotation).getIdentifier();
235
+					if (identifier.equals(name) || identifier.equals("stdlib::" + name)) {
236
+						return highLevelDefinition;
237
+					}
238
+				}
239
+			}
240
+		}
241
+
242
+		return null;
243
+	}
244
+
245
 	private <T> HighLevelDefinition convertClass(Class<T> cls) {
245
 	private <T> HighLevelDefinition convertClass(Class<T> cls) {
246
 		if ((cls.getModifiers() & Modifier.PUBLIC) == 0)
246
 		if ((cls.getModifiers() & Modifier.PUBLIC) == 0)
247
 			throw new IllegalArgumentException("Class \" " + cls.getName() + "\" must be public");
247
 			throw new IllegalArgumentException("Class \" " + cls.getName() + "\" must be public");
252
 
252
 
253
 		String className = cls.getName();
253
 		String className = cls.getName();
254
         boolean isStruct = cls.isAnnotationPresent(ZenCodeType.Struct.class);
254
         boolean isStruct = cls.isAnnotationPresent(ZenCodeType.Struct.class);
255
-        
256
-        ZSPackage classPkg;
257
-        ZenCodeType.Name nameAnnotation = cls.getDeclaredAnnotation(ZenCodeType.Name.class);
258
-		className = className.contains(".") ? className.substring(className.lastIndexOf('.') + 1) : className;
259
-        if (nameAnnotation == null) {
260
-            classPkg = getPackage(className);
261
-        } else {
262
-            String specifiedName = nameAnnotation.value();
263
-			if (specifiedName.startsWith(".")) {
264
-				classPkg = getPackage(specifiedName);
265
-				className = specifiedName.substring(specifiedName.lastIndexOf('.') + 1);
266
-			} else if (specifiedName.indexOf('.') >= 0) {
267
-				if (!specifiedName.startsWith(pkg.fullName))
268
-					throw new IllegalArgumentException("Specified @Name as \"" + specifiedName + "\" for class: \"" + cls.toString() + "\" but it's not in the module root package: \"" + pkg.fullName + "\"");
269
-
270
-				classPkg = getPackage(basePackage + specifiedName.substring(pkg.fullName.length()));
271
-				className = specifiedName.substring(specifiedName.lastIndexOf('.') + 1);
272
-			} else {
273
-                classPkg = getPackage(specifiedName);
274
-                className = nameAnnotation.value();
275
-			}
276
-		}
277
 
255
 
278
-
279
-		
280
-		HighLevelDefinition definition;
256
+		HighLevelDefinition definition = checkRegistry(cls);
257
+		final boolean foundRegistry = definition != null;
281
 		String internalName = getInternalName(cls);
258
 		String internalName = getInternalName(cls);
282
 		JavaClass javaClass;
259
 		JavaClass javaClass;
283
-		if (cls.isInterface()) {
284
-			definition = new InterfaceDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
285
-			javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.INTERFACE);
286
-		} else if (cls.isEnum()) {
287
-			definition = new EnumDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
288
-			javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.ENUM);
289
-		} else if (isStruct) {
290
-			definition = new StructDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
291
-			javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.CLASS);
260
+
261
+		if (foundRegistry) {
262
+			javaClass = JavaClass.fromInternalName(internalName, definition.isInterface() ? JavaClass.Kind.INTERFACE : JavaClass.Kind.CLASS);
292
 		} else {
263
 		} else {
293
-			definition = new ClassDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC);
294
-			javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.CLASS);
264
+			ZSPackage classPkg;
265
+			ZenCodeType.Name nameAnnotation = cls.getDeclaredAnnotation(ZenCodeType.Name.class);
266
+			className = className.contains(".") ? className.substring(className.lastIndexOf('.') + 1) : className;
267
+			if (nameAnnotation == null) {
268
+				classPkg = getPackage(className);
269
+			} else {
270
+				String specifiedName = nameAnnotation.value();
271
+				if (specifiedName.startsWith(".")) {
272
+					classPkg = getPackage(specifiedName);
273
+					className = specifiedName.substring(specifiedName.lastIndexOf('.') + 1);
274
+				} else if (specifiedName.indexOf('.') >= 0) {
275
+					if (!specifiedName.startsWith(pkg.fullName))
276
+						throw new IllegalArgumentException("Specified @Name as \"" + specifiedName + "\" for class: \"" + cls
277
+								.toString() + "\" but it's not in the module root package");
278
+
279
+					classPkg = getPackage(basePackage + specifiedName.substring(pkg.fullName.length()));
280
+					className = specifiedName.substring(specifiedName.lastIndexOf('.') + 1);
281
+				} else {
282
+					classPkg = getPackage(specifiedName);
283
+					className = nameAnnotation.value();
284
+				}
285
+			}
295
 
286
 
287
+
288
+			if (cls.isInterface()) {
289
+				definition = new InterfaceDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
290
+				javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.INTERFACE);
291
+			} else if (cls.isEnum()) {
292
+				definition = new EnumDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
293
+				javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.ENUM);
294
+			} else if (isStruct) {
295
+				definition = new StructDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC, null);
296
+				javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.CLASS);
297
+			} else {
298
+				definition = new ClassDefinition(CodePosition.NATIVE, module, classPkg, className, Modifiers.PUBLIC);
299
+				javaClass = JavaClass.fromInternalName(internalName, JavaClass.Kind.CLASS);
300
+
301
+			}
296
 		}
302
 		}
297
 
303
 
298
 		//Moved up here so that circular dependencies are caught (hopefully)
304
 		//Moved up here so that circular dependencies are caught (hopefully)
299
 		definitionByClass.put(cls, definition);
305
 		definitionByClass.put(cls, definition);
300
 
306
 
301
-		TypeVariableContext context = new TypeVariableContext();
307
+		//TypeVariableContext context = new TypeVariableContext();
302
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
308
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
303
-        definition.typeParameters = new TypeParameter[cls.getTypeParameters().length];
309
+		TypeParameter[] typeParameters = new TypeParameter[cls.getTypeParameters().length];
310
+		definition.typeParameters = typeParameters;
311
+
304
 		for (int i = 0; i < javaTypeParameters.length; i++) {
312
 		for (int i = 0; i < javaTypeParameters.length; i++) {
313
+			//Put up here for nested parameters?
305
 			TypeVariable<Class<T>> typeVariable = javaTypeParameters[i];
314
 			TypeVariable<Class<T>> typeVariable = javaTypeParameters[i];
306
 			TypeParameter parameter = new TypeParameter(CodePosition.NATIVE, typeVariable.getName());
315
 			TypeParameter parameter = new TypeParameter(CodePosition.NATIVE, typeVariable.getName());
316
+			typeParameters[i] = parameter;
317
+			context.put(typeVariable, parameter);
318
+		}
319
+
320
+		for (int i = 0; i < javaTypeParameters.length; i++) {
321
+			TypeVariable<Class<T>> typeVariable = javaTypeParameters[i];
322
+			TypeParameter parameter = typeParameters[i];
307
 			for (AnnotatedType bound : typeVariable.getAnnotatedBounds()) {
323
 			for (AnnotatedType bound : typeVariable.getAnnotatedBounds()) {
308
 				TypeID type = loadType(context, bound).type;
324
 				TypeID type = loadType(context, bound).type;
309
 				parameter.addBound(new ParameterTypeBound(CodePosition.NATIVE, type));
325
 				parameter.addBound(new ParameterTypeBound(CodePosition.NATIVE, type));
310
 			}
326
 			}
311
-            definition.typeParameters[i] = parameter;
312
-			context.put(typeVariable, parameter);
327
+			typeParameters[i] = parameter;
313
 		}
328
 		}
314
-  
315
-		if (definition instanceof ClassDefinition && cls.getAnnotatedSuperclass() != null && shouldLoadType(cls.getAnnotatedSuperclass().getType())) {
329
+
330
+		if (!foundRegistry && definition instanceof ClassDefinition && cls.getAnnotatedSuperclass() != null && shouldLoadType(cls.getAnnotatedSuperclass().getType())) {
316
 			definition.setSuperType(loadType(context, cls.getAnnotatedSuperclass()).type);
331
 			definition.setSuperType(loadType(context, cls.getAnnotatedSuperclass()).type);
317
 		}
332
 		}
318
 
333
 
319
-		if (definition.getSuperType() == null && cls != Object.class) {
334
+		if (!foundRegistry && definition.getSuperType() == null && cls != Object.class) {
320
 			definition.setSuperType(loadType(context, Object.class, false, false).type);
335
 			definition.setSuperType(loadType(context, Object.class, false, false).type);
321
 		}
336
 		}
322
 
337
 
328
 				compiled.setImplementationInfo(member, new JavaImplementation(true, javaClass));
343
 				compiled.setImplementationInfo(member, new JavaImplementation(true, javaClass));
329
 			}
344
 			}
330
 		}
345
 		}
331
-		
332
-		
346
+
333
 		compiled.setClassInfo(definition, javaClass);
347
 		compiled.setClassInfo(definition, javaClass);
334
-		
348
+
335
 		StoredType thisType = new StoredType(registry.getForMyDefinition(definition), AutoStorageTag.INSTANCE);
349
 		StoredType thisType = new StoredType(registry.getForMyDefinition(definition), AutoStorageTag.INSTANCE);
336
 		for (Field field : cls.getDeclaredFields()) {
350
 		for (Field field : cls.getDeclaredFields()) {
337
 			ZenCodeType.Field annotation = field.getAnnotation(ZenCodeType.Field.class);
351
 			ZenCodeType.Field annotation = field.getAnnotation(ZenCodeType.Field.class);
339
 				continue;
353
 				continue;
340
 			if (!isPublic(field.getModifiers()))
354
 			if (!isPublic(field.getModifiers()))
341
 				continue;
355
 				continue;
342
-			
356
+
343
 			final String fieldName = annotation.value().isEmpty() ? field.getName() : annotation.value();
357
 			final String fieldName = annotation.value().isEmpty() ? field.getName() : annotation.value();
344
-			
358
+
345
 			StoredType fieldType = loadStoredType(context, field.getAnnotatedType());
359
 			StoredType fieldType = loadStoredType(context, field.getAnnotatedType());
346
 			FieldMember member = new FieldMember(CodePosition.NATIVE, definition, getMethodModifiers(field), fieldName, thisType, fieldType, registry, 0, 0, null);
360
 			FieldMember member = new FieldMember(CodePosition.NATIVE, definition, getMethodModifiers(field), fieldName, thisType, fieldType, registry, 0, 0, null);
347
 			definition.addMember(member);
361
 			definition.addMember(member);
348
 			compiled.setFieldInfo(member, new JavaField(javaClass, field.getName(), getDescriptor(field.getType())));
362
 			compiled.setFieldInfo(member, new JavaField(javaClass, field.getName(), getDescriptor(field.getType())));
349
 		}
363
 		}
350
-		
364
+
351
 		boolean hasConstructor = false;
365
 		boolean hasConstructor = false;
352
-		for (java.lang.reflect.Constructor constructor : cls.getConstructors()) {
366
+		for (java.lang.reflect.Constructor<?> constructor : cls.getConstructors()) {
353
 			ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor) constructor.getAnnotation(ZenCodeType.Constructor.class);
367
 			ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor) constructor.getAnnotation(ZenCodeType.Constructor.class);
354
 			if (constructorAnnotation != null) {
368
 			if (constructorAnnotation != null) {
355
 				ConstructorMember member = asConstructor(context, definition, constructor);
369
 				ConstructorMember member = asConstructor(context, definition, constructor);
358
 				hasConstructor = true;
372
 				hasConstructor = true;
359
 			}
373
 			}
360
 		}
374
 		}
361
-		
362
-		if (!hasConstructor) {
375
+
376
+		if (!hasConstructor && !foundRegistry) {
363
 			// no constructor! make a private constructor so the compiler doesn't add one
377
 			// no constructor! make a private constructor so the compiler doesn't add one
364
 			ConstructorMember member = new ConstructorMember(CodePosition.BUILTIN, definition, Modifiers.PRIVATE, new FunctionHeader(BasicTypeID.VOID), BuiltinID.CLASS_DEFAULT_CONSTRUCTOR);
378
 			ConstructorMember member = new ConstructorMember(CodePosition.BUILTIN, definition, Modifiers.PRIVATE, new FunctionHeader(BasicTypeID.VOID), BuiltinID.CLASS_DEFAULT_CONSTRUCTOR);
365
 			definition.addMember(member);
379
 			definition.addMember(member);
366
 		}
380
 		}
367
-		
381
+
368
 		for (Method method : cls.getDeclaredMethods()) {
382
 		for (Method method : cls.getDeclaredMethods()) {
369
 			ZenCodeType.Method methodAnnotation = method.getAnnotation(ZenCodeType.Method.class);
383
 			ZenCodeType.Method methodAnnotation = method.getAnnotation(ZenCodeType.Method.class);
370
 			if (methodAnnotation != null) {
384
 			if (methodAnnotation != null) {
373
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.header.getReturnType()));
387
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.header.getReturnType()));
374
 				continue;
388
 				continue;
375
 			}
389
 			}
376
-			
390
+
377
 			ZenCodeType.Getter getter = method.getAnnotation(ZenCodeType.Getter.class);
391
 			ZenCodeType.Getter getter = method.getAnnotation(ZenCodeType.Getter.class);
378
 			if (getter != null) {
392
 			if (getter != null) {
379
 				GetterMember member = asGetter(context, definition, method, getter);
393
 				GetterMember member = asGetter(context, definition, method, getter);
380
 				definition.addMember(member);
394
 				definition.addMember(member);
381
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.getType()));
395
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.getType()));
382
 			}
396
 			}
383
-			
397
+
384
 			ZenCodeType.Setter setter = method.getAnnotation(ZenCodeType.Setter.class);
398
 			ZenCodeType.Setter setter = method.getAnnotation(ZenCodeType.Setter.class);
385
 			if (setter != null) {
399
 			if (setter != null) {
386
 				SetterMember member = asSetter(context, definition, method, setter);
400
 				SetterMember member = asSetter(context, definition, method, setter);
387
 				definition.addMember(member);
401
 				definition.addMember(member);
388
 				compiled.setMethodInfo(member, getMethod(javaClass, method, BasicTypeID.VOID.stored));
402
 				compiled.setMethodInfo(member, getMethod(javaClass, method, BasicTypeID.VOID.stored));
389
 			}
403
 			}
390
-			
404
+
391
 			ZenCodeType.Operator operator = method.getAnnotation(ZenCodeType.Operator.class);
405
 			ZenCodeType.Operator operator = method.getAnnotation(ZenCodeType.Operator.class);
392
 			if (operator != null) {
406
 			if (operator != null) {
393
 				OperatorMember member = asOperator(context, definition, method, operator);
407
 				OperatorMember member = asOperator(context, definition, method, operator);
394
 				definition.addMember(member);
408
 				definition.addMember(member);
395
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.header.getReturnType()));
409
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.header.getReturnType()));
396
 			}
410
 			}
397
-			
411
+
398
 			ZenCodeType.Caster caster = method.getAnnotation(ZenCodeType.Caster.class);
412
 			ZenCodeType.Caster caster = method.getAnnotation(ZenCodeType.Caster.class);
399
 			if (caster != null) {
413
 			if (caster != null) {
400
 				CasterMember member = asCaster(context, definition, method, caster);
414
 				CasterMember member = asCaster(context, definition, method, caster);
401
 				definition.addMember(member);
415
 				definition.addMember(member);
402
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.toType));
416
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.toType));
403
 			}
417
 			}
404
-			
418
+
405
 			/*if (!annotated) {
419
 			/*if (!annotated) {
406
 				MethodMember member = asMethod(definition, method, null);
420
 				MethodMember member = asMethod(definition, method, null);
407
 				definition.addMember(member);
421
 				definition.addMember(member);
408
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.header.getReturnType()));
422
 				compiled.setMethodInfo(member, getMethod(javaClass, method, member.header.getReturnType()));
409
 			}*/
423
 			}*/
410
 		}
424
 		}
411
-		
425
+
412
 		return definition;
426
 		return definition;
413
 	}
427
 	}
414
 
428
 
449
             if(methodAnnotation != null) {
463
             if(methodAnnotation != null) {
450
                 String name = !methodAnnotation.value().isEmpty() ? methodAnnotation.value() : method.getName();
464
                 String name = !methodAnnotation.value().isEmpty() ? methodAnnotation.value() : method.getName();
451
 
465
 
452
-                TypeVariableContext context = new TypeVariableContext();
466
+                //TypeVariableContext context = new TypeVariableContext();
453
 
467
 
454
                 final Parameter[] parameters = getExpansionParameters(method);
468
                 final Parameter[] parameters = getExpansionParameters(method);
455
 
469
 
468
                 if (implicit) {
482
                 if (implicit) {
469
                     modifiers |= Modifiers.IMPLICIT;
483
                     modifiers |= Modifiers.IMPLICIT;
470
                 }
484
                 }
471
-                TypeVariableContext context = new TypeVariableContext();
485
+                //TypeVariableContext context = new TypeVariableContext();
472
                 StoredType toType = loadStoredType(context, method.getAnnotatedReturnType());
486
                 StoredType toType = loadStoredType(context, method.getAnnotatedReturnType());
473
                 final CasterMember member = new CasterMember(CodePosition.NATIVE, expansion, modifiers, toType,  null);
487
                 final CasterMember member = new CasterMember(CodePosition.NATIVE, expansion, modifiers, toType,  null);
474
 
488
 
571
 		return null;
585
 		return null;
572
 	}
586
 	}
573
 
587
 
574
-	
588
+
575
 	private boolean shouldLoadType(Type type) {
589
 	private boolean shouldLoadType(Type type) {
576
 		if (type instanceof Class)
590
 		if (type instanceof Class)
577
 			return definitionByClass.containsKey(type) || shouldLoadClass((Class<?>)type);
591
 			return definitionByClass.containsKey(type) || shouldLoadClass((Class<?>)type);
578
 		if (type instanceof ParameterizedType)
592
 		if (type instanceof ParameterizedType)
579
 			return shouldLoadType(((ParameterizedType)type).getRawType());
593
 			return shouldLoadType(((ParameterizedType)type).getRawType());
580
-		
594
+
581
 		return false;
595
 		return false;
582
 	}
596
 	}
583
-	
597
+
584
 	private String getClassName(Class<?> cls) {
598
 	private String getClassName(Class<?> cls) {
585
 	    return cls.isAnnotationPresent(ZenCodeType.Name.class) ? cls.getAnnotation(ZenCodeType.Name.class).value() : cls.getName();
599
 	    return cls.isAnnotationPresent(ZenCodeType.Name.class) ? cls.getAnnotation(ZenCodeType.Name.class).value() : cls.getName();
586
     }
600
     }
588
 	private boolean shouldLoadClass(Class<?> cls) {
602
 	private boolean shouldLoadClass(Class<?> cls) {
589
 	    return isInBasePackage(getClassName(cls));
603
 	    return isInBasePackage(getClassName(cls));
590
     }
604
     }
591
-	
605
+
592
 	private boolean isGetterName(String name) {
606
 	private boolean isGetterName(String name) {
593
 		return name.startsWith("get") || name.startsWith("is") || name.startsWith("has");
607
 		return name.startsWith("get") || name.startsWith("is") || name.startsWith("has");
594
 	}
608
 	}
595
-	
609
+
596
 	private String translateGetterName(String name) {
610
 	private String translateGetterName(String name) {
597
 		if (name.startsWith("get"))
611
 		if (name.startsWith("get"))
598
 			return name.substring(3, 4).toLowerCase() + name.substring(4);
612
 			return name.substring(3, 4).toLowerCase() + name.substring(4);
599
-		
613
+
600
 		return name;
614
 		return name;
601
 	}
615
 	}
602
-	
616
+
603
 	private String translateSetterName(String name) {
617
 	private String translateSetterName(String name) {
604
 		if (name.startsWith("set"))
618
 		if (name.startsWith("set"))
605
 			return name.substring(3, 4).toLowerCase() + name.substring(4);
619
 			return name.substring(3, 4).toLowerCase() + name.substring(4);
606
-		
620
+
607
 		return name;
621
 		return name;
608
 	}
622
 	}
609
-	
623
+
610
 	private ConstructorMember asConstructor(TypeVariableContext context, HighLevelDefinition definition, java.lang.reflect.Constructor method) {
624
 	private ConstructorMember asConstructor(TypeVariableContext context, HighLevelDefinition definition, java.lang.reflect.Constructor method) {
611
 		FunctionHeader header = getHeader(context, method);
625
 		FunctionHeader header = getHeader(context, method);
612
 		return new ConstructorMember(
626
 		return new ConstructorMember(
616
 				header,
630
 				header,
617
 				null);
631
 				null);
618
 	}
632
 	}
619
-	
633
+
620
 	private MethodMember asMethod(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Method annotation) {
634
 	private MethodMember asMethod(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Method annotation) {
621
 		String name = annotation != null && !annotation.value().isEmpty() ? annotation.value() : method.getName();
635
 		String name = annotation != null && !annotation.value().isEmpty() ? annotation.value() : method.getName();
622
 		FunctionHeader header = getHeader(context, method);
636
 		FunctionHeader header = getHeader(context, method);
628
 				header,
642
 				header,
629
 				null);
643
 				null);
630
 	}
644
 	}
631
-	
645
+
632
 	private OperatorMember asOperator(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Operator annotation) {
646
 	private OperatorMember asOperator(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Operator annotation) {
633
 		FunctionHeader header = getHeader(context, method);
647
 		FunctionHeader header = getHeader(context, method);
634
 		if (isStatic(method.getModifiers()))
648
 		if (isStatic(method.getModifiers()))
635
 			throw new IllegalArgumentException("operator method \"" + method.toString() + "\"cannot be static");
649
 			throw new IllegalArgumentException("operator method \"" + method.toString() + "\"cannot be static");
636
-		
650
+
637
 		// TODO: check number of parameters
651
 		// TODO: check number of parameters
638
 		//if (header.parameters.length != annotation.value().parameters)
652
 		//if (header.parameters.length != annotation.value().parameters)
639
-		
653
+
640
 		return new OperatorMember(
654
 		return new OperatorMember(
641
 				CodePosition.NATIVE,
655
 				CodePosition.NATIVE,
642
 				definition,
656
 				definition,
645
 				header,
659
 				header,
646
 				null);
660
 				null);
647
 	}
661
 	}
648
-	
662
+
649
 	private GetterMember asGetter(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Getter annotation) {
663
 	private GetterMember asGetter(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Getter annotation) {
650
 		StoredType type = loadStoredType(context, method.getAnnotatedReturnType());
664
 		StoredType type = loadStoredType(context, method.getAnnotatedReturnType());
651
 		String name = null;
665
 		String name = null;
653
 			name = annotation.value();
667
 			name = annotation.value();
654
 		if (name == null)
668
 		if (name == null)
655
 			name = translateGetterName(method.getName());
669
 			name = translateGetterName(method.getName());
656
-		
670
+
657
 		return new GetterMember(CodePosition.NATIVE, definition, getMethodModifiers(method), name, type, null);
671
 		return new GetterMember(CodePosition.NATIVE, definition, getMethodModifiers(method), name, type, null);
658
 	}
672
 	}
659
-	
673
+
660
 	private SetterMember asSetter(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Setter annotation) {
674
 	private SetterMember asSetter(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Setter annotation) {
661
 		if (method.getParameterCount() != 1)
675
 		if (method.getParameterCount() != 1)
662
 			throw new IllegalArgumentException("Illegal setter: \"" + method.toString() + "\"must have exactly 1 parameter");
676
 			throw new IllegalArgumentException("Illegal setter: \"" + method.toString() + "\"must have exactly 1 parameter");
663
-		
677
+
664
 		StoredType type = loadStoredType(context, method.getAnnotatedParameterTypes()[0]);
678
 		StoredType type = loadStoredType(context, method.getAnnotatedParameterTypes()[0]);
665
 		String name = null;
679
 		String name = null;
666
 		if (annotation != null && !annotation.value().isEmpty())
680
 		if (annotation != null && !annotation.value().isEmpty())
667
 			name = annotation.value();
681
 			name = annotation.value();
668
 		if (name == null)
682
 		if (name == null)
669
 			name = translateSetterName(method.getName());
683
 			name = translateSetterName(method.getName());
670
-		
684
+
671
 		return new SetterMember(CodePosition.NATIVE, definition, getMethodModifiers(method), name, type, null);
685
 		return new SetterMember(CodePosition.NATIVE, definition, getMethodModifiers(method), name, type, null);
672
 	}
686
 	}
673
-	
687
+
674
 	private CasterMember asCaster(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Caster annotation) {
688
 	private CasterMember asCaster(TypeVariableContext context, HighLevelDefinition definition, Method method, ZenCodeType.Caster annotation) {
675
 		boolean implicit = annotation != null && annotation.implicit();
689
 		boolean implicit = annotation != null && annotation.implicit();
676
 		int modifiers = Modifiers.PUBLIC;
690
 		int modifiers = Modifiers.PUBLIC;
677
 		if (implicit)
691
 		if (implicit)
678
 			modifiers |= Modifiers.IMPLICIT;
692
 			modifiers |= Modifiers.IMPLICIT;
679
-		
693
+
680
 		StoredType toType = loadStoredType(context, method.getAnnotatedReturnType());
694
 		StoredType toType = loadStoredType(context, method.getAnnotatedReturnType());
681
 		return new CasterMember(CodePosition.NATIVE, definition, modifiers, toType, null);
695
 		return new CasterMember(CodePosition.NATIVE, definition, modifiers, toType, null);
682
 	}
696
 	}
683
-	
697
+
684
 	private FunctionHeader getHeader(TypeVariableContext context, java.lang.reflect.Constructor constructor) {
698
 	private FunctionHeader getHeader(TypeVariableContext context, java.lang.reflect.Constructor constructor) {
685
 		return getHeader(
699
 		return getHeader(
686
 				context,
700
 				context,
689
 				constructor.getTypeParameters(),
703
 				constructor.getTypeParameters(),
690
 				constructor.getAnnotatedExceptionTypes());
704
 				constructor.getAnnotatedExceptionTypes());
691
 	}
705
 	}
692
-	
706
+
693
 	private FunctionHeader getHeader(TypeVariableContext context, Method method) {
707
 	private FunctionHeader getHeader(TypeVariableContext context, Method method) {
694
 		return getHeader(
708
 		return getHeader(
695
 				context,
709
 				context,
698
 				method.getTypeParameters(),
712
 				method.getTypeParameters(),
699
 				method.getAnnotatedExceptionTypes());
713
 				method.getAnnotatedExceptionTypes());
700
 	}
714
 	}
701
-	
715
+
702
 	protected Expression getDefaultValue(Parameter parameter, StoredType type) {
716
 	protected Expression getDefaultValue(Parameter parameter, StoredType type) {
703
 		if (parameter.isAnnotationPresent(ZenCodeType.Optional.class)) {
717
 		if (parameter.isAnnotationPresent(ZenCodeType.Optional.class)) {
704
 				final String s = parameter.getAnnotation(ZenCodeType.Optional.class).value();
718
 				final String s = parameter.getAnnotation(ZenCodeType.Optional.class).value();
776
 			TypeVariable<Method>[] javaTypeParameters,
790
 			TypeVariable<Method>[] javaTypeParameters,
777
 			AnnotatedType[] exceptionTypes) {
791
 			AnnotatedType[] exceptionTypes) {
778
 		StoredType returnType = javaReturnType == null ? BasicTypeID.VOID.stored : loadStoredType(context, javaReturnType);
792
 		StoredType returnType = javaReturnType == null ? BasicTypeID.VOID.stored : loadStoredType(context, javaReturnType);
779
-		
793
+
794
+
795
+		TypeParameter[] typeParameters = new TypeParameter[javaTypeParameters.length];
796
+		for (int i = 0; i < javaTypeParameters.length; i++) {
797
+			//Put up here for nested parameters?
798
+			TypeVariable<Method> typeVariable = javaTypeParameters[i];
799
+			TypeParameter parameter = new TypeParameter(CodePosition.NATIVE, typeVariable.getName());
800
+			typeParameters[i] = parameter;
801
+			context.put(typeVariable, parameter);
802
+		}
803
+
804
+		for (int i = 0; i < javaTypeParameters.length; i++) {
805
+			TypeVariable<Method> javaTypeParameter = javaTypeParameters[i];
806
+
807
+			for (AnnotatedType bound : javaTypeParameter.getAnnotatedBounds())
808
+				typeParameters[i].addBound(new ParameterTypeBound(CodePosition.NATIVE, loadType(context, bound).type));
809
+		}
810
+
780
 		FunctionParameter[] parameters = new FunctionParameter[javaParameters.length];
811
 		FunctionParameter[] parameters = new FunctionParameter[javaParameters.length];
781
 		for (int i = 0; i < parameters.length; i++) {
812
 		for (int i = 0; i < parameters.length; i++) {
782
 			Parameter parameter = javaParameters[i];
813
 			Parameter parameter = javaParameters[i];
783
 
814
 
784
 			//AnnotatedType parameterType = parameter.getAnnotatedType();
815
 			//AnnotatedType parameterType = parameter.getAnnotatedType();
785
-			StoredType type = loadStoredType(context, parameter);
816
+ 			StoredType type = loadStoredType(context, parameter);
786
 			Expression defaultValue = getDefaultValue(parameter, type);
817
 			Expression defaultValue = getDefaultValue(parameter, type);
787
 			parameters[i] = new FunctionParameter(type, parameter.getName(), defaultValue, parameter.isVarArgs());
818
 			parameters[i] = new FunctionParameter(type, parameter.getName(), defaultValue, parameter.isVarArgs());
788
 		}
819
 		}
789
-		
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
-		
820
+
800
 		if (exceptionTypes.length > 1)
821
 		if (exceptionTypes.length > 1)
801
 			throw new IllegalArgumentException("A method can only throw a single exception type!");
822
 			throw new IllegalArgumentException("A method can only throw a single exception type!");
802
-		
823
+
803
 		StoredType thrownType = exceptionTypes.length == 0 ? null : loadStoredType(context, exceptionTypes[0]);
824
 		StoredType thrownType = exceptionTypes.length == 0 ? null : loadStoredType(context, exceptionTypes[0]);
804
 		return new FunctionHeader(typeParameters, returnType, thrownType, AutoStorageTag.INSTANCE, parameters);
825
 		return new FunctionHeader(typeParameters, returnType, thrownType, AutoStorageTag.INSTANCE, parameters);
805
 	}
826
 	}
806
-	
827
+
807
 	private StoredType loadStoredType(TypeVariableContext context, AnnotatedType annotatedType) {
828
 	private StoredType loadStoredType(TypeVariableContext context, AnnotatedType annotatedType) {
808
 		return loadType(context, annotatedType);
829
 		return loadType(context, annotatedType);
809
 	}
830
 	}
815
 			return new StoredType(registry.getOptional(type.type), type.getSpecifiedStorage());
836
 			return new StoredType(registry.getOptional(type.type), type.getSpecifiedStorage());
816
 		return type;
837
 		return type;
817
 	}
838
 	}
818
-	
839
+
819
 	private StoredType loadType(TypeVariableContext context, AnnotatedType annotatedType) {
840
 	private StoredType loadType(TypeVariableContext context, AnnotatedType annotatedType) {
820
 		if (annotatedType.isAnnotationPresent(ZenCodeType.USize.class))
841
 		if (annotatedType.isAnnotationPresent(ZenCodeType.USize.class))
821
 			return BasicTypeID.USIZE.stored;
842
 			return BasicTypeID.USIZE.stored;
822
 		else if (annotatedType.isAnnotationPresent(ZenCodeType.NullableUSize.class))
843
 		else if (annotatedType.isAnnotationPresent(ZenCodeType.NullableUSize.class))
823
 			return registry.getOptional(BasicTypeID.USIZE).stored();
844
 			return registry.getOptional(BasicTypeID.USIZE).stored();
824
-		
845
+
825
 		boolean nullable = annotatedType.isAnnotationPresent(ZenCodeType.Nullable.class);
846
 		boolean nullable = annotatedType.isAnnotationPresent(ZenCodeType.Nullable.class);
826
 		boolean unsigned = annotatedType.isAnnotationPresent(ZenCodeType.Unsigned.class);
847
 		boolean unsigned = annotatedType.isAnnotationPresent(ZenCodeType.Unsigned.class);
827
-		
848
+
828
 		return loadType(context, annotatedType, nullable, unsigned);
849
 		return loadType(context, annotatedType, nullable, unsigned);
829
 	}
850
 	}
830
-	
851
+
831
 	private StoredType loadType(TypeVariableContext context, AnnotatedElement type, boolean nullable, boolean unsigned) {
852
 	private StoredType loadType(TypeVariableContext context, AnnotatedElement type, boolean nullable, boolean unsigned) {
832
 		StoredType result = loadType(context, type, unsigned);
853
 		StoredType result = loadType(context, type, unsigned);
833
 		if (nullable)
854
 		if (nullable)
834
 			result = new StoredType(registry.getOptional(result.type), result.getSpecifiedStorage());
855
 			result = new StoredType(registry.getOptional(result.type), result.getSpecifiedStorage());
835
-		
856
+
836
 		return result;
857
 		return result;
837
 	}
858
 	}
838
-	
859
+
839
 	@SuppressWarnings("ChainOfInstanceofChecks")
860
 	@SuppressWarnings("ChainOfInstanceofChecks")
840
     private StoredType loadType(TypeVariableContext context, AnnotatedElement type, boolean unsigned) {
861
     private StoredType loadType(TypeVariableContext context, AnnotatedElement type, boolean unsigned) {
841
 		if (type instanceof Class) {
862
 		if (type instanceof Class) {
851
 			} else if (classType.isAnnotationPresent(FunctionalInterface.class)) {
872
 			} else if (classType.isAnnotationPresent(FunctionalInterface.class)) {
852
 				return loadFunctionalInterface(context, classType, new AnnotatedElement[0]);
873
 				return loadFunctionalInterface(context, classType, new AnnotatedElement[0]);
853
 			}
874
 			}
854
-			
875
+
855
 			if (typeByClass.containsKey(classType))
876
 			if (typeByClass.containsKey(classType))
856
 				return typeByClass.get(classType).stored();
877
 				return typeByClass.get(classType).stored();
857
-			
878
+
858
 			HighLevelDefinition definition = addClass(classType);
879
 			HighLevelDefinition definition = addClass(classType);
859
-			return registry.getForDefinition(definition).stored();
880
+			final List<StoredType> s = new ArrayList<>();
881
+			for (TypeVariable<? extends Class<?>> typeParameter : classType.getTypeParameters()) {
882
+				s.add(registry.getGeneric(context.get(typeParameter)).stored());
883
+			}
884
+
885
+			return registry.getForDefinition(definition, s.toArray(StoredType.NONE)).stored();
860
 		} else if (type instanceof ParameterizedType) {
886
 		} else if (type instanceof ParameterizedType) {
861
 			ParameterizedType parameterizedType = (ParameterizedType) type;
887
 			ParameterizedType parameterizedType = (ParameterizedType) type;
862
-			Class<?> rawType = (Class) parameterizedType.getRawType();
888
+			Class<?> rawType = (Class<?>) parameterizedType.getRawType();
863
 			if (rawType.isAnnotationPresent(FunctionalInterface.class))
889
 			if (rawType.isAnnotationPresent(FunctionalInterface.class))
864
 				return loadFunctionalInterface(context, rawType, (AnnotatedElement[]) parameterizedType.getActualTypeArguments());
890
 				return loadFunctionalInterface(context, rawType, (AnnotatedElement[]) parameterizedType.getActualTypeArguments());
865
-			
891
+
866
 			Type[] parameters = parameterizedType.getActualTypeArguments();
892
 			Type[] parameters = parameterizedType.getActualTypeArguments();
867
 			StoredType[] codeParameters = new StoredType[parameters.length];
893
 			StoredType[] codeParameters = new StoredType[parameters.length];
868
 			for (int i = 0; i < parameters.length; i++)
894
 			for (int i = 0; i < parameters.length; i++)
869
 			    codeParameters[i] = loadType(context, (AnnotatedElement) parameters[i], false, false);
895
 			    codeParameters[i] = loadType(context, (AnnotatedElement) parameters[i], false, false);
870
-       
896
+
871
 			if(rawType == Map.class) {
897
 			if(rawType == Map.class) {
872
                 return registry.getAssociative(codeParameters[0], codeParameters[1]).stored();
898
                 return registry.getAssociative(codeParameters[0], codeParameters[1]).stored();
873
             }
899
             }
874
-            
900
+
875
             HighLevelDefinition definition = addClass(rawType);
901
             HighLevelDefinition definition = addClass(rawType);
876
             return registry.getForDefinition(definition, codeParameters).stored();
902
             return registry.getForDefinition(definition, codeParameters).stored();
877
-		} else if (type instanceof TypeVariable) {
878
-            TypeVariable variable = (TypeVariable) type;
903
+		} else if (type instanceof TypeVariable<?>) {
904
+            TypeVariable<?> variable = (TypeVariable<?>) type;
879
             return registry.getGeneric(context.get(variable)).stored();
905
             return registry.getGeneric(context.get(variable)).stored();
880
         }else if(type instanceof AnnotatedType){
906
         }else if(type instanceof AnnotatedType){
881
-		    final StoredType storedType;
907
+		    StoredType storedType;
882
 		    if(type instanceof AnnotatedParameterizedType) {
908
 		    if(type instanceof AnnotatedParameterizedType) {
883
                 AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) type;
909
                 AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) type;
910
+
884
                 final Type rawType = ((ParameterizedType) parameterizedType.getType()).getRawType();
911
                 final Type rawType = ((ParameterizedType) parameterizedType.getType()).getRawType();
885
                 final AnnotatedType[] actualTypeArguments = parameterizedType.getAnnotatedActualTypeArguments();
912
                 final AnnotatedType[] actualTypeArguments = parameterizedType.getAnnotatedActualTypeArguments();
886
                 final StoredType[] codeParameters = new StoredType[actualTypeArguments.length];
913
                 final StoredType[] codeParameters = new StoredType[actualTypeArguments.length];
887
                 for(int i = 0; i < actualTypeArguments.length; i++) {
914
                 for(int i = 0; i < actualTypeArguments.length; i++) {
888
                     codeParameters[i] = loadType(context, actualTypeArguments[i], false, false);
915
                     codeParameters[i] = loadType(context, actualTypeArguments[i], false, false);
889
                 }
916
                 }
890
-            
917
+
891
                 if(rawType == Map.class) {
918
                 if(rawType == Map.class) {
892
                     storedType = registry.getAssociative(codeParameters[0], codeParameters[1]).stored();
919
                     storedType = registry.getAssociative(codeParameters[0], codeParameters[1]).stored();
893
-                } else {
894
-                    HighLevelDefinition definition = addClass((Class<?>) rawType);
895
-                    storedType = registry.getForDefinition(definition, codeParameters).stored();
920
+                } else if(rawType instanceof Class<?>){
921
+                	final Map<TypeParameter, StoredType> map = new HashMap<>();
922
+					final TypeVariable<? extends Class<?>>[] typeParameters = ((Class<?>) rawType).getTypeParameters();
923
+					final StoredType loadType = loadType(context, (AnnotatedElement) rawType, unsigned);
924
+					for (int i = 0; i < typeParameters.length; i++) {
925
+						final TypeParameter typeParameter = context.get(typeParameters[i]);
926
+						map.put(typeParameter, codeParameters[i]);
927
+					}
928
+					storedType = loadType.instance(new GenericMapper(CodePosition.NATIVE, registry, map));
929
+				} else {
930
+                    storedType = loadType(context, (AnnotatedElement) rawType, unsigned);
896
                 }
931
                 }
897
             } else {
932
             } else {
898
-		        storedType = loadType(context, (AnnotatedElement) ((AnnotatedType) type).getType(), unsigned);
933
+				if (((AnnotatedType) type).getType() instanceof WildcardType) {
934
+					storedType = BasicTypeID.UNDETERMINED.stored();
935
+				} else {
936
+					storedType = loadType(context, (AnnotatedElement) ((AnnotatedType) type).getType(), unsigned);
937
+				}
899
             }
938
             }
900
-            
939
+
901
 		    if(type.isAnnotationPresent(ZenCodeStorageTag.class)) {
940
 		    if(type.isAnnotationPresent(ZenCodeStorageTag.class)) {
902
 		        //Replace with switch if more StorageTagTypes are added
941
 		        //Replace with switch if more StorageTagTypes are added
903
                 if(type.getAnnotation(ZenCodeStorageTag.class).value() == StorageTagType.STATIC) {
942
                 if(type.getAnnotation(ZenCodeStorageTag.class).value() == StorageTagType.STATIC) {
905
                 }
944
                 }
906
             }
945
             }
907
 		    return storedType;
946
 		    return storedType;
908
-		    
947
+
909
         } else {
948
         } else {
910
 			throw new IllegalArgumentException("Could not analyze type: " + type);
949
 			throw new IllegalArgumentException("Could not analyze type: " + type);
911
 		}
950
 		}
912
 	}
951
 	}
913
-	
952
+
914
 	private StoredType loadFunctionalInterface(TypeVariableContext loadContext, Class<?> cls, AnnotatedElement[] parameters) {
953
 	private StoredType loadFunctionalInterface(TypeVariableContext loadContext, Class<?> cls, AnnotatedElement[] parameters) {
915
 		Method functionalInterfaceMethod = getFunctionalInterfaceMethod(cls);
954
 		Method functionalInterfaceMethod = getFunctionalInterfaceMethod(cls);
916
 		TypeVariableContext context = convertTypeParameters(cls);
955
 		TypeVariableContext context = convertTypeParameters(cls);
917
 		FunctionHeader header = getHeader(context, functionalInterfaceMethod);
956
 		FunctionHeader header = getHeader(context, functionalInterfaceMethod);
918
-		
957
+
919
 		Map<TypeParameter, StoredType> mapping = new HashMap<>();
958
 		Map<TypeParameter, StoredType> mapping = new HashMap<>();
920
 		TypeVariable[] javaParameters = cls.getTypeParameters();
959
 		TypeVariable[] javaParameters = cls.getTypeParameters();
921
-		for (int i = 0; i < javaParameters.length; i++)
960
+		for (int i = 0; i < parameters.length; i++)
922
 			mapping.put(context.get(javaParameters[i]), loadType(loadContext, parameters[i], false, false));
961
 			mapping.put(context.get(javaParameters[i]), loadType(loadContext, parameters[i], false, false));
923
-		
962
+
924
 		JavaMethod method = new JavaMethod(
963
 		JavaMethod method = new JavaMethod(
925
 				JavaClass.fromInternalName(getInternalName(cls), JavaClass.Kind.INTERFACE),
964
 				JavaClass.fromInternalName(getInternalName(cls), JavaClass.Kind.INTERFACE),
926
 				JavaMethod.Kind.INTERFACE,
965
 				JavaMethod.Kind.INTERFACE,
932
 		StorageTag tag = new JavaFunctionalInterfaceStorageTag(functionalInterfaceMethod, method);
971
 		StorageTag tag = new JavaFunctionalInterfaceStorageTag(functionalInterfaceMethod, method);
933
 		return registry.getFunction(header).stored(tag);
972
 		return registry.getFunction(header).stored(tag);
934
 	}
973
 	}
935
-	
974
+
936
 	private <T> TypeVariableContext convertTypeParameters(Class<T> cls) {
975
 	private <T> TypeVariableContext convertTypeParameters(Class<T> cls) {
937
-		TypeVariableContext context = new TypeVariableContext();
976
+		//TypeVariableContext context = new TypeVariableContext();
938
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
977
 		TypeVariable<Class<T>>[] javaTypeParameters = cls.getTypeParameters();
939
 		TypeParameter[] typeParameters = new TypeParameter[cls.getTypeParameters().length];
978
 		TypeParameter[] typeParameters = new TypeParameter[cls.getTypeParameters().length];
979
+
940
 		for (int i = 0; i < javaTypeParameters.length; i++) {
980
 		for (int i = 0; i < javaTypeParameters.length; i++) {
941
 			TypeVariable<Class<T>> typeVariable = javaTypeParameters[i];
981
 			TypeVariable<Class<T>> typeVariable = javaTypeParameters[i];
942
 			TypeParameter parameter = new TypeParameter(CodePosition.NATIVE, typeVariable.getName());
982
 			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
 			typeParameters[i] = parameter;
983
 			typeParameters[i] = parameter;
984
+
985
+			//Put up here so that Nested Type parameters may work..?
948
 			context.put(typeVariable, parameter);
986
 			context.put(typeVariable, parameter);
949
 		}
987
 		}
988
+
989
+		for (int i = 0; i < javaTypeParameters.length; i++) {
990
+			for (AnnotatedType bound : javaTypeParameters[i].getAnnotatedBounds()) {
991
+				TypeID type = loadType(context, bound).type;
992
+				typeParameters[i].addBound(new ParameterTypeBound(CodePosition.NATIVE, type));
993
+			}
994
+		}
950
 		return context;
995
 		return context;
951
 	}
996
 	}
952
-	
997
+
953
 	private Method getFunctionalInterfaceMethod(Class<?> functionalInterface) {
998
 	private Method getFunctionalInterfaceMethod(Class<?> functionalInterface) {
954
 		for (Method method : functionalInterface.getDeclaredMethods()) {
999
 		for (Method method : functionalInterface.getDeclaredMethods()) {
955
 			if (!method.isDefault())
1000
 			if (!method.isDefault())
956
 				return method;
1001
 				return method;
957
 		}
1002
 		}
958
-		
1003
+
959
 		return null;
1004
 		return null;
960
 	}
1005
 	}
961
-	
1006
+
962
 	private int getMethodModifiers(Member method) {
1007
 	private int getMethodModifiers(Member method) {
963
 		int result = Modifiers.PUBLIC;
1008
 		int result = Modifiers.PUBLIC;
964
 		if (isStatic(method.getModifiers()))
1009
 		if (isStatic(method.getModifiers()))
965
 			result |= Modifiers.STATIC;
1010
 			result |= Modifiers.STATIC;
966
 		if (isFinal(method.getModifiers()))
1011
 		if (isFinal(method.getModifiers()))
967
 			result |= Modifiers.FINAL;
1012
 			result |= Modifiers.FINAL;
968
-		
1013
+
969
 		return result;
1014
 		return result;
970
 	}
1015
 	}
971
-	
1016
+
972
 	private static boolean isPublic(int modifiers) {
1017
 	private static boolean isPublic(int modifiers) {
973
 		return (modifiers & Modifier.PUBLIC) > 0;
1018
 		return (modifiers & Modifier.PUBLIC) > 0;
974
 	}
1019
 	}
975
-	
1020
+
976
 	private static boolean isStatic(int modifiers) {
1021
 	private static boolean isStatic(int modifiers) {
977
 		return (modifiers & Modifier.STATIC) > 0;
1022
 		return (modifiers & Modifier.STATIC) > 0;
978
 	}
1023
 	}
979
-	
1024
+
980
 	private static boolean isFinal(int modifiers) {
1025
 	private static boolean isFinal(int modifiers) {
981
 		return (modifiers & Modifier.FINAL) > 0;
1026
 		return (modifiers & Modifier.FINAL) > 0;
982
 	}
1027
 	}
983
-	
1028
+
984
 	private static String getInternalName(Class<?> cls) {
1029
 	private static String getInternalName(Class<?> cls) {
985
 		return org.objectweb.asm.Type.getInternalName(cls);
1030
 		return org.objectweb.asm.Type.getInternalName(cls);
986
 	}
1031
 	}
987
-	
1032
+
988
 	private static String getDescriptor(Class<?> cls) {
1033
 	private static String getDescriptor(Class<?> cls) {
989
 		return org.objectweb.asm.Type.getDescriptor(cls);
1034
 		return org.objectweb.asm.Type.getDescriptor(cls);
990
 	}
1035
 	}
991
-	
1036
+
992
 	private static String getMethodDescriptor(java.lang.reflect.Constructor constructor) {
1037
 	private static String getMethodDescriptor(java.lang.reflect.Constructor constructor) {
993
 		return org.objectweb.asm.Type.getConstructorDescriptor(constructor);
1038
 		return org.objectweb.asm.Type.getConstructorDescriptor(constructor);
994
 	}
1039
 	}
995
-	
1040
+
996
 	private static String getMethodDescriptor(Method method) {
1041
 	private static String getMethodDescriptor(Method method) {
997
 		return org.objectweb.asm.Type.getMethodDescriptor(method);
1042
 		return org.objectweb.asm.Type.getMethodDescriptor(method);
998
 	}
1043
 	}
999
-	
1044
+
1000
 	private static JavaMethod getMethod(JavaClass cls, java.lang.reflect.Constructor constructor) {
1045
 	private static JavaMethod getMethod(JavaClass cls, java.lang.reflect.Constructor constructor) {
1001
 		return new JavaMethod(
1046
 		return new JavaMethod(
1002
 				cls,
1047
 				cls,
1007
 				constructor.getModifiers(),
1052
 				constructor.getModifiers(),
1008
 				false);
1053
 				false);
1009
 	}
1054
 	}
1010
-	
1055
+
1011
 	private static JavaMethod getMethod(JavaClass cls, Method method, StoredType result) {
1056
 	private static JavaMethod getMethod(JavaClass cls, Method method, StoredType result) {
1012
 		JavaMethod.Kind kind;
1057
 		JavaMethod.Kind kind;
1013
 		if (method.getName().equals("<init>"))
1058
 		if (method.getName().equals("<init>"))
1018
 			kind = JavaMethod.Kind.STATIC;
1063
 			kind = JavaMethod.Kind.STATIC;
1019
 		else
1064
 		else
1020
 			kind = JavaMethod.Kind.INSTANCE;
1065
 			kind = JavaMethod.Kind.INSTANCE;
1021
-		
1066
+
1022
 		return new JavaMethod(cls, kind, method.getName(), false, getMethodDescriptor(method), method.getModifiers(), result.isGeneric());
1067
 		return new JavaMethod(cls, kind, method.getName(), false, getMethodDescriptor(method), method.getModifiers(), result.isGeneric());
1023
 	}
1068
 	}
1024
 
1069
 
1028
 
1073
 
1029
 	private static class TypeVariableContext {
1074
 	private static class TypeVariableContext {
1030
 		private final Map<TypeVariable, TypeParameter> typeVariables = new HashMap<>();
1075
 		private final Map<TypeVariable, TypeParameter> typeVariables = new HashMap<>();
1031
-		
1076
+
1032
 		public void put(TypeVariable variable, TypeParameter parameter) {
1077
 		public void put(TypeVariable variable, TypeParameter parameter) {
1033
 			typeVariables.put(variable, parameter);
1078
 			typeVariables.put(variable, parameter);
1034
 		}
1079
 		}
1035
-		
1080
+
1036
 		public TypeParameter get(TypeVariable variable) {
1081
 		public TypeParameter get(TypeVariable variable) {
1037
 			if (!typeVariables.containsKey(variable))
1082
 			if (!typeVariables.containsKey(variable))
1038
 				throw new IllegalStateException("Could not find type variable " + variable.getName());
1083
 				throw new IllegalStateException("Could not find type variable " + variable.getName());
1039
-			
1084
+
1040
 			return typeVariables.get(variable);
1085
 			return typeVariables.get(variable);
1041
 		}
1086
 		}
1042
 	}
1087
 	}

+ 1
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java View File

52
 	
52
 	
53
 	public static String getNameFromFile(String filename) {
53
 	public static String getNameFromFile(String filename) {
54
 		if (filename.indexOf('.') > 0)
54
 		if (filename.indexOf('.') > 0)
55
-			return filename.substring(0, filename.indexOf('.'));
55
+			return filename.substring(0, filename.lastIndexOf('.'));
56
 		else
56
 		else
57
 			return filename;
57
 			return filename;
58
 	}
58
 	}

+ 10
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java View File

73
 			JavaNativeClass list = new JavaNativeClass(new JavaClass("java.util", "List", JavaClass.Kind.INTERFACE));
73
 			JavaNativeClass list = new JavaNativeClass(new JavaClass("java.util", "List", JavaClass.Kind.INTERFACE));
74
 			JavaClass arrayList = new JavaClass("java.util", "ArrayList", JavaClass.Kind.CLASS);
74
 			JavaClass arrayList = new JavaClass("java.util", "ArrayList", JavaClass.Kind.CLASS);
75
 			list.addMethod("constructor", JavaMethod.getNativeConstructor(arrayList, "()V"));
75
 			list.addMethod("constructor", JavaMethod.getNativeConstructor(arrayList, "()V"));
76
-			list.addInstanceMethod("add", "add", "(Ljava/lang/Object;)Z"); List<?> l;
76
+			list.addInstanceMethod("add", "add", "(Ljava/lang/Object;)Z");
77
 			list.addInstanceMethod("insert", "add", "(Ljava/lang/Object;I)V");
77
 			list.addInstanceMethod("insert", "add", "(Ljava/lang/Object;I)V");
78
 			list.addInstanceMethod("remove", "remove", "(Ljava/lang/Object;)Z");
78
 			list.addInstanceMethod("remove", "remove", "(Ljava/lang/Object;)Z");
79
 			list.addInstanceMethod("indexOf", "indexOf", "(Ljava/lang/Object;)I");
79
 			list.addInstanceMethod("indexOf", "indexOf", "(Ljava/lang/Object;)I");
236
 	
236
 	
237
 	private final JavaContext context;
237
 	private final JavaContext context;
238
 	private final String filename;
238
 	private final String filename;
239
+	private final String className;
239
 	private final JavaClass outerClass;
240
 	private final JavaClass outerClass;
240
 	private final JavaCompiledModule module;
241
 	private final JavaCompiledModule module;
241
-	
242
+
242
 	public JavaPrepareDefinitionVisitor(JavaContext context, JavaCompiledModule module, String filename, JavaClass outerClass) {
243
 	public JavaPrepareDefinitionVisitor(JavaContext context, JavaCompiledModule module, String filename, JavaClass outerClass) {
244
+		this(context, module, filename, outerClass, JavaClass.getNameFromFile(filename));
245
+	}
246
+
247
+	public JavaPrepareDefinitionVisitor(JavaContext context, JavaCompiledModule module, String filename, JavaClass outerClass, String className) {
243
 		this.context = context;
248
 		this.context = context;
244
 		this.filename = filename;
249
 		this.filename = filename;
245
 		this.outerClass = outerClass;
250
 		this.outerClass = outerClass;
246
 		this.module = module;
251
 		this.module = module;
252
+		this.className = className;
247
 	}
253
 	}
248
 	
254
 	
249
 	private boolean isPrepared(HighLevelDefinition definition) {
255
 	private boolean isPrepared(HighLevelDefinition definition) {
298
 		if (isPrepared(definition))
304
 		if (isPrepared(definition))
299
 			return context.getJavaClass(definition);
305
 			return context.getJavaClass(definition);
300
 		
306
 		
301
-		JavaClass cls = new JavaClass(context.getPackageName(definition.pkg), JavaClass.getNameFromFile(filename), JavaClass.Kind.CLASS);
307
+		JavaClass cls = new JavaClass(context.getPackageName(definition.pkg), className, JavaClass.Kind.CLASS);
302
 		context.setJavaClass(definition, cls);
308
 		context.setJavaClass(definition, cls);
303
 		return cls;
309
 		return cls;
304
 	}
310
 	}
313
 			context.setJavaNativeClass(definition, nativeClasses.get(nativeTag.value));
319
 			context.setJavaNativeClass(definition, nativeClasses.get(nativeTag.value));
314
 		}
320
 		}
315
 		
321
 		
316
-		JavaClass cls = new JavaClass(context.getPackageName(definition.pkg), JavaClass.getNameFromFile(filename), JavaClass.Kind.CLASS);
322
+		JavaClass cls = new JavaClass(context.getPackageName(definition.pkg), className, JavaClass.Kind.CLASS);
317
 		context.setJavaClass(definition, cls);
323
 		context.setJavaClass(definition, cls);
318
 		return cls;
324
 		return cls;
319
 	}
325
 	}

+ 124
- 0
Parser/src/main/java/org/openzen/zenscript/parser/EscapableBracketParser.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.parser;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zenscript.codemodel.OperatorType;
11
+import org.openzen.zenscript.codemodel.expression.CallArguments;
12
+import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
13
+import org.openzen.zenscript.codemodel.expression.Expression;
14
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
15
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
+import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
18
+import org.openzen.zenscript.codemodel.type.StringTypeID;
19
+import org.openzen.zenscript.codemodel.type.TypeID;
20
+import org.openzen.zenscript.lexer.ParseException;
21
+import org.openzen.zenscript.lexer.ZSToken;
22
+import org.openzen.zenscript.lexer.ZSTokenParser;
23
+import org.openzen.zenscript.lexer.ZSTokenType;
24
+import org.openzen.zenscript.parser.expression.ParsedExpression;
25
+import org.openzen.zenscript.parser.expression.ParsedExpressionBinary;
26
+import org.openzen.zenscript.parser.expression.ParsedExpressionString;
27
+
28
+import java.util.ArrayList;
29
+import java.util.List;
30
+
31
+/**
32
+ * @author Hoofdgebruiker and kindlich
33
+ */
34
+public class EscapableBracketParser implements BracketExpressionParser {
35
+    private final FunctionalMemberRef method;
36
+    private final TypeID targetType;
37
+
38
+    public EscapableBracketParser(GlobalTypeRegistry registry, FunctionalMemberRef method) {
39
+        if (!method.isStatic())
40
+            throw new IllegalArgumentException("Method must be static");
41
+        if (method.getHeader().getNumberOfTypeParameters() > 0)
42
+            throw new IllegalArgumentException("Method cannot have type parameters");
43
+
44
+        this.method = method;
45
+        this.targetType = registry.getForDefinition(method.getTarget().definition);
46
+    }
47
+
48
+    @Override
49
+    public ParsedExpression parse(CodePosition position, ZSTokenParser tokens) throws ParseException {
50
+        StringBuilder string = new StringBuilder();
51
+
52
+        //This list will contain the BEP calls
53
+        //If this is only a normal BEP, then it will contain exactly one String ParsedExpression.
54
+        final List<ParsedExpression> expressionList = new ArrayList<>();
55
+
56
+        while (tokens.optional(ZSTokenType.T_GREATER) == null) {
57
+            ZSToken next = tokens.next();
58
+
59
+            if (next.type != ZSTokenType.T_DOLLAR) {
60
+                string.append(next.content);
61
+                string.append(tokens.getLastWhitespace());
62
+                continue;
63
+            }
64
+
65
+            //We found a $, now check that it has a { directly after it.
66
+            final String ws = tokens.getLastWhitespace();
67
+            if (!ws.isEmpty()) {
68
+                //$  {..} is not ${..} so we print it as literal
69
+                string.append(next.content).append(ws);
70
+                continue;
71
+            }
72
+
73
+            next = tokens.next();
74
+            //Now we check if it is a {
75
+            if (next.type == ZSTokenType.T_AOPEN) {
76
+                if (string.length() != 0) {
77
+                    expressionList.add(new ParsedExpressionString(position, string.toString(), false));
78
+                    string = new StringBuilder();
79
+                }
80
+                expressionList.add(ParsedExpression.parse(tokens));
81
+                tokens.required(ZSTokenType.T_ACLOSE, "} expected.");
82
+                string.append(tokens.getLastWhitespace());
83
+            } else {
84
+                //No { after the $, so we treat them both as literal
85
+                string.append("$").append(ws); //Technically, the whitespace here is empty, but let's be sure
86
+                string.append(next.content).append(tokens.getLastWhitespace());
87
+            }
88
+
89
+        }
90
+
91
+        if (string.length() != 0) {
92
+            expressionList.add(new ParsedExpressionString(position, string.toString(), false));
93
+        }
94
+
95
+        return new StaticMethodCallExpression(position, expressionList);
96
+    }
97
+
98
+    private class StaticMethodCallExpression extends ParsedExpression {
99
+
100
+        private final ParsedExpression call;
101
+
102
+        public StaticMethodCallExpression(CodePosition position, List<ParsedExpression> expressions) {
103
+            super(position);
104
+            ParsedExpression p = null;
105
+            for (ParsedExpression expression : expressions) {
106
+                p = p == null ? expression : new ParsedExpressionBinary(expression.position, p, expression, OperatorType.ADD);
107
+            }
108
+
109
+            this.call = p;
110
+        }
111
+
112
+        @Override
113
+        public IPartialExpression compile(ExpressionScope scope) throws CompileException {
114
+            final Expression methodCall = call.compile(scope.withHint(StringTypeID.AUTO)).eval();
115
+            final CallArguments arguments = new CallArguments(methodCall);
116
+            return new CallStaticExpression(position, targetType, method, method.getHeader(), arguments);
117
+        }
118
+
119
+        @Override
120
+        public boolean hasStrongType() {
121
+            return true;
122
+        }
123
+    }
124
+}

+ 19
- 9
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java View File

81
 			
81
 			
82
 			header.setReturnType(returnType);
82
 			header.setReturnType(returnType);
83
 		}
83
 		}
84
-		
85
-		if (!scope.genericInferenceMap.isEmpty()) {
84
+
85
+
86
+		if (genericHeader.typeParameters.length > 0 && !scope.genericInferenceMap.isEmpty()) {
86
 			// perform type parameter inference
87
 			// perform type parameter inference
87
 			StoredType returnType = statements.getReturnType();
88
 			StoredType returnType = statements.getReturnType();
88
-			Map<TypeParameter, StoredType> inferredTypes = returnType.type.inferTypeParameters(scope.getMemberCache(), genericHeader.getReturnType());
89
-			if (inferredTypes == null)
90
-				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
91
-			
92
-			scope.genericInferenceMap.putAll(inferredTypes);
89
+			if (returnType != null) {
90
+				Map<TypeParameter, StoredType> inferredTypes = returnType.type.inferTypeParameters(scope.getMemberCache(), genericHeader
91
+						.getReturnType());
92
+				if (inferredTypes == null) {
93
+					throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
94
+				}
95
+
96
+				scope.genericInferenceMap.putAll(inferredTypes);
97
+			}
98
+
99
+		}
100
+
101
+		final FunctionHeader thatOtherHeader = genericHeader.withGenericArguments(new GenericMapper(position, scope.getTypeRegistry(), scope.genericInferenceMap));
102
+		if(thatOtherHeader.getReturnType().isBasic(BasicTypeID.UNDETERMINED)) {
103
+			thatOtherHeader.setReturnType(header.getReturnType());
93
 		}
104
 		}
94
-		
95
 		StoredType functionType = scope.getTypeRegistry()
105
 		StoredType functionType = scope.getTypeRegistry()
96
-				.getFunction(genericHeader.withGenericArguments(new GenericMapper(position, scope.getTypeRegistry(), scope.genericInferenceMap)))
106
+				.getFunction(thatOtherHeader)
97
 				.stored(storage);
107
 				.stored(storage);
98
 		return new FunctionExpression(position, functionType, closure, header, statements);
108
 		return new FunctionExpression(position, functionType, closure, header, statements);
99
 	}
109
 	}

+ 0
- 4
ScriptingExample/scripts/arithmetic.zs View File

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

+ 0
- 75
ScriptingExample/scripts/arrays.zs View File

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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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 View File

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

+ 0
- 2
ScriptingExample/scripts/statements.zs View File

1
-//while true
2
-//	println("Hello!");

+ 0
- 18
ScriptingExample/scripts/switch.zs View File

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 View File

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());

+ 4
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Globals.java View File

67
 	public static TestClass bracket(String value) {
67
 	public static TestClass bracket(String value) {
68
 		return new TestClass(value);
68
 		return new TestClass(value);
69
 	}
69
 	}
70
+
71
+	public static String staticToString(String value) {
72
+		return value;
73
+	}
70
 	
74
 	
71
 	@FunctionalInterface
75
 	@FunctionalInterface
72
 	public static interface MyFunctionalInterface {
76
 	public static interface MyFunctionalInterface {

+ 19
- 7
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java View File

15
 import org.openzen.zenscript.codemodel.type.StringTypeID;
15
 import org.openzen.zenscript.codemodel.type.StringTypeID;
16
 import org.openzen.zenscript.lexer.ParseException;
16
 import org.openzen.zenscript.lexer.ParseException;
17
 import org.openzen.zenscript.parser.BracketExpressionParser;
17
 import org.openzen.zenscript.parser.BracketExpressionParser;
18
+import org.openzen.zenscript.parser.EscapableBracketParser;
19
+import org.openzen.zenscript.parser.PrefixedBracketParser;
18
 import org.openzen.zenscript.parser.SimpleBracketParser;
20
 import org.openzen.zenscript.parser.SimpleBracketParser;
21
+import org.openzen.zenscript.scriptingexample.events.EventManager;
22
+import org.openzen.zenscript.scriptingexample.events.IEvent;
23
+import org.openzen.zenscript.scriptingexample.events.impl.CTStringedEvent;
19
 
24
 
20
 public class Main {
25
 public class Main {
21
 	public static void main(String[] args) throws CompileException, ParseException, IOException, NoSuchMethodException {
26
 	public static void main(String[] args) throws CompileException, ParseException, IOException, NoSuchMethodException {
22
 		ScriptingEngine scriptingEngine = new ScriptingEngine();
27
 		ScriptingEngine scriptingEngine = new ScriptingEngine();
23
 		scriptingEngine.debug = true;
28
 		scriptingEngine.debug = true;
24
-		
29
+
25
 		JavaNativeModule example = scriptingEngine.createNativeModule("example", "org.openzen.zenscript.scriptingexample");
30
 		JavaNativeModule example = scriptingEngine.createNativeModule("example", "org.openzen.zenscript.scriptingexample");
26
 		example.addGlobals(Globals.class);
31
 		example.addGlobals(Globals.class);
27
 		example.addClass(TestBaseInterface.class);
32
 		example.addClass(TestBaseInterface.class);
28
 		example.addClass(TestGenericInterface.class);
33
 		example.addClass(TestGenericInterface.class);
29
 		example.addClass(TestClass.class);
34
 		example.addClass(TestClass.class);
30
 		example.addClass(TestInterface.class);
35
 		example.addClass(TestInterface.class);
36
+		example.addClass(IEvent.class);
37
+		example.addClass(EventManager.class);
38
+		example.addClass(CTStringedEvent.class);
31
 		scriptingEngine.registerNativeProvided(example);
39
 		scriptingEngine.registerNativeProvided(example);
32
-		
40
+
33
 		File inputDirectory = new File("scripts");
41
 		File inputDirectory = new File("scripts");
34
 		File[] inputFiles = Optional.ofNullable(inputDirectory.listFiles((dir, name) -> name.endsWith(".zs"))).orElseGet(() -> new File[0]);
42
 		File[] inputFiles = Optional.ofNullable(inputDirectory.listFiles((dir, name) -> name.endsWith(".zs"))).orElseGet(() -> new File[0]);
35
 		SourceFile[] sourceFiles = new SourceFile[inputFiles.length];
43
 		SourceFile[] sourceFiles = new SourceFile[inputFiles.length];
36
 		for (int i = 0; i < inputFiles.length; i++)
44
 		for (int i = 0; i < inputFiles.length; i++)
37
 			sourceFiles[i] = new FileSourceFile(inputFiles[i].getName(), inputFiles[i]);
45
 			sourceFiles[i] = new FileSourceFile(inputFiles[i].getName(), inputFiles[i]);
38
-		
39
-		BracketExpressionParser bracketParser = new SimpleBracketParser(scriptingEngine.registry, example.loadStaticMethod(Globals.class.getMethod("bracket", String.class)));
46
+
47
+		final PrefixedBracketParser parser = new PrefixedBracketParser(null);
48
+		BracketExpressionParser testParser = new SimpleBracketParser(scriptingEngine.registry, example.loadStaticMethod(Globals.class.getMethod("bracket", String.class)));
49
+		parser.register("test", testParser);
50
+		BracketExpressionParser toStringParser = new EscapableBracketParser(scriptingEngine.registry, example.loadStaticMethod(Globals.class.getMethod("staticToString", String.class)));
51
+		parser.register("toString", toStringParser);
40
 		FunctionParameter parameter = new FunctionParameter(scriptingEngine.registry.getArray(StringTypeID.AUTO, 1).stored(), "args");
52
 		FunctionParameter parameter = new FunctionParameter(scriptingEngine.registry.getArray(StringTypeID.AUTO, 1).stored(), "args");
41
-		SemanticModule scripts = scriptingEngine.createScriptedModule("script", sourceFiles, bracketParser, new FunctionParameter[] { parameter });
53
+		SemanticModule scripts = scriptingEngine.createScriptedModule("script", sourceFiles, parser, new FunctionParameter[] { parameter });
42
 		if (!scripts.isValid())
54
 		if (!scripts.isValid())
43
 			return;
55
 			return;
44
-		
56
+
45
 		scriptingEngine.registerCompiled(scripts);
57
 		scriptingEngine.registerCompiled(scripts);
46
-		
58
+
47
 		Map<FunctionParameter, Object> scriptArgs = new HashMap<>();
59
 		Map<FunctionParameter, Object> scriptArgs = new HashMap<>();
48
 		scriptArgs.put(parameter, new String[] { "hello", "world", "example" });
60
 		scriptArgs.put(parameter, new String[] { "hello", "world", "example" });
49
 		scriptingEngine.run(scriptArgs);
61
 		scriptingEngine.run(scriptArgs);

+ 24
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/EventManager.java View File

1
+package org.openzen.zenscript.scriptingexample.events;
2
+
3
+import org.openzen.zencode.java.ZenCodeType;
4
+import org.openzen.zenscript.scriptingexample.events.impl.CTStringedEvent;
5
+import org.openzen.zenscript.scriptingexample.events.impl.StringedEvent;
6
+
7
+@ZenCodeType.Name("example.org.openzen.scripting_example.events.EventManager")
8
+public class EventManager {
9
+    @ZenCodeType.Method
10
+    public static void register(IEvent<?, ?> event) {
11
+    //public static <EVE extends IEvent<EVE, VA>, VA extends SomeMCEvent> void register(IEvent<EVE, VA> event) {
12
+        System.out.println("HIT!!!");
13
+
14
+        if(event instanceof CTStringedEvent) {
15
+            ((CTStringedEvent)event).getHandler().accept(new CTStringedEvent(null));
16
+        }
17
+    }
18
+
19
+    //@ZenCodeType.Method
20
+    //public static void register(CTStringedEvent event) {
21
+    //    System.out.println("HIT!!!");
22
+    //    event.getConsumer().accept(new StringedEvent("Abcdef"));
23
+    //}
24
+}

+ 41
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/IEvent.java View File

1
+package org.openzen.zenscript.scriptingexample.events;
2
+
3
+import org.openzen.zencode.java.ZenCodeType;
4
+
5
+import java.util.function.Consumer;
6
+
7
+@ZenCodeType.Name("example.org.openzen.scripting_example.events.IEvent")
8
+public abstract class IEvent<E extends IEvent<E, V>, V extends SomeMCEvent> {
9
+
10
+    private V internal;
11
+
12
+    private Consumer<E> handler;
13
+
14
+    public IEvent(V internal) {
15
+        this.internal = internal;
16
+    }
17
+
18
+    @ZenCodeType.Constructor
19
+    public IEvent(Consumer<E> handler) {
20
+        this.handler = handler;
21
+    }
22
+
23
+    public void setInternal(V internal) {
24
+        this.internal = internal;
25
+    }
26
+
27
+    public abstract Consumer<V> getConsumer();
28
+
29
+
30
+    public V getInternal() {
31
+        return internal;
32
+    }
33
+
34
+    public Consumer<E> getHandler() {
35
+        return handler;
36
+    }
37
+
38
+    public void setHandler(Consumer<E> handler) {
39
+        this.handler = handler;
40
+    }
41
+}

+ 4
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/SomeMCEvent.java View File

1
+package org.openzen.zenscript.scriptingexample.events;
2
+
3
+public interface SomeMCEvent {
4
+}

+ 25
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/impl/CTStringedEvent.java View File

1
+package org.openzen.zenscript.scriptingexample.events.impl;
2
+
3
+import org.openzen.zencode.java.ZenCodeType;
4
+import org.openzen.zenscript.scriptingexample.events.IEvent;
5
+
6
+import java.util.function.Consumer;
7
+
8
+@ZenCodeType.Name("example.org.openzen.scripting_example.events.CTStringedEvent")
9
+public class CTStringedEvent extends IEvent<CTStringedEvent, StringedEvent> {
10
+
11
+    @ZenCodeType.Getter("blub")
12
+    public String getBlub() {
13
+        return "ASDF";
14
+    }
15
+
16
+    @ZenCodeType.Constructor
17
+    public CTStringedEvent(Consumer<CTStringedEvent> handler) {
18
+        super(handler);
19
+    }
20
+
21
+    @Override
22
+    public Consumer<StringedEvent> getConsumer() {
23
+        return stringedEvent -> getHandler().accept(new CTStringedEvent(null));
24
+    }
25
+}

+ 12
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/events/impl/StringedEvent.java View File

1
+package org.openzen.zenscript.scriptingexample.events.impl;
2
+
3
+import org.openzen.zenscript.scriptingexample.events.SomeMCEvent;
4
+
5
+public class StringedEvent implements SomeMCEvent {
6
+    private final String text;
7
+
8
+    public StringedEvent(String text) {
9
+
10
+        this.text = text;
11
+    }
12
+}

Loading…
Cancel
Save