Browse Source

- Annotations are now serializable

- Fixed various serialization bugs, continuing work on serializer
Stan Hebben 6 years ago
parent
commit
17a2cadf8a
35 changed files with 353 additions and 66 deletions
  1. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/Annotation.java
  2. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationDefinition.java
  3. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/DefinitionAnnotation.java
  4. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/MemberAnnotation.java
  5. 25
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeAnnotationDefinition.java
  6. 12
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeDefinitionAnnotation.java
  7. 12
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeMemberAnnotation.java
  8. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionAnnotationDefinition.java
  9. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionForMethod.java
  10. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/StatementAnnotation.java
  11. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java
  12. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java
  13. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  14. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java
  15. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java
  16. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ImplementationMember.java
  17. 6
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinitionMember.java
  18. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java
  19. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java
  20. 3
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/serialization/CodeSerializationInput.java
  21. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/serialization/CodeSerializationOutput.java
  22. 2
    2
      IDE/src/main/java/org/openzen/zenscript/ide/Arguments.java
  23. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/JavaBytecodeMain.java
  24. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/Main.java
  25. 16
    3
      ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/CodeReader.java
  26. 46
    16
      ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/DefinitionMemberDeserializer.java
  27. 13
    5
      ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/ModuleDeserializer.java
  28. 1
    0
      ModuleSerializationShared/src/main/java/org/openzen/zenscript/moduleserialization/DefinitionEncoding.java
  29. 1
    0
      ModuleSerializationShared/src/main/java/org/openzen/zenscript/moduleserialization/MemberEncoding.java
  30. 21
    12
      ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/CodeWriter.java
  31. 17
    2
      ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/ModuleSerializer.java
  32. 11
    0
      ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/TableBuilder.java
  33. 0
    4
      ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/encoder/DefinitionMemberSerializer.java
  34. 15
    3
      ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/encoder/DefinitionSerializer.java
  35. 27
    15
      ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/encoder/MemberSerializer.java

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

12
 public interface Annotation {
12
 public interface Annotation {
13
 	public static final Annotation[] NONE = new Annotation[0];
13
 	public static final Annotation[] NONE = new Annotation[0];
14
 	
14
 	
15
+	public AnnotationDefinition getDefinition();
16
+	
15
 	public void apply();
17
 	public void apply();
16
 }
18
 }

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

10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionParameter;
11
 import org.openzen.zenscript.codemodel.FunctionParameter;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.context.StatementContext;
14
+import org.openzen.zenscript.codemodel.context.TypeContext;
13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
16
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
15
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
 import org.openzen.zenscript.codemodel.scope.StatementScope;
19
 import org.openzen.zenscript.codemodel.scope.StatementScope;
20
+import org.openzen.zenscript.codemodel.serialization.CodeSerializationInput;
18
 import org.openzen.zenscript.codemodel.statement.Statement;
21
 import org.openzen.zenscript.codemodel.statement.Statement;
19
 
22
 
20
 /**
23
 /**
41
 	public StatementAnnotation createForStatement(CodePosition position, CallArguments arguments);
44
 	public StatementAnnotation createForStatement(CodePosition position, CallArguments arguments);
42
 	
45
 	
43
 	public Annotation createForParameter(CodePosition position, CallArguments arguments);
46
 	public Annotation createForParameter(CodePosition position, CallArguments arguments);
47
+	
48
+	public MemberAnnotation deserializeForMember(CodeSerializationInput input, TypeContext context, IDefinitionMember member);
49
+	
50
+	public DefinitionAnnotation deserializeForDefinition(CodeSerializationInput input, TypeContext context);
51
+	
52
+	public StatementAnnotation deserializeForStatement(CodeSerializationInput input, StatementContext context);
53
+	
54
+	public Annotation deserializeForParameter(CodeSerializationInput input, TypeContext context);
44
 }
55
 }

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

6
 package org.openzen.zenscript.codemodel.annotations;
6
 package org.openzen.zenscript.codemodel.annotations;
7
 
7
 
8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.context.TypeContext;
9
 import org.openzen.zenscript.codemodel.scope.BaseScope;
10
 import org.openzen.zenscript.codemodel.scope.BaseScope;
11
+import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
10
 
12
 
11
 /**
13
 /**
12
  *
14
  *
15
 public interface DefinitionAnnotation {
17
 public interface DefinitionAnnotation {
16
 	public static final DefinitionAnnotation[] NONE = new DefinitionAnnotation[0];
18
 	public static final DefinitionAnnotation[] NONE = new DefinitionAnnotation[0];
17
 	
19
 	
20
+	public AnnotationDefinition getDefinition();
21
+	
18
 	public void apply(HighLevelDefinition definition, BaseScope scope);
22
 	public void apply(HighLevelDefinition definition, BaseScope scope);
19
 	
23
 	
20
 	public void applyOnSubtype(HighLevelDefinition definition, BaseScope scope);
24
 	public void applyOnSubtype(HighLevelDefinition definition, BaseScope scope);
25
+	
26
+	public void serialize(CodeSerializationOutput output, HighLevelDefinition definition, TypeContext context);
21
 }
27
 }

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.annotations;
6
 package org.openzen.zenscript.codemodel.annotations;
7
 
7
 
8
+import org.openzen.zenscript.codemodel.context.TypeContext;
8
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
 import org.openzen.zenscript.codemodel.member.GetterMember;
10
 import org.openzen.zenscript.codemodel.member.GetterMember;
10
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11
 import org.openzen.zenscript.codemodel.member.SetterMember;
12
 import org.openzen.zenscript.codemodel.member.SetterMember;
12
 import org.openzen.zenscript.codemodel.scope.BaseScope;
13
 import org.openzen.zenscript.codemodel.scope.BaseScope;
14
+import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
13
 
15
 
14
 /**
16
 /**
15
  *
17
  *
18
 public interface MemberAnnotation {
20
 public interface MemberAnnotation {
19
 	public static final MemberAnnotation[] NONE = new MemberAnnotation[0];
21
 	public static final MemberAnnotation[] NONE = new MemberAnnotation[0];
20
 	
22
 	
23
+	public AnnotationDefinition getDefinition();
24
+	
21
 	public void apply(IDefinitionMember member, BaseScope scope);
25
 	public void apply(IDefinitionMember member, BaseScope scope);
22
 	
26
 	
23
 	public void applyOnOverridingMethod(FunctionalMember member, BaseScope scope);
27
 	public void applyOnOverridingMethod(FunctionalMember member, BaseScope scope);
25
 	public void applyOnOverridingGetter(GetterMember member, BaseScope scope);
29
 	public void applyOnOverridingGetter(GetterMember member, BaseScope scope);
26
 	
30
 	
27
 	public void applyOnOverridingSetter(SetterMember member, BaseScope scope);
31
 	public void applyOnOverridingSetter(SetterMember member, BaseScope scope);
32
+	
33
+	public void serialize(CodeSerializationOutput output, IDefinitionMember member, TypeContext context);
28
 }
34
 }

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

11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionParameter;
12
 import org.openzen.zenscript.codemodel.FunctionParameter;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
+import org.openzen.zenscript.codemodel.context.StatementContext;
15
+import org.openzen.zenscript.codemodel.context.TypeContext;
14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
16
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15
 import org.openzen.zenscript.codemodel.expression.Expression;
17
 import org.openzen.zenscript.codemodel.expression.Expression;
16
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
18
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
19
 import org.openzen.zenscript.codemodel.scope.BaseScope;
18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
20
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
19
 import org.openzen.zenscript.codemodel.scope.StatementScope;
21
 import org.openzen.zenscript.codemodel.scope.StatementScope;
22
+import org.openzen.zenscript.codemodel.serialization.CodeSerializationInput;
20
 import org.openzen.zenscript.codemodel.statement.Statement;
23
 import org.openzen.zenscript.codemodel.statement.Statement;
21
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
24
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
22
 
25
 
85
 	public Annotation createForParameter(CodePosition position, CallArguments arguments) {
88
 	public Annotation createForParameter(CodePosition position, CallArguments arguments) {
86
 		throw new UnsupportedOperationException("Not supported");
89
 		throw new UnsupportedOperationException("Not supported");
87
 	}
90
 	}
91
+
92
+	@Override
93
+	public MemberAnnotation deserializeForMember(CodeSerializationInput input, TypeContext context, IDefinitionMember member) {
94
+		String name = input.readString();
95
+		return new NativeMemberAnnotation(name);
96
+	}
97
+
98
+	@Override
99
+	public DefinitionAnnotation deserializeForDefinition(CodeSerializationInput input, TypeContext context) {
100
+		String name = input.readString();
101
+		return new NativeDefinitionAnnotation(name);
102
+	}
103
+
104
+	@Override
105
+	public StatementAnnotation deserializeForStatement(CodeSerializationInput input, StatementContext context) {
106
+		throw new UnsupportedOperationException("Not supported");
107
+	}
108
+
109
+	@Override
110
+	public Annotation deserializeForParameter(CodeSerializationInput input, TypeContext context) {
111
+		throw new UnsupportedOperationException("Not supported");
112
+	}
88
 }
113
 }

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

6
 package org.openzen.zenscript.codemodel.annotations;
6
 package org.openzen.zenscript.codemodel.annotations;
7
 
7
 
8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.context.TypeContext;
9
 import org.openzen.zenscript.codemodel.scope.BaseScope;
10
 import org.openzen.zenscript.codemodel.scope.BaseScope;
11
+import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
10
 
12
 
11
 /**
13
 /**
12
  *
14
  *
18
 	public NativeDefinitionAnnotation(String identifier) {
20
 	public NativeDefinitionAnnotation(String identifier) {
19
 		this.identifier = identifier;
21
 		this.identifier = identifier;
20
 	}
22
 	}
23
+
24
+	@Override
25
+	public AnnotationDefinition getDefinition() {
26
+		return NativeAnnotationDefinition.INSTANCE;
27
+	}
21
 	
28
 	
22
 	@Override
29
 	@Override
23
 	public void apply(HighLevelDefinition definition, BaseScope scope) {
30
 	public void apply(HighLevelDefinition definition, BaseScope scope) {
28
 	public void applyOnSubtype(HighLevelDefinition definition, BaseScope scope) {
35
 	public void applyOnSubtype(HighLevelDefinition definition, BaseScope scope) {
29
 		// this annotation is not inherited
36
 		// this annotation is not inherited
30
 	}
37
 	}
38
+
39
+	@Override
40
+	public void serialize(CodeSerializationOutput output, HighLevelDefinition definition, TypeContext context) {
41
+		output.writeString(identifier);
42
+	}
31
 }
43
 }

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.annotations;
6
 package org.openzen.zenscript.codemodel.annotations;
7
 
7
 
8
+import org.openzen.zenscript.codemodel.context.TypeContext;
8
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
 import org.openzen.zenscript.codemodel.member.GetterMember;
10
 import org.openzen.zenscript.codemodel.member.GetterMember;
10
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11
 import org.openzen.zenscript.codemodel.member.SetterMember;
12
 import org.openzen.zenscript.codemodel.member.SetterMember;
12
 import org.openzen.zenscript.codemodel.scope.BaseScope;
13
 import org.openzen.zenscript.codemodel.scope.BaseScope;
14
+import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
13
 
15
 
14
 /**
16
 /**
15
  *
17
  *
21
 	public NativeMemberAnnotation(String identifier) {
23
 	public NativeMemberAnnotation(String identifier) {
22
 		this.identifier = identifier;
24
 		this.identifier = identifier;
23
 	}
25
 	}
26
+
27
+	@Override
28
+	public AnnotationDefinition getDefinition() {
29
+		return NativeAnnotationDefinition.INSTANCE;
30
+	}
24
 	
31
 	
25
 	@Override
32
 	@Override
26
 	public void apply(IDefinitionMember member, BaseScope scope) {
33
 	public void apply(IDefinitionMember member, BaseScope scope) {
41
 	public void applyOnOverridingSetter(SetterMember member, BaseScope scope) {
48
 	public void applyOnOverridingSetter(SetterMember member, BaseScope scope) {
42
 		// not inherited
49
 		// not inherited
43
 	}
50
 	}
51
+
52
+	@Override
53
+	public void serialize(CodeSerializationOutput output, IDefinitionMember member, TypeContext context) {
54
+		output.writeString(identifier);
55
+	}
44
 }
56
 }

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

12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
+import org.openzen.zenscript.codemodel.context.StatementContext;
16
+import org.openzen.zenscript.codemodel.context.TypeContext;
15
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
17
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
16
 import org.openzen.zenscript.codemodel.expression.CallArguments;
18
 import org.openzen.zenscript.codemodel.expression.CallArguments;
17
 import org.openzen.zenscript.codemodel.expression.Expression;
19
 import org.openzen.zenscript.codemodel.expression.Expression;
21
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
23
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
22
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
24
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
23
 import org.openzen.zenscript.codemodel.scope.StatementScope;
25
 import org.openzen.zenscript.codemodel.scope.StatementScope;
26
+import org.openzen.zenscript.codemodel.serialization.CodeSerializationInput;
24
 import org.openzen.zenscript.codemodel.statement.Statement;
27
 import org.openzen.zenscript.codemodel.statement.Statement;
25
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
28
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
26
 import org.openzen.zenscript.codemodel.type.GenericName;
29
 import org.openzen.zenscript.codemodel.type.GenericName;
104
 	public Annotation createForParameter(CodePosition position, CallArguments arguments) {
107
 	public Annotation createForParameter(CodePosition position, CallArguments arguments) {
105
 		throw new UnsupportedOperationException("Not supported");
108
 		throw new UnsupportedOperationException("Not supported");
106
 	}
109
 	}
110
+
111
+	@Override
112
+	public MemberAnnotation deserializeForMember(CodeSerializationInput input, TypeContext context, IDefinitionMember member) {
113
+		CodePosition position = input.deserializePosition();
114
+		String enforcement = input.readString();
115
+		StatementContext statementContext = new StatementContext(context, member.getHeader());
116
+		Expression condition = input.deserializeExpression(statementContext);
117
+		Expression message = input.deserializeExpression(statementContext);
118
+		return new PreconditionForMethod(position, enforcement, condition, message);
119
+	}
120
+
121
+	@Override
122
+	public DefinitionAnnotation deserializeForDefinition(CodeSerializationInput input, TypeContext context) {
123
+		throw new UnsupportedOperationException("Not supported");
124
+	}
125
+
126
+	@Override
127
+	public StatementAnnotation deserializeForStatement(CodeSerializationInput input, StatementContext context) {
128
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
129
+	}
130
+
131
+	@Override
132
+	public Annotation deserializeForParameter(CodeSerializationInput input, TypeContext context) {
133
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
134
+	}
107
 }
135
 }

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

9
 import java.util.Arrays;
9
 import java.util.Arrays;
10
 import java.util.List;
10
 import java.util.List;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zenscript.codemodel.context.StatementContext;
13
+import org.openzen.zenscript.codemodel.context.TypeContext;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.ExpressionBuilder;
15
 import org.openzen.zenscript.codemodel.expression.ExpressionBuilder;
14
 import org.openzen.zenscript.codemodel.expression.PanicExpression;
16
 import org.openzen.zenscript.codemodel.expression.PanicExpression;
18
 import org.openzen.zenscript.codemodel.member.SetterMember;
20
 import org.openzen.zenscript.codemodel.member.SetterMember;
19
 import org.openzen.zenscript.codemodel.scope.BaseScope;
21
 import org.openzen.zenscript.codemodel.scope.BaseScope;
20
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
22
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
23
+import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
21
 import org.openzen.zenscript.codemodel.statement.BlockStatement;
24
 import org.openzen.zenscript.codemodel.statement.BlockStatement;
22
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
25
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
23
 import org.openzen.zenscript.codemodel.statement.IfStatement;
26
 import org.openzen.zenscript.codemodel.statement.IfStatement;
44
 		this.condition = condition;
47
 		this.condition = condition;
45
 		this.message = message;
48
 		this.message = message;
46
 	}
49
 	}
50
+	
51
+	@Override
52
+	public AnnotationDefinition getDefinition() {
53
+		return PreconditionAnnotationDefinition.INSTANCE;
54
+	}
47
 
55
 
48
 	@Override
56
 	@Override
49
 	public void apply(IDefinitionMember member, BaseScope scope) {
57
 	public void apply(IDefinitionMember member, BaseScope scope) {
89
 		}
97
 		}
90
 		return new BlockStatement(position, statements.toArray(new Statement[statements.size()]));
98
 		return new BlockStatement(position, statements.toArray(new Statement[statements.size()]));
91
 	}
99
 	}
100
+
101
+	@Override
102
+	public void serialize(CodeSerializationOutput output, IDefinitionMember member, TypeContext context) {
103
+		output.serialize(position);
104
+		output.writeString(enforcement);
105
+		StatementContext statementContext = new StatementContext(context, member.getHeader());
106
+		output.serialize(statementContext, condition);
107
+		output.serialize(statementContext, message);
108
+	}
92
 }
109
 }

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

15
 public interface StatementAnnotation {
15
 public interface StatementAnnotation {
16
 	public static final StatementAnnotation[] NONE = new StatementAnnotation[0];
16
 	public static final StatementAnnotation[] NONE = new StatementAnnotation[0];
17
 	
17
 	
18
+	public AnnotationDefinition getDefinition();
19
+	
18
 	public Statement apply(Statement statement, StatementScope scope);
20
 	public Statement apply(Statement statement, StatementScope scope);
19
 }
21
 }

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

6
 package org.openzen.zenscript.codemodel.member;
6
 package org.openzen.zenscript.codemodel.member;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
71
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
72
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
72
 		return new ConstMemberRef(type, this, mapper);
73
 		return new ConstMemberRef(type, this, mapper);
73
 	}
74
 	}
75
+	
76
+	@Override
77
+	public FunctionHeader getHeader() {
78
+		return null;
79
+	}
74
 }
80
 }

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

6
 package org.openzen.zenscript.codemodel.member;
6
 package org.openzen.zenscript.codemodel.member;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
162
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
163
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
163
 		return new FieldMemberRef(type, this, mapper);
164
 		return new FieldMemberRef(type, this, mapper);
164
 	}
165
 	}
166
+	
167
+	@Override
168
+	public FunctionHeader getHeader() {
169
+		return null;
170
+	}
165
 }
171
 }

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

66
 	public boolean isAbstract() {
66
 	public boolean isAbstract() {
67
 		return body == null && builtin == null;
67
 		return body == null && builtin == null;
68
 	}
68
 	}
69
+	
70
+	@Override
71
+	public FunctionHeader getHeader() {
72
+		return header;
73
+	}
69
 }
74
 }

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

7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.ConcatMap;
9
 import org.openzen.zencode.shared.ConcatMap;
10
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
95
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
96
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
96
 		return new GetterMemberRef(type, this, mapper);
97
 		return new GetterMemberRef(type, this, mapper);
97
 	}
98
 	}
99
+	
100
+	@Override
101
+	public FunctionHeader getHeader() {
102
+		return new FunctionHeader(type);
103
+	}
98
 }
104
 }

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

6
 package org.openzen.zenscript.codemodel.member;
6
 package org.openzen.zenscript.codemodel.member;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
12
 import org.openzen.zenscript.codemodel.scope.TypeScope;
14
 import org.openzen.zenscript.codemodel.scope.TypeScope;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
24
 	
26
 	
25
 	public int getModifiers();
27
 	public int getModifiers();
26
 	
28
 	
29
+	public MemberAnnotation[] getAnnotations();
30
+	
27
 	public HighLevelDefinition getDefinition();
31
 	public HighLevelDefinition getDefinition();
28
 	
32
 	
29
 	public String describe();
33
 	public String describe();
49
 	boolean isAbstract();
53
 	boolean isAbstract();
50
 	
54
 	
51
 	DefinitionMemberRef ref(ITypeID type, GenericMapper mapper);
55
 	DefinitionMemberRef ref(ITypeID type, GenericMapper mapper);
56
+	
57
+	FunctionHeader getHeader();
52
 }
58
 }

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

8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
85
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
86
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
86
 		throw new UnsupportedOperationException("Cannot create an implementation reference");
87
 		throw new UnsupportedOperationException("Cannot create an implementation reference");
87
 	}
88
 	}
89
+
90
+	@Override
91
+	public FunctionHeader getHeader() {
92
+		return null;
93
+	}
88
 }
94
 }

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

6
 package org.openzen.zenscript.codemodel.member;
6
 package org.openzen.zenscript.codemodel.member;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.Modifiers;
12
 import org.openzen.zenscript.codemodel.Modifiers;
12
-import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
13
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
13
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
14
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
15
 import org.openzen.zenscript.codemodel.scope.TypeScope;
15
 import org.openzen.zenscript.codemodel.scope.TypeScope;
79
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
79
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
80
 		throw new UnsupportedOperationException("Cannot create an inner definition reference");
80
 		throw new UnsupportedOperationException("Cannot create an inner definition reference");
81
 	}
81
 	}
82
+	
83
+	@Override
84
+	public FunctionHeader getHeader() {
85
+		return null;
86
+	}
82
 }
87
 }

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

7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.ConcatMap;
9
 import org.openzen.zencode.shared.ConcatMap;
10
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.FunctionParameter;
11
 import org.openzen.zenscript.codemodel.FunctionParameter;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
100
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
101
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
101
 		return new SetterMemberRef(type, this, mapper);
102
 		return new SetterMemberRef(type, this, mapper);
102
 	}
103
 	}
104
+	
105
+	@Override
106
+	public FunctionHeader getHeader() {
107
+		return new FunctionHeader(BasicTypeID.VOID, type);
108
+	}
103
 }
109
 }

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

7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.ConcatMap;
9
 import org.openzen.zencode.shared.ConcatMap;
10
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
14
 import org.openzen.zenscript.codemodel.scope.TypeScope;
14
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
15
 import org.openzen.zenscript.codemodel.statement.Statement;
16
 import org.openzen.zenscript.codemodel.statement.Statement;
17
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
19
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
18
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
20
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
73
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
75
 	public DefinitionMemberRef ref(ITypeID type, GenericMapper mapper) {
74
 		throw new UnsupportedOperationException("Cannot reference a static initializer");
76
 		throw new UnsupportedOperationException("Cannot reference a static initializer");
75
 	}
77
 	}
78
+	
79
+	@Override
80
+	public FunctionHeader getHeader() {
81
+		return new FunctionHeader(BasicTypeID.VOID);
82
+	}
76
 }
83
 }

+ 3
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/serialization/CodeSerializationInput.java View File

8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
-import org.openzen.zenscript.codemodel.context.ModuleContext;
11
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
59
 	
59
 	
60
 	VariantOptionRef readVariantOption(TypeContext context, ITypeID type);
60
 	VariantOptionRef readVariantOption(TypeContext context, ITypeID type);
61
 	
61
 	
62
+	AnnotationDefinition readAnnotationType();
63
+	
62
 	ITypeID deserializeType(TypeContext context);
64
 	ITypeID deserializeType(TypeContext context);
63
 	
65
 	
64
 	CodePosition deserializePosition();
66
 	CodePosition deserializePosition();

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

8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
14
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
60
 	
61
 	
61
 	void write(TypeContext context, DefinitionMemberRef member);
62
 	void write(TypeContext context, DefinitionMemberRef member);
62
 	
63
 	
64
+	void write(AnnotationDefinition annotationType);
65
+	
63
 	void serialize(TypeContext context, IDefinitionMember member);
66
 	void serialize(TypeContext context, IDefinitionMember member);
64
 	
67
 	
65
 	void serialize(TypeContext context, ITypeID type);
68
 	void serialize(TypeContext context, ITypeID type);

+ 2
- 2
IDE/src/main/java/org/openzen/zenscript/ide/Arguments.java View File

14
 public class Arguments {
14
 public class Arguments {
15
 	public final File projectDirectory;
15
 	public final File projectDirectory;
16
 	
16
 	
17
-	public Arguments(String[] arguments) {
18
-		File projectDir = new File("../../ZenCode"); // TODO: remove this and open a project chooser/creator instead
17
+	public Arguments(String[] arguments, File defaultProjectDir) {
18
+		File projectDir = defaultProjectDir;
19
 		int positional = 0;
19
 		int positional = 0;
20
 		for (int i = 0; i < arguments.length; i++) {
20
 		for (int i = 0; i < arguments.length; i++) {
21
 			switch (positional) {
21
 			switch (positional) {

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/JavaBytecodeMain.java View File

21
      * @param args the command line arguments
21
      * @param args the command line arguments
22
      */
22
      */
23
     public static void main(String[] args) throws IOException {
23
     public static void main(String[] args) throws IOException {
24
-		Arguments arguments = new Arguments(args);
24
+		Arguments arguments = new Arguments(args, new File("../../ZenCode")); // TODO: remove this and open a project chooser/creator instead
25
 		File directory = arguments.projectDirectory;
25
 		File directory = arguments.projectDirectory;
26
 		
26
 		
27
 		Project project = new Project(directory);
27
 		Project project = new Project(directory);

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/Main.java View File

18
      * @param args the command line arguments
18
      * @param args the command line arguments
19
      */
19
      */
20
     public static void main(String[] args) throws IOException {
20
     public static void main(String[] args) throws IOException {
21
-		Arguments arguments = new Arguments(args);
21
+		Arguments arguments = new Arguments(args, new File("../../ZenCode")); // TODO: remove this and open a project chooser/creator instead
22
 		File directory = arguments.projectDirectory;
22
 		File directory = arguments.projectDirectory;
23
 		
23
 		
24
 		Project project = new Project(directory);
24
 		Project project = new Project(directory);

+ 16
- 3
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/CodeReader.java View File

14
 import org.openzen.zenscript.codemodel.CompareType;
14
 import org.openzen.zenscript.codemodel.CompareType;
15
 import org.openzen.zenscript.codemodel.FunctionHeader;
15
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
 import org.openzen.zenscript.codemodel.FunctionParameter;
16
 import org.openzen.zenscript.codemodel.FunctionParameter;
17
-import org.openzen.zenscript.codemodel.GenericMapper;
18
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
17
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
18
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
19
 import org.openzen.zenscript.codemodel.context.StatementContext;
19
 import org.openzen.zenscript.codemodel.context.StatementContext;
20
 import org.openzen.zenscript.codemodel.context.TypeContext;
20
 import org.openzen.zenscript.codemodel.context.TypeContext;
21
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
21
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
91
 	
91
 	
92
 	private final String[] strings;
92
 	private final String[] strings;
93
 	private final SourceFile[] sourceFiles;
93
 	private final SourceFile[] sourceFiles;
94
+	private final AnnotationDefinition[] annotations;
94
 	private final List<HighLevelDefinition> definitions = new ArrayList<>();
95
 	private final List<HighLevelDefinition> definitions = new ArrayList<>();
95
 	private final List<IDefinitionMember> memberList = new ArrayList<>();
96
 	private final List<IDefinitionMember> memberList = new ArrayList<>();
96
 	private final List<EnumConstantMember> enumConstantMembers = new ArrayList<>();
97
 	private final List<EnumConstantMember> enumConstantMembers = new ArrayList<>();
102
 			CompactDataInput input,
103
 			CompactDataInput input,
103
 			String[] strings,
104
 			String[] strings,
104
 			SourceFile[] sourceFiles,
105
 			SourceFile[] sourceFiles,
106
+			AnnotationDefinition[] annotations,
105
 			GlobalTypeRegistry registry)
107
 			GlobalTypeRegistry registry)
106
 	{
108
 	{
107
 		this.input = input;
109
 		this.input = input;
108
 		
110
 		
109
 		this.strings = strings;
111
 		this.strings = strings;
110
 		this.sourceFiles = sourceFiles;
112
 		this.sourceFiles = sourceFiles;
113
+		this.annotations = annotations;
111
 		this.registry = registry;
114
 		this.registry = registry;
112
 	}
115
 	}
113
 	
116
 	
202
 
205
 
203
 	@Override
206
 	@Override
204
 	public HighLevelDefinition readDefinition() {
207
 	public HighLevelDefinition readDefinition() {
205
-		return definitions.get(input.readVarUInt());
208
+		int id = input.readVarUInt();
209
+		if (id == 0)
210
+			return null;
211
+		
212
+		HighLevelDefinition definition = definitions.get(id - 1);
213
+		return definition;
206
 	}
214
 	}
207
 
215
 
208
 	@Override
216
 	@Override
232
 	public VariantOptionRef readVariantOption(TypeContext context, ITypeID type) {
240
 	public VariantOptionRef readVariantOption(TypeContext context, ITypeID type) {
233
 		return variantOptions.get(readUInt()).instance(type, context.getMapper());
241
 		return variantOptions.get(readUInt()).instance(type, context.getMapper());
234
 	}
242
 	}
243
+	
244
+	@Override
245
+	public AnnotationDefinition readAnnotationType() {
246
+		return annotations[readUInt()];
247
+	}
235
 
248
 
236
 	@Override
249
 	@Override
237
 	public ITypeID deserializeType(TypeContext context) {
250
 	public ITypeID deserializeType(TypeContext context) {
344
 			fromLine = input.readVarUInt();
357
 			fromLine = input.readVarUInt();
345
 		if ((flags & CodePositionEncoding.FLAG_FROM_OFFSET) > 0)
358
 		if ((flags & CodePositionEncoding.FLAG_FROM_OFFSET) > 0)
346
 			fromLineOffset = input.readVarUInt();
359
 			fromLineOffset = input.readVarUInt();
347
-		int toLine = lastPosition.toLine;
360
+		int toLine = fromLine;
348
 		if ((flags & CodePositionEncoding.FLAG_TO_LINE) > 0)
361
 		if ((flags & CodePositionEncoding.FLAG_TO_LINE) > 0)
349
 			toLine = fromLine + input.readVarUInt();
362
 			toLine = fromLine + input.readVarUInt();
350
 		int toLineOffset = lastPosition.toLineOffset;
363
 		int toLineOffset = lastPosition.toLineOffset;

+ 46
- 16
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/DefinitionMemberDeserializer.java View File

9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.OperatorType;
12
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
12
 import org.openzen.zenscript.codemodel.context.StatementContext;
14
 import org.openzen.zenscript.codemodel.context.StatementContext;
13
 import org.openzen.zenscript.codemodel.context.TypeContext;
15
 import org.openzen.zenscript.codemodel.context.TypeContext;
14
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
16
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
26
 import org.openzen.zenscript.codemodel.member.CasterMember;
28
 import org.openzen.zenscript.codemodel.member.CasterMember;
27
 import org.openzen.zenscript.codemodel.member.ConstMember;
29
 import org.openzen.zenscript.codemodel.member.ConstMember;
28
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
30
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
31
+import org.openzen.zenscript.codemodel.member.DefinitionMember;
29
 import org.openzen.zenscript.codemodel.member.DestructorMember;
32
 import org.openzen.zenscript.codemodel.member.DestructorMember;
30
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
33
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
31
 import org.openzen.zenscript.codemodel.member.FieldMember;
34
 import org.openzen.zenscript.codemodel.member.FieldMember;
99
 			modifiers = reader.readUInt();
102
 			modifiers = reader.readUInt();
100
 		}
103
 		}
101
 		
104
 		
105
+		DefinitionMember member;
102
 		switch (kind) {
106
 		switch (kind) {
103
 			case MemberEncoding.TYPE_CONST: {
107
 			case MemberEncoding.TYPE_CONST: {
104
 				String name = readName(flags);
108
 				String name = readName(flags);
106
 				
110
 				
107
 				ConstMember result = new ConstMember(position, definition, modifiers, name, type, null);
111
 				ConstMember result = new ConstMember(position, definition, modifiers, name, type, null);
108
 				reader.enqueueCode(reader -> result.value = reader.deserializeExpression(new StatementContext(context)));
112
 				reader.enqueueCode(reader -> result.value = reader.deserializeExpression(new StatementContext(context)));
109
-				return result;
113
+				member = result;
114
+				break;
110
 			}
115
 			}
111
 			case MemberEncoding.TYPE_FIELD: {
116
 			case MemberEncoding.TYPE_FIELD: {
112
 				String name = readName(flags);
117
 				String name = readName(flags);
116
 				
121
 				
117
 				FieldMember result = new FieldMember(position, definition, flags, name, context.thisType, type, context.moduleContext.registry, autoGetterAccess, autoSetterAccess, null);
122
 				FieldMember result = new FieldMember(position, definition, flags, name, context.thisType, type, context.moduleContext.registry, autoGetterAccess, autoSetterAccess, null);
118
 				reader.enqueueCode(reader -> result.initializer = reader.deserializeExpression(new StatementContext(context)));
123
 				reader.enqueueCode(reader -> result.initializer = reader.deserializeExpression(new StatementContext(context)));
119
-				return result;
124
+				member = result;
125
+				break;
120
 			}
126
 			}
121
 			case MemberEncoding.TYPE_CONSTRUCTOR: {
127
 			case MemberEncoding.TYPE_CONSTRUCTOR: {
122
 				FunctionHeader header = reader.deserializeHeader(context);
128
 				FunctionHeader header = reader.deserializeHeader(context);
124
 				reader.enqueueCode(reader -> {
130
 				reader.enqueueCode(reader -> {
125
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
131
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
126
 				});
132
 				});
127
-				return result;
133
+				member = result;
134
+				break;
128
 			}
135
 			}
129
 			case MemberEncoding.TYPE_DESTRUCTOR: {
136
 			case MemberEncoding.TYPE_DESTRUCTOR: {
130
 				DestructorMember result = new DestructorMember(position, definition, modifiers);
137
 				DestructorMember result = new DestructorMember(position, definition, modifiers);
132
 					result.overrides = (FunctionalMemberRef)reader.readMember(context, supertype);
139
 					result.overrides = (FunctionalMemberRef)reader.readMember(context, supertype);
133
 					result.setBody(reader.deserializeStatement(new StatementContext(context, result.header)));
140
 					result.setBody(reader.deserializeStatement(new StatementContext(context, result.header)));
134
 				});
141
 				});
135
-				return result;
142
+				member = result;
143
+				break;
136
 			}
144
 			}
137
 			case MemberEncoding.TYPE_METHOD: {
145
 			case MemberEncoding.TYPE_METHOD: {
138
 				String name = readName(flags);
146
 				String name = readName(flags);
142
 					result.setOverrides(context.moduleContext.registry, (FunctionalMemberRef)reader.readMember(context, supertype));
150
 					result.setOverrides(context.moduleContext.registry, (FunctionalMemberRef)reader.readMember(context, supertype));
143
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
151
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
144
 				});
152
 				});
145
-				return result;
153
+				member = result;
154
+				break;
146
 			}
155
 			}
147
 			case MemberEncoding.TYPE_GETTER: {
156
 			case MemberEncoding.TYPE_GETTER: {
148
 				ITypeID type = reader.deserializeType(context);
157
 				ITypeID type = reader.deserializeType(context);
154
 					FunctionHeader header = new FunctionHeader(type);
163
 					FunctionHeader header = new FunctionHeader(type);
155
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
164
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
156
 				});
165
 				});
157
-				return result;
166
+				member = result;
167
+				break;
158
 			}
168
 			}
159
 			case MemberEncoding.TYPE_SETTER: {
169
 			case MemberEncoding.TYPE_SETTER: {
160
 				ITypeID type = reader.deserializeType(context);
170
 				ITypeID type = reader.deserializeType(context);
166
 					FunctionHeader header = new FunctionHeader(BasicTypeID.VOID, result.parameter);
176
 					FunctionHeader header = new FunctionHeader(BasicTypeID.VOID, result.parameter);
167
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
177
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
168
 				});
178
 				});
169
-				return result;
179
+				member = result;
180
+				break;
170
 			}
181
 			}
171
 			case MemberEncoding.TYPE_OPERATOR: {
182
 			case MemberEncoding.TYPE_OPERATOR: {
172
 				OperatorType operator = readOperator();
183
 				OperatorType operator = readOperator();
177
 					result.setOverrides(context.moduleContext.registry, (FunctionalMemberRef)reader.readMember(context, supertype));
188
 					result.setOverrides(context.moduleContext.registry, (FunctionalMemberRef)reader.readMember(context, supertype));
178
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
189
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
179
 				});
190
 				});
180
-				return result;
191
+				member = result;
192
+				break;
181
 			}
193
 			}
182
 			case MemberEncoding.TYPE_CASTER: {
194
 			case MemberEncoding.TYPE_CASTER: {
183
 				ITypeID toType = reader.deserializeType(context);
195
 				ITypeID toType = reader.deserializeType(context);
187
 					result.setOverrides(context.moduleContext.registry, (CasterMemberRef)reader.readMember(context, supertype));
199
 					result.setOverrides(context.moduleContext.registry, (CasterMemberRef)reader.readMember(context, supertype));
188
 					result.setBody(reader.deserializeStatement(new StatementContext(context, new FunctionHeader(toType))));
200
 					result.setBody(reader.deserializeStatement(new StatementContext(context, new FunctionHeader(toType))));
189
 				});
201
 				});
190
-				return result;
202
+				member = result;
203
+				break;
191
 			}
204
 			}
192
 			case MemberEncoding.TYPE_ITERATOR: {
205
 			case MemberEncoding.TYPE_ITERATOR: {
193
 				ITypeID[] types = new ITypeID[reader.readUInt()];
206
 				ITypeID[] types = new ITypeID[reader.readUInt()];
199
 					result.setOverrides((IteratorMemberRef)reader.readMember(context, supertype));
212
 					result.setOverrides((IteratorMemberRef)reader.readMember(context, supertype));
200
 					result.setBody(reader.deserializeStatement(new StatementContext(context, result.header)));
213
 					result.setBody(reader.deserializeStatement(new StatementContext(context, result.header)));
201
 				});
214
 				});
202
-				return result;
215
+				member = result;
216
+				break;
203
 			}
217
 			}
204
 			case MemberEncoding.TYPE_CALLER: {
218
 			case MemberEncoding.TYPE_CALLER: {
205
 				FunctionHeader header = reader.deserializeHeader(context);
219
 				FunctionHeader header = reader.deserializeHeader(context);
209
 					result.setOverrides(context.moduleContext.registry, (FunctionalMemberRef)reader.readMember(context, supertype));
223
 					result.setOverrides(context.moduleContext.registry, (FunctionalMemberRef)reader.readMember(context, supertype));
210
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
224
 					result.setBody(reader.deserializeStatement(new StatementContext(context, header)));
211
 				});
225
 				});
212
-				return result;
226
+				member = result;
227
+				break;
213
 			}
228
 			}
214
 			case MemberEncoding.TYPE_IMPLEMENTATION: {
229
 			case MemberEncoding.TYPE_IMPLEMENTATION: {
215
 				ITypeID type = reader.deserializeType(context);
230
 				ITypeID type = reader.deserializeType(context);
217
 				
232
 				
218
 				int members = reader.readUInt();
233
 				int members = reader.readUInt();
219
 				for (int i = 0; i < members; i++) {
234
 				for (int i = 0; i < members; i++) {
220
-					IDefinitionMember member = deserializeMember(context, definition, type);
221
-					result.addMember(member);
222
-					reader.add(member);
235
+					IDefinitionMember imember = deserializeMember(context, definition, type);
236
+					result.addMember(imember);
237
+					reader.add(imember);
223
 				}
238
 				}
224
 				
239
 				
225
-				return result;
240
+				member = result;
241
+				break;
226
 			}
242
 			}
227
 			case MemberEncoding.TYPE_INNER_DEFINITION:
243
 			case MemberEncoding.TYPE_INNER_DEFINITION:
228
 				return null;
244
 				return null;
231
 				reader.enqueueCode(reader -> {
247
 				reader.enqueueCode(reader -> {
232
 					result.body = reader.deserializeStatement(new StatementContext(context, new FunctionHeader(BasicTypeID.VOID)));
248
 					result.body = reader.deserializeStatement(new StatementContext(context, new FunctionHeader(BasicTypeID.VOID)));
233
 				});
249
 				});
234
-				return result;
250
+				member = result;
251
+				break;
235
 			}
252
 			}
236
 			default:
253
 			default:
237
 				throw new RuntimeException("Invalid member type: " + kind);
254
 				throw new RuntimeException("Invalid member type: " + kind);
238
 		}
255
 		}
256
+		
257
+		if ((flags & MemberEncoding.FLAG_ANNOTATIONS) > 0) {
258
+			reader.enqueueCode(input -> {
259
+				MemberAnnotation[] annotations = new MemberAnnotation[input.readUInt()];
260
+				for (int i = 0; i < annotations.length; i++) {
261
+					AnnotationDefinition type = input.readAnnotationType();
262
+					annotations[i] = type.deserializeForMember(input, context, member);
263
+				}
264
+				member.annotations = annotations;
265
+			});
266
+			
267
+		}
268
+		return member;
239
 	}
269
 	}
240
 	
270
 	
241
 	private OperatorType readOperator() {
271
 	private OperatorType readOperator() {

+ 13
- 5
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/ModuleDeserializer.java View File

75
 		for (int i = 0; i < sourceFiles.length; i++)
75
 		for (int i = 0; i < sourceFiles.length; i++)
76
 			sourceFiles[i] = new VirtualSourceFile(input.readString());
76
 			sourceFiles[i] = new VirtualSourceFile(input.readString());
77
 		
77
 		
78
+		AnnotationDefinition[] annotations = new AnnotationDefinition[input.readVarUInt()];
79
+		for (int i = 0; i < annotations.length; i++) {
80
+			String name = stringTable[input.readVarUInt()];
81
+			for (AnnotationDefinition annotation : this.annotations)
82
+				if (annotation.getAnnotationName().equals(name))
83
+					annotations[i] = annotation;
84
+			
85
+			if (annotations[i] == null)
86
+				throw new DeserializationException("Annotation type not found: " + name);
87
+		}
88
+		
78
 		CodeReader decoder = new CodeReader(
89
 		CodeReader decoder = new CodeReader(
79
 				input,
90
 				input,
80
 				stringTable,
91
 				stringTable,
81
 				sourceFiles,
92
 				sourceFiles,
93
+				annotations,
82
 				compilationUnit.globalTypeRegistry);
94
 				compilationUnit.globalTypeRegistry);
83
 		
95
 		
84
 		DeserializingModule[] packagedModules = new DeserializingModule[decoder.readUInt()];
96
 		DeserializingModule[] packagedModules = new DeserializingModule[decoder.readUInt()];
147
 		@Override
159
 		@Override
148
 		public void decode(CodeSerializationInput input) throws DeserializationException {
160
 		public void decode(CodeSerializationInput input) throws DeserializationException {
149
 			int numDefinitions = input.readUInt();
161
 			int numDefinitions = input.readUInt();
150
-			DefinitionMemberDeserializer memberDeserializer = new DefinitionMemberDeserializer(reader);
151
 			for (int i = 0; i < numDefinitions; i++) {
162
 			for (int i = 0; i < numDefinitions; i++) {
152
 				HighLevelDefinition definition = deserializeDefinition(reader, module.context, null);
163
 				HighLevelDefinition definition = deserializeDefinition(reader, module.context, null);
153
 				reader.add(definition);
164
 				reader.add(definition);
154
 				module.add(definition);
165
 				module.add(definition);
155
-				
156
-				TypeContext typeContext = new TypeContext(module.context, definition.typeParameters, module.context.registry.getForMyDefinition(definition));
157
-				reader.members.enqueue(in -> definition.accept(typeContext, memberDeserializer));
158
 			}
166
 			}
159
 		}
167
 		}
160
 	}
168
 	}
161
-		
169
+	
162
 	private HighLevelDefinition deserializeDefinition(CodeReader reader, ModuleContext context, HighLevelDefinition outer) throws DeserializationException {
170
 	private HighLevelDefinition deserializeDefinition(CodeReader reader, ModuleContext context, HighLevelDefinition outer) throws DeserializationException {
163
 		int type = reader.readUInt();
171
 		int type = reader.readUInt();
164
 		int flags = reader.readUInt();
172
 		int flags = reader.readUInt();

+ 1
- 0
ModuleSerializationShared/src/main/java/org/openzen/zenscript/moduleserialization/DefinitionEncoding.java View File

15
 	public static final int FLAG_POSITION = 1;
15
 	public static final int FLAG_POSITION = 1;
16
 	public static final int FLAG_NAME = 2;
16
 	public static final int FLAG_NAME = 2;
17
 	public static final int FLAG_TYPE_PARAMETERS = 4;
17
 	public static final int FLAG_TYPE_PARAMETERS = 4;
18
+	public static final int FLAG_ANNOTATIONS = 8;
18
 	
19
 	
19
 	public static final int TYPE_CLASS = 1;
20
 	public static final int TYPE_CLASS = 1;
20
 	public static final int TYPE_STRUCT = 2;
21
 	public static final int TYPE_STRUCT = 2;

+ 1
- 0
ModuleSerializationShared/src/main/java/org/openzen/zenscript/moduleserialization/MemberEncoding.java View File

16
 	public static final int FLAG_NAME = 2;
16
 	public static final int FLAG_NAME = 2;
17
 	public static final int FLAG_AUTO_GETTER = 4;
17
 	public static final int FLAG_AUTO_GETTER = 4;
18
 	public static final int FLAG_AUTO_SETTER = 8;
18
 	public static final int FLAG_AUTO_SETTER = 8;
19
+	public static final int FLAG_ANNOTATIONS = 16;
19
 	
20
 	
20
 	public static final int TYPE_BUILTIN = 1;
21
 	public static final int TYPE_BUILTIN = 1;
21
 	public static final int TYPE_CONST = 2;
22
 	public static final int TYPE_CONST = 2;

+ 21
- 12
ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/CodeWriter.java View File

16
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
 import org.openzen.zenscript.codemodel.FunctionHeader;
17
 import org.openzen.zenscript.codemodel.FunctionParameter;
17
 import org.openzen.zenscript.codemodel.FunctionParameter;
18
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
18
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
19
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
19
 import org.openzen.zenscript.codemodel.expression.CallArguments;
20
 import org.openzen.zenscript.codemodel.expression.CallArguments;
20
 import org.openzen.zenscript.codemodel.expression.Expression;
21
 import org.openzen.zenscript.codemodel.expression.Expression;
21
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
22
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
50
 public class CodeWriter implements CodeSerializationOutput {
51
 public class CodeWriter implements CodeSerializationOutput {
51
 	private final Map<String, Integer> stringMap = new HashMap<>();
52
 	private final Map<String, Integer> stringMap = new HashMap<>();
52
 	private final Map<SourceFile, Integer> sourceFileMap = new HashMap<>();
53
 	private final Map<SourceFile, Integer> sourceFileMap = new HashMap<>();
53
-	
54
-	private final List<HighLevelDefinition> definitions = new ArrayList<>();
54
+	private final Map<AnnotationDefinition, Integer> annotationMap = new HashMap<>();
55
 	private final Map<HighLevelDefinition, Integer> definitionsMap = new HashMap<>();
55
 	private final Map<HighLevelDefinition, Integer> definitionsMap = new HashMap<>();
56
 	
56
 	
57
 	private final Map<IDefinitionMember, Integer> memberMap = new HashMap<>();
57
 	private final Map<IDefinitionMember, Integer> memberMap = new HashMap<>();
78
 			SerializationOptions options,
78
 			SerializationOptions options,
79
 			String[] strings,
79
 			String[] strings,
80
 			SourceFile[] sourceFiles,
80
 			SourceFile[] sourceFiles,
81
-			List<IDefinitionMember> members)
81
+			HighLevelDefinition[] definitions,
82
+			List<IDefinitionMember> members,
83
+			AnnotationDefinition[] annotations)
82
 	{
84
 	{
83
 		this.output = output;
85
 		this.output = output;
84
 		this.options = options;
86
 		this.options = options;
93
 			stringMap.put(string, stringMap.size());
95
 			stringMap.put(string, stringMap.size());
94
 		for (SourceFile sourceFile : sourceFiles)
96
 		for (SourceFile sourceFile : sourceFiles)
95
 			sourceFileMap.put(sourceFile, sourceFileMap.size());
97
 			sourceFileMap.put(sourceFile, sourceFileMap.size());
98
+		for (HighLevelDefinition definition : definitions)
99
+			definitionsMap.put(definition, definitionsMap.size());
96
 		for (IDefinitionMember member : members)
100
 		for (IDefinitionMember member : members)
97
 			memberMap.put(member, memberMap.size());
101
 			memberMap.put(member, memberMap.size());
102
+		for (AnnotationDefinition annotation : annotations)
103
+			annotationMap.put(annotation, annotationMap.size());
98
 	}
104
 	}
99
 	
105
 	
100
 	public void startClasses() {
106
 	public void startClasses() {
109
 		currentStage = code;
115
 		currentStage = code;
110
 	}
116
 	}
111
 	
117
 	
112
-	public void add(HighLevelDefinition definition) {
113
-		definitions.add(definition);
114
-		definitionsMap.put(definition, definitions.size());
115
-	}
116
-	
117
 	public void add(SourceFile file) {
118
 	public void add(SourceFile file) {
118
 		sourceFileMap.put(file, sourceFileMap.size());
119
 		sourceFileMap.put(file, sourceFileMap.size());
119
 	}
120
 	}
198
 		if (!definitionsMap.containsKey(definition))
199
 		if (!definitionsMap.containsKey(definition))
199
 			throw new IllegalStateException("Definition not yet prepared: " + definition.name);
200
 			throw new IllegalStateException("Definition not yet prepared: " + definition.name);
200
 		
201
 		
201
-		output.writeVarUInt(definitionsMap.get(definition) + 1);
202
+		int id = definitionsMap.get(definition) + 1;
203
+		output.writeVarUInt(id);
202
 	}
204
 	}
203
 	
205
 	
204
 	@Override
206
 	@Override
235
 		writeUInt(definition.getTag(EncodingDefinition.class).variantOptions.indexOf(option));
237
 		writeUInt(definition.getTag(EncodingDefinition.class).variantOptions.indexOf(option));
236
 	}
238
 	}
237
 	
239
 	
240
+	@Override
241
+	public void write(AnnotationDefinition annotationType) {
242
+		writeUInt(annotationMap.get(annotationType));
243
+	}
244
+	
238
 	@Override
245
 	@Override
239
 	public void serialize(TypeContext context, ITypeID type) {
246
 	public void serialize(TypeContext context, ITypeID type) {
240
 		if (type == null) {
247
 		if (type == null) {
280
 	
287
 	
281
 	private void serializeRemaining(int flags, TypeContext context, TypeParameter parameter) {
288
 	private void serializeRemaining(int flags, TypeContext context, TypeParameter parameter) {
282
 		if (currentStage == code || currentStage == members) {
289
 		if (currentStage == code || currentStage == members) {
283
-			output.writeVarUInt(parameter.bounds.size());
284
-			for (TypeParameterBound bound : parameter.bounds)
285
-				bound.accept(context, typeParameterEncoder);
290
+			if ((flags & TypeParameterEncoding.FLAG_BOUNDS) > 0) {
291
+				writeUInt(parameter.bounds.size());
292
+				for (TypeParameterBound bound : parameter.bounds)
293
+					bound.accept(context, typeParameterEncoder);
294
+			}
286
 		} else {
295
 		} else {
287
 			members.enqueue(encoder -> {
296
 			members.enqueue(encoder -> {
288
 				if ((flags & TypeParameterEncoding.FLAG_BOUNDS) > 0) {
297
 				if ((flags & TypeParameterEncoding.FLAG_BOUNDS) > 0) {

+ 17
- 2
ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/ModuleSerializer.java View File

12
 import org.openzen.zencode.shared.SourceFile;
12
 import org.openzen.zencode.shared.SourceFile;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
 import org.openzen.zenscript.codemodel.ScriptBlock;
14
 import org.openzen.zenscript.codemodel.ScriptBlock;
15
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.context.ModuleContext;
16
 import org.openzen.zenscript.codemodel.context.ModuleContext;
16
 import org.openzen.zenscript.codemodel.statement.Statement;
17
 import org.openzen.zenscript.codemodel.statement.Statement;
17
 import org.openzen.zenscript.compiler.SemanticModule;
18
 import org.openzen.zenscript.compiler.SemanticModule;
61
 			}
62
 			}
62
 		}
63
 		}
63
 		
64
 		
65
+		List<HighLevelDefinition> definitions = new ArrayList<>();
66
+		for (EncodingModule module : tableBuilder.modules) {
67
+			for (EncodingDefinition definition : module.definitions)
68
+				definitions.add(definition.definition);
69
+		}
70
+		
71
+		for (AnnotationDefinition annotation : tableBuilder.getAnnotations())
72
+			tableBuilder.writeString(annotation.getAnnotationName());
73
+		
64
 		SourceFile[] sourceFiles = tableBuilder.getSourceFileList();
74
 		SourceFile[] sourceFiles = tableBuilder.getSourceFileList();
65
 		String[] strings = tableBuilder.getStrings();
75
 		String[] strings = tableBuilder.getStrings();
66
 		List<IDefinitionMember> members = tableBuilder.getMembers();
76
 		List<IDefinitionMember> members = tableBuilder.getMembers();
77
+		AnnotationDefinition[] annotations = tableBuilder.getAnnotations();
67
 		
78
 		
68
 		CompactBytesDataOutput output = new CompactBytesDataOutput();
79
 		CompactBytesDataOutput output = new CompactBytesDataOutput();
69
 		CodeWriter encoder = new CodeWriter(
80
 		CodeWriter encoder = new CodeWriter(
71
 				options,
82
 				options,
72
 				strings,
83
 				strings,
73
 				sourceFiles,
84
 				sourceFiles,
74
-				members);
85
+				definitions.toArray(new HighLevelDefinition[definitions.size()]),
86
+				members,
87
+				annotations);
75
 		
88
 		
76
 		output.writeInt(0x5A43424D); // 'ZCBM' = ZenCode Binary Module
89
 		output.writeInt(0x5A43424D); // 'ZCBM' = ZenCode Binary Module
77
 		output.writeVarUInt(0); // version
90
 		output.writeVarUInt(0); // version
79
 		output.writeVarUInt(sourceFiles.length);
92
 		output.writeVarUInt(sourceFiles.length);
80
 		for (SourceFile file : sourceFiles)
93
 		for (SourceFile file : sourceFiles)
81
 			output.writeString(file.getFilename());
94
 			output.writeString(file.getFilename());
95
+		output.writeVarUInt(annotations.length);
96
+		for (AnnotationDefinition annotation : annotations)
97
+			encoder.writeString(annotation.getAnnotationName());
82
 		
98
 		
83
 		encoder.writeUInt(encodingModules.size());
99
 		encoder.writeUInt(encodingModules.size());
84
 		System.out.println("Encoding list of modules");
100
 		System.out.println("Encoding list of modules");
162
 			for (EncodingDefinition definition : module.definitions) {
178
 			for (EncodingDefinition definition : module.definitions) {
163
 				System.out.println("Encoding definition " + definition.definition.name);
179
 				System.out.println("Encoding definition " + definition.definition.name);
164
 				definition.definition.accept(module.context, definitionEncoder);
180
 				definition.definition.accept(module.context, definitionEncoder);
165
-				encoder.add(definition.definition);
166
 			}
181
 			}
167
 		}
182
 		}
168
 	}
183
 	}

+ 11
- 0
ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/TableBuilder.java View File

18
 import org.openzen.zenscript.codemodel.FunctionParameter;
18
 import org.openzen.zenscript.codemodel.FunctionParameter;
19
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
19
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
20
 import org.openzen.zenscript.codemodel.Module;
20
 import org.openzen.zenscript.codemodel.Module;
21
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
21
 import org.openzen.zenscript.codemodel.context.ModuleContext;
22
 import org.openzen.zenscript.codemodel.context.ModuleContext;
22
 import org.openzen.zenscript.codemodel.context.StatementContext;
23
 import org.openzen.zenscript.codemodel.context.StatementContext;
23
 import org.openzen.zenscript.codemodel.context.TypeContext;
24
 import org.openzen.zenscript.codemodel.context.TypeContext;
55
 	private final Set<SourceFile> sourceFiles = new HashSet<>();
56
 	private final Set<SourceFile> sourceFiles = new HashSet<>();
56
 	public final List<EncodingModule> modules = new ArrayList<>();
57
 	public final List<EncodingModule> modules = new ArrayList<>();
57
 	private final List<IDefinitionMember> members = new ArrayList<>();
58
 	private final List<IDefinitionMember> members = new ArrayList<>();
59
+	private final Set<AnnotationDefinition> annotations = new HashSet<>();
58
 	
60
 	
59
 	private final SerializationOptions options;
61
 	private final SerializationOptions options;
60
 	
62
 	
109
 		return members;
111
 		return members;
110
 	}
112
 	}
111
 	
113
 	
114
+	public AnnotationDefinition[] getAnnotations() {
115
+		return annotations.toArray(new AnnotationDefinition[annotations.size()]);
116
+	}
117
+	
112
 	private EncodingDefinition prepare(HighLevelDefinition definition) {
118
 	private EncodingDefinition prepare(HighLevelDefinition definition) {
113
 		register(definition.module, null);
119
 		register(definition.module, null);
114
 		
120
 		
194
 				members.add(member.getTarget());
200
 				members.add(member.getTarget());
195
 		}
201
 		}
196
 	}
202
 	}
203
+	
204
+	@Override
205
+	public void write(AnnotationDefinition annotationType) {
206
+		annotations.add(annotationType);
207
+	}
197
 
208
 
198
 	@Override
209
 	@Override
199
 	public void serialize(TypeContext context, IDefinitionMember member) {
210
 	public void serialize(TypeContext context, IDefinitionMember member) {

+ 0
- 4
ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/encoder/DefinitionMemberSerializer.java View File

43
 	private EncodingDefinition visit(TypeContext context, HighLevelDefinition definition) {
43
 	private EncodingDefinition visit(TypeContext context, HighLevelDefinition definition) {
44
 		EncodingDefinition encoding = definition.getTag(EncodingDefinition.class);
44
 		EncodingDefinition encoding = definition.getTag(EncodingDefinition.class);
45
 		
45
 		
46
-		for (DefinitionAnnotation annotation : definition.annotations) {
47
-			// TODO: how to serialize annotations?
48
-		}
49
-		
50
 		output.serialize(context, definition.getSuperType());
46
 		output.serialize(context, definition.getSuperType());
51
 		
47
 		
52
 		output.writeUInt(encoding.members.size());
48
 		output.writeUInt(encoding.members.size());

+ 15
- 3
ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/encoder/DefinitionSerializer.java View File

10
 import org.openzen.zenscript.codemodel.context.TypeContext;
10
 import org.openzen.zenscript.codemodel.context.TypeContext;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.annotations.DefinitionAnnotation;
13
 import org.openzen.zenscript.codemodel.context.ModuleContext;
14
 import org.openzen.zenscript.codemodel.context.ModuleContext;
14
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
15
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
15
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
16
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
20
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
21
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
21
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
22
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
22
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
23
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
23
-import org.openzen.zenscript.codemodel.generic.TypeParameter;
24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
25
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
25
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
26
 import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
26
 import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
48
 			flags |= DefinitionEncoding.FLAG_NAME;
48
 			flags |= DefinitionEncoding.FLAG_NAME;
49
 		if (definition.typeParameters.length > 0)
49
 		if (definition.typeParameters.length > 0)
50
 			flags |= DefinitionEncoding.FLAG_TYPE_PARAMETERS;
50
 			flags |= DefinitionEncoding.FLAG_TYPE_PARAMETERS;
51
+		if (definition.annotations.length > 0)
52
+			flags |= DefinitionEncoding.FLAG_ANNOTATIONS;
51
 		
53
 		
52
 		output.writeUInt(flags);
54
 		output.writeUInt(flags);
53
 		output.writeUInt(definition.modifiers);
55
 		output.writeUInt(definition.modifiers);
56
 		output.writeString(definition.pkg.fullName);
58
 		output.writeString(definition.pkg.fullName);
57
 		if (definition.name != null)
59
 		if (definition.name != null)
58
 			output.writeString(definition.name);
60
 			output.writeString(definition.name);
59
-		if (definition.typeParameters.length > 0) {
60
-			TypeContext typeContext = new TypeContext(context, TypeParameter.NONE, null);
61
+		
62
+		TypeContext typeContext = new TypeContext(context, definition.typeParameters, null);
63
+		if (definition.typeParameters.length > 0)
61
 			output.serialize(typeContext, definition.typeParameters);
64
 			output.serialize(typeContext, definition.typeParameters);
65
+		
66
+		if (definition.annotations.length > 0) {
67
+			output.enqueueCode(output -> {
68
+				output.writeUInt(definition.annotations.length);
69
+				for (DefinitionAnnotation annotation : definition.annotations) {
70
+					output.write(annotation.getDefinition());
71
+					annotation.serialize(output, definition, typeContext);
72
+				}
73
+			});
62
 		}
74
 		}
63
 	}
75
 	}
64
 	
76
 	

+ 27
- 15
ModuleSerializer/src/main/java/org/openzen/zenscript/moduleserializer/encoder/MemberSerializer.java View File

10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.OperatorType;
12
 import org.openzen.zenscript.codemodel.OperatorType;
13
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
13
 import org.openzen.zenscript.codemodel.member.CallerMember;
14
 import org.openzen.zenscript.codemodel.member.CallerMember;
14
 import org.openzen.zenscript.codemodel.member.CasterMember;
15
 import org.openzen.zenscript.codemodel.member.CasterMember;
15
 import org.openzen.zenscript.codemodel.member.ConstMember;
16
 import org.openzen.zenscript.codemodel.member.ConstMember;
29
 import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
30
 import org.openzen.zenscript.codemodel.serialization.CodeSerializationOutput;
30
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
31
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
31
 import org.openzen.zenscript.codemodel.type.ITypeID;
32
 import org.openzen.zenscript.codemodel.type.ITypeID;
32
-import org.openzen.zenscript.codemodel.type.IteratorTypeID;
33
 import org.openzen.zenscript.moduleserialization.MemberEncoding;
33
 import org.openzen.zenscript.moduleserialization.MemberEncoding;
34
 import org.openzen.zenscript.moduleserializer.SerializationOptions;
34
 import org.openzen.zenscript.moduleserializer.SerializationOptions;
35
 
35
 
50
 		int flags = 0;
50
 		int flags = 0;
51
 		if (member.getPosition() != CodePosition.UNKNOWN && options.positions)
51
 		if (member.getPosition() != CodePosition.UNKNOWN && options.positions)
52
 			flags |= MemberEncoding.FLAG_POSITION;
52
 			flags |= MemberEncoding.FLAG_POSITION;
53
+		if (member.getAnnotations().length > 0)
54
+			flags |= MemberEncoding.FLAG_ANNOTATIONS;
53
 		
55
 		
54
 		return flags;
56
 		return flags;
55
 	}
57
 	}
56
 	
58
 	
57
-	private void serialize(int flags, IDefinitionMember member) {
59
+	private void serialize(int flags, TypeContext context, IDefinitionMember member) {
58
 		output.writeUInt(flags);
60
 		output.writeUInt(flags);
59
 		if ((flags & MemberEncoding.FLAG_POSITION) > 0)
61
 		if ((flags & MemberEncoding.FLAG_POSITION) > 0)
60
 			output.serialize(member.getPosition());
62
 			output.serialize(member.getPosition());
61
 		
63
 		
62
 		output.writeUInt(member.getModifiers());
64
 		output.writeUInt(member.getModifiers());
65
+		
66
+		if (member.getAnnotations().length > 0) {
67
+			output.enqueueCode(output -> {
68
+				output.writeUInt(member.getAnnotations().length);
69
+				for (MemberAnnotation annotation : member.getAnnotations()) {
70
+					output.write(annotation.getDefinition());
71
+					annotation.serialize(output, member, context);
72
+				}
73
+			});
74
+		}
63
 	}
75
 	}
64
 	
76
 	
65
 	private void writeName(int flags, String name) {
77
 	private void writeName(int flags, String name) {
75
 		if (member.name != null)
87
 		if (member.name != null)
76
 			flags |= MemberEncoding.FLAG_NAME;
88
 			flags |= MemberEncoding.FLAG_NAME;
77
 		
89
 		
78
-		serialize(flags, member);
90
+		serialize(flags, context, member);
79
 		if ((flags & MemberEncoding.FLAG_NAME) > 0)
91
 		if ((flags & MemberEncoding.FLAG_NAME) > 0)
80
 			output.writeString(member.name);
92
 			output.writeString(member.name);
81
 		
93
 		
96
 		if (member.autoSetterAccess != 0)
108
 		if (member.autoSetterAccess != 0)
97
 			flags |= MemberEncoding.FLAG_AUTO_SETTER;
109
 			flags |= MemberEncoding.FLAG_AUTO_SETTER;
98
 		
110
 		
99
-		serialize(flags, member);
111
+		serialize(flags, context, member);
100
 		writeName(flags, member.name);
112
 		writeName(flags, member.name);
101
 		if ((flags & MemberEncoding.FLAG_AUTO_GETTER) > 0)
113
 		if ((flags & MemberEncoding.FLAG_AUTO_GETTER) > 0)
102
 			output.writeUInt(member.autoGetterAccess);
114
 			output.writeUInt(member.autoGetterAccess);
113
 		output.writeUInt(MemberEncoding.TYPE_CONSTRUCTOR);
125
 		output.writeUInt(MemberEncoding.TYPE_CONSTRUCTOR);
114
 		
126
 		
115
 		int flags = getFlags(member);
127
 		int flags = getFlags(member);
116
-		serialize(flags, member);
128
+		serialize(flags, context, member);
117
 		
129
 		
118
 		StatementContext inner = new StatementContext(context, member.header);
130
 		StatementContext inner = new StatementContext(context, member.header);
119
 		output.serialize(inner, member.header);
131
 		output.serialize(inner, member.header);
128
 	public Void visitDestructor(TypeContext context, DestructorMember member) {
140
 	public Void visitDestructor(TypeContext context, DestructorMember member) {
129
 		output.writeUInt(MemberEncoding.TYPE_DESTRUCTOR);
141
 		output.writeUInt(MemberEncoding.TYPE_DESTRUCTOR);
130
 		int flags = getFlags(member);
142
 		int flags = getFlags(member);
131
-		serialize(flags, member);
143
+		serialize(flags, context, member);
132
 		
144
 		
133
 		output.enqueueCode(encoder -> {
145
 		output.enqueueCode(encoder -> {
134
 			encoder.write(context, member.overrides);
146
 			encoder.write(context, member.overrides);
143
 		int flags = getFlags(member);
155
 		int flags = getFlags(member);
144
 		if (member.name != null)
156
 		if (member.name != null)
145
 			flags |= MemberEncoding.FLAG_NAME;
157
 			flags |= MemberEncoding.FLAG_NAME;
146
-		serialize(flags, member);
158
+		serialize(flags, context, member);
147
 		writeName(flags, member.name);
159
 		writeName(flags, member.name);
148
 		
160
 		
149
 		StatementContext inner = new StatementContext(context, member.header);
161
 		StatementContext inner = new StatementContext(context, member.header);
162
 		int flags = getFlags(member);
174
 		int flags = getFlags(member);
163
 		if (member.name != null)
175
 		if (member.name != null)
164
 			flags |= MemberEncoding.FLAG_NAME;
176
 			flags |= MemberEncoding.FLAG_NAME;
165
-		serialize(flags, member);
177
+		serialize(flags, context, member);
166
 		output.serialize(context, member.type);
178
 		output.serialize(context, member.type);
167
 		writeName(flags, member.name);
179
 		writeName(flags, member.name);
168
 		
180
 		
177
 	public Void visitSetter(TypeContext context, SetterMember member) {
189
 	public Void visitSetter(TypeContext context, SetterMember member) {
178
 		output.writeUInt(MemberEncoding.TYPE_SETTER);
190
 		output.writeUInt(MemberEncoding.TYPE_SETTER);
179
 		int flags = getFlags(member);
191
 		int flags = getFlags(member);
180
-		serialize(flags, member);
192
+		serialize(flags, context, member);
181
 		output.serialize(context, member.type);
193
 		output.serialize(context, member.type);
182
 		writeName(flags, member.name);
194
 		writeName(flags, member.name);
183
 		
195
 		
195
 	public Void visitOperator(TypeContext context, OperatorMember member) {
207
 	public Void visitOperator(TypeContext context, OperatorMember member) {
196
 		output.writeUInt(MemberEncoding.TYPE_OPERATOR);
208
 		output.writeUInt(MemberEncoding.TYPE_OPERATOR);
197
 		int flags = getFlags(member);
209
 		int flags = getFlags(member);
198
-		serialize(flags, member);
210
+		serialize(flags, context, member);
199
 		output.writeUInt(getId(member.operator));
211
 		output.writeUInt(getId(member.operator));
200
 		
212
 		
201
 		StatementContext inner = new StatementContext(context, member.header);
213
 		StatementContext inner = new StatementContext(context, member.header);
212
 	public Void visitCaster(TypeContext context, CasterMember member) {
224
 	public Void visitCaster(TypeContext context, CasterMember member) {
213
 		output.writeUInt(MemberEncoding.TYPE_CASTER);
225
 		output.writeUInt(MemberEncoding.TYPE_CASTER);
214
 		int flags = getFlags(member);
226
 		int flags = getFlags(member);
215
-		serialize(flags, member);
227
+		serialize(flags, context, member);
216
 		output.serialize(context, member.toType);
228
 		output.serialize(context, member.toType);
217
 		
229
 		
218
 		output.enqueueCode(encoder -> {
230
 		output.enqueueCode(encoder -> {
228
 	public Void visitIterator(TypeContext context, IteratorMember member) {
240
 	public Void visitIterator(TypeContext context, IteratorMember member) {
229
 		output.writeUInt(MemberEncoding.TYPE_ITERATOR);
241
 		output.writeUInt(MemberEncoding.TYPE_ITERATOR);
230
 		int flags = getFlags(member);
242
 		int flags = getFlags(member);
231
-		serialize(flags, member);
243
+		serialize(flags, context, member);
232
 		output.writeUInt(member.getLoopVariableCount());
244
 		output.writeUInt(member.getLoopVariableCount());
233
 		for (ITypeID type : member.getLoopVariableTypes())
245
 		for (ITypeID type : member.getLoopVariableTypes())
234
 			output.serialize(context, type);
246
 			output.serialize(context, type);
246
 	public Void visitCaller(TypeContext context, CallerMember member) {
258
 	public Void visitCaller(TypeContext context, CallerMember member) {
247
 		output.writeUInt(MemberEncoding.TYPE_CALLER);
259
 		output.writeUInt(MemberEncoding.TYPE_CALLER);
248
 		int flags = getFlags(member);
260
 		int flags = getFlags(member);
249
-		serialize(flags, member);
261
+		serialize(flags, context, member);
250
 		
262
 		
251
 		StatementContext inner = new StatementContext(context, member.header);
263
 		StatementContext inner = new StatementContext(context, member.header);
252
 		output.serialize(inner, member.header);
264
 		output.serialize(inner, member.header);
262
 	public Void visitImplementation(TypeContext context, ImplementationMember member) {
274
 	public Void visitImplementation(TypeContext context, ImplementationMember member) {
263
 		output.writeUInt(MemberEncoding.TYPE_IMPLEMENTATION);
275
 		output.writeUInt(MemberEncoding.TYPE_IMPLEMENTATION);
264
 		int flags = getFlags(member);
276
 		int flags = getFlags(member);
265
-		serialize(flags, member);
277
+		serialize(flags, context, member);
266
 		output.serialize(context, member.type);
278
 		output.serialize(context, member.type);
267
 		
279
 		
268
 		output.writeUInt(member.members.size());
280
 		output.writeUInt(member.members.size());
282
 	public Void visitStaticInitializer(TypeContext context, StaticInitializerMember member) {
294
 	public Void visitStaticInitializer(TypeContext context, StaticInitializerMember member) {
283
 		output.writeUInt(MemberEncoding.TYPE_STATIC_INITIALIZER);
295
 		output.writeUInt(MemberEncoding.TYPE_STATIC_INITIALIZER);
284
 		int flags = getFlags(member);
296
 		int flags = getFlags(member);
285
-		serialize(flags, member);
297
+		serialize(flags, context, member);
286
 		
298
 		
287
 		output.enqueueCode(encoder -> {
299
 		output.enqueueCode(encoder -> {
288
 			encoder.serialize(new StatementContext(context, new FunctionHeader(BasicTypeID.VOID)), member.body);
300
 			encoder.serialize(new StatementContext(context, new FunctionHeader(BasicTypeID.VOID)), member.body);

Loading…
Cancel
Save