浏览代码

- 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 年前
父节点
当前提交
2864226fab
共有 89 个文件被更改,包括 816 次插入132 次删除
  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 查看文件

@@ -56,6 +56,7 @@ import org.openzen.zenscript.codemodel.expression.NullExpression;
56 56
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
57 57
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
58 58
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
59
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
59 60
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
60 61
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
61 62
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
@@ -63,6 +64,7 @@ import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
63 64
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
64 65
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
65 66
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
67
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
66 68
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
67 69
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
68 70
 import org.openzen.zenscript.codemodel.member.OperatorMember;
@@ -532,6 +534,11 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
532 534
 	public ExpressionString visitRange(RangeExpression expression) {
533 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 543
 	@Override
537 544
 	public ExpressionString visitSetField(SetFieldExpression expression) {
@@ -581,6 +588,11 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
581 588
 				expression.type.accept(typeFormatter) + "." + expression.setter.name + " = " + expression.setter.name,
582 589
 				OperatorPriority.ASSIGN);
583 590
 	}
591
+	
592
+	@Override
593
+	public ExpressionString visitSupertypeCast(SupertypeCastExpression expression) {
594
+		return expression.value.accept(this);
595
+	}
584 596
 
585 597
 	@Override
586 598
 	public ExpressionString visitThis(ThisExpression expression) {

+ 10
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java 查看文件

@@ -10,6 +10,7 @@ import org.openzen.zenscript.codemodel.member.CallerMember;
10 10
 import org.openzen.zenscript.codemodel.member.CasterMember;
11 11
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
12 12
 import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
13
+import org.openzen.zenscript.codemodel.member.DestructorMember;
13 14
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
14 15
 import org.openzen.zenscript.codemodel.member.FieldMember;
15 16
 import org.openzen.zenscript.codemodel.member.GetterMember;
@@ -81,6 +82,15 @@ public class MemberFormatter implements MemberVisitor<Void> {
81 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 94
 	@Override
85 95
 	public Void visitMethod(MethodMember member) {
86 96
 		visit(false);

+ 2
- 7
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java 查看文件

@@ -27,7 +27,6 @@ import org.openzen.zenscript.codemodel.statement.ThrowStatement;
27 27
 import org.openzen.zenscript.codemodel.statement.TryCatchStatement;
28 28
 import org.openzen.zenscript.codemodel.statement.VarStatement;
29 29
 import org.openzen.zenscript.codemodel.statement.WhileStatement;
30
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
31 30
 
32 31
 /**
33 32
  *
@@ -252,12 +251,8 @@ public class StatementFormatter implements StatementVisitor<Void> {
252 251
 		
253 252
 		for (CatchClause catchClause : statement.catchClauses) {
254 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 257
 			format(ParentStatementType.CATCH, catchClause.content);
263 258
 		}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java 查看文件

@@ -237,7 +237,7 @@ public class FunctionHeader {
237 237
 		if (this.parameters.length != arguments.arguments.length)
238 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 241
 			return typeParameters.length + " type parameters expected but " + arguments.typeArguments.length + " given.";
242 242
 		
243 243
 		for (int i = 0; i < parameters.length; i++) {

+ 1
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/OperatorType.java 查看文件

@@ -47,6 +47,7 @@ public enum OperatorType {
47 47
 	RANGE("..", "rangeTo"),
48 48
 	
49 49
 	CONSTRUCTOR("this", "construct"),
50
+	DESTRUCTOR("~this", "destruct"),
50 51
 	CALL("()", "call"),
51 52
 	CAST("as", "cast");
52 53
 	

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java 查看文件

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

@@ -5,7 +5,13 @@
5 5
  */
6 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 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,4 +42,23 @@ public class CallArguments {
36 42
 	public int getNumberOfTypeArguments() {
37 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 查看文件

@@ -5,12 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.expression;
7 7
 
8
-import java.util.Arrays;
9 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 9
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
10
+import org.openzen.zenscript.codemodel.scope.TypeScope;
11 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,22 +20,12 @@ public class CallExpression extends Expression {
22 20
 	public final CallArguments arguments;
23 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 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 26
 		this.target = target;
39 27
 		this.member = member;
40
-		this.arguments = arguments;
28
+		this.arguments = arguments.normalize(position, scope, instancedHeader);
41 29
 		this.instancedHeader = instancedHeader;
42 30
 	}
43 31
 	

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java 查看文件

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.expression;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
9 9
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
10
+import org.openzen.zenscript.codemodel.scope.TypeScope;
10 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 12
 import org.openzen.zenscript.shared.CodePosition;
12 13
 
@@ -20,12 +21,12 @@ public class CallStaticExpression extends Expression {
20 21
 	public final CallArguments arguments;
21 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 25
 		super(position, member.header.returnType);
25 26
 		
26 27
 		this.member = member;
27 28
 		this.target = target;
28
-		this.arguments = arguments;
29
+		this.arguments = arguments.normalize(position, scope, instancedHeader);
29 30
 		this.instancedHeader = instancedHeader;
30 31
 	}
31 32
 

+ 4
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallTranslator.java 查看文件

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.expression;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.scope.TypeScope;
9 10
 import org.openzen.zenscript.shared.CodePosition;
10 11
 
11 12
 /**
@@ -18,12 +19,14 @@ public interface CallTranslator {
18 19
 		public final Expression target;
19 20
 		public final FunctionHeader instancedHeader;
20 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 25
 			this.position = position;
24 26
 			this.target = target;
25 27
 			this.instancedHeader = instancedHeader;
26 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 查看文件

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

+ 4
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorThisCallExpression.java 查看文件

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.expression;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
9
+import org.openzen.zenscript.codemodel.scope.TypeScope;
9 10
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
10 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 12
 import org.openzen.zenscript.shared.CodePosition;
@@ -19,9 +20,11 @@ public class ConstructorThisCallExpression extends Expression {
19 20
 	public final ConstructorMember constructor;
20 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 24
 		super(position, BasicTypeID.VOID);
24 25
 		
26
+		arguments = arguments.normalize(position, scope, constructor.header);
27
+		
25 28
 		this.objectType = type;
26 29
 		this.constructor = constructor;
27 30
 		this.arguments = arguments;

+ 4
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java 查看文件

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

+ 8
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFieldExpression.java 查看文件

@@ -8,8 +8,11 @@ package org.openzen.zenscript.codemodel.expression;
8 8
 import java.util.Collections;
9 9
 import java.util.List;
10 10
 import org.openzen.zenscript.codemodel.member.FieldMember;
11
+import org.openzen.zenscript.codemodel.scope.TypeScope;
11 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
12 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,6 +38,11 @@ public class GetFieldExpression extends Expression {
35 38
 	public CapturedExpression capture(CodePosition position, LambdaClosure closure) {
36 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 47
 	@Override
40 48
 	public <T> T accept(ExpressionVisitor<T> visitor) {

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SameObjectExpression.java 查看文件

@@ -0,0 +1,32 @@
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 查看文件

@@ -0,0 +1,29 @@
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 查看文件

@@ -16,6 +16,8 @@ import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
16 16
  * @author Hoofdgebruiker
17 17
  */
18 18
 public abstract class GenericParameterBound {
19
+	public abstract boolean isObjectType();
20
+	
19 21
 	public abstract <T> T accept(GenericParameterBoundVisitor<T> visitor);
20 22
 	
21 23
 	public abstract void registerMembers(LocalMemberCache cache, TypeMembers type);

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java 查看文件

@@ -45,4 +45,9 @@ public class ParameterSuperBound extends GenericParameterBound {
45 45
 	public <T> T accept(GenericParameterBoundVisitor<T> visitor) {
46 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 查看文件

@@ -45,4 +45,9 @@ public class ParameterTypeBound extends GenericParameterBound {
45 45
 	public <T> T accept(GenericParameterBoundVisitor<T> visitor) {
46 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 查看文件

@@ -37,6 +37,14 @@ public class TypeParameter {
37 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 48
 	public boolean matches(LocalMemberCache cache, ITypeID type) {
41 49
 		for (GenericParameterBound bound : bounds) {
42 50
 			if (!bound.matches(cache, type))

+ 6
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CallerMember.java 查看文件

@@ -23,6 +23,11 @@ public class CallerMember extends FunctionalMember {
23 23
 	public CallerMember(CodePosition position, HighLevelDefinition definition, int modifiers, FunctionHeader header) {
24 24
 		super(position, definition, modifiers, "()", header);
25 25
 	}
26
+	
27
+	@Override
28
+	public String getInformalName() {
29
+		return "caller";
30
+	}
26 31
 
27 32
 	@Override
28 33
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
@@ -31,7 +36,7 @@ public class CallerMember extends FunctionalMember {
31 36
 
32 37
 	@Override
33 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 42
 	@Override

+ 7
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java 查看文件

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.expression.CallArguments;
13 13
 import org.openzen.zenscript.codemodel.expression.CastExpression;
14 14
 import org.openzen.zenscript.codemodel.expression.Expression;
15 15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
+import org.openzen.zenscript.codemodel.scope.TypeScope;
16 17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17 18
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18 19
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -31,6 +32,11 @@ public class CasterMember extends FunctionalMember implements ICasterMember {
31 32
 		
32 33
 		this.toType = toType;
33 34
 	}
35
+	
36
+	@Override
37
+	public String getInformalName() {
38
+		return "caster to " + toType.toString();
39
+	}
34 40
 
35 41
 	@Override
36 42
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
@@ -53,7 +59,7 @@ public class CasterMember extends FunctionalMember implements ICasterMember {
53 59
 	}
54 60
 
55 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 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 查看文件

@@ -43,6 +43,11 @@ public class ConstructorMember extends FunctionalMember {
43 43
 				firstExpression.expression instanceof ConstructorSuperCallExpression
44 44
 				|| firstExpression.expression instanceof ConstructorThisCallExpression);
45 45
 	}
46
+	
47
+	@Override
48
+	public String getInformalName() {
49
+		return "constructor";
50
+	}
46 51
 
47 52
 	@Override
48 53
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
@@ -52,7 +57,10 @@ public class ConstructorMember extends FunctionalMember {
52 57
 
53 58
 	@Override
54 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 66
 	@Override

+ 55
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DestructorMember.java 查看文件

@@ -0,0 +1,55 @@
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 查看文件

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.expression.BasicCompareExpression;
14 14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15 15
 import org.openzen.zenscript.codemodel.expression.Expression;
16 16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
17
+import org.openzen.zenscript.codemodel.scope.TypeScope;
17 18
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
18 19
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19 20
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -35,6 +36,11 @@ public class EqualsMember extends Taggable implements ICallableMember {
35 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 44
 	@Override
39 45
 	public boolean isStatic() {
40 46
 		return false;
@@ -46,22 +52,22 @@ public class EqualsMember extends Taggable implements ICallableMember {
46 52
 	}
47 53
 
48 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 56
 		return new BasicCompareExpression(position, target, arguments.arguments[0], CompareType.EQ);
51 57
 	}
52 58
 
53 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 61
 		throw new UnsupportedOperationException("Comparator not supported here");
56 62
 	}
57 63
 
58 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 66
 		throw new UnsupportedOperationException("Cannot be called statically");
61 67
 	}
62 68
 
63 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 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 查看文件

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.expression.CallExpression;
13 13
 import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14 14
 import org.openzen.zenscript.codemodel.expression.Expression;
15 15
 import org.openzen.zenscript.codemodel.expression.GenericCompareExpression;
16
+import org.openzen.zenscript.codemodel.scope.TypeScope;
16 17
 import org.openzen.zenscript.codemodel.statement.Statement;
17 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
18 19
 import org.openzen.zenscript.shared.CodePosition;
@@ -43,26 +44,26 @@ public abstract class FunctionalMember extends DefinitionMember implements ICall
43 44
 	}
44 45
 
45 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 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 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 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 查看文件

@@ -32,6 +32,11 @@ public class GetterMember extends FunctionalMember implements IGettableMember {
32 32
 		this.name = name;
33 33
 		this.type = type;
34 34
 	}
35
+	
36
+	@Override
37
+	public String getInformalName() {
38
+		return "getter " + name;
39
+	}
35 40
 
36 41
 	@Override
37 42
 	public String getName() {

+ 7
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICallableMember.java 查看文件

@@ -9,6 +9,7 @@ import org.openzen.zenscript.codemodel.CompareType;
9 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.expression.CallArguments;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
+import org.openzen.zenscript.codemodel.scope.TypeScope;
12 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13 14
 import org.openzen.zenscript.shared.CodePosition;
14 15
 
@@ -19,13 +20,15 @@ import org.openzen.zenscript.shared.CodePosition;
19 20
 public interface ICallableMember extends IDefinitionMember {
20 21
 	public boolean isStatic();
21 22
 	
23
+	public String getInformalName();
24
+	
22 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 查看文件

@@ -14,6 +14,8 @@ public interface MemberVisitor<T> {
14 14
 	
15 15
 	public T visitConstructor(ConstructorMember member);
16 16
 	
17
+	public T visitDestructor(DestructorMember member);
18
+	
17 19
 	public T visitMethod(MethodMember member);
18 20
 	
19 21
 	public T visitGetter(GetterMember member);

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MethodMember.java 查看文件

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/OperatorMember.java 查看文件

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java 查看文件

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

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/TranslatedOperatorMember.java 查看文件

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.OperatorType;
11 11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12 12
 import org.openzen.zenscript.codemodel.expression.CallTranslator;
13 13
 import org.openzen.zenscript.codemodel.expression.Expression;
14
+import org.openzen.zenscript.codemodel.scope.TypeScope;
14 15
 import org.openzen.zenscript.shared.CodePosition;
15 16
 
16 17
 /**
@@ -27,7 +28,7 @@ public class TranslatedOperatorMember extends OperatorMember {
27 28
 	}
28 29
 
29 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 查看文件

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
12 12
 import org.openzen.zenscript.codemodel.member.ICallableMember;
13 13
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
14 14
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
15
+import org.openzen.zenscript.codemodel.scope.TypeScope;
15 16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16 17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -36,6 +37,11 @@ public class ComparatorMember extends Taggable implements ICallableMember {
36 37
 	public ComparatorMember(ITypeID type) {
37 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 46
 	@Override
41 47
 	public boolean isStatic() {
@@ -48,22 +54,22 @@ public class ComparatorMember extends Taggable implements ICallableMember {
48 54
 	}
49 55
 
50 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 58
 		throw new UnsupportedOperationException("Can't call a comparator");
53 59
 	}
54 60
 
55 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 63
 		return new BasicCompareExpression(position, target, arguments.arguments[0], operator);
58 64
 	}
59 65
 
60 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 68
 		throw new UnsupportedOperationException("Can't call a comparator");
63 69
 	}
64 70
 
65 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 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 查看文件

@@ -24,7 +24,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
24 24
  */
25 25
 public class PartialStaticMemberGroupExpression implements IPartialExpression {
26 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 28
 		group.addMethod(method, TypeMemberPriority.SPECIFIED);
29 29
 		return new PartialStaticMemberGroupExpression(position, target, group, typeArguments);
30 30
 	}

+ 4
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/CatchClause.java 查看文件

@@ -5,20 +5,18 @@
5 5
  */
6 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 12
  * @author Hoofdgebruiker
13 13
  */
14 14
 public class CatchClause {
15
-	public final String exceptionName;
16
-	public final ITypeID exceptionType;
17 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 20
 		this.content = content;
23 21
 	}
24 22
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java 查看文件

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java 查看文件

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java 查看文件

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ConstTypeID.java 查看文件

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

+ 10
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java 查看文件

@@ -54,8 +54,8 @@ public class DefinitionTypeID implements ITypeID {
54 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 61
 	public boolean hasTypeParameters() {
@@ -92,7 +92,9 @@ public class DefinitionTypeID implements ITypeID {
92 92
 		if (typeParameters != null) {
93 93
 			instancedArguments = new ITypeID[typeParameters.length];
94 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,6 +133,11 @@ public class DefinitionTypeID implements ITypeID {
131 133
 	public boolean isConst() {
132 134
 		return false;
133 135
 	}
136
+	
137
+	@Override
138
+	public boolean isObjectType() {
139
+		return true;
140
+	}
134 141
 
135 142
 	@Override
136 143
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java 查看文件

@@ -46,6 +46,11 @@ public class FunctionTypeID implements ITypeID {
46 46
 	public boolean isConst() {
47 47
 		return false;
48 48
 	}
49
+	
50
+	@Override
51
+	public boolean isObjectType() {
52
+		return true;
53
+	}
49 54
 
50 55
 	@Override
51 56
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java 查看文件

@@ -58,6 +58,11 @@ public class GenericMapTypeID implements ITypeID {
58 58
 		return true;
59 59
 	}
60 60
 	
61
+	@Override
62
+	public boolean isObjectType() {
63
+		return true;
64
+	}
65
+	
61 66
 	@Override
62 67
 	public String toString() {
63 68
 		StringBuilder result = new StringBuilder();

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java 查看文件

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

+ 0
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java 查看文件

@@ -13,8 +13,6 @@ import org.openzen.zenscript.codemodel.HighLevelDefinition;
13 13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14 14
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_CONST;
15 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,10 +158,6 @@ public class GlobalTypeRegistry {
160 158
 			return getModified(modifiers & ~MODIFIER_OPTIONAL, getOptional(type));
161 159
 		if ((modifiers & MODIFIER_CONST) > 0)
162 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 162
 		throw new UnsupportedOperationException();
169 163
 	}

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java 查看文件

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java 查看文件

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java 查看文件

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

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java 查看文件

@@ -49,6 +49,11 @@ public class RangeTypeID implements ITypeID {
49 49
 	public boolean isConst() {
50 50
 		return false;
51 51
 	}
52
+	
53
+	@Override
54
+	public boolean isObjectType() {
55
+		return false;
56
+	}
52 57
 
53 58
 	@Override
54 59
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {

+ 13
- 7
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java 查看文件

@@ -38,7 +38,7 @@ import org.openzen.zenscript.codemodel.scope.TypeScope;
38 38
  */
39 39
 public class DefinitionMemberGroup {
40 40
 	public static DefinitionMemberGroup forMethod(ICallableMember member) {
41
-		DefinitionMemberGroup instance = new DefinitionMemberGroup(member.isStatic());
41
+		DefinitionMemberGroup instance = new DefinitionMemberGroup(member.isStatic(), member.getInformalName());
42 42
 		instance.addMethod(member, TypeMemberPriority.SPECIFIED);
43 43
 		return instance;
44 44
 	}
@@ -48,9 +48,11 @@ public class DefinitionMemberGroup {
48 48
 	private TypeMember<SetterMember> setter;
49 49
 	private final List<TypeMember<ICallableMember>> methods = new ArrayList<>();
50 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 54
 		this.isStatic = isStatic;
55
+		this.name = name;
54 56
 	}
55 57
 	
56 58
 	public void merge(CodePosition position, DefinitionMemberGroup other, TypeMemberPriority priority) {
@@ -241,7 +243,7 @@ public class DefinitionMemberGroup {
241 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 249
 	public Expression callPostfix(CodePosition position, TypeScope scope, Expression target) {
@@ -264,13 +266,13 @@ public class DefinitionMemberGroup {
264 266
 			CompareType compareType) {
265 267
 		ICallableMember method = selectMethod(position, scope, arguments, true, false);
266 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 272
 	public Expression callStatic(CodePosition position, ITypeID target, TypeScope scope, CallArguments arguments) {
271 273
 		ICallableMember method = selectMethod(position, scope, arguments, false, true);
272 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 278
 	public Expression callStaticWithComparator(
@@ -281,7 +283,7 @@ public class DefinitionMemberGroup {
281 283
 			CompareType compareType) {
282 284
 		ICallableMember method = selectMethod(position, scope, arguments, false, true);
283 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 289
 	public ICallableMember selectMethod(CodePosition position, TypeScope scope, CallArguments arguments, boolean allowNonStatic, boolean allowStatic) {
@@ -342,6 +344,10 @@ public class DefinitionMemberGroup {
342 344
 		if (selected == null) {
343 345
 			// let's figure out why this didn't work out
344 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 351
 			outer: for (TypeMember<ICallableMember> method : methods) {
346 352
 				if (!(method.member.isStatic() ? allowStatic : allowNonStatic)) {
347 353
 					message.append(method.member.isStatic() ? "Method must not be static" : "Method must be static").append('\n');
@@ -351,7 +357,7 @@ public class DefinitionMemberGroup {
351 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 363
 		return selected;

+ 9
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java 查看文件

@@ -40,6 +40,7 @@ import org.openzen.zenscript.codemodel.member.builtin.ComparatorMember;
40 40
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
41 41
 import org.openzen.zenscript.codemodel.member.builtin.RangeIterator;
42 42
 import org.openzen.zenscript.codemodel.member.builtin.StringCharIterator;
43
+import org.openzen.zenscript.codemodel.scope.TypeScope;
43 44
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
44 45
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
45 46
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -161,6 +162,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
161 162
 		}
162 163
 
163 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 166
 		members.addIterator(new ArrayIteratorKeyValues(array), TypeMemberPriority.SPECIFIED);
165 167
 		members.addIterator(new ArrayIteratorValues(array), TypeMemberPriority.SPECIFIED);
166 168
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "clear", new FunctionHeader(VOID)), TypeMemberPriority.SPECIFIED);
@@ -190,6 +192,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
190 192
 		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "size", INT));
191 193
 		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL));
192 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 197
 		members.addIterator(new AssocIterator(assoc), TypeMemberPriority.SPECIFIED);
195 198
 		return null;
@@ -204,6 +207,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
204 207
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOptional", new FunctionHeader(map.keys, registry.getOptional(valueType), new FunctionParameter[0])));
205 208
 		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, new FunctionParameter(valueType))));
206 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 211
 		return null;
208 212
 	}
209 213
 	
@@ -228,8 +232,9 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
228 232
 				for (int i = 0; i < type.typeParameters.length; i++)
229 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 239
 			for (IDefinitionMember member : definition.members) {
235 240
 				member.instance(cache.getRegistry(), mapping).registerTo(members, TypeMemberPriority.SPECIFIED);
@@ -273,6 +278,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
273 278
 			}
274 279
 		}
275 280
 		
281
+		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
276 282
 		return null;
277 283
 	}
278 284
 
@@ -516,6 +522,6 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
516 522
 	}
517 523
 	
518 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 查看文件

@@ -18,10 +18,13 @@ import org.openzen.zenscript.codemodel.expression.Expression;
18 18
 import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
19 19
 import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
20 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 23
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
22 24
 import org.openzen.zenscript.codemodel.member.CallerMember;
23 25
 import org.openzen.zenscript.codemodel.member.CasterMember;
24 26
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
27
+import org.openzen.zenscript.codemodel.member.DestructorMember;
25 28
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
26 29
 import org.openzen.zenscript.codemodel.member.FieldMember;
27 30
 import org.openzen.zenscript.codemodel.member.ICallableMember;
@@ -54,8 +57,6 @@ import org.openzen.zenscript.codemodel.scope.TypeScope;
54 57
 public final class TypeMembers {
55 58
 	public static final int MODIFIER_OPTIONAL = 1;
56 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 61
 	private final LocalMemberCache cache;
61 62
 	public final ITypeID type;
@@ -88,7 +89,7 @@ public final class TypeMembers {
88 89
 		}
89 90
 		
90 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 93
 				return true;
93 94
 			if (cache.get(implementation.member.type).extendsOrImplements(other))
94 95
 				return true;
@@ -97,6 +98,18 @@ public final class TypeMembers {
97 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 113
 	public GlobalTypeRegistry getTypeRegistry() {
101 114
 		return cache.getRegistry();
102 115
 	}
@@ -135,6 +148,10 @@ public final class TypeMembers {
135 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 155
 	public void addCaller(CallerMember caller, TypeMemberPriority priority) {
139 156
 		getOrCreateGroup(OperatorType.CALL).addMethod(caller, priority);
140 157
 	}
@@ -232,14 +249,14 @@ public final class TypeMembers {
232 249
 	
233 250
 	public DefinitionMemberGroup getOrCreateGroup(String name, boolean isStatic) {
234 251
 		if (!members.containsKey(name))
235
-			members.put(name, new DefinitionMemberGroup(isStatic));
252
+			members.put(name, new DefinitionMemberGroup(isStatic, name));
236 253
 		
237 254
 		return members.get(name);
238 255
 	}
239 256
 	
240 257
 	public DefinitionMemberGroup getOrCreateGroup(OperatorType operator) {
241 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 261
 		return operators.get(operator);
245 262
 	}
@@ -256,7 +273,17 @@ public final class TypeMembers {
256 273
 	}
257 274
 	
258 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 287
 			DefinitionMemberGroup equal = getOrCreateGroup(OperatorType.EQUALS);
261 288
 			for (TypeMember<ICallableMember> member : equal.getMethodMembers()) {
262 289
 				if (member.member.getHeader().accepts(scope, right))
@@ -267,7 +294,7 @@ public final class TypeMembers {
267 294
 			for (TypeMember<ICallableMember> member : equal.getMethodMembers()) {
268 295
 				if (member.member.getHeader().accepts(scope, right)) {
269 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,12 +350,8 @@ public final class TypeMembers {
323 350
 			if (caster.member.isImplicit() && toType == caster.member.getTargetType())
324 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 357
 	public boolean canCast(ITypeID toType) {
@@ -363,9 +386,11 @@ public final class TypeMembers {
363 386
 				return caster.member.cast(position, value, implicit);
364 387
 		}
365 388
 		for (TypeMember<ImplementationMember> implementation : implementations) {
366
-			if (implementation.member.type == toType)
389
+			if (implementation.member.type.equals(toType))
367 390
 				return new InterfaceCastExpression(position, value, toType);
368 391
 		}
392
+		if (extendsType(toType))
393
+			return new SupertypeCastExpression(position, value, toType);
369 394
 		
370 395
 		throw new CompileException(position, CompileExceptionCode.INVALID_CAST, "Could not cast " + toString() + " to " + toType);
371 396
 	}

+ 2
- 0
Constructor/libraries/collections/src/HashSet.zs 查看文件

@@ -3,6 +3,8 @@ export class HashSet<T> {
3 3
 		add(value as T) as bool;
4 4
 		remove(value as T) as bool;
5 5
 		
6
+		get size as int;
7
+		
6 8
 		in(value as T) as bool;
7 9
 		for(x as T);
8 10
 	}

+ 35
- 5
Constructor/libraries/collections/src/LinkedList.zs 查看文件

@@ -1,6 +1,7 @@
1 1
 export class LinkedList<T> {
2 2
 	var first as Node?;
3 3
 	var last as Node?;
4
+	var size as int : get;
4 5
 	
5 6
 	public get empty as bool
6 7
 		=> first == null;
@@ -14,16 +15,45 @@ export class LinkedList<T> {
14 15
 			node.prev = last;
15 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 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 57
 			return first.value;
28 58
 		}
29 59
 		

+ 5
- 1
Constructor/libraries/collections/src/Set.zs 查看文件

@@ -2,7 +2,11 @@ export interface Set<T> {
2 2
 	add(value as T) as bool;
3 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 11
 	for(x as T);
8 12
 }

+ 21
- 0
Constructor/libraries/collections/src/Stack.zs 查看文件

@@ -0,0 +1,21 @@
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 查看文件

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

+ 10
- 0
Constructor/libraries/io/src/Reader.zs 查看文件

@@ -0,0 +1,10 @@
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 查看文件

@@ -0,0 +1,22 @@
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 查看文件

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

+ 19
- 0
Constructor/libraries/stdlib/src/Arrays.zs 查看文件

@@ -0,0 +1,19 @@
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 查看文件

@@ -1,4 +1,4 @@
1 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 查看文件

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

+ 5
- 0
Constructor/libraries/stdlib/src/Integers.zs 查看文件

@@ -2,4 +2,9 @@ expand int {
2 2
 	public extern toHexString() as string;
3 3
 	public static extern parse(value as string) as int;
4 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 查看文件

@@ -3,6 +3,8 @@ export class StringBuilder {
3 3
 	public extern this(capacity as int);
4 4
 	public extern this(value as string);
5 5
 	
6
+	public extern get empty as bool;
7
+	
6 8
 	public extern <<(value as bool) as StringBuilder;
7 9
 	public extern <<(value as char) as StringBuilder;
8 10
 	public extern <<(value as byte) as StringBuilder;

+ 3
- 5
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java 查看文件

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

+ 2
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java 查看文件

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

+ 27
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java 查看文件

@@ -468,8 +468,10 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
468 468
 
469 469
     @Override
470 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 472
         if (expression.from.type.accept(JavaTypeClassVisitor.INSTANCE) != int.class)
472 473
             throw new CompileException(expression.position, CompileExceptionCode.INTERNAL_ERROR, "Only integer ranges supported");
474
+		
473 475
         javaWriter.newObject(IntRange.class);
474 476
         javaWriter.dup();
475 477
         expression.from.accept(this);
@@ -479,6 +481,26 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
479 481
 
480 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 505
     @Override
484 506
     public Void visitSetField(SetFieldExpression expression) {
@@ -534,6 +556,11 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
534 556
     public Void visitStaticSetter(StaticSetterExpression expression) {
535 557
         return null;
536 558
     }
559
+	
560
+	@Override
561
+	public Void visitSupertypeCast(SupertypeCastExpression expression) {
562
+		return null; // nothing to do
563
+	}
537 564
 
538 565
     @Override
539 566
     public Void visitThis(ThisExpression expression) {

+ 12
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java 查看文件

@@ -55,6 +55,7 @@ import org.openzen.zenscript.codemodel.expression.NullExpression;
55 55
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
56 56
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57 57
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
58
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
58 59
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59 60
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
60 61
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
@@ -62,6 +63,7 @@ import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
62 63
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
63 64
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
64 65
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
66
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
65 67
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
66 68
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
67 69
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
@@ -347,6 +349,11 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
347 349
 	public Void visitRange(RangeExpression expression) {
348 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 358
 	@Override
352 359
 	public Void visitSetField(SetFieldExpression expression) {
@@ -382,6 +389,11 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
382 389
 	public Void visitStaticSetter(StaticSetterExpression expression) {
383 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 398
 	@Override
387 399
 	public Void visitThis(ThisExpression expression) {

+ 12
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java 查看文件

@@ -55,6 +55,7 @@ import org.openzen.zenscript.codemodel.expression.NullExpression;
55 55
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
56 56
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57 57
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
58
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
58 59
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59 60
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
60 61
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
@@ -62,6 +63,7 @@ import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
62 63
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
63 64
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
64 65
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
66
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
65 67
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
66 68
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
67 69
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
@@ -353,6 +355,11 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
353 355
 	public Void visitRange(RangeExpression expression) {
354 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 364
 	@Override
358 365
 	public Void visitSetField(SetFieldExpression expression) {
@@ -388,6 +395,11 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
388 395
 	public Void visitStaticSetter(StaticSetterExpression expression) {
389 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 404
 	@Override
393 405
 	public Void visitThis(ThisExpression expression) {

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java 查看文件

@@ -233,7 +233,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
233 233
             javaWriter.label(catchStart);
234 234
 
235 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 237
             final int local = javaWriter.local(exceptionType);
238 238
             javaWriter.store(exceptionType, local);
239 239
 

+ 18
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java 查看文件

@@ -94,6 +94,24 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
94 94
         statementVisitor.end();
95 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 116
     @Override
99 117
     public Void visitMethod(MethodMember member) {

+ 0
- 2
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenStream.java 查看文件

@@ -37,8 +37,6 @@ public class ZSTokenStream extends TokenStream<ZSToken, ZSTokenType> {
37 37
 		KEYWORDS.put("final", K_FINAL);
38 38
 		KEYWORDS.put("override", K_OVERRIDE);
39 39
 		KEYWORDS.put("const", K_CONST);
40
-		KEYWORDS.put("shared", K_SHARED);
41
-		KEYWORDS.put("weak", K_WEAK);
42 40
 		KEYWORDS.put("private", K_PRIVATE);
43 41
 		KEYWORDS.put("public", K_PUBLIC);
44 42
 		KEYWORDS.put("export", K_EXPORT);

+ 0
- 2
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java 查看文件

@@ -87,8 +87,6 @@ public enum ZSTokenType implements TokenType {
87 87
 	K_FINAL,
88 88
 	K_OVERRIDE,
89 89
 	K_CONST,
90
-	K_SHARED,
91
-	K_WEAK,
92 90
 	K_PRIVATE,
93 91
 	K_PUBLIC,
94 92
 	K_EXPORT,

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java 查看文件

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

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java 查看文件

@@ -52,7 +52,7 @@ public class ParsedExpressionCall extends ParsedExpression {
52 52
 			if (!(member instanceof ConstructorMember))
53 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 56
 		} else if (receiver instanceof ParsedExpressionThis) {
57 57
 			// this call (intended as first call in constructor)
58 58
 			ITypeID targetType = scope.getThisType();
@@ -63,7 +63,7 @@ public class ParsedExpressionCall extends ParsedExpression {
63 63
 			if (!(member instanceof ConstructorMember))
64 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 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 查看文件

@@ -45,13 +45,14 @@ public class ParsedExpressionMap extends ParsedExpression {
45 45
 
46 46
 	@Override
47 47
 	public IPartialExpression compile(ExpressionScope scope) {
48
+		AssocTypeID assocHint = null;
48 49
 		List<ITypeID> keyHints = new ArrayList<>();
49 50
 		List<ITypeID> valueHints = new ArrayList<>();
50 51
 		
51 52
 		boolean hasAssocHint = false;
52 53
 		for (ITypeID hint : scope.hints) {
53 54
 			if (hint instanceof AssocTypeID) {
54
-				AssocTypeID assocHint = (AssocTypeID) hint;
55
+				assocHint = (AssocTypeID) hint;
55 56
 				if (!keyHints.contains(assocHint.keyType))
56 57
 					keyHints.add(assocHint.keyType);
57 58
 				if (!valueHints.contains(assocHint.valueType))
@@ -67,6 +68,14 @@ public class ParsedExpressionMap extends ParsedExpression {
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 79
 		if (!hasAssocHint && scope.hints.size() == 1 && scope.hints.get(0) != BasicTypeID.ANY) {
71 80
 			// compile as constructor call
72 81
 			ITypeID hint = scope.hints.get(0);

+ 7
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionString.java 查看文件

@@ -27,8 +27,13 @@ public class ParsedExpressionString extends ParsedExpression {
27 27
 
28 28
 	@Override
29 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 39
 		return new ConstantStringExpression(position, value);

+ 3
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java 查看文件

@@ -57,6 +57,9 @@ public class ParsedNewExpression extends ParsedExpression{
57 57
 		if (!(member instanceof ConstructorMember))
58 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 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 查看文件

@@ -174,6 +174,7 @@ public abstract class ParsedDefinitionMember {
174 174
 				return new ParsedCaller(start, forDefinition, modifiers, header, body);
175 175
 			}
176 176
 			case T_SQOPEN: {
177
+				tokens.next();
177 178
 				tokens.required(ZSTokenType.T_SQCLOSE, "] expected");
178 179
 				OperatorType operator = OperatorType.INDEXGET;
179 180
 				if (tokens.optional(ZSTokenType.T_ASSIGN) != null) {
@@ -183,9 +184,20 @@ public abstract class ParsedDefinitionMember {
183 184
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
184 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 199
 			case T_ADD:
187 200
 			case T_SUB:
188
-			case T_CAT:
189 201
 			case T_MUL:
190 202
 			case T_DIV:
191 203
 			case T_MOD:

+ 27
- 0
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDestructor.java 查看文件

@@ -0,0 +1,27 @@
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 查看文件

@@ -5,26 +5,95 @@
5 5
  */
6 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 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 20
 import org.openzen.zenscript.linker.StatementScope;
10 21
 import org.openzen.zenscript.parser.type.IParsedType;
22
+import org.openzen.zenscript.shared.CodePosition;
11 23
 
12 24
 /**
13 25
  *
14 26
  * @author Hoofdgebruiker
15 27
  */
16 28
 public class ParsedCatchClause {
29
+	public final CodePosition position;
17 30
 	public final String exceptionName;
18 31
 	public final IParsedType exceptionType;
19 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 36
 		this.exceptionName = exceptionName;
23 37
 		this.exceptionType = exceptionType;
24 38
 		this.content = content;
25 39
 	}
26 40
 	
27 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 查看文件

@@ -197,6 +197,8 @@ public abstract class ParsedStatement {
197 197
 				ParsedStatement content = parse(parser);
198 198
 				List<ParsedCatchClause> catchClauses = new ArrayList<>();
199 199
 				while (parser.optional(K_CATCH) != null) {
200
+					CodePosition position = parser.getPosition();
201
+					
200 202
 					String catchName = null;
201 203
 					if (parser.isNext(ZSTokenType.T_IDENTIFIER))
202 204
 						catchName = parser.next().content;
@@ -206,7 +208,7 @@ public abstract class ParsedStatement {
206 208
 						catchType = IParsedType.parse(parser);
207 209
 					
208 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 214
 				ParsedStatement finallyClause = null;

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementTryCatch.java 查看文件

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

+ 0
- 4
Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java 查看文件

@@ -37,10 +37,6 @@ public interface IParsedType {
37 37
 		while (true) {
38 38
 			if (tokens.optional(ZSTokenType.K_CONST) != null) {
39 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 40
 			} else {
45 41
 				break;
46 42
 			}

+ 2
- 1
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java 查看文件

@@ -61,6 +61,7 @@ public class ValidationLogEntry {
61 61
 		INVALID_SOURCE_TYPE,
62 62
 		SETTING_FINAL_FIELD,
63 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 查看文件

@@ -15,6 +15,7 @@ import org.openzen.zenscript.codemodel.member.CallerMember;
15 15
 import org.openzen.zenscript.codemodel.member.CasterMember;
16 16
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
17 17
 import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
18
+import org.openzen.zenscript.codemodel.member.DestructorMember;
18 19
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
19 20
 import org.openzen.zenscript.codemodel.member.FieldMember;
20 21
 import org.openzen.zenscript.codemodel.member.GetterMember;
@@ -47,6 +48,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
47 48
 	private final HighLevelDefinition definition;
48 49
 	private final Set<EnumConstantMember> initializedEnumConstants = new HashSet<>();
49 50
 	private final Set<ITypeID> implementedTypes = new HashSet<>();
51
+	private boolean hasDestructor = false;
50 52
 	
51 53
 	public DefinitionMemberValidator(Validator validator, HighLevelDefinition definition) {
52 54
 		this.validator = validator;
@@ -100,6 +102,21 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
100 102
 		
101 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 121
 	@Override
105 122
 	public Boolean visitMethod(MethodMember member) {

+ 5
- 1
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java 查看文件

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

+ 16
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java 查看文件

@@ -58,6 +58,7 @@ import org.openzen.zenscript.codemodel.expression.NullExpression;
58 58
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
59 59
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
60 60
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
61
+import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
61 62
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
62 63
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
63 64
 import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
@@ -65,6 +66,7 @@ import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
65 66
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
66 67
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
67 68
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
69
+import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
68 70
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
69 71
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
70 72
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
@@ -496,6 +498,14 @@ public class ExpressionValidator implements ExpressionVisitor<Boolean> {
496 498
 		}
497 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 510
 	@Override
501 511
 	public Boolean visitSetField(SetFieldExpression expression) {
@@ -607,6 +617,12 @@ public class ExpressionValidator implements ExpressionVisitor<Boolean> {
607 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 626
 	@Override
611 627
 	public Boolean visitThis(ThisExpression expression) {
612 628
 		if (!scope.hasThis()) {

正在加载...
取消
保存