Browse Source

- Added destructors

- Added === and !== operator support
- Fixed some cases where arguments aren't casted properly during call
- Continued some work on stdlib
Stan Hebben 6 years ago
parent
commit
2864226fab
89 changed files with 816 additions and 132 deletions
  1. 12
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  2. 10
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java
  3. 2
    7
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java
  4. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  5. 1
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/OperatorType.java
  6. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  7. 25
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallArguments.java
  8. 3
    15
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java
  9. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java
  10. 4
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallTranslator.java
  11. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorSuperCallExpression.java
  12. 4
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorThisCallExpression.java
  13. 4
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  14. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFieldExpression.java
  15. 32
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SameObjectExpression.java
  16. 29
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SupertypeCastExpression.java
  17. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/GenericParameterBound.java
  18. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java
  19. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java
  20. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java
  21. 6
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java
  22. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java
  23. 9
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  24. 55
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DestructorMember.java
  25. 10
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EqualsMember.java
  26. 11
    10
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  27. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java
  28. 7
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICallableMember.java
  29. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MemberVisitor.java
  30. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MethodMember.java
  31. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/OperatorMember.java
  32. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java
  33. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/TranslatedOperatorMember.java
  34. 10
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ComparatorMember.java
  35. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java
  36. 4
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/CatchClause.java
  37. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java
  38. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java
  39. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java
  40. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ConstTypeID.java
  41. 10
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java
  42. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java
  43. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java
  44. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java
  45. 0
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  46. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java
  47. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java
  48. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java
  49. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java
  50. 13
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  51. 9
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  52. 38
    13
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  53. 2
    0
      Constructor/libraries/collections/src/HashSet.zs
  54. 35
    5
      Constructor/libraries/collections/src/LinkedList.zs
  55. 5
    1
      Constructor/libraries/collections/src/Set.zs
  56. 21
    0
      Constructor/libraries/collections/src/Stack.zs
  57. 4
    0
      Constructor/libraries/io/module.json
  58. 10
    0
      Constructor/libraries/io/src/Reader.zs
  59. 22
    0
      Constructor/libraries/io/src/StringReader.zs
  60. 1
    0
      Constructor/libraries/stdlib/module.json
  61. 19
    0
      Constructor/libraries/stdlib/src/Arrays.zs
  62. 2
    2
      Constructor/libraries/stdlib/src/Exception.zs
  63. 4
    0
      Constructor/libraries/stdlib/src/Hashable.zs
  64. 5
    0
      Constructor/libraries/stdlib/src/Integers.zs
  65. 2
    0
      Constructor/libraries/stdlib/src/StringBuilder.zs
  66. 3
    5
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  67. 2
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java
  68. 27
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  69. 12
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  70. 12
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  71. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  72. 18
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  73. 0
    2
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenStream.java
  74. 0
    2
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java
  75. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java
  76. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java
  77. 10
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java
  78. 7
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionString.java
  79. 3
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java
  80. 13
    1
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java
  81. 27
    0
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDestructor.java
  82. 71
    2
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java
  83. 3
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatement.java
  84. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementTryCatch.java
  85. 0
    4
      Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java
  86. 2
    1
      Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java
  87. 17
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java
  88. 5
    1
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java
  89. 16
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java

+ 12
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java View File

56
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
56
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
57
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
58
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
58
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
59
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
59
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
60
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
60
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
61
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
61
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
62
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
63
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
64
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
64
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
65
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
65
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
66
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
67
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
66
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
68
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
67
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
69
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
68
 import org.openzen.zenscript.codemodel.member.OperatorMember;
70
 import org.openzen.zenscript.codemodel.member.OperatorMember;
532
 	public ExpressionString visitRange(RangeExpression expression) {
534
 	public ExpressionString visitRange(RangeExpression expression) {
533
 		return binary(expression.from, expression.to, OperatorPriority.RANGE, " .. ");
535
 		return binary(expression.from, expression.to, OperatorPriority.RANGE, " .. ");
534
 	}
536
 	}
537
+	
538
+	@Override
539
+	public ExpressionString visitSameObject(SameObjectExpression expression) {
540
+		return binary(expression.left, expression.right, OperatorPriority.COMPARE, expression.inverted ? " !== " : " === ");
541
+	}
535
 
542
 
536
 	@Override
543
 	@Override
537
 	public ExpressionString visitSetField(SetFieldExpression expression) {
544
 	public ExpressionString visitSetField(SetFieldExpression expression) {
581
 				expression.type.accept(typeFormatter) + "." + expression.setter.name + " = " + expression.setter.name,
588
 				expression.type.accept(typeFormatter) + "." + expression.setter.name + " = " + expression.setter.name,
582
 				OperatorPriority.ASSIGN);
589
 				OperatorPriority.ASSIGN);
583
 	}
590
 	}
591
+	
592
+	@Override
593
+	public ExpressionString visitSupertypeCast(SupertypeCastExpression expression) {
594
+		return expression.value.accept(this);
595
+	}
584
 
596
 
585
 	@Override
597
 	@Override
586
 	public ExpressionString visitThis(ThisExpression expression) {
598
 	public ExpressionString visitThis(ThisExpression expression) {

+ 10
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java View File

10
 import org.openzen.zenscript.codemodel.member.CasterMember;
10
 import org.openzen.zenscript.codemodel.member.CasterMember;
11
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
11
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
12
 import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
12
 import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
13
+import org.openzen.zenscript.codemodel.member.DestructorMember;
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.GetterMember;
16
 import org.openzen.zenscript.codemodel.member.GetterMember;
81
 		return null;
82
 		return null;
82
 	}
83
 	}
83
 
84
 
85
+	@Override
86
+	public Void visitDestructor(DestructorMember member) {
87
+		visit(false);
88
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
89
+		output.append("this");
90
+		formatBody(member.body);
91
+		return null;
92
+	}
93
+
84
 	@Override
94
 	@Override
85
 	public Void visitMethod(MethodMember member) {
95
 	public Void visitMethod(MethodMember member) {
86
 		visit(false);
96
 		visit(false);

+ 2
- 7
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java View File

27
 import org.openzen.zenscript.codemodel.statement.TryCatchStatement;
27
 import org.openzen.zenscript.codemodel.statement.TryCatchStatement;
28
 import org.openzen.zenscript.codemodel.statement.VarStatement;
28
 import org.openzen.zenscript.codemodel.statement.VarStatement;
29
 import org.openzen.zenscript.codemodel.statement.WhileStatement;
29
 import org.openzen.zenscript.codemodel.statement.WhileStatement;
30
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
31
 
30
 
32
 /**
31
 /**
33
  *
32
  *
252
 		
251
 		
253
 		for (CatchClause catchClause : statement.catchClauses) {
252
 		for (CatchClause catchClause : statement.catchClauses) {
254
 			output.append(indent).append("catch ");
253
 			output.append(indent).append("catch ");
255
-			if (catchClause.exceptionName != null)
256
-				output.append(catchClause.exceptionName);
257
-			if (catchClause.exceptionType != BasicTypeID.ANY) {
258
-				output.append(" as ");
259
-				catchClause.exceptionType.accept(expressionFormatter.typeFormatter);
260
-			}
254
+			if (catchClause.exceptionVariable != null)
255
+				output.append(catchClause.exceptionVariable.name).append(" as ").append(catchClause.exceptionVariable.type.accept(expressionFormatter.typeFormatter));
261
 			
256
 			
262
 			format(ParentStatementType.CATCH, catchClause.content);
257
 			format(ParentStatementType.CATCH, catchClause.content);
263
 		}
258
 		}

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

237
 		if (this.parameters.length != arguments.arguments.length)
237
 		if (this.parameters.length != arguments.arguments.length)
238
 			return parameters.length + " parameters expected but " + arguments.arguments.length + " given.";
238
 			return parameters.length + " parameters expected but " + arguments.arguments.length + " given.";
239
 		
239
 		
240
-		if (typeParameters.length != arguments.typeArguments.length)
240
+		if (getNumberOfTypeParameters() != arguments.getNumberOfTypeArguments())
241
 			return typeParameters.length + " type parameters expected but " + arguments.typeArguments.length + " given.";
241
 			return typeParameters.length + " type parameters expected but " + arguments.typeArguments.length + " given.";
242
 		
242
 		
243
 		for (int i = 0; i < parameters.length; i++) {
243
 		for (int i = 0; i < parameters.length; i++) {

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

47
 	RANGE("..", "rangeTo"),
47
 	RANGE("..", "rangeTo"),
48
 	
48
 	
49
 	CONSTRUCTOR("this", "construct"),
49
 	CONSTRUCTOR("this", "construct"),
50
+	DESTRUCTOR("~this", "destruct"),
50
 	CALL("()", "call"),
51
 	CALL("()", "call"),
51
 	CAST("as", "cast");
52
 	CAST("as", "cast");
52
 	
53
 	

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.definition;
6
 package org.openzen.zenscript.codemodel.definition;
7
 
7
 
8
-import java.util.List;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
8
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.Modifiers;
10
 import org.openzen.zenscript.codemodel.Modifiers;
24
 	public FunctionHeader header;
23
 	public FunctionHeader header;
25
 	public Statement statement;
24
 	public Statement statement;
26
 	public OperatorMember caller;
25
 	public OperatorMember caller;
27
-	public DefinitionMemberGroup callerGroup = new DefinitionMemberGroup(true);
26
+	public final DefinitionMemberGroup callerGroup;
28
 	
27
 	
29
 	public FunctionDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
28
 	public FunctionDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
30
 		super(position, pkg, name, modifiers, outerDefinition);
29
 		super(position, pkg, name, modifiers, outerDefinition);
30
+		callerGroup = new DefinitionMemberGroup(true, name);
31
 	}
31
 	}
32
 	
32
 	
33
 	public FunctionDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, FunctionHeader header) {
33
 	public FunctionDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, FunctionHeader header) {

+ 25
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallArguments.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.Arrays;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.scope.TypeScope;
8
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.shared.CodePosition;
13
+import org.openzen.zenscript.shared.CompileException;
14
+import org.openzen.zenscript.shared.CompileExceptionCode;
9
 
15
 
10
 /**
16
 /**
11
  *
17
  *
36
 	public int getNumberOfTypeArguments() {
42
 	public int getNumberOfTypeArguments() {
37
 		return typeArguments.length;
43
 		return typeArguments.length;
38
 	}
44
 	}
45
+	
46
+	public CallArguments normalize(CodePosition position, TypeScope scope, FunctionHeader header) {
47
+		CallArguments result = this;
48
+		
49
+		for (int i = 0; i < arguments.length; i++) {
50
+			arguments[i] = arguments[i].castImplicit(position, scope, header.parameters[i].type);
51
+		}
52
+		
53
+		if (arguments.length < header.parameters.length) {
54
+			Expression[] newArguments = Arrays.copyOf(arguments, header.parameters.length);
55
+			for (int i = arguments.length; i < header.parameters.length; i++) {
56
+				if (header.parameters[i].defaultValue == null)
57
+					throw new CompileException(position, CompileExceptionCode.MISSING_PARAMETER, "Parameter missing and no default value specified");
58
+				newArguments[i] = header.parameters[i].defaultValue;
59
+			}
60
+			result = new CallArguments(typeArguments, newArguments);
61
+		}
62
+		return result;
63
+	}
39
 }
64
 }

+ 3
- 15
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.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.Arrays;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
8
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
10
+import org.openzen.zenscript.codemodel.scope.TypeScope;
11
 import org.openzen.zenscript.shared.CodePosition;
11
 import org.openzen.zenscript.shared.CodePosition;
12
-import org.openzen.zenscript.shared.CompileException;
13
-import org.openzen.zenscript.shared.CompileExceptionCode;
14
 
12
 
15
 /**
13
 /**
16
  *
14
  *
22
 	public final CallArguments arguments;
20
 	public final CallArguments arguments;
23
 	public final FunctionHeader instancedHeader;
21
 	public final FunctionHeader instancedHeader;
24
 	
22
 	
25
-	public CallExpression(CodePosition position, Expression target, FunctionalMember member, FunctionHeader instancedHeader, CallArguments arguments) {
23
+	public CallExpression(CodePosition position, Expression target, FunctionalMember member, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
26
 		super(position, instancedHeader.returnType);
24
 		super(position, instancedHeader.returnType);
27
 		
25
 		
28
-		if (arguments.arguments.length < instancedHeader.parameters.length) {
29
-			Expression[] newArguments = Arrays.copyOf(arguments.arguments, instancedHeader.parameters.length);
30
-			for (int i = arguments.arguments.length; i < instancedHeader.parameters.length; i++) {
31
-				if (instancedHeader.parameters[i].defaultValue == null)
32
-					throw new CompileException(position, CompileExceptionCode.MISSING_PARAMETER, "Parameter missing and no default value specified");
33
-				newArguments[i] = instancedHeader.parameters[i].defaultValue;
34
-			}
35
-			arguments = new CallArguments(arguments.typeArguments, newArguments);
36
-		}
37
-		
38
 		this.target = target;
26
 		this.target = target;
39
 		this.member = member;
27
 		this.member = member;
40
-		this.arguments = arguments;
28
+		this.arguments = arguments.normalize(position, scope, instancedHeader);
41
 		this.instancedHeader = instancedHeader;
29
 		this.instancedHeader = instancedHeader;
42
 	}
30
 	}
43
 	
31
 	

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

7
 
7
 
8
 import org.openzen.zenscript.codemodel.FunctionHeader;
8
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
10
+import org.openzen.zenscript.codemodel.scope.TypeScope;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.shared.CodePosition;
12
 import org.openzen.zenscript.shared.CodePosition;
12
 
13
 
20
 	public final CallArguments arguments;
21
 	public final CallArguments arguments;
21
 	public final FunctionHeader instancedHeader;
22
 	public final FunctionHeader instancedHeader;
22
 	
23
 	
23
-	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMember member, CallArguments arguments, FunctionHeader instancedHeader) {
24
+	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMember member, CallArguments arguments, FunctionHeader instancedHeader, TypeScope scope) {
24
 		super(position, member.header.returnType);
25
 		super(position, member.header.returnType);
25
 		
26
 		
26
 		this.member = member;
27
 		this.member = member;
27
 		this.target = target;
28
 		this.target = target;
28
-		this.arguments = arguments;
29
+		this.arguments = arguments.normalize(position, scope, instancedHeader);
29
 		this.instancedHeader = instancedHeader;
30
 		this.instancedHeader = instancedHeader;
30
 	}
31
 	}
31
 
32
 

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

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.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.scope.TypeScope;
9
 import org.openzen.zenscript.shared.CodePosition;
10
 import org.openzen.zenscript.shared.CodePosition;
10
 
11
 
11
 /**
12
 /**
18
 		public final Expression target;
19
 		public final Expression target;
19
 		public final FunctionHeader instancedHeader;
20
 		public final FunctionHeader instancedHeader;
20
 		public final CallArguments arguments;
21
 		public final CallArguments arguments;
22
+		public final TypeScope scope;
21
 		
23
 		
22
-		public Call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
24
+		public Call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
23
 			this.position = position;
25
 			this.position = position;
24
 			this.target = target;
26
 			this.target = target;
25
 			this.instancedHeader = instancedHeader;
27
 			this.instancedHeader = instancedHeader;
26
 			this.arguments = arguments;
28
 			this.arguments = arguments;
29
+			this.scope = scope;
27
 		}
30
 		}
28
 	}
31
 	}
29
 	
32
 	

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

6
 package org.openzen.zenscript.codemodel.expression;
6
 package org.openzen.zenscript.codemodel.expression;
7
 
7
 
8
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
8
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
9
+import org.openzen.zenscript.codemodel.scope.TypeScope;
9
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
10
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.shared.CodePosition;
12
 import org.openzen.zenscript.shared.CodePosition;
19
 	public final ConstructorMember constructor;
20
 	public final ConstructorMember constructor;
20
 	public final CallArguments arguments;
21
 	public final CallArguments arguments;
21
 	
22
 	
22
-	public ConstructorSuperCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments) {
23
+	public ConstructorSuperCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments, TypeScope scope) {
23
 		super(position, BasicTypeID.VOID);
24
 		super(position, BasicTypeID.VOID);
24
 		
25
 		
25
 		this.objectType = type;
26
 		this.objectType = type;
26
 		this.constructor = constructor;
27
 		this.constructor = constructor;
27
-		this.arguments = arguments;
28
+		this.arguments = arguments.normalize(position, scope, constructor.header);
28
 	}
29
 	}
29
 
30
 
30
 	@Override
31
 	@Override

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

6
 package org.openzen.zenscript.codemodel.expression;
6
 package org.openzen.zenscript.codemodel.expression;
7
 
7
 
8
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
8
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
9
+import org.openzen.zenscript.codemodel.scope.TypeScope;
9
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
10
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
10
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.shared.CodePosition;
12
 import org.openzen.zenscript.shared.CodePosition;
19
 	public final ConstructorMember constructor;
20
 	public final ConstructorMember constructor;
20
 	public final CallArguments arguments;
21
 	public final CallArguments arguments;
21
 	
22
 	
22
-	public ConstructorThisCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments) {
23
+	public ConstructorThisCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments, TypeScope scope) {
23
 		super(position, BasicTypeID.VOID);
24
 		super(position, BasicTypeID.VOID);
24
 		
25
 		
26
+		arguments = arguments.normalize(position, scope, constructor.header);
27
+		
25
 		this.objectType = type;
28
 		this.objectType = type;
26
 		this.constructor = constructor;
29
 		this.constructor = constructor;
27
 		this.arguments = arguments;
30
 		this.arguments = arguments;

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

106
 	
106
 	
107
 	public T visitRange(RangeExpression expression);
107
 	public T visitRange(RangeExpression expression);
108
 	
108
 	
109
+	public T visitSameObject(SameObjectExpression expression);
110
+	
109
 	public T visitSetField(SetFieldExpression expression);
111
 	public T visitSetField(SetFieldExpression expression);
110
 	
112
 	
111
 	public T visitSetFunctionParameter(SetFunctionParameterExpression expression);
113
 	public T visitSetFunctionParameter(SetFunctionParameterExpression expression);
120
 	
122
 	
121
 	public T visitStaticSetter(StaticSetterExpression expression);
123
 	public T visitStaticSetter(StaticSetterExpression expression);
122
 	
124
 	
125
+	public T visitSupertypeCast(SupertypeCastExpression expression);
126
+	
123
 	public T visitThis(ThisExpression expression);
127
 	public T visitThis(ThisExpression expression);
124
 	
128
 	
125
 	public T visitWrapOptional(WrapOptionalExpression expression);
129
 	public T visitWrapOptional(WrapOptionalExpression expression);

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

8
 import java.util.Collections;
8
 import java.util.Collections;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zenscript.codemodel.member.FieldMember;
10
 import org.openzen.zenscript.codemodel.member.FieldMember;
11
+import org.openzen.zenscript.codemodel.scope.TypeScope;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.shared.CodePosition;
13
 import org.openzen.zenscript.shared.CodePosition;
14
+import org.openzen.zenscript.shared.CompileException;
15
+import org.openzen.zenscript.shared.CompileExceptionCode;
13
 
16
 
14
 /**
17
 /**
15
  *
18
  *
35
 	public CapturedExpression capture(CodePosition position, LambdaClosure closure) {
38
 	public CapturedExpression capture(CodePosition position, LambdaClosure closure) {
36
 		return new CapturedDirectExpression(position, closure, this);
39
 		return new CapturedDirectExpression(position, closure, this);
37
 	}
40
 	}
41
+	
42
+	@Override
43
+	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
44
+		return new SetFieldExpression(position, target, field, value);
45
+	}
38
 
46
 
39
 	@Override
47
 	@Override
40
 	public <T> T accept(ExpressionVisitor<T> visitor) {
48
 	public <T> T accept(ExpressionVisitor<T> visitor) {

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SameObjectExpression.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.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class SameObjectExpression extends Expression {
16
+	public final Expression left;
17
+	public final Expression right;
18
+	public final boolean inverted;
19
+	
20
+	public SameObjectExpression(CodePosition position, Expression left, Expression right, boolean inverted) {
21
+		super(position, BasicTypeID.BOOL);
22
+		
23
+		this.left = left;
24
+		this.right = right;
25
+		this.inverted = inverted;
26
+	}
27
+
28
+	@Override
29
+	public <T> T accept(ExpressionVisitor<T> visitor) {
30
+		return visitor.visitSameObject(this);
31
+	}
32
+}

+ 29
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SupertypeCastExpression.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.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ * Using to cast a class type to a base type.
13
+ * 
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class SupertypeCastExpression extends Expression {
17
+	public final Expression value;
18
+	
19
+	public SupertypeCastExpression(CodePosition position, Expression value, ITypeID type) {
20
+		super(position, type);
21
+		
22
+		this.value = value;
23
+	}
24
+
25
+	@Override
26
+	public <T> T accept(ExpressionVisitor<T> visitor) {
27
+		return visitor.visitSupertypeCast(this);
28
+	}
29
+}

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

16
  * @author Hoofdgebruiker
16
  * @author Hoofdgebruiker
17
  */
17
  */
18
 public abstract class GenericParameterBound {
18
 public abstract class GenericParameterBound {
19
+	public abstract boolean isObjectType();
20
+	
19
 	public abstract <T> T accept(GenericParameterBoundVisitor<T> visitor);
21
 	public abstract <T> T accept(GenericParameterBoundVisitor<T> visitor);
20
 	
22
 	
21
 	public abstract void registerMembers(LocalMemberCache cache, TypeMembers type);
23
 	public abstract void registerMembers(LocalMemberCache cache, TypeMembers type);

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

45
 	public <T> T accept(GenericParameterBoundVisitor<T> visitor) {
45
 	public <T> T accept(GenericParameterBoundVisitor<T> visitor) {
46
 		return visitor.visitSuper(this);
46
 		return visitor.visitSuper(this);
47
 	}
47
 	}
48
+
49
+	@Override
50
+	public boolean isObjectType() {
51
+		return true;
52
+	}
48
 }
53
 }

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

45
 	public <T> T accept(GenericParameterBoundVisitor<T> visitor) {
45
 	public <T> T accept(GenericParameterBoundVisitor<T> visitor) {
46
 		return visitor.visitType(this);
46
 		return visitor.visitType(this);
47
 	}
47
 	}
48
+
49
+	@Override
50
+	public boolean isObjectType() {
51
+		return true;
52
+	}
48
 }
53
 }

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

37
 		bounds.add(bound);
37
 		bounds.add(bound);
38
 	}
38
 	}
39
 	
39
 	
40
+	public boolean isObjectType() {
41
+		for (GenericParameterBound bound : bounds)
42
+			if (bound.isObjectType())
43
+				return true;
44
+		
45
+		return false;
46
+	}
47
+	
40
 	public boolean matches(LocalMemberCache cache, ITypeID type) {
48
 	public boolean matches(LocalMemberCache cache, ITypeID type) {
41
 		for (GenericParameterBound bound : bounds) {
49
 		for (GenericParameterBound bound : bounds) {
42
 			if (!bound.matches(cache, type))
50
 			if (!bound.matches(cache, type))

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

23
 	public CallerMember(CodePosition position, HighLevelDefinition definition, int modifiers, FunctionHeader header) {
23
 	public CallerMember(CodePosition position, HighLevelDefinition definition, int modifiers, FunctionHeader header) {
24
 		super(position, definition, modifiers, "()", header);
24
 		super(position, definition, modifiers, "()", header);
25
 	}
25
 	}
26
+	
27
+	@Override
28
+	public String getInformalName() {
29
+		return "caller";
30
+	}
26
 
31
 
27
 	@Override
32
 	@Override
28
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
33
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
31
 
36
 
32
 	@Override
37
 	@Override
33
 	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
38
 	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
34
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
39
+		return new CallerMember(position, definition, modifiers, header.instance(registry, mapping));
35
 	}
40
 	}
36
 
41
 
37
 	@Override
42
 	@Override

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

13
 import org.openzen.zenscript.codemodel.expression.CastExpression;
13
 import org.openzen.zenscript.codemodel.expression.CastExpression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
+import org.openzen.zenscript.codemodel.scope.TypeScope;
16
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
31
 		
32
 		
32
 		this.toType = toType;
33
 		this.toType = toType;
33
 	}
34
 	}
35
+	
36
+	@Override
37
+	public String getInformalName() {
38
+		return "caster to " + toType.toString();
39
+	}
34
 
40
 
35
 	@Override
41
 	@Override
36
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
42
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
53
 	}
59
 	}
54
 
60
 
55
 	@Override
61
 	@Override
56
-	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
62
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
57
 		throw new UnsupportedOperationException("Cannot call a caster!");
63
 		throw new UnsupportedOperationException("Cannot call a caster!");
58
 	}
64
 	}
59
 
65
 

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

43
 				firstExpression.expression instanceof ConstructorSuperCallExpression
43
 				firstExpression.expression instanceof ConstructorSuperCallExpression
44
 				|| firstExpression.expression instanceof ConstructorThisCallExpression);
44
 				|| firstExpression.expression instanceof ConstructorThisCallExpression);
45
 	}
45
 	}
46
+	
47
+	@Override
48
+	public String getInformalName() {
49
+		return "constructor";
50
+	}
46
 
51
 
47
 	@Override
52
 	@Override
48
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
53
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
52
 
57
 
53
 	@Override
58
 	@Override
54
 	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
59
 	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
55
-		return new ConstructorMember(position, definition, modifiers, header.instance(registry, mapping));
60
+		ConstructorMember result = new ConstructorMember(position, definition, modifiers, header.instance(registry, mapping));
61
+		if (definition.name.equals("NFAState"))
62
+			System.out.println("X");
63
+		return result;
56
 	}
64
 	}
57
 
65
 
58
 	@Override
66
 	@Override

+ 55
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DestructorMember.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;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
13
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14
+import org.openzen.zenscript.codemodel.type.ITypeID;
15
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
+import org.openzen.zenscript.shared.CodePosition;
18
+
19
+/**
20
+ *
21
+ * @author Hoofdgebruiker
22
+ */
23
+public class DestructorMember extends FunctionalMember {
24
+	private static final FunctionHeader HEADER = new FunctionHeader(BasicTypeID.VOID);
25
+	
26
+	public DestructorMember(CodePosition position, HighLevelDefinition definition, int modifiers) {
27
+		super(position, definition, modifiers, "~this", HEADER);
28
+	}
29
+	
30
+	@Override
31
+	public String getInformalName() {
32
+		return "destructor";
33
+	}
34
+
35
+	@Override
36
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
37
+		if (priority == TypeMemberPriority.SPECIFIED)
38
+			type.addDestructor(this, priority);
39
+	}
40
+
41
+	@Override
42
+	public DefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
43
+		return this;
44
+	}
45
+
46
+	@Override
47
+	public String describe() {
48
+		return "destructor";
49
+	}
50
+
51
+	@Override
52
+	public <T> T accept(MemberVisitor<T> visitor) {
53
+		return visitor.visitDestructor(this);
54
+	}
55
+}

+ 10
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/EqualsMember.java View File

14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15
 import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.expression.Expression;
16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
17
+import org.openzen.zenscript.codemodel.scope.TypeScope;
17
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
18
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
18
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20
 import org.openzen.zenscript.codemodel.type.ITypeID;
35
 		this.header = new FunctionHeader(BasicTypeID.BOOL, new FunctionParameter(type));
36
 		this.header = new FunctionHeader(BasicTypeID.BOOL, new FunctionParameter(type));
36
 	}
37
 	}
37
 	
38
 	
39
+	@Override
40
+	public String getInformalName() {
41
+		return "equals operator";
42
+	}
43
+	
38
 	@Override
44
 	@Override
39
 	public boolean isStatic() {
45
 	public boolean isStatic() {
40
 		return false;
46
 		return false;
46
 	}
52
 	}
47
 
53
 
48
 	@Override
54
 	@Override
49
-	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
55
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
50
 		return new BasicCompareExpression(position, target, arguments.arguments[0], CompareType.EQ);
56
 		return new BasicCompareExpression(position, target, arguments.arguments[0], CompareType.EQ);
51
 	}
57
 	}
52
 
58
 
53
 	@Override
59
 	@Override
54
-	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
60
+	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
55
 		throw new UnsupportedOperationException("Comparator not supported here");
61
 		throw new UnsupportedOperationException("Comparator not supported here");
56
 	}
62
 	}
57
 
63
 
58
 	@Override
64
 	@Override
59
-	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments) {
65
+	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
60
 		throw new UnsupportedOperationException("Cannot be called statically");
66
 		throw new UnsupportedOperationException("Cannot be called statically");
61
 	}
67
 	}
62
 
68
 
63
 	@Override
69
 	@Override
64
-	public Expression callStaticWithComparator(CodePosition position, ITypeID target, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments) {
70
+	public Expression callStaticWithComparator(CodePosition position, ITypeID target, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
65
 		throw new UnsupportedOperationException("Cannot be called statically");
71
 		throw new UnsupportedOperationException("Cannot be called statically");
66
 	}
72
 	}
67
 
73
 

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

13
 import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
13
 import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.expression.GenericCompareExpression;
15
 import org.openzen.zenscript.codemodel.expression.GenericCompareExpression;
16
+import org.openzen.zenscript.codemodel.scope.TypeScope;
16
 import org.openzen.zenscript.codemodel.statement.Statement;
17
 import org.openzen.zenscript.codemodel.statement.Statement;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.shared.CodePosition;
19
 import org.openzen.zenscript.shared.CodePosition;
43
 	}
44
 	}
44
 
45
 
45
 	@Override
46
 	@Override
46
-	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
47
-		return new CallExpression(position, target, this, instancedHeader, arguments);
47
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
48
+		return new CallExpression(position, target, this, instancedHeader, arguments, scope);
48
 	}
49
 	}
49
 	
50
 	
50
-	public final Expression call(CodePosition position, Expression target, CallArguments arguments) {
51
-		return call(position, target, header, arguments);
51
+	public final Expression call(CodePosition position, Expression target, CallArguments arguments, TypeScope scope) {
52
+		return call(position, target, header, arguments, scope);
52
 	}
53
 	}
53
 	
54
 	
54
 	@Override
55
 	@Override
55
-	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
56
-		return new GenericCompareExpression(position, call(position, target, instancedHeader, arguments), operator);
56
+	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
57
+		return new GenericCompareExpression(position, call(position, target, instancedHeader, arguments, scope), operator);
57
 	}
58
 	}
58
 	
59
 	
59
 	@Override
60
 	@Override
60
-	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments) {
61
-		return new CallStaticExpression(position, target, this, arguments, instancedHeader);
61
+	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
62
+		return new CallStaticExpression(position, target, this, arguments, instancedHeader, scope);
62
 	}
63
 	}
63
 	
64
 	
64
 	@Override
65
 	@Override
65
-	public Expression callStaticWithComparator(CodePosition position, ITypeID target, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments) {
66
-		return new GenericCompareExpression(position, callStatic(position, target, instancedHeader, arguments), operator);
66
+	public Expression callStaticWithComparator(CodePosition position, ITypeID target, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
67
+		return new GenericCompareExpression(position, callStatic(position, target, instancedHeader, arguments, scope), operator);
67
 	}
68
 	}
68
 }
69
 }

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

32
 		this.name = name;
32
 		this.name = name;
33
 		this.type = type;
33
 		this.type = type;
34
 	}
34
 	}
35
+	
36
+	@Override
37
+	public String getInformalName() {
38
+		return "getter " + name;
39
+	}
35
 
40
 
36
 	@Override
41
 	@Override
37
 	public String getName() {
42
 	public String getName() {

+ 7
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICallableMember.java View File

9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.expression.CallArguments;
10
 import org.openzen.zenscript.codemodel.expression.CallArguments;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
+import org.openzen.zenscript.codemodel.scope.TypeScope;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.shared.CodePosition;
14
 import org.openzen.zenscript.shared.CodePosition;
14
 
15
 
19
 public interface ICallableMember extends IDefinitionMember {
20
 public interface ICallableMember extends IDefinitionMember {
20
 	public boolean isStatic();
21
 	public boolean isStatic();
21
 	
22
 	
23
+	public String getInformalName();
24
+	
22
 	public FunctionHeader getHeader();
25
 	public FunctionHeader getHeader();
23
 	
26
 	
24
-	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments);
27
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope);
25
 	
28
 	
26
-	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments);
29
+	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope);
27
 	
30
 	
28
-	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments);
31
+	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope);
29
 	
32
 	
30
-	public Expression callStaticWithComparator(CodePosition position, ITypeID target, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments);
33
+	public Expression callStaticWithComparator(CodePosition position, ITypeID target, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope);
31
 }
34
 }

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

14
 	
14
 	
15
 	public T visitConstructor(ConstructorMember member);
15
 	public T visitConstructor(ConstructorMember member);
16
 	
16
 	
17
+	public T visitDestructor(DestructorMember member);
18
+	
17
 	public T visitMethod(MethodMember member);
19
 	public T visitMethod(MethodMember member);
18
 	
20
 	
19
 	public T visitGetter(GetterMember member);
21
 	public T visitGetter(GetterMember member);

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

23
 	public MethodMember(CodePosition position, HighLevelDefinition definition, int modifiers, String name, FunctionHeader header) {
23
 	public MethodMember(CodePosition position, HighLevelDefinition definition, int modifiers, String name, FunctionHeader header) {
24
 		super(position, definition, modifiers, name, header);
24
 		super(position, definition, modifiers, name, header);
25
 	}
25
 	}
26
+	
27
+	@Override
28
+	public String getInformalName() {
29
+		return name + " method";
30
+	}
26
 
31
 
27
 	@Override
32
 	@Override
28
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
33
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {

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

28
 		
28
 		
29
 		this.operator = operator;
29
 		this.operator = operator;
30
 	}
30
 	}
31
+	
32
+	@Override
33
+	public String getInformalName() {
34
+		return operator.operator + " operator";
35
+	}
31
 
36
 
32
 	@Override
37
 	@Override
33
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
38
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {

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

31
 		this.name = name;
31
 		this.name = name;
32
 		this.type = type;
32
 		this.type = type;
33
 	}
33
 	}
34
+	
35
+	@Override
36
+	public String getInformalName() {
37
+		return "setter " + name;
38
+	}
34
 
39
 
35
 	@Override
40
 	@Override
36
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
41
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {

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

11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.CallTranslator;
12
 import org.openzen.zenscript.codemodel.expression.CallTranslator;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
14
+import org.openzen.zenscript.codemodel.scope.TypeScope;
14
 import org.openzen.zenscript.shared.CodePosition;
15
 import org.openzen.zenscript.shared.CodePosition;
15
 
16
 
16
 /**
17
 /**
27
 	}
28
 	}
28
 
29
 
29
 	@Override
30
 	@Override
30
-	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
31
-		return translator.translate(new CallTranslator.Call(position, target, instancedHeader, arguments));
31
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
32
+		return translator.translate(new CallTranslator.Call(position, target, instancedHeader, arguments, scope));
32
 	}
33
 	}
33
 }
34
 }

+ 10
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ComparatorMember.java View File

12
 import org.openzen.zenscript.codemodel.member.ICallableMember;
12
 import org.openzen.zenscript.codemodel.member.ICallableMember;
13
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
13
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
14
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
15
+import org.openzen.zenscript.codemodel.scope.TypeScope;
15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
36
 	public ComparatorMember(ITypeID type) {
37
 	public ComparatorMember(ITypeID type) {
37
 		header = new FunctionHeader(BasicTypeID.BOOL, new FunctionParameter(type));
38
 		header = new FunctionHeader(BasicTypeID.BOOL, new FunctionParameter(type));
38
 	}
39
 	}
40
+	
41
+	@Override
42
+	public String getInformalName() {
43
+		return "comparator";
44
+	}
39
 
45
 
40
 	@Override
46
 	@Override
41
 	public boolean isStatic() {
47
 	public boolean isStatic() {
48
 	}
54
 	}
49
 
55
 
50
 	@Override
56
 	@Override
51
-	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
57
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
52
 		throw new UnsupportedOperationException("Can't call a comparator");
58
 		throw new UnsupportedOperationException("Can't call a comparator");
53
 	}
59
 	}
54
 
60
 
55
 	@Override
61
 	@Override
56
-	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
62
+	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
57
 		return new BasicCompareExpression(position, target, arguments.arguments[0], operator);
63
 		return new BasicCompareExpression(position, target, arguments.arguments[0], operator);
58
 	}
64
 	}
59
 
65
 
60
 	@Override
66
 	@Override
61
-	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments) {
67
+	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
62
 		throw new UnsupportedOperationException("Can't call a comparator");
68
 		throw new UnsupportedOperationException("Can't call a comparator");
63
 	}
69
 	}
64
 
70
 
65
 	@Override
71
 	@Override
66
-	public Expression callStaticWithComparator(CodePosition position, ITypeID target, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments) {
72
+	public Expression callStaticWithComparator(CodePosition position, ITypeID target, CompareType operator, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
67
 		throw new UnsupportedOperationException("Can't call a comparator statically");
73
 		throw new UnsupportedOperationException("Can't call a comparator statically");
68
 	}
74
 	}
69
 
75
 

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

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, ITypeID[] typeArguments) {
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, method.getInformalName());
28
 		group.addMethod(method, TypeMemberPriority.SPECIFIED);
28
 		group.addMethod(method, TypeMemberPriority.SPECIFIED);
29
 		return new PartialStaticMemberGroupExpression(position, target, group, typeArguments);
29
 		return new PartialStaticMemberGroupExpression(position, target, group, typeArguments);
30
 	}
30
 	}

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.statement;
6
 package org.openzen.zenscript.codemodel.statement;
7
 
7
 
8
-import org.openzen.zenscript.codemodel.type.ITypeID;
8
+import org.openzen.zenscript.shared.CodePosition;
9
 
9
 
10
 /**
10
 /**
11
  *
11
  *
12
  * @author Hoofdgebruiker
12
  * @author Hoofdgebruiker
13
  */
13
  */
14
 public class CatchClause {
14
 public class CatchClause {
15
-	public final String exceptionName;
16
-	public final ITypeID exceptionType;
17
 	public final Statement content;
15
 	public final Statement content;
16
+	public final VarStatement exceptionVariable;
18
 	
17
 	
19
-	public CatchClause(String exceptionName, ITypeID exceptionType, Statement content) {
20
-		this.exceptionName = exceptionName;
21
-		this.exceptionType = exceptionType;
18
+	public CatchClause(CodePosition position, VarStatement exceptionVariable, Statement content) {
19
+		this.exceptionVariable = exceptionVariable;
22
 		this.content = content;
20
 		this.content = content;
23
 	}
21
 	}
24
 }
22
 }

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

44
 		return false;
44
 		return false;
45
 	}
45
 	}
46
 	
46
 	
47
+	@Override
48
+	public boolean isObjectType() {
49
+		return true;
50
+	}
51
+	
47
 	@Override
52
 	@Override
48
 	public ArrayTypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
53
 	public ArrayTypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
49
 		return registry.getArray(elementType.withGenericArguments(registry, arguments), dimension);
54
 		return registry.getArray(elementType.withGenericArguments(registry, arguments), dimension);

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

48
 		return false;
48
 		return false;
49
 	}
49
 	}
50
 	
50
 	
51
+	@Override
52
+	public boolean isObjectType() {
53
+		return true;
54
+	}
55
+	
51
 	@Override
56
 	@Override
52
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
57
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
53
 		return keyType.hasInferenceBlockingTypeParameters(parameters) || valueType.hasInferenceBlockingTypeParameters(parameters);
58
 		return keyType.hasInferenceBlockingTypeParameters(parameters) || valueType.hasInferenceBlockingTypeParameters(parameters);

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

71
 	public boolean isConst() {
71
 	public boolean isConst() {
72
 		return false;
72
 		return false;
73
 	}
73
 	}
74
+	
75
+	@Override
76
+	public boolean isObjectType() {
77
+		return this == ANY || this == STRING;
78
+	}
74
 
79
 
75
 	@Override
80
 	@Override
76
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
81
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

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

55
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
55
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
56
 		return baseType.hasInferenceBlockingTypeParameters(parameters);
56
 		return baseType.hasInferenceBlockingTypeParameters(parameters);
57
 	}
57
 	}
58
+	
59
+	@Override
60
+	public boolean isObjectType() {
61
+		return baseType.isObjectType();
62
+	}
58
 
63
 
59
 	@Override
64
 	@Override
60
 	public int hashCode() {
65
 	public int hashCode() {

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

54
 			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));
55
 		}
55
 		}
56
 		
56
 		
57
-		if ((typeParameters == null ? 0 : typeParameters.length) != definition.getNumberOfGenericParameters())
58
-			throw new RuntimeException("Invalid number of type parameters");
57
+		//if ((typeParameters == null ? 0 : typeParameters.length) != definition.getNumberOfGenericParameters())
58
+		//	throw new RuntimeException("Invalid number of type parameters");
59
 	}
59
 	}
60
 	
60
 	
61
 	public boolean hasTypeParameters() {
61
 	public boolean hasTypeParameters() {
92
 		if (typeParameters != null) {
92
 		if (typeParameters != null) {
93
 			instancedArguments = new ITypeID[typeParameters.length];
93
 			instancedArguments = new ITypeID[typeParameters.length];
94
 			for (int i = 0; i < typeParameters.length; i++) {
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);
95
+				// TODO: why was this line written like this?
96
+				//instancedArguments[i] = arguments.containsKey(definition.genericParameters[i]) ? arguments.get(definition.genericParameters[i]) : typeParameters[i].withGenericArguments(registry, arguments);
97
+				instancedArguments[i] = typeParameters[i].withGenericArguments(registry, arguments);
96
 			}
98
 			}
97
 		}
99
 		}
98
 		
100
 		
131
 	public boolean isConst() {
133
 	public boolean isConst() {
132
 		return false;
134
 		return false;
133
 	}
135
 	}
136
+	
137
+	@Override
138
+	public boolean isObjectType() {
139
+		return true;
140
+	}
134
 
141
 
135
 	@Override
142
 	@Override
136
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
143
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

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

46
 	public boolean isConst() {
46
 	public boolean isConst() {
47
 		return false;
47
 		return false;
48
 	}
48
 	}
49
+	
50
+	@Override
51
+	public boolean isObjectType() {
52
+		return true;
53
+	}
49
 
54
 
50
 	@Override
55
 	@Override
51
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
56
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

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

58
 		return true;
58
 		return true;
59
 	}
59
 	}
60
 	
60
 	
61
+	@Override
62
+	public boolean isObjectType() {
63
+		return true;
64
+	}
65
+	
61
 	@Override
66
 	@Override
62
 	public String toString() {
67
 	public String toString() {
63
 		StringBuilder result = new StringBuilder();
68
 		StringBuilder result = new StringBuilder();

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

48
 	public boolean isConst() {
48
 	public boolean isConst() {
49
 		return false;
49
 		return false;
50
 	}
50
 	}
51
+	
52
+	@Override
53
+	public boolean isObjectType() {
54
+		return parameter.isObjectType();
55
+	}
51
 
56
 
52
 	@Override
57
 	@Override
53
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
58
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

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

13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_CONST;
14
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_CONST;
15
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_OPTIONAL;
15
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_OPTIONAL;
16
-import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_SHARED;
17
-import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_WEAK;
18
 
16
 
19
 /**
17
 /**
20
  *
18
  *
160
 			return getModified(modifiers & ~MODIFIER_OPTIONAL, getOptional(type));
158
 			return getModified(modifiers & ~MODIFIER_OPTIONAL, getOptional(type));
161
 		if ((modifiers & MODIFIER_CONST) > 0)
159
 		if ((modifiers & MODIFIER_CONST) > 0)
162
 			return getModified(modifiers & ~MODIFIER_CONST, getConst(type));
160
 			return getModified(modifiers & ~MODIFIER_CONST, getConst(type));
163
-		if ((modifiers & MODIFIER_SHARED) > 0)
164
-			throw new UnsupportedOperationException();
165
-		if ((modifiers & MODIFIER_WEAK) > 0)
166
-			throw new UnsupportedOperationException();
167
 		
161
 		
168
 		throw new UnsupportedOperationException();
162
 		throw new UnsupportedOperationException();
169
 	}
163
 	}

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

36
 	
36
 	
37
 	public boolean hasDefaultValue();
37
 	public boolean hasDefaultValue();
38
 	
38
 	
39
+	public boolean isObjectType();
40
+	
39
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
41
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
40
 	
42
 	
41
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);
43
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);

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

40
 	public boolean isConst() {
40
 	public boolean isConst() {
41
 		return false;
41
 		return false;
42
 	}
42
 	}
43
+	
44
+	@Override
45
+	public boolean isObjectType() {
46
+		return true;
47
+	}
43
 
48
 
44
 	@Override
49
 	@Override
45
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
50
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {

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

51
 		return false;
51
 		return false;
52
 	}
52
 	}
53
 	
53
 	
54
+	@Override
55
+	public boolean isObjectType() {
56
+		return baseType.isObjectType();
57
+	}
58
+	
54
 	@Override
59
 	@Override
55
 	public ITypeID unwrap() {
60
 	public ITypeID unwrap() {
56
 		return baseType;
61
 		return baseType;

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

49
 	public boolean isConst() {
49
 	public boolean isConst() {
50
 		return false;
50
 		return false;
51
 	}
51
 	}
52
+	
53
+	@Override
54
+	public boolean isObjectType() {
55
+		return false;
56
+	}
52
 
57
 
53
 	@Override
58
 	@Override
54
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
59
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

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

38
  */
38
  */
39
 public class DefinitionMemberGroup {
39
 public class DefinitionMemberGroup {
40
 	public static DefinitionMemberGroup forMethod(ICallableMember member) {
40
 	public static DefinitionMemberGroup forMethod(ICallableMember member) {
41
-		DefinitionMemberGroup instance = new DefinitionMemberGroup(member.isStatic());
41
+		DefinitionMemberGroup instance = new DefinitionMemberGroup(member.isStatic(), member.getInformalName());
42
 		instance.addMethod(member, TypeMemberPriority.SPECIFIED);
42
 		instance.addMethod(member, TypeMemberPriority.SPECIFIED);
43
 		return instance;
43
 		return instance;
44
 	}
44
 	}
48
 	private TypeMember<SetterMember> setter;
48
 	private TypeMember<SetterMember> setter;
49
 	private final List<TypeMember<ICallableMember>> methods = new ArrayList<>();
49
 	private final List<TypeMember<ICallableMember>> methods = new ArrayList<>();
50
 	public final boolean isStatic;
50
 	public final boolean isStatic;
51
+	public final String name;
51
 	
52
 	
52
-	public DefinitionMemberGroup(boolean isStatic) {
53
+	public DefinitionMemberGroup(boolean isStatic, String name) {
53
 		this.isStatic = isStatic;
54
 		this.isStatic = isStatic;
55
+		this.name = name;
54
 	}
56
 	}
55
 	
57
 	
56
 	public void merge(CodePosition position, DefinitionMemberGroup other, TypeMemberPriority priority) {
58
 	public void merge(CodePosition position, DefinitionMemberGroup other, TypeMemberPriority priority) {
241
 			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
243
 			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
242
 		}
244
 		}
243
 		
245
 		
244
-		return method.call(position, target, instancedHeader, arguments);
246
+		return method.call(position, target, instancedHeader, arguments, scope);
245
 	}
247
 	}
246
 	
248
 	
247
 	public Expression callPostfix(CodePosition position, TypeScope scope, Expression target) {
249
 	public Expression callPostfix(CodePosition position, TypeScope scope, Expression target) {
264
 			CompareType compareType) {
266
 			CompareType compareType) {
265
 		ICallableMember method = selectMethod(position, scope, arguments, true, false);
267
 		ICallableMember method = selectMethod(position, scope, arguments, true, false);
266
 		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
268
 		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
267
-		return method.callWithComparator(position, compareType, target, instancedHeader, arguments);
269
+		return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
268
 	}
270
 	}
269
 	
271
 	
270
 	public Expression callStatic(CodePosition position, ITypeID target, TypeScope scope, CallArguments arguments) {
272
 	public Expression callStatic(CodePosition position, ITypeID target, TypeScope scope, CallArguments arguments) {
271
 		ICallableMember method = selectMethod(position, scope, arguments, false, true);
273
 		ICallableMember method = selectMethod(position, scope, arguments, false, true);
272
 		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
274
 		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
273
-		return method.callStatic(position, target, instancedHeader, arguments);
275
+		return method.callStatic(position, target, instancedHeader, arguments, scope);
274
 	}
276
 	}
275
 	
277
 	
276
 	public Expression callStaticWithComparator(
278
 	public Expression callStaticWithComparator(
281
 			CompareType compareType) {
283
 			CompareType compareType) {
282
 		ICallableMember method = selectMethod(position, scope, arguments, false, true);
284
 		ICallableMember method = selectMethod(position, scope, arguments, false, true);
283
 		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
285
 		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
284
-		return method.callStaticWithComparator(position, target, compareType, instancedHeader, arguments);
286
+		return method.callStaticWithComparator(position, target, compareType, instancedHeader, arguments, scope);
285
 	}
287
 	}
286
 	
288
 	
287
 	public ICallableMember selectMethod(CodePosition position, TypeScope scope, CallArguments arguments, boolean allowNonStatic, boolean allowStatic) {
289
 	public ICallableMember selectMethod(CodePosition position, TypeScope scope, CallArguments arguments, boolean allowNonStatic, boolean allowStatic) {
342
 		if (selected == null) {
344
 		if (selected == null) {
343
 			// let's figure out why this didn't work out
345
 			// let's figure out why this didn't work out
344
 			StringBuilder message = new StringBuilder();
346
 			StringBuilder message = new StringBuilder();
347
+			if (methods.isEmpty()) {
348
+				throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "This type has no " + name);
349
+			}
350
+			
345
 			outer: for (TypeMember<ICallableMember> method : methods) {
351
 			outer: for (TypeMember<ICallableMember> method : methods) {
346
 				if (!(method.member.isStatic() ? allowStatic : allowNonStatic)) {
352
 				if (!(method.member.isStatic() ? allowStatic : allowNonStatic)) {
347
 					message.append(method.member.isStatic() ? "Method must not be static" : "Method must be static").append('\n');
353
 					message.append(method.member.isStatic() ? "Method must not be static" : "Method must be static").append('\n');
351
 				message.append(method.member.getHeader().explainWhyIncompatible(scope, arguments)).append("\n");
357
 				message.append(method.member.getHeader().explainWhyIncompatible(scope, arguments)).append("\n");
352
 			}
358
 			}
353
 			
359
 			
354
-			throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "No matching method found:\n" + message.toString());
360
+			throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "No matching method found for " + name + ":\n" + message.toString());
355
 		}
361
 		}
356
 		
362
 		
357
 		return selected;
363
 		return selected;

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

40
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
40
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
41
 import org.openzen.zenscript.codemodel.member.builtin.RangeIterator;
41
 import org.openzen.zenscript.codemodel.member.builtin.RangeIterator;
42
 import org.openzen.zenscript.codemodel.member.builtin.StringCharIterator;
42
 import org.openzen.zenscript.codemodel.member.builtin.StringCharIterator;
43
+import org.openzen.zenscript.codemodel.scope.TypeScope;
43
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
44
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
44
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
45
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
45
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
46
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
161
 		}
162
 		}
162
 
163
 
163
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL), TypeMemberPriority.SPECIFIED);
164
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL), TypeMemberPriority.SPECIFIED);
165
+		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
164
 		members.addIterator(new ArrayIteratorKeyValues(array), TypeMemberPriority.SPECIFIED);
166
 		members.addIterator(new ArrayIteratorKeyValues(array), TypeMemberPriority.SPECIFIED);
165
 		members.addIterator(new ArrayIteratorValues(array), TypeMemberPriority.SPECIFIED);
167
 		members.addIterator(new ArrayIteratorValues(array), TypeMemberPriority.SPECIFIED);
166
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "clear", new FunctionHeader(VOID)), TypeMemberPriority.SPECIFIED);
168
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "clear", new FunctionHeader(VOID)), TypeMemberPriority.SPECIFIED);
190
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "size", INT));
192
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "size", INT));
191
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL));
193
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL));
192
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "keys", cache.getRegistry().getArray(keyType, 1)));
194
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "keys", cache.getRegistry().getArray(keyType, 1)));
195
+		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
193
 		
196
 		
194
 		members.addIterator(new AssocIterator(assoc), TypeMemberPriority.SPECIFIED);
197
 		members.addIterator(new AssocIterator(assoc), TypeMemberPriority.SPECIFIED);
195
 		return null;
198
 		return null;
204
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOptional", new FunctionHeader(map.keys, registry.getOptional(valueType), new FunctionParameter[0])));
207
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOptional", new FunctionHeader(map.keys, registry.getOptional(valueType), new FunctionParameter[0])));
205
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, new FunctionParameter(valueType))));
208
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, new FunctionParameter(valueType))));
206
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "contains", new FunctionHeader(map.keys, BasicTypeID.BOOL, new FunctionParameter[0])));
209
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "contains", new FunctionHeader(map.keys, BasicTypeID.BOOL, new FunctionParameter[0])));
210
+		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
207
 		return null;
211
 		return null;
208
 	}
212
 	}
209
 	
213
 	
228
 				for (int i = 0; i < type.typeParameters.length; i++)
232
 				for (int i = 0; i < type.typeParameters.length; i++)
229
 					mapping.put(definition.genericParameters[i], type.typeParameters[i]);
233
 					mapping.put(definition.genericParameters[i], type.typeParameters[i]);
230
 			
234
 			
231
-			for (Map.Entry<TypeParameter, ITypeID> entry : type.outerTypeParameters.entrySet())
232
-				mapping.put(entry.getKey(), entry.getValue());
235
+			if (!type.definition.isStatic())
236
+				for (Map.Entry<TypeParameter, ITypeID> entry : type.outerTypeParameters.entrySet())
237
+					mapping.put(entry.getKey(), entry.getValue());
233
 			
238
 			
234
 			for (IDefinitionMember member : definition.members) {
239
 			for (IDefinitionMember member : definition.members) {
235
 				member.instance(cache.getRegistry(), mapping).registerTo(members, TypeMemberPriority.SPECIFIED);
240
 				member.instance(cache.getRegistry(), mapping).registerTo(members, TypeMemberPriority.SPECIFIED);
273
 			}
278
 			}
274
 		}
279
 		}
275
 		
280
 		
281
+		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
276
 		return null;
282
 		return null;
277
 	}
283
 	}
278
 
284
 
516
 	}
522
 	}
517
 	
523
 	
518
 	private static CallTranslator castedTargetCall(FunctionalMember member, CasterMember caster) {
524
 	private static CallTranslator castedTargetCall(FunctionalMember member, CasterMember caster) {
519
-		return call -> member.call(call.position, caster.cast(call.position, call.target, true), call.arguments);
525
+		return call -> member.call(call.position, caster.cast(call.position, call.target, true), call.arguments, call.scope);
520
 	}
526
 	}
521
 }
527
 }

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

18
 import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
18
 import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
19
 import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
19
 import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
20
 import org.openzen.zenscript.codemodel.expression.NullExpression;
20
 import org.openzen.zenscript.codemodel.expression.NullExpression;
21
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
22
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
21
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
23
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
22
 import org.openzen.zenscript.codemodel.member.CallerMember;
24
 import org.openzen.zenscript.codemodel.member.CallerMember;
23
 import org.openzen.zenscript.codemodel.member.CasterMember;
25
 import org.openzen.zenscript.codemodel.member.CasterMember;
24
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
26
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
27
+import org.openzen.zenscript.codemodel.member.DestructorMember;
25
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
28
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
26
 import org.openzen.zenscript.codemodel.member.FieldMember;
29
 import org.openzen.zenscript.codemodel.member.FieldMember;
27
 import org.openzen.zenscript.codemodel.member.ICallableMember;
30
 import org.openzen.zenscript.codemodel.member.ICallableMember;
54
 public final class TypeMembers {
57
 public final class TypeMembers {
55
 	public static final int MODIFIER_OPTIONAL = 1;
58
 	public static final int MODIFIER_OPTIONAL = 1;
56
 	public static final int MODIFIER_CONST = 2;
59
 	public static final int MODIFIER_CONST = 2;
57
-	public static final int MODIFIER_SHARED = 4;
58
-	public static final int MODIFIER_WEAK = 8;
59
 	
60
 	
60
 	private final LocalMemberCache cache;
61
 	private final LocalMemberCache cache;
61
 	public final ITypeID type;
62
 	public final ITypeID type;
88
 		}
89
 		}
89
 		
90
 		
90
 		for (TypeMember<ImplementationMember> implementation : implementations) {
91
 		for (TypeMember<ImplementationMember> implementation : implementations) {
91
-			if (implementation.member.type == other)
92
+			if (implementation.member.type.equals(other)) // TODO: for some reason duplicate types are generated
92
 				return true;
93
 				return true;
93
 			if (cache.get(implementation.member.type).extendsOrImplements(other))
94
 			if (cache.get(implementation.member.type).extendsOrImplements(other))
94
 				return true;
95
 				return true;
97
 		return false;
98
 		return false;
98
 	}
99
 	}
99
 	
100
 	
101
+	public boolean extendsType(ITypeID other) {
102
+		ITypeID superType = type.getSuperType();
103
+		if (superType != null) {
104
+			if (superType == other)
105
+				return true;
106
+			if (cache.get(superType).extendsType(other))
107
+				return true;
108
+		}
109
+		
110
+		return false;
111
+	}
112
+	
100
 	public GlobalTypeRegistry getTypeRegistry() {
113
 	public GlobalTypeRegistry getTypeRegistry() {
101
 		return cache.getRegistry();
114
 		return cache.getRegistry();
102
 	}
115
 	}
135
 		getOrCreateGroup(OperatorType.CONSTRUCTOR).addMethod(constructor, TypeMemberPriority.SPECIFIED);
148
 		getOrCreateGroup(OperatorType.CONSTRUCTOR).addMethod(constructor, TypeMemberPriority.SPECIFIED);
136
 	}
149
 	}
137
 	
150
 	
151
+	public void addDestructor(DestructorMember destructor, TypeMemberPriority priority) {
152
+		getOrCreateGroup(OperatorType.DESTRUCTOR).addMethod(destructor, priority);
153
+	}
154
+	
138
 	public void addCaller(CallerMember caller, TypeMemberPriority priority) {
155
 	public void addCaller(CallerMember caller, TypeMemberPriority priority) {
139
 		getOrCreateGroup(OperatorType.CALL).addMethod(caller, priority);
156
 		getOrCreateGroup(OperatorType.CALL).addMethod(caller, priority);
140
 	}
157
 	}
232
 	
249
 	
233
 	public DefinitionMemberGroup getOrCreateGroup(String name, boolean isStatic) {
250
 	public DefinitionMemberGroup getOrCreateGroup(String name, boolean isStatic) {
234
 		if (!members.containsKey(name))
251
 		if (!members.containsKey(name))
235
-			members.put(name, new DefinitionMemberGroup(isStatic));
252
+			members.put(name, new DefinitionMemberGroup(isStatic, name));
236
 		
253
 		
237
 		return members.get(name);
254
 		return members.get(name);
238
 	}
255
 	}
239
 	
256
 	
240
 	public DefinitionMemberGroup getOrCreateGroup(OperatorType operator) {
257
 	public DefinitionMemberGroup getOrCreateGroup(OperatorType operator) {
241
 		if (!operators.containsKey(operator))
258
 		if (!operators.containsKey(operator))
242
-			operators.put(operator, new DefinitionMemberGroup(false));
259
+			operators.put(operator, new DefinitionMemberGroup(false, operator.operator + " operator"));
243
 		
260
 		
244
 		return operators.get(operator);
261
 		return operators.get(operator);
245
 	}
262
 	}
256
 	}
273
 	}
257
 	
274
 	
258
 	public Expression compare(CodePosition position, TypeScope scope, CompareType operator, Expression left, Expression right) {
275
 	public Expression compare(CodePosition position, TypeScope scope, CompareType operator, Expression left, Expression right) {
259
-		if (operator == CompareType.EQ) {
276
+		if (operator == CompareType.SAME) {
277
+			if (left.type.isObjectType() && right.type.isObjectType())
278
+				return new SameObjectExpression(position, left, right, false);
279
+			else
280
+				return compare(position, scope, CompareType.EQ, left, right);
281
+		} else if (operator == CompareType.NOTSAME) {
282
+			if (left.type.isObjectType() && right.type.isObjectType())
283
+				return new SameObjectExpression(position, left, right, true);
284
+			else
285
+				return compare(position, scope, CompareType.NE, left, right);
286
+		} else if (operator == CompareType.EQ) {
260
 			DefinitionMemberGroup equal = getOrCreateGroup(OperatorType.EQUALS);
287
 			DefinitionMemberGroup equal = getOrCreateGroup(OperatorType.EQUALS);
261
 			for (TypeMember<ICallableMember> member : equal.getMethodMembers()) {
288
 			for (TypeMember<ICallableMember> member : equal.getMethodMembers()) {
262
 				if (member.member.getHeader().accepts(scope, right))
289
 				if (member.member.getHeader().accepts(scope, right))
267
 			for (TypeMember<ICallableMember> member : equal.getMethodMembers()) {
294
 			for (TypeMember<ICallableMember> member : equal.getMethodMembers()) {
268
 				if (member.member.getHeader().accepts(scope, right)) {
295
 				if (member.member.getHeader().accepts(scope, right)) {
269
 					Expression equalExpression = equal.call(position, scope, left, new CallArguments(right), false);
296
 					Expression equalExpression = equal.call(position, scope, left, new CallArguments(right), false);
270
-					return new CallExpression(position, equalExpression, BuiltinTypeMembers.BOOL_NOT, BuiltinTypeMembers.BOOL_NOT.header, CallArguments.EMPTY);
297
+					return new CallExpression(position, equalExpression, BuiltinTypeMembers.BOOL_NOT, BuiltinTypeMembers.BOOL_NOT.header, CallArguments.EMPTY, scope);
271
 				}
298
 				}
272
 			}
299
 			}
273
 		}
300
 		}
323
 			if (caster.member.isImplicit() && toType == caster.member.getTargetType())
350
 			if (caster.member.isImplicit() && toType == caster.member.getTargetType())
324
 				return true;
351
 				return true;
325
 		}
352
 		}
326
-		for (TypeMember<ImplementationMember> implementation : implementations) {
327
-			if (implementation.member.type == toType)
328
-				return true;
329
-		}
330
 		
353
 		
331
-		return false;
354
+		return extendsOrImplements(toType);
332
 	}
355
 	}
333
 	
356
 	
334
 	public boolean canCast(ITypeID toType) {
357
 	public boolean canCast(ITypeID toType) {
363
 				return caster.member.cast(position, value, implicit);
386
 				return caster.member.cast(position, value, implicit);
364
 		}
387
 		}
365
 		for (TypeMember<ImplementationMember> implementation : implementations) {
388
 		for (TypeMember<ImplementationMember> implementation : implementations) {
366
-			if (implementation.member.type == toType)
389
+			if (implementation.member.type.equals(toType))
367
 				return new InterfaceCastExpression(position, value, toType);
390
 				return new InterfaceCastExpression(position, value, toType);
368
 		}
391
 		}
392
+		if (extendsType(toType))
393
+			return new SupertypeCastExpression(position, value, toType);
369
 		
394
 		
370
 		throw new CompileException(position, CompileExceptionCode.INVALID_CAST, "Could not cast " + toString() + " to " + toType);
395
 		throw new CompileException(position, CompileExceptionCode.INVALID_CAST, "Could not cast " + toString() + " to " + toType);
371
 	}
396
 	}

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

3
 		add(value as T) as bool;
3
 		add(value as T) as bool;
4
 		remove(value as T) as bool;
4
 		remove(value as T) as bool;
5
 		
5
 		
6
+		get size as int;
7
+		
6
 		in(value as T) as bool;
8
 		in(value as T) as bool;
7
 		for(x as T);
9
 		for(x as T);
8
 	}
10
 	}

+ 35
- 5
Constructor/libraries/collections/src/LinkedList.zs View File

1
 export class LinkedList<T> {
1
 export class LinkedList<T> {
2
 	var first as Node?;
2
 	var first as Node?;
3
 	var last as Node?;
3
 	var last as Node?;
4
+	var size as int : get;
4
 	
5
 	
5
 	public get empty as bool
6
 	public get empty as bool
6
 		=> first == null;
7
 		=> first == null;
14
 			node.prev = last;
15
 			node.prev = last;
15
 			last = node;
16
 			last = node;
16
 		}
17
 		}
18
+		size++;
17
 	}
19
 	}
18
 	
20
 	
19
-	public implements Queue<T> {
20
-		poll() as T?
21
-			=> first == null ? null : first.value;
21
+	public clear() as void {
22
+		first = last = null;
23
+		size = 0;
24
+	}
25
+	
26
+	public [](index as int) as T {
27
+		var node = first;
28
+		while index > 0 {
29
+			if node == null
30
+				throw new NoSuchElementException("index out of bounds");
31
+			
32
+			node = node.next;
33
+		}
34
+		
35
+		if node == null
36
+			throw new NoSuchElementException("index out of bounds");
22
 		
37
 		
23
-		peek() as T {
38
+		return node.value;
39
+	}
40
+	
41
+	public implements Queue<T> {
42
+		poll() as T {
24
 			if first == null
43
 			if first == null
25
-				throw new NoSuchElementException("Cannot peek an empty queue");
44
+				throw new NoSuchElementException("Cannot poll an empty queue");
26
 			
45
 			
46
+			val result = first.value;
47
+			first = first.next;
48
+			if first == null
49
+				last = null;
50
+			else
51
+				first.prev = null;
52
+				
53
+			size--;
54
+		}
55
+		
56
+		peek() as T? {
27
 			return first.value;
57
 			return first.value;
28
 		}
58
 		}
29
 		
59
 		

+ 5
- 1
Constructor/libraries/collections/src/Set.zs View File

2
 	add(value as T) as bool;
2
 	add(value as T) as bool;
3
 	remove(value as T) as bool;
3
 	remove(value as T) as bool;
4
 	
4
 	
5
-	in(value as T) as bool;
5
+	get size as int;
6
+	
7
+	toArray();
8
+	toArray(comparator as function(a as T, b as T) as int);
6
 	
9
 	
10
+	in(value as T) as bool;
7
 	for(x as T);
11
 	for(x as T);
8
 }
12
 }

+ 21
- 0
Constructor/libraries/collections/src/Stack.zs View File

1
+export class Stack<T> {
2
+	var values as T[] = new T[](8);
3
+	var size as int : get = 0;
4
+	
5
+	public push(value as T) as void {
6
+		if size == values.length
7
+			values = values.copy(values.length * 2);
8
+			
9
+		values[size++] = value;
10
+	}
11
+	
12
+	public pop() as T {
13
+		if size == 0
14
+			throw new NoSuchElementException("Stack is empty!");
15
+		
16
+		return values[--size];
17
+	}
18
+	
19
+	public get empty as bool
20
+		=> size == 0;
21
+}

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

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

+ 10
- 0
Constructor/libraries/io/src/Reader.zs View File

1
+export interface Reader {
2
+	~this;
3
+	
4
+	read() as int;
5
+	
6
+	read(buffer as char[]) as int
7
+		=> read(buffer, 0, buffer.length);
8
+	
9
+	read(buffer as char[], offset as int, length as int) as int;
10
+}

+ 22
- 0
Constructor/libraries/io/src/StringReader.zs View File

1
+export class StringReader {
2
+	val data as char[];
3
+	var offset as int;
4
+	
5
+	public this(value as string) {
6
+		data = value.characters;
7
+	}
8
+	
9
+	public implements Reader {
10
+		~this {}
11
+	
12
+		read() as int
13
+			=> offset == data.length ? -1 : data[offset++];
14
+	
15
+		read(buffer as char[], offset as int, length as int) as int {
16
+			length = int.min(data.length - this.offset, length);
17
+			data.copyTo(buffer, this.offset, offset, length);
18
+			this.offset += length;
19
+			return length;
20
+		}
21
+	}
22
+}

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

4
 	"globals": {
4
 	"globals": {
5
 		"Comparable": {"type": "Definition", "definition": "Comparable"},
5
 		"Comparable": {"type": "Definition", "definition": "Comparable"},
6
 		"Exception": {"type": "Definition", "definition": "Exception"},
6
 		"Exception": {"type": "Definition", "definition": "Exception"},
7
+		"Hashable": {"type": "Definition", "definition": "Hashable"},
7
 		"IllegalArgumentException": {"type": "Definition", "definition": "IllegalArgumentException"},
8
 		"IllegalArgumentException": {"type": "Definition", "definition": "IllegalArgumentException"},
8
 		"StringBuilder": {"type": "Definition", "definition": "StringBuilder"},
9
 		"StringBuilder": {"type": "Definition", "definition": "StringBuilder"},
9
 		"StringBuildable": {"type": "Definition", "definition": "StringBuildable"}
10
 		"StringBuildable": {"type": "Definition", "definition": "StringBuildable"}

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

1
+export expand <T : Comparable<T>> T[] {
2
+	public extern sort() as void;
3
+	public extern sorted() as T[];
4
+}
5
+
6
+export expand <T : Hashable<T>> T[] {
7
+	public implements Hashable<T[]> {
8
+		public extern hashCode() as int;
9
+		public extern == (other as T) as bool;
10
+	}
11
+}
12
+
13
+export expand <T> T[] {
14
+	public extern sort(comparator as function(a as T, b as T) as int) as void;
15
+	public extern sorted(comparator as function(a as T, b as T) as int) as T[];
16
+	public extern copy() as T[];
17
+	public extern copy(newSize as int) as T[];
18
+	public extern copyTo(target as T[], sourceOffset as int, targetOffset as int, length as int) as void;
19
+}

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

1
 export virtual class Exception {
1
 export virtual class Exception {
2
-	public this(message as string) {
3
-	}
2
+	public this(message as string) {}
3
+	public this(message as string, cause as Exception) {}
4
 }
4
 }

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

1
+public interface Hashable<T> {
2
+	hashCode() as int;
3
+	== (other as T) as bool;
4
+}

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

2
 	public extern toHexString() as string;
2
 	public extern toHexString() as string;
3
 	public static extern parse(value as string) as int;
3
 	public static extern parse(value as string) as int;
4
 	public static extern parse(value as string, radix as int) as int;
4
 	public static extern parse(value as string, radix as int) as int;
5
+	
6
+	public static min(a as int, b as int) as int
7
+		=> a < b ? a : b;
8
+	public static max(a as int, b as int) as int
9
+		=> a > b ? a : b;
5
 }
10
 }

+ 2
- 0
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 get empty as bool;
7
+	
6
 	public extern <<(value as bool) as StringBuilder;
8
 	public extern <<(value as bool) as StringBuilder;
7
 	public extern <<(value as char) as StringBuilder;
9
 	public extern <<(value as char) as StringBuilder;
8
 	public extern <<(value as byte) as StringBuilder;
10
 	public extern <<(value as byte) as StringBuilder;

+ 3
- 5
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java View File

20
 import org.openzen.zenscript.codemodel.ScriptBlock;
20
 import org.openzen.zenscript.codemodel.ScriptBlock;
21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
22
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
22
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
23
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
24
 import org.openzen.zenscript.constructor.module.ModuleSpace;
23
 import org.openzen.zenscript.constructor.module.ModuleSpace;
25
 import org.openzen.zenscript.constructor.module.SemanticModule;
24
 import org.openzen.zenscript.constructor.module.SemanticModule;
26
 import org.openzen.zenscript.linker.symbol.ISymbol;
25
 import org.openzen.zenscript.linker.symbol.ISymbol;
88
 		Map<String, ISymbol> globals = registry.collectGlobals();
87
 		Map<String, ISymbol> globals = registry.collectGlobals();
89
 		boolean failed = false;
88
 		boolean failed = false;
90
 		
89
 		
91
-		GlobalTypeRegistry globalRegistry = new GlobalTypeRegistry();
92
 		for (ParsedFile file : files) {
90
 		for (ParsedFile file : files) {
93
 			// compileMembers will register all definition members to their
91
 			// compileMembers will register all definition members to their
94
 			// respective definitions, such as fields, constructors, methods...
92
 			// respective definitions, such as fields, constructors, methods...
95
 			// It doesn't yet compile the method contents.
93
 			// It doesn't yet compile the method contents.
96
 			try {
94
 			try {
97
-				file.compileTypes(rootPackage, definitions, globalRegistry, expansions, globals);
95
+				file.compileTypes(rootPackage, definitions, registry.typeRegistry, expansions, globals);
98
 			} catch (CompileException ex) {
96
 			} catch (CompileException ex) {
99
 				System.out.println(ex.getMessage());
97
 				System.out.println(ex.getMessage());
100
 				failed = true;
98
 				failed = true;
109
 			// respective definitions, such as fields, constructors, methods...
107
 			// respective definitions, such as fields, constructors, methods...
110
 			// It doesn't yet compile the method contents.
108
 			// It doesn't yet compile the method contents.
111
 			try {
109
 			try {
112
-				file.compileMembers(rootPackage, definitions, globalRegistry, expansions, globals);
110
+				file.compileMembers(rootPackage, definitions, registry.typeRegistry, expansions, globals);
113
 			} catch (CompileException ex) {
111
 			} catch (CompileException ex) {
114
 				System.out.println(ex.getMessage());
112
 				System.out.println(ex.getMessage());
115
 				failed = true;
113
 				failed = true;
126
 			// into semantic code. This semantic code can then be compiled
124
 			// into semantic code. This semantic code can then be compiled
127
 			// to various targets.
125
 			// to various targets.
128
 			try {
126
 			try {
129
-				file.compileCode(rootPackage, definitions, globalRegistry, expansions, scripts, globals);
127
+				file.compileCode(rootPackage, definitions, registry.typeRegistry, expansions, scripts, globals);
130
 			} catch (CompileException ex) {
128
 			} catch (CompileException ex) {
131
 				System.out.println(ex.getMessage());
129
 				System.out.println(ex.getMessage());
132
 				failed = true;
130
 				failed = true;

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

11
 import java.util.Map;
11
 import java.util.Map;
12
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
12
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
13
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
13
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14
 import org.openzen.zenscript.constructor.ConstructorException;
15
 import org.openzen.zenscript.constructor.ConstructorException;
15
 import org.openzen.zenscript.linker.symbol.ISymbol;
16
 import org.openzen.zenscript.linker.symbol.ISymbol;
16
 
17
 
19
  * @author Hoofdgebruiker
20
  * @author Hoofdgebruiker
20
  */
21
  */
21
 public class ModuleSpace {
22
 public class ModuleSpace {
23
+	public final GlobalTypeRegistry typeRegistry = new GlobalTypeRegistry();
22
 	public final ZSPackage globalsPackage = new ZSPackage("");
24
 	public final ZSPackage globalsPackage = new ZSPackage("");
23
 	private final ZSPackage rootPackage = new ZSPackage("");
25
 	private final ZSPackage rootPackage = new ZSPackage("");
24
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
26
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();

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

468
 
468
 
469
     @Override
469
     @Override
470
     public Void visitRange(RangeExpression expression) {
470
     public Void visitRange(RangeExpression expression) {
471
+		// TODO: there are other kinds of ranges also; there should be a Range<T, T> type with creation of synthetic types
471
         if (expression.from.type.accept(JavaTypeClassVisitor.INSTANCE) != int.class)
472
         if (expression.from.type.accept(JavaTypeClassVisitor.INSTANCE) != int.class)
472
             throw new CompileException(expression.position, CompileExceptionCode.INTERNAL_ERROR, "Only integer ranges supported");
473
             throw new CompileException(expression.position, CompileExceptionCode.INTERNAL_ERROR, "Only integer ranges supported");
474
+		
473
         javaWriter.newObject(IntRange.class);
475
         javaWriter.newObject(IntRange.class);
474
         javaWriter.dup();
476
         javaWriter.dup();
475
         expression.from.accept(this);
477
         expression.from.accept(this);
479
 
481
 
480
         return null;
482
         return null;
481
     }
483
     }
484
+	
485
+	@Override
486
+	public Void visitSameObject(SameObjectExpression expression) {
487
+		expression.left.accept(this);
488
+		expression.right.accept(this);
489
+		
490
+		Label end = new Label();
491
+		Label equal = new Label();
492
+		
493
+		if (expression.inverted)
494
+			javaWriter.ifACmpNe(equal);
495
+		else
496
+			javaWriter.ifACmpEq(equal);
497
+		javaWriter.iConst0();
498
+		javaWriter.goTo(end);
499
+		javaWriter.label(equal);
500
+		javaWriter.iConst1();
501
+		javaWriter.label(end);
502
+		return null;
503
+	}
482
 
504
 
483
     @Override
505
     @Override
484
     public Void visitSetField(SetFieldExpression expression) {
506
     public Void visitSetField(SetFieldExpression expression) {
534
     public Void visitStaticSetter(StaticSetterExpression expression) {
556
     public Void visitStaticSetter(StaticSetterExpression expression) {
535
         return null;
557
         return null;
536
     }
558
     }
559
+	
560
+	@Override
561
+	public Void visitSupertypeCast(SupertypeCastExpression expression) {
562
+		return null; // nothing to do
563
+	}
537
 
564
 
538
     @Override
565
     @Override
539
     public Void visitThis(ThisExpression expression) {
566
     public Void visitThis(ThisExpression expression) {

+ 12
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java View File

55
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
55
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
56
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
56
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
57
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
58
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
58
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
60
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
60
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
61
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
62
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
63
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
63
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
64
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
64
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
65
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
66
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
65
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
67
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
66
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
68
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
67
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
69
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
347
 	public Void visitRange(RangeExpression expression) {
349
 	public Void visitRange(RangeExpression expression) {
348
 		throw new UnsupportedOperationException("Invalid increment target");
350
 		throw new UnsupportedOperationException("Invalid increment target");
349
 	}
351
 	}
352
+	
353
+	@Override
354
+	public Void visitSameObject(SameObjectExpression expression) {
355
+		throw new UnsupportedOperationException("Invalid increment target");
356
+	}
350
 
357
 
351
 	@Override
358
 	@Override
352
 	public Void visitSetField(SetFieldExpression expression) {
359
 	public Void visitSetField(SetFieldExpression expression) {
382
 	public Void visitStaticSetter(StaticSetterExpression expression) {
389
 	public Void visitStaticSetter(StaticSetterExpression expression) {
383
 		throw new UnsupportedOperationException("Invalid increment target");
390
 		throw new UnsupportedOperationException("Invalid increment target");
384
 	}
391
 	}
392
+	
393
+	@Override
394
+	public Void visitSupertypeCast(SupertypeCastExpression expression) {
395
+		throw new UnsupportedOperationException("Invalid increment target");
396
+	}
385
 
397
 
386
 	@Override
398
 	@Override
387
 	public Void visitThis(ThisExpression expression) {
399
 	public Void visitThis(ThisExpression expression) {

+ 12
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java View File

55
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
55
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
56
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
56
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
57
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
58
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
58
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
60
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
60
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
61
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
62
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
63
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
63
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
64
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
64
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
65
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
66
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
65
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
67
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
66
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
68
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
67
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
69
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
353
 	public Void visitRange(RangeExpression expression) {
355
 	public Void visitRange(RangeExpression expression) {
354
 		throw new UnsupportedOperationException("Invalid increment target");
356
 		throw new UnsupportedOperationException("Invalid increment target");
355
 	}
357
 	}
358
+	
359
+	@Override
360
+	public Void visitSameObject(SameObjectExpression expression) {
361
+		throw new UnsupportedOperationException("Invalid increment target");
362
+	}
356
 
363
 
357
 	@Override
364
 	@Override
358
 	public Void visitSetField(SetFieldExpression expression) {
365
 	public Void visitSetField(SetFieldExpression expression) {
388
 	public Void visitStaticSetter(StaticSetterExpression expression) {
395
 	public Void visitStaticSetter(StaticSetterExpression expression) {
389
 		throw new UnsupportedOperationException("Invalid increment target");
396
 		throw new UnsupportedOperationException("Invalid increment target");
390
 	}
397
 	}
398
+	
399
+	@Override
400
+	public Void visitSupertypeCast(SupertypeCastExpression expression) {
401
+		throw new UnsupportedOperationException("Invalid increment target");
402
+	}
391
 
403
 
392
 	@Override
404
 	@Override
393
 	public Void visitThis(ThisExpression expression) {
405
 	public Void visitThis(ThisExpression expression) {

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

233
             javaWriter.label(catchStart);
233
             javaWriter.label(catchStart);
234
 
234
 
235
             //final Type exceptionType = Type.getType(RuntimeException.class);
235
             //final Type exceptionType = Type.getType(RuntimeException.class);
236
-            final Type exceptionType = Type.getType(catchClause.exceptionType.accept(JavaTypeClassVisitor.INSTANCE));
236
+            final Type exceptionType = Type.getType(catchClause.exceptionVariable.type.accept(JavaTypeClassVisitor.INSTANCE));
237
             final int local = javaWriter.local(exceptionType);
237
             final int local = javaWriter.local(exceptionType);
238
             javaWriter.store(exceptionType, local);
238
             javaWriter.store(exceptionType, local);
239
 
239
 

+ 18
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java View File

94
         statementVisitor.end();
94
         statementVisitor.end();
95
         return null;
95
         return null;
96
     }
96
     }
97
+	
98
+	@Override
99
+	public Void visitDestructor(DestructorMember member) {
100
+		final JavaMethodInfo method = new JavaMethodInfo(toClass, "close", "()V", Opcodes.ACC_PUBLIC);
101
+
102
+        final Label constructorStart = new Label();
103
+        final Label constructorEnd = new Label();
104
+        final JavaWriter destructorWriter = new JavaWriter(writer, method, definition, null, null);
105
+        destructorWriter.label(constructorStart);
106
+
107
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(destructorWriter);
108
+        statementVisitor.start();
109
+		// TODO: destruction of members (to be done when memory tags are implemented)
110
+        member.body.accept(statementVisitor);
111
+        destructorWriter.label(constructorEnd);
112
+        statementVisitor.end();
113
+        return null;
114
+	}
97
 
115
 
98
     @Override
116
     @Override
99
     public Void visitMethod(MethodMember member) {
117
     public Void visitMethod(MethodMember member) {

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

37
 		KEYWORDS.put("final", K_FINAL);
37
 		KEYWORDS.put("final", K_FINAL);
38
 		KEYWORDS.put("override", K_OVERRIDE);
38
 		KEYWORDS.put("override", K_OVERRIDE);
39
 		KEYWORDS.put("const", K_CONST);
39
 		KEYWORDS.put("const", K_CONST);
40
-		KEYWORDS.put("shared", K_SHARED);
41
-		KEYWORDS.put("weak", K_WEAK);
42
 		KEYWORDS.put("private", K_PRIVATE);
40
 		KEYWORDS.put("private", K_PRIVATE);
43
 		KEYWORDS.put("public", K_PUBLIC);
41
 		KEYWORDS.put("public", K_PUBLIC);
44
 		KEYWORDS.put("export", K_EXPORT);
42
 		KEYWORDS.put("export", K_EXPORT);

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

87
 	K_FINAL,
87
 	K_FINAL,
88
 	K_OVERRIDE,
88
 	K_OVERRIDE,
89
 	K_CONST,
89
 	K_CONST,
90
-	K_SHARED,
91
-	K_WEAK,
92
 	K_PRIVATE,
90
 	K_PRIVATE,
93
 	K_PUBLIC,
91
 	K_PUBLIC,
94
 	K_EXPORT,
92
 	K_EXPORT,

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

38
 		for (ITypeID hint : scope.hints) {
38
 		for (ITypeID hint : scope.hints) {
39
 			// TODO: what if multiple hints fit?
39
 			// TODO: what if multiple hints fit?
40
 			if (hint.getUnmodified() instanceof ArrayTypeID) {
40
 			if (hint.getUnmodified() instanceof ArrayTypeID) {
41
-				ArrayTypeID arrayHint = (ArrayTypeID) hint;
41
+				ArrayTypeID arrayHint = (ArrayTypeID) hint.getUnmodified();
42
 				if (arrayHint.dimension == 1) {
42
 				if (arrayHint.dimension == 1) {
43
 					asBaseType = arrayHint.elementType;
43
 					asBaseType = arrayHint.elementType;
44
 					asType = arrayHint;
44
 					asType = arrayHint;

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

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!");
54
 			
54
 			
55
-			return new ConstructorThisCallExpression(position, scope.getThisType().getSuperType(), (ConstructorMember) member, callArguments);
55
+			return new ConstructorThisCallExpression(position, scope.getThisType().getSuperType(), (ConstructorMember) member, callArguments, scope);
56
 		} else if (receiver instanceof ParsedExpressionThis) {
56
 		} else if (receiver instanceof ParsedExpressionThis) {
57
 			// this call (intended as first call in constructor)
57
 			// this call (intended as first call in constructor)
58
 			ITypeID targetType = scope.getThisType();
58
 			ITypeID targetType = scope.getThisType();
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!");
65
 			
65
 			
66
-			return new ConstructorThisCallExpression(position, scope.getThisType(), (ConstructorMember) member, callArguments);
66
+			return new ConstructorThisCallExpression(position, scope.getThisType(), (ConstructorMember) member, callArguments, scope);
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());

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

45
 
45
 
46
 	@Override
46
 	@Override
47
 	public IPartialExpression compile(ExpressionScope scope) {
47
 	public IPartialExpression compile(ExpressionScope scope) {
48
+		AssocTypeID assocHint = null;
48
 		List<ITypeID> keyHints = new ArrayList<>();
49
 		List<ITypeID> keyHints = new ArrayList<>();
49
 		List<ITypeID> valueHints = new ArrayList<>();
50
 		List<ITypeID> valueHints = new ArrayList<>();
50
 		
51
 		
51
 		boolean hasAssocHint = false;
52
 		boolean hasAssocHint = false;
52
 		for (ITypeID hint : scope.hints) {
53
 		for (ITypeID hint : scope.hints) {
53
 			if (hint instanceof AssocTypeID) {
54
 			if (hint instanceof AssocTypeID) {
54
-				AssocTypeID assocHint = (AssocTypeID) hint;
55
+				assocHint = (AssocTypeID) hint;
55
 				if (!keyHints.contains(assocHint.keyType))
56
 				if (!keyHints.contains(assocHint.keyType))
56
 					keyHints.add(assocHint.keyType);
57
 					keyHints.add(assocHint.keyType);
57
 				if (!valueHints.contains(assocHint.valueType))
58
 				if (!valueHints.contains(assocHint.valueType))
67
 			}
68
 			}
68
 		}
69
 		}
69
 		
70
 		
71
+		if (keys.isEmpty() && keyHints.size() == 1) {
72
+			ICallableMember constructor = scope
73
+						.getTypeMembers(assocHint)
74
+						.getOrCreateGroup(OperatorType.CONSTRUCTOR)
75
+						.selectMethod(position, scope, CallArguments.EMPTY, true, true);
76
+				return new NewExpression(position, assocHint, (ConstructorMember) constructor, CallArguments.EMPTY);
77
+		}
78
+		
70
 		if (!hasAssocHint && scope.hints.size() == 1 && scope.hints.get(0) != BasicTypeID.ANY) {
79
 		if (!hasAssocHint && scope.hints.size() == 1 && scope.hints.get(0) != BasicTypeID.ANY) {
71
 			// compile as constructor call
80
 			// compile as constructor call
72
 			ITypeID hint = scope.hints.get(0);
81
 			ITypeID hint = scope.hints.get(0);

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

27
 
27
 
28
 	@Override
28
 	@Override
29
 	public IPartialExpression compile(ExpressionScope scope) {
29
 	public IPartialExpression compile(ExpressionScope scope) {
30
-		if (scope.hints.contains(BasicTypeID.CHAR) && value.length() == 1) {
31
-			return new ConstantCharExpression(position, value.charAt(0));
30
+		if (value.length() == 1) {
31
+			if (scope.hints.contains(BasicTypeID.CHAR)) {
32
+				return new ConstantCharExpression(position, value.charAt(0));
33
+			} else if (!scope.hints.contains(BasicTypeID.STRING)) {
34
+				if (scope.hints.contains(BasicTypeID.INT))
35
+					return new ConstantCharExpression(position, value.charAt(0));
36
+			}
32
 		}
37
 		}
33
 		
38
 		
34
 		return new ConstantStringExpression(position, value);
39
 		return new ConstantStringExpression(position, value);

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

57
 		if (!(member instanceof ConstructorMember))
57
 		if (!(member instanceof ConstructorMember))
58
 			throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "COMPILER BUG: constructor is not a constructor");
58
 			throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "COMPILER BUG: constructor is not a constructor");
59
 		
59
 		
60
+		for (int i = 0; i < compiledArguments.arguments.length; i++) {
61
+			compiledArguments.arguments[i] = compiledArguments.arguments[i].castImplicit(position, scope, member.getHeader().parameters[i].type);
62
+		}
60
 		return new NewExpression(position, type, (ConstructorMember) member, compiledArguments);
63
 		return new NewExpression(position, type, (ConstructorMember) member, compiledArguments);
61
 	}
64
 	}
62
 }
65
 }

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

174
 				return new ParsedCaller(start, forDefinition, modifiers, header, body);
174
 				return new ParsedCaller(start, forDefinition, modifiers, header, body);
175
 			}
175
 			}
176
 			case T_SQOPEN: {
176
 			case T_SQOPEN: {
177
+				tokens.next();
177
 				tokens.required(ZSTokenType.T_SQCLOSE, "] expected");
178
 				tokens.required(ZSTokenType.T_SQCLOSE, "] expected");
178
 				OperatorType operator = OperatorType.INDEXGET;
179
 				OperatorType operator = OperatorType.INDEXGET;
179
 				if (tokens.optional(ZSTokenType.T_ASSIGN) != null) {
180
 				if (tokens.optional(ZSTokenType.T_ASSIGN) != null) {
183
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
184
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
184
 				return new ParsedOperator(start, forDefinition, modifiers, operator, header, body);
185
 				return new ParsedOperator(start, forDefinition, modifiers, operator, header, body);
185
 			}
186
 			}
187
+			case T_CAT:
188
+				tokens.pushMark();
189
+				tokens.next();
190
+				if (tokens.optional(ZSTokenType.K_THIS) != null) {
191
+					tokens.popMark();
192
+					
193
+					// destructor
194
+					ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
195
+					return new ParsedDestructor(start, forDefinition, modifiers, body);
196
+				}
197
+				tokens.reset();
198
+				// else it is a ~ operator, continue...
186
 			case T_ADD:
199
 			case T_ADD:
187
 			case T_SUB:
200
 			case T_SUB:
188
-			case T_CAT:
189
 			case T_MUL:
201
 			case T_MUL:
190
 			case T_DIV:
202
 			case T_DIV:
191
 			case T_MOD:
203
 			case T_MOD:

+ 27
- 0
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDestructor.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.parser.member;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.member.DestructorMember;
10
+import org.openzen.zenscript.linker.BaseScope;
11
+import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
12
+import org.openzen.zenscript.shared.CodePosition;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class ParsedDestructor extends ParsedFunctionalMember {
19
+	public ParsedDestructor(CodePosition position, HighLevelDefinition definition, int modifiers, ParsedFunctionBody body) {
20
+		super(position, definition, modifiers, body);
21
+	}
22
+
23
+	@Override
24
+	public void linkTypes(BaseScope scope) {
25
+		compiled = new DestructorMember(position, definition, modifiers);
26
+	}
27
+}

+ 71
- 2
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.parser.statements;
6
 package org.openzen.zenscript.parser.statements;
7
 
7
 
8
+import java.util.List;
9
+import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.FunctionHeader;
11
+import org.openzen.zenscript.codemodel.expression.Expression;
12
+import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
13
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
8
 import org.openzen.zenscript.codemodel.statement.CatchClause;
14
 import org.openzen.zenscript.codemodel.statement.CatchClause;
15
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
16
+import org.openzen.zenscript.codemodel.statement.VarStatement;
17
+import org.openzen.zenscript.codemodel.type.GenericName;
18
+import org.openzen.zenscript.codemodel.type.ITypeID;
19
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
9
 import org.openzen.zenscript.linker.StatementScope;
20
 import org.openzen.zenscript.linker.StatementScope;
10
 import org.openzen.zenscript.parser.type.IParsedType;
21
 import org.openzen.zenscript.parser.type.IParsedType;
22
+import org.openzen.zenscript.shared.CodePosition;
11
 
23
 
12
 /**
24
 /**
13
  *
25
  *
14
  * @author Hoofdgebruiker
26
  * @author Hoofdgebruiker
15
  */
27
  */
16
 public class ParsedCatchClause {
28
 public class ParsedCatchClause {
29
+	public final CodePosition position;
17
 	public final String exceptionName;
30
 	public final String exceptionName;
18
 	public final IParsedType exceptionType;
31
 	public final IParsedType exceptionType;
19
 	public final ParsedStatement content;
32
 	public final ParsedStatement content;
20
 	
33
 	
21
-	public ParsedCatchClause(String exceptionName, IParsedType exceptionType, ParsedStatement content) {
34
+	public ParsedCatchClause(CodePosition position, String exceptionName, IParsedType exceptionType, ParsedStatement content) {
35
+		this.position = position;
22
 		this.exceptionName = exceptionName;
36
 		this.exceptionName = exceptionName;
23
 		this.exceptionType = exceptionType;
37
 		this.exceptionType = exceptionType;
24
 		this.content = content;
38
 		this.content = content;
25
 	}
39
 	}
26
 	
40
 	
27
 	public CatchClause compile(StatementScope scope) {
41
 	public CatchClause compile(StatementScope scope) {
28
-		return new CatchClause(exceptionName, exceptionType.compile(scope), content.compile(scope));
42
+		VarStatement exceptionVariable = new VarStatement(position, exceptionName, exceptionType.compile(scope), null, true);
43
+		CatchScope localScope = new CatchScope(scope, exceptionVariable);
44
+		return new CatchClause(position, exceptionVariable, content.compile(localScope));
45
+	}
46
+	
47
+	private class CatchScope extends StatementScope {
48
+		private final StatementScope outer;
49
+		private final VarStatement exceptionVariable;
50
+		
51
+		public CatchScope(StatementScope outer, VarStatement exceptionVariable) {
52
+			this.outer = outer;
53
+			this.exceptionVariable = exceptionVariable;
54
+		}
55
+	
56
+		@Override
57
+		public IPartialExpression get(CodePosition position, GenericName name) {
58
+			if (name.hasNoArguments() && exceptionVariable.name.equals(name.name))
59
+				return new GetLocalVariableExpression(position, exceptionVariable);
60
+
61
+			return outer.get(position, name);
62
+		}
63
+
64
+		@Override
65
+		public LocalMemberCache getMemberCache() {
66
+			return outer.getMemberCache();
67
+		}
68
+
69
+		@Override
70
+		public ITypeID getType(CodePosition position, List<GenericName> name) {
71
+			return outer.getType(position, name);
72
+		}
73
+
74
+		@Override
75
+		public LoopStatement getLoop(String name) {
76
+			return outer.getLoop(name);
77
+		}
78
+
79
+		@Override
80
+		public FunctionHeader getFunctionHeader() {
81
+			return outer.getFunctionHeader();
82
+		}
83
+
84
+		@Override
85
+		public ITypeID getThisType() {
86
+			return outer.getThisType();
87
+		}
88
+
89
+		@Override
90
+		public Function<CodePosition, Expression> getDollar() {
91
+			return outer.getDollar();
92
+		}
93
+
94
+		@Override
95
+		public IPartialExpression getOuterInstance(CodePosition position) {
96
+			return outer.getOuterInstance(position);
97
+		}
29
 	}
98
 	}
30
 }
99
 }

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

197
 				ParsedStatement content = parse(parser);
197
 				ParsedStatement content = parse(parser);
198
 				List<ParsedCatchClause> catchClauses = new ArrayList<>();
198
 				List<ParsedCatchClause> catchClauses = new ArrayList<>();
199
 				while (parser.optional(K_CATCH) != null) {
199
 				while (parser.optional(K_CATCH) != null) {
200
+					CodePosition position = parser.getPosition();
201
+					
200
 					String catchName = null;
202
 					String catchName = null;
201
 					if (parser.isNext(ZSTokenType.T_IDENTIFIER))
203
 					if (parser.isNext(ZSTokenType.T_IDENTIFIER))
202
 						catchName = parser.next().content;
204
 						catchName = parser.next().content;
206
 						catchType = IParsedType.parse(parser);
208
 						catchType = IParsedType.parse(parser);
207
 					
209
 					
208
 					ParsedStatement catchContent = ParsedStatement.parse(parser);
210
 					ParsedStatement catchContent = ParsedStatement.parse(parser);
209
-					catchClauses.add(new ParsedCatchClause(catchName, catchType, catchContent));
211
+					catchClauses.add(new ParsedCatchClause(position, catchName, catchType, catchContent));
210
 				}
212
 				}
211
 				
213
 				
212
 				ParsedStatement finallyClause = null;
214
 				ParsedStatement finallyClause = null;

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

51
 		Expression resourceInitializer = this.resourceInitializer == null ? null : this.resourceInitializer.compile(new ExpressionScope(scope)).eval();
51
 		Expression resourceInitializer = this.resourceInitializer == null ? null : this.resourceInitializer.compile(new ExpressionScope(scope)).eval();
52
 		Statement statement = this.statement.compile(scope);
52
 		Statement statement = this.statement.compile(scope);
53
 		List<CatchClause> catches = new ArrayList<>();
53
 		List<CatchClause> catches = new ArrayList<>();
54
-		for (ParsedCatchClause catchClause : catchClauses)
54
+		for (ParsedCatchClause catchClause : catchClauses) {
55
 			catches.add(catchClause.compile(scope));
55
 			catches.add(catchClause.compile(scope));
56
+		}
56
 		
57
 		
57
 		Statement finallyClause = this.finallyClause == null ? null : this.finallyClause.compile(scope);
58
 		Statement finallyClause = this.finallyClause == null ? null : this.finallyClause.compile(scope);
58
 		VarStatement resource = null;
59
 		VarStatement resource = null;

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

37
 		while (true) {
37
 		while (true) {
38
 			if (tokens.optional(ZSTokenType.K_CONST) != null) {
38
 			if (tokens.optional(ZSTokenType.K_CONST) != null) {
39
 				modifiers |= TypeMembers.MODIFIER_CONST;
39
 				modifiers |= TypeMembers.MODIFIER_CONST;
40
-			} else if (tokens.optional(ZSTokenType.K_SHARED) != null) {
41
-				modifiers |= TypeMembers.MODIFIER_SHARED;
42
-			} else if (tokens.optional(ZSTokenType.K_WEAK) != null) {
43
-				modifiers |= TypeMembers.MODIFIER_WEAK;
44
 			} else {
40
 			} else {
45
 				break;
41
 				break;
46
 			}
42
 			}

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

61
 		INVALID_SOURCE_TYPE,
61
 		INVALID_SOURCE_TYPE,
62
 		SETTING_FINAL_FIELD,
62
 		SETTING_FINAL_FIELD,
63
 		SETTING_FINAL_VARIABLE,
63
 		SETTING_FINAL_VARIABLE,
64
-		INVALID_SUPERTYPE
64
+		INVALID_SUPERTYPE,
65
+		MULTIPLE_DESTRUCTORS
65
 	}
66
 	}
66
 }
67
 }

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

15
 import org.openzen.zenscript.codemodel.member.CasterMember;
15
 import org.openzen.zenscript.codemodel.member.CasterMember;
16
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
16
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
17
 import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
17
 import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
18
+import org.openzen.zenscript.codemodel.member.DestructorMember;
18
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
19
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
19
 import org.openzen.zenscript.codemodel.member.FieldMember;
20
 import org.openzen.zenscript.codemodel.member.FieldMember;
20
 import org.openzen.zenscript.codemodel.member.GetterMember;
21
 import org.openzen.zenscript.codemodel.member.GetterMember;
47
 	private final HighLevelDefinition definition;
48
 	private final HighLevelDefinition definition;
48
 	private final Set<EnumConstantMember> initializedEnumConstants = new HashSet<>();
49
 	private final Set<EnumConstantMember> initializedEnumConstants = new HashSet<>();
49
 	private final Set<ITypeID> implementedTypes = new HashSet<>();
50
 	private final Set<ITypeID> implementedTypes = new HashSet<>();
51
+	private boolean hasDestructor = false;
50
 	
52
 	
51
 	public DefinitionMemberValidator(Validator validator, HighLevelDefinition definition) {
53
 	public DefinitionMemberValidator(Validator validator, HighLevelDefinition definition) {
52
 		this.validator = validator;
54
 		this.validator = validator;
100
 		
102
 		
101
 		return isValid;
103
 		return isValid;
102
 	}
104
 	}
105
+	
106
+	@Override
107
+	public Boolean visitDestructor(DestructorMember member) {
108
+		boolean isValid = true;
109
+		if (hasDestructor) {
110
+			validator.logError(ValidationLogEntry.Code.MULTIPLE_DESTRUCTORS, member.position, "A type have only a single destructor");
111
+			isValid = false;
112
+		}
113
+		hasDestructor = true;
114
+		if (member.body != null) {
115
+			StatementValidator statementValidator = new StatementValidator(validator, new ConstructorStatementScope(member.header));
116
+			isValid &= member.body.accept(statementValidator);
117
+		}
118
+		return isValid;
119
+	}
103
 
120
 
104
 	@Override
121
 	@Override
105
 	public Boolean visitMethod(MethodMember member) {
122
 	public Boolean visitMethod(MethodMember member) {

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

90
 
90
 
91
 	@Override
91
 	@Override
92
 	public Boolean visitStruct(StructDefinition definition) {
92
 	public Boolean visitStruct(StructDefinition definition) {
93
+		int validModifiers = PUBLIC | EXPORT | PROTECTED | PRIVATE;
94
+		if (definition.outerDefinition != null)
95
+			validModifiers |= STATIC;
96
+		
93
 		boolean isValid = true;
97
 		boolean isValid = true;
94
 		isValid &= ValidationUtils.validateModifiers(
98
 		isValid &= ValidationUtils.validateModifiers(
95
 				validator,
99
 				validator,
96
 				definition.modifiers,
100
 				definition.modifiers,
97
-				PUBLIC | EXPORT | PROTECTED | PRIVATE,
101
+				validModifiers,
98
 				definition.position,
102
 				definition.position,
99
 				"Invalid struct modifier");
103
 				"Invalid struct modifier");
100
 		isValid &= ValidationUtils.validateIdentifier(
104
 		isValid &= ValidationUtils.validateIdentifier(

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

58
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
58
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
59
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
59
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
60
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
60
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
61
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
61
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
62
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
62
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
63
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
63
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
64
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
65
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
66
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
66
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
67
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
67
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
68
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
69
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
68
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
70
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
69
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
71
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
70
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
72
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
496
 		}
498
 		}
497
 		return isValid;
499
 		return isValid;
498
 	}
500
 	}
501
+	
502
+	@Override
503
+	public Boolean visitSameObject(SameObjectExpression expression) {
504
+		boolean isValid = true;
505
+		isValid &= expression.left.accept(this);
506
+		isValid &= expression.right.accept(this);
507
+		return isValid;
508
+	}
499
 
509
 
500
 	@Override
510
 	@Override
501
 	public Boolean visitSetField(SetFieldExpression expression) {
511
 	public Boolean visitSetField(SetFieldExpression expression) {
607
 		return isValid;
617
 		return isValid;
608
 	}
618
 	}
609
 
619
 
620
+	@Override
621
+	public Boolean visitSupertypeCast(SupertypeCastExpression expression) {
622
+		boolean isValid = expression.value.accept(this);
623
+		return isValid;
624
+	}
625
+
610
 	@Override
626
 	@Override
611
 	public Boolean visitThis(ThisExpression expression) {
627
 	public Boolean visitThis(ThisExpression expression) {
612
 		if (!scope.hasThis()) {
628
 		if (!scope.hasThis()) {

Loading…
Cancel
Save