Browse Source

WIP on storage tags

Stan Hebben 6 years ago
parent
commit
e0e6b5be3f
100 changed files with 1252 additions and 347 deletions
  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 View File

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

+ 45
- 6
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java View File

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

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

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

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

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

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

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

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

84
 		
84
 		
85
 		if (types.containsKey(name.get(index).name)) {
85
 		if (types.containsKey(name.get(index).name)) {
86
 			CompilingType type = types.get(name.get(index).name);
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
 			return getInner(context, name, index + 1, type, result);
88
 			return getInner(context, name, index + 1, type, result);
89
 		}
89
 		}
90
 		
90
 		
99
 		if (innerType == null)
99
 		if (innerType == null)
100
 			return null;
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
 		return getInner(context, name, index + 1, innerType, innerResult);
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 View File

21
 	HighLevelDefinition load();
21
 	HighLevelDefinition load();
22
 	
22
 	
23
 	default DefinitionTypeID getInnerType(GlobalTypeRegistry registry, List<GenericName> name, int index, DefinitionTypeID outer) {
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
 		index++;
25
 		index++;
26
 		if (index == name.size())
26
 		if (index == name.size())
27
 			return type;
27
 			return type;

+ 11
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/FileResolutionContext.java View File

14
 import org.openzen.zenscript.codemodel.type.GenericName;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
17
 
18
 
18
 /**
19
 /**
19
  *
20
  *
44
 	}
45
 	}
45
 
46
 
46
 	@Override
47
 	@Override
47
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
48
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
48
 		if (imports.containsKey(name.get(0).name)) {
49
 		if (imports.containsKey(name.get(0).name)) {
49
 			return GenericName.getInnerType(
50
 			return GenericName.getInnerType(
50
 					getTypeRegistry(),
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
 					name,
53
 					name,
53
-					1);
54
+					1,
55
+					storage);
54
 		}
56
 		}
55
 		
57
 		
56
 		ITypeID moduleType = modulePackage.getType(this, name);
58
 		ITypeID moduleType = modulePackage.getType(this, name);
57
 		if (moduleType != null)
59
 		if (moduleType != null)
58
 			return moduleType;
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
 	@Override
70
 	@Override

+ 9
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java View File

13
 import org.openzen.zenscript.codemodel.type.GenericName;
13
 import org.openzen.zenscript.codemodel.type.GenericName;
14
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
16
 
17
 
17
 /**
18
 /**
18
  *
19
  *
40
 	}
41
 	}
41
 
42
 
42
 	@Override
43
 	@Override
43
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
44
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
44
 		if (type != null) {
45
 		if (type != null) {
45
 			CompilingType compiling = type.getInner(name.get(0).name);
46
 			CompilingType compiling = type.getInner(name.get(0).name);
46
 			if (compiling != null) {
47
 			if (compiling != null) {
52
 		if (name.size() == 1 && name.get(0).hasNoArguments()) {
53
 		if (name.size() == 1 && name.get(0).hasNoArguments()) {
53
 			for (TypeParameter parameter : parameters)
54
 			for (TypeParameter parameter : parameters)
54
 				if (parameter.name.equals(name.get(0).name))
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
 	@Override
67
 	@Override

+ 19
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/ModuleTypeResolutionContext.java View File

9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.Map;
10
 import java.util.Map;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13
+import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
15
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
16
 import org.openzen.zenscript.codemodel.type.GenericName;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
 import org.openzen.zenscript.codemodel.type.ISymbol;
18
 import org.openzen.zenscript.codemodel.type.ISymbol;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
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
 public class ModuleTypeResolutionContext implements TypeResolutionContext {
27
 public class ModuleTypeResolutionContext implements TypeResolutionContext {
24
 	private final GlobalTypeRegistry registry;
28
 	private final GlobalTypeRegistry registry;
25
 	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
29
 	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
30
+	private final Map<String, StorageType> storageTypes = new HashMap<>();
26
 	private final Map<String, ISymbol> globals;
31
 	private final Map<String, ISymbol> globals;
27
 	private final ZSPackage rootPackage;
32
 	private final ZSPackage rootPackage;
28
 	
33
 	
31
 	public ModuleTypeResolutionContext(
36
 	public ModuleTypeResolutionContext(
32
 			GlobalTypeRegistry registry,
37
 			GlobalTypeRegistry registry,
33
 			AnnotationDefinition[] annotations,
38
 			AnnotationDefinition[] annotations,
39
+			StorageType[] storageTypes,
34
 			ZSPackage rootPackage,
40
 			ZSPackage rootPackage,
35
 			CompilingPackage rootCompiling,
41
 			CompilingPackage rootCompiling,
36
 			Map<String, ISymbol> globals)
42
 			Map<String, ISymbol> globals)
42
 		
48
 		
43
 		for (AnnotationDefinition annotation : annotations)
49
 		for (AnnotationDefinition annotation : annotations)
44
 			this.annotations.put(annotation.getAnnotationName(), annotation);
50
 			this.annotations.put(annotation.getAnnotationName(), annotation);
51
+		for (StorageType storageType : storageTypes)
52
+			this.storageTypes.put(storageType.getName(), storageType);
45
 	}
53
 	}
46
 	
54
 	
47
 	@Override
55
 	@Override
55
 	}
63
 	}
56
 
64
 
57
 	@Override
65
 	@Override
58
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
66
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
59
 		if (rootCompiling != null) {
67
 		if (rootCompiling != null) {
60
 			ITypeID compiling = rootCompiling.getType(this, name);
68
 			ITypeID compiling = rootCompiling.getType(this, name);
61
 			if (compiling != null)
69
 			if (compiling != null)
63
 		}
71
 		}
64
 		
72
 		
65
 		if (name.size() == 1 && globals.containsKey(name.get(0).name))
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
 	@Override
87
 	@Override

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

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

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

11
 import org.openzen.zenscript.codemodel.type.GenericName;
11
 import org.openzen.zenscript.codemodel.type.GenericName;
12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14
 
15
 
15
 /**
16
 /**
16
  *
17
  *
21
 	
22
 	
22
 	AnnotationDefinition getAnnotation(String name);
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
 	ITypeID getThisType();
29
 	ITypeID getThisType();
27
 }
30
 }

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

41
 	public void setHeader(GlobalTypeRegistry registry, FunctionHeader header) {
41
 	public void setHeader(GlobalTypeRegistry registry, FunctionHeader header) {
42
 		this.header = header;
42
 		this.header = header;
43
 		addMember(caller = new CallerMember(position, this, modifiers | Modifiers.STATIC, header, null));
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
 	public void setCode(Statement statement) {
47
 	public void setCode(Statement statement) {

+ 10
- 9
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java View File

20
 import org.openzen.zenscript.codemodel.type.GenericName;
20
 import org.openzen.zenscript.codemodel.type.GenericName;
21
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
21
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
22
 import org.openzen.zenscript.codemodel.type.ITypeID;
22
 import org.openzen.zenscript.codemodel.type.ITypeID;
23
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
23
 
24
 
24
 /**
25
 /**
25
  *
26
  *
58
 			if (types.get(name.name).typeParameters.length != name.getNumberOfArguments())
59
 			if (types.get(name.name).typeParameters.length != name.getNumberOfArguments())
59
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
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
 		return null;
65
 		return null;
85
 		return null;
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
 		if (types.containsKey(name.name)) {
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
 		return null;
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
 		if (depth >= nameParts.size())
102
 		if (depth >= nameParts.size())
102
 			return null;
103
 			return null;
103
 		
104
 		
104
 		GenericName name = nameParts.get(depth);
105
 		GenericName name = nameParts.get(depth);
105
 		if (subPackages.containsKey(name.name) && name.hasNoArguments())
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
 		if (types.containsKey(name.name)) {
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
 		return null;
114
 		return null;

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

11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
+import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
14
 
15
 
15
 /**
16
 /**
16
  *
17
  *
26
 	}
27
 	}
27
 	
28
 	
28
 	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
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
 		this.value = value;
32
 		this.value = value;
32
 	}
33
 	}

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

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

130
 	
130
 	
131
 	public T visitStaticSetter(StaticSetterExpression expression);
131
 	public T visitStaticSetter(StaticSetterExpression expression);
132
 	
132
 	
133
+	public T visitStorageCast(StorageCastExpression expression);
134
+	
133
 	public T visitSupertypeCast(SupertypeCastExpression expression);
135
 	public T visitSupertypeCast(SupertypeCastExpression expression);
134
 	
136
 	
135
 	public T visitThis(ThisExpression expression);
137
 	public T visitThis(ThisExpression expression);

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

130
 	
130
 	
131
 	public R visitStaticSetter(C context, StaticSetterExpression expression);
131
 	public R visitStaticSetter(C context, StaticSetterExpression expression);
132
 	
132
 	
133
+	public R visitStorageCast(C context, StorageCastExpression expression);
134
+	
133
 	public R visitSupertypeCast(C context, SupertypeCastExpression expression);
135
 	public R visitSupertypeCast(C context, SupertypeCastExpression expression);
134
 	
136
 	
135
 	public R visitThis(C context, ThisExpression expression);
137
 	public R visitThis(C context, ThisExpression expression);

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

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.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 View File

60
 		if (definition.typeParameters != null) {
60
 		if (definition.typeParameters != null) {
61
 			parameters = new ITypeID[definition.typeParameters.length];
61
 			parameters = new ITypeID[definition.typeParameters.length];
62
 			for (int i = 0; i < parameters.length; i++)
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
 		if (autoGetterAccess != 0) {
66
 		if (autoGetterAccess != 0) {

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

12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
14
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
15
 
16
 
16
 /**
17
 /**
17
  *
18
  *
31
 		this.outerTypeArguments = outerTypeArguments;
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 View File

17
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
17
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
18
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
18
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
19
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
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
 	}
86
 	}
86
 	
87
 	
87
 	private static FunctionHeader createIteratorHeader(GlobalTypeRegistry registry, ITypeID[] iteratorTypes) {
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 View File

15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
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 View File

18
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 	}
56
 	}
56
 
57
 
57
 	@Override
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
 	@Override
68
 	@Override

+ 11
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java View File

22
 import org.openzen.zenscript.codemodel.type.ITypeID;
22
 import org.openzen.zenscript.codemodel.type.ITypeID;
23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
24
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 	@Override
48
 	@Override
48
 	public IPartialExpression get(CodePosition position, GenericName name) {
49
 	public IPartialExpression get(CodePosition position, GenericName name) {
49
 		if (typeParameters.containsKey(name.name) && !name.hasArguments())
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
 		return outer.get(position, name);
53
 		return outer.get(position, name);
53
 	}
54
 	}
54
 
55
 
55
 	@Override
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
 	@Override
69
 	@Override

+ 18
- 12
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java View File

31
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
31
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
32
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
32
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
33
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
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
 			
61
 			
61
 			for (TypeParameter parameter : expansion.typeParameters) {
62
 			for (TypeParameter parameter : expansion.typeParameters) {
62
 				genericParameters.put(parameter.name, parameter);
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
 		} else {
66
 		} else {
66
 			DefinitionTypeID definitionType = outer.getTypeRegistry().getForMyDefinition(definition);
67
 			DefinitionTypeID definitionType = outer.getTypeRegistry().getForMyDefinition(definition);
69
 			while (definitionType != null) {
70
 			while (definitionType != null) {
70
 				for (TypeParameter parameter : definitionType.definition.typeParameters) {
71
 				for (TypeParameter parameter : definitionType.definition.typeParameters) {
71
 					genericParameters.put(parameter.name, parameter);
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
 				definitionType = definitionType.definition.isStatic() ? null : definitionType.outer;
75
 				definitionType = definitionType.definition.isStatic() ? null : definitionType.outer;
75
 			}
76
 			}
92
 	public IPartialExpression get(CodePosition position, GenericName name) {
93
 	public IPartialExpression get(CodePosition position, GenericName name) {
93
 		if (members != null) {
94
 		if (members != null) {
94
 			if (members.hasInnerType(name.name))
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
 			if (members.hasMember(name.name) && !name.hasArguments())
97
 			if (members.hasMember(name.name) && !name.hasArguments())
97
 				return members.getMemberExpression(position, this, new ThisExpression(position, type), name, true);
98
 				return members.getMemberExpression(position, this, new ThisExpression(position, type), name, true);
98
 		} else if (innerTypes.containsKey(name.name)) {
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
 		if (genericParameters.containsKey(name.name) && !name.hasArguments())
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
 		return outer.get(position, name);
105
 		return outer.get(position, name);
105
 	}
106
 	}
106
 
107
 
107
 	@Override
108
 	@Override
108
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
109
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
109
 		if (members != null && members.hasInnerType(name.get(0).name)) {
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
 			for (int i = 1; i < name.size(); i++) {
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
 			return result;
115
 			return result;
115
 		} else if (genericParameters.containsKey(name.get(0).name) && name.size() == 1 && !name.get(0).hasArguments()) {
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
 		} else if (innerTypes.containsKey(name.get(0).name)) {
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
 			for (int i = 1; i < name.size(); i++) {
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
 			return result;
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
 	@Override
134
 	@Override

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java View File

27
 import org.openzen.zenscript.codemodel.type.ITypeID;
27
 import org.openzen.zenscript.codemodel.type.ITypeID;
28
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
28
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
29
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 	}
128
 	}
128
 	
129
 	
129
 	@Override
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
 	@Override
140
 	@Override

+ 11
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java View File

27
 import org.openzen.zenscript.codemodel.type.ITypeID;
27
 import org.openzen.zenscript.codemodel.type.ITypeID;
28
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
28
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
29
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 
58
 
58
 	@Override
59
 	@Override
59
 	public IPartialExpression get(CodePosition position, GenericName name) {
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
 		if (type != null)
62
 		if (type != null)
62
 			return new PartialTypeExpression(position, type, name.arguments);
63
 			return new PartialTypeExpression(position, type, name.arguments);
63
 		
64
 		
70
 	}
71
 	}
71
 
72
 
72
 	@Override
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
 		if (type != null)
76
 		if (type != null)
76
 			return type;
77
 			return type;
77
 		
78
 		
78
 		if (globals.containsKey(name.get(0).name)) {
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
 			for (int i = 1; i < name.size(); i++) {
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
 				if (type == null)
83
 				if (type == null)
83
 					break;
84
 					break;
84
 			}
85
 			}
90
 		return null;
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
 	@Override
99
 	@Override
94
 	public LoopStatement getLoop(String name) {
100
 	public LoopStatement getLoop(String name) {
95
 		return null;
101
 		return null;

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java View File

21
 import org.openzen.zenscript.codemodel.type.ITypeID;
21
 import org.openzen.zenscript.codemodel.type.ITypeID;
22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 	}
58
 	}
58
 
59
 
59
 	@Override
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
 	@Override
70
 	@Override

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

22
 import org.openzen.zenscript.codemodel.type.ITypeID;
22
 import org.openzen.zenscript.codemodel.type.ITypeID;
23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
24
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 			if (header.typeParameters != null) {
76
 			if (header.typeParameters != null) {
76
 				for (TypeParameter parameter : header.typeParameters) {
77
 				for (TypeParameter parameter : header.typeParameters) {
77
 					if (parameter.name.equals(name.name))
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
 	}
85
 	}
85
 
86
 
86
 	@Override
87
 	@Override
87
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
88
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
88
 		if (name.size() == 1 && name.get(0).hasNoArguments()) {
89
 		if (name.size() == 1 && name.get(0).hasNoArguments()) {
89
 			if (header.typeParameters != null) {
90
 			if (header.typeParameters != null) {
90
 				for (TypeParameter parameter : header.typeParameters) {
91
 				for (TypeParameter parameter : header.typeParameters) {
91
 					if (parameter.name.equals(name.get(0).name))
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
 	@Override
106
 	@Override

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

22
 import org.openzen.zenscript.codemodel.type.ITypeID;
22
 import org.openzen.zenscript.codemodel.type.ITypeID;
23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
24
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 	@Override
48
 	@Override
48
 	public IPartialExpression get(CodePosition position, GenericName name) {
49
 	public IPartialExpression get(CodePosition position, GenericName name) {
49
 		if (parameters.containsKey(name.name) && name.hasNoArguments())
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
 		return outer.get(position, name);
53
 		return outer.get(position, name);
53
 	}
54
 	}
54
 
55
 
55
 	@Override
56
 	@Override
56
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
57
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
57
 		if (name.size() == 1 && parameters.containsKey(name.get(0).name) && name.get(0).hasNoArguments())
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
 	@Override
69
 	@Override

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java View File

18
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 	}
46
 	}
46
 
47
 
47
 	@Override
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
 	@Override
58
 	@Override

+ 11
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java View File

22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
23
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
24
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
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
 	@Override
48
 	@Override
48
 	public IPartialExpression get(CodePosition position, GenericName name) {
49
 	public IPartialExpression get(CodePosition position, GenericName name) {
49
 		if (members.hasInnerType(name.name))
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
 		if (members.hasMember(name.name))
52
 		if (members.hasMember(name.name))
52
 			return members.getMemberExpression(position, this, new ThisExpression(position, outer.getThisType()), name, true);
53
 			return members.getMemberExpression(position, this, new ThisExpression(position, outer.getThisType()), name, true);
53
 		
54
 		
55
 	}
56
 	}
56
 
57
 
57
 	@Override
58
 	@Override
58
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
59
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
59
 		if (members.hasInnerType(name.get(0).name)) {
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
 			for (int i = 1; i < name.size(); i++) {
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
 			return result;
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
 	@Override
76
 	@Override

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java View File

21
 import org.openzen.zenscript.codemodel.type.ITypeID;
21
 import org.openzen.zenscript.codemodel.type.ITypeID;
22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 	}
71
 	}
71
 
72
 
72
 	@Override
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
 	@Override
83
 	@Override

+ 8
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java View File

18
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
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
 	}
48
 	}
48
 
49
 
49
 	@Override
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
 	@Override
60
 	@Override

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

12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.statement.VarStatement;
13
 import org.openzen.zenscript.codemodel.statement.VarStatement;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
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 View File

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Objects;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
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
  * @author Hoofdgebruiker
17
  * @author Hoofdgebruiker
15
  */
18
  */
16
 public class ArrayTypeID implements ITypeID {
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
 	public final ITypeID elementType;
26
 	public final ITypeID elementType;
21
 	public final int dimension;
27
 	public final int dimension;
28
+	public final StorageTag storage;
22
 	private final ArrayTypeID normalized;
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
 		this.elementType = elementType;
51
 		this.elementType = elementType;
26
 		this.dimension = dimension;
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
 	@Override
59
 	@Override
64
 	
93
 	
65
 	@Override
94
 	@Override
66
 	public ArrayTypeID instance(GenericMapper mapper) {
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
 	@Override
104
 	@Override
87
 		int hash = 7;
121
 		int hash = 7;
88
 		hash = 79 * hash + elementType.hashCode();
122
 		hash = 79 * hash + elementType.hashCode();
89
 		hash = 79 * hash + dimension;
123
 		hash = 79 * hash + dimension;
124
+		hash = 79 * hash + Objects.hashCode(storage);
90
 		return hash;
125
 		return hash;
91
 	}
126
 	}
92
 
127
 
102
 			return false;
137
 			return false;
103
 		}
138
 		}
104
 		final ArrayTypeID other = (ArrayTypeID) obj;
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
 	@Override
145
 	@Override
114
 			result.append(',');
151
 			result.append(',');
115
 		}
152
 		}
116
 		result.append(']');
153
 		result.append(']');
154
+		if (storage != null) {
155
+			result.append('`');
156
+			result.append(storage.toString());
157
+		}
117
 		return result.toString();
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 View File

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Objects;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
11
 
13
 
12
 /**
14
 /**
13
  *
15
  *
16
 public class AssocTypeID implements ITypeID {
18
 public class AssocTypeID implements ITypeID {
17
 	public final ITypeID keyType;
19
 	public final ITypeID keyType;
18
 	public final ITypeID valueType;
20
 	public final ITypeID valueType;
21
+	public final StorageTag storage;
19
 	private final AssocTypeID normalized;
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
 		this.keyType = keyType;
26
 		this.keyType = keyType;
23
 		this.valueType = valueType;
27
 		this.valueType = valueType;
28
+		this.storage = storage;
24
 		
29
 		
25
 		if (keyType != keyType.getNormalized() || valueType != valueType.getNormalized())
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
 		else
32
 		else
28
 			normalized = this;
33
 			normalized = this;
34
+		
35
+		withoutStorage = storage == null ? this : typeRegistry.getAssociative(normalized.keyType, normalized.valueType, null);
29
 	}
36
 	}
30
 	
37
 	
31
 	@Override
38
 	@Override
32
 	public AssocTypeID instance(GenericMapper mapper) {
39
 	public AssocTypeID instance(GenericMapper mapper) {
33
 		return mapper.registry.getAssociative(
40
 		return mapper.registry.getAssociative(
34
 				keyType.instance(mapper),
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
 	@Override
51
 	@Override
91
 		int hash = 7;
104
 		int hash = 7;
92
 		hash = 29 * hash + keyType.hashCode();
105
 		hash = 29 * hash + keyType.hashCode();
93
 		hash = 29 * hash + valueType.hashCode();
106
 		hash = 29 * hash + valueType.hashCode();
107
+		hash = 29 * hash + Objects.hashCode(storage);
94
 		return hash;
108
 		return hash;
95
 	}
109
 	}
96
 
110
 
106
 			return false;
120
 			return false;
107
 		}
121
 		}
108
 		final AssocTypeID other = (AssocTypeID) obj;
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
 	@Override
128
 	@Override
118
 		result.append(']');
134
 		result.append(']');
119
 		return result.toString();
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 View File

9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
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
 	public ITypeID instance(GenericMapper mapper) {
52
 	public ITypeID instance(GenericMapper mapper) {
51
 		return this;
53
 		return this;
52
 	}
54
 	}
55
+
56
+	@Override
57
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage) {
58
+		return this;
59
+	}
53
 	
60
 	
54
 	@Override
61
 	@Override
55
 	public String toString() {
62
 	public String toString() {
100
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
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 View File

16
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
16
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
17
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
17
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
18
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
18
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
19
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
19
 
20
 
20
 /**
21
 /**
21
  *
22
  *
22
  * @author Hoofdgebruiker
23
  * @author Hoofdgebruiker
23
  */
24
  */
24
 public class DefinitionTypeID implements ITypeID {
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
 		if (definition.typeParameters != null && definition.typeParameters.length > 0)
27
 		if (definition.typeParameters != null && definition.typeParameters.length > 0)
27
 			throw new IllegalArgumentException("Definition has type arguments!");
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
 	public final HighLevelDefinition definition;
33
 	public final HighLevelDefinition definition;
33
-	public final ITypeID[] typeParameters;
34
+	public final ITypeID[] typeArguments;
34
 	public final DefinitionTypeID outer;
35
 	public final DefinitionTypeID outer;
36
+	public final StorageTag storage;
35
 	private ITypeID normalized;
37
 	private ITypeID normalized;
38
+	private ITypeID withoutStorage;
36
 	
39
 	
37
 	public ITypeID superType;
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
 	// For inner classes of generic outer classes
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
 		if (typeParameters == null)
48
 		if (typeParameters == null)
46
 			throw new NullPointerException("typeParameters cannot be null");
49
 			throw new NullPointerException("typeParameters cannot be null");
47
 		if (typeParameters.length != definition.getNumberOfGenericParameters())
50
 		if (typeParameters.length != definition.getNumberOfGenericParameters())
52
 			throw new IllegalArgumentException("Static inner definition must not have outer instance");
55
 			throw new IllegalArgumentException("Static inner definition must not have outer instance");
53
 		
56
 		
54
 		this.definition = definition;
57
 		this.definition = definition;
55
-		this.typeParameters = typeParameters;
58
+		this.typeArguments = typeParameters;
56
 		this.outer = outer;
59
 		this.outer = outer;
60
+		this.storage = storage;
57
 		
61
 		
58
 		normalized = isDenormalized() ? normalize(typeRegistry) : this;
62
 		normalized = isDenormalized() ? normalize(typeRegistry) : this;
59
 		if (normalized instanceof DefinitionTypeID && ((DefinitionTypeID)normalized).isDenormalized())
63
 		if (normalized instanceof DefinitionTypeID && ((DefinitionTypeID)normalized).isDenormalized())
60
 			throw new AssertionError();
64
 			throw new AssertionError();
65
+		
66
+		withoutStorage = storage == null ? this : typeRegistry.getForDefinition(definition, typeParameters, outer, null);
61
 	}
67
 	}
62
 	
68
 	
63
 	private boolean isDenormalized() {
69
 	private boolean isDenormalized() {
64
 		if (definition instanceof AliasDefinition)
70
 		if (definition instanceof AliasDefinition)
65
 			return true;
71
 			return true;
66
 		
72
 		
67
-		for (ITypeID typeParameter : typeParameters)
73
+		for (ITypeID typeParameter : typeArguments)
68
 			if (typeParameter.getNormalized() != typeParameter)
74
 			if (typeParameter.getNormalized() != typeParameter)
69
 				return true;
75
 				return true;
70
 		if (outer != null && outer.getNormalized() != outer)
76
 		if (outer != null && outer.getNormalized() != outer)
81
 			
87
 			
82
 			Map<TypeParameter, ITypeID> typeMapping = new HashMap<>();
88
 			Map<TypeParameter, ITypeID> typeMapping = new HashMap<>();
83
 			for (int i = 0; i < definition.typeParameters.length; i++)
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
 			GenericMapper mapper = new GenericMapper(typeRegistry, typeMapping);
91
 			GenericMapper mapper = new GenericMapper(typeRegistry, typeMapping);
86
 			ITypeID result = alias.type.instance(mapper).getNormalized();
92
 			ITypeID result = alias.type.instance(mapper).getNormalized();
87
 			return result;
93
 			return result;
88
 		}
94
 		}
89
 		
95
 		
90
-		ITypeID[] normalizedTypeParameters = new ITypeID[typeParameters.length];
96
+		ITypeID[] normalizedTypeParameters = new ITypeID[typeArguments.length];
91
 		for (int i = 0; i < normalizedTypeParameters.length; i++)
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
 	public boolean hasTypeParameters() {
103
 	public boolean hasTypeParameters() {
98
-		return typeParameters.length > 0;
104
+		return typeArguments.length > 0;
99
 	}
105
 	}
100
 	
106
 	
101
 	public Map<TypeParameter, ITypeID> getTypeParameterMapping() {
107
 	public Map<TypeParameter, ITypeID> getTypeParameterMapping() {
102
 		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
108
 		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
103
 		DefinitionTypeID current = this;
109
 		DefinitionTypeID current = this;
104
 		do {
110
 		do {
105
-			if (current.typeParameters != null) {
111
+			if (current.typeArguments != null) {
106
 				if (current.definition.typeParameters == null)
112
 				if (current.definition.typeParameters == null)
107
 					System.out.println("Type parameters but no generic parameters");
113
 					System.out.println("Type parameters but no generic parameters");
108
 				else
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
 			current = current.outer;
119
 			current = current.outer;
115
 		return mapping;
121
 		return mapping;
116
 	}
122
 	}
117
 	
123
 	
118
-	public DefinitionTypeID(HighLevelDefinition definition) {
124
+	public DefinitionTypeID(HighLevelDefinition definition, StorageTag storage) {
119
 		this.definition = definition;
125
 		this.definition = definition;
120
-		this.typeParameters = ITypeID.NONE;
126
+		this.typeArguments = ITypeID.NONE;
121
 		this.superType = definition.getSuperType();
127
 		this.superType = definition.getSuperType();
122
 		this.outer = null;
128
 		this.outer = null;
129
+		this.storage = storage;
123
 	}
130
 	}
124
 	
131
 	
125
 	@Override
132
 	@Override
138
 		
145
 		
139
 		ITypeID[] instancedArguments = ITypeID.NONE;
146
 		ITypeID[] instancedArguments = ITypeID.NONE;
140
 		if (hasTypeParameters()) {
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
 		DefinitionTypeID instancedOuter = outer == null ? null : outer.instance(mapper);
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
 	@Override
162
 	@Override
201
 	@Override
212
 	@Override
202
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
213
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
203
 		if (hasTypeParameters()) {
214
 		if (hasTypeParameters()) {
204
-			for (ITypeID typeParameter : typeParameters)
215
+			for (ITypeID typeParameter : typeArguments)
205
 				if (typeParameter.hasInferenceBlockingTypeParameters(parameters))
216
 				if (typeParameter.hasInferenceBlockingTypeParameters(parameters))
206
 					return true;
217
 					return true;
207
 		}
218
 		}
213
 	public int hashCode() {
224
 	public int hashCode() {
214
 		int hash = 7;
225
 		int hash = 7;
215
 		hash = 97 * hash + definition.hashCode();
226
 		hash = 97 * hash + definition.hashCode();
216
-		hash = 97 * hash + Arrays.deepHashCode(typeParameters);
227
+		hash = 97 * hash + Arrays.deepHashCode(typeArguments);
217
 		hash = 97 * hash + Objects.hashCode(outer);
228
 		hash = 97 * hash + Objects.hashCode(outer);
229
+		hash = 97 * hash + Objects.hashCode(storage);
218
 		return hash;
230
 		return hash;
219
 	}
231
 	}
220
 
232
 
231
 		}
243
 		}
232
 		final DefinitionTypeID other = (DefinitionTypeID) obj;
244
 		final DefinitionTypeID other = (DefinitionTypeID) obj;
233
 		return this.definition == other.definition
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
 	@Override
251
 	@Override
246
 		
259
 		
247
 		result.append(definition.name);
260
 		result.append(definition.name);
248
 		result.append('<');
261
 		result.append('<');
249
-		for (int i = 0; i < typeParameters.length; i++) { 
262
+		for (int i = 0; i < typeArguments.length; i++) { 
250
 			if (i > 0)
263
 			if (i > 0)
251
 				result.append(", ");
264
 				result.append(", ");
252
-			result.append(typeParameters[i].toString());
265
+			result.append(typeArguments[i].toString());
253
 		}
266
 		}
254
 		result.append('>');
267
 		result.append('>');
255
 		return result.toString();
268
 		return result.toString();
262
 
275
 
263
 	@Override
276
 	@Override
264
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
277
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
265
-		for (ITypeID type : this.typeParameters)
278
+		for (ITypeID type : this.typeArguments)
266
 			type.extractTypeParameters(typeParameters);
279
 			type.extractTypeParameters(typeParameters);
267
 	}
280
 	}
268
 	
281
 	
271
 		return definition.isDestructible();
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
 		HighLevelDefinition type = definition.getInnerType(name.name);
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 View File

7
 
7
 
8
 import java.util.Arrays;
8
 import java.util.Arrays;
9
 import java.util.List;
9
 import java.util.List;
10
+import java.util.Objects;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionParameter;
12
 import org.openzen.zenscript.codemodel.FunctionParameter;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14
 
16
 
15
 /**
17
 /**
16
  *
18
  *
18
  */
20
  */
19
 public class FunctionTypeID implements ITypeID {
21
 public class FunctionTypeID implements ITypeID {
20
 	public final FunctionHeader header;
22
 	public final FunctionHeader header;
23
+	public final StorageTag storage;
21
 	private final FunctionTypeID normalized;
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
 		this.header = header;
28
 		this.header = header;
29
+		this.storage = storage;
25
 		
30
 		
26
 		FunctionHeader normalizedHeader = header.normalize(registry);
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
 	@Override
36
 	@Override
34
 	
40
 	
35
 	@Override
41
 	@Override
36
 	public ITypeID instance(GenericMapper mapper) {
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
 	@Override
51
 	@Override
90
 		hash = 71 * hash + header.getReturnType().hashCode();
101
 		hash = 71 * hash + header.getReturnType().hashCode();
91
 		hash = 71 * hash + Arrays.deepHashCode(header.parameters);
102
 		hash = 71 * hash + Arrays.deepHashCode(header.parameters);
92
 		hash = 71 * hash + Arrays.deepHashCode(header.typeParameters);
103
 		hash = 71 * hash + Arrays.deepHashCode(header.typeParameters);
104
+		hash = 71 * hash + Objects.hashCode(storage);
93
 		return hash;
105
 		return hash;
94
 	}
106
 	}
95
 
107
 
107
 		final FunctionTypeID other = (FunctionTypeID) obj;
119
 		final FunctionTypeID other = (FunctionTypeID) obj;
108
 		return this.header.getReturnType() == other.header.getReturnType()
120
 		return this.header.getReturnType() == other.header.getReturnType()
109
 				&& Arrays.deepEquals(this.header.parameters, other.header.parameters)
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
 	@Override
126
 	@Override
128
 		result.append(header.getReturnType());
141
 		result.append(header.getReturnType());
129
 		return result.toString();
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 View File

9
 import java.util.Objects;
9
 import java.util.Objects;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
12
 
13
 
13
 /**
14
 /**
14
  *
15
  *
17
 public class GenericMapTypeID implements ITypeID {
18
 public class GenericMapTypeID implements ITypeID {
18
 	public final ITypeID value;
19
 	public final ITypeID value;
19
 	public final TypeParameter key;
20
 	public final TypeParameter key;
21
+	public final StorageTag storage;
20
 	private final GenericMapTypeID normalized;
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
 		this.value = value;
26
 		this.value = value;
24
 		this.key = key;
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
 	@Override
34
 	@Override
58
 
63
 
59
 	@Override
64
 	@Override
60
 	public ITypeID instance(GenericMapper mapper) {
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
 	@Override
74
 	@Override
97
 		int hash = 5;
107
 		int hash = 5;
98
 		hash = 97 * hash + this.value.hashCode();
108
 		hash = 97 * hash + this.value.hashCode();
99
 		hash = 97 * hash + this.key.hashCode();
109
 		hash = 97 * hash + this.key.hashCode();
110
+		hash = 97 * hash + Objects.hashCode(this.storage);
100
 		return hash;
111
 		return hash;
101
 	}
112
 	}
102
 
113
 
103
 	@Override
114
 	@Override
104
 	public boolean equals(Object obj) {
115
 	public boolean equals(Object obj) {
105
-		if (this == obj) {
116
+		if (this == obj)
106
 			return true;
117
 			return true;
107
-		}
108
-		if (obj == null) {
118
+		if (obj == null)
109
 			return false;
119
 			return false;
110
-		}
111
-		if (getClass() != obj.getClass()) {
120
+		if (getClass() != obj.getClass())
112
 			return false;
121
 			return false;
113
-		}
122
+		
114
 		final GenericMapTypeID other = (GenericMapTypeID) obj;
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 View File

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
9
 
10
 
10
 /**
11
 /**
11
  *
12
  *
39
 		return arguments.length == 0;
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
 		while (index < name.size()) {
44
 		while (index < name.size()) {
44
 			GenericName innerName = name.get(index++);
45
 			GenericName innerName = name.get(index++);
45
-			type = type.getInnerType(innerName, registry);
46
+			type = type.getInnerType(innerName, registry, storage);
46
 			if (type == null)
47
 			if (type == null)
47
 				return null;
48
 				return null;
48
 		}
49
 		}

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

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Objects;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
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
  */
18
  */
17
 public class GenericTypeID implements ITypeID {
19
 public class GenericTypeID implements ITypeID {
18
 	public final TypeParameter parameter;
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
 		this.parameter = parameter;
25
 		this.parameter = parameter;
26
+		this.storage = storage;
27
+		withoutStorage = storage == null ? this : registry.getGeneric(parameter, null);
22
 	}
28
 	}
23
 	
29
 	
24
 	public boolean matches(LocalMemberCache cache, ITypeID type) {
30
 	public boolean matches(LocalMemberCache cache, ITypeID type) {
32
 	
38
 	
33
 	@Override
39
 	@Override
34
 	public ITypeID instance(GenericMapper mapper) {
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
 	@Override
49
 	@Override
89
 	public int hashCode() {
100
 	public int hashCode() {
90
 		int hash = 7;
101
 		int hash = 7;
91
 		hash = 47 * hash + parameter.hashCode();
102
 		hash = 47 * hash + parameter.hashCode();
103
+		hash = 47 * hash + Objects.hashCode(storage);
92
 		return hash;
104
 		return hash;
93
 	}
105
 	}
94
 
106
 
104
 			return false;
116
 			return false;
105
 		}
117
 		}
106
 		final GenericTypeID other = (GenericTypeID) obj;
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
 	@Override
123
 	@Override
111
 	public String toString() {
124
 	public String toString() {
112
 		return parameter.toString();
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 View File

11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
12
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
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
  * @author Hoofdgebruiker
19
  * @author Hoofdgebruiker
18
  */
20
  */
19
 public class GlobalTypeRegistry {
21
 public class GlobalTypeRegistry {
22
+	private final Map<StringTypeID, StringTypeID> stringTypes = new HashMap<>();
20
 	private final Map<ArrayTypeID, ArrayTypeID> arrayTypes = new HashMap<>();
23
 	private final Map<ArrayTypeID, ArrayTypeID> arrayTypes = new HashMap<>();
21
 	private final Map<AssocTypeID, AssocTypeID> assocTypes = new HashMap<>();
24
 	private final Map<AssocTypeID, AssocTypeID> assocTypes = new HashMap<>();
22
 	private final Map<GenericMapTypeID, GenericMapTypeID> genericMapTypes = new HashMap<>();
25
 	private final Map<GenericMapTypeID, GenericMapTypeID> genericMapTypes = new HashMap<>();
33
 	public GlobalTypeRegistry(ZSPackage stdlib) {
36
 	public GlobalTypeRegistry(ZSPackage stdlib) {
34
 		this.stdlib = stdlib;
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
 		rangeTypes.put(RangeTypeID.INT, RangeTypeID.INT);
49
 		rangeTypes.put(RangeTypeID.INT, RangeTypeID.INT);
40
 		rangeTypes.put(RangeTypeID.USIZE, RangeTypeID.USIZE);
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
 		if (functionTypes.containsKey(id)) {
80
 		if (functionTypes.containsKey(id)) {
86
 			return functionTypes.get(id);
81
 			return functionTypes.get(id);
87
 		} else {
82
 		} else {
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
 		if (genericTypes.containsKey(id)) {
100
 		if (genericTypes.containsKey(id)) {
106
 			return genericTypes.get(id);
101
 			return genericTypes.get(id);
107
 		} else {
102
 		} else {
115
 		if (definition.getNumberOfGenericParameters() > 0) {
110
 		if (definition.getNumberOfGenericParameters() > 0) {
116
 			typeArguments = new ITypeID[definition.getNumberOfGenericParameters()];
111
 			typeArguments = new ITypeID[definition.getNumberOfGenericParameters()];
117
 			for (int i = 0; i < definition.typeParameters.length; i++)
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
 		DefinitionTypeID outer = null;
115
 		DefinitionTypeID outer = null;
121
 		if (definition.outerDefinition != null)
116
 		if (definition.outerDefinition != null)
122
 			outer = getForMyDefinition(definition.outerDefinition);
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
 		if (definitionTypes.containsKey(id)) {
129
 		if (definitionTypes.containsKey(id)) {
135
 			return definitionTypes.get(id);
130
 			return definitionTypes.get(id);
152
 		}
147
 		}
153
 		
148
 		
154
 		ModifiedTypeID result = new ModifiedTypeID(this, modifiers, type);
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
 		} else {
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 View File

9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
10
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
10
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.scope.BaseScope;
11
 import org.openzen.zenscript.codemodel.scope.BaseScope;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
12
 
13
 
13
 /**
14
 /**
14
  *
15
  *
17
 public interface ISymbol {
18
 public interface ISymbol {
18
 	public IPartialExpression getExpression(CodePosition position, BaseScope scope, ITypeID[] typeArguments);
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 View File

11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
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
 		throw new UnsupportedOperationException("Not an immutable type");
56
 		throw new UnsupportedOperationException("Not an immutable type");
56
 	}
57
 	}
57
 	
58
 	
59
+	public ITypeID withoutStorage();
60
+	
61
+	public StorageTag getStorage();
62
+	
58
 	public boolean hasDefaultValue();
63
 	public boolean hasDefaultValue();
59
 	
64
 	
60
 	public boolean isObjectType();
65
 	public boolean isObjectType();
73
 	
78
 	
74
 	public ITypeID instance(GenericMapper mapper);
79
 	public ITypeID instance(GenericMapper mapper);
75
 	
80
 	
81
+	public ITypeID withStorage(GlobalTypeRegistry registry, StorageTag storage);
82
+	
76
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);
83
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);
77
 	
84
 	
78
 	// Infers type parameters for this type so it matches with targetType
85
 	// Infers type parameters for this type so it matches with targetType
177
 				if (definitionType.definition != definition.definition)
184
 				if (definitionType.definition != definition.definition)
178
 					return false;
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
 							return false;
190
 							return false;
184
 					}
191
 					}
185
 				}
192
 				}

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

7
 
7
 
8
 import java.util.Arrays;
8
 import java.util.Arrays;
9
 import java.util.List;
9
 import java.util.List;
10
-import java.util.Map;
10
+import java.util.Objects;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
13
 
14
 
14
 /**
15
 /**
15
  *
16
  *
17
  */
18
  */
18
 public class IteratorTypeID implements ITypeID {
19
 public class IteratorTypeID implements ITypeID {
19
 	public final ITypeID[] iteratorTypes;
20
 	public final ITypeID[] iteratorTypes;
21
+	public final StorageTag storage;
20
 	private final IteratorTypeID normalized;
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
 		this.iteratorTypes = iteratorTypes;
26
 		this.iteratorTypes = iteratorTypes;
27
+		this.storage = storage;
24
 		
28
 		
25
 		normalized = isDenormalized() ? normalize(registry) : this;
29
 		normalized = isDenormalized() ? normalize(registry) : this;
30
+		withoutStorage = storage == null ? this : registry.getIterator(iteratorTypes, null);
26
 	}
31
 	}
27
 	
32
 	
28
 	@Override
33
 	@Override
42
 		ITypeID[] normalizedTypes = new ITypeID[iteratorTypes.length];
47
 		ITypeID[] normalizedTypes = new ITypeID[iteratorTypes.length];
43
 		for (int i = 0; i < normalizedTypes.length; i++)
48
 		for (int i = 0; i < normalizedTypes.length; i++)
44
 			normalizedTypes[i] = iteratorTypes[i].getNormalized();
49
 			normalizedTypes[i] = iteratorTypes[i].getNormalized();
45
-		return registry.getIterator(normalizedTypes);
50
+		return registry.getIterator(normalizedTypes, storage);
46
 	}
51
 	}
47
 
52
 
48
 	@Override
53
 	@Override
80
 		ITypeID[] instanced = new ITypeID[iteratorTypes.length];
85
 		ITypeID[] instanced = new ITypeID[iteratorTypes.length];
81
 		for (int i = 0; i < iteratorTypes.length; i++)
86
 		for (int i = 0; i < iteratorTypes.length; i++)
82
 			instanced[i] = iteratorTypes[i].instance(mapper);
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
 	@Override
96
 	@Override
107
 	public int hashCode() {
117
 	public int hashCode() {
108
 		int hash = 5;
118
 		int hash = 5;
109
 		hash = 13 * hash + Arrays.deepHashCode(this.iteratorTypes);
119
 		hash = 13 * hash + Arrays.deepHashCode(this.iteratorTypes);
120
+		hash = 13 * hash + Objects.hashCode(storage);
110
 		return hash;
121
 		return hash;
111
 	}
122
 	}
112
 
123
 
122
 			return false;
133
 			return false;
123
 		}
134
 		}
124
 		final IteratorTypeID other = (IteratorTypeID) obj;
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 View File

10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
13
 
14
 
14
 /**
15
 /**
15
  *
16
  *
24
 	public final ITypeID baseType;
25
 	public final ITypeID baseType;
25
 	private final ITypeID normalized;
26
 	private final ITypeID normalized;
26
 	private final GlobalTypeRegistry registry;
27
 	private final GlobalTypeRegistry registry;
28
+	private final ITypeID withoutStorage;
27
 	
29
 	
28
 	public ModifiedTypeID(GlobalTypeRegistry registry, int modifiers, ITypeID baseType) {
30
 	public ModifiedTypeID(GlobalTypeRegistry registry, int modifiers, ITypeID baseType) {
29
 		this.modifiers = modifiers;
31
 		this.modifiers = modifiers;
31
 		this.registry = registry;
33
 		this.registry = registry;
32
 		
34
 		
33
 		normalized = baseType.getNormalized() == baseType ? this : registry.getModified(modifiers, baseType.getNormalized());
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
 	@Override
39
 	@Override
43
 		return mapper.registry.getModified(modifiers, baseType.instance(mapper));
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
 	@Override
54
 	@Override
47
 	public <T> T accept(TypeVisitor<T> visitor) {
55
 	public <T> T accept(TypeVisitor<T> visitor) {
48
 		return visitor.visitModified(this);
56
 		return visitor.visitModified(this);
122
 	public int hashCode() {
130
 	public int hashCode() {
123
 		int hash = 3;
131
 		int hash = 3;
124
 		hash = 79 * hash + Objects.hashCode(this.baseType);
132
 		hash = 79 * hash + Objects.hashCode(this.baseType);
133
+		hash = 79 * hash + modifiers;
125
 		return hash;
134
 		return hash;
126
 	}
135
 	}
127
 
136
 
128
 	@Override
137
 	@Override
129
 	public boolean equals(Object obj) {
138
 	public boolean equals(Object obj) {
130
-		if (this == obj) {
139
+		if (this == obj)
131
 			return true;
140
 			return true;
132
-		}
133
-		if (obj == null) {
141
+		if (obj == null)
134
 			return false;
142
 			return false;
135
-		}
136
-		if (getClass() != obj.getClass()) {
143
+		if (getClass() != obj.getClass())
137
 			return false;
144
 			return false;
138
-		}
139
 		final ModifiedTypeID other = (ModifiedTypeID) obj;
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
 	@Override
150
 	@Override
152
 			result.append("?");
159
 			result.append("?");
153
 		return result.toString();
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 View File

8
 import java.util.List;
8
 import java.util.List;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
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
 	public ITypeID instance(GenericMapper mapper) {
41
 	public ITypeID instance(GenericMapper mapper) {
40
 		return mapper.registry.getRange(baseType.instance(mapper));
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
 	@Override
50
 	@Override
44
 	public <T> T accept(TypeVisitor<T> visitor) {
51
 	public <T> T accept(TypeVisitor<T> visitor) {
111
 	public String toString() {
118
 	public String toString() {
112
 		return baseType.toString() + " .. " + baseType.toString();
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 View File

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Objects;
9
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.type.storage.AnyStorageTag;
12
 import org.openzen.zenscript.codemodel.type.storage.AnyStorageTag;
25
 	public static final StringTypeID UNIQUE = new StringTypeID(UniqueStorageTag.INSTANCE);
26
 	public static final StringTypeID UNIQUE = new StringTypeID(UniqueStorageTag.INSTANCE);
26
 	public static final StringTypeID BORROW = new StringTypeID(BorrowStorageTag.INVOCATION);
27
 	public static final StringTypeID BORROW = new StringTypeID(BorrowStorageTag.INVOCATION);
27
 	public static final StringTypeID SHARED = new StringTypeID(SharedStorageTag.INSTANCE);
28
 	public static final StringTypeID SHARED = new StringTypeID(SharedStorageTag.INSTANCE);
29
+	public static final StringTypeID NOSTORAGE = new StringTypeID(null);
28
 	
30
 	
29
 	public final StorageTag storage;
31
 	public final StorageTag storage;
30
 	
32
 	
64
 
66
 
65
 	@Override
67
 	@Override
66
 	public ITypeID instance(GenericMapper mapper) {
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
 	@Override
77
 	@Override
71
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
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
 	@Override
82
 	@Override
76
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
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 View File

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

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

11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
12
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
13
 import org.openzen.zenscript.codemodel.scope.BaseScope;
13
 import org.openzen.zenscript.codemodel.scope.BaseScope;
14
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14
 
15
 
15
 /**
16
 /**
16
  *
17
  *
25
 	
26
 	
26
 	@Override
27
 	@Override
27
 	public IPartialExpression getExpression(CodePosition position, BaseScope scope, ITypeID[] typeArguments) {
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
 	@Override
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 View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.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 View File

73
 import org.openzen.zenscript.codemodel.member.IteratorMember;
73
 import org.openzen.zenscript.codemodel.member.IteratorMember;
74
 import org.openzen.zenscript.codemodel.type.StringTypeID;
74
 import org.openzen.zenscript.codemodel.type.StringTypeID;
75
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
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
 	public Void visitString(StringTypeID string) {
177
 	public Void visitString(StringTypeID string) {
174
 		ClassDefinition builtin = new ClassDefinition(BUILTIN, Module.BUILTIN, null, "string", Modifiers.EXPORT, null);
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
 		add(builtin, STRING_ADD_STRING, StringTypeID.BORROW, StringTypeID.UNIQUE);
182
 		add(builtin, STRING_ADD_STRING, StringTypeID.BORROW, StringTypeID.UNIQUE);
179
 		indexGet(builtin, STRING_INDEXGET, USIZE, CHAR);
183
 		indexGet(builtin, STRING_INDEXGET, USIZE, CHAR);
181
 		compare(builtin, STRING_COMPARE, StringTypeID.BORROW);
185
 		compare(builtin, STRING_COMPARE, StringTypeID.BORROW);
182
 		
186
 		
183
 		getter(builtin, STRING_LENGTH, "length", USIZE);
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
 		getter(builtin, STRING_ISEMPTY, "isEmpty", BOOL);
189
 		getter(builtin, STRING_ISEMPTY, "isEmpty", BOOL);
186
 
190
 
187
 		method(builtin, STRING_REMOVE_DIACRITICS, "removeDiacritics", StringTypeID.BORROW);
191
 		method(builtin, STRING_REMOVE_DIACRITICS, "removeDiacritics", StringTypeID.BORROW);
220
 					ARRAY_INDEXGETRANGE);
224
 					ARRAY_INDEXGETRANGE);
221
 			
225
 			
222
 			if (baseType == BYTE)
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
 			if (baseType == SBYTE)
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
 			if (baseType == SHORT)
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
 			if (baseType == USHORT)
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
 			if (baseType == INT)
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
 			if (baseType == UINT)
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
 			if (baseType == LONG)
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
 			if (baseType == ULONG)
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
 		FunctionHeader containsHeader = new FunctionHeader(BOOL, new FunctionParameter(baseType, "value"));
244
 		FunctionHeader containsHeader = new FunctionHeader(BOOL, new FunctionParameter(baseType, "value"));
271
 			lambdaConstructorParameters[i] = new FunctionParameter(USIZE, null);
275
 			lambdaConstructorParameters[i] = new FunctionParameter(USIZE, null);
272
 		
276
 		
273
 		FunctionHeader lambdaConstructorFunction = new FunctionHeader(baseType, indexGetParameters);
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
 		FunctionHeader lambdaConstructorHeader = new FunctionHeader(VOID, lambdaConstructorParameters);
279
 		FunctionHeader lambdaConstructorHeader = new FunctionHeader(VOID, lambdaConstructorParameters);
276
 		members.addConstructor(new ConstructorMember(
280
 		members.addConstructor(new ConstructorMember(
277
 				BUILTIN,
281
 				BUILTIN,
282
 		
286
 		
283
 		{
287
 		{
284
 			TypeParameter mappedConstructorParameter = new TypeParameter(BUILTIN, "T");
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
 			FunctionHeader mappedConstructorFunctionWithoutIndex = new FunctionHeader(
290
 			FunctionHeader mappedConstructorFunctionWithoutIndex = new FunctionHeader(
287
 					new TypeParameter[] { mappedConstructorParameter },
291
 					new TypeParameter[] { mappedConstructorParameter },
288
 					VOID,
292
 					VOID,
289
 					null,
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
 			members.addConstructor(new ConstructorMember(
296
 			members.addConstructor(new ConstructorMember(
293
 					BUILTIN,
297
 					BUILTIN,
294
 					definition,
298
 					definition,
302
 			FunctionParameter[] projectionParameters = new FunctionParameter[dimension + 1];
306
 			FunctionParameter[] projectionParameters = new FunctionParameter[dimension + 1];
303
 			for (int i = 0; i < dimension; i++)
307
 			for (int i = 0; i < dimension; i++)
304
 				projectionParameters[i] = new FunctionParameter(USIZE);
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
 			FunctionHeader mappedConstructorHeaderWithIndex = new FunctionHeader(baseType, projectionParameters);
311
 			FunctionHeader mappedConstructorHeaderWithIndex = new FunctionHeader(baseType, projectionParameters);
308
 			FunctionHeader mappedConstructorFunctionWithIndex = new FunctionHeader(
312
 			FunctionHeader mappedConstructorFunctionWithIndex = new FunctionHeader(
309
 					new TypeParameter[] { mappedConstructorParameter },
313
 					new TypeParameter[] { mappedConstructorParameter },
310
 					VOID,
314
 					VOID,
311
 					null,
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
 			constructor(definition, ARRAY_CONSTRUCTOR_PROJECTED_INDEXED, mappedConstructorFunctionWithIndex);
318
 			constructor(definition, ARRAY_CONSTRUCTOR_PROJECTED_INDEXED, mappedConstructorFunctionWithIndex);
315
 		}
319
 		}
316
 		
320
 		
362
 		
366
 		
363
 		getter(builtin, BuiltinID.ASSOC_SIZE, "size", USIZE);
367
 		getter(builtin, BuiltinID.ASSOC_SIZE, "size", USIZE);
364
 		getter(builtin, BuiltinID.ASSOC_ISEMPTY, "isEmpty", BOOL);
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
 		getter(builtin, BuiltinID.ASSOC_HASHCODE, "objectHashCode", BasicTypeID.INT);
371
 		getter(builtin, BuiltinID.ASSOC_HASHCODE, "objectHashCode", BasicTypeID.INT);
368
 		
372
 		
369
 		iterator(builtin, ITERATOR_ASSOC_KEYS, keyType);
373
 		iterator(builtin, ITERATOR_ASSOC_KEYS, keyType);
381
 	@Override
385
 	@Override
382
 	public Void visitGenericMap(GenericMapTypeID map) {
386
 	public Void visitGenericMap(GenericMapTypeID map) {
383
 		TypeParameter functionParameter = new TypeParameter(BUILTIN, "T");
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
 		ITypeID valueType = map.value.instance(new GenericMapper(registry, parameterFilled));
389
 		ITypeID valueType = map.value.instance(new GenericMapper(registry, parameterFilled));
386
 		
390
 		
387
 		FunctionHeader getOptionalHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, registry.getOptional(valueType), null, new FunctionParameter[0]);
391
 		FunctionHeader getOptionalHeader = new FunctionHeader(new TypeParameter[] { functionParameter }, registry.getOptional(valueType), null, new FunctionParameter[0]);
496
 			for (int i = 0; i < constValues.length; i++)
500
 			for (int i = 0; i < constValues.length; i++)
497
 				constValues[i] = new EnumConstantExpression(BUILTIN, type, enumConstants.get(i));
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
 			compare(definition, ENUM_COMPARE, type);
504
 			compare(definition, ENUM_COMPARE, type);
501
 			
505
 			
502
 			if (!members.canCast(StringTypeID.STATIC)) {
506
 			if (!members.canCast(StringTypeID.STATIC)) {

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

21
 import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
21
 import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
22
 import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
22
 import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
23
 import org.openzen.zenscript.codemodel.expression.NullExpression;
23
 import org.openzen.zenscript.codemodel.expression.NullExpression;
24
+import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
24
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
25
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
25
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
26
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
26
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
27
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
47
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
48
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
48
 import org.openzen.zenscript.codemodel.type.ITypeID;
49
 import org.openzen.zenscript.codemodel.type.ITypeID;
49
 import org.openzen.zenscript.codemodel.scope.TypeScope;
50
 import org.openzen.zenscript.codemodel.scope.TypeScope;
51
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
50
 
52
 
51
 /**
53
 /**
52
  *
54
  *
81
 	}
83
 	}
82
 	
84
 	
83
 	public boolean extendsOrImplements(ITypeID other) {
85
 	public boolean extendsOrImplements(ITypeID other) {
84
-		other = other.getNormalized();
86
+		other = other.getNormalized().withoutStorage();
85
 		ITypeID superType = type.getSuperType(cache.getRegistry());
87
 		ITypeID superType = type.getSuperType(cache.getRegistry());
86
 		if (superType != null) {
88
 		if (superType != null) {
87
 			if (superType == other)
89
 			if (superType == other)
397
 	
399
 	
398
 	public boolean canCastImplicit(ITypeID toType) {
400
 	public boolean canCastImplicit(ITypeID toType) {
399
 		toType = toType.getNormalized();
401
 		toType = toType.getNormalized();
400
-		if (toType == type)
402
+		if (areEquivalent(type, toType))
401
 			return true;
403
 			return true;
402
-		if (toType == null)
403
-			throw new NullPointerException();
404
 		if (toType == BasicTypeID.UNDETERMINED)
404
 		if (toType == BasicTypeID.UNDETERMINED)
405
 			throw new IllegalArgumentException("Cannot cast to undetermined type!");
405
 			throw new IllegalArgumentException("Cannot cast to undetermined type!");
406
-		
407
 		if (type == BasicTypeID.NULL && toType.isOptional())
406
 		if (type == BasicTypeID.NULL && toType.isOptional())
408
 			return true;
407
 			return true;
408
+		
409
+		if (!type.getStorage().canCastTo(toType.getStorage()) && !toType.getStorage().canCastFrom(type.getStorage()))
410
+			return false;
411
+		
409
 		if (toType.isOptional() && canCastImplicit(toType.withoutOptional()))
412
 		if (toType.isOptional() && canCastImplicit(toType.withoutOptional()))
410
 			return true;
413
 			return true;
411
 		if (toType.isConst() && canCastImplicit(toType.withoutConst()))
414
 		if (toType.isConst() && canCastImplicit(toType.withoutConst()))
412
 			return true;
415
 			return true;
413
-		if (type.isOptional() && type.withoutOptional() == toType)
416
+		if (type.isOptional() && areEquivalent(type.withoutOptional(), toType))
414
 			return true;
417
 			return true;
415
 		
418
 		
416
 		return getImplicitCaster(toType) != null || extendsOrImplements(toType);
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
 	public CasterMemberRef getImplicitCaster(ITypeID toType) {
433
 	public CasterMemberRef getImplicitCaster(ITypeID toType) {
420
 		toType = toType.getNormalized();
434
 		toType = toType.getNormalized();
421
 		for (TypeMember<CasterMemberRef> caster : casters) {
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
 				return caster.member;
437
 				return caster.member;
424
 		}
438
 		}
425
 		
439
 		
429
 	public CasterMemberRef getCaster(ITypeID toType) {
443
 	public CasterMemberRef getCaster(ITypeID toType) {
430
 		toType = toType.getNormalized();
444
 		toType = toType.getNormalized();
431
 		for (TypeMember<CasterMemberRef> caster : casters) {
445
 		for (TypeMember<CasterMemberRef> caster : casters) {
432
-			if (toType == caster.member.toType)
446
+			if (areEquivalent(caster.member.toType, toType))
433
 				return caster.member;
447
 				return caster.member;
434
 		}
448
 		}
435
 		
449
 		
442
 			return true;
456
 			return true;
443
 		
457
 		
444
 		for (TypeMember<CasterMemberRef> caster : casters) {
458
 		for (TypeMember<CasterMemberRef> caster : casters) {
445
-			if (toType == caster.member.toType)
459
+			if (areEquivalent(caster.member.toType, toType))
446
 				return true;
460
 				return true;
447
 		}
461
 		}
448
 		
462
 		
449
 		return false;
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
 	public Expression castImplicit(CodePosition position, Expression value, ITypeID toType, boolean implicit) {
473
 	public Expression castImplicit(CodePosition position, Expression value, ITypeID toType, boolean implicit) {
453
 		toType = toType.getNormalized();
474
 		toType = toType.getNormalized();
454
 		if (toType == type || toType == BasicTypeID.UNDETERMINED)
475
 		if (toType == type || toType == BasicTypeID.UNDETERMINED)
455
 			return value;
476
 			return value;
477
+		if (toType.withoutStorage() == type.withoutStorage())
478
+			return new StorageCastExpression(position, value, toType);
456
 		if (toType == null)
479
 		if (toType == null)
457
 			throw new NullPointerException();
480
 			throw new NullPointerException();
458
 		
481
 		
459
 		if (type == BasicTypeID.NULL && toType.isOptional())
482
 		if (type == BasicTypeID.NULL && toType.isOptional())
460
 			return new NullExpression(position, toType);
483
 			return new NullExpression(position, toType);
461
 		if (toType.isOptional() && canCastImplicit(toType.withoutOptional()))
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
 		if (toType.isConst() && canCastImplicit(toType.withoutConst()))
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
 		for (TypeMember<CasterMemberRef> caster : casters) {
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
 		for (TypeMember<ImplementationMemberRef> implementation : implementations) {
495
 		for (TypeMember<ImplementationMemberRef> implementation : implementations) {
473
 			if (implementation.member.implementsType.equals(toType))
496
 			if (implementation.member.implementsType.equals(toType))
512
 		if (members.containsKey(name.name))
535
 		if (members.containsKey(name.name))
513
 			return new PartialStaticMemberGroupExpression(position, scope, type, members.get(name.name), name.arguments);
536
 			return new PartialStaticMemberGroupExpression(position, scope, type, members.get(name.name), name.arguments);
514
 		if (innerTypes.containsKey(name.name))
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
 		if (variantOptions.containsKey(name.name))
539
 		if (variantOptions.containsKey(name.name))
517
 			return new PartialVariantOptionExpression(position, scope, variantOptions.get(name.name));
540
 			return new PartialVariantOptionExpression(position, scope, variantOptions.get(name.name));
518
 		
541
 		
523
 		return innerTypes.containsKey(name);
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
 		if (!innerTypes.containsKey(name.name))
550
 		if (!innerTypes.containsKey(name.name))
528
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_INNER_TYPE, "No such inner type in " + type + ": " + name.name);
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
 	@Override
556
 	@Override

+ 15
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/AnyStorageTag.java View File

18
 	public StorageType getType() {
18
 	public StorageType getType() {
19
 		return AnyStorageType.INSTANCE;
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 View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.type.storage;
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
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
13
 	public static final AnyStorageType INSTANCE = new AnyStorageType();
17
 	public static final AnyStorageType INSTANCE = new AnyStorageType();
14
 	
18
 	
15
 	private AnyStorageType() {}
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 View File

11
  */
11
  */
12
 public class BorrowStorageTag implements StorageTag {
12
 public class BorrowStorageTag implements StorageTag {
13
 	public static final BorrowStorageTag INVOCATION = new BorrowStorageTag();
13
 	public static final BorrowStorageTag INVOCATION = new BorrowStorageTag();
14
+	public static final BorrowStorageTag THIS = new BorrowStorageTag();
14
 	
15
 	
15
 	private BorrowStorageTag() {} // TODO: scoped borrow
16
 	private BorrowStorageTag() {} // TODO: scoped borrow
16
 
17
 
18
 	public StorageType getType() {
19
 	public StorageType getType() {
19
 		return BorrowStorageType.INSTANCE;
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 View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.type.storage;
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
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
13
 	public static final BorrowStorageType INSTANCE = new BorrowStorageType();
17
 	public static final BorrowStorageType INSTANCE = new BorrowStorageType();
14
 
18
 
15
 	private BorrowStorageType() {}
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 View File

18
 	public StorageType getType() {
18
 	public StorageType getType() {
19
 		return SharedStorageType.INSTANCE;
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 View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.type.storage;
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
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
13
 	public static final SharedStorageType INSTANCE = new SharedStorageType();
17
 	public static final SharedStorageType INSTANCE = new SharedStorageType();
14
 	
18
 	
15
 	private SharedStorageType() {}
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 View File

18
 	public StorageType getType() {
18
 	public StorageType getType() {
19
 		return StaticStorageType.INSTANCE;
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 View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.type.storage;
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
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
13
 	public static final StaticStorageType INSTANCE = new StaticStorageType();
17
 	public static final StaticStorageType INSTANCE = new StaticStorageType();
14
 	
18
 	
15
 	private StaticStorageType() {}
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 View File

11
  */
11
  */
12
 public interface StorageTag {
12
 public interface StorageTag {
13
 	StorageType getType();
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 View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.type.storage;
6
 package org.openzen.zenscript.codemodel.type.storage;
7
 
7
 
8
+import org.openzen.zencode.shared.CodePosition;
9
+
8
 /**
10
 /**
9
  *
11
  *
10
  * @author Hoofdgebruiker
12
  * @author Hoofdgebruiker
11
  */
13
  */
12
 public interface StorageType {
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 View File

18
 	public StorageType getType() {
18
 	public StorageType getType() {
19
 		return UniqueStorageType.INSTANCE;
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 View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.type.storage;
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
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
13
 	public static final UniqueStorageType INSTANCE = new UniqueStorageType();
17
 	public static final UniqueStorageType INSTANCE = new UniqueStorageType();
14
 	
18
 	
15
 	private UniqueStorageType() {}
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 View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.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 View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.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 View File

9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.Map;
10
 import java.util.Map;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13
+import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
16
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
21
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
22
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
21
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
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
 	private final List<ExpansionDefinition> expansions;
33
 	private final List<ExpansionDefinition> expansions;
30
 	private final LocalMemberCache cache;
34
 	private final LocalMemberCache cache;
31
 	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
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
 		this.globalRegistry = globalRegistry;
39
 		this.globalRegistry = globalRegistry;
35
 		this.expansions = expansions;
40
 		this.expansions = expansions;
36
 		this.cache = new LocalMemberCache(globalRegistry, expansions);
41
 		this.cache = new LocalMemberCache(globalRegistry, expansions);
37
 		
42
 		
38
-		for (AnnotationDefinition annotation : annotations) {
43
+		for (AnnotationDefinition annotation : annotations)
39
 			this.annotations.put(annotation.getAnnotationName(), annotation);
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
 	@Override
49
 	@Override
61
 	}
67
 	}
62
 
68
 
63
 	@Override
69
 	@Override
64
-	public ITypeID getType(CodePosition position, List<GenericName> name) {
70
+	public ITypeID getType(CodePosition position, List<GenericName> name, StorageTag storage) {
65
 		throw new UnsupportedOperationException("Not supported yet.");
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
 	@Override
82
 	@Override
69
 	public ITypeID getThisType() {
83
 	public ITypeID getThisType() {
70
 		return null;
84
 		return null;

+ 8
- 1
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java View File

18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
20
 import org.openzen.zenscript.codemodel.type.ISymbol;
20
 import org.openzen.zenscript.codemodel.type.ISymbol;
21
+import org.openzen.zenscript.codemodel.type.storage.StorageType;
21
 
22
 
22
 /**
23
 /**
23
  *
24
  *
30
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
31
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
31
 	private final Map<String, ISymbol> globals = new HashMap<>();
32
 	private final Map<String, ISymbol> globals = new HashMap<>();
32
 	private final AnnotationDefinition[] annotations;
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
 		this.compilationUnit = compilationUnit;
37
 		this.compilationUnit = compilationUnit;
36
 		
38
 		
37
 		annotations.add(NativeAnnotationDefinition.INSTANCE);
39
 		annotations.add(NativeAnnotationDefinition.INSTANCE);
38
 		annotations.add(PreconditionAnnotationDefinition.INSTANCE);
40
 		annotations.add(PreconditionAnnotationDefinition.INSTANCE);
39
 		this.annotations = annotations.toArray(new AnnotationDefinition[annotations.size()]);
41
 		this.annotations = annotations.toArray(new AnnotationDefinition[annotations.size()]);
42
+		this.storageTypes = storageTypes;
40
 	}
43
 	}
41
 	
44
 	
42
 	public void addModule(String name, SemanticModule dependency) {
45
 	public void addModule(String name, SemanticModule dependency) {
70
 	public AnnotationDefinition[] getAnnotations() {
73
 	public AnnotationDefinition[] getAnnotations() {
71
 		return annotations;
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 View File

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

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

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

+ 0
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java View File

7
 
7
 
8
 import org.openzen.drawablegui.DEmptyView;
8
 import org.openzen.drawablegui.DEmptyView;
9
 import org.openzen.drawablegui.DScalableSize;
9
 import org.openzen.drawablegui.DScalableSize;
10
-import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.border.DLineBorder;
10
 import org.openzen.drawablegui.border.DLineBorder;
12
 import org.openzen.drawablegui.scroll.DScrollPane;
11
 import org.openzen.drawablegui.scroll.DScrollPane;
13
 import org.openzen.drawablegui.layout.DSideLayout;
12
 import org.openzen.drawablegui.layout.DSideLayout;

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

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

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

23
 
23
 
24
 import java.io.FileOutputStream;
24
 import java.io.FileOutputStream;
25
 import java.io.IOException;
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
 import org.openzen.zenscript.javashared.JavaClass;
31
 import org.openzen.zenscript.javashared.JavaClass;
27
 import org.openzen.zenscript.javashared.JavaField;
32
 import org.openzen.zenscript.javashared.JavaField;
28
 import org.openzen.zenscript.javashared.JavaMethod;
33
 import org.openzen.zenscript.javashared.JavaMethod;
144
 	public static final JavaMethod OBJECT_HASHCODE = JavaMethod.getNativeVirtual(JavaClass.OBJECT, "hashCode", "()I");
149
 	public static final JavaMethod OBJECT_HASHCODE = JavaMethod.getNativeVirtual(JavaClass.OBJECT, "hashCode", "()I");
145
 	private static final JavaMethod COLLECTION_SIZE = JavaMethod.getNativeVirtual(JavaClass.COLLECTION, "size", "()I");
150
 	private static final JavaMethod COLLECTION_SIZE = JavaMethod.getNativeVirtual(JavaClass.COLLECTION, "size", "()I");
146
 	private static final JavaMethod COLLECTION_TOARRAY = JavaMethod.getNativeVirtual(JavaClass.COLLECTION, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
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
 	protected final JavaWriter javaWriter;
158
 	protected final JavaWriter javaWriter;
149
 	private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
159
 	private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
150
 	private final JavaBytecodeContext context;
160
 	private final JavaBytecodeContext context;
826
 						case CHAR:
836
 						case CHAR:
827
 							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_CHARS);
837
 							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_CHARS);
828
 							break;
838
 							break;
829
-						case STRING:
830
-							javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
831
-							javaWriter.checkCast("[Ljava/lang/String;");
832
-							break;
833
 						default:
839
 						default:
834
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
840
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
835
 					}
841
 					}
874
 						case CHAR:
880
 						case CHAR:
875
 							javaWriter.invokeStatic(ARRAYS_EQUALS_CHARS);
881
 							javaWriter.invokeStatic(ARRAYS_EQUALS_CHARS);
876
 							break;
882
 							break;
877
-						case STRING:
878
-							javaWriter.invokeStatic(ARRAYS_EQUALS_OBJECTS);
879
-							break;
880
 						default:
883
 						default:
881
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
884
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
882
 					}
885
 					}
1651
 
1654
 
1652
 		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", signature);
1655
 		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", signature);
1653
 		final ClassWriter lambdaCW = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
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
 		final JavaWriter functionWriter = new JavaWriter(lambdaCW, methodInfo, null, signature, null, "java/lang/Override");
1658
 		final JavaWriter functionWriter = new JavaWriter(lambdaCW, methodInfo, null, signature, null, "java/lang/Override");
1656
 
1659
 
1657
 		javaWriter.newObject(name);
1660
 		javaWriter.newObject(name);
1888
 				break;
1891
 				break;
1889
 			case ASSOC_KEYS: {
1892
 			case ASSOC_KEYS: {
1890
 				AssocTypeID type = (AssocTypeID) expression.target.type;
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
 				Type resultType = context.getType(result);
1895
 				Type resultType = context.getType(result);
1893
 
1896
 
1894
 				javaWriter.invokeVirtual(MAP_KEYS);
1897
 				javaWriter.invokeVirtual(MAP_KEYS);
1901
 			}
1904
 			}
1902
 			case ASSOC_VALUES: {
1905
 			case ASSOC_VALUES: {
1903
 				AssocTypeID type = (AssocTypeID) expression.target.type;
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
 				Type resultType = context.getType(result);
1908
 				Type resultType = context.getType(result);
1906
 
1909
 
1907
 				javaWriter.invokeVirtual(MAP_VALUES);
1910
 				javaWriter.invokeVirtual(MAP_VALUES);
1955
 						case CHAR:
1958
 						case CHAR:
1956
 							javaWriter.invokeStatic(ARRAYS_HASHCODE_CHARS);
1959
 							javaWriter.invokeStatic(ARRAYS_HASHCODE_CHARS);
1957
 							break;
1960
 							break;
1958
-						case STRING:
1959
-							javaWriter.invokeStatic(ARRAYS_DEEPHASHCODE);
1960
-							break;
1961
 						default:
1961
 						default:
1962
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
1962
 							throw new IllegalArgumentException("Unknown basic type: " + type.elementType);
1963
 					}
1963
 					}
2056
 		expression.value.accept(this);
2056
 		expression.value.accept(this);
2057
 
2057
 
2058
 		//TODO replace beforeSwitch visitor or similar
2058
 		//TODO replace beforeSwitch visitor or similar
2059
-		if (expression.value.type == BasicTypeID.STRING)
2059
+		if (expression.value.type instanceof StringTypeID)
2060
 			javaWriter.invokeVirtual(OBJECT_HASHCODE);
2060
 			javaWriter.invokeVirtual(OBJECT_HASHCODE);
2061
 
2061
 
2062
 		//TODO replace with beforeSwitch visitor or similar
2062
 		//TODO replace with beforeSwitch visitor or similar
2366
 
2366
 
2367
 	@Override
2367
 	@Override
2368
 	public Void visitStaticSetter(StaticSetterExpression expression) {
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
 		return null;
2390
 		return null;
2370
 	}
2391
 	}
2371
 
2392
 

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

354
 		throw new UnsupportedOperationException("Invalid increment target");
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
 	@Override
362
 	@Override
358
 	public Void visitSupertypeCast(SupertypeCastExpression expression) {
363
 	public Void visitSupertypeCast(SupertypeCastExpression expression) {
359
 		throw new UnsupportedOperationException("Invalid increment target");
364
 		throw new UnsupportedOperationException("Invalid increment target");

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

360
 		throw new UnsupportedOperationException("Invalid increment target");
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
 	@Override
368
 	@Override
364
 	public Void visitSupertypeCast(SupertypeCastExpression expression) {
369
 	public Void visitSupertypeCast(SupertypeCastExpression expression) {
365
 		throw new UnsupportedOperationException("Invalid increment target");
370
 		throw new UnsupportedOperationException("Invalid increment target");

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

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

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

33
 	public static final JavaClass CHARACTER = new JavaClass("java.lang", "Character", Kind.CLASS);
33
 	public static final JavaClass CHARACTER = new JavaClass("java.lang", "Character", Kind.CLASS);
34
 	public static final JavaClass COLLECTION = new JavaClass("java.util", "Collection", Kind.INTERFACE);
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
 	public static JavaClass fromInternalName(String internalName, Kind kind) {
38
 	public static JavaClass fromInternalName(String internalName, Kind kind) {
37
 		if (kind == Kind.ARRAY)
39
 		if (kind == Kind.ARRAY)
38
 			return new JavaClass("", internalName, kind, new String[0]);
40
 			return new JavaClass("", internalName, kind, new String[0]);

+ 8
- 8
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java View File

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

+ 11
- 6
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java View File

22
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
22
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
23
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
23
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
24
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
24
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
25
+import org.openzen.zenscript.codemodel.type.StringTypeID;
25
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
26
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
26
 
27
 
27
 /**
28
 /**
29
  * @author Hoofdgebruiker
30
  * @author Hoofdgebruiker
30
  */
31
  */
31
 public class JavaSyntheticTypeSignatureConverter implements TypeVisitor<String> {
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
 	private final Map<TypeParameter, String> typeParameters = new HashMap<>();
34
 	private final Map<TypeParameter, String> typeParameters = new HashMap<>();
34
 	public final List<TypeParameter> typeParameterList = new ArrayList<>();
35
 	public final List<TypeParameter> typeParameterList = new ArrayList<>();
35
 	
36
 	
50
 			case FLOAT: return "Float";
51
 			case FLOAT: return "Float";
51
 			case DOUBLE: return "Double";
52
 			case DOUBLE: return "Double";
52
 			case CHAR: return "Char";
53
 			case CHAR: return "Char";
53
-			case STRING: return "String";
54
 			default:
54
 			default:
55
 				throw new IllegalArgumentException("Invalid type: " + basic);
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
 	@Override
64
 	@Override
60
 	public String visitArray(ArrayTypeID array) {
65
 	public String visitArray(ArrayTypeID array) {
107
 	public String visitDefinition(DefinitionTypeID definition) {
112
 	public String visitDefinition(DefinitionTypeID definition) {
108
 		StringBuilder result = new StringBuilder();
113
 		StringBuilder result = new StringBuilder();
109
 		result.append(definition.definition.name);
114
 		result.append(definition.definition.name);
110
-		if (definition.typeParameters.length > 0) {
115
+		if (definition.typeArguments.length > 0) {
111
 			result.append("With");
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
 		return result.toString();
121
 		return result.toString();
121
 		if (typeParameters.containsKey(generic.parameter))
126
 		if (typeParameters.containsKey(generic.parameter))
122
 			return typeParameters.get(generic.parameter);
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
 		typeParameters.put(generic.parameter, name);
130
 		typeParameters.put(generic.parameter, name);
126
 		typeParameterList.add(generic.parameter);
131
 		typeParameterList.add(generic.parameter);
127
 		return name;
132
 		return name;

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

36
 				case USIZE: return "I"; // special case: optional usize fits in an int where null = -1
36
 				case USIZE: return "I"; // special case: optional usize fits in an int where null = -1
37
 				case FLOAT: return "Ljava/lang/Float;";
37
 				case FLOAT: return "Ljava/lang/Float;";
38
 				case DOUBLE: return "Ljava/lang/Double;";
38
 				case DOUBLE: return "Ljava/lang/Double;";
39
-				case STRING: return "Ljava/lang/String;";
40
 				default:
39
 				default:
41
 					throw new IllegalArgumentException("Not a valid type: " + basic);
40
 					throw new IllegalArgumentException("Not a valid type: " + basic);
42
 			}
41
 			}
56
 				case USIZE: return "I";
55
 				case USIZE: return "I";
57
 				case FLOAT: return "F";
56
 				case FLOAT: return "F";
58
 				case DOUBLE: return "D";
57
 				case DOUBLE: return "D";
59
-				case STRING: return "Ljava/lang/String;";
60
 				default:
58
 				default:
61
 					throw new IllegalArgumentException("Not a valid type: " + basic);
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
     @Override
69
     @Override
67
     public String visitArray(ArrayTypeID array) {
70
     public String visitArray(ArrayTypeID array) {

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

89
 	public String visitBasic(BasicTypeID basic) {
89
 	public String visitBasic(BasicTypeID basic) {
90
 		return context.getDescriptor(basic);
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
 	@Override
98
 	@Override
94
 	public String visitArray(ArrayTypeID array) {
99
 	public String visitArray(ArrayTypeID array) {
119
 	public String visitDefinition(DefinitionTypeID definition) {
124
 	public String visitDefinition(DefinitionTypeID definition) {
120
 		StringBuilder builder = new StringBuilder("L").append(definition.definition.name);
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
 			builder.append("<");
128
 			builder.append("<");
124
-			for (ITypeID typeParameter : definition.typeParameters) {
129
+			for (ITypeID typeParameter : definition.typeArguments) {
125
 				builder.append(typeParameter.accept(this));
130
 				builder.append(typeParameter.accept(this));
126
 			}
131
 			}
127
 			builder.append(">");
132
 			builder.append(">");

+ 7
- 7
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInfo.java View File

16
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
16
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
17
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
17
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
18
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
18
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
19
+import org.openzen.zenscript.codemodel.type.StringTypeID;
19
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
20
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
20
 
21
 
21
 /**
22
 /**
45
 
46
 
46
 		@Override
47
 		@Override
47
 		public JavaTypeInfo visitBasic(BasicTypeID basic) {
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
 		@Override
57
 		@Override

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

36
 				case USIZE: return "java/lang/Integer";
36
 				case USIZE: return "java/lang/Integer";
37
 				case FLOAT: return "java/lang/Float";
37
 				case FLOAT: return "java/lang/Float";
38
 				case DOUBLE: return "java/lang/Double";
38
 				case DOUBLE: return "java/lang/Double";
39
-				case STRING: return "java/lang/String";
40
 				default:
39
 				default:
41
 					throw new IllegalArgumentException("Not a valid type: " + basic);
40
 					throw new IllegalArgumentException("Not a valid type: " + basic);
42
 			}
41
 			}
56
 				case USIZE: return "I";
55
 				case USIZE: return "I";
57
 				case FLOAT: return "F";
56
 				case FLOAT: return "F";
58
 				case DOUBLE: return "D";
57
 				case DOUBLE: return "D";
59
-				case STRING: return "java/lang/String";
60
 				default:
58
 				default:
61
 					throw new IllegalArgumentException("Not a valid type: " + basic);
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
     @Override
69
     @Override
67
     public String visitArray(ArrayTypeID array) {
70
     public String visitArray(ArrayTypeID array) {

+ 6
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeNameVisitor.java View File

16
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
16
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
17
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
17
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
18
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
18
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
19
+import org.openzen.zenscript.codemodel.type.StringTypeID;
19
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
20
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
20
 
21
 
21
 /**
22
 /**
40
 			case ULONG: return "ULong";
41
 			case ULONG: return "ULong";
41
 			case FLOAT: return "Float";
42
 			case FLOAT: return "Float";
42
 			case DOUBLE: return "Double";
43
 			case DOUBLE: return "Double";
43
-			case STRING: return "String";
44
 			case CHAR: return "Char";
44
 			case CHAR: return "Char";
45
 			default: throw new IllegalArgumentException("Invalid type: " + basic);
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
 	@Override
54
 	@Override
50
 	public String visitArray(ArrayTypeID array) {
55
 	public String visitArray(ArrayTypeID array) {

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java View File

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

+ 3
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java View File

75
 		GlobalTypeRegistry typeRegistry = module.compilationUnit.globalTypeRegistry;
75
 		GlobalTypeRegistry typeRegistry = module.compilationUnit.globalTypeRegistry;
76
 		DefinitionTypeID thisType = typeRegistry.getForMyDefinition(definition);
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
 		return new JavaSourceFileScope(file.importer, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition, thisType, compiler.context);
79
 		return new JavaSourceFileScope(file.importer, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition, thisType, compiler.context);
80
 	}
80
 	}
81
 
81
 
371
 		if (definition.hasTag(JavaNativeClass.class)) {
371
 		if (definition.hasTag(JavaNativeClass.class)) {
372
 			ITypeID[] typeParameters = new ITypeID[definition.getNumberOfGenericParameters()];
372
 			ITypeID[] typeParameters = new ITypeID[definition.getNumberOfGenericParameters()];
373
 			for (int i = 0; i < typeParameters.length; i++)
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
 			JavaExpansionMemberCompiler memberCompiler = new JavaExpansionMemberCompiler(settings, targetType, definition.typeParameters, indent + settings.indent, output, scope, definition);
377
 			JavaExpansionMemberCompiler memberCompiler = new JavaExpansionMemberCompiler(settings, targetType, definition.typeParameters, indent + settings.indent, output, scope, definition);
378
 			for (IDefinitionMember member : definition.members)
378
 			for (IDefinitionMember member : definition.members)

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

30
 import org.openzen.zenscript.codemodel.statement.Statement;
30
 import org.openzen.zenscript.codemodel.statement.Statement;
31
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
31
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
32
 import org.openzen.zenscript.codemodel.type.ITypeID;
32
 import org.openzen.zenscript.codemodel.type.ITypeID;
33
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
33
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
34
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
34
 import org.openzen.zenscript.javashared.JavaMethod;
35
 import org.openzen.zenscript.javashared.JavaMethod;
35
 
36
 
164
 
165
 
165
 	@Override
166
 	@Override
166
 	public Void visitCustomIterator(IteratorMember member) {
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
 		return null;
169
 		return null;
169
 	}
170
 	}
170
 
171
 

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

35
 import org.openzen.zenscript.codemodel.statement.EmptyStatement;
35
 import org.openzen.zenscript.codemodel.statement.EmptyStatement;
36
 import org.openzen.zenscript.codemodel.statement.Statement;
36
 import org.openzen.zenscript.codemodel.statement.Statement;
37
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
37
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
38
+import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
38
 import org.openzen.zenscript.compiler.SemanticModule;
39
 import org.openzen.zenscript.compiler.SemanticModule;
39
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
40
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
40
 import org.openzen.zenscript.javashared.JavaClass;
41
 import org.openzen.zenscript.javashared.JavaClass;
210
 
211
 
211
 	@Override
212
 	@Override
212
 	public Void visitCustomIterator(IteratorMember member) {
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
 		return null;
215
 		return null;
215
 	}
216
 	}
216
 
217
 

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

74
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
74
 import org.openzen.zenscript.codemodel.expression.SetterExpression;
75
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
75
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
76
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
76
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
77
+import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
77
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
78
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
78
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
79
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
79
 import org.openzen.zenscript.codemodel.expression.ThrowExpression;
80
 import org.openzen.zenscript.codemodel.expression.ThrowExpression;
92
 import org.openzen.zenscript.codemodel.type.ITypeID;
93
 import org.openzen.zenscript.codemodel.type.ITypeID;
93
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
94
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
94
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
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
 import org.openzen.zenscript.formattershared.ExpressionString;
100
 import org.openzen.zenscript.formattershared.ExpressionString;
96
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
101
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
97
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
102
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
650
 				JavaOperator.ASSIGN);
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
 	@Override
675
 	@Override
654
 	public ExpressionString visitSupertypeCast(SupertypeCastExpression expression) {
676
 	public ExpressionString visitSupertypeCast(SupertypeCastExpression expression) {
655
 		return expression.value.accept(this);
677
 		return expression.value.accept(this);
690
 		
712
 		
691
 		ExpressionString value = hoist(expression.value).accept(this);
713
 		ExpressionString value = hoist(expression.value).accept(this);
692
 		target.writeLine("if (" + value.value + " instanceof " + errorType + ")");
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
 		return value
717
 		return value
696
-				.unaryPrefix(JavaOperator.CAST, "(" + okType + formatTypeArguments(type.typeParameters) + ")")
718
+				.unaryPrefix(JavaOperator.CAST, "(" + okType + formatTypeArguments(type.typeArguments) + ")")
697
 				.unaryPostfix(JavaOperator.MEMBER, ".value");
719
 				.unaryPostfix(JavaOperator.MEMBER, ".value");
698
 	}
720
 	}
699
 
721
 
706
 		
728
 		
707
 		ExpressionString value = hoist(expression.value).accept(this);
729
 		ExpressionString value = hoist(expression.value).accept(this);
708
 		target.writeLine("if (" + value.value + " instanceof " + errorType + ")");
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
 		return value
733
 		return value
712
-				.unaryPrefix(JavaOperator.CAST, "(" + okType + formatTypeArguments(type.typeParameters) + ")")
734
+				.unaryPrefix(JavaOperator.CAST, "(" + okType + formatTypeArguments(type.typeArguments) + ")")
713
 				.unaryPostfix(JavaOperator.MEMBER, ".value");
735
 				.unaryPostfix(JavaOperator.MEMBER, ".value");
714
 	}
736
 	}
715
 	
737
 	

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java View File

32
 			case FLOAT: return "Float";
32
 			case FLOAT: return "Float";
33
 			case DOUBLE: return "Double";
33
 			case DOUBLE: return "Double";
34
 			case CHAR: return "Character";
34
 			case CHAR: return "Character";
35
-			case STRING: return "String";
36
 			default:
35
 			default:
37
 				throw new IllegalArgumentException("Unknown basic type: " + basic);
36
 				throw new IllegalArgumentException("Unknown basic type: " + basic);
38
 		}
37
 		}

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

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

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticHelperGenerator.java View File

26
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
26
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
27
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
27
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
28
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
28
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
29
+import org.openzen.zenscript.codemodel.type.StringTypeID;
29
 import org.openzen.zenscript.javashared.JavaClass;
30
 import org.openzen.zenscript.javashared.JavaClass;
30
 import org.openzen.zenscript.javashared.JavaContext;
31
 import org.openzen.zenscript.javashared.JavaContext;
31
 import org.openzen.zenscript.javashared.JavaMethod;
32
 import org.openzen.zenscript.javashared.JavaMethod;
156
 					throw new UnsupportedOperationException("Invalid array base type: " + basic);
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
 		@Override
166
 		@Override
161
 		public ArrayKind visitArray(ArrayTypeID array) {
167
 		public ArrayKind visitArray(ArrayTypeID array) {

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

19
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
19
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
20
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
20
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
21
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
21
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
22
+import org.openzen.zenscript.codemodel.type.StringTypeID;
22
 import org.openzen.zenscript.javashared.JavaClass;
23
 import org.openzen.zenscript.javashared.JavaClass;
23
 import org.openzen.zenscript.javashared.JavaSynthesizedFunctionInstance;
24
 import org.openzen.zenscript.javashared.JavaSynthesizedFunctionInstance;
24
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
25
 import org.openzen.zenscript.codemodel.type.TypeVisitor;
66
 			case FLOAT: return "float";
67
 			case FLOAT: return "float";
67
 			case DOUBLE: return "double";
68
 			case DOUBLE: return "double";
68
 			case CHAR: return "char";
69
 			case CHAR: return "char";
69
-			case STRING: return "String";
70
 			default:
70
 			default:
71
 				throw new IllegalArgumentException("Unknown basic type: " + basic);
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
 	@Override
80
 	@Override
76
 	public String visitArray(ArrayTypeID array) {
81
 	public String visitArray(ArrayTypeID array) {
144
 			output.append(cls == null ? importer.importType(type.definition) : importer.importType(cls));
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
 			output.append("<");
153
 			output.append("<");
149
-			for (int i = 0; i < type.typeParameters.length; i++) {
154
+			for (int i = 0; i < type.typeArguments.length; i++) {
150
 				if (i > 0)
155
 				if (i > 0)
151
 					output.append(", ");
156
 					output.append(", ");
152
-				output.append(type.typeParameters[i].accept(objectTypeVisitor));
157
+				output.append(type.typeArguments[i].accept(objectTypeVisitor));
153
 			}
158
 			}
154
 			output.append(">");
159
 			output.append(">");
155
 		}
160
 		}

+ 2
- 1
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/CodeReader.java View File

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

+ 8
- 2
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/DeserializingModule.java View File

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

+ 0
- 0
ModuleDeserializer/src/main/java/org/openzen/zenscript/moduledeserializer/Main.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save