Browse Source

- Added (key, value) iterator for associative arrays

- Added type bounds checking code
- Fixed definitions not being added to the respective packages
- Fixed various bugs with generics
- Added some things to stdlib and created collections library
Stan Hebben 6 years ago
parent
commit
f307a7d81e
89 changed files with 668 additions and 228 deletions
  1. 4
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  2. 20
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  3. 4
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  4. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallArguments.java
  5. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java
  6. 4
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java
  7. 1
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java
  8. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  9. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/WrapOptionalExpression.java
  10. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/GenericParameterBound.java
  11. 7
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java
  12. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java
  13. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java
  14. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  15. 1
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinition.java
  16. 77
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.java
  17. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/IPartialExpression.java
  18. 8
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialGlobalExpression.java
  19. 11
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java
  20. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialPackageExpression.java
  21. 10
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java
  22. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java
  23. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java
  24. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java
  25. 6
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java
  26. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java
  27. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ConstTypeID.java
  28. 27
    15
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java
  29. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java
  30. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java
  31. 21
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericName.java
  32. 8
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java
  33. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  34. 10
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java
  35. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java
  36. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java
  37. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java
  38. 1
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinTypeMembers.java
  39. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  40. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/LocalMemberCache.java
  41. 25
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  42. 23
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  43. 4
    0
      Constructor/libraries/collections/module.json
  44. 9
    0
      Constructor/libraries/collections/src/HashSet.zs
  45. 43
    0
      Constructor/libraries/collections/src/LinkedList.zs
  46. 5
    0
      Constructor/libraries/collections/src/NoSuchElementException.zs
  47. 7
    0
      Constructor/libraries/collections/src/Queue.zs
  48. 8
    0
      Constructor/libraries/collections/src/Set.zs
  49. 3
    1
      Constructor/libraries/stdlib/module.json
  50. 3
    0
      Constructor/libraries/stdlib/src/Comparable.zs
  51. 0
    0
      Constructor/libraries/stdlib/src/IllegalOperationException.zs
  52. 6
    0
      Constructor/libraries/stdlib/src/StringBuildable.zs
  53. 16
    2
      Constructor/libraries/stdlib/src/StringBuilder.zs
  54. 6
    11
      Constructor/src/main/java/org/openzen/zenscript/constructor/Main.java
  55. 30
    5
      Constructor/src/main/java/org/openzen/zenscript/constructor/Project.java
  56. 5
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java
  57. 2
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java
  58. 11
    8
      Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java
  59. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java
  60. 1
    1
      Linker/src/main/java/org/openzen/zenscript/linker/ForeachScope.java
  61. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java
  62. 5
    4
      Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java
  63. 1
    1
      Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java
  64. 1
    1
      Linker/src/main/java/org/openzen/zenscript/linker/LambdaScope.java
  65. 1
    1
      Linker/src/main/java/org/openzen/zenscript/linker/StatementScope.java
  66. 2
    3
      Linker/src/main/java/org/openzen/zenscript/linker/symbol/ISymbol.java
  67. 2
    3
      Linker/src/main/java/org/openzen/zenscript/linker/symbol/TypeSymbol.java
  68. 2
    3
      Parser/src/main/java/org/openzen/zenscript/lexer/CompiledDFA.java
  69. 9
    0
      Parser/src/main/java/org/openzen/zenscript/lexer/TokenStream.java
  70. 1
    1
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenStream.java
  71. 1
    1
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java
  72. 10
    9
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedGenericParameter.java
  73. 1
    0
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java
  74. 19
    15
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedCallArguments.java
  75. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java
  76. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java
  77. 5
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIndex.java
  78. 6
    11
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java
  79. 8
    7
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java
  80. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java
  81. 13
    2
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java
  82. 3
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementForeach.java
  83. 28
    11
      Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java
  84. 2
    11
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedNamedType.java
  85. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeGenericMap.java
  86. 3
    2
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java
  87. 2
    1
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java
  88. 15
    13
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java
  89. 8
    2
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java

+ 4
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java View File

15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.scope.TypeScope;
17
 import org.openzen.zenscript.codemodel.scope.TypeScope;
18
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
18
 
19
 
19
 /**
20
 /**
20
  *
21
  *
58
 		return new FunctionHeader(genericParameters, returnType, parameters);
59
 		return new FunctionHeader(genericParameters, returnType, parameters);
59
 	}
60
 	}
60
 	
61
 	
61
-	public ITypeID[] inferTypes(CallArguments arguments, List<ITypeID> resultHint) {
62
+	public ITypeID[] inferTypes(LocalMemberCache cache, CallArguments arguments, List<ITypeID> resultHint) {
62
 		if (arguments.arguments.length != this.parameters.length)
63
 		if (arguments.arguments.length != this.parameters.length)
63
 			return null;
64
 			return null;
64
 		
65
 		
66
 		if (!resultHint.isEmpty()) {
67
 		if (!resultHint.isEmpty()) {
67
 			Map<TypeParameter, ITypeID> temp = new HashMap<>();
68
 			Map<TypeParameter, ITypeID> temp = new HashMap<>();
68
 			for (ITypeID hint : resultHint) {
69
 			for (ITypeID hint : resultHint) {
69
-				if (returnType.inferTypeParameters(hint, temp)) {
70
+				if (returnType.inferTypeParameters(cache, hint, temp)) {
70
 					mapping = temp;
71
 					mapping = temp;
71
 					break;
72
 					break;
72
 				}
73
 				}
75
 		
76
 		
76
 		// TODO: lambda header inference
77
 		// TODO: lambda header inference
77
 		for (int i = 0; i < parameters.length; i++)
78
 		for (int i = 0; i < parameters.length; i++)
78
-			if (!parameters[i].type.inferTypeParameters(arguments.arguments[i].type, mapping))
79
+			if (!parameters[i].type.inferTypeParameters(cache, arguments.arguments[i].type, mapping))
79
 				return null;
80
 				return null;
80
 		
81
 		
81
 		if (mapping.size() > typeParameters.length)
82
 		if (mapping.size() > typeParameters.length)

+ 20
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java View File

10
 import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
10
 import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
11
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
11
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
+import org.openzen.zenscript.codemodel.member.ConstructorMember;
13
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
14
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
14
 import org.openzen.zenscript.codemodel.member.FieldMember;
15
 import org.openzen.zenscript.codemodel.member.FieldMember;
15
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
16
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
22
  * @author Hoofdgebruiker
23
  * @author Hoofdgebruiker
23
  */
24
  */
24
 public abstract class HighLevelDefinition extends Taggable {
25
 public abstract class HighLevelDefinition extends Taggable {
25
-	private static final TypeParameter[] NO_PARAMETERS = new TypeParameter[0];
26
-	
27
 	public final CodePosition position;
26
 	public final CodePosition position;
28
 	public final ZSPackage pkg;
27
 	public final ZSPackage pkg;
29
 	public final String name;
28
 	public final String name;
30
 	public final int modifiers;
29
 	public final int modifiers;
31
 	public final List<IDefinitionMember> members = new ArrayList<>();
30
 	public final List<IDefinitionMember> members = new ArrayList<>();
32
-	public TypeParameter[] genericParameters = NO_PARAMETERS;
31
+	public TypeParameter[] genericParameters = null;
33
 	
32
 	
34
 	public HighLevelDefinition outerDefinition;
33
 	public HighLevelDefinition outerDefinition;
35
 	public ITypeID superType;
34
 	public ITypeID superType;
40
 		this.name = name;
39
 		this.name = name;
41
 		this.modifiers = modifiers;
40
 		this.modifiers = modifiers;
42
 		this.outerDefinition = outerDefinition;
41
 		this.outerDefinition = outerDefinition;
42
+		
43
+		if (pkg != null)
44
+			pkg.register(this);
45
+	}
46
+	
47
+	public int getNumberOfGenericParameters() {
48
+		return genericParameters == null ? 0 : genericParameters.length;
43
 	}
49
 	}
44
 	
50
 	
45
 	public void setOuterDefinition(HighLevelDefinition outerDefinition) {
51
 	public void setOuterDefinition(HighLevelDefinition outerDefinition) {
77
 		return enumMembers;
83
 		return enumMembers;
78
 	}
84
 	}
79
 	
85
 	
86
+	public boolean hasEmptyConstructor() {
87
+		for (IDefinitionMember member : members) {
88
+			if (member instanceof ConstructorMember) {
89
+				if (((ConstructorMember) member).header.parameters.length == 0)
90
+					return true;
91
+			}
92
+		}
93
+		
94
+		return false;
95
+	}
96
+	
80
 	public boolean isStatic() {
97
 	public boolean isStatic() {
81
 		return (modifiers & Modifiers.STATIC) > 0;
98
 		return (modifiers & Modifiers.STATIC) > 0;
82
 	}
99
 	}

+ 4
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java View File

38
 		if (subPackages.containsKey(name))
38
 		if (subPackages.containsKey(name))
39
 			throw new RuntimeException("Such package already exists: " + name);
39
 			throw new RuntimeException("Such package already exists: " + name);
40
 		
40
 		
41
-		subPackages.put(name, this);
41
+		subPackages.put(name, subPackage);
42
 	}
42
 	}
43
 	
43
 	
44
 	public IPartialExpression getMember(CodePosition position, GlobalTypeRegistry registry, GenericName name) {
44
 	public IPartialExpression getMember(CodePosition position, GlobalTypeRegistry registry, GenericName name) {
45
-		if (subPackages.containsKey(name.name) && name.arguments.isEmpty())
45
+		if (subPackages.containsKey(name.name) && name.hasNoArguments())
46
 			return new PartialPackageExpression(position, subPackages.get(name.name));
46
 			return new PartialPackageExpression(position, subPackages.get(name.name));
47
 		
47
 		
48
 		if (types.containsKey(name.name)) {
48
 		if (types.containsKey(name.name)) {
49
-			if (types.get(name.name).genericParameters.length != name.arguments.size())
49
+			if (types.get(name.name).genericParameters.length != name.getNumberOfArguments())
50
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
50
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
51
 			
51
 			
52
 			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments));
52
 			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments));
77
 			return null;
77
 			return null;
78
 		
78
 		
79
 		GenericName name = nameParts.get(depth);
79
 		GenericName name = nameParts.get(depth);
80
-		if (subPackages.containsKey(name.name) && name.arguments.isEmpty())
80
+		if (subPackages.containsKey(name.name) && name.hasNoArguments())
81
 			return subPackages.get(name.name).getType(position, scope, nameParts, depth + 1);
81
 			return subPackages.get(name.name).getType(position, scope, nameParts, depth + 1);
82
 		
82
 		
83
 		if (types.containsKey(name.name)) {
83
 		if (types.containsKey(name.name)) {

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallArguments.java View File

25
 	
25
 	
26
 	public CallArguments(ITypeID[] typeArguments, Expression[] arguments) {
26
 	public CallArguments(ITypeID[] typeArguments, Expression[] arguments) {
27
 		if (typeArguments == null)
27
 		if (typeArguments == null)
28
-			throw new IllegalArgumentException("Type arguments cannot be null!");
28
+			typeArguments = NO_TYPE_ARGUMENTS;
29
 		if (arguments == null)
29
 		if (arguments == null)
30
 			throw new IllegalArgumentException("Arguments cannot be null!");
30
 			throw new IllegalArgumentException("Arguments cannot be null!");
31
 		
31
 		

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

20
 	public final Expression target;
20
 	public final Expression target;
21
 	public final FunctionalMember member;
21
 	public final FunctionalMember member;
22
 	public final CallArguments arguments;
22
 	public final CallArguments arguments;
23
+	public final FunctionHeader instancedHeader;
23
 	
24
 	
24
 	public CallExpression(CodePosition position, Expression target, FunctionalMember member, FunctionHeader instancedHeader, CallArguments arguments) {
25
 	public CallExpression(CodePosition position, Expression target, FunctionalMember member, FunctionHeader instancedHeader, CallArguments arguments) {
25
 		super(position, instancedHeader.returnType);
26
 		super(position, instancedHeader.returnType);
37
 		this.target = target;
38
 		this.target = target;
38
 		this.member = member;
39
 		this.member = member;
39
 		this.arguments = arguments;
40
 		this.arguments = arguments;
41
+		this.instancedHeader = instancedHeader;
40
 	}
42
 	}
41
 	
43
 	
42
 	public Expression getFirstArgument() {
44
 	public Expression getFirstArgument() {

+ 4
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.expression;
6
 package org.openzen.zenscript.codemodel.expression;
7
 
7
 
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
8
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
 import org.openzen.zenscript.codemodel.type.ITypeID;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
10
 import org.openzen.zenscript.shared.CodePosition;
11
 import org.openzen.zenscript.shared.CodePosition;
17
 	public final FunctionalMember member;
18
 	public final FunctionalMember member;
18
 	public final ITypeID target;
19
 	public final ITypeID target;
19
 	public final CallArguments arguments;
20
 	public final CallArguments arguments;
21
+	public final FunctionHeader instancedHeader;
20
 	
22
 	
21
-	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMember member, CallArguments arguments) {
23
+	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMember member, CallArguments arguments, FunctionHeader instancedHeader) {
22
 		super(position, member.header.returnType);
24
 		super(position, member.header.returnType);
23
 		
25
 		
24
 		this.member = member;
26
 		this.member = member;
25
 		this.target = target;
27
 		this.target = target;
26
 		this.arguments = arguments;
28
 		this.arguments = arguments;
29
+		this.instancedHeader = instancedHeader;
27
 	}
30
 	}
28
 
31
 
29
 	@Override
32
 	@Override

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.expression;
6
 package org.openzen.zenscript.codemodel.expression;
7
 
7
 
8
-import java.util.Collections;
9
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
8
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
10
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
9
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
11
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
26
 	}
25
 	}
27
 	
26
 	
28
 	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
27
 	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
29
-		super(position, registry.getForDefinition(type, Collections.emptyList()));
28
+		super(position, registry.getForDefinition(type, null));
30
 		
29
 		
31
 		this.value = value;
30
 		this.value = value;
32
 	}
31
 	}

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

79
 		TypeMembers members = scope.getTypeMembers(type);
79
 		TypeMembers members = scope.getTypeMembers(type);
80
 		return members.getMemberExpression(position, this, name, false);
80
 		return members.getMemberExpression(position, this, name, false);
81
 	}
81
 	}
82
+	
83
+	@Override
84
+	public ITypeID[] getGenericCallTypes() {
85
+		return null;
86
+	}
82
 }
87
 }

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/WrapOptionalExpression.java View File

18
 	public WrapOptionalExpression(CodePosition position, Expression value, ITypeID optionalType) {
18
 	public WrapOptionalExpression(CodePosition position, Expression value, ITypeID optionalType) {
19
 		super(position, optionalType);
19
 		super(position, optionalType);
20
 		
20
 		
21
+		if (value.type.isOptional())
22
+			throw new IllegalArgumentException("Value is already optional");
23
+		
21
 		this.value = value;
24
 		this.value = value;
22
 	}
25
 	}
23
 
26
 

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/GenericParameterBound.java View File

20
 	
20
 	
21
 	public abstract void registerMembers(LocalMemberCache cache, TypeMembers type);
21
 	public abstract void registerMembers(LocalMemberCache cache, TypeMembers type);
22
 	
22
 	
23
-	public abstract boolean matches(ITypeID type);
23
+	public abstract boolean matches(LocalMemberCache cache, ITypeID type);
24
 	
24
 	
25
 	public abstract GenericParameterBound withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
25
 	public abstract GenericParameterBound withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
26
 }
26
 }

+ 7
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java View File

28
 	}
28
 	}
29
 
29
 
30
 	@Override
30
 	@Override
31
-	public boolean matches(ITypeID type) {
32
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
31
+	public boolean matches(LocalMemberCache cache, ITypeID type) {
32
+		return cache.get(this.type).extendsOrImplements(type);
33
 	}
33
 	}
34
 
34
 
35
 	@Override
35
 	@Override
36
 	public GenericParameterBound withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
36
 	public GenericParameterBound withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
37
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
37
+		ITypeID translated = type.withGenericArguments(registry, arguments);
38
+		if (translated == type)
39
+			return this;
40
+		
41
+		return new ParameterSuperBound(translated);
38
 	}
42
 	}
39
 
43
 
40
 	@Override
44
 	@Override

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java View File

32
 	}
32
 	}
33
 
33
 
34
 	@Override
34
 	@Override
35
-	public boolean matches(ITypeID type) {
36
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
35
+	public boolean matches(LocalMemberCache cache, ITypeID type) {
36
+		return cache.get(type).extendsOrImplements(this.type);
37
 	}
37
 	}
38
 
38
 
39
 	@Override
39
 	@Override

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java View File

10
 import java.util.Map;
10
 import java.util.Map;
11
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
13
 import org.openzen.zenscript.shared.CodePosition;
14
 import org.openzen.zenscript.shared.CodePosition;
14
 
15
 
15
 /**
16
 /**
36
 		bounds.add(bound);
37
 		bounds.add(bound);
37
 	}
38
 	}
38
 	
39
 	
39
-	public boolean matches(ITypeID type) {
40
+	public boolean matches(LocalMemberCache cache, ITypeID type) {
40
 		for (GenericParameterBound bound : bounds) {
41
 		for (GenericParameterBound bound : bounds) {
41
-			if (!bound.matches(type))
42
+			if (!bound.matches(cache, type))
42
 				return false;
43
 				return false;
43
 		}
44
 		}
44
 		
45
 		

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java View File

58
 	
58
 	
59
 	@Override
59
 	@Override
60
 	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments) {
60
 	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments) {
61
-		return new CallStaticExpression(position, target, this, arguments);
61
+		return new CallStaticExpression(position, target, this, arguments, instancedHeader);
62
 	}
62
 	}
63
 	
63
 	
64
 	@Override
64
 	@Override

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

6
 package org.openzen.zenscript.codemodel.member;
6
 package org.openzen.zenscript.codemodel.member;
7
 
7
 
8
 import java.util.Collections;
8
 import java.util.Collections;
9
-import java.util.List;
10
 import java.util.Map;
9
 import java.util.Map;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
32
 		this.outerTypeArguments = outerTypeArguments;
31
 		this.outerTypeArguments = outerTypeArguments;
33
 	}
32
 	}
34
 	
33
 	
35
-	public DefinitionTypeID instance(GlobalTypeRegistry registry, List<ITypeID> typeArguments) {
34
+	public DefinitionTypeID instance(GlobalTypeRegistry registry, ITypeID[] typeArguments) {
36
 		return registry.getForDefinition(definition, typeArguments, outerTypeArguments);
35
 		return registry.getForDefinition(definition, typeArguments, outerTypeArguments);
37
 	}
36
 	}
38
 }
37
 }

+ 77
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.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.codemodel.member.builtin;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
10
+import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
11
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
12
+import org.openzen.zenscript.codemodel.member.IIteratorMember;
13
+import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.type.AssocTypeID;
15
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
+import org.openzen.zenscript.codemodel.type.ITypeID;
17
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
18
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
19
+import org.openzen.zenscript.shared.CodePosition;
20
+import org.openzen.zenscript.shared.Taggable;
21
+
22
+/**
23
+ *
24
+ * @author Hoofdgebruiker
25
+ */
26
+public class AssocIterator extends Taggable implements IIteratorMember {
27
+	private final AssocTypeID type;
28
+	private final ITypeID[] loopVariableTypes;
29
+	
30
+	public AssocIterator(AssocTypeID type) {
31
+		this.type = type;
32
+		
33
+		loopVariableTypes = new ITypeID[2];
34
+		loopVariableTypes[0] = type.keyType;
35
+		loopVariableTypes[1] = type.valueType;
36
+	}
37
+	
38
+	@Override
39
+	public CodePosition getPosition() {
40
+		return CodePosition.BUILTIN;
41
+	}
42
+
43
+	@Override
44
+	public int getLoopVariableCount() {
45
+		return loopVariableTypes.length;
46
+	}
47
+
48
+	@Override
49
+	public ITypeID[] getLoopVariableTypes() {
50
+		return loopVariableTypes;
51
+	}
52
+
53
+	@Override
54
+	public String describe() {
55
+		return "iterator for key/value pairs in an associative array";
56
+	}
57
+
58
+	@Override
59
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
60
+		type.addIterator(this, priority);
61
+	}
62
+
63
+	@Override
64
+	public IDefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
65
+		return new AssocIterator(type.withGenericArguments(registry, mapping));
66
+	}
67
+
68
+	@Override
69
+	public <T> T accept(MemberVisitor<T> visitor) {
70
+		throw new UnsupportedOperationException("Not a compilable member");
71
+	}
72
+
73
+	@Override
74
+	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
75
+		return visitor.visitArrayKeyValueIterator();
76
+	}
77
+}

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

37
 	
37
 	
38
 	Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments);
38
 	Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments);
39
 	
39
 	
40
+	ITypeID[] getGenericCallTypes();
41
+	
40
 	default Expression assign(CodePosition position, TypeScope scope, Expression value) {
42
 	default Expression assign(CodePosition position, TypeScope scope, Expression value) {
41
 		throw new CompileException(position, CompileExceptionCode.CANNOT_ASSIGN, "This expression is not assignable");
43
 		throw new CompileException(position, CompileExceptionCode.CANNOT_ASSIGN, "This expression is not assignable");
42
 	}
44
 	}

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

24
 	private final CodePosition position;
24
 	private final CodePosition position;
25
 	private final String name;
25
 	private final String name;
26
 	private final IPartialExpression resolution;
26
 	private final IPartialExpression resolution;
27
+	private final ITypeID[] typeParameters;
27
 	
28
 	
28
-	public PartialGlobalExpression(CodePosition position, String name, IPartialExpression resolution) {
29
+	public PartialGlobalExpression(CodePosition position, String name, IPartialExpression resolution, ITypeID[] typeParameters) {
29
 		this.position = position;
30
 		this.position = position;
30
 		this.name = name;
31
 		this.name = name;
31
 		this.resolution = resolution;
32
 		this.resolution = resolution;
33
+		this.typeParameters = typeParameters;
32
 	}
34
 	}
33
 	
35
 	
34
 	@Override
36
 	@Override
55
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
57
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
56
 		return new GlobalCallExpression(position, name, arguments, resolution.call(position, scope, hints, arguments));
58
 		return new GlobalCallExpression(position, name, arguments, resolution.call(position, scope, hints, arguments));
57
 	}
59
 	}
60
+
61
+	@Override
62
+	public ITypeID[] getGenericCallTypes() {
63
+		return typeParameters;
64
+	}
58
 }
65
 }

+ 11
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java View File

27
 	private final CodePosition position;
27
 	private final CodePosition position;
28
 	private final Expression target;
28
 	private final Expression target;
29
 	private final DefinitionMemberGroup group;
29
 	private final DefinitionMemberGroup group;
30
+	private final ITypeID[] typeArguments;
30
 	private final boolean allowStaticUsage;
31
 	private final boolean allowStaticUsage;
31
 	
32
 	
32
-	public PartialMemberGroupExpression(CodePosition position, Expression target, DefinitionMemberGroup group, boolean allowStaticMembers) {
33
+	public PartialMemberGroupExpression(CodePosition position, Expression target, DefinitionMemberGroup group, ITypeID[] typeArguments, boolean allowStaticMembers) {
33
 		this.position = position;
34
 		this.position = position;
34
 		this.target = target;
35
 		this.target = target;
35
 		this.group = group;
36
 		this.group = group;
37
+		this.typeArguments = typeArguments;
36
 		this.allowStaticUsage = allowStaticMembers;
38
 		this.allowStaticUsage = allowStaticMembers;
37
 	}
39
 	}
38
 	
40
 	
39
-	public PartialMemberGroupExpression(CodePosition position, Expression target, ICallableMember member, boolean allowStaticMembers) {
41
+	public PartialMemberGroupExpression(CodePosition position, Expression target, ICallableMember member, ITypeID[] typeArguments, boolean allowStaticMembers) {
40
 		this.position = position;
42
 		this.position = position;
41
 		this.target = target;
43
 		this.target = target;
42
 		this.group = DefinitionMemberGroup.forMethod(member);
44
 		this.group = DefinitionMemberGroup.forMethod(member);
45
+		this.typeArguments = typeArguments;
43
 		this.allowStaticUsage = allowStaticMembers;
46
 		this.allowStaticUsage = allowStaticMembers;
44
 	}
47
 	}
45
 
48
 
91
 	
94
 	
92
 	@Override
95
 	@Override
93
 	public IPartialExpression capture(CodePosition position, LambdaClosure closure) {
96
 	public IPartialExpression capture(CodePosition position, LambdaClosure closure) {
94
-		return new PartialMemberGroupExpression(position, target.capture(position, closure).eval(), group, allowStaticUsage);
97
+		return new PartialMemberGroupExpression(position, target.capture(position, closure).eval(), group, typeArguments, allowStaticUsage);
98
+	}
99
+
100
+	@Override
101
+	public ITypeID[] getGenericCallTypes() {
102
+		return typeArguments;
95
 	}
103
 	}
96
 }
104
 }

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

55
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
55
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
56
 		throw new CompileException(position, CompileExceptionCode.USING_PACKAGE_AS_CALL_TARGET, "Cannot call a package");
56
 		throw new CompileException(position, CompileExceptionCode.USING_PACKAGE_AS_CALL_TARGET, "Cannot call a package");
57
 	}
57
 	}
58
+
59
+	@Override
60
+	public ITypeID[] getGenericCallTypes() {
61
+		return null;
62
+	}
58
 }
63
 }

+ 10
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java View File

23
  * @author Hoofdgebruiker
23
  * @author Hoofdgebruiker
24
  */
24
  */
25
 public class PartialStaticMemberGroupExpression implements IPartialExpression {
25
 public class PartialStaticMemberGroupExpression implements IPartialExpression {
26
-	public static PartialStaticMemberGroupExpression forMethod(CodePosition position, ITypeID target, ICallableMember method) {
26
+	public static PartialStaticMemberGroupExpression forMethod(CodePosition position, ITypeID target, ICallableMember method, ITypeID[] typeArguments) {
27
 		DefinitionMemberGroup group = new DefinitionMemberGroup(true);
27
 		DefinitionMemberGroup group = new DefinitionMemberGroup(true);
28
 		group.addMethod(method, TypeMemberPriority.SPECIFIED);
28
 		group.addMethod(method, TypeMemberPriority.SPECIFIED);
29
-		return new PartialStaticMemberGroupExpression(position, target, group);
29
+		return new PartialStaticMemberGroupExpression(position, target, group, typeArguments);
30
 	}
30
 	}
31
 	
31
 	
32
 	private final CodePosition position;
32
 	private final CodePosition position;
33
 	private final ITypeID target;
33
 	private final ITypeID target;
34
 	private final DefinitionMemberGroup group;
34
 	private final DefinitionMemberGroup group;
35
+	private final ITypeID[] typeArguments;
35
 	
36
 	
36
-	public PartialStaticMemberGroupExpression(CodePosition position, ITypeID target, DefinitionMemberGroup group) {
37
+	public PartialStaticMemberGroupExpression(CodePosition position, ITypeID target, DefinitionMemberGroup group, ITypeID[] typeArguments) {
37
 		this.position = position;
38
 		this.position = position;
38
 		this.group = group;
39
 		this.group = group;
39
 		this.target = target;
40
 		this.target = target;
41
+		this.typeArguments = typeArguments;
40
 	}
42
 	}
41
 	
43
 	
42
 	@Override
44
 	@Override
71
 	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
73
 	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
72
 		return group.staticSetter(position, scope, value);
74
 		return group.staticSetter(position, scope, value);
73
 	}
75
 	}
76
+
77
+	@Override
78
+	public ITypeID[] getGenericCallTypes() {
79
+		return typeArguments;
80
+	}
74
 }
81
 }

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

60
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
60
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
61
 		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).callStatic(position, type, scope, arguments);
61
 		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).callStatic(position, type, scope, arguments);
62
 	}
62
 	}
63
+
64
+	@Override
65
+	public ITypeID[] getGenericCallTypes() {
66
+		return null;
67
+	}
63
 }
68
 }

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java View File

7
 
7
 
8
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
8
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
9
 import org.openzen.zenscript.codemodel.type.ITypeID;
9
 import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
10
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
11
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
11
 
12
 
12
 /**
13
 /**
16
 public interface TypeScope {
17
 public interface TypeScope {
17
 	public GlobalTypeRegistry getTypeRegistry();
18
 	public GlobalTypeRegistry getTypeRegistry();
18
 	
19
 	
20
+	public LocalMemberCache getMemberCache();
21
+	
19
 	public TypeMembers getTypeMembers(ITypeID type);
22
 	public TypeMembers getTypeMembers(ITypeID type);
20
 }
23
 }

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

54
 		return elementType.hasInferenceBlockingTypeParameters(parameters);
54
 		return elementType.hasInferenceBlockingTypeParameters(parameters);
55
 	}
55
 	}
56
 
56
 
57
+	@Override
58
+	public boolean hasDefaultValue() {
59
+		return false;
60
+	}
61
+
57
 	@Override
62
 	@Override
58
 	public int hashCode() {
63
 	public int hashCode() {
59
 		int hash = 7;
64
 		int hash = 7;

+ 6
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java View File

22
 	}
22
 	}
23
 	
23
 	
24
 	@Override
24
 	@Override
25
-	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
25
+	public AssocTypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
26
 		return registry.getAssociative(
26
 		return registry.getAssociative(
27
 				keyType.withGenericArguments(registry, arguments),
27
 				keyType.withGenericArguments(registry, arguments),
28
 				valueType.withGenericArguments(registry, arguments));
28
 				valueType.withGenericArguments(registry, arguments));
53
 		return keyType.hasInferenceBlockingTypeParameters(parameters) || valueType.hasInferenceBlockingTypeParameters(parameters);
53
 		return keyType.hasInferenceBlockingTypeParameters(parameters) || valueType.hasInferenceBlockingTypeParameters(parameters);
54
 	}
54
 	}
55
 
55
 
56
+	@Override
57
+	public boolean hasDefaultValue() {
58
+		return true;
59
+	}
60
+
56
 	@Override
61
 	@Override
57
 	public int hashCode() {
62
 	public int hashCode() {
58
 		int hash = 7;
63
 		int hash = 7;

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

76
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
76
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
77
 		return false;
77
 		return false;
78
 	}
78
 	}
79
+
80
+	@Override
81
+	public boolean hasDefaultValue() {
82
+		return true;
83
+	}
79
 }
84
 }

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

82
 	public String toString() {
82
 	public String toString() {
83
 		return "const " + baseType.toString();
83
 		return "const " + baseType.toString();
84
 	}
84
 	}
85
+
86
+	@Override
87
+	public boolean hasDefaultValue() {
88
+		return baseType.hasDefaultValue();
89
+	}
85
 }
90
 }

+ 27
- 15
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.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.ArrayList;
9
 import java.util.Arrays;
8
 import java.util.Arrays;
10
 import java.util.Collections;
9
 import java.util.Collections;
11
 import java.util.HashMap;
10
 import java.util.HashMap;
12
-import java.util.List;
13
 import java.util.Map;
11
 import java.util.Map;
14
 import java.util.Objects;
12
 import java.util.Objects;
15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
24
 		if (definition.genericParameters.length > 0)
22
 		if (definition.genericParameters.length > 0)
25
 			throw new IllegalArgumentException("Definition has type arguments!");
23
 			throw new IllegalArgumentException("Definition has type arguments!");
26
 		
24
 		
27
-		return new DefinitionTypeID(definition, NO_TYPE_PARAMETERS);
25
+		return new DefinitionTypeID(definition, null);
28
 	}
26
 	}
29
 	
27
 	
30
 	private static final OuterTypeEntry[] NO_OUTER_ENTRIES = new OuterTypeEntry[0];
28
 	private static final OuterTypeEntry[] NO_OUTER_ENTRIES = new OuterTypeEntry[0];
31
-	private static final ITypeID[] NO_TYPE_PARAMETERS = new ITypeID[0];
32
 	
29
 	
33
 	public final HighLevelDefinition definition;
30
 	public final HighLevelDefinition definition;
34
 	public final ITypeID[] typeParameters;
31
 	public final ITypeID[] typeParameters;
57
 			Arrays.sort(outerTypeEntries, (a, b) -> a.parameter.name.compareTo(b.parameter.name));
54
 			Arrays.sort(outerTypeEntries, (a, b) -> a.parameter.name.compareTo(b.parameter.name));
58
 		}
55
 		}
59
 		
56
 		
60
-		if (typeParameters.length != definition.genericParameters.length)
57
+		if ((typeParameters == null ? 0 : typeParameters.length) != definition.getNumberOfGenericParameters())
61
 			throw new RuntimeException("Invalid number of type parameters");
58
 			throw new RuntimeException("Invalid number of type parameters");
62
 	}
59
 	}
63
 	
60
 	
61
+	public boolean hasTypeParameters() {
62
+		return typeParameters != null && typeParameters.length > 0;
63
+	}
64
+	
64
 	public void init(GlobalTypeRegistry registry) {
65
 	public void init(GlobalTypeRegistry registry) {
65
 		ITypeID superType = definition.superType;
66
 		ITypeID superType = definition.superType;
66
-		if (superType != null && typeParameters.length > 0) {
67
+		if (superType != null && hasTypeParameters()) {
67
 			Map<TypeParameter, ITypeID> genericSuperArguments = new HashMap<>();
68
 			Map<TypeParameter, ITypeID> genericSuperArguments = new HashMap<>();
68
 			for (int i = 0; i < typeParameters.length; i++)
69
 			for (int i = 0; i < typeParameters.length; i++)
69
 				genericSuperArguments.put(definition.genericParameters[i], typeParameters[i]);
70
 				genericSuperArguments.put(definition.genericParameters[i], typeParameters[i]);
76
 	// To be used exclusively by StaticDefinitionTypeID
77
 	// To be used exclusively by StaticDefinitionTypeID
77
 	protected DefinitionTypeID(HighLevelDefinition definition) {
78
 	protected DefinitionTypeID(HighLevelDefinition definition) {
78
 		this.definition = definition;
79
 		this.definition = definition;
79
-		this.typeParameters = new ITypeID[0];
80
+		this.typeParameters = null;
80
 		this.superType = definition.superType;
81
 		this.superType = definition.superType;
81
 		this.outerTypeParameters = Collections.emptyMap();
82
 		this.outerTypeParameters = Collections.emptyMap();
82
 		this.outerTypeEntries = NO_OUTER_ENTRIES;
83
 		this.outerTypeEntries = NO_OUTER_ENTRIES;
84
 	
85
 	
85
 	@Override
86
 	@Override
86
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
87
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
87
-		if (typeParameters.length == 0 && outerTypeParameters.isEmpty())
88
+		if (!hasTypeParameters() && outerTypeParameters.isEmpty())
88
 			return this;
89
 			return this;
89
 		
90
 		
90
-		List<ITypeID> instancedArguments = new ArrayList<>();
91
-		for (int i = 0; i < typeParameters.length; i++) {
92
-			instancedArguments.add(arguments.containsKey(definition.genericParameters[i]) ? arguments.get(definition.genericParameters[i]) : typeParameters[i].withGenericArguments(registry, arguments));
91
+		ITypeID[] instancedArguments = null;
92
+		if (typeParameters != null) {
93
+			instancedArguments = new ITypeID[typeParameters.length];
94
+			for (int i = 0; i < typeParameters.length; i++) {
95
+				instancedArguments[i] = arguments.containsKey(definition.genericParameters[i]) ? arguments.get(definition.genericParameters[i]) : typeParameters[i].withGenericArguments(registry, arguments);
96
+			}
93
 		}
97
 		}
98
+		
94
 		Map<TypeParameter, ITypeID> instancedOuter;
99
 		Map<TypeParameter, ITypeID> instancedOuter;
95
 		if (outerTypeParameters.isEmpty()) {
100
 		if (outerTypeParameters.isEmpty()) {
96
 			instancedOuter = Collections.emptyMap();
101
 			instancedOuter = Collections.emptyMap();
129
 
134
 
130
 	@Override
135
 	@Override
131
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
136
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
132
-		for (ITypeID typeParameter : typeParameters)
133
-			if (typeParameter.hasInferenceBlockingTypeParameters(parameters))
134
-				return true;
137
+		if (typeParameters != null) {
138
+			for (ITypeID typeParameter : typeParameters)
139
+				if (typeParameter.hasInferenceBlockingTypeParameters(parameters))
140
+					return true;
141
+		}
135
 		
142
 		
136
 		return superType != null && superType.hasInferenceBlockingTypeParameters(parameters);
143
 		return superType != null && superType.hasInferenceBlockingTypeParameters(parameters);
137
 	}
144
 	}
164
 	
171
 	
165
 	@Override
172
 	@Override
166
 	public String toString() {
173
 	public String toString() {
167
-		if (typeParameters.length == 0) {
174
+		if (typeParameters == null) {
168
 			return definition.name;
175
 			return definition.name;
169
 		} else {
176
 		} else {
170
 			StringBuilder result = new StringBuilder();
177
 			StringBuilder result = new StringBuilder();
179
 			return result.toString();
186
 			return result.toString();
180
 		}
187
 		}
181
 	}
188
 	}
189
+
190
+	@Override
191
+	public boolean hasDefaultValue() {
192
+		return definition.hasEmptyConstructor();
193
+	}
182
 	
194
 	
183
 	private class OuterTypeEntry {
195
 	private class OuterTypeEntry {
184
 		private final TypeParameter parameter;
196
 		private final TypeParameter parameter;

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

52
 		return header.hasInferenceBlockingTypeParameters(parameters);
52
 		return header.hasInferenceBlockingTypeParameters(parameters);
53
 	}
53
 	}
54
 
54
 
55
+	@Override
56
+	public boolean hasDefaultValue() {
57
+		return false;
58
+	}
59
+
55
 	@Override
60
 	@Override
56
 	public int hashCode() {
61
 	public int hashCode() {
57
 		int hash = 5;
62
 		int hash = 5;

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

52
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
52
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
53
 		return value.hasInferenceBlockingTypeParameters(parameters);
53
 		return value.hasInferenceBlockingTypeParameters(parameters);
54
 	}
54
 	}
55
+
56
+	@Override
57
+	public boolean hasDefaultValue() {
58
+		return true;
59
+	}
55
 	
60
 	
56
 	@Override
61
 	@Override
57
 	public String toString() {
62
 	public String toString() {

+ 21
- 7
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericName.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.Collections;
9
-import java.util.List;
10
-
11
 /**
8
 /**
12
  *
9
  *
13
  * @author Hoofdgebruiker
10
  * @author Hoofdgebruiker
14
  */
11
  */
15
 public class GenericName {
12
 public class GenericName {
16
 	public final String name;
13
 	public final String name;
17
-	public final List<ITypeID> arguments;
14
+	public final ITypeID[] arguments;
18
 	
15
 	
19
 	public GenericName(String name) {
16
 	public GenericName(String name) {
20
-		this(name, Collections.emptyList());
17
+		this(name, null);
21
 	}
18
 	}
22
 	
19
 	
23
-	public GenericName(String name, List<ITypeID> arguments) {
20
+	public GenericName(String name, ITypeID[] arguments) {
24
 		this.name = name;
21
 		this.name = name;
25
 		this.arguments = arguments;
22
 		this.arguments = arguments;
26
 	}
23
 	}
27
 	
24
 	
25
+	public int getNumberOfArguments() {
26
+		return arguments == null ? 0 : arguments.length;
27
+	}
28
+	
29
+	public boolean hasArguments() {
30
+		return arguments != null && arguments.length > 0;
31
+	}
32
+	
33
+	public boolean hasNoArguments() {
34
+		return arguments == null || arguments.length == 0;
35
+	}
36
+	
28
 	@Override
37
 	@Override
29
 	public String toString() {
38
 	public String toString() {
30
 		StringBuilder result = new StringBuilder(name);
39
 		StringBuilder result = new StringBuilder(name);
31
-		if (!arguments.isEmpty()) {
40
+		if (arguments != null) {
32
 			result.append("<");
41
 			result.append("<");
42
+			for (int i = 0; i < arguments.length; i++) {
43
+				if (i > 0)
44
+					result.append(", ");
45
+				result.append(arguments[i].toString());
46
+			}
33
 			result.append(">");
47
 			result.append(">");
34
 		}
48
 		}
35
 		return result.toString();
49
 		return result.toString();

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java View File

7
 
7
 
8
 import java.util.Map;
8
 import java.util.Map;
9
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
9
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
10
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
10
 
11
 
11
 /**
12
 /**
12
  *
13
  *
19
 		this.parameter = parameter;
20
 		this.parameter = parameter;
20
 	}
21
 	}
21
 	
22
 	
22
-	public boolean matches(ITypeID type) {
23
-		return parameter.matches(type);
23
+	public boolean matches(LocalMemberCache cache, ITypeID type) {
24
+		return parameter.matches(cache, type);
24
 	}
25
 	}
25
 	
26
 	
26
 	@Override
27
 	@Override
57
 		return false;
58
 		return false;
58
 	}
59
 	}
59
 
60
 
61
+	@Override
62
+	public boolean hasDefaultValue() {
63
+		return false;
64
+	}
65
+
60
 	@Override
66
 	@Override
61
 	public int hashCode() {
67
 	public int hashCode() {
62
 		int hash = 7;
68
 		int hash = 7;

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

7
 
7
 
8
 import java.util.Collections;
8
 import java.util.Collections;
9
 import java.util.HashMap;
9
 import java.util.HashMap;
10
-import java.util.List;
11
 import java.util.Map;
10
 import java.util.Map;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
111
 		}
110
 		}
112
 	}
111
 	}
113
 	
112
 	
114
-	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, List<ITypeID> genericArguments) {
113
+	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] genericArguments) {
115
 		return this.getForDefinition(definition, genericArguments, Collections.emptyMap());
114
 		return this.getForDefinition(definition, genericArguments, Collections.emptyMap());
116
 	}
115
 	}
117
 	
116
 	
118
-	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, List<ITypeID> typeParameters, Map<TypeParameter, ITypeID> outerInstance) {
117
+	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] typeParameters, Map<TypeParameter, ITypeID> outerInstance) {
119
 		DefinitionTypeID id;
118
 		DefinitionTypeID id;
120
-		if (definition.genericParameters.length > 0 && typeParameters.isEmpty() && outerInstance.isEmpty()) {
119
+		if (definition.genericParameters == null && typeParameters == null && outerInstance.isEmpty()) {
121
 			// make it a static one
120
 			// make it a static one
122
 			id = new StaticDefinitionTypeID(definition);
121
 			id = new StaticDefinitionTypeID(definition);
123
 		} else {
122
 		} else {
124
-			id = new DefinitionTypeID(definition, typeParameters.toArray(new ITypeID[typeParameters.size()]), outerInstance);
123
+			id = new DefinitionTypeID(definition, typeParameters, outerInstance);
125
 		}
124
 		}
126
 		
125
 		
127
 		if (definitionTypes.containsKey(id)) {
126
 		if (definitionTypes.containsKey(id)) {

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

7
 
7
 
8
 import java.util.Map;
8
 import java.util.Map;
9
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
9
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
10
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
10
 
11
 
11
 /**
12
 /**
12
  *
13
  *
33
 		return this;
34
 		return this;
34
 	}
35
 	}
35
 	
36
 	
37
+	public boolean hasDefaultValue();
38
+	
36
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
39
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
37
 	
40
 	
38
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);
41
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);
39
 	
42
 	
40
 	// Infers type parameters for this type so it matches with targetType
43
 	// Infers type parameters for this type so it matches with targetType
41
 	// returns false if that isn't possible
44
 	// returns false if that isn't possible
42
-	public default boolean inferTypeParameters(ITypeID targetType, Map<TypeParameter, ITypeID> mapping) {
43
-		return accept(new MatchingTypeVisitor(targetType, mapping));
45
+	public default boolean inferTypeParameters(LocalMemberCache cache, ITypeID targetType, Map<TypeParameter, ITypeID> mapping) {
46
+		return accept(new MatchingTypeVisitor(cache, targetType, mapping));
44
 	}
47
 	}
45
 	
48
 	
46
 	public static class MatchingTypeVisitor implements ITypeVisitor<Boolean> {
49
 	public static class MatchingTypeVisitor implements ITypeVisitor<Boolean> {
47
 		private final ITypeID type;
50
 		private final ITypeID type;
48
 		private final Map<TypeParameter, ITypeID> mapping;
51
 		private final Map<TypeParameter, ITypeID> mapping;
52
+		private final LocalMemberCache cache;
49
 		
53
 		
50
-		public MatchingTypeVisitor(ITypeID type, Map<TypeParameter, ITypeID> mapping) {
54
+		public MatchingTypeVisitor(LocalMemberCache cache, ITypeID type, Map<TypeParameter, ITypeID> mapping) {
51
 			this.type = type;
55
 			this.type = type;
52
 			this.mapping = mapping;
56
 			this.mapping = mapping;
57
+			this.cache = cache;
53
 		}
58
 		}
54
 
59
 
55
 		@Override
60
 		@Override
141
 		public Boolean visitGeneric(GenericTypeID generic) {
146
 		public Boolean visitGeneric(GenericTypeID generic) {
142
 			if (mapping.containsKey(generic.parameter)) {
147
 			if (mapping.containsKey(generic.parameter)) {
143
 				return mapping.get(generic.parameter) == type;
148
 				return mapping.get(generic.parameter) == type;
144
-			} else if (generic.matches(type)) {
149
+			} else if (generic.matches(cache, type)) {
145
 				mapping.put(generic.parameter, type);
150
 				mapping.put(generic.parameter, type);
146
 				return true;
151
 				return true;
147
 			} else {
152
 			} else {
183
 			if (type == pattern)
188
 			if (type == pattern)
184
 				return true;
189
 				return true;
185
 			
190
 			
186
-			return pattern.accept(new MatchingTypeVisitor(type, mapping));
191
+			return pattern.accept(new MatchingTypeVisitor(cache, type, mapping));
187
 		}
192
 		}
188
 
193
 
189
 		@Override
194
 		@Override

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

58
 		return false;
58
 		return false;
59
 	}
59
 	}
60
 
60
 
61
+	@Override
62
+	public boolean hasDefaultValue() {
63
+		return false;
64
+	}
65
+
61
 	@Override
66
 	@Override
62
 	public int hashCode() {
67
 	public int hashCode() {
63
 		int hash = 5;
68
 		int hash = 5;

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

61
 		return baseType.hasInferenceBlockingTypeParameters(parameters);
61
 		return baseType.hasInferenceBlockingTypeParameters(parameters);
62
 	}
62
 	}
63
 
63
 
64
+	@Override
65
+	public boolean hasDefaultValue() {
66
+		return true;
67
+	}
68
+
64
 	@Override
69
 	@Override
65
 	public int hashCode() {
70
 	public int hashCode() {
66
 		int hash = 7;
71
 		int hash = 7;

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

55
 		return from.hasInferenceBlockingTypeParameters(parameters) || to.hasInferenceBlockingTypeParameters(parameters);
55
 		return from.hasInferenceBlockingTypeParameters(parameters) || to.hasInferenceBlockingTypeParameters(parameters);
56
 	}
56
 	}
57
 
57
 
58
+	@Override
59
+	public boolean hasDefaultValue() {
60
+		return false;
61
+	}
62
+
58
 	@Override
63
 	@Override
59
 	public int hashCode() {
64
 	public int hashCode() {
60
 		int hash = 5;
65
 		int hash = 5;

+ 1
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinTypeMembers.java View File

224
 	public static final OperatorMember STRING_INDEXGET = new OperatorMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, OperatorType.INDEXGET, new FunctionHeader(CHAR, new FunctionParameter(INT)));
224
 	public static final OperatorMember STRING_INDEXGET = new OperatorMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, OperatorType.INDEXGET, new FunctionHeader(CHAR, new FunctionParameter(INT)));
225
 	public static final OperatorMember STRING_RANGEGET = new OperatorMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, OperatorType.INDEXGET, new FunctionHeader(STRING, new FunctionParameter(RangeTypeID.INT)));
225
 	public static final OperatorMember STRING_RANGEGET = new OperatorMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, OperatorType.INDEXGET, new FunctionHeader(STRING, new FunctionParameter(RangeTypeID.INT)));
226
 	public static final GetterMember STRING_LENGTH = new GetterMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, "length", INT);
226
 	public static final GetterMember STRING_LENGTH = new GetterMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, "length", INT);
227
+	public static final GetterMember STRING_CHARACTERS = new GetterMember(BUILTIN, T_STRING, Modifiers.PUBLIC | Modifiers.EXTERN, "characters", ArrayTypeID.CHAR);
227
 	
228
 	
228
 	private static OperatorMember not(ClassDefinition cls, ITypeID result) {
229
 	private static OperatorMember not(ClassDefinition cls, ITypeID result) {
229
 		return new OperatorMember(BUILTIN, cls, 0, OperatorType.NOT, new FunctionHeader(result));
230
 		return new OperatorMember(BUILTIN, cls, 0, OperatorType.NOT, new FunctionHeader(result));

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java View File

218
 			if (header.typeParameters.length > 0) {
218
 			if (header.typeParameters.length > 0) {
219
 				for (ITypeID resultHint : typeHints) {
219
 				for (ITypeID resultHint : typeHints) {
220
 					Map<TypeParameter, ITypeID> mapping = new HashMap<>();
220
 					Map<TypeParameter, ITypeID> mapping = new HashMap<>();
221
-					if (header.returnType.inferTypeParameters(resultHint, mapping)) {
221
+					if (header.returnType.inferTypeParameters(scope.getMemberCache(), resultHint, mapping)) {
222
 						header = header.withGenericArguments(scope.getTypeRegistry(), mapping);
222
 						header = header.withGenericArguments(scope.getTypeRegistry(), mapping);
223
 						break;
223
 						break;
224
 					}
224
 					}
236
 	
236
 	
237
 	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) {
237
 	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) {
238
 		ICallableMember method = selectMethod(position, scope, arguments, true, allowStaticUsage);
238
 		ICallableMember method = selectMethod(position, scope, arguments, true, allowStaticUsage);
239
+		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
239
 		for (int i = 0; i < arguments.arguments.length; i++) {
240
 		for (int i = 0; i < arguments.arguments.length; i++) {
240
-			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, method.getHeader().parameters[i].type);
241
+			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
241
 		}
242
 		}
242
 		
243
 		
243
-		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
244
 		return method.call(position, target, instancedHeader, arguments);
244
 		return method.call(position, target, instancedHeader, arguments);
245
 	}
245
 	}
246
 	
246
 	

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/LocalMemberCache.java View File

54
 	}
54
 	}
55
 	
55
 	
56
 	private void registerMembers(TypeMembers members) {
56
 	private void registerMembers(TypeMembers members) {
57
-		members.type.accept(new TypeMemberBuilder(members, this));
57
+		members.type.accept(new TypeMemberBuilder(registry, members, this));
58
 		
58
 		
59
 		for (ExpansionDefinition expansion : expansions) {
59
 		for (ExpansionDefinition expansion : expansions) {
60
 			if (expansion.target == null)
60
 			if (expansion.target == null)
78
 			return Collections.emptyMap();
78
 			return Collections.emptyMap();
79
 		
79
 		
80
 		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
80
 		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
81
-		if (pattern.inferTypeParameters(type, mapping))
81
+		if (pattern.inferTypeParameters(this, type, mapping))
82
 			return mapping;
82
 			return mapping;
83
 		
83
 		
84
 		return null;
84
 		return null;

+ 25
- 7
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java View File

35
 import org.openzen.zenscript.codemodel.member.TranslatedOperatorMember;
35
 import org.openzen.zenscript.codemodel.member.TranslatedOperatorMember;
36
 import org.openzen.zenscript.codemodel.member.builtin.ArrayIteratorKeyValues;
36
 import org.openzen.zenscript.codemodel.member.builtin.ArrayIteratorKeyValues;
37
 import org.openzen.zenscript.codemodel.member.builtin.ArrayIteratorValues;
37
 import org.openzen.zenscript.codemodel.member.builtin.ArrayIteratorValues;
38
+import org.openzen.zenscript.codemodel.member.builtin.AssocIterator;
38
 import org.openzen.zenscript.codemodel.member.builtin.ComparatorMember;
39
 import org.openzen.zenscript.codemodel.member.builtin.ComparatorMember;
39
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
40
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
40
 import org.openzen.zenscript.codemodel.member.builtin.RangeIterator;
41
 import org.openzen.zenscript.codemodel.member.builtin.RangeIterator;
48
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
49
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
49
 import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
50
 import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
50
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
51
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
52
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
51
 import org.openzen.zenscript.codemodel.type.ITypeID;
53
 import org.openzen.zenscript.codemodel.type.ITypeID;
52
 import org.openzen.zenscript.codemodel.type.ITypeVisitor;
54
 import org.openzen.zenscript.codemodel.type.ITypeVisitor;
53
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
55
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
61
  * @author Hoofdgebruiker
63
  * @author Hoofdgebruiker
62
  */
64
  */
63
 public class TypeMemberBuilder implements ITypeVisitor<Void> {
65
 public class TypeMemberBuilder implements ITypeVisitor<Void> {
66
+	private final GlobalTypeRegistry registry;
64
 	private final TypeMembers members;
67
 	private final TypeMembers members;
65
 	private final LocalMemberCache cache;
68
 	private final LocalMemberCache cache;
66
 
69
 
67
-	public TypeMemberBuilder(TypeMembers members, LocalMemberCache cache) {
70
+	public TypeMemberBuilder(GlobalTypeRegistry registry, TypeMembers members, LocalMemberCache cache) {
71
+		this.registry = registry;
68
 		this.members = members;
72
 		this.members = members;
69
 		this.cache = cache;
73
 		this.cache = cache;
70
 		
74
 		
178
 		FunctionHeader indexSetHeader = new FunctionHeader(VOID, new FunctionParameter(keyType, "key"), new FunctionParameter(valueType, "value"));
182
 		FunctionHeader indexSetHeader = new FunctionHeader(VOID, new FunctionParameter(keyType, "key"), new FunctionParameter(valueType, "value"));
179
 		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.INDEXSET, indexSetHeader));
183
 		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.INDEXSET, indexSetHeader));
180
 		
184
 		
181
-		FunctionHeader getOrDefaultHeader = new FunctionHeader(valueType, new FunctionParameter(keyType, "key"), new FunctionParameter(valueType, "defaultValue"));
185
+		FunctionHeader getOrDefaultHeader = new FunctionHeader(registry.getOptional(valueType), new FunctionParameter(keyType, "key"), new FunctionParameter(valueType, "defaultValue"));
182
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOrDefault", getOrDefaultHeader));
186
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOrDefault", getOrDefaultHeader));
183
 		
187
 		
184
 		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.CONTAINS, new FunctionHeader(BOOL, new FunctionParameter(keyType, "key"))));
188
 		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.CONTAINS, new FunctionHeader(BOOL, new FunctionParameter(keyType, "key"))));
186
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "size", INT));
190
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "size", INT));
187
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL));
191
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL));
188
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "keys", cache.getRegistry().getArray(keyType, 1)));
192
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "keys", cache.getRegistry().getArray(keyType, 1)));
193
+		
194
+		members.addIterator(new AssocIterator(assoc), TypeMemberPriority.SPECIFIED);
189
 		return null;
195
 		return null;
190
 	}
196
 	}
191
 	
197
 	
195
 		
201
 		
196
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
202
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
197
 		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, new FunctionHeader(VOID)));
203
 		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, new FunctionHeader(VOID)));
198
-		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOptional", new FunctionHeader(map.keys, valueType, new FunctionParameter[0])));
204
+		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOptional", new FunctionHeader(map.keys, registry.getOptional(valueType), new FunctionParameter[0])));
199
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, new FunctionParameter(valueType))));
205
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, new FunctionParameter(valueType))));
200
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "contains", new FunctionHeader(map.keys, BasicTypeID.BOOL, new FunctionParameter[0])));
206
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "contains", new FunctionHeader(map.keys, BasicTypeID.BOOL, new FunctionParameter[0])));
201
 		return null;
207
 		return null;
216
 	@Override
222
 	@Override
217
 	public Void visitDefinition(DefinitionTypeID type) {
223
 	public Void visitDefinition(DefinitionTypeID type) {
218
 		HighLevelDefinition definition = type.definition;
224
 		HighLevelDefinition definition = type.definition;
219
-		if (type.typeParameters.length > 0 || !type.outerTypeParameters.isEmpty()) {
225
+		if (type.hasTypeParameters() || !type.outerTypeParameters.isEmpty()) {
220
 			Map<TypeParameter, ITypeID> mapping = new HashMap<>();
226
 			Map<TypeParameter, ITypeID> mapping = new HashMap<>();
221
-			for (int i = 0; i < type.typeParameters.length; i++)
222
-				mapping.put(definition.genericParameters[i], type.typeParameters[i]);
227
+			if (type.typeParameters != null)
228
+				for (int i = 0; i < type.typeParameters.length; i++)
229
+					mapping.put(definition.genericParameters[i], type.typeParameters[i]);
230
+			
223
 			for (Map.Entry<TypeParameter, ITypeID> entry : type.outerTypeParameters.entrySet())
231
 			for (Map.Entry<TypeParameter, ITypeID> entry : type.outerTypeParameters.entrySet())
224
 				mapping.put(entry.getKey(), entry.getValue());
232
 				mapping.put(entry.getKey(), entry.getValue());
225
 			
233
 			
286
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
294
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
287
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "from", fromType), TypeMemberPriority.SPECIFIED);
295
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "from", fromType), TypeMemberPriority.SPECIFIED);
288
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "to", toType), TypeMemberPriority.SPECIFIED);
296
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "to", toType), TypeMemberPriority.SPECIFIED);
289
-		members.addIterator(new RangeIterator(range), TypeMemberPriority.SPECIFIED);
297
+		if (range.from == range.to && (range.from == BasicTypeID.BYTE
298
+				|| range.from == BasicTypeID.SBYTE
299
+				|| range.from == BasicTypeID.SHORT
300
+				|| range.from == BasicTypeID.USHORT
301
+				|| range.from == BasicTypeID.INT
302
+				|| range.from == BasicTypeID.UINT
303
+				|| range.from == BasicTypeID.LONG
304
+				|| range.from == BasicTypeID.ULONG)) {
305
+			members.addIterator(new RangeIterator(range), TypeMemberPriority.SPECIFIED);
306
+		}
290
 		return null;
307
 		return null;
291
 	}
308
 	}
292
 
309
 
450
 		members.addOperator(STRING_INDEXGET);
467
 		members.addOperator(STRING_INDEXGET);
451
 		members.addOperator(STRING_RANGEGET);
468
 		members.addOperator(STRING_RANGEGET);
452
 		members.addGetter(STRING_LENGTH);
469
 		members.addGetter(STRING_LENGTH);
470
+		members.addGetter(STRING_CHARACTERS);
453
 
471
 
454
 		members.addConstructor(STRING_CONSTRUCTOR_CHARACTERS);
472
 		members.addConstructor(STRING_CONSTRUCTOR_CHARACTERS);
455
 		members.addConstructor(STRING_CONSTRUCTOR_CHARACTER_RANGE);
473
 		members.addConstructor(STRING_CONSTRUCTOR_CHARACTER_RANGE);

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

78
 		return cache;
78
 		return cache;
79
 	}
79
 	}
80
 	
80
 	
81
+	public boolean extendsOrImplements(ITypeID other) {
82
+		ITypeID superType = type.getSuperType();
83
+		if (superType != null) {
84
+			if (superType == other)
85
+				return true;
86
+			if (cache.get(superType).extendsOrImplements(other))
87
+				return true;
88
+		}
89
+		
90
+		for (TypeMember<ImplementationMember> implementation : implementations) {
91
+			if (implementation.member.type == other)
92
+				return true;
93
+			if (cache.get(implementation.member.type).extendsOrImplements(other))
94
+				return true;
95
+		}
96
+		
97
+		return false;
98
+	}
99
+	
81
 	public GlobalTypeRegistry getTypeRegistry() {
100
 	public GlobalTypeRegistry getTypeRegistry() {
82
 		return cache.getRegistry();
101
 		return cache.getRegistry();
83
 	}
102
 	}
84
 	
103
 	
85
 	public void copyMembersTo(CodePosition position, TypeMembers other, TypeMemberPriority priority) {
104
 	public void copyMembersTo(CodePosition position, TypeMembers other, TypeMemberPriority priority) {
86
 		other.casters.addAll(casters);
105
 		other.casters.addAll(casters);
106
+		other.iterators.addAll(iterators);
87
 		
107
 		
88
 		for (Map.Entry<String, EnumConstantMember> entry : enumMembers.entrySet())
108
 		for (Map.Entry<String, EnumConstantMember> entry : enumMembers.entrySet())
89
 			other.addEnumMember(entry.getValue(), priority);
109
 			other.addEnumMember(entry.getValue(), priority);
369
 		if (members.containsKey(name.name)) {
389
 		if (members.containsKey(name.name)) {
370
 			DefinitionMemberGroup group = members.get(name.name);
390
 			DefinitionMemberGroup group = members.get(name.name);
371
 			
391
 			
372
-			if (!name.arguments.isEmpty()) {
373
-				/* ... */
374
-			}
375
-			
376
 			if (group.isStatic)
392
 			if (group.isStatic)
377
-				return new PartialStaticMemberGroupExpression(position, type, group);
393
+				return new PartialStaticMemberGroupExpression(position, type, group, name.arguments);
378
 			else
394
 			else
379
-				return new PartialMemberGroupExpression(position, target, group, allowStatic);
395
+				return new PartialMemberGroupExpression(position, target, group, name.arguments, allowStatic);
380
 		}
396
 		}
381
 		
397
 		
382
 		return null;
398
 		return null;
384
 	
400
 	
385
 	public IPartialExpression getStaticMemberExpression(CodePosition position, GenericName name) {
401
 	public IPartialExpression getStaticMemberExpression(CodePosition position, GenericName name) {
386
 		if (members.containsKey(name.name))
402
 		if (members.containsKey(name.name))
387
-			return new PartialStaticMemberGroupExpression(position, type, members.get(name.name));
403
+			return new PartialStaticMemberGroupExpression(position, type, members.get(name.name), name.arguments);
388
 		if (innerTypes.containsKey(name.name))
404
 		if (innerTypes.containsKey(name.name))
389
 			return new PartialTypeExpression(position, innerTypes.get(name.name).instance(cache.getRegistry(), name.arguments));
405
 			return new PartialTypeExpression(position, innerTypes.get(name.name).instance(cache.getRegistry(), name.arguments));
390
 		
406
 		

+ 4
- 0
Constructor/libraries/collections/module.json View File

1
+{
2
+	"package": "collections",
3
+	"host": "universal"
4
+}

+ 9
- 0
Constructor/libraries/collections/src/HashSet.zs View File

1
+export class HashSet<T> {
2
+	public implements Set<T> {
3
+		add(value as T) as bool;
4
+		remove(value as T) as bool;
5
+		
6
+		in(value as T) as bool;
7
+		for(x as T);
8
+	}
9
+}

+ 43
- 0
Constructor/libraries/collections/src/LinkedList.zs View File

1
+export class LinkedList<T> {
2
+	var first as Node?;
3
+	var last as Node?;
4
+	
5
+	public get empty as bool
6
+		=> first == null;
7
+	
8
+	public add(value as T) as void {
9
+		if first == null {
10
+			first = last = new Node(value);
11
+		} else {
12
+			val node = new Node(value);
13
+			last.next = node;
14
+			node.prev = last;
15
+			last = node;
16
+		}
17
+	}
18
+	
19
+	public implements Queue<T> {
20
+		poll() as T?
21
+			=> first == null ? null : first.value;
22
+		
23
+		peek() as T {
24
+			if first == null
25
+				throw new NoSuchElementException("Cannot peek an empty queue");
26
+			
27
+			return first.value;
28
+		}
29
+		
30
+		offer(value as T) as void
31
+			=> add(value);
32
+	}
33
+	
34
+	private struct Node {
35
+		var next as Node?;
36
+		var prev as Node?;
37
+		val value as T;
38
+		
39
+		this(value as T) {
40
+			this.value = value;
41
+		}
42
+	}
43
+}

+ 5
- 0
Constructor/libraries/collections/src/NoSuchElementException.zs View File

1
+export class NoSuchElementException : Exception {
2
+	public this(message as string) {
3
+		super(message);
4
+	}
5
+}

+ 7
- 0
Constructor/libraries/collections/src/Queue.zs View File

1
+export interface Queue<T> {
2
+	get empty as bool;
3
+	
4
+	poll() as T;
5
+	peek() as T;
6
+	push(value as T) as void;
7
+}

+ 8
- 0
Constructor/libraries/collections/src/Set.zs View File

1
+export interface Set<T> {
2
+	add(value as T) as bool;
3
+	remove(value as T) as bool;
4
+	
5
+	in(value as T) as bool;
6
+	
7
+	for(x as T);
8
+}

+ 3
- 1
Constructor/libraries/stdlib/module.json View File

2
 	"package": "stdlib",
2
 	"package": "stdlib",
3
 	"host": "universal",
3
 	"host": "universal",
4
 	"globals": {
4
 	"globals": {
5
+		"Comparable": {"type": "Definition", "definition": "Comparable"},
5
 		"Exception": {"type": "Definition", "definition": "Exception"},
6
 		"Exception": {"type": "Definition", "definition": "Exception"},
6
 		"IllegalArgumentException": {"type": "Definition", "definition": "IllegalArgumentException"},
7
 		"IllegalArgumentException": {"type": "Definition", "definition": "IllegalArgumentException"},
7
-		"StringBuilder": {"type": "Definition", "definition": "StringBuilder"}
8
+		"StringBuilder": {"type": "Definition", "definition": "StringBuilder"},
9
+		"StringBuildable": {"type": "Definition", "definition": "StringBuildable"}
8
 	}
10
 	}
9
 }
11
 }

+ 3
- 0
Constructor/libraries/stdlib/src/Comparable.zs View File

1
+export interface Comparable<T> {
2
+	compareTo(other as T) as int;
3
+}

+ 0
- 0
Constructor/libraries/stdlib/src/IllegalOperationException.zs View File


+ 6
- 0
Constructor/libraries/stdlib/src/StringBuildable.zs View File

1
+export interface StringBuildable {
2
+	toString(output as StringBuilder) as void;
3
+	
4
+	as string
5
+		=> new StringBuilder() << this;
6
+}

+ 16
- 2
Constructor/libraries/stdlib/src/StringBuilder.zs View File

3
 	public extern this(capacity as int);
3
 	public extern this(capacity as int);
4
 	public extern this(value as string);
4
 	public extern this(value as string);
5
 	
5
 	
6
-	public extern +=(value as string);
7
-	public extern +=(value as char);
6
+	public extern <<(value as bool) as StringBuilder;
7
+	public extern <<(value as char) as StringBuilder;
8
+	public extern <<(value as byte) as StringBuilder;
9
+	public extern <<(value as sbyte) as StringBuilder;
10
+	public extern <<(value as short) as StringBuilder;
11
+	public extern <<(value as ushort) as StringBuilder;
12
+	public extern <<(value as int) as StringBuilder;
13
+	public extern <<(value as uint) as StringBuilder;
14
+	public extern <<(value as float) as StringBuilder;
15
+	public extern <<(value as double) as StringBuilder;
16
+	public extern <<(value as string) as StringBuilder;
17
+	
18
+	public <<(value as StringBuildable) as StringBuilder {
19
+		value.toString(this);
20
+		return this;
21
+	}
8
 	
22
 	
9
 	public extern implicit as string;
23
 	public extern implicit as string;
10
 }
24
 }

+ 6
- 11
Constructor/src/main/java/org/openzen/zenscript/constructor/Main.java View File

3
 import java.io.File;
3
 import java.io.File;
4
 import java.io.IOException;
4
 import java.io.IOException;
5
 import org.openzen.zenscript.constructor.module.DirectoryModuleLoader;
5
 import org.openzen.zenscript.constructor.module.DirectoryModuleLoader;
6
+import org.openzen.zenscript.constructor.module.ModuleReference;
6
 
7
 
7
 public class Main {
8
 public class Main {
8
     /**
9
     /**
17
 		}
18
 		}
18
 		
19
 		
19
 		File currentDirectory = new File(arguments.directory);
20
 		File currentDirectory = new File(arguments.directory);
20
-		File projectJson = new File(currentDirectory, "project.json");
21
-		if (!projectJson.exists()) {
22
-			System.out.println("Error: not a valid project (missing project.json)");
23
-			return;
24
-		}
25
-		
26
 		ModuleLoader moduleLoader = new ModuleLoader();
21
 		ModuleLoader moduleLoader = new ModuleLoader();
27
 		moduleLoader.register("stdlib", new DirectoryModuleLoader(moduleLoader, "stdlib", new File("libraries/stdlib"), true));
22
 		moduleLoader.register("stdlib", new DirectoryModuleLoader(moduleLoader, "stdlib", new File("libraries/stdlib"), true));
28
 		
23
 		
29
-		Project project = new Project(projectJson);
30
-		for (String moduleName : project.modules) {
31
-			moduleLoader.register(moduleName, new DirectoryModuleLoader(moduleLoader, moduleName, new File(currentDirectory, moduleName), false));
24
+		Project project = new Project(moduleLoader, currentDirectory);
25
+		for (ModuleReference module : project.modules) {
26
+			moduleLoader.register(module.getName(), module);
32
 		}
27
 		}
33
 		
28
 		
34
 		// TODO: compile targets
29
 		// TODO: compile targets
35
-		for (String moduleName : project.modules) {
36
-			moduleLoader.getModule(moduleName);
30
+		for (ModuleReference module : project.modules) {
31
+			moduleLoader.getModule(module.getName());
37
 		}
32
 		}
38
     }
33
     }
39
 	
34
 	

+ 30
- 5
Constructor/src/main/java/org/openzen/zenscript/constructor/Project.java View File

9
 import java.io.IOException;
9
 import java.io.IOException;
10
 import org.json.JSONArray;
10
 import org.json.JSONArray;
11
 import org.json.JSONObject;
11
 import org.json.JSONObject;
12
+import org.openzen.zenscript.constructor.module.DirectoryModuleLoader;
13
+import org.openzen.zenscript.constructor.module.ModuleReference;
12
 
14
 
13
 /**
15
 /**
14
  *
16
  *
15
  * @author Hoofdgebruiker
17
  * @author Hoofdgebruiker
16
  */
18
  */
17
 public class Project {
19
 public class Project {
18
-	public final String[] modules;
20
+	public final ModuleReference[] modules;
19
 	
21
 	
20
-	public Project(File projectFile) throws IOException {
22
+	public Project(ModuleLoader loader, File directory) throws IOException {
23
+		if (!directory.exists())
24
+			throw new ConstructorException("Project directory doesn't exist");
25
+		if (!directory.isDirectory())
26
+			throw new ConstructorException("Project directory isn't a directory");
27
+		
28
+		File projectFile = new File(directory, "project.json");
29
+		if (!projectFile.exists())
30
+			throw new ConstructorException("Missing project.json file in project directory");
31
+		
21
 		JSONObject json = JSONUtils.load(projectFile);
32
 		JSONObject json = JSONUtils.load(projectFile);
22
 		
33
 		
23
 		JSONArray jsonModules = json.getJSONArray("modules");
34
 		JSONArray jsonModules = json.getJSONArray("modules");
24
-		modules = new String[jsonModules.length()];
25
-		for (int i = 0; i < jsonModules.length(); i++)
26
-			modules[i] = jsonModules.getString(i);
35
+		modules = new ModuleReference[jsonModules.length()];
36
+		for (int i = 0; i < jsonModules.length(); i++) {
37
+			Object module = jsonModules.get(i);
38
+			if (module instanceof String) {
39
+				modules[i] = new DirectoryModuleLoader(loader, module.toString(), new File(directory, module.toString()), false);
40
+			} else if (module instanceof JSONObject) {
41
+				JSONObject jsonModule = (JSONObject) module;
42
+				String name = jsonModule.getString("name");
43
+				switch (jsonModule.getString("type")) {
44
+					case "directory":
45
+						modules[i] = new DirectoryModuleLoader(loader, name, new File(directory, jsonModule.getString("directory")), false);
46
+						break;
47
+					default:
48
+						throw new ConstructorException("Invalid module type: " + jsonModule.getString("type"));
49
+				}
50
+			}
51
+		}
27
 	}
52
 	}
28
 }
53
 }

+ 5
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java View File

35
 		this.directory = directory;
35
 		this.directory = directory;
36
 		this.isStdlib = isStdlib;
36
 		this.isStdlib = isStdlib;
37
 	}
37
 	}
38
+	
39
+	@Override
40
+	public String getName() {
41
+		return moduleName;
42
+	}
38
 
43
 
39
 	@Override
44
 	@Override
40
 	public SemanticModule load() {
45
 	public SemanticModule load() {

+ 2
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java View File

10
  * @author Hoofdgebruiker
10
  * @author Hoofdgebruiker
11
  */
11
  */
12
 public interface ModuleReference {
12
 public interface ModuleReference {
13
+	public String getName();
14
+	
13
 	public SemanticModule load();
15
 	public SemanticModule load();
14
 }
16
 }

+ 11
- 8
Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.linker;
6
 package org.openzen.zenscript.linker;
7
 
7
 
8
-import java.util.ArrayList;
9
 import java.util.HashMap;
8
 import java.util.HashMap;
10
 import java.util.List;
9
 import java.util.List;
11
 import java.util.Map;
10
 import java.util.Map;
43
 		this.outer = outer;
42
 		this.outer = outer;
44
 		this.definition = definition;
43
 		this.definition = definition;
45
 		
44
 		
46
-		List<ITypeID> genericParameterList = new ArrayList<>();
47
-		for (TypeParameter parameter : definition.genericParameters) {
48
-			genericParameterList.add(outer.getTypeRegistry().getGeneric(parameter));
49
-			genericParameters.put(parameter.name, parameter);
45
+		ITypeID[] genericParameterList = null;
46
+		if (definition.genericParameters != null) {
47
+			genericParameterList = new ITypeID[definition.genericParameters.length];
48
+			for (int i = 0; i < definition.genericParameters.length; i++) {
49
+				TypeParameter parameter = definition.genericParameters[i];
50
+				genericParameterList[i] = outer.getTypeRegistry().getGeneric(parameter);
51
+				genericParameters.put(parameter.name, parameter);
52
+			}
50
 		}
53
 		}
51
 		
54
 		
52
 		if (definition instanceof ExpansionDefinition) {
55
 		if (definition instanceof ExpansionDefinition) {
67
 	public IPartialExpression get(CodePosition position, GenericName name) {
70
 	public IPartialExpression get(CodePosition position, GenericName name) {
68
 		if (members.hasInnerType(name.name))
71
 		if (members.hasInnerType(name.name))
69
 			return new PartialTypeExpression(position, members.getInnerType(position, name));
72
 			return new PartialTypeExpression(position, members.getInnerType(position, name));
70
-		if (members.hasMember(name.name) && name.arguments.isEmpty())
73
+		if (members.hasMember(name.name) && !name.hasArguments())
71
 			return members.getMemberExpression(position, new ThisExpression(position, type), name, true);
74
 			return members.getMemberExpression(position, new ThisExpression(position, type), name, true);
72
-		if (genericParameters.containsKey(name.name) && name.arguments.isEmpty())
75
+		if (genericParameters.containsKey(name.name) && !name.hasArguments())
73
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(genericParameters.get(name.name)));
76
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(genericParameters.get(name.name)));
74
 		
77
 		
75
 		return outer.get(position, name);
78
 		return outer.get(position, name);
83
 				result = getTypeMembers(result).getInnerType(position, name.get(i));
86
 				result = getTypeMembers(result).getInnerType(position, name.get(i));
84
 			}
87
 			}
85
 			return result;
88
 			return result;
86
-		} else if (genericParameters.containsKey(name.get(0).name) && name.size() == 1 && name.get(0).arguments.isEmpty()) {
89
+		} else if (genericParameters.containsKey(name.get(0).name) && name.size() == 1 && !name.get(0).hasArguments()) {
87
 			return getTypeRegistry().getGeneric(genericParameters.get(name.get(0).name));
90
 			return getTypeRegistry().getGeneric(genericParameters.get(name.get(0).name));
88
 		}
91
 		}
89
 		
92
 		

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java View File

77
 		
77
 		
78
 		if (globalSymbols.containsKey(name.name)) {
78
 		if (globalSymbols.containsKey(name.name)) {
79
 			IPartialExpression resolution = globalSymbols.get(name.name).getExpression(position, globalRegistry, name.arguments);
79
 			IPartialExpression resolution = globalSymbols.get(name.name).getExpression(position, globalRegistry, name.arguments);
80
-			return new PartialGlobalExpression(position, name.name, resolution);
80
+			return new PartialGlobalExpression(position, name.name, resolution, name.arguments);
81
 		}
81
 		}
82
 		
82
 		
83
 		return rootPackage.getMember(position, globalRegistry, name);
83
 		return rootPackage.getMember(position, globalRegistry, name);
103
 			}
103
 			}
104
 			
104
 			
105
 			// TODO: take care of non-static inner classes in generic classes!
105
 			// TODO: take care of non-static inner classes in generic classes!
106
-			if (type != null && name.get(name.size() - 1).arguments.size() != type.definition.genericParameters.length)
106
+			if (type != null && name.get(name.size() - 1).getNumberOfArguments() != type.definition.getNumberOfGenericParameters())
107
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
107
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
108
 			
108
 			
109
 			if (type != null)
109
 			if (type != null)

+ 1
- 1
Linker/src/main/java/org/openzen/zenscript/linker/ForeachScope.java View File

39
 
39
 
40
 	@Override
40
 	@Override
41
 	public IPartialExpression get(CodePosition position, GenericName name) {
41
 	public IPartialExpression get(CodePosition position, GenericName name) {
42
-		if (name.arguments.isEmpty()) {
42
+		if (name.hasNoArguments()) {
43
 			for (VarStatement loopVariable : statement.loopVariables) {
43
 			for (VarStatement loopVariable : statement.loopVariables) {
44
 				if (loopVariable.name.equals(name.name))
44
 				if (loopVariable.name.equals(name.name))
45
 					return new GetLocalVariableExpression(position, loopVariable);
45
 					return new GetLocalVariableExpression(position, loopVariable);

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java View File

54
 		if (fromSuper != null)
54
 		if (fromSuper != null)
55
 			return fromSuper;
55
 			return fromSuper;
56
 		
56
 		
57
-		if (name.arguments.isEmpty()) {
57
+		if (name.hasNoArguments()) {
58
 			for (FunctionParameter parameter : header.parameters) {
58
 			for (FunctionParameter parameter : header.parameters) {
59
 				if (parameter.name.equals(name.name)) {
59
 				if (parameter.name.equals(name.name)) {
60
 					return new GetFunctionParameterExpression(position, parameter);
60
 					return new GetFunctionParameterExpression(position, parameter);
72
 
72
 
73
 	@Override
73
 	@Override
74
 	public ITypeID getType(CodePosition position, List<GenericName> name) {
74
 	public ITypeID getType(CodePosition position, List<GenericName> name) {
75
-		if (name.size() == 1 && name.get(0).arguments.isEmpty()) {
75
+		if (name.size() == 1 && name.get(0).hasNoArguments()) {
76
 			for (TypeParameter parameter : header.typeParameters) {
76
 			for (TypeParameter parameter : header.typeParameters) {
77
 				if (parameter.name.equals(name.get(0).name))
77
 				if (parameter.name.equals(name.get(0).name))
78
 					return getTypeRegistry().getGeneric(parameter);
78
 					return getTypeRegistry().getGeneric(parameter);

+ 5
- 4
Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java View File

31
 	public GenericFunctionScope(BaseScope outer, TypeParameter[] parameters) {
31
 	public GenericFunctionScope(BaseScope outer, TypeParameter[] parameters) {
32
 		this.outer = outer;
32
 		this.outer = outer;
33
 		
33
 		
34
-		for (TypeParameter parameter : parameters)
35
-			this.parameters.put(parameter.name, parameter);
34
+		if (parameters != null)
35
+			for (TypeParameter parameter : parameters)
36
+				this.parameters.put(parameter.name, parameter);
36
 	}
37
 	}
37
 	
38
 	
38
 	@Override
39
 	@Override
42
 
43
 
43
 	@Override
44
 	@Override
44
 	public IPartialExpression get(CodePosition position, GenericName name) {
45
 	public IPartialExpression get(CodePosition position, GenericName name) {
45
-		if (parameters.containsKey(name.name) && name.arguments.isEmpty())
46
+		if (parameters.containsKey(name.name) && name.hasNoArguments())
46
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name)));
47
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name)));
47
 		
48
 		
48
 		return outer.get(position, name);
49
 		return outer.get(position, name);
50
 
51
 
51
 	@Override
52
 	@Override
52
 	public ITypeID getType(CodePosition position, List<GenericName> name) {
53
 	public ITypeID getType(CodePosition position, List<GenericName> name) {
53
-		if (name.size() == 1 && parameters.containsKey(name.get(0).name) && name.get(0).arguments.isEmpty())
54
+		if (name.size() == 1 && parameters.containsKey(name.get(0).name) && name.get(0).hasNoArguments())
54
 			return getTypeRegistry().getGeneric(parameters.get(name.get(0).name));
55
 			return getTypeRegistry().getGeneric(parameters.get(name.get(0).name));
55
 		
56
 		
56
 		return outer.getType(position, name);
57
 		return outer.getType(position, name);

+ 1
- 1
Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java View File

53
 	public IPartialExpression get(CodePosition position, GenericName name) {
53
 	public IPartialExpression get(CodePosition position, GenericName name) {
54
 		if (members.hasInnerType(name.name))
54
 		if (members.hasInnerType(name.name))
55
 			return new PartialTypeExpression(position, members.getInnerType(position, name));
55
 			return new PartialTypeExpression(position, members.getInnerType(position, name));
56
-		if (members.hasMember(name.name) && name.arguments.isEmpty())
56
+		if (members.hasMember(name.name))
57
 			return members.getMemberExpression(position, new ThisExpression(position, outer.getThisType()), name, true);
57
 			return members.getMemberExpression(position, new ThisExpression(position, outer.getThisType()), name, true);
58
 		
58
 		
59
 		return outer.get(position, name);
59
 		return outer.get(position, name);

+ 1
- 1
Linker/src/main/java/org/openzen/zenscript/linker/LambdaScope.java View File

43
 	public IPartialExpression get(CodePosition position, GenericName name) {
43
 	public IPartialExpression get(CodePosition position, GenericName name) {
44
 		IPartialExpression outer = this.outer.get(position, name);
44
 		IPartialExpression outer = this.outer.get(position, name);
45
 		if (outer == null) {
45
 		if (outer == null) {
46
-			if (name.arguments.isEmpty()) {
46
+			if (name.hasNoArguments()) {
47
 				for (FunctionParameter parameter : header.parameters) {
47
 				for (FunctionParameter parameter : header.parameters) {
48
 					if (parameter.name.equals(name.name))
48
 					if (parameter.name.equals(name.name))
49
 						return new GetFunctionParameterExpression(position, parameter);
49
 						return new GetFunctionParameterExpression(position, parameter);

+ 1
- 1
Linker/src/main/java/org/openzen/zenscript/linker/StatementScope.java View File

26
 	
26
 	
27
 	@Override
27
 	@Override
28
 	public IPartialExpression get(CodePosition position, GenericName name) {
28
 	public IPartialExpression get(CodePosition position, GenericName name) {
29
-		if (variables.containsKey(name.name) && name.arguments.isEmpty())
29
+		if (variables.containsKey(name.name) && name.hasNoArguments())
30
 			return new GetLocalVariableExpression(position, variables.get(name.name));
30
 			return new GetLocalVariableExpression(position, variables.get(name.name));
31
 		
31
 		
32
 		return null;
32
 		return null;

+ 2
- 3
Linker/src/main/java/org/openzen/zenscript/linker/symbol/ISymbol.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.linker.symbol;
6
 package org.openzen.zenscript.linker.symbol;
7
 
7
 
8
-import java.util.List;
9
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
8
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
10
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
9
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
  * @author Hoofdgebruiker
15
  * @author Hoofdgebruiker
17
  */
16
  */
18
 public interface ISymbol {
17
 public interface ISymbol {
19
-	public IPartialExpression getExpression(CodePosition position, GlobalTypeRegistry types, List<ITypeID> typeArguments);
18
+	public IPartialExpression getExpression(CodePosition position, GlobalTypeRegistry types, ITypeID[] typeArguments);
20
 	
19
 	
21
-	public ITypeID getType(CodePosition position, GlobalTypeRegistry types, List<ITypeID> typeArguments);
20
+	public ITypeID getType(CodePosition position, GlobalTypeRegistry types, ITypeID[] typeArguments);
22
 }
21
 }

+ 2
- 3
Linker/src/main/java/org/openzen/zenscript/linker/symbol/TypeSymbol.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.linker.symbol;
6
 package org.openzen.zenscript.linker.symbol;
7
 
7
 
8
-import java.util.List;
9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
9
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
10
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
25
 	}
24
 	}
26
 	
25
 	
27
 	@Override
26
 	@Override
28
-	public IPartialExpression getExpression(CodePosition position, GlobalTypeRegistry types, List<ITypeID> typeArguments) {
27
+	public IPartialExpression getExpression(CodePosition position, GlobalTypeRegistry types, ITypeID[] typeArguments) {
29
 		return new PartialTypeExpression(position, types.getForDefinition(definition, typeArguments));
28
 		return new PartialTypeExpression(position, types.getForDefinition(definition, typeArguments));
30
 	}
29
 	}
31
 
30
 
32
 	@Override
31
 	@Override
33
-	public ITypeID getType(CodePosition position, GlobalTypeRegistry types, List<ITypeID> typeArguments) {
32
+	public ITypeID getType(CodePosition position, GlobalTypeRegistry types, ITypeID[] typeArguments) {
34
 		return types.getForDefinition(definition, typeArguments);
33
 		return types.getForDefinition(definition, typeArguments);
35
 	}
34
 	}
36
 }
35
 }

+ 2
- 3
Parser/src/main/java/org/openzen/zenscript/lexer/CompiledDFA.java View File

4
 import gnu.trove.iterator.TIntIterator;
4
 import gnu.trove.iterator.TIntIterator;
5
 import gnu.trove.map.hash.TIntIntHashMap;
5
 import gnu.trove.map.hash.TIntIntHashMap;
6
 import java.util.ArrayList;
6
 import java.util.ArrayList;
7
-import java.util.Arrays;
8
 import java.util.List;
7
 import java.util.List;
9
 
8
 
10
 /**
9
 /**
21
 {
20
 {
22
 	public static <T extends TokenType & Comparable<T>> CompiledDFA<T> createLexerDFA(T[] tokenTypes, Class<T> tokenClass)
21
 	public static <T extends TokenType & Comparable<T>> CompiledDFA<T> createLexerDFA(T[] tokenTypes, Class<T> tokenClass)
23
 	{
22
 	{
24
-		List<T> tokens = new ArrayList<T>();
25
-		List<String> regexps = new ArrayList<String>();
23
+		List<T> tokens = new ArrayList<>();
24
+		List<String> regexps = new ArrayList<>();
26
 		for (T tokenType : tokenTypes) {
25
 		for (T tokenType : tokenTypes) {
27
 			if (tokenType.getRegexp() != null) {
26
 			if (tokenType.getRegexp() != null) {
28
 				tokens.add(tokenType);
27
 				tokens.add(tokenType);

+ 9
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/TokenStream.java View File

170
 	{
170
 	{
171
         tokenMemoryCurrent = marks.pop();
171
         tokenMemoryCurrent = marks.pop();
172
     }
172
     }
173
+	
174
+	/**
175
+	 * Replaces the current token with another one. Used to split composite tokens.
176
+	 * 
177
+	 * @param other 
178
+	 */
179
+	public void replace(TT other) {
180
+		next = createToken(next.getPosition(), next.getWhitespaceBefore(), next.getContent(), other);
181
+	}
173
 
182
 
174
     // ===============================
183
     // ===============================
175
     // === Iterator implementation ===
184
     // === Iterator implementation ===

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenStream.java View File

58
 		KEYWORDS.put("any", K_ANY);
58
 		KEYWORDS.put("any", K_ANY);
59
 		KEYWORDS.put("bool", K_BOOL);
59
 		KEYWORDS.put("bool", K_BOOL);
60
 		KEYWORDS.put("byte", K_BYTE);
60
 		KEYWORDS.put("byte", K_BYTE);
61
-		KEYWORDS.put("ubyte", K_UBYTE);
61
+		KEYWORDS.put("sbyte", K_SBYTE);
62
 		KEYWORDS.put("short", K_SHORT);
62
 		KEYWORDS.put("short", K_SHORT);
63
 		KEYWORDS.put("ushort", K_USHORT);
63
 		KEYWORDS.put("ushort", K_USHORT);
64
 		KEYWORDS.put("int", K_INT);
64
 		KEYWORDS.put("int", K_INT);

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java View File

108
 	K_ANY,
108
 	K_ANY,
109
 	K_BOOL,
109
 	K_BOOL,
110
 	K_BYTE,
110
 	K_BYTE,
111
-	K_UBYTE,
111
+	K_SBYTE,
112
 	K_SHORT,
112
 	K_SHORT,
113
 	K_USHORT,
113
 	K_USHORT,
114
 	K_INT,
114
 	K_INT,

+ 10
- 9
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedGenericParameter.java View File

35
 	}
35
 	}
36
 	
36
 	
37
 	public static List<ParsedGenericParameter> parseAll(ZSTokenStream tokens) {
37
 	public static List<ParsedGenericParameter> parseAll(ZSTokenStream tokens) {
38
+		if (tokens.optional(ZSTokenType.T_LESS) == null)
39
+			return null;
40
+		
38
 		List<ParsedGenericParameter> genericParameters = new ArrayList<>();
41
 		List<ParsedGenericParameter> genericParameters = new ArrayList<>();
39
-		if (tokens.optional(ZSTokenType.T_LESS) != null) {
40
-			do {
41
-				genericParameters.add(ParsedGenericParameter.parse(tokens));
42
-			} while (tokens.optional(ZSTokenType.T_COMMA) != null);
43
-			tokens.required(ZSTokenType.T_GREATER, "> expected");
44
-		}
42
+		do {
43
+			genericParameters.add(ParsedGenericParameter.parse(tokens));
44
+		} while (tokens.optional(ZSTokenType.T_COMMA) != null);
45
+		tokens.required(ZSTokenType.T_GREATER, "> expected");
45
 		return genericParameters;
46
 		return genericParameters;
46
 	}
47
 	}
47
 	
48
 	
48
 	public static void compile(BaseScope scope, TypeParameter[] compiled, List<ParsedGenericParameter> parameters) {
49
 	public static void compile(BaseScope scope, TypeParameter[] compiled, List<ParsedGenericParameter> parameters) {
49
-		if (compiled.length == 0)
50
+		if (compiled == null)
50
 			return;
51
 			return;
51
 		
52
 		
52
 		GenericFunctionScope innerScope = new GenericFunctionScope(scope, compiled);
53
 		GenericFunctionScope innerScope = new GenericFunctionScope(scope, compiled);
58
 	
59
 	
59
 	private static TypeParameter[] NO_TYPE_PARAMETERS = new TypeParameter[0];
60
 	private static TypeParameter[] NO_TYPE_PARAMETERS = new TypeParameter[0];
60
 	public static TypeParameter[] getCompiled(List<ParsedGenericParameter> parameters) {
61
 	public static TypeParameter[] getCompiled(List<ParsedGenericParameter> parameters) {
61
-		if (parameters.isEmpty())
62
-			return NO_TYPE_PARAMETERS;
62
+		if (parameters == null)
63
+			return null;
63
 		
64
 		
64
 		TypeParameter[] result = new TypeParameter[parameters.size()];
65
 		TypeParameter[] result = new TypeParameter[parameters.size()];
65
 		for (int i = 0; i < result.length; i++)
66
 		for (int i = 0; i < result.length; i++)

+ 1
- 0
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java View File

55
 		this.superInterfaces = superInterfaces;
55
 		this.superInterfaces = superInterfaces;
56
 		
56
 		
57
 		compiled = new InterfaceDefinition(position, pkg, name, modifiers, outerDefinition);
57
 		compiled = new InterfaceDefinition(position, pkg, name, modifiers, outerDefinition);
58
+		compiled.setTypeParameters(ParsedGenericParameter.getCompiled(genericParameters));
58
 	}
59
 	}
59
 
60
 
60
 	@Override
61
 	@Override

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

53
 	public CallArguments compileCall(
53
 	public CallArguments compileCall(
54
 			CodePosition position, 
54
 			CodePosition position, 
55
 			ExpressionScope scope,
55
 			ExpressionScope scope,
56
+			ITypeID[] genericParameters,
56
 			DefinitionMemberGroup member)
57
 			DefinitionMemberGroup member)
57
 	{
58
 	{
58
 		List<FunctionHeader> possibleHeaders = member.getMethodMembers().stream()
59
 		List<FunctionHeader> possibleHeaders = member.getMethodMembers().stream()
59
 				.map(method -> method.member.getHeader())
60
 				.map(method -> method.member.getHeader())
60
 				.collect(Collectors.toList());
61
 				.collect(Collectors.toList());
61
-		return compileCall(position, scope, possibleHeaders);
62
+		return compileCall(position, scope, genericParameters, possibleHeaders);
62
 	}
63
 	}
63
 	
64
 	
64
 	public CallArguments compileCall(
65
 	public CallArguments compileCall(
65
 			CodePosition position,
66
 			CodePosition position,
66
 			ExpressionScope scope,
67
 			ExpressionScope scope,
68
+			ITypeID[] genericParameters,
67
 			List<FunctionHeader> candidateFunctions)
69
 			List<FunctionHeader> candidateFunctions)
68
 	{
70
 	{
69
 		List<FunctionHeader> candidates = new ArrayList<>();
71
 		List<FunctionHeader> candidates = new ArrayList<>();
70
 		for (FunctionHeader header : candidateFunctions) {
72
 		for (FunctionHeader header : candidateFunctions) {
71
-			if (isCompatibleWith(scope, header))
73
+			if (isCompatibleWith(scope, header, genericParameters))
72
 				candidates.add(header);
74
 				candidates.add(header);
73
 		}
75
 		}
74
 		
76
 		
110
 			cArguments[i] = cArgument.eval();
112
 			cArguments[i] = cArgument.eval();
111
 		}
113
 		}
112
 		
114
 		
113
-		ITypeID[] typeParameters = CallArguments.NO_TYPE_ARGUMENTS;
114
-		for (FunctionHeader candidate : candidates) {
115
-			if (candidate.typeParameters.length > 0) {
116
-				typeParameters = new ITypeID[candidate.typeParameters.length];
117
-				for (int i = 0; i < typeParameters.length; i++) {
118
-					if (innerScope.genericInferenceMap.get(candidate.typeParameters[i]) == null)
119
-						throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer type parameter " + candidate.typeParameters[i].name);
120
-					else
121
-						typeParameters[i] = innerScope.genericInferenceMap.get(candidate.typeParameters[i]);
122
-				}
115
+		ITypeID[] typeParameters = genericParameters;
116
+		if (typeParameters == null) {
117
+			for (FunctionHeader candidate : candidates) {
118
+				if (candidate.typeParameters.length > 0) {
119
+					typeParameters = new ITypeID[candidate.typeParameters.length];
120
+					for (int i = 0; i < typeParameters.length; i++) {
121
+						if (innerScope.genericInferenceMap.get(candidate.typeParameters[i]) == null)
122
+							throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer type parameter " + candidate.typeParameters[i].name);
123
+						else
124
+							typeParameters[i] = innerScope.genericInferenceMap.get(candidate.typeParameters[i]);
125
+					}
123
 
126
 
124
-				break;
127
+					break;
128
+				}
125
 			}
129
 			}
126
 		}
130
 		}
127
 		
131
 		
137
 		return new CallArguments(new ITypeID[0], cArguments);
141
 		return new CallArguments(new ITypeID[0], cArguments);
138
 	}
142
 	}
139
 	
143
 	
140
-	private boolean isCompatibleWith(BaseScope scope, FunctionHeader header) {
144
+	private boolean isCompatibleWith(BaseScope scope, FunctionHeader header, ITypeID[] typeParameters) {
141
 		if (arguments.size() != header.parameters.length)
145
 		if (arguments.size() != header.parameters.length)
142
 			return false;
146
 			return false;
143
 		
147
 		
144
 		for (int i = 0; i < arguments.size(); i++) {
148
 		for (int i = 0; i < arguments.size(); i++) {
145
-			if (header.parameters[i].type.hasInferenceBlockingTypeParameters(header.typeParameters))
149
+			if (typeParameters == null && header.parameters[i].type.hasInferenceBlockingTypeParameters(header.typeParameters))
146
 				return false;
150
 				return false;
147
 			
151
 			
148
 			if (!arguments.get(i).isCompatibleWith(scope, header.parameters[i].type))
152
 			if (!arguments.get(i).isCompatibleWith(scope, header.parameters[i].type))

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java View File

47
 				throw new CompileException(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Class has no superclass");
47
 				throw new CompileException(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Class has no superclass");
48
 			
48
 			
49
 			DefinitionMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
49
 			DefinitionMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
50
-			CallArguments callArguments = arguments.compileCall(position, scope, memberGroup);
50
+			CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
51
 			ICallableMember member = memberGroup.selectMethod(position, scope, callArguments, true, true);
51
 			ICallableMember member = memberGroup.selectMethod(position, scope, callArguments, true, true);
52
 			if (!(member instanceof ConstructorMember))
52
 			if (!(member instanceof ConstructorMember))
53
 				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
53
 				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
58
 			ITypeID targetType = scope.getThisType();
58
 			ITypeID targetType = scope.getThisType();
59
 			
59
 			
60
 			DefinitionMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
60
 			DefinitionMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
61
-			CallArguments callArguments = arguments.compileCall(position, scope, memberGroup);
61
+			CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
62
 			ICallableMember member = memberGroup.selectMethod(position, scope, callArguments, true, true);
62
 			ICallableMember member = memberGroup.selectMethod(position, scope, callArguments, true, true);
63
 			if (!(member instanceof ConstructorMember))
63
 			if (!(member instanceof ConstructorMember))
64
 				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
64
 				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
67
 		}
67
 		}
68
 
68
 
69
 		List<FunctionHeader> headers = cReceiver.getPossibleFunctionHeaders(scope, scope.hints, arguments.arguments.size());
69
 		List<FunctionHeader> headers = cReceiver.getPossibleFunctionHeaders(scope, scope.hints, arguments.arguments.size());
70
-		CallArguments callArguments = arguments.compileCall(position, scope, headers);
70
+		CallArguments callArguments = arguments.compileCall(position, scope, cReceiver.getGenericCallTypes(), headers);
71
 		return cReceiver.call(position, scope, scope.hints, callArguments);
71
 		return cReceiver.call(position, scope, scope.hints, callArguments);
72
 	}
72
 	}
73
 
73
 

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

70
 			// perform type parameter inference
70
 			// perform type parameter inference
71
 			ITypeID returnType = statements.getReturnType();
71
 			ITypeID returnType = statements.getReturnType();
72
 			Map<TypeParameter, ITypeID> inferredTypes = new HashMap<>();
72
 			Map<TypeParameter, ITypeID> inferredTypes = new HashMap<>();
73
-			if (!genericHeader.returnType.inferTypeParameters(returnType, inferredTypes))
73
+			if (!genericHeader.returnType.inferTypeParameters(scope.getMemberCache(), returnType, inferredTypes))
74
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
74
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
75
 			
75
 			
76
 			for (Map.Entry<TypeParameter, ITypeID> type : inferredTypes.entrySet()) {
76
 			for (Map.Entry<TypeParameter, ITypeID> type : inferredTypes.entrySet()) {

+ 5
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIndex.java View File

107
 		private Expression getLength(CodePosition position) {
107
 		private Expression getLength(CodePosition position) {
108
 			return target.getMember(position, scope, scope.hints, new GenericName("length")).eval();
108
 			return target.getMember(position, scope, scope.hints, new GenericName("length")).eval();
109
 		}
109
 		}
110
+
111
+		@Override
112
+		public ITypeID[] getGenericCallTypes() {
113
+			return null;
114
+		}
110
 	}
115
 	}
111
 }
116
 }

+ 6
- 11
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java View File

6
 
6
 
7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
-import java.util.ArrayList;
10
-import java.util.Collections;
11
 import java.util.List;
9
 import java.util.List;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
10
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.type.GenericName;
11
 import org.openzen.zenscript.codemodel.type.GenericName;
37
 
35
 
38
 	@Override
36
 	@Override
39
 	public IPartialExpression compile(ExpressionScope scope) {
37
 	public IPartialExpression compile(ExpressionScope scope) {
40
-		List<ITypeID> genericArguments = Collections.emptyList();
41
-		if (!genericParameters.isEmpty()) {
42
-			genericArguments = new ArrayList<>();
43
-			for (IParsedType type : this.genericParameters) {
44
-				genericArguments.add(type.compile(scope));
45
-			}
46
-		}
47
-		
48
 		IPartialExpression cValue = value.compile(scope.withoutHints());
38
 		IPartialExpression cValue = value.compile(scope.withoutHints());
49
-		IPartialExpression member = cValue.getMember(position, scope, scope.hints, new GenericName(this.member, genericArguments));
39
+		ITypeID[] typeParameters = IParsedType.compileList(genericParameters, scope);
40
+		IPartialExpression member = cValue.getMember(
41
+				position,
42
+				scope,
43
+				scope.hints,
44
+				new GenericName(this.member, typeParameters));
50
 		if (member == null)
45
 		if (member == null)
51
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member not found: " + this.member);
46
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member not found: " + this.member);
52
 		return member;
47
 		return member;

+ 8
- 7
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java View File

6
 
6
 
7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
-import java.util.ArrayList;
10
 import java.util.Collections;
9
 import java.util.Collections;
11
 import java.util.List;
10
 import java.util.List;
12
 import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
11
 import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
42
 
41
 
43
 	@Override
42
 	@Override
44
 	public IPartialExpression compile(ExpressionScope scope) {
43
 	public IPartialExpression compile(ExpressionScope scope) {
45
-		List<ITypeID> genericParameters = Collections.emptyList();
46
-		if (!this.genericParameters.isEmpty()) {
47
-			genericParameters = new ArrayList<>();
48
-			for (IParsedType genericType : this.genericParameters)
49
-				genericParameters.add(genericType.compile(scope));
44
+		ITypeID[] genericArguments = null;
45
+		if (genericParameters != null) {
46
+			genericArguments = new ITypeID[genericParameters.size()];
47
+			for (int i = 0; i < genericParameters.size(); i++) {
48
+				genericArguments[i] = genericParameters.get(i).compile(scope);
49
+			}
50
 		}
50
 		}
51
-		IPartialExpression result = scope.get(position, new GenericName(name, genericParameters));
51
+		
52
+		IPartialExpression result = scope.get(position, new GenericName(name, genericArguments));
52
 		if (result == null) {
53
 		if (result == null) {
53
 			for (ITypeID hint : scope.hints) {
54
 			for (ITypeID hint : scope.hints) {
54
 				EnumConstantMember member = scope.getTypeMembers(hint).getEnumMember(name);
55
 				EnumConstantMember member = scope.getTypeMembers(hint).getEnumMember(name);

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java View File

50
 	public static NewExpression compile(CodePosition position, ITypeID type, ParsedCallArguments arguments, ExpressionScope scope) {
50
 	public static NewExpression compile(CodePosition position, ITypeID type, ParsedCallArguments arguments, ExpressionScope scope) {
51
 		DefinitionMemberGroup constructors = scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CONSTRUCTOR);
51
 		DefinitionMemberGroup constructors = scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CONSTRUCTOR);
52
 		List<ITypeID>[] predictedTypes = constructors.predictCallTypes(scope, scope.hints, arguments.arguments.size());
52
 		List<ITypeID>[] predictedTypes = constructors.predictCallTypes(scope, scope.hints, arguments.arguments.size());
53
-		CallArguments compiledArguments = arguments.compileCall(position, scope, constructors);
53
+		CallArguments compiledArguments = arguments.compileCall(position, scope, null, constructors);
54
 		ICallableMember member = constructors.selectMethod(position, scope, compiledArguments, true, true);
54
 		ICallableMember member = constructors.selectMethod(position, scope, compiledArguments, true, true);
55
 		if (member == null)
55
 		if (member == null)
56
 			throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "No matching constructor found");
56
 			throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "No matching constructor found");

+ 13
- 2
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java View File

16
 import org.openzen.zenscript.codemodel.Modifiers;
16
 import org.openzen.zenscript.codemodel.Modifiers;
17
 import org.openzen.zenscript.codemodel.OperatorType;
17
 import org.openzen.zenscript.codemodel.OperatorType;
18
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
18
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
19
-import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
20
 import org.openzen.zenscript.lexer.ZSToken;
19
 import org.openzen.zenscript.lexer.ZSToken;
21
 import org.openzen.zenscript.lexer.ZSTokenStream;
20
 import org.openzen.zenscript.lexer.ZSTokenStream;
22
 import org.openzen.zenscript.lexer.ZSTokenType;
21
 import org.openzen.zenscript.lexer.ZSTokenType;
205
 			case T_XORASSIGN:
204
 			case T_XORASSIGN:
206
 			case T_INCREMENT:
205
 			case T_INCREMENT:
207
 			case T_DECREMENT:
206
 			case T_DECREMENT:
208
-			case T_DOT2: {
207
+			case T_DOT2:
208
+			case T_SHL:
209
+			case T_SHR:
210
+			case T_USHR:
211
+			case T_SHLASSIGN:
212
+			case T_SHRASSIGN:
213
+			case T_USHRASSIGN: {
209
 				ZSToken token = tokens.next();
214
 				ZSToken token = tokens.next();
210
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
215
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
211
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
216
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
274
 			case T_INCREMENT: return OperatorType.INCREMENT;
279
 			case T_INCREMENT: return OperatorType.INCREMENT;
275
 			case T_DECREMENT: return OperatorType.DECREMENT;
280
 			case T_DECREMENT: return OperatorType.DECREMENT;
276
 			case T_DOT2: return OperatorType.RANGE;
281
 			case T_DOT2: return OperatorType.RANGE;
282
+			case T_SHL: return OperatorType.SHL;
283
+			case T_SHR: return OperatorType.SHR;
284
+			case T_USHR: return OperatorType.USHR;
285
+			case T_SHLASSIGN: return OperatorType.SHLASSIGN;
286
+			case T_SHRASSIGN: return OperatorType.SHRASSIGN;
287
+			case T_USHRASSIGN: return OperatorType.USHRASSIGN;
277
 			default:
288
 			default:
278
 				throw new AssertionError("Missing switch case in getOperator");
289
 				throw new AssertionError("Missing switch case in getOperator");
279
 		}
290
 		}

+ 3
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementForeach.java View File

7
 import org.openzen.zenscript.codemodel.statement.Statement;
7
 import org.openzen.zenscript.codemodel.statement.Statement;
8
 import org.openzen.zenscript.codemodel.statement.VarStatement;
8
 import org.openzen.zenscript.codemodel.statement.VarStatement;
9
 import org.openzen.zenscript.codemodel.type.ITypeID;
9
 import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
10
 import org.openzen.zenscript.linker.ExpressionScope;
11
 import org.openzen.zenscript.linker.ExpressionScope;
11
 import org.openzen.zenscript.linker.ForeachScope;
12
 import org.openzen.zenscript.linker.ForeachScope;
12
 import org.openzen.zenscript.linker.StatementScope;
13
 import org.openzen.zenscript.linker.StatementScope;
32
 	public Statement compile(StatementScope scope) {
33
 	public Statement compile(StatementScope scope) {
33
 		Expression list = this.list.compile(new ExpressionScope(scope)).eval();
34
 		Expression list = this.list.compile(new ExpressionScope(scope)).eval();
34
 		
35
 		
35
-		IIteratorMember iterator = scope.getTypeMembers(list.type).getIterator(varnames.length);
36
+		TypeMembers members = scope.getTypeMembers(list.type);
37
+		IIteratorMember iterator = members.getIterator(varnames.length);
36
 		if (iterator == null)
38
 		if (iterator == null)
37
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_ITERATOR, list.type + " doesn't have an iterator with " + varnames.length + " variables");
39
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_ITERATOR, list.type + " doesn't have an iterator with " + varnames.length + " variables");
38
 		
40
 		

+ 28
- 11
Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java View File

12
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
12
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
13
 import org.openzen.zenscript.lexer.ZSTokenStream;
13
 import org.openzen.zenscript.lexer.ZSTokenStream;
14
 import org.openzen.zenscript.lexer.ZSTokenType;
14
 import org.openzen.zenscript.lexer.ZSTokenType;
15
-import static org.openzen.zenscript.lexer.ZSTokenType.T_COMMA;
16
-import static org.openzen.zenscript.lexer.ZSTokenType.T_GREATER;
17
-import static org.openzen.zenscript.lexer.ZSTokenType.T_LESS;
15
+import static org.openzen.zenscript.lexer.ZSTokenType.*;
18
 import org.openzen.zenscript.linker.BaseScope;
16
 import org.openzen.zenscript.linker.BaseScope;
19
 import org.openzen.zenscript.parser.ParseException;
17
 import org.openzen.zenscript.parser.ParseException;
20
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
18
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
64
 				break;
62
 				break;
65
 			case K_BYTE:
63
 			case K_BYTE:
66
 				tokens.next();
64
 				tokens.next();
67
-				result = ParsedTypeBasic.SBYTE;
65
+				result = ParsedTypeBasic.BYTE;
68
 				break;
66
 				break;
69
-			case K_UBYTE:
67
+			case K_SBYTE:
70
 				tokens.next();
68
 				tokens.next();
71
-				result = ParsedTypeBasic.BYTE;
69
+				result = ParsedTypeBasic.SBYTE;
72
 				break;
70
 				break;
73
 			case K_SHORT:
71
 			case K_SHORT:
74
 				tokens.next();
72
 				tokens.next();
175
 	
173
 	
176
 	public static List<IParsedType> parseGenericParameters(ZSTokenStream tokens) {
174
 	public static List<IParsedType> parseGenericParameters(ZSTokenStream tokens) {
177
 		if (!tokens.isNext(T_LESS))
175
 		if (!tokens.isNext(T_LESS))
178
-			return Collections.emptyList();
176
+			return null;
179
 		
177
 		
180
 		tokens.pushMark();
178
 		tokens.pushMark();
181
 		tokens.next();
179
 		tokens.next();
190
 			genericParameters.add(type);
188
 			genericParameters.add(type);
191
 		} while (tokens.optional(T_COMMA) != null);
189
 		} while (tokens.optional(T_COMMA) != null);
192
 		
190
 		
193
-		if (tokens.optional(T_GREATER) == null) {
191
+		if (tokens.isNext(T_SHR)) {
192
+			tokens.replace(T_GREATER);
193
+		} else if (tokens.isNext(T_USHR)) {
194
+			tokens.replace(T_SHR);
195
+		} else if (tokens.isNext(T_SHRASSIGN)) {
196
+			tokens.replace(T_GREATEREQ);
197
+		} else if (tokens.isNext(T_USHRASSIGN)) {
198
+			tokens.replace(T_SHRASSIGN);
199
+		} else if (tokens.optional(T_GREATER) == null) {
194
 			tokens.reset();
200
 			tokens.reset();
195
 			return Collections.emptyList();
201
 			return Collections.emptyList();
196
-		} else {
197
-			tokens.popMark();
198
-			return genericParameters;
199
 		}
202
 		}
203
+		
204
+		tokens.popMark();
205
+		return genericParameters;
206
+	}
207
+	
208
+	public static ITypeID[] compileList(List<IParsedType> typeParameters, BaseScope scope) {
209
+		ITypeID[] result = null;
210
+		if (typeParameters != null) {
211
+			result = new ITypeID[typeParameters.size()];
212
+			for (int i = 0; i < typeParameters.size(); i++) {
213
+				result[i] = typeParameters.get(i).compile(scope);
214
+			}
215
+		}
216
+		return result;
200
 	}
217
 	}
201
 	
218
 	
202
 	public IParsedType withOptional();
219
 	public IParsedType withOptional();

+ 2
- 11
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedNamedType.java View File

6
 package org.openzen.zenscript.parser.type;
6
 package org.openzen.zenscript.parser.type;
7
 
7
 
8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
-import java.util.Collections;
10
 import java.util.List;
9
 import java.util.List;
11
 import org.openzen.zenscript.codemodel.type.GenericName;
10
 import org.openzen.zenscript.codemodel.type.GenericName;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
94
 		}
93
 		}
95
 		
94
 		
96
 		private GenericName compile(BaseScope scope) {
95
 		private GenericName compile(BaseScope scope) {
97
-			if (typeArguments.isEmpty()) {
98
-				return new GenericName(name, Collections.emptyList());
99
-			} else {
100
-				List<ITypeID> genericTypes = new ArrayList<>();
101
-				for (IParsedType type : typeArguments)
102
-					genericTypes.add(type.compile(scope));
103
-				
104
-				return new GenericName(name, genericTypes);
105
-			}
96
+			return new GenericName(name, IParsedType.compileList(typeArguments, scope));
106
 		}
97
 		}
107
 		
98
 		
108
 		@Override
99
 		@Override
109
 		public String toString() {
100
 		public String toString() {
110
 			StringBuilder result = new StringBuilder(name);
101
 			StringBuilder result = new StringBuilder(name);
111
-			if (!typeArguments.isEmpty()) {
102
+			if (typeArguments != null) {
112
 				result.append("<");
103
 				result.append("<");
113
 				for (int i = 0; i < typeArguments.size(); i++) {
104
 				for (int i = 0; i < typeArguments.size(); i++) {
114
 					if (i > 0)
105
 					if (i > 0)

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeGenericMap.java View File

75
 
75
 
76
 		@Override
76
 		@Override
77
 		public IPartialExpression get(CodePosition position, GenericName name) {
77
 		public IPartialExpression get(CodePosition position, GenericName name) {
78
-			if (typeParameters.containsKey(name.name) && name.arguments.isEmpty())
78
+			if (typeParameters.containsKey(name.name) && name.hasNoArguments())
79
 				return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)));
79
 				return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)));
80
 			
80
 			
81
 			return outer.get(position, name);
81
 			return outer.get(position, name);
83
 
83
 
84
 		@Override
84
 		@Override
85
 		public ITypeID getType(CodePosition position, List<GenericName> name) {
85
 		public ITypeID getType(CodePosition position, List<GenericName> name) {
86
-			if (typeParameters.containsKey(name.get(0).name) && name.size() == 1 && name.get(0).arguments.isEmpty())
86
+			if (typeParameters.containsKey(name.get(0).name) && name.size() == 1 && name.get(0).hasNoArguments())
87
 				return getTypeRegistry().getGeneric(typeParameters.get(name.get(0).name));
87
 				return getTypeRegistry().getGeneric(typeParameters.get(name.get(0).name));
88
 			
88
 			
89
 			return outer.getType(position, name);
89
 			return outer.getType(position, name);

+ 3
- 2
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java View File

121
 	private class PrintlnSymbol implements ISymbol {
121
 	private class PrintlnSymbol implements ISymbol {
122
 
122
 
123
 		@Override
123
 		@Override
124
-		public IPartialExpression getExpression(CodePosition position, GlobalTypeRegistry types, List<ITypeID> typeArguments) {
124
+		public IPartialExpression getExpression(CodePosition position, GlobalTypeRegistry types, ITypeID[] typeArguments) {
125
 			//return new PartialStaticMemberGroupExpression(position, PRINTLN.callerGroup);
125
 			//return new PartialStaticMemberGroupExpression(position, PRINTLN.callerGroup);
126
 			return new PartialMemberGroupExpression(
126
 			return new PartialMemberGroupExpression(
127
 					position,
127
 					position,
128
 					new GetStaticFieldExpression(position, SYSTEM_OUT),
128
 					new GetStaticFieldExpression(position, SYSTEM_OUT),
129
 					PRINTSTREAM_PRINTLN,
129
 					PRINTSTREAM_PRINTLN,
130
+					null,
130
 					false);
131
 					false);
131
 		}
132
 		}
132
 
133
 
133
 		@Override
134
 		@Override
134
-		public ITypeID getType(CodePosition position, GlobalTypeRegistry types, List<ITypeID> typeArguments) {
135
+		public ITypeID getType(CodePosition position, GlobalTypeRegistry types, ITypeID[] typeArguments) {
135
 			// don't be fooled! this symbol is the System.out.println bound method and thus its type is a function
136
 			// don't be fooled! this symbol is the System.out.println bound method and thus its type is a function
136
 			return new FunctionTypeID(PRINTSTREAM_PRINTLN.header);
137
 			return new FunctionTypeID(PRINTSTREAM_PRINTLN.header);
137
 		}
138
 		}

+ 2
- 1
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java View File

187
 
187
 
188
 	@Override
188
 	@Override
189
 	public Boolean visitCustomIterator(CustomIteratorMember member) {
189
 	public Boolean visitCustomIterator(CustomIteratorMember member) {
190
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
190
+		// TODO: validate iterators
191
+		return true;
191
 	}
192
 	}
192
 
193
 
193
 	@Override
194
 	@Override

+ 15
- 13
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java View File

145
 	public Boolean visitCall(CallExpression expression) {
145
 	public Boolean visitCall(CallExpression expression) {
146
 		boolean isValid = true;
146
 		boolean isValid = true;
147
 		isValid &= expression.target.accept(this);
147
 		isValid &= expression.target.accept(this);
148
-		isValid &= checkCallArguments(expression.position, expression.member.header, expression.arguments);
148
+		isValid &= checkCallArguments(expression.position, expression.member.header, expression.instancedHeader, expression.arguments);
149
 		return isValid;
149
 		return isValid;
150
 	}
150
 	}
151
 
151
 
152
 	@Override
152
 	@Override
153
 	public Boolean visitCallStatic(CallStaticExpression expression) {
153
 	public Boolean visitCallStatic(CallStaticExpression expression) {
154
-		return checkCallArguments(expression.position, expression.member.header, expression.arguments);
154
+		return checkCallArguments(expression.position, expression.member.header, expression.instancedHeader, expression.arguments);
155
 	}
155
 	}
156
 
156
 
157
 	@Override
157
 	@Override
297
 			isValid = false;
297
 			isValid = false;
298
 		}
298
 		}
299
 		scope.markConstructorForwarded();
299
 		scope.markConstructorForwarded();
300
-		isValid &= checkCallArguments(expression.position, expression.constructor.header, expression.arguments);
300
+		isValid &= checkCallArguments(expression.position, expression.constructor.header, expression.constructor.header, expression.arguments);
301
 		return isValid;
301
 		return isValid;
302
 	}
302
 	}
303
 
303
 
313
 			isValid = false;
313
 			isValid = false;
314
 		}
314
 		}
315
 		scope.markConstructorForwarded();
315
 		scope.markConstructorForwarded();
316
-		isValid &= checkCallArguments(expression.position, expression.constructor.header, expression.arguments);
316
+		isValid &= checkCallArguments(expression.position, expression.constructor.header, expression.constructor.header, expression.arguments);
317
 		return isValid;
317
 		return isValid;
318
 	}
318
 	}
319
 
319
 
331
 
331
 
332
 	@Override
332
 	@Override
333
 	public Boolean visitFunction(FunctionExpression expression) {
333
 	public Boolean visitFunction(FunctionExpression expression) {
334
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
334
+		// TODO
335
+		return true;
335
 	}
336
 	}
336
 
337
 
337
 	@Override
338
 	@Override
444
 		boolean isValid = checkCallArguments(
445
 		boolean isValid = checkCallArguments(
445
 				expression.position,
446
 				expression.position,
446
 				expression.constructor.header,
447
 				expression.constructor.header,
448
+				expression.constructor.header,
447
 				expression.arguments);
449
 				expression.arguments);
448
 		return isValid;
450
 		return isValid;
449
 	}
451
 	}
618
 	@Override
620
 	@Override
619
 	public Boolean visitWrapOptional(WrapOptionalExpression expression) {
621
 	public Boolean visitWrapOptional(WrapOptionalExpression expression) {
620
 		boolean isValid = expression.value.accept(this);
622
 		boolean isValid = expression.value.accept(this);
621
-		if (expression.type.isOptional()) {
623
+		if (expression.value.type.isOptional()) {
622
 			validator.logError(ValidationLogEntry.Code.INVALID_OPERAND_TYPE, expression.position, "expression value is already optional");
624
 			validator.logError(ValidationLogEntry.Code.INVALID_OPERAND_TYPE, expression.position, "expression value is already optional");
623
 			isValid = false;
625
 			isValid = false;
624
 		}
626
 		}
625
 		return isValid;
627
 		return isValid;
626
 	}
628
 	}
627
 	
629
 	
628
-	private boolean checkCallArguments(CodePosition position, FunctionHeader header, CallArguments arguments) {
630
+	private boolean checkCallArguments(CodePosition position, FunctionHeader originalHeader, FunctionHeader instancedHeader, CallArguments arguments) {
629
 		boolean isValid = true;
631
 		boolean isValid = true;
630
-		isValid &= ValidationUtils.validateTypeArguments(validator, position, header.typeParameters, arguments.typeArguments);
632
+		isValid &= ValidationUtils.validateTypeArguments(validator, position, originalHeader.typeParameters, arguments.typeArguments);
631
 		
633
 		
632
 		for (int i = 0; i < arguments.arguments.length; i++) {
634
 		for (int i = 0; i < arguments.arguments.length; i++) {
633
 			Expression argument = arguments.arguments[i];
635
 			Expression argument = arguments.arguments[i];
634
 			isValid &= argument.accept(this);
636
 			isValid &= argument.accept(this);
635
 			
637
 			
636
-			if (i >= header.parameters.length) {
637
-				FunctionParameter variadic = header.getVariadicParameter();
638
+			if (i >= instancedHeader.parameters.length) {
639
+				FunctionParameter variadic = instancedHeader.getVariadicParameter();
638
 				if (variadic == null) {
640
 				if (variadic == null) {
639
 					validator.logError(ValidationLogEntry.Code.INVALID_CALL_ARGUMENT, position, "too many call arguments");
641
 					validator.logError(ValidationLogEntry.Code.INVALID_CALL_ARGUMENT, position, "too many call arguments");
640
 					isValid = false;
642
 					isValid = false;
649
 				}
651
 				}
650
 			}
652
 			}
651
 			
653
 			
652
-			FunctionParameter parameter = header.parameters[i];
654
+			FunctionParameter parameter = instancedHeader.parameters[i];
653
 			if (parameter.type != argument.type) {
655
 			if (parameter.type != argument.type) {
654
 				validator.logError(
656
 				validator.logError(
655
 						ValidationLogEntry.Code.INVALID_CALL_ARGUMENT,
657
 						ValidationLogEntry.Code.INVALID_CALL_ARGUMENT,
659
 			}
661
 			}
660
 		}
662
 		}
661
 		
663
 		
662
-		for (int i = arguments.arguments.length; i < header.parameters.length; i++) {
663
-			FunctionParameter parameter = header.parameters[i];
664
+		for (int i = arguments.arguments.length; i < instancedHeader.parameters.length; i++) {
665
+			FunctionParameter parameter = instancedHeader.parameters[i];
664
 			if (parameter.defaultValue == null && !parameter.variadic) {
666
 			if (parameter.defaultValue == null && !parameter.variadic) {
665
 				validator.logError(ValidationLogEntry.Code.INVALID_CALL_ARGUMENT, position, "missing call argument for " + parameter.name);
667
 				validator.logError(ValidationLogEntry.Code.INVALID_CALL_ARGUMENT, position, "missing call argument for " + parameter.name);
666
 				isValid = false;
668
 				isValid = false;

+ 8
- 2
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java View File

148
 			TypeParameter[] typeParameters,
148
 			TypeParameter[] typeParameters,
149
 			ITypeID[] typeArguments)
149
 			ITypeID[] typeArguments)
150
 	{
150
 	{
151
+		if (typeParameters == null)
152
+			return typeArguments == null;
153
+		if (typeArguments == null)
154
+			return false;
155
+		
151
 		if (typeParameters.length != typeArguments.length) {
156
 		if (typeParameters.length != typeArguments.length) {
152
 			target.logError(
157
 			target.logError(
153
 					ValidationLogEntry.Code.INVALID_TYPE_ARGUMENT,
158
 					ValidationLogEntry.Code.INVALID_TYPE_ARGUMENT,
164
 		for (int i = 0; i < typeParameters.length; i++) {
169
 		for (int i = 0; i < typeParameters.length; i++) {
165
 			TypeParameter typeParameter = typeParameters[i];
170
 			TypeParameter typeParameter = typeParameters[i];
166
 			for (GenericParameterBound bound : typeParameter.bounds) {
171
 			for (GenericParameterBound bound : typeParameter.bounds) {
167
-				if (!bound.matches(typeArguments[i])) {
172
+				// TODO - obtain member cache for validation
173
+				/*if (!bound.matches(typeArguments[i])) {
168
 					target.logError(
174
 					target.logError(
169
 							ValidationLogEntry.Code.INVALID_TYPE_ARGUMENT,
175
 							ValidationLogEntry.Code.INVALID_TYPE_ARGUMENT,
170
 							position,
176
 							position,
171
 							bound.accept(new TypeParameterBoundErrorVisitor(typeArguments[i], target)));
177
 							bound.accept(new TypeParameterBoundErrorVisitor(typeArguments[i], target)));
172
 					isValid = false;
178
 					isValid = false;
173
-				}
179
+				}*/
174
 			}
180
 			}
175
 		}
181
 		}
176
 		return isValid;
182
 		return isValid;

Loading…
Cancel
Save