Browse Source

- All definitions are now also module-aware (will be use for binary module serialization & access checks)

- Fixing function expressions not being properly linked to their functional interface
Stan Hebben 6 years ago
parent
commit
9c3aa8efc3
48 changed files with 1332 additions and 106 deletions
  1. 2
    2
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java
  2. 12
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  3. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/Module.java
  4. 5
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingPackage.java
  5. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/AliasDefinition.java
  6. 5
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ClassDefinition.java
  7. 11
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/EnumDefinition.java
  8. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ExpansionDefinition.java
  9. 5
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  10. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/InterfaceDefinition.java
  11. 21
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/MemberCollector.java
  12. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/StructDefinition.java
  13. 11
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/VariantDefinition.java
  14. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java
  15. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java
  16. 6
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java
  17. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameterBound.java
  18. 23
    22
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  19. 5
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  20. 2
    2
      Constructor/src/main/java/org/openzen/zenscript/constructor/ParsedModule.java
  21. 8
    6
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  22. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  23. 2
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java
  24. 2
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java
  25. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java
  26. 4
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceUtils.java
  27. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  28. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedAlias.java
  29. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java
  30. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java
  31. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java
  32. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java
  33. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedGenericBound.java
  34. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java
  35. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedStruct.java
  36. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedSuperBound.java
  37. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedTypeBound.java
  38. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java
  39. 5
    3
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java
  40. 6
    4
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  41. 407
    0
      Shared/src/main/java/compactio/CompactBytesDataInput.java
  42. 497
    0
      Shared/src/main/java/compactio/CompactBytesDataOutput.java
  43. 106
    0
      Shared/src/main/java/compactio/CompactDataInput.java
  44. 108
    0
      Shared/src/main/java/compactio/CompactDataOutput.java
  45. 6
    0
      Shared/src/main/java/zsynthetic/FunctionUSizeTToBool.java
  46. 6
    0
      Shared/src/main/java/zsynthetic/FunctionUSizeTToU.java
  47. 6
    0
      Shared/src/main/java/zsynthetic/FunctionUSizeTToVoid.java
  48. 2
    2
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java

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

@@ -10,7 +10,7 @@ import org.openzen.zenscript.codemodel.FunctionParameter;
10 10
 import org.openzen.zenscript.codemodel.Modifiers;
11 11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12 12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
13
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
14 14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15 15
 import org.openzen.zenscript.codemodel.statement.BlockStatement;
16 16
 import org.openzen.zenscript.codemodel.statement.BreakStatement;
@@ -103,7 +103,7 @@ public class FormattingUtils {
103 103
 				result.append(parameter.name);
104 104
 				
105 105
 				if (parameter.bounds.size() > 0) {
106
-					for (GenericParameterBound bound : parameter.bounds) {
106
+					for (TypeParameterBound bound : parameter.bounds) {
107 107
 						result.append(": ");
108 108
 						result.append(bound.accept(typeFormatter));
109 109
 					}

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

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.definition.AliasDefinition;
14 14
 import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
15 15
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
16 16
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
17
+import org.openzen.zenscript.codemodel.definition.MemberCollector;
17 18
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18 19
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
19 20
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
@@ -31,6 +32,7 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
31 32
  */
32 33
 public abstract class HighLevelDefinition extends Taggable {
33 34
 	public final CodePosition position;
35
+	public final Module module;
34 36
 	public final ZSPackage pkg;
35 37
 	public final String name;
36 38
 	public final int modifiers;
@@ -43,8 +45,12 @@ public abstract class HighLevelDefinition extends Taggable {
43 45
 	
44 46
 	private boolean isDestructible = false;
45 47
 	
46
-	public HighLevelDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
48
+	public HighLevelDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
49
+		if (module == null)
50
+			throw new NullPointerException();
51
+		
47 52
 		this.position = position;
53
+		this.module = module;
48 54
 		this.pkg = pkg;
49 55
 		this.name = name;
50 56
 		this.modifiers = modifiers;
@@ -100,6 +106,11 @@ public abstract class HighLevelDefinition extends Taggable {
100 106
 			members.add(member);
101 107
 	}
102 108
 	
109
+	public void collectMembers(MemberCollector collector) {
110
+		for (IDefinitionMember member : members)
111
+			collector.member(member);
112
+	}
113
+	
103 114
 	public boolean isDestructible() {
104 115
 		boolean isDestructible = false;
105 116
 		for (IDefinitionMember member : members) {

+ 22
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/Module.java View File

@@ -0,0 +1,22 @@
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;
7
+
8
+import org.openzen.zencode.shared.Taggable;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class Module extends Taggable {
15
+	public static final Module BUILTIN = new Module("builtin");
16
+	
17
+	public final String name;
18
+	
19
+	public Module(String name) {
20
+		this.name = name;
21
+	}
22
+}

+ 5
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingPackage.java View File

@@ -9,6 +9,7 @@ import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Module;
12 13
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
13 14
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
14 15
 import org.openzen.zenscript.codemodel.type.GenericName;
@@ -19,12 +20,14 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
19 20
  * @author Hoofdgebruiker
20 21
  */
21 22
 public class CompilingPackage {
23
+	public final Module module;
22 24
 	private final ZSPackage pkg;
23 25
 	private final Map<String, CompilingPackage> packages = new HashMap<>();
24 26
 	private final Map<String, CompilingType> types = new HashMap<>();
25 27
 	
26
-	public CompilingPackage(ZSPackage pkg) {
28
+	public CompilingPackage(ZSPackage pkg, Module module) {
27 29
 		this.pkg = pkg;
30
+		this.module = module;
28 31
 	}
29 32
 	
30 33
 	public ZSPackage getPackage() {
@@ -35,7 +38,7 @@ public class CompilingPackage {
35 38
 		if (packages.containsKey(name))
36 39
 			return packages.get(name);
37 40
 		
38
-		CompilingPackage newPackage = new CompilingPackage(pkg.getOrCreatePackage(name));
41
+		CompilingPackage newPackage = new CompilingPackage(pkg.getOrCreatePackage(name), module);
39 42
 		packages.put(name, newPackage);
40 43
 		return newPackage;
41 44
 	}

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/AliasDefinition.java View File

@@ -7,7 +7,7 @@ package org.openzen.zenscript.codemodel.definition;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
-import org.openzen.zenscript.codemodel.Modifiers;
10
+import org.openzen.zenscript.codemodel.Module;
11 11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
13 13
 
@@ -18,8 +18,8 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
18 18
 public class AliasDefinition extends HighLevelDefinition {
19 19
 	public ITypeID type;
20 20
 	
21
-	public AliasDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
22
-		super(position, pkg, name, modifiers, outerDefinition);
21
+	public AliasDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
22
+		super(position, module, pkg, name, modifiers, outerDefinition);
23 23
 	}
24 24
 	
25 25
 	public void setType(ITypeID type) {

+ 5
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ClassDefinition.java View File

@@ -7,20 +7,19 @@ package org.openzen.zenscript.codemodel.definition;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
-import org.openzen.zenscript.codemodel.scope.TypeScope;
11
-import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.codemodel.Module;
12 11
 
13 12
 /**
14 13
  *
15 14
  * @author Hoofdgebruiker
16 15
  */
17 16
 public class ClassDefinition extends HighLevelDefinition {
18
-	public ClassDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers) {
19
-		this(position, pkg, name, modifiers, null);
17
+	public ClassDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers) {
18
+		this(position, module, pkg, name, modifiers, null);
20 19
 	}
21 20
 	
22
-	public ClassDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
23
-		super(position, pkg, name, modifiers, outerDefinition);
21
+	public ClassDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
22
+		super(position, module, pkg, name, modifiers, outerDefinition);
24 23
 	}
25 24
 
26 25
 	@Override

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

@@ -9,6 +9,7 @@ import java.util.ArrayList;
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Module;
12 13
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
13 14
 
14 15
 /**
@@ -18,8 +19,8 @@ import org.openzen.zenscript.codemodel.member.EnumConstantMember;
18 19
 public class EnumDefinition extends HighLevelDefinition {
19 20
 	public List<EnumConstantMember> enumConstants = new ArrayList<>();
20 21
 	
21
-	public EnumDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
22
-		super(position, pkg, name, modifiers, outerDefinition);
22
+	public EnumDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
23
+		super(position, module, pkg, name, modifiers, outerDefinition);
23 24
 	}
24 25
 
25 26
 	@Override
@@ -27,6 +28,14 @@ public class EnumDefinition extends HighLevelDefinition {
27 28
 		return visitor.visitEnum(this);
28 29
 	}
29 30
 	
31
+	@Override
32
+	public void collectMembers(MemberCollector collector) {
33
+		super.collectMembers(collector);
34
+		
35
+		for (EnumConstantMember member : enumConstants)
36
+			collector.enumConstant(member);
37
+	}
38
+	
30 39
 	public void addEnumConstant(EnumConstantMember constant) {
31 40
 		enumConstants.add(constant);
32 41
 	}

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

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.definition;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
+import org.openzen.zenscript.codemodel.Module;
10 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 12
 
12 13
 /**
@@ -16,8 +17,8 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
16 17
 public class ExpansionDefinition extends HighLevelDefinition {
17 18
 	public ITypeID target;
18 19
 	
19
-	public ExpansionDefinition(CodePosition position, ZSPackage pkg, int modifiers, HighLevelDefinition outerDefinition) {
20
-		super(position, pkg, null, modifiers, outerDefinition);
20
+	public ExpansionDefinition(CodePosition position, Module module, ZSPackage pkg, int modifiers, HighLevelDefinition outerDefinition) {
21
+		super(position, module, pkg, null, modifiers, outerDefinition);
21 22
 	}
22 23
 
23 24
 	@Override

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

@@ -10,6 +10,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.Modifiers;
13
+import org.openzen.zenscript.codemodel.Module;
13 14
 import org.openzen.zenscript.codemodel.member.CallerMember;
14 15
 import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
15 16
 import org.openzen.zenscript.codemodel.statement.Statement;
@@ -26,13 +27,13 @@ public class FunctionDefinition extends HighLevelDefinition {
26 27
 	public CallerMember caller;
27 28
 	public final DefinitionMemberGroup callerGroup;
28 29
 	
29
-	public FunctionDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
30
-		super(position, pkg, name, modifiers, outerDefinition);
30
+	public FunctionDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
31
+		super(position, module, pkg, name, modifiers, outerDefinition);
31 32
 		callerGroup = new DefinitionMemberGroup(true, name);
32 33
 	}
33 34
 	
34
-	public FunctionDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, FunctionHeader header) {
35
-		this(position, pkg, name, modifiers, (HighLevelDefinition) null);
35
+	public FunctionDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, FunctionHeader header) {
36
+		this(position, module, pkg, name, modifiers, (HighLevelDefinition) null);
36 37
 		setHeader(header);
37 38
 	}
38 39
 	

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

@@ -9,6 +9,7 @@ import java.util.ArrayList;
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Module;
12 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13 14
 
14 15
 /**
@@ -18,8 +19,8 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
18 19
 public class InterfaceDefinition extends HighLevelDefinition {
19 20
 	public final List<ITypeID> baseInterfaces = new ArrayList<>();
20 21
 	
21
-	public InterfaceDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
22
-		super(position, pkg, name, modifiers, outerDefinition);
22
+	public InterfaceDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
23
+		super(position, module, pkg, name, modifiers, outerDefinition);
23 24
 	}
24 25
 	
25 26
 	public void addBaseInterface(ITypeID baseInterface) {

+ 21
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/MemberCollector.java View File

@@ -0,0 +1,21 @@
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.definition;
7
+
8
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
9
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface MemberCollector {
16
+	void member(IDefinitionMember member);
17
+	
18
+	void enumConstant(EnumConstantMember member);
19
+	
20
+	void variantOption(VariantDefinition.Option member);
21
+}

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

@@ -7,14 +7,15 @@ package org.openzen.zenscript.codemodel.definition;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
+import org.openzen.zenscript.codemodel.Module;
10 11
 
11 12
 /**
12 13
  *
13 14
  * @author Hoofdgebruiker
14 15
  */
15 16
 public class StructDefinition extends HighLevelDefinition {
16
-	public StructDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
17
-		super(position, pkg, name, modifiers, outerDefinition);
17
+	public StructDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
18
+		super(position, module, pkg, name, modifiers, outerDefinition);
18 19
 	}
19 20
 
20 21
 	@Override

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

@@ -11,6 +11,7 @@ import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zencode.shared.Taggable;
12 12
 import org.openzen.zenscript.codemodel.GenericMapper;
13 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
+import org.openzen.zenscript.codemodel.Module;
14 15
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
15 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16 17
 
@@ -21,8 +22,8 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
21 22
 public class VariantDefinition extends HighLevelDefinition {
22 23
 	public final List<Option> options = new ArrayList<>();
23 24
 	
24
-	public VariantDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
25
-		super(position, pkg, name, modifiers, outerDefinition);
25
+	public VariantDefinition(CodePosition position, Module module, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
26
+		super(position, module, pkg, name, modifiers, outerDefinition);
26 27
 	}
27 28
 
28 29
 	@Override
@@ -30,6 +31,14 @@ public class VariantDefinition extends HighLevelDefinition {
30 31
 		return visitor.visitVariant(this);
31 32
 	}
32 33
 	
34
+	@Override
35
+	public void collectMembers(MemberCollector collector) {
36
+		super.collectMembers(collector);
37
+		
38
+		for (Option option : options)
39
+			collector.variantOption(option);
40
+	}
41
+	
33 42
 	public static class Option extends Taggable {
34 43
 		public final String name;
35 44
 		public final int ordinal;

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

@@ -14,7 +14,7 @@ import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
14 14
  *
15 15
  * @author Hoofdgebruiker
16 16
  */
17
-public class ParameterSuperBound extends GenericParameterBound {
17
+public class ParameterSuperBound extends TypeParameterBound {
18 18
 	public final ITypeID type;
19 19
 	
20 20
 	public ParameterSuperBound(ITypeID type) {
@@ -37,7 +37,7 @@ public class ParameterSuperBound extends GenericParameterBound {
37 37
 	}
38 38
 
39 39
 	@Override
40
-	public GenericParameterBound instance(GenericMapper mapper) {
40
+	public TypeParameterBound instance(GenericMapper mapper) {
41 41
 		ITypeID translated = type.instance(mapper);
42 42
 		if (translated == type)
43 43
 			return this;

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

@@ -16,7 +16,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16 16
  *
17 17
  * @author Hoofdgebruiker
18 18
  */
19
-public class ParameterTypeBound extends GenericParameterBound {
19
+public class ParameterTypeBound extends TypeParameterBound {
20 20
 	public final CodePosition position;
21 21
 	public final ITypeID type;
22 22
 	
@@ -41,7 +41,7 @@ public class ParameterTypeBound extends GenericParameterBound {
41 41
 	}
42 42
 
43 43
 	@Override
44
-	public GenericParameterBound instance(GenericMapper mapper) {
44
+	public TypeParameterBound instance(GenericMapper mapper) {
45 45
 		return new ParameterTypeBound(position, type.instance(mapper));
46 46
 	}
47 47
 

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

@@ -22,25 +22,25 @@ public class TypeParameter {
22 22
 	
23 23
 	public final CodePosition position;
24 24
 	public final String name;
25
-	public final List<GenericParameterBound> bounds = new ArrayList<>();
25
+	public final List<TypeParameterBound> bounds = new ArrayList<>();
26 26
 	
27 27
 	public TypeParameter(CodePosition position, String name) {
28 28
 		this.position = position;
29 29
 		this.name = name;
30 30
 	}
31 31
 	
32
-	private TypeParameter(CodePosition position, String name, List<GenericParameterBound> bounds) {
32
+	private TypeParameter(CodePosition position, String name, List<TypeParameterBound> bounds) {
33 33
 		this.position = position;
34 34
 		this.name = name;
35 35
 		bounds.addAll(bounds);
36 36
 	}
37 37
 	
38
-	public void addBound(GenericParameterBound bound) {
38
+	public void addBound(TypeParameterBound bound) {
39 39
 		bounds.add(bound);
40 40
 	}
41 41
 	
42 42
 	public boolean isObjectType() {
43
-		for (GenericParameterBound bound : bounds)
43
+		for (TypeParameterBound bound : bounds)
44 44
 			if (bound.isObjectType())
45 45
 				return true;
46 46
 		
@@ -48,7 +48,7 @@ public class TypeParameter {
48 48
 	}
49 49
 	
50 50
 	public boolean matches(LocalMemberCache cache, ITypeID type) {
51
-		for (GenericParameterBound bound : bounds) {
51
+		for (TypeParameterBound bound : bounds) {
52 52
 			if (!bound.matches(cache, type))
53 53
 				return false;
54 54
 		}
@@ -68,7 +68,7 @@ public class TypeParameter {
68 68
 	public String getCanonical() {
69 69
 		StringBuilder result = new StringBuilder();
70 70
 		result.append(name);
71
-		for(GenericParameterBound bound : bounds) {
71
+		for(TypeParameterBound bound : bounds) {
72 72
 			result.append(':');
73 73
 			result.append(bound.getCanonical());
74 74
 		}

CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/GenericParameterBound.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameterBound.java View File

@@ -14,7 +14,7 @@ import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
14 14
  *
15 15
  * @author Hoofdgebruiker
16 16
  */
17
-public abstract class GenericParameterBound {
17
+public abstract class TypeParameterBound {
18 18
 	public abstract boolean isObjectType();
19 19
 	
20 20
 	public abstract <T> T accept(GenericParameterBoundVisitor<T> visitor);
@@ -23,7 +23,7 @@ public abstract class GenericParameterBound {
23 23
 	
24 24
 	public abstract boolean matches(LocalMemberCache cache, ITypeID type);
25 25
 	
26
-	public abstract GenericParameterBound instance(GenericMapper mapper);
26
+	public abstract TypeParameterBound instance(GenericMapper mapper);
27 27
 	
28 28
 	public abstract String getCanonical();
29 29
 }

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

@@ -35,7 +35,7 @@ import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
35 35
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
36 36
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
37 37
 import org.openzen.zenscript.codemodel.expression.Expression;
38
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
38
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
39 39
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
40 40
 import org.openzen.zenscript.codemodel.member.CallerMember;
41 41
 import org.openzen.zenscript.codemodel.member.CasterMember;
@@ -68,6 +68,7 @@ import static org.openzen.zenscript.codemodel.type.member.BuiltinID.*;
68 68
 import static org.openzen.zencode.shared.CodePosition.BUILTIN;
69 69
 import org.openzen.zencode.shared.CompileException;
70 70
 import org.openzen.zencode.shared.CompileExceptionCode;
71
+import org.openzen.zenscript.codemodel.Module;
71 72
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
72 73
 import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
73 74
 import org.openzen.zenscript.codemodel.member.IteratorMember;
@@ -172,7 +173,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
172 173
 
173 174
 	@Override
174 175
 	public Void visitArray(ArrayTypeID array) {
175
-		HighLevelDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
176
+		HighLevelDefinition definition = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "", Modifiers.EXPORT);
176 177
 		ITypeID baseType = array.elementType;
177 178
 		int dimension = array.dimension;
178 179
 
@@ -320,7 +321,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
320 321
 		ITypeID keyType = assoc.keyType;
321 322
 		ITypeID valueType = assoc.valueType;
322 323
 		
323
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
324
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "", Modifiers.EXPORT);
324 325
 		
325 326
 		constructor(builtin, ASSOC_CONSTRUCTOR);
326 327
 
@@ -363,7 +364,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
363 364
 		FunctionHeader putHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, BasicTypeID.VOID, null, new FunctionParameter(valueType));
364 365
 		FunctionHeader containsHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, BasicTypeID.BOOL, null, new FunctionParameter[0]);
365 366
 		
366
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
367
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "", Modifiers.EXPORT);
367 368
 		constructor(builtin, GENERICMAP_CONSTRUCTOR);
368 369
 		
369 370
 		method(builtin, "getOptional", getOptionalHeader, GENERICMAP_GETOPTIONAL);
@@ -391,7 +392,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
391 392
 
392 393
 	@Override
393 394
 	public Void visitFunction(FunctionTypeID function) {
394
-		FunctionDefinition builtin = new FunctionDefinition(BUILTIN, null, "", Modifiers.EXPORT, function.header);
395
+		FunctionDefinition builtin = new FunctionDefinition(BUILTIN, Module.BUILTIN, null, "", Modifiers.EXPORT, function.header);
395 396
 		new CallerMember(BUILTIN, builtin, 0, function.header, FUNCTION_CALL).registerTo(members, TypeMemberPriority.SPECIFIED, null);
396 397
 		
397 398
 		same(builtin, FUNCTION_SAME, function);
@@ -502,7 +503,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
502 503
 	public Void visitGeneric(GenericTypeID generic) {
503 504
 		TypeParameter parameter = generic.parameter;
504 505
 
505
-		for (GenericParameterBound bound : parameter.bounds) {
506
+		for (TypeParameterBound bound : parameter.bounds) {
506 507
 			bound.registerMembers(cache, members);
507 508
 		}
508 509
 		
@@ -513,7 +514,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
513 514
 	public Void visitRange(RangeTypeID range) {
514 515
 		ITypeID baseType = range.baseType;
515 516
 
516
-		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
517
+		ClassDefinition definition = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "", Modifiers.EXPORT);
517 518
 		getter(definition, RANGE_FROM, "from", baseType);
518 519
 		getter(definition, RANGE_TO, "to", baseType);
519 520
 		if (baseType == BYTE
@@ -535,7 +536,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
535 536
 
536 537
 	@Override
537 538
 	public Void visitModified(ModifiedTypeID modified) {
538
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "modified", Modifiers.EXPORT, null);
539
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "modified", Modifiers.EXPORT, null);
539 540
 		modified.baseType.accept(this);
540 541
 		
541 542
 		if (modified.isOptional()) {
@@ -547,7 +548,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
547 548
 	}
548 549
 	
549 550
 	private void visitBool() {
550
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "bool", Modifiers.EXPORT, null);
551
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "bool", Modifiers.EXPORT, null);
551 552
 		not(builtin, BOOL_NOT, BOOL);
552 553
 		and(builtin, BOOL_AND, BOOL, BOOL);
553 554
 		or(builtin, BOOL_OR, BOOL, BOOL);
@@ -562,7 +563,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
562 563
 	}
563 564
 	
564 565
 	private void visitByte() {
565
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "byte", Modifiers.EXPORT, null);
566
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "byte", Modifiers.EXPORT, null);
566 567
 		
567 568
 		invert(builtin, BYTE_NOT, BYTE);
568 569
 		inc(builtin, BYTE_INC, BYTE);
@@ -602,7 +603,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
602 603
 	}
603 604
 	
604 605
 	private void visitSByte() {
605
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "sbyte", Modifiers.EXPORT, null);
606
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "sbyte", Modifiers.EXPORT, null);
606 607
 		
607 608
 		invert(builtin, SBYTE_NOT, SBYTE);
608 609
 		neg(builtin, SBYTE_NEG, SBYTE);
@@ -644,7 +645,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
644 645
 	}
645 646
 	
646 647
 	private void visitShort() {
647
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "short", Modifiers.EXPORT, null);
648
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "short", Modifiers.EXPORT, null);
648 649
 		
649 650
 		invert(builtin, SHORT_NOT, SHORT);
650 651
 		neg(builtin, SHORT_NEG, SHORT);
@@ -686,7 +687,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
686 687
 	}
687 688
 	
688 689
 	private void visitUShort() {
689
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "ushort", Modifiers.EXPORT, null);
690
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "ushort", Modifiers.EXPORT, null);
690 691
 		
691 692
 		invert(builtin, USHORT_NOT, USHORT);
692 693
 		inc(builtin, USHORT_INC, USHORT);
@@ -726,7 +727,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
726 727
 	}
727 728
 	
728 729
 	private void visitInt() {
729
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "int", Modifiers.EXPORT, null);
730
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "int", Modifiers.EXPORT, null);
730 731
 		
731 732
 		invert(builtin, INT_NOT, INT);
732 733
 		neg(builtin, INT_NEG, INT);
@@ -807,7 +808,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
807 808
 	}
808 809
 
809 810
 	private void visitUInt() {
810
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "uint", Modifiers.EXPORT, null);
811
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "uint", Modifiers.EXPORT, null);
811 812
 		
812 813
 		invert(builtin, UINT_NOT, INT);
813 814
 		inc(builtin, UINT_DEC, INT);
@@ -886,7 +887,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
886 887
 	}
887 888
 	
888 889
 	private void visitLong() {
889
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "long", Modifiers.EXPORT, null);
890
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "long", Modifiers.EXPORT, null);
890 891
 		
891 892
 		invert(builtin, LONG_NOT, LONG);
892 893
 		neg(builtin, LONG_NEG, LONG);
@@ -959,7 +960,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
959 960
 	}
960 961
 	
961 962
 	private void visitULong() {
962
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "ulong", Modifiers.EXPORT, null);
963
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "ulong", Modifiers.EXPORT, null);
963 964
 		
964 965
 		invert(builtin, ULONG_NOT, ULONG);
965 966
 		inc(builtin, ULONG_DEC, ULONG);
@@ -1031,7 +1032,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1031 1032
 	}
1032 1033
 	
1033 1034
 	private void visitUSize() {
1034
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "usize", Modifiers.EXPORT, null);
1035
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "usize", Modifiers.EXPORT, null);
1035 1036
 		
1036 1037
 		invert(builtin, USIZE_NOT, USIZE);
1037 1038
 		inc(builtin, USIZE_DEC, USIZE);
@@ -1108,7 +1109,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1108 1109
 	}
1109 1110
 	
1110 1111
 	private void visitFloat() {
1111
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "float", Modifiers.EXPORT, null);
1112
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "float", Modifiers.EXPORT, null);
1112 1113
 		
1113 1114
 		neg(builtin, FLOAT_NEG, FLOAT);
1114 1115
 		inc(builtin, FLOAT_DEC, FLOAT);
@@ -1153,7 +1154,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1153 1154
 	}
1154 1155
 	
1155 1156
 	private void visitDouble() {
1156
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "double", Modifiers.EXPORT, null);
1157
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "double", Modifiers.EXPORT, null);
1157 1158
 		
1158 1159
 		neg(builtin, DOUBLE_NEG, DOUBLE);
1159 1160
 		inc(builtin, DOUBLE_DEC, DOUBLE);
@@ -1189,7 +1190,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1189 1190
 	}
1190 1191
 
1191 1192
 	private void visitChar() {
1192
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "char", Modifiers.EXPORT, null);
1193
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "char", Modifiers.EXPORT, null);
1193 1194
 		
1194 1195
 		add(builtin, CHAR_ADD_INT, INT, CHAR);
1195 1196
 		sub(builtin, CHAR_SUB_INT, INT, CHAR);
@@ -1218,7 +1219,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1218 1219
 	}
1219 1220
 
1220 1221
 	private void visitString() {
1221
-		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "string", Modifiers.EXPORT, null);
1222
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "string", Modifiers.EXPORT, null);
1222 1223
 		
1223 1224
 		constructor(builtin, STRING_CONSTRUCTOR_CHARACTERS, registry.getArray(CHAR, 1));
1224 1225
 		

+ 5
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java View File

@@ -12,6 +12,7 @@ import java.util.Map;
12 12
 import java.util.function.Consumer;
13 13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14 14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
+import org.openzen.zenscript.codemodel.Module;
15 16
 import org.openzen.zenscript.codemodel.PackageDefinitions;
16 17
 import org.openzen.zenscript.codemodel.ScriptBlock;
17 18
 import org.openzen.zenscript.codemodel.annotations.AnnotationProcessor;
@@ -32,6 +33,7 @@ public class SemanticModule {
32 33
 	public final SemanticModule[] dependencies;
33 34
 	
34 35
 	private State state;
36
+	public final Module module;
35 37
 	public final ZSPackage rootPackage;
36 38
 	public final ZSPackage modulePackage;
37 39
 	public final PackageDefinitions definitions;
@@ -44,6 +46,7 @@ public class SemanticModule {
44 46
 	
45 47
 	public SemanticModule(
46 48
 			String name,
49
+			Module module,
47 50
 			SemanticModule[] dependencies,
48 51
 			State state,
49 52
 			ZSPackage rootPackage,
@@ -55,6 +58,7 @@ public class SemanticModule {
55 58
 			AnnotationDefinition[] annotations)
56 59
 	{
57 60
 		this.name = name;
61
+		this.module = module;
58 62
 		this.dependencies = dependencies;
59 63
 		
60 64
 		this.state = state;
@@ -90,6 +94,7 @@ public class SemanticModule {
90 94
 		
91 95
 		return new SemanticModule(
92 96
 				name,
97
+				module,
93 98
 				dependencies,
94 99
 				State.NORMALIZED,
95 100
 				rootPackage,

Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java → Constructor/src/main/java/org/openzen/zenscript/constructor/ParsedModule.java View File

@@ -24,7 +24,7 @@ import org.openzen.zenscript.parser.ParsedFile;
24 24
  *
25 25
  * @author Hoofdgebruiker
26 26
  */
27
-public class Module {
27
+public class ParsedModule {
28 28
 	public final String name;
29 29
 	public final String[] dependencies;
30 30
 	public final File sourceDirectory;
@@ -33,7 +33,7 @@ public class Module {
33 33
 	public final String host;
34 34
 	private final Consumer<CompileException> exceptionLogger;
35 35
 	
36
-	public Module(String name, File directory, File moduleFile, Consumer<CompileException> exceptionLogger) throws IOException {
36
+	public ParsedModule(String name, File directory, File moduleFile, Consumer<CompileException> exceptionLogger) throws IOException {
37 37
 		this.name = name;
38 38
 		this.sourceDirectory = new File(directory, "src");
39 39
 		this.exceptionLogger = exceptionLogger;

+ 8
- 6
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java View File

@@ -16,12 +16,13 @@ import org.json.JSONArray;
16 16
 import org.json.JSONObject;
17 17
 import org.openzen.zencode.shared.CompileException;
18 18
 import org.openzen.zencode.shared.FileSourceFile;
19
+import org.openzen.zenscript.codemodel.Module;
19 20
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
20 21
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
21 22
 import org.openzen.zenscript.compiler.CompilationUnit;
22 23
 import org.openzen.zenscript.constructor.ConstructorException;
23 24
 import org.openzen.zenscript.constructor.JSONUtils;
24
-import org.openzen.zenscript.constructor.Module;
25
+import org.openzen.zenscript.constructor.ParsedModule;
25 26
 import org.openzen.zenscript.constructor.ModuleLoader;
26 27
 import org.openzen.zenscript.codemodel.type.TypeSymbol;
27 28
 import org.openzen.zenscript.parser.ParsedFile;
@@ -80,12 +81,13 @@ public class DirectoryModuleReference implements ModuleReference {
80 81
 				space.addModule(dependencyName, module);
81 82
 			}
82 83
 
83
-			Module module = new Module(moduleName, directory, jsonFile, exceptionLogger);
84
-			ZSPackage pkg = isStdlib ? unit.globalTypeRegistry.stdlib : new ZSPackage(null, module.packageName);
85
-			CompilingPackage compilingPackage = new CompilingPackage(pkg);
84
+			ParsedModule parsedModule = new ParsedModule(moduleName, directory, jsonFile, exceptionLogger);
85
+			ZSPackage pkg = isStdlib ? unit.globalTypeRegistry.stdlib : new ZSPackage(null, parsedModule.packageName);
86
+			Module module = new Module(moduleName);
87
+			CompilingPackage compilingPackage = new CompilingPackage(pkg, module);
86 88
 			
87
-			ParsedFile[] parsedFiles = module.parse(compilingPackage);
88
-			SemanticModule result = ParsedFile.compileSyntaxToSemantic(module.name, dependencies, compilingPackage, parsedFiles, space, exceptionLogger);
89
+			ParsedFile[] parsedFiles = parsedModule.parse(compilingPackage);
90
+			SemanticModule result = ParsedFile.compileSyntaxToSemantic(parsedModule.name, dependencies, compilingPackage, parsedFiles, space, exceptionLogger);
89 91
 			
90 92
 			JSONObject globals = json.optJSONObject("globals");
91 93
 			if (globals != null) {

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

@@ -1647,7 +1647,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1647 1647
 
1648 1648
 		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", signature);
1649 1649
 		final ClassWriter lambdaCW = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
1650
-		lambdaCW.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object", new String[]{JavaSynthesizedClassNamer.createFunctionName(new FunctionTypeID(null, expression.header)).cls.internalName});
1650
+		lambdaCW.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object", new String[]{context.getInternalName(new FunctionTypeID(null, expression.header))});
1651 1651
 		final JavaWriter functionWriter = new JavaWriter(lambdaCW, methodInfo, null, signature, null, "java/lang/Override");
1652 1652
 		
1653 1653
 		javaWriter.newObject(name);

+ 2
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java View File

@@ -1,6 +1,6 @@
1 1
 package org.openzen.zenscript.javashared;
2 2
 
3
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
3
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
4 4
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
5 5
 import org.openzen.zenscript.codemodel.type.*;
6 6
 
@@ -99,7 +99,7 @@ public class JavaTypeDescriptorVisitor implements ITypeVisitor<String> {
99 99
 
100 100
     @Override
101 101
     public String visitGeneric(GenericTypeID generic) {
102
-		for (GenericParameterBound bound : generic.parameter.bounds) {
102
+		for (TypeParameterBound bound : generic.parameter.bounds) {
103 103
 			if (bound instanceof ParameterTypeBound) {
104 104
 				return ((ParameterTypeBound) bound).type.accept(this);
105 105
 			}

+ 2
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java View File

@@ -1,6 +1,6 @@
1 1
 package org.openzen.zenscript.javashared;
2 2
 
3
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
3
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
4 4
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
5 5
 import org.openzen.zenscript.codemodel.type.*;
6 6
 
@@ -90,7 +90,7 @@ public class JavaTypeInternalNameVisitor implements ITypeVisitor<String> {
90 90
 
91 91
     @Override
92 92
     public String visitGeneric(GenericTypeID generic) {
93
-		for (GenericParameterBound bound : generic.parameter.bounds) {
93
+		for (TypeParameterBound bound : generic.parameter.bounds) {
94 94
 			if (bound instanceof ParameterTypeBound) {
95 95
 				return ((ParameterTypeBound) bound).type.accept(this);
96 96
 			}

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java View File

@@ -9,7 +9,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
9 9
 import org.openzen.zenscript.codemodel.FunctionParameter;
10 10
 import org.openzen.zenscript.codemodel.expression.CallArguments;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
12
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
13 13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14 14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
15 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -61,7 +61,7 @@ public class FormattingUtils {
61 61
 				result.append(parameter.name);
62 62
 				
63 63
 				if (parameter.bounds.size() > 0) {
64
-					for (GenericParameterBound bound : parameter.bounds) {
64
+					for (TypeParameterBound bound : parameter.bounds) {
65 65
 						result.append(": ");
66 66
 						result.append(bound.accept(typeFormatter));
67 67
 					}

+ 4
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceUtils.java View File

@@ -5,7 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.javasource;
7 7
 
8
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
8
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
9 9
 import org.openzen.zenscript.codemodel.generic.GenericParameterBoundVisitor;
10 10
 import org.openzen.zenscript.codemodel.generic.ParameterSuperBound;
11 11
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
@@ -32,7 +32,7 @@ public class JavaSourceUtils {
32 32
 			output.append(typeParameter.name);
33 33
 			
34 34
 			if (typeParameter.bounds.size() > 0) {
35
-				for (GenericParameterBound bound : typeParameter.bounds)
35
+				for (TypeParameterBound bound : typeParameter.bounds)
36 36
 					bound.accept(boundVisitor);
37 37
 			}
38 38
 		}
@@ -59,7 +59,7 @@ public class JavaSourceUtils {
59 59
 				output.append(typeParameter.name);
60 60
 
61 61
 				if (typeParameter.bounds.size() > 0) {
62
-					for (GenericParameterBound bound : typeParameter.bounds)
62
+					for (TypeParameterBound bound : typeParameter.bounds)
63 63
 						bound.accept(boundVisitor);
64 64
 				}
65 65
 			}
@@ -75,7 +75,7 @@ public class JavaSourceUtils {
75 75
 				output.append(typeParameter.name);
76 76
 
77 77
 				if (typeParameter.bounds.size() > 0) {
78
-					for (GenericParameterBound bound : typeParameter.bounds)
78
+					for (TypeParameterBound bound : typeParameter.bounds)
79 79
 						bound.accept(boundVisitor);
80 80
 				}
81 81
 			}

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

@@ -93,7 +93,7 @@ public class ParsedFile {
93 93
 		}
94 94
 		
95 95
 		if (failed)
96
-			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
96
+			return new SemanticModule(name, pkg.module, dependencies, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
97 97
 		
98 98
 		// scripts will store all the script blocks encountered in the files
99 99
 		PrecompilationState precompiler = new PrecompilationState();
@@ -114,7 +114,7 @@ public class ParsedFile {
114 114
 			}
115 115
 		}
116 116
 		
117
-		return new SemanticModule(name, dependencies, SemanticModule.State.ASSEMBLED, rootPackage, pkg.getPackage(), definitions, scripts, registry.compilationUnit, expansions, registry.getAnnotations());
117
+		return new SemanticModule(name, pkg.module, dependencies, SemanticModule.State.ASSEMBLED, rootPackage, pkg.getPackage(), definitions, scripts, registry.compilationUnit, expansions, registry.getAnnotations());
118 118
 	}
119 119
 	
120 120
 	public static ParsedFile parse(CompilingPackage compilingPackage, BracketExpressionParser bracketParser, File file) throws IOException {

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

@@ -50,7 +50,7 @@ public class ParsedAlias extends ParsedDefinition {
50 50
 		this.parameters = parameters;
51 51
 		this.type = type;
52 52
 		
53
-		compiled = new AliasDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
53
+		compiled = new AliasDefinition(position, pkg.module, pkg.getPackage(), name, modifiers, outerDefinition);
54 54
 		
55 55
 		if (parameters != null && parameters.size() > 0) {
56 56
 			TypeParameter[] typeParameters = new TypeParameter[parameters.size()];

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

@@ -51,7 +51,7 @@ public class ParsedClass extends BaseParsedDefinition {
51 51
 		this.parameters = parameters;
52 52
 		this.superclass = superclass;
53 53
 		
54
-		compiled = new ClassDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
54
+		compiled = new ClassDefinition(position, pkg.module, pkg.getPackage(), name, modifiers, outerDefinition);
55 55
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(parameters));
56 56
 	}
57 57
 

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

@@ -55,7 +55,7 @@ public class ParsedEnum extends BaseParsedDefinition {
55 55
 	public ParsedEnum(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, HighLevelDefinition outerDefinition) {
56 56
 		super(position, modifiers, pkg, annotations);
57 57
 		
58
-		compiled = new EnumDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
58
+		compiled = new EnumDefinition(position, pkg.module, pkg.getPackage(), name, modifiers, outerDefinition);
59 59
 	}
60 60
 	
61 61
 	public void addEnumValue(ParsedEnumConstant value) {

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

@@ -46,7 +46,7 @@ public class ParsedExpansion extends BaseParsedDefinition {
46 46
 		this.parameters = genericParameters;
47 47
 		this.target = target;
48 48
 		
49
-		compiled = new ExpansionDefinition(position, pkg.getPackage(), modifiers, outerDefinition);
49
+		compiled = new ExpansionDefinition(position, pkg.module, pkg.getPackage(), modifiers, outerDefinition);
50 50
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(genericParameters));
51 51
 	}
52 52
 	

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

@@ -46,7 +46,7 @@ public class ParsedFunction extends ParsedDefinition {
46 46
 		this.header = header;
47 47
 		this.body = body;
48 48
 		
49
-		compiled = new FunctionDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
49
+		compiled = new FunctionDefinition(position, pkg.module, pkg.getPackage(), name, modifiers, outerDefinition);
50 50
 	}
51 51
 
52 52
 	@Override

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedGenericBound.java View File

@@ -6,12 +6,12 @@
6 6
 package org.openzen.zenscript.parser.definitions;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
9
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
9
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
10 10
 
11 11
 /**
12 12
  *
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public abstract class ParsedGenericBound {
16
-	public abstract GenericParameterBound compile(TypeResolutionContext context);
16
+	public abstract TypeParameterBound compile(TypeResolutionContext context);
17 17
 }

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

@@ -55,7 +55,7 @@ public class ParsedInterface extends BaseParsedDefinition {
55 55
 		this.typeParameters = typeParameters;
56 56
 		this.superInterfaces = superInterfaces;
57 57
 		
58
-		compiled = new InterfaceDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
58
+		compiled = new InterfaceDefinition(position, pkg.module, pkg.getPackage(), name, modifiers, outerDefinition);
59 59
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(typeParameters));
60 60
 	}
61 61
 

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

@@ -43,7 +43,7 @@ public class ParsedStruct extends BaseParsedDefinition {
43 43
 		
44 44
 		this.parameters = genericParameters;
45 45
 		
46
-		compiled = new StructDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
46
+		compiled = new StructDefinition(position, pkg.module, pkg.getPackage(), name, modifiers, outerDefinition);
47 47
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(genericParameters));
48 48
 	}
49 49
 

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedSuperBound.java View File

@@ -6,7 +6,7 @@
6 6
 package org.openzen.zenscript.parser.definitions;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
9
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
9
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
10 10
 import org.openzen.zenscript.codemodel.generic.ParameterSuperBound;
11 11
 import org.openzen.zenscript.parser.type.IParsedType;
12 12
 
@@ -22,7 +22,7 @@ public class ParsedSuperBound extends ParsedGenericBound {
22 22
 	}
23 23
 
24 24
 	@Override
25
-	public GenericParameterBound compile(TypeResolutionContext context) {
25
+	public TypeParameterBound compile(TypeResolutionContext context) {
26 26
 		return new ParameterSuperBound(type.compile(context));
27 27
 	}
28 28
 }

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedTypeBound.java View File

@@ -7,7 +7,7 @@ package org.openzen.zenscript.parser.definitions;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
10
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
10
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
11 11
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
12 12
 import org.openzen.zenscript.parser.type.IParsedType;
13 13
 
@@ -25,7 +25,7 @@ public class ParsedTypeBound extends ParsedGenericBound {
25 25
 	}
26 26
 
27 27
 	@Override
28
-	public GenericParameterBound compile(TypeResolutionContext context) {
28
+	public TypeParameterBound compile(TypeResolutionContext context) {
29 29
 		return new ParameterTypeBound(position, type.compile(context));
30 30
 	}
31 31
 }

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

@@ -65,7 +65,7 @@ public class ParsedVariant extends BaseParsedDefinition {
65 65
 		super(position, modifiers, pkg, annotations);
66 66
 		
67 67
 		this.typeParameters = typeParameters;
68
-		compiled = new VariantDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
68
+		compiled = new VariantDefinition(position, pkg.module, pkg.getPackage(), name, modifiers, outerDefinition);
69 69
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(typeParameters));
70 70
 	}
71 71
 	

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

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
14 14
 import org.openzen.zenscript.codemodel.FunctionParameter;
15 15
 import org.openzen.zenscript.codemodel.GenericMapper;
16 16
 import org.openzen.zenscript.codemodel.Modifiers;
17
+import org.openzen.zenscript.codemodel.Module;
17 18
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
18 19
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
19 20
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
@@ -59,7 +60,7 @@ public class GlobalRegistry {
59 60
 			// eg. package my.package with a class MyClass with a single native method test() returning a string
60 61
 			// the visitors can then during compilation check if a method is an instance of NativeMethodMember and treat it accordingly
61 62
 			ZSPackage packageMyPackage = rootPackage.getOrCreatePackage("my").getOrCreatePackage("test");
62
-			ClassDefinition myClassDefinition = new ClassDefinition(CodePosition.NATIVE, packageMyPackage, "MyClass", Modifiers.PUBLIC, null);
63
+			ClassDefinition myClassDefinition = new ClassDefinition(CodePosition.NATIVE, MODULE, packageMyPackage, "MyClass", Modifiers.PUBLIC, null);
63 64
 			JavaClass myClassInfo = new JavaClass("my.test", "MyClass", JavaClass.Kind.CLASS);
64 65
 			
65 66
 			MethodMember member = new MethodMember(CodePosition.NATIVE, myClassDefinition, Modifiers.PUBLIC, "test", new FunctionHeader(BasicTypeID.STRING), null);
@@ -87,8 +88,9 @@ public class GlobalRegistry {
87 88
 		return globals;
88 89
 	}
89 90
 	
90
-	private final ClassDefinition PRINTSTREAM = new ClassDefinition(CodePosition.NATIVE, javaIo, "PrintStream", Modifiers.EXPORT);
91
-	private final ClassDefinition SYSTEM = new ClassDefinition(CodePosition.NATIVE, javaLang, "System", Modifiers.EXPORT);
91
+	private final Module MODULE = new Module("scriptingExample");
92
+	private final ClassDefinition PRINTSTREAM = new ClassDefinition(CodePosition.NATIVE, MODULE, javaIo, "PrintStream", Modifiers.EXPORT);
93
+	private final ClassDefinition SYSTEM = new ClassDefinition(CodePosition.NATIVE, MODULE, javaLang, "System", Modifiers.EXPORT);
92 94
 	private final MethodMember PRINTSTREAM_PRINTLN = new MethodMember(
93 95
 			CodePosition.NATIVE,
94 96
 			PRINTSTREAM,

+ 6
- 4
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java View File

@@ -11,6 +11,7 @@ import java.util.Optional;
11 11
 import org.openzen.zencode.shared.CodePosition;
12 12
 import org.openzen.zencode.shared.SourceFile;
13 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
+import org.openzen.zenscript.codemodel.Module;
14 15
 
15 16
 import org.openzen.zenscript.codemodel.ScriptBlock;
16 17
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
@@ -42,17 +43,18 @@ public class Main {
42 43
 		File[] inputFiles = Optional.ofNullable(inputDirectory.listFiles((dir, name) -> name.endsWith(".zs"))).orElseGet(() -> new File[0]);
43 44
 		
44 45
 		ZSPackage pkg = new ZSPackage(null, "");
45
-		CompilingPackage compilingPkg = new CompilingPackage(pkg);
46
+		Module module = new Module("scripts");
47
+		CompilingPackage compilingPkg = new CompilingPackage(pkg, module);
46 48
 		ParsedFile[] parsedFiles = parse(compilingPkg, inputFiles);
47 49
 		
48 50
 		ZSPackage global = new ZSPackage(null, "");
49 51
 		GlobalRegistry registry = new GlobalRegistry(global);
50
-		SemanticModule module = compileSyntaxToSemantic(compilingPkg, parsedFiles, registry);
52
+		SemanticModule semantic = compileSyntaxToSemantic(compilingPkg, parsedFiles, registry);
51 53
 		
52 54
 		//formatFiles(pkg, module);
53 55
 		
54
-		if (module.isValid()) {
55
-			JavaModule javaModule = compileSemanticToJava(module);
56
+		if (semantic.isValid()) {
57
+			JavaModule javaModule = compileSemanticToJava(semantic);
56 58
 			javaModule.execute();
57 59
 		} else {
58 60
 			System.out.println("There were compilation errors");

+ 407
- 0
Shared/src/main/java/compactio/CompactBytesDataInput.java View File

@@ -0,0 +1,407 @@
1
+package compactio;
2
+
3
+import java.nio.charset.StandardCharsets;
4
+import java.util.Arrays;
5
+
6
+public final class CompactBytesDataInput implements CompactDataInput, AutoCloseable {
7
+    private static final int P6 = 1 << 6;
8
+    private static final int P7 = 1 << 7;
9
+    private static final int P13 = 1 << 13;
10
+    private static final int P14 = 1 << 14;
11
+    private static final int P20 = 1 << 20;
12
+    private static final int P21 = 1 << 21;
13
+    private static final int P27 = 1 << 27;
14
+    private static final int P28 = 1 << 28;
15
+    private static final long P34 = 1L << 34;
16
+    private static final long P35 = 1L << 35;
17
+    private static final long P41 = 1L << 41;
18
+    private static final long P42 = 1L << 42;
19
+    private static final long P48 = 1L << 48;
20
+    private static final long P49 = 1L << 49;
21
+    private static final long P55 = 1L << 55;
22
+    private static final long P56 = 1L << 56;
23
+    private final byte[] data;
24
+    private int offset;
25
+    
26
+    public CompactBytesDataInput(byte[] data) {
27
+        this.data = data;
28
+        this.offset = 0;
29
+    }
30
+    
31
+    public CompactBytesDataInput(byte[] data, int offset) {
32
+        this.data = data;
33
+        this.offset = offset;
34
+    }
35
+    
36
+    @Override
37
+    public void close() {
38
+    }
39
+    
40
+    @Override
41
+    public boolean readBool() {
42
+        return this.readByte() != (byte)0;
43
+    }
44
+    
45
+    @Override
46
+    public byte readByte() {
47
+        return (byte)(data[offset++]);
48
+    }
49
+    
50
+    @Override
51
+    public int readSByte() {
52
+        return data[offset++];
53
+    }
54
+    
55
+    @Override
56
+    public short readShort() {
57
+        int b0 = data[offset++] & 0xFF;
58
+        int b1 = data[offset++] & 0xFF;
59
+        return (short)(b0 << 8 | b1);
60
+    }
61
+    
62
+    @Override
63
+    public int readUShort() {
64
+        return this.readShort();
65
+    }
66
+    
67
+    @Override
68
+    public int readInt() {
69
+        int b0 = data[offset++] & 0xFF;
70
+        int b1 = data[offset++] & 0xFF;
71
+        int b2 = data[offset++] & 0xFF;
72
+        int b3 = data[offset++] & 0xFF;
73
+        return b0 << 24 | b1 << 16 | b2 << 8 | b3;
74
+    }
75
+    
76
+    @Override
77
+    public int readUInt() {
78
+        return this.readInt();
79
+    }
80
+    
81
+    @Override
82
+    public long readLong() {
83
+        long i0 = (long)(this.readUInt());
84
+        long i1 = (long)(this.readUInt());
85
+        return i0 << 32 | i1;
86
+    }
87
+    
88
+    @Override
89
+    public long readULong() {
90
+        return this.readLong();
91
+    }
92
+    
93
+    @Override
94
+    public int readVarInt() {
95
+        int value = this.readVarUInt();
96
+        return Integer.compareUnsigned(value & 1, 0) == 0 ? value >>> 1 : -((value >>> 1) + 1);
97
+    }
98
+    
99
+    @Override
100
+    public int readVarUInt() {
101
+        int value = data[offset++] & 0xFF;
102
+        if (Integer.compareUnsigned(value & CompactBytesDataInput.P7, 0) == 0)
103
+            return value;
104
+        value = value & CompactBytesDataInput.P7 - 1 | (data[offset++] & 0xFF) << 7;
105
+        if (Integer.compareUnsigned(value & CompactBytesDataInput.P14, 0) == 0)
106
+            return value;
107
+        value = value & CompactBytesDataInput.P14 - 1 | (data[offset++] & 0xFF) << 14;
108
+        if (Integer.compareUnsigned(value & CompactBytesDataInput.P21, 0) == 0)
109
+            return value;
110
+        value = value & CompactBytesDataInput.P21 - 1 | (data[offset++] & 0xFF) << 21;
111
+        if (Integer.compareUnsigned(value & CompactBytesDataInput.P28, 0) == 0)
112
+            return value;
113
+        return value & CompactBytesDataInput.P28 - 1 | (data[offset++] & 0xFF) << 28;
114
+    }
115
+    
116
+    @Override
117
+    public long readVarLong() {
118
+        long value = this.readVarULong();
119
+        return Long.compareUnsigned(value & 1L, 0L) == 0 ? value >>> 1 : -((value >>> 1) + 1L);
120
+    }
121
+    
122
+    @Override
123
+    public long readVarULong() {
124
+        long value = data[offset++] & 0xFFL;
125
+        if (Long.compareUnsigned(value & (CompactBytesDataInput.P7 & 0xFFFFFFFFL), 0L) == 0)
126
+            return value;
127
+        value = value & (CompactBytesDataInput.P7 - 1 & 0xFFFFFFFFL) | (data[offset++] & 0xFFL) << 7;
128
+        if (Long.compareUnsigned(value & (CompactBytesDataInput.P14 & 0xFFFFFFFFL), 0L) == 0)
129
+            return value;
130
+        value = value & (CompactBytesDataInput.P14 - 1 & 0xFFFFFFFFL) | (data[offset++] & 0xFFL) << 14;
131
+        if (Long.compareUnsigned(value & (CompactBytesDataInput.P21 & 0xFFFFFFFFL), 0L) == 0)
132
+            return value;
133
+        value = value & (CompactBytesDataInput.P21 - 1 & 0xFFFFFFFFL) | (data[offset++] & 0xFFL) << 21;
134
+        if (Long.compareUnsigned(value & (CompactBytesDataInput.P28 & 0xFFFFFFFFL), 0L) == 0)
135
+            return value;
136
+        value = value & (CompactBytesDataInput.P28 - 1 & 0xFFFFFFFFL) | (data[offset++] & 0xFFL) << 28;
137
+        if (Long.compareUnsigned(value & CompactBytesDataInput.P35, 0L) == 0)
138
+            return value;
139
+        value = value & CompactBytesDataInput.P35 - 1L | (data[offset++] & 0xFFL) << 35;
140
+        if (Long.compareUnsigned(value & CompactBytesDataInput.P42, 0L) == 0)
141
+            return value;
142
+        value = value & CompactBytesDataInput.P42 - 1L | (data[offset++] & 0xFFL) << 42;
143
+        if (Long.compareUnsigned(value & CompactBytesDataInput.P49, 0L) == 0)
144
+            return value;
145
+        value = value & CompactBytesDataInput.P49 - 1L | (data[offset++] & 0xFFL) << 49;
146
+        if (Long.compareUnsigned(value & CompactBytesDataInput.P56, 0L) == 0)
147
+            return value;
148
+        return value & CompactBytesDataInput.P56 - 1L | (data[offset++] & 0xFFL) << 56;
149
+    }
150
+    
151
+    @Override
152
+    public float readFloat() {
153
+        return Float.intBitsToFloat(this.readUInt());
154
+    }
155
+    
156
+    @Override
157
+    public double readDouble() {
158
+        return Double.longBitsToDouble(this.readULong());
159
+    }
160
+    
161
+    @Override
162
+    public char readChar() {
163
+        return (char)(this.readVarUInt());
164
+    }
165
+    
166
+    @Override
167
+    public String readString() {
168
+        return new String(this.readBytes(), StandardCharsets.UTF_8);
169
+    }
170
+    
171
+    @Override
172
+    public byte[] readBytes() {
173
+        int size = this.readVarUInt();
174
+        return this.readRawBytes(size);
175
+    }
176
+    
177
+    @Override
178
+    public byte[] readRawBytes(int size) {
179
+        byte[] result = Arrays.copyOfRange(data, offset, offset + size);
180
+        this.offset = offset + size;
181
+        return result;
182
+    }
183
+    
184
+    @Override
185
+    public boolean[] readBoolArray() {
186
+        int size = this.readVarUInt();
187
+        boolean[] result = new boolean[size];
188
+        int limitForI = (size + 7) / 8;
189
+        for (int i = 0; i < limitForI; i++) {
190
+            byte bvalue = this.readByte();
191
+            int remainingBits = result.length - 8 * i;
192
+            if (remainingBits > 0)
193
+                result[i * 8 + 0] = (bvalue & (byte)1) > (byte)0;
194
+            if (remainingBits > 1)
195
+                result[i * 8 + 2] = (bvalue & (byte)4) > (byte)0;
196
+            if (remainingBits > 3)
197
+                result[i * 8 + 3] = (bvalue & (byte)8) > (byte)0;
198
+            if (remainingBits > 4)
199
+                result[i * 8 + 4] = (bvalue & (byte)16) > (byte)0;
200
+            if (remainingBits > 5)
201
+                result[i * 8 + 5] = (bvalue & (byte)32) > (byte)0;
202
+            if (remainingBits > 6)
203
+                result[i * 8 + 6] = (bvalue & (byte)64) > (byte)0;
204
+            if (remainingBits > 7)
205
+                result[i * 8 + 7] = (bvalue & (byte)-128) > (byte)0;
206
+        }
207
+        return result;
208
+    }
209
+    
210
+    @Override
211
+    public byte[] readByteArray() {
212
+        return this.readBytes();
213
+    }
214
+    
215
+    @Override
216
+    public byte[] readSByteArray() {
217
+        return this.readBytes();
218
+    }
219
+    
220
+    @Override
221
+    public short[] readShortArray() {
222
+        return this.readShortArrayRaw(this.readVarUInt());
223
+    }
224
+    
225
+    @Override
226
+    public short[] readShortArrayRaw(int length) {
227
+        short[] result = new short[length];
228
+        int limitForI = result.length;
229
+        for (int i = 0; i < limitForI; i++)
230
+            result[i] = this.readShort();
231
+        return result;
232
+    }
233
+    
234
+    @Override
235
+    public short[] readUShortArray() {
236
+        return this.readShortArray();
237
+    }
238
+    
239
+    @Override
240
+    public short[] readUShortArrayRaw(int length) {
241
+        return this.readShortArrayRaw(length);
242
+    }
243
+    
244
+    @Override
245
+    public int[] readVarIntArray() {
246
+        return this.readVarIntArrayRaw(this.readVarUInt());
247
+    }
248
+    
249
+    @Override
250
+    public int[] readVarIntArrayRaw(int length) {
251
+        int[] result = new int[length];
252
+        int limitForI = result.length;
253
+        for (int i = 0; i < limitForI; i++)
254
+            result[i] = this.readVarInt();
255
+        return result;
256
+    }
257
+    
258
+    @Override
259
+    public int[] readVarUIntArray() {
260
+        return this.readVarUIntArrayRaw(this.readVarUInt());
261
+    }
262
+    
263
+    @Override
264
+    public int[] readVarUIntArrayRaw(int length) {
265
+        int[] result = new int[length];
266
+        int limitForI = result.length;
267
+        for (int i = 0; i < limitForI; i++)
268
+            result[i] = this.readVarUInt();
269
+        return result;
270
+    }
271
+    
272
+    @Override
273
+    public int[] readIntArray() {
274
+        return this.readIntArrayRaw(this.readVarUInt());
275
+    }
276
+    
277
+    @Override
278
+    public int[] readIntArrayRaw(int length) {
279
+        int[] result = new int[length];
280
+        int limitForI = result.length;
281
+        for (int i = 0; i < limitForI; i++)
282
+            result[i] = this.readInt();
283
+        return result;
284
+    }
285
+    
286
+    @Override
287
+    public int[] readUIntArray() {
288
+        return this.readUIntArrayRaw(this.readVarUInt());
289
+    }
290
+    
291
+    @Override
292
+    public int[] readUIntArrayRaw(int length) {
293
+        int[] result = new int[length];
294
+        int limitForI = result.length;
295
+        for (int i = 0; i < limitForI; i++)
296
+            result[i] = this.readUInt();
297
+        return result;
298
+    }
299
+    
300
+    @Override
301
+    public long[] readVarLongArray() {
302
+        return this.readVarLongArrayRaw(this.readVarUInt());
303
+    }
304
+    
305
+    @Override
306
+    public long[] readVarLongArrayRaw(int length) {
307
+        long[] result = new long[length];
308
+        int limitForI = result.length;
309
+        for (int i = 0; i < limitForI; i++)
310
+            result[i] = this.readVarLong();
311
+        return result;
312
+    }
313
+    
314
+    @Override
315
+    public long[] readVarULongArray() {
316
+        return this.readVarULongArrayRaw(this.readVarUInt());
317
+    }
318
+    
319
+    @Override
320
+    public long[] readVarULongArrayRaw(int length) {
321
+        long[] result = new long[length];
322
+        int limitForI = result.length;
323
+        for (int i = 0; i < limitForI; i++)
324
+            result[i] = this.readVarULong();
325
+        return result;
326
+    }
327
+    
328
+    @Override
329
+    public long[] readLongArray() {
330
+        return this.readLongArrayRaw(this.readVarUInt());
331
+    }
332
+    
333
+    @Override
334
+    public long[] readLongArrayRaw(int length) {
335
+        long[] result = new long[length];
336
+        int limitForI = result.length;
337
+        for (int i = 0; i < limitForI; i++)
338
+            result[i] = this.readLong();
339
+        return result;
340
+    }
341
+    
342
+    @Override
343
+    public long[] readULongArray() {
344
+        return this.readLongArray();
345
+    }
346
+    
347
+    @Override
348
+    public long[] readULongArrayRaw(int length) {
349
+        return this.readLongArrayRaw(length);
350
+    }
351
+    
352
+    @Override
353
+    public float[] readFloatArray() {
354
+        return this.readFloatArrayRaw(this.readVarUInt());
355
+    }
356
+    
357
+    @Override
358
+    public float[] readFloatArrayRaw(int length) {
359
+        float[] result = new float[length];
360
+        int limitForI = result.length;
361
+        for (int i = 0; i < limitForI; i++)
362
+            result[i] = this.readFloat();
363
+        return result;
364
+    }
365
+    
366
+    @Override
367
+    public double[] readDoubleArray() {
368
+        return this.readDoubleArrayRaw(this.readVarUInt());
369
+    }
370
+    
371
+    @Override
372
+    public double[] readDoubleArrayRaw(int length) {
373
+        double[] result = new double[length];
374
+        int limitForI = length;
375
+        for (int i = 0; i < limitForI; i++)
376
+            result[i] = this.readDouble();
377
+        return result;
378
+    }
379
+    
380
+    @Override
381
+    public String[] readStringArray() {
382
+        return this.readStringArrayRaw(this.readVarUInt());
383
+    }
384
+    
385
+    @Override
386
+    public String[] readStringArrayRaw(int length) {
387
+        String[] result = new String[length];
388
+        int limitForI = result.length;
389
+        for (int i = 0; i < limitForI; i++)
390
+            result[i] = this.readString();
391
+        return result;
392
+    }
393
+    
394
+    @Override
395
+    public void skip(int bytes) {
396
+        this.offset = offset + bytes;
397
+    }
398
+    
399
+    @Override
400
+    public boolean hasMore() {
401
+        return offset < data.length;
402
+    }
403
+    
404
+    public int getOffset() {
405
+        return offset;
406
+    }
407
+}

+ 497
- 0
Shared/src/main/java/compactio/CompactBytesDataOutput.java View File

@@ -0,0 +1,497 @@
1
+package compactio;
2
+
3
+import java.nio.charset.StandardCharsets;
4
+import java.util.Arrays;
5
+
6
+public final class CompactBytesDataOutput implements CompactDataOutput, AutoCloseable {
7
+    private static final int P6 = 1 << 6;
8
+    private static final int P7 = 1 << 7;
9
+    private static final int P13 = 1 << 13;
10
+    private static final int P14 = 1 << 14;
11
+    private static final int P20 = 1 << 20;
12
+    private static final int P21 = 1 << 21;
13
+    private static final int P27 = 1 << 27;
14
+    private static final int P28 = 1 << 28;
15
+    private static final long P34 = 1L << 34;
16
+    private static final long P35 = 1L << 35;
17
+    private static final long P41 = 1L << 41;
18
+    private static final long P42 = 1L << 42;
19
+    private static final long P48 = 1L << 48;
20
+    private static final long P49 = 1L << 49;
21
+    private static final long P55 = 1L << 55;
22
+    private static final long P56 = 1L << 56;
23
+    private byte[] data = new byte[16];
24
+    private int length = 0;
25
+    
26
+    private void reserve(int bytes) {
27
+        while (length + bytes > data.length)
28
+            this.data = Arrays.copyOf(data, 2 * data.length);
29
+    }
30
+    
31
+    public byte[] asByteArray() {
32
+        return Arrays.copyOf(data, length);
33
+    }
34
+    
35
+    @Override
36
+    public void close() {
37
+    }
38
+    
39
+    @Override
40
+    public void writeBool(boolean value) {
41
+        this.writeByte(value ? 1 : 0);
42
+    }
43
+    
44
+    @Override
45
+    public void writeByte(int value) {
46
+        this.reserve(1);
47
+        data[length++] = (byte)value;
48
+    }
49
+    
50
+    @Override
51
+    public void writeSByte(byte value) {
52
+        this.writeByte(value);
53
+    }
54
+    
55
+    @Override
56
+    public void writeShort(short value) {
57
+        this.writeUShort(value);
58
+    }
59
+    
60
+    @Override
61
+    public void writeUShort(int value) {
62
+        this.reserve(2);
63
+        data[length++] = (byte)(value >> 8);
64
+        data[length++] = (byte)value;
65
+    }
66
+    
67
+    @Override
68
+    public void writeInt(int value) {
69
+        this.writeUInt(value);
70
+    }
71
+    
72
+    @Override
73
+    public void writeUInt(int value) {
74
+        this.reserve(4);
75
+        data[length++] = (byte)(value >>> 24);
76
+        data[length++] = (byte)(value >>> 16);
77
+        data[length++] = (byte)(value >>> 8);
78
+        data[length++] = (byte)value;
79
+    }
80
+    
81
+    @Override
82
+    public void writeLong(long value) {
83
+        this.writeULong(value);
84
+    }
85
+    
86
+    @Override
87
+    public void writeULong(long value) {
88
+        this.reserve(8);
89
+        data[length++] = (byte)(value >>> 56);
90
+        data[length++] = (byte)(value >>> 48);
91
+        data[length++] = (byte)(value >>> 40);
92
+        data[length++] = (byte)(value >>> 32);
93
+        data[length++] = (byte)(value >>> 24);
94
+        data[length++] = (byte)(value >>> 16);
95
+        data[length++] = (byte)(value >>> 8);
96
+        data[length++] = (byte)value;
97
+    }
98
+    
99
+    @Override
100
+    public void writeVarInt(int value) {
101
+        this.writeVarUInt(value < 0 ? (1 - value << 1) + 1 : value << 1);
102
+    }
103
+    
104
+    @Override
105
+    public void writeVarUInt(int value) {
106
+        this.reserve(5);
107
+        if (Integer.compareUnsigned(value, CompactBytesDataOutput.P7) < 0) {
108
+            data[length++] = (byte)(value & 127);
109
+        }
110
+        else
111
+            if (Integer.compareUnsigned(value, CompactBytesDataOutput.P14) < 0) {
112
+                data[length++] = (byte)(value & 127 | 128);
113
+                data[length++] = (byte)(value >>> 7 & 127);
114
+            }
115
+            else
116
+                if (Integer.compareUnsigned(value, CompactBytesDataOutput.P21) < 0) {
117
+                    data[length++] = (byte)(value & 127 | 128);
118
+                    data[length++] = (byte)(value >>> 7 & 127 | 128);
119
+                    data[length++] = (byte)(value >>> 14 & 127);
120
+                }
121
+                else
122
+                    if (Integer.compareUnsigned(value, CompactBytesDataOutput.P28) < 0) {
123
+                        data[length++] = (byte)(value & 127 | 128);
124
+                        data[length++] = (byte)(value >>> 7 & 127 | 128);
125
+                        data[length++] = (byte)(value >>> 14 & 127 | 128);
126
+                        data[length++] = (byte)(value >>> 21 & 127);
127
+                    }
128
+                    else {
129
+                        data[length++] = (byte)(value & 127 | 128);
130
+                        data[length++] = (byte)(value >>> 7 & 127 | 128);
131
+                        data[length++] = (byte)(value >>> 14 & 127 | 128);
132
+                        data[length++] = (byte)(value >>> 21 & 127 | 128);
133
+                        data[length++] = (byte)(value >>> 28 & 127);
134
+                    }
135
+    }
136
+    
137
+    @Override
138
+    public void writeVarLong(long value) {
139
+        this.writeVarULong(value < 0L ? (1L - value << 1) + 1L : value << 1);
140
+    }
141
+    
142
+    @Override
143
+    public void writeVarULong(long value) {
144
+        this.reserve(9);
145
+        if (Long.compareUnsigned(value, CompactBytesDataOutput.P7) < 0) {
146
+            data[length++] = (byte)(value & 127L);
147
+        }
148
+        else
149
+            if (Long.compareUnsigned(value, CompactBytesDataOutput.P14) < 0) {
150
+                data[length++] = (byte)(value & 127L | 128L);
151
+                data[length++] = (byte)(value >>> 7 & 127L);
152
+            }
153
+            else
154
+                if (Long.compareUnsigned(value, CompactBytesDataOutput.P21) < 0) {
155
+                    data[length++] = (byte)(value & 127L | 128L);
156
+                    data[length++] = (byte)(value >>> 7 & 127L | 128L);
157
+                    data[length++] = (byte)(value >>> 14 & 127L);
158
+                }
159
+                else
160
+                    if (Long.compareUnsigned(value, CompactBytesDataOutput.P28) < 0) {
161
+                        data[length++] = (byte)(value & 127L | 128L);
162
+                        data[length++] = (byte)(value >>> 7 & 127L | 128L);
163
+                        data[length++] = (byte)(value >>> 14 & 127L | 128L);
164
+                        data[length++] = (byte)(value >>> 21 & 127L);
165
+                    }
166
+                    else
167
+                        if (Long.compareUnsigned(value, CompactBytesDataOutput.P35) < 0) {
168
+                            data[length++] = (byte)(value & 127L | 128L);
169
+                            data[length++] = (byte)(value >>> 7 & 127L | 128L);
170
+                            data[length++] = (byte)(value >>> 14 & 127L | 128L);
171
+                            data[length++] = (byte)(value >>> 21 & 127L | 128L);
172
+                            data[length++] = (byte)(value >>> 28 & 127L);
173
+                        }
174
+                        else
175
+                            if (Long.compareUnsigned(value, CompactBytesDataOutput.P42) < 0) {
176
+                                data[length++] = (byte)(value & 127L | 128L);
177
+                                data[length++] = (byte)(value >>> 7 & 127L | 128L);
178
+                                data[length++] = (byte)(value >>> 14 & 127L | 128L);
179
+                                data[length++] = (byte)(value >>> 21 & 127L | 128L);
180
+                                data[length++] = (byte)(value >>> 28 & 127L | 128L);
181
+                                data[length++] = (byte)(value >>> 35 & 127L);
182
+                            }
183
+                            else
184
+                                if (Long.compareUnsigned(value, CompactBytesDataOutput.P49) < 0) {
185
+                                    data[length++] = (byte)(value & 127L | 128L);
186
+                                    data[length++] = (byte)(value >>> 7 & 127L | 128L);
187
+                                    data[length++] = (byte)(value >>> 14 & 127L | 128L);
188
+                                    data[length++] = (byte)(value >>> 21 & 127L | 128L);
189
+                                    data[length++] = (byte)(value >>> 28 & 127L | 128L);
190
+                                    data[length++] = (byte)(value >>> 35 & 127L | 128L);
191
+                                    data[length++] = (byte)(value >>> 42 & 127L);
192
+                                }
193
+                                else
194
+                                    if (Long.compareUnsigned(value, CompactBytesDataOutput.P56) < 0) {
195
+                                        data[length++] = (byte)(value & 127L | 128L);
196
+                                        data[length++] = (byte)(value >>> 7 & 127L | 128L);
197
+                                        data[length++] = (byte)(value >>> 14 & 127L | 128L);
198
+                                        data[length++] = (byte)(value >>> 21 & 127L | 128L);
199
+                                        data[length++] = (byte)(value >>> 28 & 127L | 128L);
200
+                                        data[length++] = (byte)(value >>> 35 & 127L | 128L);
201
+                                        data[length++] = (byte)(value >>> 42 & 127L | 128L);
202
+                                        data[length++] = (byte)(value >>> 49 & 127L);
203
+                                    }
204
+                                    else {
205
+                                        data[length++] = (byte)(value & 127L | 128L);
206
+                                        data[length++] = (byte)(value >>> 7 & 127L | 128L);
207
+                                        data[length++] = (byte)(value >>> 14 & 127L | 128L);
208
+                                        data[length++] = (byte)(value >>> 21 & 127L | 128L);
209
+                                        data[length++] = (byte)(value >>> 28 & 127L | 128L);
210
+                                        data[length++] = (byte)(value >>> 35 & 127L | 128L);
211
+                                        data[length++] = (byte)(value >>> 42 & 127L | 128L);
212
+                                        data[length++] = (byte)(value >>> 49 & 127L | 128L);
213
+                                        data[length++] = (byte)(value >>> 56);
214
+                                    }
215
+    }
216
+    
217
+    @Override
218
+    public void writeFloat(float value) {
219
+        this.writeUInt(Float.floatToRawIntBits(value));
220
+    }
221
+    
222
+    @Override
223
+    public void writeDouble(double value) {
224
+        this.writeULong(Double.doubleToRawLongBits(value));
225
+    }
226
+    
227
+    @Override
228
+    public void writeChar(char value) {
229
+        this.writeVarUInt(value);
230
+    }
231
+    
232
+    @Override
233
+    public void writeBytes(byte[] data) {
234
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
235
+            throw new AssertionError("Array length cannot exceed uint limit");
236
+        this.writeVarUInt(data.length);
237
+        this.writeRawBytes(data);
238
+    }
239
+    
240
+    @Override
241
+    public void writeBytes(byte[] data, int offset, int length) {
242
+        if (!(Integer.compareUnsigned(length, -1) < 0))
243
+            throw new AssertionError("Array length cannot exceed uint limit");
244
+        this.writeVarUInt(length);
245
+        this.writeRawBytes(data, offset, length);
246
+    }
247
+    
248
+    @Override
249
+    public void writeString(String str) {
250
+        this.writeBytes(str.getBytes(StandardCharsets.UTF_8));
251
+    }
252
+    
253
+    @Override
254
+    public void writeRawBytes(byte[] value) {
255
+        this.reserve(value.length);
256
+        System.arraycopy(value, 0, data, length, value.length);
257
+        this.length = length + value.length;
258
+    }
259
+    
260
+    @Override
261
+    public void writeRawBytes(byte[] value, int offset, int length) {
262
+        this.reserve(value.length);
263
+        System.arraycopy(value, offset, data, this.length, value.length);
264
+        this.length = this.length + length;
265
+    }
266
+    
267
+    @Override
268
+    public void writeBoolArray(boolean[] data) {
269
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
270
+            throw new AssertionError("Array length cannot exceed uint limit");
271
+        this.writeVarUInt(data.length);
272
+        int i = 0;
273
+        while (i < data.length - 7) {
274
+            int bvalue = 0;
275
+            if (data[i + 0])
276
+                bvalue = bvalue | 1;
277
+            if (data[i + 1])
278
+                bvalue = bvalue | 2;
279
+            if (data[i + 2])
280
+                bvalue = bvalue + 4;
281
+            if (data[i + 3])
282
+                bvalue = bvalue + 8;
283
+            if (data[i + 4])
284
+                bvalue = bvalue + 16;
285
+            if (data[i + 5])
286
+                bvalue = bvalue + 32;
287
+            if (data[i + 6])
288
+                bvalue = bvalue + 64;
289
+            if (data[i + 7])
290
+                bvalue = bvalue + 128;
291
+            this.writeByte(bvalue);
292
+            i = i + 8;
293
+        }
294
+        if (i < data.length) {
295
+            int bvalue = 0;
296
+            int limitForOffset = data.length % 7;
297
+            for (int offset = 0; offset < limitForOffset; offset++)
298
+                if (data[i + offset])
299
+                    bvalue = bvalue + (1 << i);
300
+            this.writeByte(bvalue);
301
+        }
302
+    }
303
+    
304
+    @Override
305
+    public void writeByteArray(byte[] data) {
306
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
307
+            throw new AssertionError("Array length cannot exceed uint limit");
308
+        this.writeBytes(data);
309
+    }
310
+    
311
+    @Override
312
+    public void writeSByteArray(byte[] data) {
313
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
314
+            throw new AssertionError("Array length cannot exceed uint limit");
315
+        this.writeBytes(data);
316
+    }
317
+    
318
+    @Override
319
+    public void writeShortArray(short[] data) {
320
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
321
+            throw new AssertionError("Array length cannot exceed uint limit");
322
+        this.writeVarUInt(data.length);
323
+        this.writeShortArrayRaw(data);
324
+    }
325
+    
326
+    @Override
327
+    public void writeShortArrayRaw(short[] data) {
328
+        for (short element : data)
329
+            this.writeShort(element);
330
+    }
331
+    
332
+    @Override
333
+    public void writeUShortArray(short[] data) {
334
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
335
+            throw new AssertionError("Array length cannot exceed uint limit");
336
+        this.writeShortArray(data);
337
+    }
338
+    
339
+    @Override
340
+    public void writeUShortArrayRaw(short[] data) {
341
+        this.writeShortArrayRaw(data);
342
+    }
343
+    
344
+    @Override
345
+    public void writeVarIntArray(int[] data) {
346
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
347
+            throw new AssertionError("Array length cannot exceed uint limit");
348
+        this.writeVarUInt(data.length);
349
+        this.writeVarIntArrayRaw(data);
350
+    }
351
+    
352
+    @Override
353
+    public void writeVarIntArrayRaw(int[] data) {
354
+        for (int element : data)
355
+            this.writeVarInt(element);
356
+    }
357
+    
358
+    @Override
359
+    public void writeVarUIntArray(int[] data) {
360
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
361
+            throw new AssertionError("Array length cannot exceed uint limit");
362
+        this.writeVarUInt(data.length);
363
+        this.writeVarUIntArrayRaw(data);
364
+    }
365
+    
366
+    @Override
367
+    public void writeVarUIntArrayRaw(int[] data) {
368
+        for (int element : data)
369
+            this.writeVarUInt(element);
370
+    }
371
+    
372
+    @Override
373
+    public void writeIntArray(int[] data) {
374
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
375
+            throw new AssertionError("Array length cannot exceed uint limit");
376
+        this.writeVarUInt(data.length);
377
+        this.writeIntArrayRaw(data);
378
+    }
379
+    
380
+    @Override
381
+    public void writeIntArrayRaw(int[] data) {
382
+        for (int element : data)
383
+            this.writeInt(element);
384
+    }
385
+    
386
+    @Override
387
+    public void writeUIntArray(int[] data) {
388
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
389
+            throw new AssertionError("Array length cannot exceed uint limit");
390
+        this.writeIntArray(data);
391
+    }
392
+    
393
+    @Override
394
+    public void writeUIntArrayRaw(int[] data) {
395
+        this.writeIntArrayRaw(data);
396
+    }
397
+    
398
+    @Override
399
+    public void writeVarLongArray(long[] data) {
400
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
401
+            throw new AssertionError("Array length cannot exceed uint limit");
402
+        this.writeVarUInt(data.length);
403
+        this.writeVarLongArrayRaw(data);
404
+    }
405
+    
406
+    @Override
407
+    public void writeVarLongArrayRaw(long[] data) {
408
+        for (long element : data)
409
+            this.writeVarLong(element);
410
+    }
411
+    
412
+    @Override
413
+    public void writeVarULongArray(long[] data) {
414
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
415
+            throw new AssertionError("Array length cannot exceed uint limit");
416
+        this.writeVarUInt(data.length);
417
+        this.writeVarULongArrayRaw(data);
418
+    }
419
+    
420
+    @Override
421
+    public void writeVarULongArrayRaw(long[] data) {
422
+        for (long element : data)
423
+            this.writeVarULong(element);
424
+    }
425
+    
426
+    @Override
427
+    public void writeLongArray(long[] data) {
428
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
429
+            throw new AssertionError("Array length cannot exceed uint limit");
430
+        this.writeVarUInt(data.length);
431
+        this.writeLongArrayRaw(data);
432
+    }
433
+    
434
+    @Override
435
+    public void writeLongArrayRaw(long[] data) {
436
+        for (long element : data)
437
+            this.writeLong(element);
438
+    }
439
+    
440
+    @Override
441
+    public void writeULongArray(long[] data) {
442
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
443
+            throw new AssertionError("Array length cannot exceed uint limit");
444
+        this.writeLongArray(data);
445
+    }
446
+    
447
+    @Override
448
+    public void writeULongArrayRaw(long[] data) {
449
+        this.writeLongArrayRaw(data);
450
+    }
451
+    
452
+    @Override
453
+    public void writeFloatArray(float[] data) {
454
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
455
+            throw new AssertionError("Array length cannot exceed uint limit");
456
+        this.writeVarUInt(data.length);
457
+        this.writeFloatArrayRaw(data);
458
+    }
459
+    
460
+    @Override
461
+    public void writeFloatArrayRaw(float[] data) {
462
+        for (float element : data)
463
+            this.writeFloat(element);
464
+    }
465
+    
466
+    @Override
467
+    public void writeDoubleArray(double[] data) {
468
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
469
+            throw new AssertionError("Array length cannot exceed uint limit");
470
+        this.writeVarUInt(data.length);
471
+        this.writeDoubleArrayRaw(data);
472
+    }
473
+    
474
+    @Override
475
+    public void writeDoubleArrayRaw(double[] data) {
476
+        for (double element : data)
477
+            this.writeDouble(element);
478
+    }
479
+    
480
+    @Override
481
+    public void writeStringArray(String[] data) {
482
+        if (!(Integer.compareUnsigned(data.length, -1) < 0))
483
+            throw new AssertionError("Array length cannot exceed uint limit");
484
+        this.writeVarUInt(data.length);
485
+        this.writeStringArrayRaw(data);
486
+    }
487
+    
488
+    @Override
489
+    public void writeStringArrayRaw(String[] data) {
490
+        for (String element : data)
491
+            this.writeString(element);
492
+    }
493
+    
494
+    @Override
495
+    public void flush() {
496
+    }
497
+}

+ 106
- 0
Shared/src/main/java/compactio/CompactDataInput.java View File

@@ -0,0 +1,106 @@
1
+package compactio;
2
+
3
+public interface CompactDataInput extends AutoCloseable {
4
+    boolean readBool();
5
+    
6
+    byte readByte();
7
+    
8
+    int readSByte();
9
+    
10
+    short readShort();
11
+    
12
+    int readUShort();
13
+    
14
+    int readInt();
15
+    
16
+    int readUInt();
17
+    
18
+    long readLong();
19
+    
20
+    long readULong();
21
+    
22
+    int readVarInt();
23
+    
24
+    int readVarUInt();
25
+    
26
+    long readVarLong();
27
+    
28
+    long readVarULong();
29
+    
30
+    float readFloat();
31
+    
32
+    double readDouble();
33
+    
34
+    char readChar();
35
+    
36
+    String readString();
37
+    
38
+    byte[] readBytes();
39
+    
40
+    byte[] readRawBytes(int length);
41
+    
42
+    boolean[] readBoolArray();
43
+    
44
+    byte[] readByteArray();
45
+    
46
+    byte[] readSByteArray();
47
+    
48
+    short[] readShortArray();
49
+    
50
+    short[] readShortArrayRaw(int length);
51
+    
52
+    short[] readUShortArray();
53
+    
54
+    short[] readUShortArrayRaw(int length);
55
+    
56
+    int[] readVarIntArray();
57
+    
58
+    int[] readVarIntArrayRaw(int length);
59
+    
60
+    int[] readVarUIntArray();
61
+    
62
+    int[] readVarUIntArrayRaw(int length);
63
+    
64
+    int[] readIntArray();
65
+    
66
+    int[] readIntArrayRaw(int length);
67
+    
68
+    int[] readUIntArray();
69
+    
70
+    int[] readUIntArrayRaw(int length);
71
+    
72
+    long[] readVarLongArray();
73
+    
74
+    long[] readVarLongArrayRaw(int length);
75
+    
76
+    long[] readVarULongArray();
77
+    
78
+    long[] readVarULongArrayRaw(int length);
79
+    
80
+    long[] readLongArray();
81
+    
82
+    long[] readLongArrayRaw(int length);
83
+    
84
+    long[] readULongArray();
85
+    
86
+    long[] readULongArrayRaw(int length);
87
+    
88
+    float[] readFloatArray();
89
+    
90
+    float[] readFloatArrayRaw(int length);
91
+    
92
+    double[] readDoubleArray();
93
+    
94
+    double[] readDoubleArrayRaw(int length);
95
+    
96
+    String[] readStringArray();
97
+    
98
+    String[] readStringArrayRaw(int length);
99
+    
100
+    void skip(int bytes);
101
+    
102
+    boolean hasMore();
103
+    
104
+    @Override
105
+    public void close();
106
+}

+ 108
- 0
Shared/src/main/java/compactio/CompactDataOutput.java View File

@@ -0,0 +1,108 @@
1
+package compactio;
2
+
3
+public interface CompactDataOutput extends AutoCloseable {
4
+    void writeBool(boolean value);
5
+    
6
+    void writeByte(int value);
7
+    
8
+    void writeSByte(byte value);
9
+    
10
+    void writeShort(short value);
11
+    
12
+    void writeUShort(int value);
13
+    
14
+    void writeInt(int value);
15
+    
16
+    void writeUInt(int value);
17
+    
18
+    void writeLong(long value);
19
+    
20
+    void writeULong(long value);
21
+    
22
+    void writeVarInt(int value);
23
+    
24
+    void writeVarUInt(int value);
25
+    
26
+    void writeVarLong(long value);
27
+    
28
+    void writeVarULong(long value);
29
+    
30
+    void writeFloat(float value);
31
+    
32
+    void writeDouble(double value);
33
+    
34
+    void writeChar(char value);
35
+    
36
+    void writeString(String value);
37
+    
38
+    void writeBytes(byte[] data);
39
+    
40
+    void writeBytes(byte[] data, int offset, int length);
41
+    
42
+    void writeRawBytes(byte[] value);
43
+    
44
+    void writeRawBytes(byte[] value, int offset, int length);
45
+    
46
+    void writeBoolArray(boolean[] data);
47
+    
48
+    void writeByteArray(byte[] data);
49
+    
50
+    void writeSByteArray(byte[] data);
51
+    
52
+    void writeShortArray(short[] data);
53
+    
54
+    void writeShortArrayRaw(short[] data);
55
+    
56
+    void writeUShortArray(short[] data);
57
+    
58
+    void writeUShortArrayRaw(short[] data);
59
+    
60
+    void writeVarIntArray(int[] data);
61
+    
62
+    void writeVarIntArrayRaw(int[] data);
63
+    
64
+    void writeVarUIntArray(int[] data);
65
+    
66
+    void writeVarUIntArrayRaw(int[] data);
67
+    
68
+    void writeIntArray(int[] data);
69
+    
70
+    void writeIntArrayRaw(int[] data);
71
+    
72
+    void writeUIntArray(int[] data);
73
+    
74
+    void writeUIntArrayRaw(int[] data);
75
+    
76
+    void writeVarLongArray(long[] data);
77
+    
78
+    void writeVarLongArrayRaw(long[] data);
79
+    
80
+    void writeVarULongArray(long[] data);
81
+    
82
+    void writeVarULongArrayRaw(long[] data);
83
+    
84
+    void writeLongArray(long[] data);
85
+    
86
+    void writeLongArrayRaw(long[] data);
87
+    
88
+    void writeULongArray(long[] data);
89
+    
90
+    void writeULongArrayRaw(long[] data);
91
+    
92
+    void writeFloatArray(float[] data);
93
+    
94
+    void writeFloatArrayRaw(float[] data);
95
+    
96
+    void writeDoubleArray(double[] data);
97
+    
98
+    void writeDoubleArrayRaw(double[] data);
99
+    
100
+    void writeStringArray(String[] data);
101
+    
102
+    void writeStringArrayRaw(String[] data);
103
+    
104
+    void flush();
105
+    
106
+    @Override
107
+    public void close();
108
+}

+ 6
- 0
Shared/src/main/java/zsynthetic/FunctionUSizeTToBool.java View File

@@ -0,0 +1,6 @@
1
+package zsynthetic;
2
+
3
+@FunctionalInterface
4
+public interface FunctionUSizeTToBool<T> {
5
+    boolean invoke(int index, T value);
6
+}

+ 6
- 0
Shared/src/main/java/zsynthetic/FunctionUSizeTToU.java View File

@@ -0,0 +1,6 @@
1
+package zsynthetic;
2
+
3
+@FunctionalInterface
4
+public interface FunctionUSizeTToU<U, T> {
5
+    U invoke(int index, T value);
6
+}

+ 6
- 0
Shared/src/main/java/zsynthetic/FunctionUSizeTToVoid.java View File

@@ -0,0 +1,6 @@
1
+package zsynthetic;
2
+
3
+@FunctionalInterface
4
+public interface FunctionUSizeTToVoid<T> {
5
+    void invoke(int index, T value);
6
+}

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

@@ -13,7 +13,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14 14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 15
 import org.openzen.zenscript.codemodel.Modifiers;
16
-import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
16
+import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
17 17
 import org.openzen.zenscript.codemodel.generic.GenericParameterBoundVisitor;
18 18
 import org.openzen.zenscript.codemodel.generic.ParameterSuperBound;
19 19
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
@@ -178,7 +178,7 @@ public class ValidationUtils {
178 178
 		
179 179
 		for (int i = 0; i < typeParameters.length; i++) {
180 180
 			TypeParameter typeParameter = typeParameters[i];
181
-			for (GenericParameterBound bound : typeParameter.bounds) {
181
+			for (TypeParameterBound bound : typeParameter.bounds) {
182 182
 				// TODO - obtain member cache for validation
183 183
 				/*if (!bound.matches(typeArguments[i])) {
184 184
 					target.logError(

Loading…
Cancel
Save