Stan Hebben 6 лет назад
Родитель
Сommit
e0e6b5be3f
100 измененных файлов: 1252 добавлений и 347 удалений
  1. 6
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  2. 45
    6
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java
  3. 2
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  4. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/GenericMapper.java
  5. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionAnnotationDefinition.java
  6. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingPackage.java
  7. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingType.java
  8. 11
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/FileResolutionContext.java
  9. 9
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java
  10. 19
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/ModuleTypeResolutionContext.java
  11. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/TypeContext.java
  12. 4
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/TypeResolutionContext.java
  13. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  14. 10
    9
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  15. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java
  16. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java
  17. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  18. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitorWithContext.java
  19. 46
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StorageCastExpression.java
  20. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java
  21. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinition.java
  22. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IteratorMember.java
  23. 1
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java
  24. 8
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java
  25. 11
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java
  26. 18
    12
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java
  27. 8
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java
  28. 11
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java
  29. 8
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java
  30. 10
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java
  31. 10
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java
  32. 8
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java
  33. 11
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java
  34. 8
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java
  35. 8
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java
  36. 0
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/StatementScope.java
  37. 57
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java
  38. 30
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java
  39. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java
  40. 55
    32
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java
  41. 27
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java
  42. 31
    16
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java
  43. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericName.java
  44. 26
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java
  45. 47
    48
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  46. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ISymbol.java
  47. 10
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java
  48. 27
    8
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java
  49. 24
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ModifiedTypeID.java
  50. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java
  51. 48
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StringTypeID.java
  52. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeParameterCollector.java
  53. 4
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeSymbol.java
  54. 16
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/UnstoredTypeID.java
  55. 25
    21
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  56. 41
    18
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  57. 15
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/AnyStorageTag.java
  58. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/AnyStorageType.java
  59. 16
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/BorrowStorageTag.java
  60. 21
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/BorrowStorageType.java
  61. 15
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageTag.java
  62. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageType.java
  63. 15
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StaticStorageTag.java
  64. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StaticStorageType.java
  65. 4
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StorageTag.java
  66. 14
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StorageType.java
  67. 15
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/UniqueStorageTag.java
  68. 17
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/UniqueStorageType.java
  69. 31
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/ValueStorageTag.java
  70. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/ValueStorageType.java
  71. 18
    4
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java
  72. 8
    1
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java
  73. 8
    3
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  74. 2
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  75. 0
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java
  76. 6
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaBoxingTypeVisitor.java
  77. 36
    15
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  78. 5
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  79. 5
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  80. 2
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  81. 2
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java
  82. 8
    8
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java
  83. 11
    6
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java
  84. 5
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java
  85. 7
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeGenericVisitor.java
  86. 7
    7
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInfo.java
  87. 5
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java
  88. 6
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeNameVisitor.java
  89. 6
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java
  90. 3
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  91. 2
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java
  92. 2
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  93. 26
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  94. 0
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java
  95. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java
  96. 6
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticHelperGenerator.java
  97. 9
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java
  98. 2
    1
      ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/CodeReader.java
  99. 8
    2
      ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/DeserializingModule.java
  100. 0
    0
      ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/Main.java

+ 6
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java Просмотреть файл

@@ -70,6 +70,7 @@ import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
70 70
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
71 71
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
72 72
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
73
+import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
73 74
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
74 75
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
75 76
 import org.openzen.zenscript.codemodel.expression.ThrowExpression;
@@ -660,6 +661,11 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
660 661
 				ZenScriptOperator.ASSIGN);
661 662
 	}
662 663
 	
664
+	@Override
665
+	public ExpressionString visitStorageCast(StorageCastExpression expression) {
666
+		return expression.value.accept(this);
667
+	}
668
+	
663 669
 	@Override
664 670
 	public ExpressionString visitSupertypeCast(SupertypeCastExpression expression) {
665 671
 		return expression.value.accept(this);

+ 45
- 6
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java Просмотреть файл

@@ -21,6 +21,7 @@ import org.openzen.zenscript.codemodel.type.GenericTypeID;
21 21
 import org.openzen.zenscript.codemodel.type.ITypeID;
22 22
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
23 23
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
24
+import org.openzen.zenscript.codemodel.type.StringTypeID;
24 25
 import stdlib.Chars;
25 26
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
26 27
 
@@ -41,20 +42,37 @@ public class TypeFormatter implements TypeVisitor<String>, GenericParameterBound
41 42
 	public String visitBasic(BasicTypeID basic) {
42 43
 		return basic.name;
43 44
 	}
45
+	
46
+	@Override
47
+	public String visitString(StringTypeID string) {
48
+		if (string.storage == null)
49
+			return "string";
50
+		else
51
+			return "string`" + string.storage.toString();
52
+	}
44 53
 
45 54
 	@Override
46 55
 	public String visitArray(ArrayTypeID array) {
47 56
 		String element = array.elementType.accept(this);
57
+		String result;
48 58
 		if (array.dimension == 1) {
49
-			return element + "[]";
59
+			result = element + "[]";
50 60
 		} else {
51
-			return element + "[" + Chars.times(',', array.dimension - 1) + "]";
61
+			result = element + "[" + Chars.times(',', array.dimension - 1) + "]";
52 62
 		}
63
+		if (array.storage == null)
64
+			return result;
65
+		
66
+		return result + '`' + array.storage.toString();
53 67
 	}
54 68
 
55 69
 	@Override
56 70
 	public String visitAssoc(AssocTypeID assoc) {
57
-		return assoc.valueType.accept(this) + "[" + assoc.keyType.accept(this) + "]";
71
+		String result = assoc.valueType.accept(this) + "[" + assoc.keyType.accept(this) + "]";
72
+		if (assoc.storage == null)
73
+			return result;
74
+		
75
+		return result + '`' + assoc.storage.toString();
58 76
 	}
59 77
 
60 78
 	@Override
@@ -67,32 +85,47 @@ public class TypeFormatter implements TypeVisitor<String>, GenericParameterBound
67 85
 		StringBuilder result = new StringBuilder();
68 86
 		result.append("function");
69 87
 		FormattingUtils.formatHeader(result, settings, function.header, this);
88
+		
89
+		if (function.storage != null) {
90
+			result.append('`');
91
+			result.append(function.storage.toString());
92
+		}
93
+		
70 94
 		return result.toString();
71 95
 	}
72 96
 
73 97
 	@Override
74 98
 	public String visitDefinition(DefinitionTypeID definition) {
75 99
 		String importedName = importer.importDefinition(definition.definition);
76
-		if (definition.typeParameters == null)
100
+		if (definition.typeArguments == null)
77 101
 			return importedName;
78 102
 		
79 103
 		StringBuilder result = new StringBuilder();
80 104
 		result.append(importedName);
81 105
 		result.append("<");
82 106
 		int index = 0;
83
-		for (ITypeID typeParameter : definition.typeParameters) {
107
+		for (ITypeID typeParameter : definition.typeArguments) {
84 108
 			if (index > 0)
85 109
 				result.append(", ");
86 110
 			
87 111
 			result.append(typeParameter.accept(this));
88 112
 		}
89 113
 		result.append(">");
114
+		
115
+		if (definition.storage != null) {
116
+			result.append('`');
117
+			result.append(definition.storage.toString());
118
+		}
119
+		
90 120
 		return result.toString();
91 121
 	}
92 122
 
93 123
 	@Override
94 124
 	public String visitGeneric(GenericTypeID generic) {
95
-		return generic.parameter.name;
125
+		if (generic.storage == null)
126
+			return generic.parameter.name;
127
+		
128
+		return generic.parameter.name + '`' + generic.storage.toString();
96 129
 	}
97 130
 
98 131
 	@Override
@@ -131,6 +164,12 @@ public class TypeFormatter implements TypeVisitor<String>, GenericParameterBound
131 164
 		result.append("[<");
132 165
 		FormattingUtils.formatTypeParameters(result, new TypeParameter[] { map.key }, this);
133 166
 		result.append("]>");
167
+		
168
+		if (map.storage != null) {
169
+			result.append('`');
170
+			result.append(map.storage.toString());
171
+		}
172
+		
134 173
 		return result.toString();
135 174
 	}
136 175
 }

+ 2
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Просмотреть файл

@@ -23,8 +23,6 @@ import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23 23
  * @author Hoofdgebruiker
24 24
  */
25 25
 public class FunctionHeader {
26
-	private static final FunctionParameter[] NO_PARAMETERS = new FunctionParameter[0];
27
-	
28 26
 	public final TypeParameter[] typeParameters;
29 27
 	private ITypeID returnType;
30 28
 	public final FunctionParameter[] parameters;
@@ -40,7 +38,7 @@ public class FunctionHeader {
40 38
 		
41 39
 		this.typeParameters = TypeParameter.NONE;
42 40
 		this.returnType = returnType;
43
-		this.parameters = NO_PARAMETERS;
41
+		this.parameters = FunctionParameter.NONE;
44 42
 		this.thrownType = null;
45 43
 		
46 44
 		minParameters = 0;
@@ -357,7 +355,7 @@ public class FunctionHeader {
357 355
 		if (typeParameters.length > 0) {
358 356
 			Map<TypeParameter, ITypeID> innerMap = new HashMap<>();
359 357
 			for (TypeParameter parameter : typeParameters)
360
-				innerMap.put(parameter, mapper.registry.getGeneric(parameter));
358
+				innerMap.put(parameter, mapper.registry.getGeneric(parameter, null));
361 359
 			
362 360
 			mapper = mapper.getInner(registry, innerMap);
363 361
 		}

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/GenericMapper.java Просмотреть файл

@@ -50,7 +50,7 @@ public class GenericMapper {
50 50
 		if (!mapping.containsKey(type.parameter))
51 51
 			throw new IllegalStateException("No mapping found for type " + type);
52 52
 		
53
-		return mapping.containsKey(type.parameter) ? mapping.get(type.parameter) : type;
53
+		return mapping.containsKey(type.parameter) ? mapping.get(type.parameter).withStorage(registry, type.storage) : type;
54 54
 	}
55 55
 	
56 56
 	public FunctionHeader map(FunctionHeader original) {
@@ -66,7 +66,7 @@ public class GenericMapper {
66 66
 	public GenericMapper getInner(GlobalTypeRegistry registry, TypeParameter[] parameters) {
67 67
 		Map<TypeParameter, ITypeID> resultMap = new HashMap<>(this.mapping);
68 68
 		for (TypeParameter parameter : parameters)
69
-			resultMap.put(parameter, registry.getGeneric(parameter));
69
+			resultMap.put(parameter, registry.getGeneric(parameter, null));
70 70
 		return new GenericMapper(registry, resultMap);
71 71
 	}
72 72
 	

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionAnnotationDefinition.java Просмотреть файл

@@ -28,6 +28,7 @@ import org.openzen.zenscript.codemodel.statement.Statement;
28 28
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
29 29
 import org.openzen.zenscript.codemodel.type.GenericName;
30 30
 import org.openzen.zenscript.codemodel.type.StringTypeID;
31
+import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
31 32
 
32 33
 /**
33 34
  *
@@ -51,7 +52,7 @@ public class PreconditionAnnotationDefinition implements AnnotationDefinition {
51 52
 	public List<FunctionHeader> getInitializers(BaseScope scope) {
52 53
 		return Collections.singletonList(new FunctionHeader(
53 54
 				BasicTypeID.VOID,
54
-				scope.getType(CodePosition.BUILTIN, enforcementLevelName),
55
+				scope.getType(CodePosition.BUILTIN, enforcementLevelName, StaticStorageTag.INSTANCE),
55 56
 				BasicTypeID.BOOL,
56 57
 				StringTypeID.UNIQUE));
57 58
 	}

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingPackage.java Просмотреть файл

@@ -84,7 +84,7 @@ public class CompilingPackage {
84 84
 		
85 85
 		if (types.containsKey(name.get(index).name)) {
86 86
 			CompilingType type = types.get(name.get(index).name);
87
-			DefinitionTypeID result = context.getTypeRegistry().getForDefinition(type.load(), name.get(index).arguments);
87
+			DefinitionTypeID result = context.getTypeRegistry().getForDefinition(type.load(), null, name.get(index).arguments);
88 88
 			return getInner(context, name, index + 1, type, result);
89 89
 		}
90 90
 		
@@ -99,7 +99,7 @@ public class CompilingPackage {
99 99
 		if (innerType == null)
100 100
 			return null;
101 101
 		
102
-		DefinitionTypeID innerResult = context.getTypeRegistry().getForDefinition(innerType.load(), name.get(index).arguments, result);
102
+		DefinitionTypeID innerResult = context.getTypeRegistry().getForDefinition(innerType.load(), name.get(index).arguments, result, null);
103 103
 		return getInner(context, name, index + 1, innerType, innerResult);
104 104
 	}
105 105
 }

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingType.java Просмотреть файл

@@ -21,7 +21,7 @@ public interface CompilingType {
21 21
 	HighLevelDefinition load();
22 22
 	
23 23
 	default DefinitionTypeID getInnerType(GlobalTypeRegistry registry, List<GenericName> name, int index, DefinitionTypeID outer) {
24
-		DefinitionTypeID type = registry.getForDefinition(load(), name.get(index).arguments, outer);
24
+		DefinitionTypeID type = registry.getForDefinition(load(), name.get(index).arguments, outer, null);
25 25
 		index++;
26 26
 		if (index == name.size())
27 27
 			return type;

+ 11
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/FileResolutionContext.java Просмотреть файл

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14 14
 import org.openzen.zenscript.codemodel.type.GenericName;
15 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
17 18
 
18 19
 /**
19 20
  *
@@ -44,20 +45,26 @@ public class FileResolutionContext implements TypeResolutionContext {
44 45
 	}
45 46
 
46 47
 	@Override
47
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
48
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
48 49
 		if (imports.containsKey(name.get(0).name)) {
49 50
 			return GenericName.getInnerType(
50 51
 					getTypeRegistry(),
51
-					getTypeRegistry().getForDefinition(imports.get(name.get(0).name), name.get(0).arguments),
52
+					getTypeRegistry().getForDefinition(imports.get(name.get(0).name), null, name.get(0).arguments),
52 53
 					name,
53
-					1);
54
+					1,
55
+					storage);
54 56
 		}
55 57
 		
56 58
 		ITypeID moduleType = modulePackage.getType(this, name);
57 59
 		if (moduleType != null)
58 60
 			return moduleType;
59 61
 		
60
-		return module.getType(position, name);
62
+		return module.getType(position, name, storage);
63
+	}
64
+	
65
+	@Override
66
+	public StorageTag getStorageTag(CodePosition position, String name, String[] arguments) {
67
+		return module.getStorageTag(position, name, arguments);
61 68
 	}
62 69
 
63 70
 	@Override

+ 9
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java Просмотреть файл

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13 13
 import org.openzen.zenscript.codemodel.type.GenericName;
14 14
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
16 17
 
17 18
 /**
18 19
  *
@@ -40,7 +41,7 @@ public class LocalTypeResolutionContext implements TypeResolutionContext {
40 41
 	}
41 42
 
42 43
 	@Override
43
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
44
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
44 45
 		if (type != null) {
45 46
 			CompilingType compiling = type.getInner(name.get(0).name);
46 47
 			if (compiling != null) {
@@ -52,10 +53,15 @@ public class LocalTypeResolutionContext implements TypeResolutionContext {
52 53
 		if (name.size() == 1 && name.get(0).hasNoArguments()) {
53 54
 			for (TypeParameter parameter : parameters)
54 55
 				if (parameter.name.equals(name.get(0).name))
55
-					return getTypeRegistry().getGeneric(parameter);
56
+					return getTypeRegistry().getGeneric(parameter, storage);
56 57
 		}
57 58
 		
58
-		return outer.getType(position, name);
59
+		return outer.getType(position, name, storage);
60
+	}
61
+
62
+	@Override
63
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
64
+		return outer.getStorageTag(position, name, parameters);
59 65
 	}
60 66
 	
61 67
 	@Override

+ 19
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/ModuleTypeResolutionContext.java Просмотреть файл

@@ -9,12 +9,16 @@ import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13
+import org.openzen.zencode.shared.CompileExceptionCode;
12 14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13 15
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
14 16
 import org.openzen.zenscript.codemodel.type.GenericName;
15 17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16 18
 import org.openzen.zenscript.codemodel.type.ISymbol;
17 19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
21
+import org.openzen.zenscript.codemodel.type.storage.StorageType;
18 22
 
19 23
 /**
20 24
  *
@@ -23,6 +27,7 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
23 27
 public class ModuleTypeResolutionContext implements TypeResolutionContext {
24 28
 	private final GlobalTypeRegistry registry;
25 29
 	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
30
+	private final Map<String, StorageType> storageTypes = new HashMap<>();
26 31
 	private final Map<String, ISymbol> globals;
27 32
 	private final ZSPackage rootPackage;
28 33
 	
@@ -31,6 +36,7 @@ public class ModuleTypeResolutionContext implements TypeResolutionContext {
31 36
 	public ModuleTypeResolutionContext(
32 37
 			GlobalTypeRegistry registry,
33 38
 			AnnotationDefinition[] annotations,
39
+			StorageType[] storageTypes,
34 40
 			ZSPackage rootPackage,
35 41
 			CompilingPackage rootCompiling,
36 42
 			Map<String, ISymbol> globals)
@@ -42,6 +48,8 @@ public class ModuleTypeResolutionContext implements TypeResolutionContext {
42 48
 		
43 49
 		for (AnnotationDefinition annotation : annotations)
44 50
 			this.annotations.put(annotation.getAnnotationName(), annotation);
51
+		for (StorageType storageType : storageTypes)
52
+			this.storageTypes.put(storageType.getName(), storageType);
45 53
 	}
46 54
 	
47 55
 	@Override
@@ -55,7 +63,7 @@ public class ModuleTypeResolutionContext implements TypeResolutionContext {
55 63
 	}
56 64
 
57 65
 	@Override
58
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
66
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
59 67
 		if (rootCompiling != null) {
60 68
 			ITypeID compiling = rootCompiling.getType(this, name);
61 69
 			if (compiling != null)
@@ -63,9 +71,17 @@ public class ModuleTypeResolutionContext implements TypeResolutionContext {
63 71
 		}
64 72
 		
65 73
 		if (name.size() == 1 && globals.containsKey(name.get(0).name))
66
-			return globals.get(name.get(0).name).getType(position, this, name.get(0).arguments);
74
+			return globals.get(name.get(0).name).getType(position, this, name.get(0).arguments, storage);
67 75
 		
68
-		return rootPackage.getType(position, this, name);
76
+		return rootPackage.getType(position, this, name, storage);
77
+	}
78
+	
79
+	@Override
80
+	public StorageTag getStorageTag(CodePosition position, String name, String[] arguments) {
81
+		if (!storageTypes.containsKey(name))
82
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_STORAGE_TYPE, "No such storage type: " + name);
83
+		
84
+		return storageTypes.get(name).instance(position, arguments);
69 85
 	}
70 86
 	
71 87
 	@Override

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/TypeContext.java Просмотреть файл

@@ -62,7 +62,7 @@ public class TypeContext {
62 62
 	public GenericMapper getMapper() {
63 63
 		Map<TypeParameter, ITypeID> mapper = new HashMap<>();
64 64
 		for (TypeParameter parameter : typeParameters)
65
-			mapper.put(parameter, moduleContext.registry.getGeneric(parameter));
65
+			mapper.put(parameter, moduleContext.registry.getGeneric(parameter, null));
66 66
 		return new GenericMapper(moduleContext.registry, mapper);
67 67
 	}
68 68
 	

+ 4
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/TypeResolutionContext.java Просмотреть файл

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11 11
 import org.openzen.zenscript.codemodel.type.GenericName;
12 12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14 15
 
15 16
 /**
16 17
  *
@@ -21,7 +22,9 @@ public interface TypeResolutionContext {
21 22
 	
22 23
 	AnnotationDefinition getAnnotation(String name);
23 24
 	
24
-	ITypeID getType(CodePosition position, List<GenericName> name);
25
+	ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage);
26
+	
27
+	StorageTag getStorageTag(CodePosition position, String name, String[] parameters);
25 28
 	
26 29
 	ITypeID getThisType();
27 30
 }

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java Просмотреть файл

@@ -41,7 +41,7 @@ public class FunctionDefinition extends HighLevelDefinition {
41 41
 	public void setHeader(GlobalTypeRegistry registry, FunctionHeader header) {
42 42
 		this.header = header;
43 43
 		addMember(caller = new CallerMember(position, this, modifiers | Modifiers.STATIC, header, null));
44
-		callerGroup.addMethod(new FunctionalMemberRef(caller, registry.getFunction(header), GenericMapper.EMPTY), TypeMemberPriority.SPECIFIED);
44
+		callerGroup.addMethod(new FunctionalMemberRef(caller, registry.getFunction(header, null), GenericMapper.EMPTY), TypeMemberPriority.SPECIFIED);
45 45
 	}
46 46
 	
47 47
 	public void setCode(Statement statement) {

+ 10
- 9
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java Просмотреть файл

@@ -20,6 +20,7 @@ import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
20 20
 import org.openzen.zenscript.codemodel.type.GenericName;
21 21
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
22 22
 import org.openzen.zenscript.codemodel.type.ITypeID;
23
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
23 24
 
24 25
 /**
25 26
  *
@@ -58,7 +59,7 @@ public class ZSPackage {
58 59
 			if (types.get(name.name).typeParameters.length != name.getNumberOfArguments())
59 60
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
60 61
 			
61
-			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments), name.arguments);
62
+			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), null, name.arguments), name.arguments);
62 63
 		}
63 64
 		
64 65
 		return null;
@@ -85,29 +86,29 @@ public class ZSPackage {
85 86
 		return null;
86 87
 	}
87 88
 	
88
-	public ITypeID getType(CodePosition position, TypeResolutionContext context, List<GenericName> nameParts) {
89
-		return getType(position, context, nameParts, 0);
89
+	public ITypeID getType(CodePosition position, TypeResolutionContext context, List<GenericName> nameParts, StorageTag storage) {
90
+		return getType(position, context, nameParts, 0, storage);
90 91
 	}
91 92
 	
92
-	public ITypeID getType(CodePosition position, TypeResolutionContext context, GenericName name) {
93
+	public ITypeID getType(CodePosition position, TypeResolutionContext context, GenericName name, StorageTag storage) {
93 94
 		if (types.containsKey(name.name)) {
94
-			return context.getTypeRegistry().getForDefinition(types.get(name.name), name.arguments);
95
+			return context.getTypeRegistry().getForDefinition(types.get(name.name), storage, name.arguments);
95 96
 		}
96 97
 		
97 98
 		return null;
98 99
 	}
99 100
 	
100
-	private ITypeID getType(CodePosition position, TypeResolutionContext context, List<GenericName> nameParts, int depth) {
101
+	private ITypeID getType(CodePosition position, TypeResolutionContext context, List<GenericName> nameParts, int depth, StorageTag storage) {
101 102
 		if (depth >= nameParts.size())
102 103
 			return null;
103 104
 		
104 105
 		GenericName name = nameParts.get(depth);
105 106
 		if (subPackages.containsKey(name.name) && name.hasNoArguments())
106
-			return subPackages.get(name.name).getType(position, context, nameParts, depth + 1);
107
+			return subPackages.get(name.name).getType(position, context, nameParts, depth + 1, storage);
107 108
 		
108 109
 		if (types.containsKey(name.name)) {
109
-			DefinitionTypeID type = context.getTypeRegistry().getForDefinition(types.get(name.name), name.arguments);
110
-			return GenericName.getInnerType(context.getTypeRegistry(), type, nameParts, depth + 1);
110
+			DefinitionTypeID type = context.getTypeRegistry().getForDefinition(types.get(name.name), null, name.arguments);
111
+			return GenericName.getInnerType(context.getTypeRegistry(), type, nameParts, depth + 1, storage);
111 112
 		}
112 113
 		
113 114
 		return null;

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java Просмотреть файл

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.member.EnumConstantMember;
11 11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12 12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
+import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
14 15
 
15 16
 /**
16 17
  *
@@ -26,7 +27,7 @@ public class EnumConstantExpression extends Expression {
26 27
 	}
27 28
 	
28 29
 	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
29
-		super(position, registry.getForDefinition(type), null);
30
+		super(position, registry.getForDefinition(type, StaticStorageTag.INSTANCE), null);
30 31
 		
31 32
 		this.value = value;
32 33
 	}

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java Просмотреть файл

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
17 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
18 18
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
19 19
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
20
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
20 21
 import stdlib.Strings;
21 22
 
22 23
 /**
@@ -37,7 +38,7 @@ public class ExpressionBuilder {
37 38
 		List<GenericName> name = new ArrayList<>();
38 39
 		for (String namePart : nameParts)
39 40
 			name.add(new GenericName(namePart));
40
-		ITypeID type = scope.getType(position, name);
41
+		ITypeID type = scope.getType(position, name, UniqueStorageTag.INSTANCE);
41 42
 		if (type == null)
42 43
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_TYPE, "No such type: " + typename);
43 44
 		

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java Просмотреть файл

@@ -130,6 +130,8 @@ public interface ExpressionVisitor<T> {
130 130
 	
131 131
 	public T visitStaticSetter(StaticSetterExpression expression);
132 132
 	
133
+	public T visitStorageCast(StorageCastExpression expression);
134
+	
133 135
 	public T visitSupertypeCast(SupertypeCastExpression expression);
134 136
 	
135 137
 	public T visitThis(ThisExpression expression);

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitorWithContext.java Просмотреть файл

@@ -130,6 +130,8 @@ public interface ExpressionVisitorWithContext<C, R> {
130 130
 	
131 131
 	public R visitStaticSetter(C context, StaticSetterExpression expression);
132 132
 	
133
+	public R visitStorageCast(C context, StorageCastExpression expression);
134
+	
133 135
 	public R visitSupertypeCast(C context, SupertypeCastExpression expression);
134 136
 	
135 137
 	public R visitThis(C context, ThisExpression expression);

+ 46
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StorageCastExpression.java Просмотреть файл

@@ -0,0 +1,46 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.scope.TypeScope;
10
+import org.openzen.zenscript.codemodel.type.ITypeID;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class StorageCastExpression extends Expression {
17
+	public final Expression value;
18
+	
19
+	public StorageCastExpression(CodePosition position, Expression value, ITypeID toType) {
20
+		super(position, toType, value.thrownType);
21
+		
22
+		this.value = value;
23
+	}
24
+
25
+	@Override
26
+	public <T> T accept(ExpressionVisitor<T> visitor) {
27
+		return visitor.visitStorageCast(this);
28
+	}
29
+
30
+	@Override
31
+	public <C, R> R accept(C context, ExpressionVisitorWithContext<C, R> visitor) {
32
+		return visitor.visitStorageCast(context, this);
33
+	}
34
+
35
+	@Override
36
+	public Expression transform(ExpressionTransformer transformer) {
37
+		Expression transformed = transformer.transform(value);
38
+		return transformed == this ? this : new StorageCastExpression(position, transformed, type);
39
+	}
40
+
41
+	@Override
42
+	public Expression normalize(TypeScope scope) {
43
+		Expression normalized = value.normalize(scope);
44
+		return normalized == value ? this : new StorageCastExpression(position, normalized, type);
45
+	}
46
+}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java Просмотреть файл

@@ -60,7 +60,7 @@ public class FieldMember extends PropertyMember {
60 60
 		if (definition.typeParameters != null) {
61 61
 			parameters = new ITypeID[definition.typeParameters.length];
62 62
 			for (int i = 0; i < parameters.length; i++)
63
-				parameters[i] = registry.getGeneric(definition.typeParameters[i]);
63
+				parameters[i] = registry.getGeneric(definition.typeParameters[i], null);
64 64
 		}
65 65
 		
66 66
 		if (autoGetterAccess != 0) {

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinition.java Просмотреть файл

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
12 12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13 13
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14 14
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
15 16
 
16 17
 /**
17 18
  *
@@ -31,7 +32,7 @@ public class InnerDefinition {
31 32
 		this.outerTypeArguments = outerTypeArguments;
32 33
 	}
33 34
 	
34
-	public DefinitionTypeID instance(GlobalTypeRegistry registry, ITypeID[] typeArguments, DefinitionTypeID outer) {
35
-		return registry.getForDefinition(definition, typeArguments, outer);
35
+	public DefinitionTypeID instance(GlobalTypeRegistry registry, ITypeID[] typeArguments, DefinitionTypeID outer, StorageTag storage) {
36
+		return registry.getForDefinition(definition, typeArguments, outer, storage);
36 37
 	}
37 38
 }

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IteratorMember.java Просмотреть файл

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
17 17
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
18 18
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
19 19
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
20
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
20 21
 
21 22
 /**
22 23
  *
@@ -85,6 +86,6 @@ public class IteratorMember extends FunctionalMember {
85 86
 	}
86 87
 	
87 88
 	private static FunctionHeader createIteratorHeader(GlobalTypeRegistry registry, ITypeID[] iteratorTypes) {
88
-		return new FunctionHeader(registry.getIterator(iteratorTypes));
89
+		return new FunctionHeader(registry.getIterator(iteratorTypes, UniqueStorageTag.INSTANCE));
89 90
 	}
90 91
 }

+ 1
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java Просмотреть файл

@@ -15,6 +15,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
15 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16 16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17 17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
18 19
 
19 20
 /**
20 21
  *

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java Просмотреть файл

@@ -18,6 +18,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
18 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19 19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20 20
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
21
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
21 22
 
22 23
 /**
23 24
  *
@@ -55,8 +56,13 @@ public class BlockScope extends StatementScope {
55 56
 	}
56 57
 
57 58
 	@Override
58
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
59
-		return parent.getType(position, name);
59
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
60
+		return parent.getType(position, name, storage);
61
+	}
62
+
63
+	@Override
64
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
65
+		return parent.getStorageTag(position, name, parameters);
60 66
 	}
61 67
 
62 68
 	@Override

+ 11
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java Просмотреть файл

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
22 22
 import org.openzen.zenscript.codemodel.type.ITypeID;
23 23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
24 24
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
25
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
25 26
 
26 27
 /**
27 28
  *
@@ -47,18 +48,22 @@ public class CompileTypeScope extends BaseScope {
47 48
 	@Override
48 49
 	public IPartialExpression get(CodePosition position, GenericName name) {
49 50
 		if (typeParameters.containsKey(name.name) && !name.hasArguments())
50
-			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)), name.arguments);
51
+			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name), null), name.arguments);
51 52
 
52 53
 		return outer.get(position, name);
53 54
 	}
54 55
 
55 56
 	@Override
56
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
57
-		if (typeParameters.containsKey(name.get(0).name) && name.size() == 1 && !name.get(0).hasArguments()) {
58
-			return getTypeRegistry().getGeneric(typeParameters.get(name.get(0).name));
59
-		}
57
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
58
+		if (typeParameters.containsKey(name.get(0).name) && name.size() == 1 && !name.get(0).hasArguments())
59
+			return getTypeRegistry().getGeneric(typeParameters.get(name.get(0).name), storage);
60 60
 
61
-		return outer.getType(position, name);
61
+		return outer.getType(position, name, storage);
62
+	}
63
+
64
+	@Override
65
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
66
+		return outer.getStorageTag(position, name, parameters);
62 67
 	}
63 68
 
64 69
 	@Override

+ 18
- 12
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java Просмотреть файл

@@ -31,6 +31,7 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
31 31
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
32 32
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
33 33
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
34
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
34 35
 
35 36
 /**
36 37
  *
@@ -60,7 +61,7 @@ public class DefinitionScope extends BaseScope {
60 61
 			
61 62
 			for (TypeParameter parameter : expansion.typeParameters) {
62 63
 				genericParameters.put(parameter.name, parameter);
63
-				typeParameters.put(parameter, outer.getTypeRegistry().getGeneric(parameter));
64
+				typeParameters.put(parameter, outer.getTypeRegistry().getGeneric(parameter, null));
64 65
 			}
65 66
 		} else {
66 67
 			DefinitionTypeID definitionType = outer.getTypeRegistry().getForMyDefinition(definition);
@@ -69,7 +70,7 @@ public class DefinitionScope extends BaseScope {
69 70
 			while (definitionType != null) {
70 71
 				for (TypeParameter parameter : definitionType.definition.typeParameters) {
71 72
 					genericParameters.put(parameter.name, parameter);
72
-					typeParameters.put(parameter, outer.getTypeRegistry().getGeneric(parameter));
73
+					typeParameters.put(parameter, outer.getTypeRegistry().getGeneric(parameter, null));
73 74
 				}
74 75
 				definitionType = definitionType.definition.isStatic() ? null : definitionType.outer;
75 76
 			}
@@ -92,37 +93,42 @@ public class DefinitionScope extends BaseScope {
92 93
 	public IPartialExpression get(CodePosition position, GenericName name) {
93 94
 		if (members != null) {
94 95
 			if (members.hasInnerType(name.name))
95
-				return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
96
+				return new PartialTypeExpression(position, members.getInnerType(position, name, null), name.arguments);
96 97
 			if (members.hasMember(name.name) && !name.hasArguments())
97 98
 				return members.getMemberExpression(position, this, new ThisExpression(position, type), name, true);
98 99
 		} else if (innerTypes.containsKey(name.name)) {
99
-			return new PartialTypeExpression(position, getTypeRegistry().getForDefinition(innerTypes.get(name).get(), name.arguments), name.arguments);
100
+			return new PartialTypeExpression(position, getTypeRegistry().getForDefinition(innerTypes.get(name).get(), null, name.arguments), name.arguments);
100 101
 		}
101 102
 		if (genericParameters.containsKey(name.name) && !name.hasArguments())
102
-			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(genericParameters.get(name.name)), name.arguments);
103
+			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(genericParameters.get(name.name), null), name.arguments);
103 104
 		
104 105
 		return outer.get(position, name);
105 106
 	}
106 107
 
107 108
 	@Override
108
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
109
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
109 110
 		if (members != null && members.hasInnerType(name.get(0).name)) {
110
-			ITypeID result = members.getInnerType(position, name.get(0));
111
+			ITypeID result = members.getInnerType(position, name.get(0), storage);
111 112
 			for (int i = 1; i < name.size(); i++) {
112
-				result = getTypeMembers(result).getInnerType(position, name.get(i));
113
+				result = getTypeMembers(result).getInnerType(position, name.get(i), storage);
113 114
 			}
114 115
 			return result;
115 116
 		} else if (genericParameters.containsKey(name.get(0).name) && name.size() == 1 && !name.get(0).hasArguments()) {
116
-			return getTypeRegistry().getGeneric(genericParameters.get(name.get(0).name));
117
+			return getTypeRegistry().getGeneric(genericParameters.get(name.get(0).name), null);
117 118
 		} else if (innerTypes.containsKey(name.get(0).name)) {
118
-			ITypeID result = getTypeRegistry().getForDefinition(innerTypes.get(name.get(0).name).get(), name.get(0).arguments);
119
+			ITypeID result = getTypeRegistry().getForDefinition(innerTypes.get(name.get(0).name).get(), null, name.get(0).arguments);
119 120
 			for (int i = 1; i < name.size(); i++) {
120
-				result = getTypeMembers(result).getInnerType(position, name.get(i)); // TODO: this cannot be right, where did the type arguments go? the abyss?
121
+				result = getTypeMembers(result).getInnerType(position, name.get(i), storage); // TODO: this cannot be right, where did the type arguments go? the abyss?
121 122
 			}
122 123
 			return result;
123 124
 		}
124 125
 		
125
-		return outer.getType(position, name);
126
+		return outer.getType(position, name, storage);
127
+	}
128
+
129
+	@Override
130
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
131
+		return outer.getStorageTag(position, name, parameters);
126 132
 	}
127 133
 
128 134
 	@Override

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java Просмотреть файл

@@ -27,6 +27,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
27 27
 import org.openzen.zenscript.codemodel.type.ITypeID;
28 28
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
29 29
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
30
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
30 31
 
31 32
 /**
32 33
  *
@@ -127,8 +128,13 @@ public class ExpressionScope extends BaseScope {
127 128
 	}
128 129
 	
129 130
 	@Override
130
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
131
-		return outer.getType(position, name);
131
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
132
+		return outer.getType(position, name, storage);
133
+	}
134
+
135
+	@Override
136
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
137
+		return outer.getStorageTag(position, name, parameters);
132 138
 	}
133 139
 	
134 140
 	@Override

+ 11
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java Просмотреть файл

@@ -27,6 +27,7 @@ import org.openzen.zenscript.codemodel.type.ISymbol;
27 27
 import org.openzen.zenscript.codemodel.type.ITypeID;
28 28
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
29 29
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
30
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
30 31
 
31 32
 /**
32 33
  *
@@ -57,7 +58,7 @@ public class FileScope extends BaseScope {
57 58
 
58 59
 	@Override
59 60
 	public IPartialExpression get(CodePosition position, GenericName name) {
60
-		ITypeID type = context.getType(position, Collections.singletonList(name));
61
+		ITypeID type = context.getType(position, Collections.singletonList(name), null);
61 62
 		if (type != null)
62 63
 			return new PartialTypeExpression(position, type, name.arguments);
63 64
 		
@@ -70,15 +71,15 @@ public class FileScope extends BaseScope {
70 71
 	}
71 72
 
72 73
 	@Override
73
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
74
-		ITypeID type = context.getType(position, name);
74
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
75
+		ITypeID type = context.getType(position, name, storage);
75 76
 		if (type != null)
76 77
 			return type;
77 78
 		
78 79
 		if (globals.containsKey(name.get(0).name)) {
79
-			type = globals.get(name.get(0).name).getType(position, context, name.get(0).arguments);
80
+			type = globals.get(name.get(0).name).getType(position, context, name.get(0).arguments, storage);
80 81
 			for (int i = 1; i < name.size(); i++) {
81
-				type = getTypeMembers(type).getInnerType(position, name.get(i));
82
+				type = getTypeMembers(type).getInnerType(position, name.get(i), storage);
82 83
 				if (type == null)
83 84
 					break;
84 85
 			}
@@ -90,6 +91,11 @@ public class FileScope extends BaseScope {
90 91
 		return null;
91 92
 	}
92 93
 
94
+	@Override
95
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
96
+		return context.getStorageTag(position, name, parameters);
97
+	}
98
+
93 99
 	@Override
94 100
 	public LoopStatement getLoop(String name) {
95 101
 		return null;

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java Просмотреть файл

@@ -21,6 +21,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
21 21
 import org.openzen.zenscript.codemodel.type.ITypeID;
22 22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23 23
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
24
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
24 25
 
25 26
 /**
26 27
  *
@@ -57,8 +58,13 @@ public class ForeachScope extends StatementScope {
57 58
 	}
58 59
 
59 60
 	@Override
60
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
61
-		return outer.getType(position, name);
61
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
62
+		return outer.getType(position, name, storage);
63
+	}
64
+
65
+	@Override
66
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
67
+		return outer.getStorageTag(position, name, parameters);
62 68
 	}
63 69
 
64 70
 	@Override

+ 10
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java Просмотреть файл

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
22 22
 import org.openzen.zenscript.codemodel.type.ITypeID;
23 23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
24 24
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
25
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
25 26
 
26 27
 /**
27 28
  *
@@ -75,7 +76,7 @@ public class FunctionScope extends StatementScope {
75 76
 			if (header.typeParameters != null) {
76 77
 				for (TypeParameter parameter : header.typeParameters) {
77 78
 					if (parameter.name.equals(name.name))
78
-						return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameter), name.arguments);
79
+						return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameter, null), name.arguments);
79 80
 				}
80 81
 			}
81 82
 		}
@@ -84,17 +85,22 @@ public class FunctionScope extends StatementScope {
84 85
 	}
85 86
 
86 87
 	@Override
87
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
88
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
88 89
 		if (name.size() == 1 && name.get(0).hasNoArguments()) {
89 90
 			if (header.typeParameters != null) {
90 91
 				for (TypeParameter parameter : header.typeParameters) {
91 92
 					if (parameter.name.equals(name.get(0).name))
92
-						return getTypeRegistry().getGeneric(parameter);
93
+						return getTypeRegistry().getGeneric(parameter, null);
93 94
 				}
94 95
 			}
95 96
 		}
96 97
 		
97
-		return outer.getType(position, name);
98
+		return outer.getType(position, name, storage);
99
+	}
100
+
101
+	@Override
102
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
103
+		return outer.getStorageTag(position, name, parameters);
98 104
 	}
99 105
 
100 106
 	@Override

+ 10
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java Просмотреть файл

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
22 22
 import org.openzen.zenscript.codemodel.type.ITypeID;
23 23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
24 24
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
25
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
25 26
 
26 27
 /**
27 28
  *
@@ -47,17 +48,22 @@ public class GenericFunctionScope extends BaseScope {
47 48
 	@Override
48 49
 	public IPartialExpression get(CodePosition position, GenericName name) {
49 50
 		if (parameters.containsKey(name.name) && name.hasNoArguments())
50
-			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name)), name.arguments);
51
+			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name), null), name.arguments);
51 52
 		
52 53
 		return outer.get(position, name);
53 54
 	}
54 55
 
55 56
 	@Override
56
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
57
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
57 58
 		if (name.size() == 1 && parameters.containsKey(name.get(0).name) && name.get(0).hasNoArguments())
58
-			return getTypeRegistry().getGeneric(parameters.get(name.get(0).name));
59
+			return getTypeRegistry().getGeneric(parameters.get(name.get(0).name), null);
59 60
 		
60
-		return outer.getType(position, name);
61
+		return outer.getType(position, name, storage);
62
+	}
63
+
64
+	@Override
65
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
66
+		return outer.getStorageTag(position, name, parameters);
61 67
 	}
62 68
 
63 69
 	@Override

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java Просмотреть файл

@@ -18,6 +18,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
18 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19 19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20 20
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
21
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
21 22
 
22 23
 /**
23 24
  *
@@ -45,8 +46,13 @@ public class GlobalScriptScope extends StatementScope {
45 46
 	}
46 47
 
47 48
 	@Override
48
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
49
-		return file.getType(position, name);
49
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
50
+		return file.getType(position, name, storage);
51
+	}
52
+
53
+	@Override
54
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
55
+		return file.getStorageTag(position, name, parameters);
50 56
 	}
51 57
 
52 58
 	@Override

+ 11
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java Просмотреть файл

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
22 22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23 23
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
24 24
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
25
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
25 26
 
26 27
 /**
27 28
  *
@@ -47,7 +48,7 @@ public class ImplementationScope extends BaseScope {
47 48
 	@Override
48 49
 	public IPartialExpression get(CodePosition position, GenericName name) {
49 50
 		if (members.hasInnerType(name.name))
50
-			return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
51
+			return new PartialTypeExpression(position, members.getInnerType(position, name, null), name.arguments);
51 52
 		if (members.hasMember(name.name))
52 53
 			return members.getMemberExpression(position, this, new ThisExpression(position, outer.getThisType()), name, true);
53 54
 		
@@ -55,16 +56,21 @@ public class ImplementationScope extends BaseScope {
55 56
 	}
56 57
 
57 58
 	@Override
58
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
59
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
59 60
 		if (members.hasInnerType(name.get(0).name)) {
60
-			ITypeID result = members.getInnerType(position, name.get(0));
61
+			ITypeID result = members.getInnerType(position, name.get(0), storage);
61 62
 			for (int i = 1; i < name.size(); i++) {
62
-				result = getTypeMembers(result).getInnerType(position, name.get(i));
63
+				result = getTypeMembers(result).getInnerType(position, name.get(i), storage);
63 64
 			}
64 65
 			return result;
65 66
 		}
66 67
 		
67
-		return outer.getType(position, name);
68
+		return outer.getType(position, name, storage);
69
+	}
70
+
71
+	@Override
72
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
73
+		return outer.getStorageTag(position, name, parameters);
68 74
 	}
69 75
 
70 76
 	@Override

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java Просмотреть файл

@@ -21,6 +21,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
21 21
 import org.openzen.zenscript.codemodel.type.ITypeID;
22 22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23 23
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
24
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
24 25
 
25 26
 /**
26 27
  *
@@ -70,8 +71,13 @@ public class LambdaScope extends StatementScope {
70 71
 	}
71 72
 
72 73
 	@Override
73
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
74
-		return outer.getType(position, name);
74
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
75
+		return outer.getType(position, name, storage);
76
+	}
77
+
78
+	@Override
79
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
80
+		return outer.getStorageTag(position, name, parameters);
75 81
 	}
76 82
 
77 83
 	@Override

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java Просмотреть файл

@@ -18,6 +18,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
18 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19 19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20 20
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
21
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
21 22
 
22 23
 /**
23 24
  *
@@ -47,8 +48,13 @@ public class LoopScope extends StatementScope {
47 48
 	}
48 49
 
49 50
 	@Override
50
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
51
-		return outer.getType(position, name);
51
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
52
+		return outer.getType(position, name, storage);
53
+	}
54
+
55
+	@Override
56
+	public StorageTag getStorageTag(CodePosition position, String name, String[] parameters) {
57
+		return outer.getStorageTag(position, name, parameters);
52 58
 	}
53 59
 
54 60
 	@Override

+ 0
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/StatementScope.java Просмотреть файл

@@ -12,7 +12,6 @@ import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 13
 import org.openzen.zenscript.codemodel.statement.VarStatement;
14 14
 import org.openzen.zenscript.codemodel.type.GenericName;
15
-import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
16 15
 
17 16
 /**
18 17
  *

+ 57
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java Просмотреть файл

@@ -6,25 +6,54 @@
6 6
 package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import java.util.List;
9
+import java.util.Objects;
9 10
 import org.openzen.zenscript.codemodel.GenericMapper;
10 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
13
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
11 14
 
12 15
 /**
13 16
  *
14 17
  * @author Hoofdgebruiker
15 18
  */
16 19
 public class ArrayTypeID implements ITypeID {
17
-	public static final ArrayTypeID INT = new ArrayTypeID(null, BasicTypeID.INT, 1);
18
-	public static final ArrayTypeID CHAR = new ArrayTypeID(null, BasicTypeID.CHAR, 1);
20
+	public static final ArrayTypeID INT_NOSTORAGE = new ArrayTypeID(BasicTypeID.INT, 1, null);
21
+	public static final ArrayTypeID CHAR_NOSTORAGE = new ArrayTypeID(BasicTypeID.CHAR, 1, null);
22
+	
23
+	public static final ArrayTypeID INT_UNIQUE = new ArrayTypeID(BasicTypeID.INT, 1, UniqueStorageTag.INSTANCE);
24
+	public static final ArrayTypeID CHAR_UNIQUE = new ArrayTypeID(BasicTypeID.CHAR, 1, UniqueStorageTag.INSTANCE);
19 25
 	
20 26
 	public final ITypeID elementType;
21 27
 	public final int dimension;
28
+	public final StorageTag storage;
22 29
 	private final ArrayTypeID normalized;
30
+	private final ArrayTypeID withoutStorage;
23 31
 
24
-	public ArrayTypeID(GlobalTypeRegistry registry, ITypeID elementType, int dimension) {
32
+	private ArrayTypeID(ITypeID elementType, int dimension, StorageTag storage) {
33
+		this.elementType = elementType;
34
+		this.dimension = dimension;
35
+		this.normalized = this;
36
+		this.storage = storage;
37
+		
38
+		if (storage == null) {
39
+			withoutStorage = this;
40
+		} else {
41
+			if (elementType == BasicTypeID.INT)
42
+				withoutStorage = INT_NOSTORAGE;
43
+			else if (elementType == BasicTypeID.CHAR)
44
+				withoutStorage = CHAR_NOSTORAGE;
45
+			else
46
+				throw new IllegalArgumentException();
47
+		}
48
+	}
49
+	
50
+	public ArrayTypeID(GlobalTypeRegistry registry, ITypeID elementType, int dimension, StorageTag storage) {
25 51
 		this.elementType = elementType;
26 52
 		this.dimension = dimension;
27
-		this.normalized = elementType.getNormalized() == elementType ? this : registry.getArray(elementType.getNormalized(), dimension);
53
+		this.normalized = elementType.getNormalized() == elementType ? this : registry.getArray(elementType.getNormalized(), dimension, storage);
54
+		this.storage = storage;
55
+		
56
+		withoutStorage = storage == null ? this : registry.getArray(elementType, dimension, null);
28 57
 	}
29 58
 	
30 59
 	@Override
@@ -64,7 +93,12 @@ public class ArrayTypeID implements ITypeID {
64 93
 	
65 94
 	@Override
66 95
 	public ArrayTypeID instance(GenericMapper mapper) {
67
-		return mapper.registry.getArray(elementType.instance(mapper), dimension);
96
+		return mapper.registry.getArray(elementType.instance(mapper), dimension, storage);
97
+	}
98
+	
99
+	@Override
100
+	public ArrayTypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
101
+		return registry.getArray(elementType, dimension, storage);
68 102
 	}
69 103
 
70 104
 	@Override
@@ -87,6 +121,7 @@ public class ArrayTypeID implements ITypeID {
87 121
 		int hash = 7;
88 122
 		hash = 79 * hash + elementType.hashCode();
89 123
 		hash = 79 * hash + dimension;
124
+		hash = 79 * hash + Objects.hashCode(storage);
90 125
 		return hash;
91 126
 	}
92 127
 
@@ -102,7 +137,9 @@ public class ArrayTypeID implements ITypeID {
102 137
 			return false;
103 138
 		}
104 139
 		final ArrayTypeID other = (ArrayTypeID) obj;
105
-		return this.dimension == other.dimension && this.elementType == other.elementType;
140
+		return this.dimension == other.dimension
141
+				&& this.elementType == other.elementType
142
+				&& Objects.equals(this.storage, other.storage);
106 143
 	}
107 144
 
108 145
 	@Override
@@ -114,6 +151,20 @@ public class ArrayTypeID implements ITypeID {
114 151
 			result.append(',');
115 152
 		}
116 153
 		result.append(']');
154
+		if (storage != null) {
155
+			result.append('`');
156
+			result.append(storage.toString());
157
+		}
117 158
 		return result.toString();
118 159
 	}
160
+
161
+	@Override
162
+	public StorageTag getStorage() {
163
+		return storage;
164
+	}
165
+
166
+	@Override
167
+	public ITypeID withoutStorage() {
168
+		return withoutStorage;
169
+	}
119 170
 }

+ 30
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java Просмотреть файл

@@ -6,8 +6,10 @@
6 6
 package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import java.util.List;
9
+import java.util.Objects;
9 10
 import org.openzen.zenscript.codemodel.GenericMapper;
10 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
11 13
 
12 14
 /**
13 15
  *
@@ -16,23 +18,34 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
16 18
 public class AssocTypeID implements ITypeID {
17 19
 	public final ITypeID keyType;
18 20
 	public final ITypeID valueType;
21
+	public final StorageTag storage;
19 22
 	private final AssocTypeID normalized;
23
+	private final AssocTypeID withoutStorage;
20 24
 	
21
-	public AssocTypeID(GlobalTypeRegistry typeRegistry, ITypeID keyType, ITypeID valueType) {
25
+	public AssocTypeID(GlobalTypeRegistry typeRegistry, ITypeID keyType, ITypeID valueType, StorageTag storage) {
22 26
 		this.keyType = keyType;
23 27
 		this.valueType = valueType;
28
+		this.storage = storage;
24 29
 		
25 30
 		if (keyType != keyType.getNormalized() || valueType != valueType.getNormalized())
26
-			normalized = typeRegistry.getAssociative(keyType.getNormalized(), valueType.getNormalized());
31
+			normalized = typeRegistry.getAssociative(keyType.getNormalized(), valueType.getNormalized(), storage);
27 32
 		else
28 33
 			normalized = this;
34
+		
35
+		withoutStorage = storage == null ? this : typeRegistry.getAssociative(normalized.keyType, normalized.valueType, null);
29 36
 	}
30 37
 	
31 38
 	@Override
32 39
 	public AssocTypeID instance(GenericMapper mapper) {
33 40
 		return mapper.registry.getAssociative(
34 41
 				keyType.instance(mapper),
35
-				valueType.instance(mapper));
42
+				valueType.instance(mapper),
43
+				storage);
44
+	}
45
+	
46
+	@Override
47
+	public AssocTypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
48
+		return registry.getAssociative(keyType, valueType, storage);
36 49
 	}
37 50
 	
38 51
 	@Override
@@ -91,6 +104,7 @@ public class AssocTypeID implements ITypeID {
91 104
 		int hash = 7;
92 105
 		hash = 29 * hash + keyType.hashCode();
93 106
 		hash = 29 * hash + valueType.hashCode();
107
+		hash = 29 * hash + Objects.hashCode(storage);
94 108
 		return hash;
95 109
 	}
96 110
 
@@ -106,7 +120,9 @@ public class AssocTypeID implements ITypeID {
106 120
 			return false;
107 121
 		}
108 122
 		final AssocTypeID other = (AssocTypeID) obj;
109
-		return this.keyType == other.keyType && this.valueType == other.valueType;
123
+		return this.keyType == other.keyType
124
+				&& this.valueType == other.valueType
125
+				&& Objects.equals(this.storage, other.storage);
110 126
 	}
111 127
 	
112 128
 	@Override
@@ -118,4 +134,14 @@ public class AssocTypeID implements ITypeID {
118 134
 		result.append(']');
119 135
 		return result.toString();
120 136
 	}
137
+
138
+	@Override
139
+	public StorageTag getStorage() {
140
+		return storage;
141
+	}
142
+
143
+	@Override
144
+	public ITypeID withoutStorage() {
145
+		return withoutStorage;
146
+	}
121 147
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java Просмотреть файл

@@ -9,6 +9,8 @@ import java.util.Collections;
9 9
 import java.util.List;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
13
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
12 14
 
13 15
 /**
14 16
  *
@@ -50,6 +52,11 @@ public enum BasicTypeID implements ITypeID {
50 52
 	public ITypeID instance(GenericMapper mapper) {
51 53
 		return this;
52 54
 	}
55
+
56
+	@Override
57
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
58
+		return this;
59
+	}
53 60
 	
54 61
 	@Override
55 62
 	public String toString() {
@@ -100,4 +107,14 @@ public enum BasicTypeID implements ITypeID {
100 107
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
101 108
 		
102 109
 	}
110
+
111
+	@Override
112
+	public StorageTag getStorage() {
113
+		return ValueStorageTag.INSTANCE;
114
+	}
115
+
116
+	@Override
117
+	public ITypeID withoutStorage() {
118
+		return this;
119
+	}
103 120
 }

+ 55
- 32
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java Просмотреть файл

@@ -16,32 +16,35 @@ import org.openzen.zenscript.codemodel.definition.AliasDefinition;
16 16
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
17 17
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
18 18
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
19
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
19 20
 
20 21
 /**
21 22
  *
22 23
  * @author Hoofdgebruiker
23 24
  */
24 25
 public class DefinitionTypeID implements ITypeID {
25
-	public static DefinitionTypeID forType(HighLevelDefinition definition) {
26
+	public static DefinitionTypeID forType(GlobalTypeRegistry registry, HighLevelDefinition definition, StorageTag storage) {
26 27
 		if (definition.typeParameters != null && definition.typeParameters.length > 0)
27 28
 			throw new IllegalArgumentException("Definition has type arguments!");
28 29
 		
29
-		return new DefinitionTypeID(null, definition, ITypeID.NONE);
30
+		return new DefinitionTypeID(registry, definition, ITypeID.NONE, storage);
30 31
 	}
31 32
 	
32 33
 	public final HighLevelDefinition definition;
33
-	public final ITypeID[] typeParameters;
34
+	public final ITypeID[] typeArguments;
34 35
 	public final DefinitionTypeID outer;
36
+	public final StorageTag storage;
35 37
 	private ITypeID normalized;
38
+	private ITypeID withoutStorage;
36 39
 	
37 40
 	public ITypeID superType;
38 41
 	
39
-	public DefinitionTypeID(GlobalTypeRegistry typeRegistry, HighLevelDefinition definition, ITypeID[] typeParameters) {
40
-		this(typeRegistry, definition, typeParameters, null);
42
+	public DefinitionTypeID(GlobalTypeRegistry typeRegistry, HighLevelDefinition definition, ITypeID[] typeParameters, StorageTag storage) {
43
+		this(typeRegistry, definition, typeParameters, null, storage);
41 44
 	}
42 45
 	
43 46
 	// For inner classes of generic outer classes
44
-	public DefinitionTypeID(GlobalTypeRegistry typeRegistry, HighLevelDefinition definition, ITypeID[] typeParameters, DefinitionTypeID outer) {
47
+	public DefinitionTypeID(GlobalTypeRegistry typeRegistry, HighLevelDefinition definition, ITypeID[] typeParameters, DefinitionTypeID outer, StorageTag storage) {
45 48
 		if (typeParameters == null)
46 49
 			throw new NullPointerException("typeParameters cannot be null");
47 50
 		if (typeParameters.length != definition.getNumberOfGenericParameters())
@@ -52,19 +55,22 @@ public class DefinitionTypeID implements ITypeID {
52 55
 			throw new IllegalArgumentException("Static inner definition must not have outer instance");
53 56
 		
54 57
 		this.definition = definition;
55
-		this.typeParameters = typeParameters;
58
+		this.typeArguments = typeParameters;
56 59
 		this.outer = outer;
60
+		this.storage = storage;
57 61
 		
58 62
 		normalized = isDenormalized() ? normalize(typeRegistry) : this;
59 63
 		if (normalized instanceof DefinitionTypeID && ((DefinitionTypeID)normalized).isDenormalized())
60 64
 			throw new AssertionError();
65
+		
66
+		withoutStorage = storage == null ? this : typeRegistry.getForDefinition(definition, typeParameters, outer, null);
61 67
 	}
62 68
 	
63 69
 	private boolean isDenormalized() {
64 70
 		if (definition instanceof AliasDefinition)
65 71
 			return true;
66 72
 		
67
-		for (ITypeID typeParameter : typeParameters)
73
+		for (ITypeID typeParameter : typeArguments)
68 74
 			if (typeParameter.getNormalized() != typeParameter)
69 75
 				return true;
70 76
 		if (outer != null && outer.getNormalized() != outer)
@@ -81,33 +87,33 @@ public class DefinitionTypeID implements ITypeID {
81 87
 			
82 88
 			Map<TypeParameter, ITypeID> typeMapping = new HashMap<>();
83 89
 			for (int i = 0; i < definition.typeParameters.length; i++)
84
-				typeMapping.put(definition.typeParameters[i], typeParameters[i].getNormalized());
90
+				typeMapping.put(definition.typeParameters[i], typeArguments[i].getNormalized());
85 91
 			GenericMapper mapper = new GenericMapper(typeRegistry, typeMapping);
86 92
 			ITypeID result = alias.type.instance(mapper).getNormalized();
87 93
 			return result;
88 94
 		}
89 95
 		
90
-		ITypeID[] normalizedTypeParameters = new ITypeID[typeParameters.length];
96
+		ITypeID[] normalizedTypeParameters = new ITypeID[typeArguments.length];
91 97
 		for (int i = 0; i < normalizedTypeParameters.length; i++)
92
-			normalizedTypeParameters[i] = typeParameters[i].getNormalized();
98
+			normalizedTypeParameters[i] = typeArguments[i].getNormalized();
93 99
 		
94
-		return typeRegistry.getForDefinition(definition, normalizedTypeParameters, outer == null ? null : (DefinitionTypeID)outer.getNormalized());
100
+		return typeRegistry.getForDefinition(definition, normalizedTypeParameters, outer == null ? null : (DefinitionTypeID)outer.getNormalized(), storage);
95 101
 	}
96 102
 	
97 103
 	public boolean hasTypeParameters() {
98
-		return typeParameters.length > 0;
104
+		return typeArguments.length > 0;
99 105
 	}
100 106
 	
101 107
 	public Map<TypeParameter, ITypeID> getTypeParameterMapping() {
102 108
 		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
103 109
 		DefinitionTypeID current = this;
104 110
 		do {
105
-			if (current.typeParameters != null) {
111
+			if (current.typeArguments != null) {
106 112
 				if (current.definition.typeParameters == null)
107 113
 					System.out.println("Type parameters but no generic parameters");
108 114
 				else
109
-					for (int i = 0; i < current.typeParameters.length; i++)
110
-						mapping.put(current.definition.typeParameters[i], current.typeParameters[i]);
115
+					for (int i = 0; i < current.typeArguments.length; i++)
116
+						mapping.put(current.definition.typeParameters[i], current.typeArguments[i]);
111 117
 			}
112 118
 
113 119
 			current = current.outer;
@@ -115,11 +121,12 @@ public class DefinitionTypeID implements ITypeID {
115 121
 		return mapping;
116 122
 	}
117 123
 	
118
-	public DefinitionTypeID(HighLevelDefinition definition) {
124
+	public DefinitionTypeID(HighLevelDefinition definition, StorageTag storage) {
119 125
 		this.definition = definition;
120
-		this.typeParameters = ITypeID.NONE;
126
+		this.typeArguments = ITypeID.NONE;
121 127
 		this.superType = definition.getSuperType();
122 128
 		this.outer = null;
129
+		this.storage = storage;
123 130
 	}
124 131
 	
125 132
 	@Override
@@ -138,14 +145,18 @@ public class DefinitionTypeID implements ITypeID {
138 145
 		
139 146
 		ITypeID[] instancedArguments = ITypeID.NONE;
140 147
 		if (hasTypeParameters()) {
141
-			instancedArguments = new ITypeID[typeParameters.length];
142
-			for (int i = 0; i < typeParameters.length; i++) {
143
-				instancedArguments[i] = typeParameters[i].instance(mapper);
144
-			}
148
+			instancedArguments = new ITypeID[typeArguments.length];
149
+			for (int i = 0; i < typeArguments.length; i++)
150
+				instancedArguments[i] = typeArguments[i].instance(mapper);
145 151
 		}
146 152
 		
147 153
 		DefinitionTypeID instancedOuter = outer == null ? null : outer.instance(mapper);
148
-		return mapper.registry.getForDefinition(definition, instancedArguments, instancedOuter);
154
+		return mapper.registry.getForDefinition(definition, instancedArguments, instancedOuter, storage);
155
+	}
156
+
157
+	@Override
158
+	public DefinitionTypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
159
+		return registry.getForDefinition(definition, typeArguments, outer, storage);
149 160
 	}
150 161
 	
151 162
 	@Override
@@ -201,7 +212,7 @@ public class DefinitionTypeID implements ITypeID {
201 212
 	@Override
202 213
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
203 214
 		if (hasTypeParameters()) {
204
-			for (ITypeID typeParameter : typeParameters)
215
+			for (ITypeID typeParameter : typeArguments)
205 216
 				if (typeParameter.hasInferenceBlockingTypeParameters(parameters))
206 217
 					return true;
207 218
 		}
@@ -213,8 +224,9 @@ public class DefinitionTypeID implements ITypeID {
213 224
 	public int hashCode() {
214 225
 		int hash = 7;
215 226
 		hash = 97 * hash + definition.hashCode();
216
-		hash = 97 * hash + Arrays.deepHashCode(typeParameters);
227
+		hash = 97 * hash + Arrays.deepHashCode(typeArguments);
217 228
 		hash = 97 * hash + Objects.hashCode(outer);
229
+		hash = 97 * hash + Objects.hashCode(storage);
218 230
 		return hash;
219 231
 	}
220 232
 
@@ -231,8 +243,9 @@ public class DefinitionTypeID implements ITypeID {
231 243
 		}
232 244
 		final DefinitionTypeID other = (DefinitionTypeID) obj;
233 245
 		return this.definition == other.definition
234
-				&& Arrays.deepEquals(this.typeParameters, other.typeParameters)
235
-				&& Objects.equals(outer, this.outer);
246
+				&& Arrays.deepEquals(this.typeArguments, other.typeArguments)
247
+				&& Objects.equals(outer, this.outer)
248
+				&& Objects.equals(this.storage, other.storage);
236 249
 	}
237 250
 	
238 251
 	@Override
@@ -246,10 +259,10 @@ public class DefinitionTypeID implements ITypeID {
246 259
 		
247 260
 		result.append(definition.name);
248 261
 		result.append('<');
249
-		for (int i = 0; i < typeParameters.length; i++) { 
262
+		for (int i = 0; i < typeArguments.length; i++) { 
250 263
 			if (i > 0)
251 264
 				result.append(", ");
252
-			result.append(typeParameters[i].toString());
265
+			result.append(typeArguments[i].toString());
253 266
 		}
254 267
 		result.append('>');
255 268
 		return result.toString();
@@ -262,7 +275,7 @@ public class DefinitionTypeID implements ITypeID {
262 275
 
263 276
 	@Override
264 277
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
265
-		for (ITypeID type : this.typeParameters)
278
+		for (ITypeID type : this.typeArguments)
266 279
 			type.extractTypeParameters(typeParameters);
267 280
 	}
268 281
 	
@@ -271,8 +284,18 @@ public class DefinitionTypeID implements ITypeID {
271 284
 		return definition.isDestructible();
272 285
 	}
273 286
 
274
-	public DefinitionTypeID getInnerType(GenericName name, GlobalTypeRegistry registry) {
287
+	public DefinitionTypeID getInnerType(GenericName name, GlobalTypeRegistry registry, StorageTag storage) {
275 288
 		HighLevelDefinition type = definition.getInnerType(name.name);
276
-		return registry.getForDefinition(type, name.arguments, this);
289
+		return registry.getForDefinition(type, name.arguments, this, storage);
290
+	}
291
+
292
+	@Override
293
+	public StorageTag getStorage() {
294
+		return storage;
295
+	}
296
+
297
+	@Override
298
+	public ITypeID withoutStorage() {
299
+		return withoutStorage;
277 300
 	}
278 301
 }

+ 27
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java Просмотреть файл

@@ -7,10 +7,12 @@ package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import java.util.Arrays;
9 9
 import java.util.List;
10
+import java.util.Objects;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.FunctionParameter;
12 13
 import org.openzen.zenscript.codemodel.GenericMapper;
13 14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14 16
 
15 17
 /**
16 18
  *
@@ -18,13 +20,17 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
18 20
  */
19 21
 public class FunctionTypeID implements ITypeID {
20 22
 	public final FunctionHeader header;
23
+	public final StorageTag storage;
21 24
 	private final FunctionTypeID normalized;
25
+	private final FunctionTypeID withoutStorage;
22 26
 	
23
-	public FunctionTypeID(GlobalTypeRegistry registry, FunctionHeader header) {
27
+	public FunctionTypeID(GlobalTypeRegistry registry, FunctionHeader header, StorageTag storage) {
24 28
 		this.header = header;
29
+		this.storage = storage;
25 30
 		
26 31
 		FunctionHeader normalizedHeader = header.normalize(registry);
27
-		normalized = header == normalizedHeader ? this : registry.getFunction(normalizedHeader);
32
+		normalized = header == normalizedHeader ? this : registry.getFunction(normalizedHeader, storage);
33
+		withoutStorage = storage == null ? this : registry.getFunction(header, null);
28 34
 	}
29 35
 	
30 36
 	@Override
@@ -34,7 +40,12 @@ public class FunctionTypeID implements ITypeID {
34 40
 	
35 41
 	@Override
36 42
 	public ITypeID instance(GenericMapper mapper) {
37
-		return mapper.registry.getFunction(mapper.map(header));
43
+		return mapper.registry.getFunction(mapper.map(header), storage);
44
+	}
45
+
46
+	@Override
47
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
48
+		return registry.getFunction(header, storage);
38 49
 	}
39 50
 	
40 51
 	@Override
@@ -90,6 +101,7 @@ public class FunctionTypeID implements ITypeID {
90 101
 		hash = 71 * hash + header.getReturnType().hashCode();
91 102
 		hash = 71 * hash + Arrays.deepHashCode(header.parameters);
92 103
 		hash = 71 * hash + Arrays.deepHashCode(header.typeParameters);
104
+		hash = 71 * hash + Objects.hashCode(storage);
93 105
 		return hash;
94 106
 	}
95 107
 
@@ -107,7 +119,8 @@ public class FunctionTypeID implements ITypeID {
107 119
 		final FunctionTypeID other = (FunctionTypeID) obj;
108 120
 		return this.header.getReturnType() == other.header.getReturnType()
109 121
 				&& Arrays.deepEquals(this.header.parameters, other.header.parameters)
110
-				&& Arrays.deepEquals(this.header.typeParameters, other.header.typeParameters);
122
+				&& Arrays.deepEquals(this.header.typeParameters, other.header.typeParameters)
123
+				&& Objects.equals(this.storage, other.storage);
111 124
 	}
112 125
 	
113 126
 	@Override
@@ -128,4 +141,14 @@ public class FunctionTypeID implements ITypeID {
128 141
 		result.append(header.getReturnType());
129 142
 		return result.toString();
130 143
 	}
144
+
145
+	@Override
146
+	public StorageTag getStorage() {
147
+		return storage;
148
+	}
149
+
150
+	@Override
151
+	public ITypeID withoutStorage() {
152
+		return withoutStorage;
153
+	}
131 154
 }

+ 31
- 16
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java Просмотреть файл

@@ -9,6 +9,7 @@ import java.util.List;
9 9
 import java.util.Objects;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
12 13
 
13 14
 /**
14 15
  *
@@ -17,13 +18,17 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
17 18
 public class GenericMapTypeID implements ITypeID {
18 19
 	public final ITypeID value;
19 20
 	public final TypeParameter key;
21
+	public final StorageTag storage;
20 22
 	private final GenericMapTypeID normalized;
23
+	private final GenericMapTypeID withoutStorage;
21 24
 	
22
-	public GenericMapTypeID(GlobalTypeRegistry registry, ITypeID value, TypeParameter key) {
25
+	public GenericMapTypeID(GlobalTypeRegistry registry, ITypeID value, TypeParameter key, StorageTag storage) {
23 26
 		this.value = value;
24 27
 		this.key = key;
28
+		this.storage = storage;
25 29
 		
26
-		normalized = value.getNormalized() == value ? this : registry.getGenericMap(value.getNormalized(), key);
30
+		normalized = value.getNormalized() == value ? this : registry.getGenericMap(value.getNormalized(), key, storage);
31
+		withoutStorage = storage == null ? this : registry.getGenericMap(value, key, null);
27 32
 	}
28 33
 	
29 34
 	@Override
@@ -58,7 +63,12 @@ public class GenericMapTypeID implements ITypeID {
58 63
 
59 64
 	@Override
60 65
 	public ITypeID instance(GenericMapper mapper) {
61
-		return mapper.registry.getGenericMap(value.instance(mapper), key);
66
+		return mapper.registry.getGenericMap(value.instance(mapper), key, storage);
67
+	}
68
+
69
+	@Override
70
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
71
+		return registry.getGenericMap(value, key, storage);
62 72
 	}
63 73
 
64 74
 	@Override
@@ -97,27 +107,32 @@ public class GenericMapTypeID implements ITypeID {
97 107
 		int hash = 5;
98 108
 		hash = 97 * hash + this.value.hashCode();
99 109
 		hash = 97 * hash + this.key.hashCode();
110
+		hash = 97 * hash + Objects.hashCode(this.storage);
100 111
 		return hash;
101 112
 	}
102 113
 
103 114
 	@Override
104 115
 	public boolean equals(Object obj) {
105
-		if (this == obj) {
116
+		if (this == obj)
106 117
 			return true;
107
-		}
108
-		if (obj == null) {
118
+		if (obj == null)
109 119
 			return false;
110
-		}
111
-		if (getClass() != obj.getClass()) {
120
+		if (getClass() != obj.getClass())
112 121
 			return false;
113
-		}
122
+		
114 123
 		final GenericMapTypeID other = (GenericMapTypeID) obj;
115
-		if (!Objects.equals(this.value, other.value)) {
116
-			return false;
117
-		}
118
-		if (!Objects.equals(this.key, other.key)) {
119
-			return false;
120
-		}
121
-		return true;
124
+		return Objects.equals(this.value, other.value)
125
+				&& Objects.equals(this.key, other.key)
126
+				&& Objects.equals(this.storage, other.storage);
127
+	}
128
+
129
+	@Override
130
+	public StorageTag getStorage() {
131
+		return storage;
132
+	}
133
+
134
+	@Override
135
+	public ITypeID withoutStorage() {
136
+		return withoutStorage;
122 137
 	}
123 138
 }

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericName.java Просмотреть файл

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import java.util.List;
9
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
9 10
 
10 11
 /**
11 12
  *
@@ -39,10 +40,10 @@ public class GenericName {
39 40
 		return arguments.length == 0;
40 41
 	}
41 42
 	
42
-	public static ITypeID getInnerType(GlobalTypeRegistry registry, DefinitionTypeID type, List<GenericName> name, int index) {
43
+	public static ITypeID getInnerType(GlobalTypeRegistry registry, DefinitionTypeID type, List<GenericName> name, int index, StorageTag storage) {
43 44
 		while (index < name.size()) {
44 45
 			GenericName innerName = name.get(index++);
45
-			type = type.getInnerType(innerName, registry);
46
+			type = type.getInnerType(innerName, registry, storage);
46 47
 			if (type == null)
47 48
 				return null;
48 49
 		}

+ 26
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java Просмотреть файл

@@ -6,9 +6,11 @@
6 6
 package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import java.util.List;
9
+import java.util.Objects;
9 10
 import org.openzen.zenscript.codemodel.GenericMapper;
10 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11 12
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
13
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
12 14
 
13 15
 /**
14 16
  *
@@ -16,9 +18,13 @@ import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
16 18
  */
17 19
 public class GenericTypeID implements ITypeID {
18 20
 	public final TypeParameter parameter;
21
+	public final StorageTag storage;
22
+	private final GenericTypeID withoutStorage;
19 23
 
20
-	public GenericTypeID(TypeParameter parameter) {
24
+	public GenericTypeID(GlobalTypeRegistry registry, TypeParameter parameter, StorageTag storage) {
21 25
 		this.parameter = parameter;
26
+		this.storage = storage;
27
+		withoutStorage = storage == null ? this : registry.getGeneric(parameter, null);
22 28
 	}
23 29
 	
24 30
 	public boolean matches(LocalMemberCache cache, ITypeID type) {
@@ -32,7 +38,12 @@ public class GenericTypeID implements ITypeID {
32 38
 	
33 39
 	@Override
34 40
 	public ITypeID instance(GenericMapper mapper) {
35
-		return mapper.map(this);
41
+		return mapper.map(this).withStorage(mapper.registry, storage);
42
+	}
43
+	
44
+	@Override
45
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
46
+		return registry.getGeneric(parameter, storage);
36 47
 	}
37 48
 
38 49
 	@Override
@@ -89,6 +100,7 @@ public class GenericTypeID implements ITypeID {
89 100
 	public int hashCode() {
90 101
 		int hash = 7;
91 102
 		hash = 47 * hash + parameter.hashCode();
103
+		hash = 47 * hash + Objects.hashCode(storage);
92 104
 		return hash;
93 105
 	}
94 106
 
@@ -104,11 +116,22 @@ public class GenericTypeID implements ITypeID {
104 116
 			return false;
105 117
 		}
106 118
 		final GenericTypeID other = (GenericTypeID) obj;
107
-		return this.parameter == other.parameter;
119
+		return this.parameter == other.parameter
120
+				&& Objects.equals(this.storage, other.storage);
108 121
 	}
109 122
 	
110 123
 	@Override
111 124
 	public String toString() {
112 125
 		return parameter.toString();
113 126
 	}
127
+
128
+	@Override
129
+	public StorageTag getStorage() {
130
+		return storage;
131
+	}
132
+
133
+	@Override
134
+	public ITypeID withoutStorage() {
135
+		return withoutStorage;
136
+	}
114 137
 }

+ 47
- 48
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java Просмотреть файл

@@ -11,12 +11,15 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
13 13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
+import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
15
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14 16
 
15 17
 /**
16 18
  *
17 19
  * @author Hoofdgebruiker
18 20
  */
19 21
 public class GlobalTypeRegistry {
22
+	private final Map<StringTypeID, StringTypeID> stringTypes = new HashMap<>();
20 23
 	private final Map<ArrayTypeID, ArrayTypeID> arrayTypes = new HashMap<>();
21 24
 	private final Map<AssocTypeID, AssocTypeID> assocTypes = new HashMap<>();
22 25
 	private final Map<GenericMapTypeID, GenericMapTypeID> genericMapTypes = new HashMap<>();
@@ -33,55 +36,47 @@ public class GlobalTypeRegistry {
33 36
 	public GlobalTypeRegistry(ZSPackage stdlib) {
34 37
 		this.stdlib = stdlib;
35 38
 		
36
-		arrayTypes.put(ArrayTypeID.INT, ArrayTypeID.INT);
37
-		arrayTypes.put(ArrayTypeID.CHAR, ArrayTypeID.CHAR);
39
+		stringTypes.put(StringTypeID.NOSTORAGE, StringTypeID.NOSTORAGE);
40
+		stringTypes.put(StringTypeID.ANY, StringTypeID.ANY);
41
+		stringTypes.put(StringTypeID.BORROW, StringTypeID.BORROW);
42
+		stringTypes.put(StringTypeID.SHARED, StringTypeID.SHARED);
43
+		stringTypes.put(StringTypeID.STATIC, StringTypeID.STATIC);
44
+		stringTypes.put(StringTypeID.UNIQUE, StringTypeID.UNIQUE);
45
+		
46
+		arrayTypes.put(ArrayTypeID.INT_UNIQUE, ArrayTypeID.INT_UNIQUE);
47
+		arrayTypes.put(ArrayTypeID.CHAR_UNIQUE, ArrayTypeID.CHAR_UNIQUE);
38 48
 		
39 49
 		rangeTypes.put(RangeTypeID.INT, RangeTypeID.INT);
40 50
 		rangeTypes.put(RangeTypeID.USIZE, RangeTypeID.USIZE);
41 51
 	}
42 52
 	
43
-	public ArrayTypeID getArray(ITypeID baseType, int dimension) {
44
-		ArrayTypeID id = new ArrayTypeID(this, baseType, dimension);
45
-		if (arrayTypes.containsKey(id)) {
46
-			return arrayTypes.get(id);
47
-		} else {
48
-			arrayTypes.put(id, id);
49
-			return id;
50
-		}
53
+	public StringTypeID getString(StorageTag storage) {
54
+		StringTypeID id = new StringTypeID(storage);
55
+		return internalize(stringTypes, id);
51 56
 	}
52 57
 	
53
-	public AssocTypeID getAssociative(ITypeID keyType, ITypeID valueType) {
54
-		AssocTypeID id = new AssocTypeID(this, keyType, valueType);
55
-		if (assocTypes.containsKey(id)) {
56
-			return assocTypes.get(id);
57
-		} else {
58
-			assocTypes.put(id, id);
59
-			return id;
60
-		}
58
+	public ArrayTypeID getArray(ITypeID baseType, int dimension, StorageTag storage) {
59
+		ArrayTypeID id = new ArrayTypeID(this, baseType, dimension, storage);
60
+		return internalize(arrayTypes, id);
61 61
 	}
62 62
 	
63
-	public GenericMapTypeID getGenericMap(ITypeID valueType, TypeParameter key) {
64
-		GenericMapTypeID id = new GenericMapTypeID(this, valueType, key);
65
-		if (genericMapTypes.containsKey(id)) {
66
-			return genericMapTypes.get(id);
67
-		} else {
68
-			genericMapTypes.put(id, id);
69
-			return id;
70
-		}
63
+	public AssocTypeID getAssociative(ITypeID keyType, ITypeID valueType, StorageTag storage) {
64
+		AssocTypeID id = new AssocTypeID(this, keyType, valueType, storage);
65
+		return internalize(assocTypes, id);
71 66
 	}
72 67
 	
73
-	public IteratorTypeID getIterator(ITypeID[] loopTypes) {
74
-		IteratorTypeID id = new IteratorTypeID(this, loopTypes);
75
-		if (iteratorTypes.containsKey(id)) {
76
-			return iteratorTypes.get(id);
77
-		} else {
78
-			iteratorTypes.put(id, id);
79
-			return id;
80
-		}
68
+	public GenericMapTypeID getGenericMap(ITypeID valueType, TypeParameter key, StorageTag storage) {
69
+		GenericMapTypeID id = new GenericMapTypeID(this, valueType, key, storage);
70
+		return internalize(genericMapTypes, id);
81 71
 	}
82 72
 	
83
-	public FunctionTypeID getFunction(FunctionHeader header) {
84
-		FunctionTypeID id = new FunctionTypeID(this, header);
73
+	public IteratorTypeID getIterator(ITypeID[] loopTypes, StorageTag storage) {
74
+		IteratorTypeID id = new IteratorTypeID(this, loopTypes, storage);
75
+		return internalize(iteratorTypes, id);
76
+	}
77
+	
78
+	public FunctionTypeID getFunction(FunctionHeader header, StorageTag storage) {
79
+		FunctionTypeID id = new FunctionTypeID(this, header, storage);
85 80
 		if (functionTypes.containsKey(id)) {
86 81
 			return functionTypes.get(id);
87 82
 		} else {
@@ -100,8 +95,8 @@ public class GlobalTypeRegistry {
100 95
 		}
101 96
 	}
102 97
 	
103
-	public GenericTypeID getGeneric(TypeParameter parameter) {
104
-		GenericTypeID id = new GenericTypeID(parameter);
98
+	public GenericTypeID getGeneric(TypeParameter parameter, StorageTag storage) {
99
+		GenericTypeID id = new GenericTypeID(this, parameter, storage);
105 100
 		if (genericTypes.containsKey(id)) {
106 101
 			return genericTypes.get(id);
107 102
 		} else {
@@ -115,21 +110,21 @@ public class GlobalTypeRegistry {
115 110
 		if (definition.getNumberOfGenericParameters() > 0) {
116 111
 			typeArguments = new ITypeID[definition.getNumberOfGenericParameters()];
117 112
 			for (int i = 0; i < definition.typeParameters.length; i++)
118
-				typeArguments[i] = getGeneric(definition.typeParameters[i]);
113
+				typeArguments[i] = getGeneric(definition.typeParameters[i], null);
119 114
 		}
120 115
 		DefinitionTypeID outer = null;
121 116
 		if (definition.outerDefinition != null)
122 117
 			outer = getForMyDefinition(definition.outerDefinition);
123 118
 		
124
-		return getForDefinition(definition, typeArguments, outer);
119
+		return getForDefinition(definition, typeArguments, outer, BorrowStorageTag.THIS);
125 120
 	}
126 121
 	
127
-	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID... genericArguments) {
128
-		return this.getForDefinition(definition, genericArguments, null);
122
+	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, StorageTag storage, ITypeID... genericArguments) {
123
+		return this.getForDefinition(definition, genericArguments, null, storage);
129 124
 	}
130 125
 	
131
-	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] typeParameters, DefinitionTypeID outer) {
132
-		DefinitionTypeID id = new DefinitionTypeID(this, definition, typeParameters, definition.isStatic() ? null : outer);
126
+	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] typeParameters, DefinitionTypeID outer, StorageTag storage) {
127
+		DefinitionTypeID id = new DefinitionTypeID(this, definition, typeParameters, definition.isStatic() ? null : outer, storage);
133 128
 		
134 129
 		if (definitionTypes.containsKey(id)) {
135 130
 			return definitionTypes.get(id);
@@ -152,11 +147,15 @@ public class GlobalTypeRegistry {
152 147
 		}
153 148
 		
154 149
 		ModifiedTypeID result = new ModifiedTypeID(this, modifiers, type);
155
-		if (modifiedTypes.containsKey(result)) {
156
-			return modifiedTypes.get(result);
150
+		return internalize(modifiedTypes, result);
151
+	}
152
+	
153
+	private <T> T internalize(Map<T, T> identityMap, T id) {
154
+		if (identityMap.containsKey(id)) {
155
+			return identityMap.get(id);
157 156
 		} else {
158
-			modifiedTypes.put(result, result);
159
-			return result;
157
+			identityMap.put(id, id);
158
+			return id;
160 159
 		}
161 160
 	}
162 161
 }

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ISymbol.java Просмотреть файл

@@ -9,6 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
10 10
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11 11
 import org.openzen.zenscript.codemodel.scope.BaseScope;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
12 13
 
13 14
 /**
14 15
  *
@@ -17,5 +18,5 @@ import org.openzen.zenscript.codemodel.scope.BaseScope;
17 18
 public interface ISymbol {
18 19
 	public IPartialExpression getExpression(CodePosition position, BaseScope scope, ITypeID[] typeArguments);
19 20
 	
20
-	public ITypeID getType(CodePosition position, TypeResolutionContext context, ITypeID[] typeArguments);
21
+	public ITypeID getType(CodePosition position, TypeResolutionContext context, ITypeID[] typeArguments, StorageTag storage);
21 22
 }

+ 10
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java Просмотреть файл

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13 13
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
14
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14 15
 
15 16
 /**
16 17
  *
@@ -55,6 +56,10 @@ public interface ITypeID {
55 56
 		throw new UnsupportedOperationException("Not an immutable type");
56 57
 	}
57 58
 	
59
+	public ITypeID withoutStorage();
60
+	
61
+	public StorageTag getStorage();
62
+	
58 63
 	public boolean hasDefaultValue();
59 64
 	
60 65
 	public boolean isObjectType();
@@ -73,6 +78,8 @@ public interface ITypeID {
73 78
 	
74 79
 	public ITypeID instance(GenericMapper mapper);
75 80
 	
81
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage);
82
+	
76 83
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);
77 84
 	
78 85
 	// Infers type parameters for this type so it matches with targetType
@@ -177,9 +184,9 @@ public interface ITypeID {
177 184
 				if (definitionType.definition != definition.definition)
178 185
 					return false;
179 186
 				
180
-				if (definition.typeParameters != null) {
181
-					for (int i = 0; i < definitionType.typeParameters.length; i++) {
182
-						if (!match(definitionType.typeParameters[i], definition.typeParameters[i]))
187
+				if (definition.typeArguments != null) {
188
+					for (int i = 0; i < definitionType.typeArguments.length; i++) {
189
+						if (!match(definitionType.typeArguments[i], definition.typeArguments[i]))
183 190
 							return false;
184 191
 					}
185 192
 				}

+ 27
- 8
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java Просмотреть файл

@@ -7,9 +7,10 @@ package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import java.util.Arrays;
9 9
 import java.util.List;
10
-import java.util.Map;
10
+import java.util.Objects;
11 11
 import org.openzen.zenscript.codemodel.GenericMapper;
12 12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
13 14
 
14 15
 /**
15 16
  *
@@ -17,12 +18,16 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
17 18
  */
18 19
 public class IteratorTypeID implements ITypeID {
19 20
 	public final ITypeID[] iteratorTypes;
21
+	public final StorageTag storage;
20 22
 	private final IteratorTypeID normalized;
23
+	private final IteratorTypeID withoutStorage;
21 24
 	
22
-	public IteratorTypeID(GlobalTypeRegistry registry, ITypeID[] iteratorTypes) {
25
+	public IteratorTypeID(GlobalTypeRegistry registry, ITypeID[] iteratorTypes, StorageTag storage) {
23 26
 		this.iteratorTypes = iteratorTypes;
27
+		this.storage = storage;
24 28
 		
25 29
 		normalized = isDenormalized() ? normalize(registry) : this;
30
+		withoutStorage = storage == null ? this : registry.getIterator(iteratorTypes, null);
26 31
 	}
27 32
 	
28 33
 	@Override
@@ -42,7 +47,7 @@ public class IteratorTypeID implements ITypeID {
42 47
 		ITypeID[] normalizedTypes = new ITypeID[iteratorTypes.length];
43 48
 		for (int i = 0; i < normalizedTypes.length; i++)
44 49
 			normalizedTypes[i] = iteratorTypes[i].getNormalized();
45
-		return registry.getIterator(normalizedTypes);
50
+		return registry.getIterator(normalizedTypes, storage);
46 51
 	}
47 52
 
48 53
 	@Override
@@ -80,7 +85,12 @@ public class IteratorTypeID implements ITypeID {
80 85
 		ITypeID[] instanced = new ITypeID[iteratorTypes.length];
81 86
 		for (int i = 0; i < iteratorTypes.length; i++)
82 87
 			instanced[i] = iteratorTypes[i].instance(mapper);
83
-		return mapper.registry.getIterator(instanced);
88
+		return mapper.registry.getIterator(instanced, storage);
89
+	}
90
+	
91
+	@Override
92
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
93
+		return registry.getIterator(iteratorTypes, storage);
84 94
 	}
85 95
 
86 96
 	@Override
@@ -107,6 +117,7 @@ public class IteratorTypeID implements ITypeID {
107 117
 	public int hashCode() {
108 118
 		int hash = 5;
109 119
 		hash = 13 * hash + Arrays.deepHashCode(this.iteratorTypes);
120
+		hash = 13 * hash + Objects.hashCode(storage);
110 121
 		return hash;
111 122
 	}
112 123
 
@@ -122,9 +133,17 @@ public class IteratorTypeID implements ITypeID {
122 133
 			return false;
123 134
 		}
124 135
 		final IteratorTypeID other = (IteratorTypeID) obj;
125
-		if (!Arrays.deepEquals(this.iteratorTypes, other.iteratorTypes)) {
126
-			return false;
127
-		}
128
-		return true;
136
+		return Arrays.deepEquals(this.iteratorTypes, other.iteratorTypes)
137
+				&& Objects.equals(this.storage, other.storage);
138
+	}
139
+
140
+	@Override
141
+	public StorageTag getStorage() {
142
+		return storage;
143
+	}
144
+
145
+	@Override
146
+	public ITypeID withoutStorage() {
147
+		return withoutStorage;
129 148
 	}
130 149
 }

+ 24
- 7
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ModifiedTypeID.java Просмотреть файл

@@ -10,6 +10,7 @@ import java.util.Objects;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
13 14
 
14 15
 /**
15 16
  *
@@ -24,6 +25,7 @@ public class ModifiedTypeID implements ITypeID {
24 25
 	public final ITypeID baseType;
25 26
 	private final ITypeID normalized;
26 27
 	private final GlobalTypeRegistry registry;
28
+	private final ITypeID withoutStorage;
27 29
 	
28 30
 	public ModifiedTypeID(GlobalTypeRegistry registry, int modifiers, ITypeID baseType) {
29 31
 		this.modifiers = modifiers;
@@ -31,6 +33,7 @@ public class ModifiedTypeID implements ITypeID {
31 33
 		this.registry = registry;
32 34
 		
33 35
 		normalized = baseType.getNormalized() == baseType ? this : registry.getModified(modifiers, baseType.getNormalized());
36
+		withoutStorage = baseType.withoutStorage() == baseType ? this : registry.getModified(modifiers, baseType.withoutStorage());
34 37
 	}
35 38
 	
36 39
 	@Override
@@ -43,6 +46,11 @@ public class ModifiedTypeID implements ITypeID {
43 46
 		return mapper.registry.getModified(modifiers, baseType.instance(mapper));
44 47
 	}
45 48
 	
49
+	@Override
50
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
51
+		return registry.getModified(modifiers, baseType.withStorage(registry, storage));
52
+	}
53
+	
46 54
 	@Override
47 55
 	public <T> T accept(TypeVisitor<T> visitor) {
48 56
 		return visitor.visitModified(this);
@@ -122,22 +130,21 @@ public class ModifiedTypeID implements ITypeID {
122 130
 	public int hashCode() {
123 131
 		int hash = 3;
124 132
 		hash = 79 * hash + Objects.hashCode(this.baseType);
133
+		hash = 79 * hash + modifiers;
125 134
 		return hash;
126 135
 	}
127 136
 
128 137
 	@Override
129 138
 	public boolean equals(Object obj) {
130
-		if (this == obj) {
139
+		if (this == obj)
131 140
 			return true;
132
-		}
133
-		if (obj == null) {
141
+		if (obj == null)
134 142
 			return false;
135
-		}
136
-		if (getClass() != obj.getClass()) {
143
+		if (getClass() != obj.getClass())
137 144
 			return false;
138
-		}
139 145
 		final ModifiedTypeID other = (ModifiedTypeID) obj;
140
-		return this.baseType == other.baseType;
146
+		return this.baseType == other.baseType
147
+				&& this.modifiers == other.modifiers;
141 148
 	}
142 149
 	
143 150
 	@Override
@@ -152,4 +159,14 @@ public class ModifiedTypeID implements ITypeID {
152 159
 			result.append("?");
153 160
 		return result.toString();
154 161
 	}
162
+
163
+	@Override
164
+	public StorageTag getStorage() {
165
+		return baseType.getStorage();
166
+	}
167
+
168
+	@Override
169
+	public ITypeID withoutStorage() {
170
+		return withoutStorage;
171
+	}
155 172
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java Просмотреть файл

@@ -8,6 +8,8 @@ package org.openzen.zenscript.codemodel.type;
8 8
 import java.util.List;
9 9
 import org.openzen.zenscript.codemodel.GenericMapper;
10 10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
12
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
11 13
 
12 14
 /**
13 15
  *
@@ -39,6 +41,11 @@ public class RangeTypeID implements ITypeID {
39 41
 	public ITypeID instance(GenericMapper mapper) {
40 42
 		return mapper.registry.getRange(baseType.instance(mapper));
41 43
 	}
44
+	
45
+	@Override
46
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
47
+		return registry.getRange(baseType.withStorage(registry, storage));
48
+	}
42 49
 
43 50
 	@Override
44 51
 	public <T> T accept(TypeVisitor<T> visitor) {
@@ -111,4 +118,14 @@ public class RangeTypeID implements ITypeID {
111 118
 	public String toString() {
112 119
 		return baseType.toString() + " .. " + baseType.toString();
113 120
 	}
121
+
122
+	@Override
123
+	public StorageTag getStorage() {
124
+		return ValueStorageTag.INSTANCE;
125
+	}
126
+
127
+	@Override
128
+	public ITypeID withoutStorage() {
129
+		return this;
130
+	}
114 131
 }

+ 48
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StringTypeID.java Просмотреть файл

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import java.util.List;
9
+import java.util.Objects;
9 10
 import org.openzen.zenscript.codemodel.GenericMapper;
10 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11 12
 import org.openzen.zenscript.codemodel.type.storage.AnyStorageTag;
@@ -25,6 +26,7 @@ public class StringTypeID implements ITypeID {
25 26
 	public static final StringTypeID UNIQUE = new StringTypeID(UniqueStorageTag.INSTANCE);
26 27
 	public static final StringTypeID BORROW = new StringTypeID(BorrowStorageTag.INVOCATION);
27 28
 	public static final StringTypeID SHARED = new StringTypeID(SharedStorageTag.INSTANCE);
29
+	public static final StringTypeID NOSTORAGE = new StringTypeID(null);
28 30
 	
29 31
 	public final StorageTag storage;
30 32
 	
@@ -64,16 +66,59 @@ public class StringTypeID implements ITypeID {
64 66
 
65 67
 	@Override
66 68
 	public ITypeID instance(GenericMapper mapper) {
67
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
69
+		return this;
70
+	}
71
+	
72
+	@Override
73
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
74
+		return registry.getString(storage);
68 75
 	}
69 76
 
70 77
 	@Override
71 78
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
72
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
79
+		return false;
73 80
 	}
74 81
 
75 82
 	@Override
76 83
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
77
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
84
+		
85
+	}
86
+	
87
+	@Override
88
+	public String toString() {
89
+		if (storage == null)
90
+			return "string";
91
+		
92
+		return "string`" + storage.toString();
93
+	}
94
+
95
+	@Override
96
+	public int hashCode() {
97
+		int hash = 5;
98
+		hash = 97 * hash + Objects.hashCode(this.storage);
99
+		return hash;
100
+	}
101
+
102
+	@Override
103
+	public boolean equals(Object obj) {
104
+		if (this == obj)
105
+			return true;
106
+		if (obj == null)
107
+			return false;
108
+		if (getClass() != obj.getClass())
109
+			return false;
110
+		
111
+		final StringTypeID other = (StringTypeID) obj;
112
+		return Objects.equals(this.storage, other.storage);
113
+	}
114
+
115
+	@Override
116
+	public StorageTag getStorage() {
117
+		return storage;
118
+	}
119
+
120
+	@Override
121
+	public ITypeID withoutStorage() {
122
+		return NOSTORAGE;
78 123
 	}
79 124
 }

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeParameterCollector.java Просмотреть файл

@@ -65,7 +65,7 @@ public class TypeParameterCollector implements TypeVisitor<Void> {
65 65
 
66 66
 	@Override
67 67
 	public Void visitDefinition(DefinitionTypeID definition) {
68
-		for (ITypeID argument : definition.typeParameters)
68
+		for (ITypeID argument : definition.typeArguments)
69 69
 			argument.accept(this);
70 70
 		if (definition.outer != null)
71 71
 			visitDefinition(definition.outer);

+ 4
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeSymbol.java Просмотреть файл

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
11 11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12 12
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
13 13
 import org.openzen.zenscript.codemodel.scope.BaseScope;
14
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14 15
 
15 16
 /**
16 17
  *
@@ -25,11 +26,11 @@ public class TypeSymbol implements ISymbol {
25 26
 	
26 27
 	@Override
27 28
 	public IPartialExpression getExpression(CodePosition position, BaseScope scope, ITypeID[] typeArguments) {
28
-		return new PartialTypeExpression(position, scope.getTypeRegistry().getForDefinition(definition, typeArguments), typeArguments);
29
+		return new PartialTypeExpression(position, scope.getTypeRegistry().getForDefinition(definition, null, typeArguments), typeArguments);
29 30
 	}
30 31
 
31 32
 	@Override
32
-	public ITypeID getType(CodePosition position, TypeResolutionContext context, ITypeID[] typeArguments) {
33
-		return context.getTypeRegistry().getForDefinition(definition, typeArguments);
33
+	public ITypeID getType(CodePosition position, TypeResolutionContext context, ITypeID[] typeArguments, StorageTag storage) {
34
+		return context.getTypeRegistry().getForDefinition(definition, storage, typeArguments);
34 35
 	}
35 36
 }

+ 16
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/UnstoredTypeID.java Просмотреть файл

@@ -0,0 +1,16 @@
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.type;
7
+
8
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface UnstoredTypeID {
15
+	ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage);
16
+}

+ 25
- 21
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java Просмотреть файл

@@ -73,6 +73,10 @@ import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
73 73
 import org.openzen.zenscript.codemodel.member.IteratorMember;
74 74
 import org.openzen.zenscript.codemodel.type.StringTypeID;
75 75
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
76
+import org.openzen.zenscript.codemodel.type.storage.AnyStorageTag;
77
+import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
78
+import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
79
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
76 80
 
77 81
 /**
78 82
  *
@@ -173,7 +177,7 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
173 177
 	public Void visitString(StringTypeID string) {
174 178
 		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "string", Modifiers.EXPORT, null);
175 179
 		
176
-		constructor(builtin, STRING_CONSTRUCTOR_CHARACTERS, registry.getArray(CHAR, 1));
180
+		constructor(builtin, STRING_CONSTRUCTOR_CHARACTERS, registry.getModified(ModifiedTypeID.MODIFIER_CONST, registry.getArray(CHAR, 1, BorrowStorageTag.INVOCATION)));
177 181
 		
178 182
 		add(builtin, STRING_ADD_STRING, StringTypeID.BORROW, StringTypeID.UNIQUE);
179 183
 		indexGet(builtin, STRING_INDEXGET, USIZE, CHAR);
@@ -181,7 +185,7 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
181 185
 		compare(builtin, STRING_COMPARE, StringTypeID.BORROW);
182 186
 		
183 187
 		getter(builtin, STRING_LENGTH, "length", USIZE);
184
-		getter(builtin, STRING_CHARACTERS, "characters", registry.getArray(CHAR, 1));
188
+		getter(builtin, STRING_CHARACTERS, "characters", registry.getArray(CHAR, 1, UniqueStorageTag.INSTANCE)); // TODO: can this be const borrowed / immutable borrowed?
185 189
 		getter(builtin, STRING_ISEMPTY, "isEmpty", BOOL);
186 190
 
187 191
 		method(builtin, STRING_REMOVE_DIACRITICS, "removeDiacritics", StringTypeID.BORROW);
@@ -220,21 +224,21 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
220 224
 					ARRAY_INDEXGETRANGE);
221 225
 			
222 226
 			if (baseType == BYTE)
223
-				castImplicit(definition, BYTE_ARRAY_AS_SBYTE_ARRAY, registry.getArray(SBYTE, 1));
227
+				castImplicit(definition, BYTE_ARRAY_AS_SBYTE_ARRAY, registry.getArray(SBYTE, 1, array.storage));
224 228
 			if (baseType == SBYTE)
225
-				castImplicit(definition, SBYTE_ARRAY_AS_BYTE_ARRAY, registry.getArray(BYTE, 1));
229
+				castImplicit(definition, SBYTE_ARRAY_AS_BYTE_ARRAY, registry.getArray(BYTE, 1, array.storage));
226 230
 			if (baseType == SHORT)
227
-				castImplicit(definition, SHORT_ARRAY_AS_USHORT_ARRAY, registry.getArray(USHORT, 1));
231
+				castImplicit(definition, SHORT_ARRAY_AS_USHORT_ARRAY, registry.getArray(USHORT, 1, array.storage));
228 232
 			if (baseType == USHORT)
229
-				castImplicit(definition, USHORT_ARRAY_AS_SHORT_ARRAY, registry.getArray(SHORT, 1));
233
+				castImplicit(definition, USHORT_ARRAY_AS_SHORT_ARRAY, registry.getArray(SHORT, 1, array.storage));
230 234
 			if (baseType == INT)
231
-				castImplicit(definition, INT_ARRAY_AS_UINT_ARRAY, registry.getArray(UINT, 1));
235
+				castImplicit(definition, INT_ARRAY_AS_UINT_ARRAY, registry.getArray(UINT, 1, array.storage));
232 236
 			if (baseType == UINT)
233
-				castImplicit(definition, UINT_ARRAY_AS_INT_ARRAY, registry.getArray(INT, 1));
237
+				castImplicit(definition, UINT_ARRAY_AS_INT_ARRAY, registry.getArray(INT, 1, array.storage));
234 238
 			if (baseType == LONG)
235
-				castImplicit(definition, LONG_ARRAY_AS_ULONG_ARRAY, registry.getArray(ULONG, 1));
239
+				castImplicit(definition, LONG_ARRAY_AS_ULONG_ARRAY, registry.getArray(ULONG, 1, array.storage));
236 240
 			if (baseType == ULONG)
237
-				castImplicit(definition, ULONG_ARRAY_AS_LONG_ARRAY, registry.getArray(LONG, 1));
241
+				castImplicit(definition, ULONG_ARRAY_AS_LONG_ARRAY, registry.getArray(LONG, 1, array.storage));
238 242
 		}
239 243
 
240 244
 		FunctionHeader containsHeader = new FunctionHeader(BOOL, new FunctionParameter(baseType, "value"));
@@ -271,7 +275,7 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
271 275
 			lambdaConstructorParameters[i] = new FunctionParameter(USIZE, null);
272 276
 		
273 277
 		FunctionHeader lambdaConstructorFunction = new FunctionHeader(baseType, indexGetParameters);
274
-		lambdaConstructorParameters[dimension] = new FunctionParameter(cache.getRegistry().getFunction(lambdaConstructorFunction), null);
278
+		lambdaConstructorParameters[dimension] = new FunctionParameter(cache.getRegistry().getFunction(lambdaConstructorFunction, BorrowStorageTag.INVOCATION), null);
275 279
 		FunctionHeader lambdaConstructorHeader = new FunctionHeader(VOID, lambdaConstructorParameters);
276 280
 		members.addConstructor(new ConstructorMember(
277 281
 				BUILTIN,
@@ -282,13 +286,13 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
282 286
 		
283 287
 		{
284 288
 			TypeParameter mappedConstructorParameter = new TypeParameter(BUILTIN, "T");
285
-			FunctionHeader mappedConstructorHeaderWithoutIndex = new FunctionHeader(baseType, registry.getGeneric(mappedConstructorParameter));
289
+			FunctionHeader mappedConstructorHeaderWithoutIndex = new FunctionHeader(baseType, registry.getGeneric(mappedConstructorParameter, BorrowStorageTag.INVOCATION));
286 290
 			FunctionHeader mappedConstructorFunctionWithoutIndex = new FunctionHeader(
287 291
 					new TypeParameter[] { mappedConstructorParameter },
288 292
 					VOID,
289 293
 					null,
290
-					new FunctionParameter(registry.getArray(registry.getGeneric(mappedConstructorParameter), dimension), "original"),
291
-					new FunctionParameter(registry.getFunction(mappedConstructorHeaderWithoutIndex), "projection"));
294
+					new FunctionParameter(registry.getArray(registry.getGeneric(mappedConstructorParameter, BorrowStorageTag.INVOCATION), dimension, BorrowStorageTag.INVOCATION), "original"),
295
+					new FunctionParameter(registry.getFunction(mappedConstructorHeaderWithoutIndex, BorrowStorageTag.INVOCATION), "projection"));
292 296
 			members.addConstructor(new ConstructorMember(
293 297
 					BUILTIN,
294 298
 					definition,
@@ -302,15 +306,15 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
302 306
 			FunctionParameter[] projectionParameters = new FunctionParameter[dimension + 1];
303 307
 			for (int i = 0; i < dimension; i++)
304 308
 				projectionParameters[i] = new FunctionParameter(USIZE);
305
-			projectionParameters[dimension] = new FunctionParameter(registry.getGeneric(mappedConstructorParameter));
309
+			projectionParameters[dimension] = new FunctionParameter(registry.getGeneric(mappedConstructorParameter, BorrowStorageTag.INVOCATION));
306 310
 			
307 311
 			FunctionHeader mappedConstructorHeaderWithIndex = new FunctionHeader(baseType, projectionParameters);
308 312
 			FunctionHeader mappedConstructorFunctionWithIndex = new FunctionHeader(
309 313
 					new TypeParameter[] { mappedConstructorParameter },
310 314
 					VOID,
311 315
 					null,
312
-					new FunctionParameter(registry.getArray(registry.getGeneric(mappedConstructorParameter), dimension), "original"),
313
-					new FunctionParameter(registry.getFunction(mappedConstructorHeaderWithIndex), "projection"));
316
+					new FunctionParameter(registry.getArray(registry.getGeneric(mappedConstructorParameter, BorrowStorageTag.INVOCATION), dimension, BorrowStorageTag.INVOCATION), "original"),
317
+					new FunctionParameter(registry.getFunction(mappedConstructorHeaderWithIndex, BorrowStorageTag.INVOCATION), "projection"));
314 318
 			constructor(definition, ARRAY_CONSTRUCTOR_PROJECTED_INDEXED, mappedConstructorFunctionWithIndex);
315 319
 		}
316 320
 		
@@ -362,8 +366,8 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
362 366
 		
363 367
 		getter(builtin, BuiltinID.ASSOC_SIZE, "size", USIZE);
364 368
 		getter(builtin, BuiltinID.ASSOC_ISEMPTY, "isEmpty", BOOL);
365
-		getter(builtin, BuiltinID.ASSOC_KEYS, "keys", cache.getRegistry().getArray(keyType, 1));
366
-		getter(builtin, BuiltinID.ASSOC_VALUES, "values", cache.getRegistry().getArray(valueType, 1));
369
+		getter(builtin, BuiltinID.ASSOC_KEYS, "keys", cache.getRegistry().getArray(keyType, 1, UniqueStorageTag.INSTANCE));
370
+		getter(builtin, BuiltinID.ASSOC_VALUES, "values", cache.getRegistry().getArray(valueType, 1, UniqueStorageTag.INSTANCE));
367 371
 		getter(builtin, BuiltinID.ASSOC_HASHCODE, "objectHashCode", BasicTypeID.INT);
368 372
 		
369 373
 		iterator(builtin, ITERATOR_ASSOC_KEYS, keyType);
@@ -381,7 +385,7 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
381 385
 	@Override
382 386
 	public Void visitGenericMap(GenericMapTypeID map) {
383 387
 		TypeParameter functionParameter = new TypeParameter(BUILTIN, "T");
384
-		Map<TypeParameter, ITypeID> parameterFilled = Collections.singletonMap(map.key, registry.getGeneric(functionParameter));
388
+		Map<TypeParameter, ITypeID> parameterFilled = Collections.singletonMap(map.key, registry.getGeneric(functionParameter, null));
385 389
 		ITypeID valueType = map.value.instance(new GenericMapper(registry, parameterFilled));
386 390
 		
387 391
 		FunctionHeader getOptionalHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, registry.getOptional(valueType), null, new FunctionParameter[0]);
@@ -496,7 +500,7 @@ public class TypeMemberBuilder implements TypeVisitor<Void> {
496 500
 			for (int i = 0; i < constValues.length; i++)
497 501
 				constValues[i] = new EnumConstantExpression(BUILTIN, type, enumConstants.get(i));
498 502
 			
499
-			constant(definition, ENUM_VALUES, "values", new ArrayExpression(BUILTIN, constValues, registry.getArray(type, 1)));
503
+			constant(definition, ENUM_VALUES, "values", new ArrayExpression(BUILTIN, constValues, registry.getArray(type, 1, StaticStorageTag.INSTANCE)));
500 504
 			compare(definition, ENUM_COMPARE, type);
501 505
 			
502 506
 			if (!members.canCast(StringTypeID.STATIC)) {

+ 41
- 18
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java Просмотреть файл

@@ -21,6 +21,7 @@ import org.openzen.zenscript.codemodel.expression.Expression;
21 21
 import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
22 22
 import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
23 23
 import org.openzen.zenscript.codemodel.expression.NullExpression;
24
+import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
24 25
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
25 26
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
26 27
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
@@ -47,6 +48,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
47 48
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
48 49
 import org.openzen.zenscript.codemodel.type.ITypeID;
49 50
 import org.openzen.zenscript.codemodel.scope.TypeScope;
51
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
50 52
 
51 53
 /**
52 54
  *
@@ -81,7 +83,7 @@ public final class TypeMembers {
81 83
 	}
82 84
 	
83 85
 	public boolean extendsOrImplements(ITypeID other) {
84
-		other = other.getNormalized();
86
+		other = other.getNormalized().withoutStorage();
85 87
 		ITypeID superType = type.getSuperType(cache.getRegistry());
86 88
 		if (superType != null) {
87 89
 			if (superType == other)
@@ -397,29 +399,41 @@ public final class TypeMembers {
397 399
 	
398 400
 	public boolean canCastImplicit(ITypeID toType) {
399 401
 		toType = toType.getNormalized();
400
-		if (toType == type)
402
+		if (areEquivalent(type, toType))
401 403
 			return true;
402
-		if (toType == null)
403
-			throw new NullPointerException();
404 404
 		if (toType == BasicTypeID.UNDETERMINED)
405 405
 			throw new IllegalArgumentException("Cannot cast to undetermined type!");
406
-		
407 406
 		if (type == BasicTypeID.NULL && toType.isOptional())
408 407
 			return true;
408
+		
409
+		if (!type.getStorage().canCastTo(toType.getStorage()) && !toType.getStorage().canCastFrom(type.getStorage()))
410
+			return false;
411
+		
409 412
 		if (toType.isOptional() && canCastImplicit(toType.withoutOptional()))
410 413
 			return true;
411 414
 		if (toType.isConst() && canCastImplicit(toType.withoutConst()))
412 415
 			return true;
413
-		if (type.isOptional() && type.withoutOptional() == toType)
416
+		if (type.isOptional() && areEquivalent(type.withoutOptional(), toType))
414 417
 			return true;
415 418
 		
416 419
 		return getImplicitCaster(toType) != null || extendsOrImplements(toType);
417 420
 	}
418 421
 	
422
+	private boolean areEquivalent(ITypeID fromType, ITypeID toType) {
423
+		if (fromType == toType)
424
+			return true;
425
+		if (fromType.getStorage() == null || toType.getStorage() == null)
426
+			throw new NullPointerException();
427
+		if (!fromType.getStorage().canCastTo(toType.getStorage()) && !toType.getStorage().canCastFrom(fromType.getStorage()))
428
+			return false;
429
+		
430
+		return fromType.withoutStorage() == toType.withoutStorage();
431
+	}
432
+	
419 433
 	public CasterMemberRef getImplicitCaster(ITypeID toType) {
420 434
 		toType = toType.getNormalized();
421 435
 		for (TypeMember<CasterMemberRef> caster : casters) {
422
-			if (caster.member.isImplicit() && toType == caster.member.toType)
436
+			if (caster.member.isImplicit() && areEquivalent(caster.member.toType, toType))
423 437
 				return caster.member;
424 438
 		}
425 439
 		
@@ -429,7 +443,7 @@ public final class TypeMembers {
429 443
 	public CasterMemberRef getCaster(ITypeID toType) {
430 444
 		toType = toType.getNormalized();
431 445
 		for (TypeMember<CasterMemberRef> caster : casters) {
432
-			if (toType == caster.member.toType)
446
+			if (areEquivalent(caster.member.toType, toType))
433 447
 				return caster.member;
434 448
 		}
435 449
 		
@@ -442,32 +456,41 @@ public final class TypeMembers {
442 456
 			return true;
443 457
 		
444 458
 		for (TypeMember<CasterMemberRef> caster : casters) {
445
-			if (toType == caster.member.toType)
459
+			if (areEquivalent(caster.member.toType, toType))
446 460
 				return true;
447 461
 		}
448 462
 		
449 463
 		return false;
450 464
 	}
451 465
 	
466
+	private Expression castEquivalent(CodePosition position, Expression value, ITypeID toType) {
467
+		if (toType == value.type)
468
+			return value;
469
+		
470
+		return new StorageCastExpression(position, value, toType);
471
+	}
472
+	
452 473
 	public Expression castImplicit(CodePosition position, Expression value, ITypeID toType, boolean implicit) {
453 474
 		toType = toType.getNormalized();
454 475
 		if (toType == type || toType == BasicTypeID.UNDETERMINED)
455 476
 			return value;
477
+		if (toType.withoutStorage() == type.withoutStorage())
478
+			return new StorageCastExpression(position, value, toType);
456 479
 		if (toType == null)
457 480
 			throw new NullPointerException();
458 481
 		
459 482
 		if (type == BasicTypeID.NULL && toType.isOptional())
460 483
 			return new NullExpression(position, toType);
461 484
 		if (toType.isOptional() && canCastImplicit(toType.withoutOptional()))
462
-			return new WrapOptionalExpression(position, castImplicit(position, value, toType.withoutOptional(), implicit), toType);
485
+			return castEquivalent(position, new WrapOptionalExpression(position, castImplicit(position, value, toType.withoutOptional(), implicit), toType), toType);
463 486
 		if (toType.isConst() && canCastImplicit(toType.withoutConst()))
464
-			return new MakeConstExpression(position, castImplicit(position, value, toType.withoutConst(), implicit), toType);
465
-		if (type.isOptional() && type.withoutOptional() == toType)
466
-			return new CheckNullExpression(position, value);
487
+			return castEquivalent(position, new MakeConstExpression(position, castImplicit(position, value, toType.withoutConst(), implicit), toType), toType);
488
+		if (type.isOptional() && areEquivalent(type.withoutOptional(), toType))
489
+			return castEquivalent(position, new CheckNullExpression(position, value), toType);
467 490
 		
468 491
 		for (TypeMember<CasterMemberRef> caster : casters) {
469
-			if (caster.member.isImplicit() && toType == caster.member.toType)
470
-				return caster.member.cast(position, value, implicit);
492
+			if (caster.member.isImplicit() && areEquivalent(caster.member.toType, toType))
493
+				return castEquivalent(position, caster.member.cast(position, value, implicit), toType);
471 494
 		}
472 495
 		for (TypeMember<ImplementationMemberRef> implementation : implementations) {
473 496
 			if (implementation.member.implementsType.equals(toType))
@@ -512,7 +535,7 @@ public final class TypeMembers {
512 535
 		if (members.containsKey(name.name))
513 536
 			return new PartialStaticMemberGroupExpression(position, scope, type, members.get(name.name), name.arguments);
514 537
 		if (innerTypes.containsKey(name.name))
515
-			return new PartialTypeExpression(position, innerTypes.get(name.name).instance(cache.getRegistry(), name.arguments, (DefinitionTypeID)type), name.arguments);
538
+			return new PartialTypeExpression(position, innerTypes.get(name.name).instance(cache.getRegistry(), name.arguments, (DefinitionTypeID)type, null), name.arguments);
516 539
 		if (variantOptions.containsKey(name.name))
517 540
 			return new PartialVariantOptionExpression(position, scope, variantOptions.get(name.name));
518 541
 		
@@ -523,11 +546,11 @@ public final class TypeMembers {
523 546
 		return innerTypes.containsKey(name);
524 547
 	}
525 548
 	
526
-	public DefinitionTypeID getInnerType(CodePosition position, GenericName name) {
549
+	public DefinitionTypeID getInnerType(CodePosition position, GenericName name, StorageTag storage) {
527 550
 		if (!innerTypes.containsKey(name.name))
528 551
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_INNER_TYPE, "No such inner type in " + type + ": " + name.name);
529 552
 		
530
-		return innerTypes.get(name.name).instance(cache.getRegistry(), name.arguments, (DefinitionTypeID)type);
553
+		return innerTypes.get(name.name).instance(cache.getRegistry(), name.arguments, (DefinitionTypeID)type, storage);
531 554
 	}
532 555
 	
533 556
 	@Override

+ 15
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/AnyStorageTag.java Просмотреть файл

@@ -18,4 +18,19 @@ public class AnyStorageTag implements StorageTag {
18 18
 	public StorageType getType() {
19 19
 		return AnyStorageType.INSTANCE;
20 20
 	}
21
+	
22
+	@Override
23
+	public String toString() {
24
+		return "any";
25
+	}
26
+
27
+	@Override
28
+	public boolean canCastTo(StorageTag other) {
29
+		return other == BorrowStorageTag.INVOCATION;
30
+	}
31
+
32
+	@Override
33
+	public boolean canCastFrom(StorageTag other) {
34
+		return true;
35
+	}
21 36
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/AnyStorageType.java Просмотреть файл

@@ -5,6 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.type.storage;
7 7
 
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zencode.shared.CompileExceptionCode;
11
+
8 12
 /**
9 13
  *
10 14
  * @author Hoofdgebruiker
@@ -13,4 +17,17 @@ public class AnyStorageType implements StorageType {
13 17
 	public static final AnyStorageType INSTANCE = new AnyStorageType();
14 18
 	
15 19
 	private AnyStorageType() {}
20
+
21
+	@Override
22
+	public String getName() {
23
+		return "any";
24
+	}
25
+
26
+	@Override
27
+	public StorageTag instance(CodePosition position, String[] arguments) {
28
+		if (arguments != null)
29
+			throw new CompileException(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "any storage type doesn't take arguments");
30
+		
31
+		return AnyStorageTag.INSTANCE;
32
+	}
16 33
 }

+ 16
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/BorrowStorageTag.java Просмотреть файл

@@ -11,6 +11,7 @@ package org.openzen.zenscript.codemodel.type.storage;
11 11
  */
12 12
 public class BorrowStorageTag implements StorageTag {
13 13
 	public static final BorrowStorageTag INVOCATION = new BorrowStorageTag();
14
+	public static final BorrowStorageTag THIS = new BorrowStorageTag();
14 15
 	
15 16
 	private BorrowStorageTag() {} // TODO: scoped borrow
16 17
 
@@ -18,4 +19,19 @@ public class BorrowStorageTag implements StorageTag {
18 19
 	public StorageType getType() {
19 20
 		return BorrowStorageType.INSTANCE;
20 21
 	}
22
+	
23
+	@Override
24
+	public String toString() {
25
+		return "borrow";
26
+	}
27
+
28
+	@Override
29
+	public boolean canCastTo(StorageTag other) {
30
+		return this == other;
31
+	}
32
+
33
+	@Override
34
+	public boolean canCastFrom(StorageTag other) {
35
+		return true;
36
+	}
21 37
 }

+ 21
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/BorrowStorageType.java Просмотреть файл

@@ -5,6 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.type.storage;
7 7
 
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zencode.shared.CompileExceptionCode;
11
+
8 12
 /**
9 13
  *
10 14
  * @author Hoofdgebruiker
@@ -13,4 +17,21 @@ public class BorrowStorageType implements StorageType {
13 17
 	public static final BorrowStorageType INSTANCE = new BorrowStorageType();
14 18
 
15 19
 	private BorrowStorageType() {}
20
+
21
+	@Override
22
+	public String getName() {
23
+		return "borrow";
24
+	}
25
+
26
+	@Override
27
+	public StorageTag instance(CodePosition position, String[] arguments) {
28
+		if (arguments != null) {
29
+			if (arguments.length == 1 && arguments[0].equals("this"))
30
+				return BorrowStorageTag.THIS;
31
+			
32
+			throw new CompileException(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "borrow storage type doesn't take arguments");
33
+		}
34
+		
35
+		return BorrowStorageTag.INVOCATION;
36
+	}
16 37
 }

+ 15
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageTag.java Просмотреть файл

@@ -18,4 +18,19 @@ public class SharedStorageTag implements StorageTag {
18 18
 	public StorageType getType() {
19 19
 		return SharedStorageType.INSTANCE;
20 20
 	}
21
+	
22
+	@Override
23
+	public String toString() {
24
+		return "shared";
25
+	}
26
+
27
+	@Override
28
+	public boolean canCastTo(StorageTag other) {
29
+		return false;
30
+	}
31
+
32
+	@Override
33
+	public boolean canCastFrom(StorageTag other) {
34
+		return other == this || other == UniqueStorageTag.INSTANCE;
35
+	}
21 36
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageType.java Просмотреть файл

@@ -5,6 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.type.storage;
7 7
 
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zencode.shared.CompileExceptionCode;
11
+
8 12
 /**
9 13
  *
10 14
  * @author Hoofdgebruiker
@@ -13,4 +17,17 @@ public class SharedStorageType implements StorageType {
13 17
 	public static final SharedStorageType INSTANCE = new SharedStorageType();
14 18
 	
15 19
 	private SharedStorageType() {}
20
+
21
+	@Override
22
+	public String getName() {
23
+		return "shared";
24
+	}
25
+
26
+	@Override
27
+	public StorageTag instance(CodePosition position, String[] arguments) {
28
+		if (arguments != null)
29
+			throw new CompileException(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "shared storage type doesn't take arguments");
30
+		
31
+		return SharedStorageTag.INSTANCE;
32
+	}
16 33
 }

+ 15
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StaticStorageTag.java Просмотреть файл

@@ -18,4 +18,19 @@ public class StaticStorageTag implements StorageTag {
18 18
 	public StorageType getType() {
19 19
 		return StaticStorageType.INSTANCE;
20 20
 	}
21
+	
22
+	@Override
23
+	public String toString() {
24
+		return "static";
25
+	}
26
+
27
+	@Override
28
+	public boolean canCastTo(StorageTag other) {
29
+		return false;
30
+	}
31
+
32
+	@Override
33
+	public boolean canCastFrom(StorageTag other) {
34
+		return other == this || other == UniqueStorageTag.INSTANCE;
35
+	}
21 36
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StaticStorageType.java Просмотреть файл

@@ -5,6 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.type.storage;
7 7
 
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zencode.shared.CompileExceptionCode;
11
+
8 12
 /**
9 13
  *
10 14
  * @author Hoofdgebruiker
@@ -13,4 +17,17 @@ public class StaticStorageType implements StorageType {
13 17
 	public static final StaticStorageType INSTANCE = new StaticStorageType();
14 18
 	
15 19
 	private StaticStorageType() {}
20
+
21
+	@Override
22
+	public String getName() {
23
+		return "static";
24
+	}
25
+
26
+	@Override
27
+	public StorageTag instance(CodePosition position, String[] arguments) {
28
+		if (arguments != null)
29
+			throw new CompileException(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "static storage type doesn't take arguments");
30
+		
31
+		return StaticStorageTag.INSTANCE;
32
+	}
16 33
 }

+ 4
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StorageTag.java Просмотреть файл

@@ -11,4 +11,8 @@ package org.openzen.zenscript.codemodel.type.storage;
11 11
  */
12 12
 public interface StorageTag {
13 13
 	StorageType getType();
14
+	
15
+	boolean canCastTo(StorageTag other);
16
+	
17
+	boolean canCastFrom(StorageTag other);
14 18
 }

+ 14
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/StorageType.java Просмотреть файл

@@ -5,10 +5,24 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.type.storage;
7 7
 
8
+import org.openzen.zencode.shared.CodePosition;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker
11 13
  */
12 14
 public interface StorageType {
15
+	public static StorageType[] getStandard() {
16
+		return new StorageType[] {
17
+			AnyStorageType.INSTANCE,
18
+			BorrowStorageType.INSTANCE,
19
+			SharedStorageType.INSTANCE,
20
+			StaticStorageType.INSTANCE,
21
+			UniqueStorageType.INSTANCE
22
+		};
23
+	}
24
+	
25
+	String getName();
13 26
 	
27
+	StorageTag instance(CodePosition position, String[] arguments);
14 28
 }

+ 15
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/UniqueStorageTag.java Просмотреть файл

@@ -18,4 +18,19 @@ public class UniqueStorageTag implements StorageTag {
18 18
 	public StorageType getType() {
19 19
 		return UniqueStorageType.INSTANCE;
20 20
 	}
21
+	
22
+	@Override
23
+	public String toString() {
24
+		return "unique";
25
+	}
26
+
27
+	@Override
28
+	public boolean canCastTo(StorageTag other) {
29
+		return false;
30
+	}
31
+
32
+	@Override
33
+	public boolean canCastFrom(StorageTag other) {
34
+		return other == this;
35
+	}
21 36
 }

+ 17
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/UniqueStorageType.java Просмотреть файл

@@ -5,6 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.type.storage;
7 7
 
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zencode.shared.CompileExceptionCode;
11
+
8 12
 /**
9 13
  *
10 14
  * @author Hoofdgebruiker
@@ -13,4 +17,17 @@ public class UniqueStorageType implements StorageType {
13 17
 	public static final UniqueStorageType INSTANCE = new UniqueStorageType();
14 18
 	
15 19
 	private UniqueStorageType() {}
20
+
21
+	@Override
22
+	public String getName() {
23
+		return "unique";
24
+	}
25
+
26
+	@Override
27
+	public StorageTag instance(CodePosition position, String[] arguments) {
28
+		if (arguments != null)
29
+			throw new CompileException(position, CompileExceptionCode.INVALID_STORAGE_TYPE_ARGUMENTS, "unique storage type doesn't take arguments");
30
+		
31
+		return UniqueStorageTag.INSTANCE;
32
+	}
16 33
 }

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/ValueStorageTag.java Просмотреть файл

@@ -0,0 +1,31 @@
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.type.storage;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class ValueStorageTag implements StorageTag {
13
+	public static final ValueStorageTag INSTANCE = new ValueStorageTag();
14
+			
15
+	private ValueStorageTag() {}
16
+
17
+	@Override
18
+	public StorageType getType() {
19
+		return ValueStorageType.INSTANCE;
20
+	}
21
+
22
+	@Override
23
+	public boolean canCastTo(StorageTag other) {
24
+		return other == this;
25
+	}
26
+
27
+	@Override
28
+	public boolean canCastFrom(StorageTag other) {
29
+		return other == this;
30
+	}
31
+}

+ 28
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/ValueStorageType.java Просмотреть файл

@@ -0,0 +1,28 @@
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.type.storage;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class ValueStorageType implements StorageType {
15
+	public static final ValueStorageType INSTANCE = new ValueStorageType();
16
+	
17
+	private ValueStorageType() {}
18
+
19
+	@Override
20
+	public String getName() {
21
+		return "value";
22
+	}
23
+
24
+	@Override
25
+	public StorageTag instance(CodePosition position, String[] arguments) {
26
+		return ValueStorageTag.INSTANCE;
27
+	}
28
+}

+ 18
- 4
CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java Просмотреть файл

@@ -9,6 +9,8 @@ import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13
+import org.openzen.zencode.shared.CompileExceptionCode;
12 14
 import org.openzen.zenscript.codemodel.GenericMapper;
13 15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14 16
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
@@ -19,6 +21,8 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
19 21
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20 22
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
21 23
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
24
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
25
+import org.openzen.zenscript.codemodel.type.storage.StorageType;
22 26
 
23 27
 /**
24 28
  *
@@ -29,15 +33,17 @@ public class CompileScope implements TypeScope {
29 33
 	private final List<ExpansionDefinition> expansions;
30 34
 	private final LocalMemberCache cache;
31 35
 	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
36
+	private final Map<String, StorageType> storageTypes = new HashMap<>();
32 37
 	
33
-	public CompileScope(GlobalTypeRegistry globalRegistry, List<ExpansionDefinition> expansions, AnnotationDefinition[] annotations) {
38
+	public CompileScope(GlobalTypeRegistry globalRegistry, List<ExpansionDefinition> expansions, AnnotationDefinition[] annotations, StorageType[] storageTypes) {
34 39
 		this.globalRegistry = globalRegistry;
35 40
 		this.expansions = expansions;
36 41
 		this.cache = new LocalMemberCache(globalRegistry, expansions);
37 42
 		
38
-		for (AnnotationDefinition annotation : annotations) {
43
+		for (AnnotationDefinition annotation : annotations)
39 44
 			this.annotations.put(annotation.getAnnotationName(), annotation);
40
-		}
45
+		for (StorageType type : storageTypes)
46
+			this.storageTypes.put(type.getName(), type);
41 47
 	}
42 48
 
43 49
 	@Override
@@ -61,10 +67,18 @@ public class CompileScope implements TypeScope {
61 67
 	}
62 68
 
63 69
 	@Override
64
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
70
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
65 71
 		throw new UnsupportedOperationException("Not supported yet.");
66 72
 	}
67 73
 	
74
+	@Override
75
+	public StorageTag getStorageTag(CodePosition position, String name, String[] arguments) {
76
+		if (!storageTypes.containsKey(name))
77
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_STORAGE_TYPE, "No such storage type: " + name);
78
+		
79
+		return storageTypes.get(name).instance(position, arguments);
80
+	}
81
+	
68 82
 	@Override
69 83
 	public ITypeID getThisType() {
70 84
 		return null;

+ 8
- 1
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java Просмотреть файл

@@ -18,6 +18,7 @@ import org.openzen.zenscript.codemodel.annotations.PreconditionAnnotationDefinit
18 18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19 19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
20 20
 import org.openzen.zenscript.codemodel.type.ISymbol;
21
+import org.openzen.zenscript.codemodel.type.storage.StorageType;
21 22
 
22 23
 /**
23 24
  *
@@ -30,13 +31,15 @@ public final class ModuleSpace {
30 31
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
31 32
 	private final Map<String, ISymbol> globals = new HashMap<>();
32 33
 	private final AnnotationDefinition[] annotations;
34
+	private final StorageType[] storageTypes;
33 35
 	
34
-	public ModuleSpace(CompilationUnit compilationUnit, List<AnnotationDefinition> annotations) {
36
+	public ModuleSpace(CompilationUnit compilationUnit, List<AnnotationDefinition> annotations, StorageType[] storageTypes) {
35 37
 		this.compilationUnit = compilationUnit;
36 38
 		
37 39
 		annotations.add(NativeAnnotationDefinition.INSTANCE);
38 40
 		annotations.add(PreconditionAnnotationDefinition.INSTANCE);
39 41
 		this.annotations = annotations.toArray(new AnnotationDefinition[annotations.size()]);
42
+		this.storageTypes = storageTypes;
40 43
 	}
41 44
 	
42 45
 	public void addModule(String name, SemanticModule dependency) {
@@ -70,4 +73,8 @@ public final class ModuleSpace {
70 73
 	public AnnotationDefinition[] getAnnotations() {
71 74
 		return annotations;
72 75
 	}
76
+	
77
+	public StorageType[] getStorageTypes() {
78
+		return storageTypes;
79
+	}
73 80
 }

+ 8
- 3
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java Просмотреть файл

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
22 22
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
23 23
 import org.openzen.zenscript.codemodel.scope.FileScope;
24 24
 import org.openzen.zenscript.codemodel.type.ISymbol;
25
+import org.openzen.zenscript.codemodel.type.storage.StorageType;
25 26
 import org.openzen.zenscript.validator.ValidationLogEntry;
26 27
 import org.openzen.zenscript.validator.Validator;
27 28
 
@@ -44,6 +45,7 @@ public class SemanticModule {
44 45
 	public final CompilationUnit compilationUnit;
45 46
 	public final List<ExpansionDefinition> expansions;
46 47
 	public final AnnotationDefinition[] annotations;
48
+	public final StorageType[] storageTypes;
47 49
 	
48 50
 	public SemanticModule(
49 51
 			String name,
@@ -56,7 +58,8 @@ public class SemanticModule {
56 58
 			List<ScriptBlock> scripts,
57 59
 			CompilationUnit compilationUnit,
58 60
 			List<ExpansionDefinition> expansions,
59
-			AnnotationDefinition[] annotations)
61
+			AnnotationDefinition[] annotations,
62
+			StorageType[] storageTypes)
60 63
 	{
61 64
 		this.name = name;
62 65
 		this.module = module;
@@ -71,6 +74,7 @@ public class SemanticModule {
71 74
 		this.compilationUnit = compilationUnit;
72 75
 		this.expansions = expansions;
73 76
 		this.annotations = annotations;
77
+		this.storageTypes = storageTypes;
74 78
 	}
75 79
 	
76 80
 	public boolean isValid() {
@@ -81,7 +85,7 @@ public class SemanticModule {
81 85
 		if (state != State.ASSEMBLED)
82 86
 			throw new IllegalStateException("Module is invalid");
83 87
 		
84
-		ModuleTypeResolutionContext context = new ModuleTypeResolutionContext(compilationUnit.globalTypeRegistry, annotations, rootPackage, null, globals);
88
+		ModuleTypeResolutionContext context = new ModuleTypeResolutionContext(compilationUnit.globalTypeRegistry, annotations, storageTypes, rootPackage, null, globals);
85 89
 		AnnotationProcessor annotationProcessor = new AnnotationProcessor(context, expansions);
86 90
 		List<ScriptBlock> processedScripts = new ArrayList<>();
87 91
 		for (ScriptBlock block : scripts)
@@ -104,7 +108,8 @@ public class SemanticModule {
104 108
 				processedScripts,
105 109
 				compilationUnit,
106 110
 				expansions,
107
-				annotations);
111
+				annotations,
112
+				storageTypes);
108 113
 	}
109 114
 	
110 115
 	public boolean validate(Consumer<ValidationLogEntry> logger) {

+ 2
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java Просмотреть файл

@@ -25,6 +25,7 @@ import org.openzen.zenscript.constructor.JSONUtils;
25 25
 import org.openzen.zenscript.constructor.ParsedModule;
26 26
 import org.openzen.zenscript.constructor.ModuleLoader;
27 27
 import org.openzen.zenscript.codemodel.type.TypeSymbol;
28
+import org.openzen.zenscript.codemodel.type.storage.StorageType;
28 29
 import org.openzen.zenscript.parser.ParsedFile;
29 30
 
30 31
 /**
@@ -72,7 +73,7 @@ public class DirectoryModuleReference implements ModuleReference {
72 73
 			}
73 74
 
74 75
 			// TODO: annotation type registration
75
-			ModuleSpace space = new ModuleSpace(unit, new ArrayList<>());
76
+			ModuleSpace space = new ModuleSpace(unit, new ArrayList<>(), StorageType.getStandard());
76 77
 			SemanticModule[] dependencies = new SemanticModule[dependencyNames.size()];
77 78
 			for (int i = 0; i < dependencies.length; i++) {
78 79
 				String dependencyName = dependencyNames.get(i);

+ 0
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java Просмотреть файл

@@ -7,7 +7,6 @@ package org.openzen.zenscript.ide.ui.view;
7 7
 
8 8
 import org.openzen.drawablegui.DEmptyView;
9 9
 import org.openzen.drawablegui.DScalableSize;
10
-import org.openzen.drawablegui.DSizing;
11 10
 import org.openzen.drawablegui.border.DLineBorder;
12 11
 import org.openzen.drawablegui.scroll.DScrollPane;
13 12
 import org.openzen.drawablegui.layout.DSideLayout;

+ 6
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaBoxingTypeVisitor.java Просмотреть файл

@@ -66,6 +66,12 @@ public class JavaBoxingTypeVisitor implements TypeVisitor<Void> {
66 66
 			writer.invokeStatic(method);
67 67
 		return null;
68 68
 	}
69
+	
70
+	@Override
71
+	public Void visitString(StringTypeID string) {
72
+		//NO-OP
73
+		return null;
74
+	}
69 75
 
70 76
 	@Override
71 77
 	public Void visitArray(ArrayTypeID array) {

+ 36
- 15
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Просмотреть файл

@@ -23,6 +23,11 @@ import org.openzen.zenscript.javabytecode.*;
23 23
 
24 24
 import java.io.FileOutputStream;
25 25
 import java.io.IOException;
26
+import java.lang.reflect.Modifier;
27
+import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
28
+import org.openzen.zenscript.codemodel.type.storage.SharedStorageTag;
29
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
30
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
26 31
 import org.openzen.zenscript.javashared.JavaClass;
27 32
 import org.openzen.zenscript.javashared.JavaField;
28 33
 import org.openzen.zenscript.javashared.JavaMethod;
@@ -144,7 +149,12 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
144 149
 	public static final JavaMethod OBJECT_HASHCODE = JavaMethod.getNativeVirtual(JavaClass.OBJECT, "hashCode", "()I");
145 150
 	private static final JavaMethod COLLECTION_SIZE = JavaMethod.getNativeVirtual(JavaClass.COLLECTION, "size", "()I");
146 151
 	private static final JavaMethod COLLECTION_TOARRAY = JavaMethod.getNativeVirtual(JavaClass.COLLECTION, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
147
-
152
+	
153
+	private static final JavaMethod SHARED_INIT = JavaMethod.getConstructor(JavaClass.SHARED, "(Ljava/lang/Object;)V", Modifier.PUBLIC);
154
+	private static final JavaMethod SHARED_GET = JavaMethod.getNativeVirtual(JavaClass.SHARED, "get", "()Ljava/lang/Object;");
155
+	private static final JavaMethod SHARED_ADDREF = JavaMethod.getNativeVirtual(JavaClass.SHARED, "addRef", "()V");
156
+	private static final JavaMethod SHARED_RELEASE = JavaMethod.getNativeVirtual(JavaClass.SHARED, "release", "()V");
157
+	
148 158
 	protected final JavaWriter javaWriter;
149 159
 	private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
150 160
 	private final JavaBytecodeContext context;
@@ -826,10 +836,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
826 836
 						case CHAR:
827 837
 							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_CHARS);
828 838
 							break;
829
-						case STRING:
830
-							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
831
-							javaWriter.checkCast("[Ljava/lang/String;");
832
-							break;
833 839
 						default:
834 840
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
835 841
 					}
@@ -874,9 +880,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
874 880
 						case CHAR:
875 881
 							javaWriter.invokeStatic(ARRAYS_EQUALS_CHARS);
876 882
 							break;
877
-						case STRING:
878
-							javaWriter.invokeStatic(ARRAYS_EQUALS_OBJECTS);
879
-							break;
880 883
 						default:
881 884
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
882 885
 					}
@@ -1651,7 +1654,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1651 1654
 
1652 1655
 		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", signature);
1653 1656
 		final ClassWriter lambdaCW = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
1654
-		lambdaCW.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object", new String[]{context.getInternalName(new FunctionTypeID(null, expression.header))});
1657
+		lambdaCW.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object", new String[]{context.getInternalName(new FunctionTypeID(null, expression.header, null))});
1655 1658
 		final JavaWriter functionWriter = new JavaWriter(lambdaCW, methodInfo, null, signature, null, "java/lang/Override");
1656 1659
 
1657 1660
 		javaWriter.newObject(name);
@@ -1888,7 +1891,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1888 1891
 				break;
1889 1892
 			case ASSOC_KEYS: {
1890 1893
 				AssocTypeID type = (AssocTypeID) expression.target.type;
1891
-				ArrayTypeID result = new ArrayTypeID(null, type.keyType, 1);
1894
+				ArrayTypeID result = new ArrayTypeID(null, type.keyType, 1, UniqueStorageTag.INSTANCE);
1892 1895
 				Type resultType = context.getType(result);
1893 1896
 
1894 1897
 				javaWriter.invokeVirtual(MAP_KEYS);
@@ -1901,7 +1904,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1901 1904
 			}
1902 1905
 			case ASSOC_VALUES: {
1903 1906
 				AssocTypeID type = (AssocTypeID) expression.target.type;
1904
-				ArrayTypeID result = new ArrayTypeID(null, type.valueType, 1);
1907
+				ArrayTypeID result = new ArrayTypeID(null, type.valueType, 1, UniqueStorageTag.INSTANCE);
1905 1908
 				Type resultType = context.getType(result);
1906 1909
 
1907 1910
 				javaWriter.invokeVirtual(MAP_VALUES);
@@ -1955,9 +1958,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1955 1958
 						case CHAR:
1956 1959
 							javaWriter.invokeStatic(ARRAYS_HASHCODE_CHARS);
1957 1960
 							break;
1958
-						case STRING:
1959
-							javaWriter.invokeStatic(ARRAYS_DEEPHASHCODE);
1960
-							break;
1961 1961
 						default:
1962 1962
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
1963 1963
 					}
@@ -2056,7 +2056,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2056 2056
 		expression.value.accept(this);
2057 2057
 
2058 2058
 		//TODO replace beforeSwitch visitor or similar
2059
-		if (expression.value.type == BasicTypeID.STRING)
2059
+		if (expression.value.type instanceof StringTypeID)
2060 2060
 			javaWriter.invokeVirtual(OBJECT_HASHCODE);
2061 2061
 
2062 2062
 		//TODO replace with beforeSwitch visitor or similar
@@ -2366,6 +2366,27 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2366 2366
 
2367 2367
 	@Override
2368 2368
 	public Void visitStaticSetter(StaticSetterExpression expression) {
2369
+		throw new UnsupportedOperationException("Not yet implemented");
2370
+	}
2371
+	
2372
+	@Override
2373
+	public Void visitStorageCast(StorageCastExpression expression) {
2374
+		expression.value.accept(this);
2375
+		
2376
+		if (expression.type.isDestructible()) { // only destructible types matter here; nondestructible types never need conversion
2377
+			StorageTag fromTag = expression.value.type.getStorage();
2378
+			StorageTag toTag = expression.type.getStorage();
2379
+			if (fromTag == SharedStorageTag.INSTANCE && toTag == BorrowStorageTag.INVOCATION) {
2380
+				// Shared<T>.get()
2381
+				javaWriter.invokeVirtual(SHARED_GET);
2382
+			} else if (fromTag == UniqueStorageTag.INSTANCE && toTag == SharedStorageTag.INSTANCE) {
2383
+				// new Shared<T>(value)
2384
+				javaWriter.newObject("zsynthetic/Shared");
2385
+				javaWriter.dup();
2386
+				javaWriter.invokeSpecial(SHARED_INIT);
2387
+			}
2388
+		}
2389
+		
2369 2390
 		return null;
2370 2391
 	}
2371 2392
 

+ 5
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java Просмотреть файл

@@ -354,6 +354,11 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
354 354
 		throw new UnsupportedOperationException("Invalid increment target");
355 355
 	}
356 356
 	
357
+	@Override
358
+	public Void visitStorageCast(StorageCastExpression expression) {
359
+		throw new UnsupportedOperationException("Invalid increment target");
360
+	}
361
+	
357 362
 	@Override
358 363
 	public Void visitSupertypeCast(SupertypeCastExpression expression) {
359 364
 		throw new UnsupportedOperationException("Invalid increment target");

+ 5
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java Просмотреть файл

@@ -360,6 +360,11 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
360 360
 		throw new UnsupportedOperationException("Invalid increment target");
361 361
 	}
362 362
 	
363
+	@Override
364
+	public Void visitStorageCast(StorageCastExpression expression) {
365
+		throw new UnsupportedOperationException("Invalid increment target");
366
+	}
367
+	
363 368
 	@Override
364 369
 	public Void visitSupertypeCast(SupertypeCastExpression expression) {
365 370
 		throw new UnsupportedOperationException("Invalid increment target");

+ 2
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java Просмотреть файл

@@ -3,11 +3,11 @@ package org.openzen.zenscript.javabytecode.compiler;
3 3
 import org.objectweb.asm.Label;
4 4
 import org.objectweb.asm.Type;
5 5
 import org.openzen.zenscript.codemodel.statement.*;
6
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
7 6
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
8 7
 
9 8
 import java.util.Arrays;
10 9
 import java.util.List;
10
+import org.openzen.zenscript.codemodel.type.StringTypeID;
11 11
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
12 12
 
13 13
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
@@ -190,7 +190,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
190 190
 
191 191
 		javaWriter.label(start);
192 192
 		statement.value.accept(expressionVisitor);
193
-		if (statement.value.type == BasicTypeID.STRING)
193
+		if (statement.value.type instanceof StringTypeID)
194 194
 			javaWriter.invokeVirtual(JavaExpressionVisitor.OBJECT_HASHCODE);
195 195
 		boolean out = false;
196 196
 

+ 2
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java Просмотреть файл

@@ -33,6 +33,8 @@ public class JavaClass implements Comparable<JavaClass> {
33 33
 	public static final JavaClass CHARACTER = new JavaClass("java.lang", "Character", Kind.CLASS);
34 34
 	public static final JavaClass COLLECTION = new JavaClass("java.util", "Collection", Kind.INTERFACE);
35 35
 	
36
+	public static final JavaClass SHARED = new JavaClass("zsynthetic", "Shared", Kind.CLASS);
37
+	
36 38
 	public static JavaClass fromInternalName(String internalName, Kind kind) {
37 39
 		if (kind == Kind.ARRAY)
38 40
 			return new JavaClass("", internalName, kind, new String[0]);

+ 8
- 8
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java Просмотреть файл

@@ -39,31 +39,31 @@ public abstract class JavaContext {
39 39
 			functions.put("TToU", new JavaSynthesizedFunction(
40 40
 					new JavaClass("java.util.function", "Function", JavaClass.Kind.INTERFACE),
41 41
 					new TypeParameter[] { t, u },
42
-					new FunctionHeader(registry.getGeneric(u), registry.getGeneric(t)),
42
+					new FunctionHeader(registry.getGeneric(u, null), registry.getGeneric(t, null)),
43 43
 					"apply"));
44 44
 			
45 45
 			functions.put("TUToV", new JavaSynthesizedFunction(
46 46
 					new JavaClass("java.util.function", "BiFunction", JavaClass.Kind.INTERFACE),
47 47
 					new TypeParameter[] { t, u, v },
48
-					new FunctionHeader(registry.getGeneric(v), registry.getGeneric(t), registry.getGeneric(u)),
48
+					new FunctionHeader(registry.getGeneric(v, null), registry.getGeneric(t, null), registry.getGeneric(u, null)),
49 49
 					"apply"));
50 50
 			
51 51
 			functions.put("TToVoid", new JavaSynthesizedFunction(
52 52
 					new JavaClass("java.util.function", "Consumer", JavaClass.Kind.INTERFACE),
53 53
 					new TypeParameter[] { t },
54
-					new FunctionHeader(BasicTypeID.VOID, registry.getGeneric(t)),
54
+					new FunctionHeader(BasicTypeID.VOID, registry.getGeneric(t, null)),
55 55
 					"accept"));
56 56
 			
57 57
 			functions.put("TUToVoid", new JavaSynthesizedFunction(
58 58
 					new JavaClass("java.util.function", "BiConsumer", JavaClass.Kind.INTERFACE),
59 59
 					new TypeParameter[] { t, u },
60
-					new FunctionHeader(BasicTypeID.VOID, registry.getGeneric(t), registry.getGeneric(u)),
60
+					new FunctionHeader(BasicTypeID.VOID, registry.getGeneric(t, null), registry.getGeneric(u, null)),
61 61
 					"accept"));
62 62
 			
63 63
 			functions.put("TToBool", new JavaSynthesizedFunction(
64 64
 					new JavaClass("java.util.function", "Predicate", JavaClass.Kind.INTERFACE),
65 65
 					new TypeParameter[] { t },
66
-					new FunctionHeader(BasicTypeID.BOOL, registry.getGeneric(t)),
66
+					new FunctionHeader(BasicTypeID.BOOL, registry.getGeneric(t, null)),
67 67
 					"test"));
68 68
 		}
69 69
 	}
@@ -98,7 +98,7 @@ public abstract class JavaContext {
98 98
 				} else {
99 99
 					TypeParameter typeParameter = new TypeParameter(CodePosition.BUILTIN, getTypeParameter(typeParameters.size()));
100 100
 					typeParameters.add(typeParameter);
101
-					parameters.add(new FunctionParameter(registry.getGeneric(typeParameter), Character.toString((char)('a' + parameters.size()))));
101
+					parameters.add(new FunctionParameter(registry.getGeneric(typeParameter, null), Character.toString((char)('a' + parameters.size()))));
102 102
 				}
103 103
 			}
104 104
 			ITypeID returnType;
@@ -109,7 +109,7 @@ public abstract class JavaContext {
109 109
 				} else {
110 110
 					TypeParameter typeParameter = new TypeParameter(CodePosition.BUILTIN, getTypeParameter(typeParameters.size()));
111 111
 					typeParameters.add(typeParameter);
112
-					returnType = registry.getGeneric(typeParameter);
112
+					returnType = registry.getGeneric(typeParameter, null);
113 113
 				}
114 114
 			}
115 115
 			function = new JavaSynthesizedFunction(
@@ -177,7 +177,7 @@ public abstract class JavaContext {
177 177
 				range = new JavaSynthesizedRange(cls, TypeParameter.NONE, type.baseType);
178 178
 			} else {
179 179
 				TypeParameter typeParameter = new TypeParameter(CodePosition.BUILTIN, "T");
180
-				range = new JavaSynthesizedRange(cls, new TypeParameter[] { typeParameter }, registry.getGeneric(typeParameter));
180
+				range = new JavaSynthesizedRange(cls, new TypeParameter[] { typeParameter }, registry.getGeneric(typeParameter, null));
181 181
 			}
182 182
 			ranges.put(id, range);
183 183
 			getTypeGenerator().synthesizeRange(range);

+ 11
- 6
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java Просмотреть файл

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
22 22
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
23 23
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
24 24
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
25
+import org.openzen.zenscript.codemodel.type.StringTypeID;
25 26
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
26 27
 
27 28
 /**
@@ -29,7 +30,7 @@ import org.openzen.zenscript.codemodel.type.TypeVisitor;
29 30
  * @author Hoofdgebruiker
30 31
  */
31 32
 public class JavaSyntheticTypeSignatureConverter implements TypeVisitor<String> {
32
-	private static final String[] typeParameterNames = {"T", "U", "V", "W", "X", "Y", "Z"}; // if we have more than this, make it Tx with x the number
33
+	private static final String[] TYPE_PARAMETER_NAMES = {"T", "U", "V", "W", "X", "Y", "Z"}; // if we have more than this, make it Tx with x the number
33 34
 	private final Map<TypeParameter, String> typeParameters = new HashMap<>();
34 35
 	public final List<TypeParameter> typeParameterList = new ArrayList<>();
35 36
 	
@@ -50,11 +51,15 @@ public class JavaSyntheticTypeSignatureConverter implements TypeVisitor<String>
50 51
 			case FLOAT: return "Float";
51 52
 			case DOUBLE: return "Double";
52 53
 			case CHAR: return "Char";
53
-			case STRING: return "String";
54 54
 			default:
55 55
 				throw new IllegalArgumentException("Invalid type: " + basic);
56 56
 		}
57 57
 	}
58
+	
59
+	@Override
60
+	public String visitString(StringTypeID string) {
61
+		return "String";
62
+	}
58 63
 
59 64
 	@Override
60 65
 	public String visitArray(ArrayTypeID array) {
@@ -107,10 +112,10 @@ public class JavaSyntheticTypeSignatureConverter implements TypeVisitor<String>
107 112
 	public String visitDefinition(DefinitionTypeID definition) {
108 113
 		StringBuilder result = new StringBuilder();
109 114
 		result.append(definition.definition.name);
110
-		if (definition.typeParameters.length > 0) {
115
+		if (definition.typeArguments.length > 0) {
111 116
 			result.append("With");
112
-			for (int i = 0; i < definition.typeParameters.length; i++) {
113
-				result.append(definition.typeParameters[i].accept(this));
117
+			for (int i = 0; i < definition.typeArguments.length; i++) {
118
+				result.append(definition.typeArguments[i].accept(this));
114 119
 			}
115 120
 		}
116 121
 		return result.toString();
@@ -121,7 +126,7 @@ public class JavaSyntheticTypeSignatureConverter implements TypeVisitor<String>
121 126
 		if (typeParameters.containsKey(generic.parameter))
122 127
 			return typeParameters.get(generic.parameter);
123 128
 		
124
-		String name = typeParameters.size() < typeParameterNames.length ? typeParameterNames[typeParameters.size()] : "T" + typeParameters.size();
129
+		String name = typeParameters.size() < TYPE_PARAMETER_NAMES.length ? TYPE_PARAMETER_NAMES[typeParameters.size()] : "T" + typeParameters.size();
125 130
 		typeParameters.put(generic.parameter, name);
126 131
 		typeParameterList.add(generic.parameter);
127 132
 		return name;

+ 5
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java Просмотреть файл

@@ -36,7 +36,6 @@ public class JavaTypeDescriptorVisitor implements TypeVisitor<String> {
36 36
 				case USIZE: return "I"; // special case: optional usize fits in an int where null = -1
37 37
 				case FLOAT: return "Ljava/lang/Float;";
38 38
 				case DOUBLE: return "Ljava/lang/Double;";
39
-				case STRING: return "Ljava/lang/String;";
40 39
 				default:
41 40
 					throw new IllegalArgumentException("Not a valid type: " + basic);
42 41
 			}
@@ -56,12 +55,16 @@ public class JavaTypeDescriptorVisitor implements TypeVisitor<String> {
56 55
 				case USIZE: return "I";
57 56
 				case FLOAT: return "F";
58 57
 				case DOUBLE: return "D";
59
-				case STRING: return "Ljava/lang/String;";
60 58
 				default:
61 59
 					throw new IllegalArgumentException("Not a valid type: " + basic);
62 60
 			}
63 61
 		}
64 62
     }
63
+	
64
+	@Override
65
+	public String visitString(StringTypeID string) {
66
+		return "Ljava/lang/String;";
67
+	}
65 68
 
66 69
     @Override
67 70
     public String visitArray(ArrayTypeID array) {

+ 7
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeGenericVisitor.java Просмотреть файл

@@ -89,6 +89,11 @@ public class JavaTypeGenericVisitor implements TypeVisitor<String> {
89 89
 	public String visitBasic(BasicTypeID basic) {
90 90
 		return context.getDescriptor(basic);
91 91
 	}
92
+	
93
+	@Override
94
+	public String visitString(StringTypeID string) {
95
+		return context.getDescriptor(string);
96
+	}
92 97
 
93 98
 	@Override
94 99
 	public String visitArray(ArrayTypeID array) {
@@ -119,9 +124,9 @@ public class JavaTypeGenericVisitor implements TypeVisitor<String> {
119 124
 	public String visitDefinition(DefinitionTypeID definition) {
120 125
 		StringBuilder builder = new StringBuilder("L").append(definition.definition.name);
121 126
 
122
-		if (definition.typeParameters.length > 0) {
127
+		if (definition.typeArguments.length > 0) {
123 128
 			builder.append("<");
124
-			for (ITypeID typeParameter : definition.typeParameters) {
129
+			for (ITypeID typeParameter : definition.typeArguments) {
125 130
 				builder.append(typeParameter.accept(this));
126 131
 			}
127 132
 			builder.append(">");

+ 7
- 7
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInfo.java Просмотреть файл

@@ -16,6 +16,7 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
16 16
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
17 17
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
18 18
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
19
+import org.openzen.zenscript.codemodel.type.StringTypeID;
19 20
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
20 21
 
21 22
 /**
@@ -45,13 +46,12 @@ public class JavaTypeInfo {
45 46
 
46 47
 		@Override
47 48
 		public JavaTypeInfo visitBasic(BasicTypeID basic) {
48
-			switch (basic) {
49
-				case STRING:
50
-				case NULL:
51
-					return OBJECT;
52
-				default:
53
-					return PRIMITIVE;
54
-			}
49
+			return basic == BasicTypeID.NULL ? OBJECT : PRIMITIVE;
50
+		}
51
+		
52
+		@Override
53
+		public JavaTypeInfo visitString(StringTypeID string) {
54
+			return OBJECT;
55 55
 		}
56 56
 
57 57
 		@Override

+ 5
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java Просмотреть файл

@@ -36,7 +36,6 @@ public class JavaTypeInternalNameVisitor implements TypeVisitor<String> {
36 36
 				case USIZE: return "java/lang/Integer";
37 37
 				case FLOAT: return "java/lang/Float";
38 38
 				case DOUBLE: return "java/lang/Double";
39
-				case STRING: return "java/lang/String";
40 39
 				default:
41 40
 					throw new IllegalArgumentException("Not a valid type: " + basic);
42 41
 			}
@@ -56,12 +55,16 @@ public class JavaTypeInternalNameVisitor implements TypeVisitor<String> {
56 55
 				case USIZE: return "I";
57 56
 				case FLOAT: return "F";
58 57
 				case DOUBLE: return "D";
59
-				case STRING: return "java/lang/String";
60 58
 				default:
61 59
 					throw new IllegalArgumentException("Not a valid type: " + basic);
62 60
 			}
63 61
 		}
64 62
     }
63
+	
64
+	@Override
65
+	public String visitString(StringTypeID string) {
66
+		return "java/lang/String";
67
+	}
65 68
 
66 69
     @Override
67 70
     public String visitArray(ArrayTypeID array) {

+ 6
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeNameVisitor.java Просмотреть файл

@@ -16,6 +16,7 @@ import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
16 16
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
17 17
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
18 18
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
19
+import org.openzen.zenscript.codemodel.type.StringTypeID;
19 20
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
20 21
 
21 22
 /**
@@ -40,11 +41,15 @@ public class JavaTypeNameVisitor implements TypeVisitor<String> {
40 41
 			case ULONG: return "ULong";
41 42
 			case FLOAT: return "Float";
42 43
 			case DOUBLE: return "Double";
43
-			case STRING: return "String";
44 44
 			case CHAR: return "Char";
45 45
 			default: throw new IllegalArgumentException("Invalid type: " + basic);
46 46
 		}
47 47
 	}
48
+	
49
+	@Override
50
+	public String visitString(StringTypeID string) {
51
+		return "String";
52
+	}
48 53
 
49 54
 	@Override
50 55
 	public String visitArray(ArrayTypeID array) {

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java Просмотреть файл

@@ -66,6 +66,7 @@ import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
66 66
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
67 67
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
68 68
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
69
+import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
69 70
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
70 71
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
71 72
 import org.openzen.zenscript.codemodel.expression.ThrowExpression;
@@ -383,6 +384,11 @@ public class ExpressionHoistingChecker implements ExpressionVisitor<Boolean> {
383 384
 	public Boolean visitStaticSetter(StaticSetterExpression expression) {
384 385
 		return true;
385 386
 	}
387
+	
388
+	@Override
389
+	public Boolean visitStorageCast(StorageCastExpression expression) {
390
+		return false;
391
+	}
386 392
 
387 393
 	@Override
388 394
 	public Boolean visitSupertypeCast(SupertypeCastExpression expression) {

+ 3
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java Просмотреть файл

@@ -75,7 +75,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
75 75
 		GlobalTypeRegistry typeRegistry = module.compilationUnit.globalTypeRegistry;
76 76
 		DefinitionTypeID thisType = typeRegistry.getForMyDefinition(definition);
77 77
 		
78
-		CompileScope scope = new CompileScope(module.compilationUnit.globalTypeRegistry, module.expansions, module.annotations);
78
+		CompileScope scope = new CompileScope(module.compilationUnit.globalTypeRegistry, module.expansions, module.annotations, module.storageTypes);
79 79
 		return new JavaSourceFileScope(file.importer, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition, thisType, compiler.context);
80 80
 	}
81 81
 
@@ -371,8 +371,8 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
371 371
 		if (definition.hasTag(JavaNativeClass.class)) {
372 372
 			ITypeID[] typeParameters = new ITypeID[definition.getNumberOfGenericParameters()];
373 373
 			for (int i = 0; i < typeParameters.length; i++)
374
-				typeParameters[i] = scope.semanticScope.getTypeRegistry().getGeneric(definition.typeParameters[i]);
375
-			ITypeID targetType = scope.semanticScope.getTypeRegistry().getForDefinition(definition, typeParameters);
374
+				typeParameters[i] = scope.semanticScope.getTypeRegistry().getGeneric(definition.typeParameters[i], null);
375
+			ITypeID targetType = scope.semanticScope.getTypeRegistry().getForDefinition(definition, null, typeParameters);
376 376
 			
377 377
 			JavaExpansionMemberCompiler memberCompiler = new JavaExpansionMemberCompiler(settings, targetType, definition.typeParameters, indent + settings.indent, output, scope, definition);
378 378
 			for (IDefinitionMember member : definition.members)

+ 2
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java Просмотреть файл

@@ -30,6 +30,7 @@ import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
30 30
 import org.openzen.zenscript.codemodel.statement.Statement;
31 31
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
32 32
 import org.openzen.zenscript.codemodel.type.ITypeID;
33
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
33 34
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
34 35
 import org.openzen.zenscript.javashared.JavaMethod;
35 36
 
@@ -164,7 +165,7 @@ public class JavaExpansionMemberCompiler extends BaseMemberCompiler {
164 165
 
165 166
 	@Override
166 167
 	public Void visitCustomIterator(IteratorMember member) {
167
-		compileMethod(member, new FunctionHeader(scope.semanticScope.getTypeRegistry().getIterator(member.getLoopVariableTypes())), member.body);
168
+		compileMethod(member, new FunctionHeader(scope.semanticScope.getTypeRegistry().getIterator(member.getLoopVariableTypes(), UniqueStorageTag.INSTANCE)), member.body);
168 169
 		return null;
169 170
 	}
170 171
 

+ 2
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Просмотреть файл

@@ -35,6 +35,7 @@ import org.openzen.zenscript.codemodel.statement.BlockStatement;
35 35
 import org.openzen.zenscript.codemodel.statement.EmptyStatement;
36 36
 import org.openzen.zenscript.codemodel.statement.Statement;
37 37
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
38
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
38 39
 import org.openzen.zenscript.compiler.SemanticModule;
39 40
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
40 41
 import org.openzen.zenscript.javashared.JavaClass;
@@ -210,7 +211,7 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
210 211
 
211 212
 	@Override
212 213
 	public Void visitCustomIterator(IteratorMember member) {
213
-		compileMethod(member, new FunctionHeader(scope.semanticScope.getTypeRegistry().getIterator(member.getLoopVariableTypes())), member.body);
214
+		compileMethod(member, new FunctionHeader(scope.semanticScope.getTypeRegistry().getIterator(member.getLoopVariableTypes(), UniqueStorageTag.INSTANCE)), member.body);
214 215
 		return null;
215 216
 	}
216 217
 

+ 26
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java Просмотреть файл

@@ -74,6 +74,7 @@ import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
74 74
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
75 75
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
76 76
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
77
+import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
77 78
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
78 79
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
79 80
 import org.openzen.zenscript.codemodel.expression.ThrowExpression;
@@ -92,6 +93,10 @@ import org.openzen.zenscript.codemodel.type.GenericTypeID;
92 93
 import org.openzen.zenscript.codemodel.type.ITypeID;
93 94
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
94 95
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
96
+import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
97
+import org.openzen.zenscript.codemodel.type.storage.SharedStorageTag;
98
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
99
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
95 100
 import org.openzen.zenscript.formattershared.ExpressionString;
96 101
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
97 102
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
@@ -650,6 +655,23 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
650 655
 				JavaOperator.ASSIGN);
651 656
 	}
652 657
 	
658
+	@Override
659
+	public ExpressionString visitStorageCast(StorageCastExpression expression) {
660
+		ExpressionString value = expression.accept(this);
661
+		if (expression.value.type.isDestructible()) {
662
+			StorageTag fromTag = expression.value.type.getStorage();
663
+			StorageTag toTag = expression.type.getStorage();
664
+			if (fromTag == SharedStorageTag.INSTANCE && toTag == BorrowStorageTag.INVOCATION) {
665
+				// Shared<T>.get()
666
+				return value.unaryPostfix(JavaOperator.CALL, ".get()");
667
+			} else if (fromTag == UniqueStorageTag.INSTANCE && toTag == SharedStorageTag.INSTANCE) {
668
+				// new Shared<T>(value)
669
+				return new ExpressionString("new " + scope.type(JavaClass.SHARED) + "(" + value.value + ")", JavaOperator.NEW);
670
+			}
671
+		}
672
+		return value;
673
+	}
674
+	
653 675
 	@Override
654 676
 	public ExpressionString visitSupertypeCast(SupertypeCastExpression expression) {
655 677
 		return expression.value.accept(this);
@@ -690,10 +712,10 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
690 712
 		
691 713
 		ExpressionString value = hoist(expression.value).accept(this);
692 714
 		target.writeLine("if (" + value.value + " instanceof " + errorType + ")");
693
-		target.writeLine(scope.settings.indent + "throw ((" + errorType + formatTypeArguments(type.typeParameters) + ")" + value.value + ").value;");
715
+		target.writeLine(scope.settings.indent + "throw ((" + errorType + formatTypeArguments(type.typeArguments) + ")" + value.value + ").value;");
694 716
 		
695 717
 		return value
696
-				.unaryPrefix(JavaOperator.CAST, "(" + okType + formatTypeArguments(type.typeParameters) + ")")
718
+				.unaryPrefix(JavaOperator.CAST, "(" + okType + formatTypeArguments(type.typeArguments) + ")")
697 719
 				.unaryPostfix(JavaOperator.MEMBER, ".value");
698 720
 	}
699 721
 
@@ -706,10 +728,10 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
706 728
 		
707 729
 		ExpressionString value = hoist(expression.value).accept(this);
708 730
 		target.writeLine("if (" + value.value + " instanceof " + errorType + ")");
709
-		target.writeLine(scope.settings.indent + "return new " + errorType + "<>(((" + errorType + formatTypeArguments(type.typeParameters) + ")" + value.value + ").value);");
731
+		target.writeLine(scope.settings.indent + "return new " + errorType + "<>(((" + errorType + formatTypeArguments(type.typeArguments) + ")" + value.value + ").value);");
710 732
 		
711 733
 		return value
712
-				.unaryPrefix(JavaOperator.CAST, "(" + okType + formatTypeArguments(type.typeParameters) + ")")
734
+				.unaryPrefix(JavaOperator.CAST, "(" + okType + formatTypeArguments(type.typeArguments) + ")")
713 735
 				.unaryPostfix(JavaOperator.MEMBER, ".value");
714 736
 	}
715 737
 	

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java Просмотреть файл

@@ -32,7 +32,6 @@ public class JavaSourceObjectTypeVisitor extends JavaSourceTypeVisitor {
32 32
 			case FLOAT: return "Float";
33 33
 			case DOUBLE: return "Double";
34 34
 			case CHAR: return "Character";
35
-			case STRING: return "String";
36 35
 			default:
37 36
 				throw new IllegalArgumentException("Unknown basic type: " + basic);
38 37
 		}

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java Просмотреть файл

@@ -170,10 +170,10 @@ public class JavaSourceStatementFormatter implements StatementFormatter.Formatte
170 170
 						statementOutput.append(scope.type(switchValue.option.types[i])).append(" ").append(switchValue.parameters[i]).append(" = ((").append(variantTypeName).append(".").append(switchValue.option.getName());
171 171
 						if (variant.typeParameters != null && variant.typeParameters.length > 0) {
172 172
 							statementOutput.append("<");
173
-							for (int j = 0; j < variantType.typeParameters.length; j++) {
173
+							for (int j = 0; j < variantType.typeArguments.length; j++) {
174 174
 								if (j > 0)
175 175
 									statementOutput.append(", ");
176
-								statementOutput.append(scope.type(variantType.typeParameters[j]));
176
+								statementOutput.append(scope.type(variantType.typeArguments[j]));
177 177
 							}
178 178
 							statementOutput.append(">");
179 179
 						}

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticHelperGenerator.java Просмотреть файл

@@ -26,6 +26,7 @@ import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
26 26
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
27 27
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
28 28
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
29
+import org.openzen.zenscript.codemodel.type.StringTypeID;
29 30
 import org.openzen.zenscript.javashared.JavaClass;
30 31
 import org.openzen.zenscript.javashared.JavaContext;
31 32
 import org.openzen.zenscript.javashared.JavaMethod;
@@ -156,6 +157,11 @@ public class JavaSourceSyntheticHelperGenerator {
156 157
 					throw new UnsupportedOperationException("Invalid array base type: " + basic);
157 158
 			}
158 159
 		}
160
+		
161
+		@Override
162
+		public ArrayKind visitString(StringTypeID string) {
163
+			return ArrayKind.OBJECT;
164
+		}
159 165
 
160 166
 		@Override
161 167
 		public ArrayKind visitArray(ArrayTypeID array) {

+ 9
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java Просмотреть файл

@@ -19,6 +19,7 @@ import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
19 19
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
20 20
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
21 21
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
22
+import org.openzen.zenscript.codemodel.type.StringTypeID;
22 23
 import org.openzen.zenscript.javashared.JavaClass;
23 24
 import org.openzen.zenscript.javashared.JavaSynthesizedFunctionInstance;
24 25
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
@@ -66,11 +67,15 @@ public class JavaSourceTypeVisitor implements TypeVisitor<String>, GenericParame
66 67
 			case FLOAT: return "float";
67 68
 			case DOUBLE: return "double";
68 69
 			case CHAR: return "char";
69
-			case STRING: return "String";
70 70
 			default:
71 71
 				throw new IllegalArgumentException("Unknown basic type: " + basic);
72 72
 		}
73 73
 	}
74
+	
75
+	@Override
76
+	public String visitString(StringTypeID string) {
77
+		return "String";
78
+	}
74 79
 
75 80
 	@Override
76 81
 	public String visitArray(ArrayTypeID array) {
@@ -144,12 +149,12 @@ public class JavaSourceTypeVisitor implements TypeVisitor<String>, GenericParame
144 149
 			output.append(cls == null ? importer.importType(type.definition) : importer.importType(cls));
145 150
 		}
146 151
 		
147
-		if (!isStatic && type.typeParameters.length > 0) {
152
+		if (!isStatic && type.typeArguments.length > 0) {
148 153
 			output.append("<");
149
-			for (int i = 0; i < type.typeParameters.length; i++) {
154
+			for (int i = 0; i < type.typeArguments.length; i++) {
150 155
 				if (i > 0)
151 156
 					output.append(", ");
152
-				output.append(type.typeParameters[i].accept(objectTypeVisitor));
157
+				output.append(type.typeArguments[i].accept(objectTypeVisitor));
153 158
 			}
154 159
 			output.append(">");
155 160
 		}

+ 2
- 1
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/CodeReader.java Просмотреть файл

@@ -65,6 +65,7 @@ import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
65 65
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
66 66
 import org.openzen.zenscript.codemodel.type.ITypeID;
67 67
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
68
+import org.openzen.zenscript.codemodel.type.StringTypeID;
68 69
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
69 70
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
70 71
 import org.openzen.zenscript.moduleserialization.CodePositionEncoding;
@@ -281,7 +282,7 @@ public class CodeReader implements CodeSerializationInput {
281 282
 			case TypeEncoding.TYPE_CHAR:
282 283
 				return BasicTypeID.CHAR;
283 284
 			case TypeEncoding.TYPE_STRING:
284
-				return BasicTypeID.STRING;
285
+				return new StringTypeID(storageTag);
285 286
 			case TypeEncoding.TYPE_UNDETERMINED:
286 287
 				return BasicTypeID.UNDETERMINED;
287 288
 			case TypeEncoding.TYPE_DEFINITION: {

+ 8
- 2
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/DeserializingModule.java Просмотреть файл

@@ -16,6 +16,7 @@ import org.openzen.zenscript.codemodel.context.ModuleContext;
16 16
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
17 17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18 18
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
+import org.openzen.zenscript.codemodel.type.storage.StorageType;
19 20
 import org.openzen.zenscript.compiler.CompilationUnit;
20 21
 import org.openzen.zenscript.compiler.SemanticModule;
21 22
 
@@ -35,6 +36,7 @@ public class DeserializingModule {
35 36
 	private final PackageDefinitions definitions = new PackageDefinitions();
36 37
 	private final List<ScriptBlock> scripts = new ArrayList<>();
37 38
 	private final AnnotationDefinition[] annotations;
39
+	private final StorageType[] storageTypes;
38 40
 	
39 41
 	private final List<ExpansionDefinition> expansions;
40 42
 	public final ModuleContext context;
@@ -45,7 +47,8 @@ public class DeserializingModule {
45 47
 			DeserializingModule[] dependencies,
46 48
 			ZSPackage rootPackage,
47 49
 			ZSPackage modulePackage,
48
-			AnnotationDefinition[] annotations)
50
+			AnnotationDefinition[] annotations,
51
+			StorageType[] storageTypes)
49 52
 	{
50 53
 		this.name = name;
51 54
 		this.module = new Module(name);
@@ -54,6 +57,7 @@ public class DeserializingModule {
54 57
 		this.rootPackage = rootPackage;
55 58
 		this.modulePackage = modulePackage;
56 59
 		this.annotations = annotations;
60
+		this.storageTypes = storageTypes;
57 61
 		
58 62
 		expansions = new ArrayList<>();
59 63
 		context = new ModuleContext(registry, module, expansions, rootPackage);
@@ -68,6 +72,7 @@ public class DeserializingModule {
68 72
 		this.rootPackage = module.rootPackage;
69 73
 		this.modulePackage = module.modulePackage;
70 74
 		this.annotations = module.annotations;
75
+		this.storageTypes = module.storageTypes;
71 76
 		
72 77
 		expansions = module.expansions;
73 78
 		context = module.getContext();
@@ -95,7 +100,8 @@ public class DeserializingModule {
95 100
 				scripts,
96 101
 				compilationUnit,
97 102
 				expansions,
98
-				annotations);
103
+				annotations,
104
+				storageTypes);
99 105
 	}
100 106
 	
101 107
 	public void add(HighLevelDefinition definition) {

+ 0
- 0
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/Main.java Просмотреть файл


Некоторые файлы не были показаны из-за большого количества измененных файлов

Загрузка…
Отмена
Сохранить