Browse Source

- Added usize as basic type

- Ranges now only have a single base type; from and to must be the same type
- Adjusted builtins and stdlib to use usize where applicable
- Moved building a SemanticModule from ParsedFile to the parser; reduces dependencies
Stan Hebben 6 years ago
parent
commit
0298420bb2
71 changed files with 663 additions and 424 deletions
  1. 9
    3
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  2. 3
    3
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java
  3. 1
    1
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java
  4. 12
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  5. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java
  6. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java
  7. 39
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUSizeExpression.java
  8. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  9. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PostCallExpression.java
  10. 9
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/RangeExpression.java
  11. 0
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java
  12. 1
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java
  13. 4
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java
  14. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  15. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java
  16. 13
    18
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java
  17. 2
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeParameterCollector.java
  18. 52
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinID.java
  19. 2
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  20. 123
    33
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  21. 5
    3
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java
  22. 0
    84
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  23. 2
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  24. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  25. 1
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java
  26. 9
    12
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java
  27. 1
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaBoxingTypeVisitor.java
  28. 55
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  29. 6
    68
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  30. 6
    68
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  31. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  32. 2
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java
  33. 3
    4
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java
  34. 8
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java
  35. 2
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java
  36. 2
    4
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeNameVisitor.java
  37. 4
    3
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java
  38. 1
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java
  39. 20
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java
  40. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java
  41. 6
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java
  42. 3
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java
  43. 1
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  44. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java
  45. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  46. 58
    6
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  47. 11
    11
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java
  48. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceImporter.java
  49. 5
    5
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java
  50. 13
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java
  51. 1
    0
      Parser/build.gradle
  52. 1
    0
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java
  53. 77
    0
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  54. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java
  55. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java
  56. 3
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java
  57. 7
    5
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionRange.java
  58. 8
    2
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedFunctionalMember.java
  59. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java
  60. 4
    5
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementReturn.java
  61. 6
    3
      Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java
  62. 1
    0
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeBasic.java
  63. 14
    7
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeRange.java
  64. 1
    2
      ScriptingExample/build.gradle
  65. 3
    3
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  66. 2
    3
      Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java
  67. 3
    1
      Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java
  68. 9
    4
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java
  69. 2
    2
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/StatementValidator.java
  70. 1
    2
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/TypeValidator.java
  71. 1
    1
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java

+ 9
- 3
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java View File

36
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
36
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
37
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
37
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
38
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
38
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
39
+import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
39
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
40
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
40
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
41
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
41
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
42
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
391
 	public ExpressionString visitConstantShort(ConstantShortExpression expression) {
392
 	public ExpressionString visitConstantShort(ConstantShortExpression expression) {
392
 		return new ExpressionString(Integer.toString(expression.value) + " as short", ZenScriptOperator.CAST);
393
 		return new ExpressionString(Integer.toString(expression.value) + " as short", ZenScriptOperator.CAST);
393
 	}
394
 	}
395
+	
396
+	@Override
397
+	public ExpressionString visitConstantUSize(ConstantUSizeExpression expression) {
398
+		return new ExpressionString(Long.toUnsignedString(expression.value) + " as usize", ZenScriptOperator.CAST);
399
+	}
394
 
400
 
395
 	@Override
401
 	@Override
396
 	public ExpressionString visitConstantString(ConstantStringExpression expression) {
402
 	public ExpressionString visitConstantString(ConstantStringExpression expression) {
402
 
408
 
403
 	@Override
409
 	@Override
404
 	public ExpressionString visitConstantUInt(ConstantUIntExpression expression) {
410
 	public ExpressionString visitConstantUInt(ConstantUIntExpression expression) {
405
-		return new ExpressionString(Integer.toString(expression.value) + " as uint", ZenScriptOperator.CAST);
411
+		return new ExpressionString(Integer.toUnsignedString(expression.value) + " as uint", ZenScriptOperator.CAST);
406
 	}
412
 	}
407
 
413
 
408
 	@Override
414
 	@Override
409
 	public ExpressionString visitConstantULong(ConstantULongExpression expression) {
415
 	public ExpressionString visitConstantULong(ConstantULongExpression expression) {
410
-		return new ExpressionString(Long.toString(expression.value) + " as ulong", ZenScriptOperator.CAST);
416
+		return new ExpressionString(Long.toUnsignedString(expression.value) + " as ulong", ZenScriptOperator.CAST);
411
 	}
417
 	}
412
 
418
 
413
 	@Override
419
 	@Override
414
 	public ExpressionString visitConstantUShort(ConstantUShortExpression expression) {
420
 	public ExpressionString visitConstantUShort(ConstantUShortExpression expression) {
415
-		return new ExpressionString(Integer.toString(expression.value) + " as ushort", ZenScriptOperator.CAST);
421
+		return new ExpressionString(Integer.toUnsignedString(expression.value) + " as ushort", ZenScriptOperator.CAST);
416
 	}
422
 	}
417
 
423
 
418
 	@Override
424
 	@Override

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

80
 			
80
 			
81
 			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
81
 			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
82
 				result.append(" as ");
82
 				result.append(" as ");
83
-				result.append(header.returnType.accept(typeFormatter));
83
+				result.append(header.getReturnType().accept(typeFormatter));
84
 			}
84
 			}
85
 			
85
 			
86
 			parameterIndex++;
86
 			parameterIndex++;
87
 		}
87
 		}
88
 		result.append(")");
88
 		result.append(")");
89
-		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.UNDETERMINED) {
89
+		if (!settings.showAnyInFunctionHeaders || header.getReturnType() != BasicTypeID.UNDETERMINED) {
90
 			result.append(" as ");
90
 			result.append(" as ");
91
-			result.append(header.returnType.accept(typeFormatter));
91
+			result.append(header.getReturnType().accept(typeFormatter));
92
 		}
92
 		}
93
 	}
93
 	}
94
 	
94
 	

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

97
 
97
 
98
 	@Override
98
 	@Override
99
 	public String visitRange(RangeTypeID range) {
99
 	public String visitRange(RangeTypeID range) {
100
-		return range.from.accept(this) + " .. " + range.to.accept(this);
100
+		return range.baseType.accept(this) + " .. " + range.baseType.accept(this);
101
 	}
101
 	}
102
 
102
 
103
 	@Override
103
 	@Override

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

27
 	private static final FunctionParameter[] NO_PARAMETERS = new FunctionParameter[0];
27
 	private static final FunctionParameter[] NO_PARAMETERS = new FunctionParameter[0];
28
 	
28
 	
29
 	public final TypeParameter[] typeParameters;
29
 	public final TypeParameter[] typeParameters;
30
-	public ITypeID returnType;
30
+	private ITypeID returnType;
31
 	public final FunctionParameter[] parameters;
31
 	public final FunctionParameter[] parameters;
32
 	public final ITypeID thrownType;
32
 	public final ITypeID thrownType;
33
 	
33
 	
96
 		hasUnknowns = hasUnknowns(parameters, returnType);
96
 		hasUnknowns = hasUnknowns(parameters, returnType);
97
 	}
97
 	}
98
 	
98
 	
99
+	public ITypeID getReturnType() {
100
+		return returnType;
101
+	}
102
+	
103
+	public void setReturnType(ITypeID returnType) {
104
+		if (returnType == null)
105
+			throw new NullPointerException();
106
+		
107
+		this.returnType = returnType;
108
+	}
109
+	
99
 	public boolean isDenormalized() {
110
 	public boolean isDenormalized() {
100
 		if (returnType.getNormalized() != returnType)
111
 		if (returnType.getNormalized() != returnType)
101
 			return true;
112
 			return true;

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

21
 	public final FunctionHeader instancedHeader;
21
 	public final FunctionHeader instancedHeader;
22
 	
22
 	
23
 	public CallExpression(CodePosition position, Expression target, FunctionalMemberRef member, FunctionHeader instancedHeader, CallArguments arguments) {
23
 	public CallExpression(CodePosition position, Expression target, FunctionalMemberRef member, FunctionHeader instancedHeader, CallArguments arguments) {
24
-		super(position, instancedHeader.returnType, multiThrow(position, arguments.arguments));
24
+		super(position, instancedHeader.getReturnType(), multiThrow(position, arguments.arguments));
25
 		
25
 		
26
 		this.target = target;
26
 		this.target = target;
27
 		this.member = member;
27
 		this.member = member;

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

22
 	public final FunctionHeader instancedHeader;
22
 	public final FunctionHeader instancedHeader;
23
 	
23
 	
24
 	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMemberRef member, FunctionHeader instancedHeader, CallArguments arguments) {
24
 	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMemberRef member, FunctionHeader instancedHeader, CallArguments arguments) {
25
-		super(position, instancedHeader.returnType, multiThrow(position, arguments.arguments));
25
+		super(position, instancedHeader.getReturnType(), multiThrow(position, arguments.arguments));
26
 		
26
 		
27
 		this.member = member;
27
 		this.member = member;
28
 		this.target = target;
28
 		this.target = target;

+ 39
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUSizeExpression.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.BasicTypeID;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class ConstantUSizeExpression extends Expression {
17
+	public final long value;
18
+	
19
+	public ConstantUSizeExpression(CodePosition position, long value) {
20
+		super(position, BasicTypeID.USIZE, null);
21
+		
22
+		this.value = value;
23
+	}
24
+
25
+	@Override
26
+	public <T> T accept(ExpressionVisitor<T> visitor) {
27
+		return visitor.visitConstantUSize(this);
28
+	}
29
+
30
+	@Override
31
+	public Expression transform(ExpressionTransformer transformer) {
32
+		return this;
33
+	}
34
+
35
+	@Override
36
+	public Expression normalize(TypeScope scope) {
37
+		return this;
38
+	}
39
+}

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

66
 	
66
 	
67
 	public T visitConstantUShort(ConstantUShortExpression expression);
67
 	public T visitConstantUShort(ConstantUShortExpression expression);
68
 	
68
 	
69
+	public T visitConstantUSize(ConstantUSizeExpression expression);
70
+	
69
 	public T visitConstructorThisCall(ConstructorThisCallExpression expression);
71
 	public T visitConstructorThisCall(ConstructorThisCallExpression expression);
70
 	
72
 	
71
 	public T visitConstructorSuperCall(ConstructorSuperCallExpression expression);
73
 	public T visitConstructorSuperCall(ConstructorSuperCallExpression expression);

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

22
 	public final FunctionHeader instancedHeader;
22
 	public final FunctionHeader instancedHeader;
23
 	
23
 	
24
 	public PostCallExpression(CodePosition position, Expression target, FunctionalMemberRef member, FunctionHeader instancedHeader) {
24
 	public PostCallExpression(CodePosition position, Expression target, FunctionalMemberRef member, FunctionHeader instancedHeader) {
25
-		super(position, instancedHeader.returnType, binaryThrow(position, instancedHeader.thrownType, target.thrownType));
25
+		super(position, instancedHeader.getReturnType(), binaryThrow(position, instancedHeader.thrownType, target.thrownType));
26
 		
26
 		
27
 		if (member.getOperator() != OperatorType.DECREMENT && member.getOperator() != OperatorType.INCREMENT)
27
 		if (member.getOperator() != OperatorType.DECREMENT && member.getOperator() != OperatorType.INCREMENT)
28
 			throw new IllegalArgumentException("Operator must be increment or decrement");
28
 			throw new IllegalArgumentException("Operator must be increment or decrement");

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

9
 import org.openzen.zenscript.codemodel.scope.TypeScope;
9
 import org.openzen.zenscript.codemodel.scope.TypeScope;
10
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
12
 
13
 
13
 /**
14
 /**
14
  *
15
  *
18
 	public final Expression from;
19
 	public final Expression from;
19
 	public final Expression to;
20
 	public final Expression to;
20
 	
21
 	
21
-	public RangeExpression(CodePosition position, GlobalTypeRegistry registry, Expression from, Expression to) {
22
-		super(position, registry.getRange(from.type, to.type), binaryThrow(position, from.thrownType, to.thrownType));
22
+	public RangeExpression(CodePosition position, RangeTypeID type, Expression from, Expression to) {
23
+		super(position, type, binaryThrow(position, from.thrownType, to.thrownType));
23
 	
24
 	
24
 		this.from = from;
25
 		this.from = from;
25
 		this.to = to;
26
 		this.to = to;
46
 
47
 
47
 	@Override
48
 	@Override
48
 	public Expression normalize(TypeScope scope) {
49
 	public Expression normalize(TypeScope scope) {
49
-		return new RangeExpression(position, scope.getTypeRegistry(), from.normalize(scope), to.normalize(scope));
50
+		RangeTypeID rangeType = (RangeTypeID)type;
51
+		return new RangeExpression(
52
+				position,
53
+				rangeType,
54
+				from.normalize(scope).castImplicit(position, scope, rangeType.baseType),
55
+				to.normalize(scope).castImplicit(position, scope, rangeType.baseType));
50
 	}
56
 	}
51
 }
57
 }

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

61
 		this.genericInferenceMap = Collections.emptyMap();
61
 		this.genericInferenceMap = Collections.emptyMap();
62
 	}
62
 	}
63
 	
63
 	
64
-	public ExpressionScope(BaseScope scope, List<ITypeID> hints, Function<CodePosition, Expression> dollar, Map<TypeParameter, ITypeID> genericInferenceMap) {
65
-		this.outer = scope;
66
-		this.hints = hints;
67
-		this.dollar = dollar;
68
-		this.genericInferenceMap = genericInferenceMap;
69
-	}
70
-	
71
 	private ExpressionScope(
64
 	private ExpressionScope(
72
 			BaseScope scope,
65
 			BaseScope scope,
73
 			List<ITypeID> hints,
66
 			List<ITypeID> hints,

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

26
 	UINT("uint"),
26
 	UINT("uint"),
27
 	LONG("long"),
27
 	LONG("long"),
28
 	ULONG("ulong"),
28
 	ULONG("ulong"),
29
+	USIZE("usize"),
29
 	FLOAT("float"),
30
 	FLOAT("float"),
30
 	DOUBLE("double"),
31
 	DOUBLE("double"),
31
 	CHAR("char"),
32
 	CHAR("char"),

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

74
 
74
 
75
 	@Override
75
 	@Override
76
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
76
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
77
-		header.returnType.extractTypeParameters(typeParameters);
77
+		header.getReturnType().extractTypeParameters(typeParameters);
78
 		for (FunctionParameter parameter : header.parameters)
78
 		for (FunctionParameter parameter : header.parameters)
79
 			parameter.type.extractTypeParameters(typeParameters);
79
 			parameter.type.extractTypeParameters(typeParameters);
80
 	}
80
 	}
82
 	@Override
82
 	@Override
83
 	public int hashCode() {
83
 	public int hashCode() {
84
 		int hash = 5;
84
 		int hash = 5;
85
-		hash = 71 * hash + header.returnType.hashCode();
85
+		hash = 71 * hash + header.getReturnType().hashCode();
86
 		hash = 71 * hash + Arrays.deepHashCode(header.parameters);
86
 		hash = 71 * hash + Arrays.deepHashCode(header.parameters);
87
 		hash = 71 * hash + Arrays.deepHashCode(header.typeParameters);
87
 		hash = 71 * hash + Arrays.deepHashCode(header.typeParameters);
88
 		return hash;
88
 		return hash;
100
 			return false;
100
 			return false;
101
 		}
101
 		}
102
 		final FunctionTypeID other = (FunctionTypeID) obj;
102
 		final FunctionTypeID other = (FunctionTypeID) obj;
103
-		return this.header.returnType == other.header.returnType
103
+		return this.header.getReturnType() == other.header.getReturnType()
104
 				&& Arrays.deepEquals(this.header.parameters, other.header.parameters)
104
 				&& Arrays.deepEquals(this.header.parameters, other.header.parameters)
105
 				&& Arrays.deepEquals(this.header.typeParameters, other.header.typeParameters);
105
 				&& Arrays.deepEquals(this.header.typeParameters, other.header.typeParameters);
106
 	}
106
 	}
120
 		}
120
 		}
121
 		result.append(')');
121
 		result.append(')');
122
 		result.append(" as ");
122
 		result.append(" as ");
123
-		result.append(header.returnType);
123
+		result.append(header.getReturnType());
124
 		return result.toString();
124
 		return result.toString();
125
 	}
125
 	}
126
 }
126
 }

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

37
 		arrayTypes.put(ArrayTypeID.CHAR, ArrayTypeID.CHAR);
37
 		arrayTypes.put(ArrayTypeID.CHAR, ArrayTypeID.CHAR);
38
 		
38
 		
39
 		rangeTypes.put(RangeTypeID.INT, RangeTypeID.INT);
39
 		rangeTypes.put(RangeTypeID.INT, RangeTypeID.INT);
40
+		rangeTypes.put(RangeTypeID.USIZE, RangeTypeID.USIZE);
40
 	}
41
 	}
41
 	
42
 	
42
 	public ArrayTypeID getArray(ITypeID baseType, int dimension) {
43
 	public ArrayTypeID getArray(ITypeID baseType, int dimension) {
89
 		}
90
 		}
90
 	}
91
 	}
91
 	
92
 	
92
-	public RangeTypeID getRange(ITypeID from, ITypeID to) {
93
-		RangeTypeID id = new RangeTypeID(this, from, to);
93
+	public RangeTypeID getRange(ITypeID type) {
94
+		RangeTypeID id = new RangeTypeID(this, type);
94
 		if (rangeTypes.containsKey(id)) {
95
 		if (rangeTypes.containsKey(id)) {
95
 			return rangeTypes.get(id);
96
 			return rangeTypes.get(id);
96
 		} else {
97
 		} else {

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

149
 				if (functionType.header.parameters.length != function.header.parameters.length)
149
 				if (functionType.header.parameters.length != function.header.parameters.length)
150
 					return false;
150
 					return false;
151
 				
151
 				
152
-				if (!match(functionType.header.returnType, function.header.returnType))
152
+				if (!match(functionType.header.getReturnType(), function.header.getReturnType()))
153
 					return false;
153
 					return false;
154
 				
154
 				
155
 				for (int i = 0; i < function.header.parameters.length; i++) {
155
 				for (int i = 0; i < function.header.parameters.length; i++) {
199
 		public Boolean visitRange(RangeTypeID range) {
199
 		public Boolean visitRange(RangeTypeID range) {
200
 			if (type instanceof RangeTypeID) {
200
 			if (type instanceof RangeTypeID) {
201
 				RangeTypeID rangeType = (RangeTypeID) type;
201
 				RangeTypeID rangeType = (RangeTypeID) type;
202
-				return match(rangeType.from, range.from) && match(rangeType.to, range.to);
202
+				return match(rangeType.baseType, range.baseType);
203
 			} else {
203
 			} else {
204
 				return false;
204
 				return false;
205
 			}
205
 			}

+ 13
- 18
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java View File

14
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
15
  */
15
  */
16
 public class RangeTypeID implements ITypeID {
16
 public class RangeTypeID implements ITypeID {
17
-	public static final RangeTypeID INT = new RangeTypeID(null, BasicTypeID.INT, BasicTypeID.INT);
17
+	public static final RangeTypeID INT = new RangeTypeID(null, BasicTypeID.INT);
18
+	public static final RangeTypeID USIZE = new RangeTypeID(null, BasicTypeID.USIZE);
18
 	
19
 	
19
-	public final ITypeID from;
20
-	public final ITypeID to;
20
+	public final ITypeID baseType;
21
 	private final RangeTypeID normalized;
21
 	private final RangeTypeID normalized;
22
 	
22
 	
23
-	public RangeTypeID(GlobalTypeRegistry registry, ITypeID from, ITypeID to) {
24
-		this.from = from;
25
-		this.to = to;
23
+	public RangeTypeID(GlobalTypeRegistry registry, ITypeID baseType) {
24
+		this.baseType = baseType;
26
 		
25
 		
27
-		if (from.getNormalized() == from && to.getNormalized() == to) {
26
+		if (baseType.getNormalized() == baseType) {
28
 			normalized = this;
27
 			normalized = this;
29
 		} else {
28
 		} else {
30
-			normalized = registry.getRange(from.getNormalized(), to.getNormalized());
29
+			normalized = registry.getRange(baseType.getNormalized());
31
 		}
30
 		}
32
 	}
31
 	}
33
 	
32
 	
38
 	
37
 	
39
 	@Override
38
 	@Override
40
 	public ITypeID instance(GenericMapper mapper) {
39
 	public ITypeID instance(GenericMapper mapper) {
41
-		return mapper.registry.getRange(
42
-				from.instance(mapper),
43
-				to.instance(mapper));
40
+		return mapper.registry.getRange(baseType.instance(mapper));
44
 	}
41
 	}
45
 
42
 
46
 	@Override
43
 	@Override
70
 
67
 
71
 	@Override
68
 	@Override
72
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
69
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
73
-		return from.hasInferenceBlockingTypeParameters(parameters) || to.hasInferenceBlockingTypeParameters(parameters);
70
+		return baseType.hasInferenceBlockingTypeParameters(parameters);
74
 	}
71
 	}
75
 
72
 
76
 	@Override
73
 	@Override
80
 
77
 
81
 	@Override
78
 	@Override
82
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
79
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
83
-		from.extractTypeParameters(typeParameters);
84
-		to.extractTypeParameters(typeParameters);
80
+		baseType.extractTypeParameters(typeParameters);
85
 	}
81
 	}
86
 
82
 
87
 	@Override
83
 	@Override
88
 	public int hashCode() {
84
 	public int hashCode() {
89
 		int hash = 5;
85
 		int hash = 5;
90
-		hash = 89 * hash + from.hashCode();
91
-		hash = 89 * hash + to.hashCode();
86
+		hash = 89 * hash + baseType.hashCode();
92
 		return hash;
87
 		return hash;
93
 	}
88
 	}
94
 
89
 
104
 			return false;
99
 			return false;
105
 		}
100
 		}
106
 		final RangeTypeID other = (RangeTypeID) obj;
101
 		final RangeTypeID other = (RangeTypeID) obj;
107
-		return this.from == other.from && this.to == other.to;
102
+		return this.baseType == other.baseType;
108
 	}
103
 	}
109
 	
104
 	
110
 	@Override
105
 	@Override
111
 	public String toString() {
106
 	public String toString() {
112
-		return from.toString() + " .. " + to.toString();
107
+		return baseType.toString() + " .. " + baseType.toString();
113
 	}
108
 	}
114
 }
109
 }

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

52
 
52
 
53
 	@Override
53
 	@Override
54
 	public Void visitFunction(FunctionTypeID function) {
54
 	public Void visitFunction(FunctionTypeID function) {
55
-		function.header.returnType.accept(this);
55
+		function.header.getReturnType().accept(this);
56
 		for (FunctionParameter parameter : function.header.parameters)
56
 		for (FunctionParameter parameter : function.header.parameters)
57
 			parameter.type.accept(this);
57
 			parameter.type.accept(this);
58
 		return null;
58
 		return null;
75
 
75
 
76
 	@Override
76
 	@Override
77
 	public Void visitRange(RangeTypeID range) {
77
 	public Void visitRange(RangeTypeID range) {
78
-		range.from.accept(this);
79
-		range.to.accept(this);
78
+		range.baseType.accept(this);
80
 		return null;
79
 		return null;
81
 	}
80
 	}
82
 
81
 

+ 52
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinID.java View File

38
 	BYTE_TO_UINT,
38
 	BYTE_TO_UINT,
39
 	BYTE_TO_LONG,
39
 	BYTE_TO_LONG,
40
 	BYTE_TO_ULONG,
40
 	BYTE_TO_ULONG,
41
+	BYTE_TO_USIZE,
41
 	BYTE_TO_FLOAT,
42
 	BYTE_TO_FLOAT,
42
 	BYTE_TO_DOUBLE,
43
 	BYTE_TO_DOUBLE,
43
 	BYTE_TO_CHAR,
44
 	BYTE_TO_CHAR,
67
 	SBYTE_TO_UINT,
68
 	SBYTE_TO_UINT,
68
 	SBYTE_TO_LONG,
69
 	SBYTE_TO_LONG,
69
 	SBYTE_TO_ULONG,
70
 	SBYTE_TO_ULONG,
71
+	SBYTE_TO_USIZE,
70
 	SBYTE_TO_FLOAT,
72
 	SBYTE_TO_FLOAT,
71
 	SBYTE_TO_DOUBLE,
73
 	SBYTE_TO_DOUBLE,
72
 	SBYTE_TO_CHAR,
74
 	SBYTE_TO_CHAR,
96
 	SHORT_TO_UINT,
98
 	SHORT_TO_UINT,
97
 	SHORT_TO_LONG,
99
 	SHORT_TO_LONG,
98
 	SHORT_TO_ULONG,
100
 	SHORT_TO_ULONG,
101
+	SHORT_TO_USIZE,
99
 	SHORT_TO_FLOAT,
102
 	SHORT_TO_FLOAT,
100
 	SHORT_TO_DOUBLE,
103
 	SHORT_TO_DOUBLE,
101
 	SHORT_TO_CHAR,
104
 	SHORT_TO_CHAR,
124
 	USHORT_TO_UINT,
127
 	USHORT_TO_UINT,
125
 	USHORT_TO_LONG,
128
 	USHORT_TO_LONG,
126
 	USHORT_TO_ULONG,
129
 	USHORT_TO_ULONG,
130
+	USHORT_TO_USIZE,
127
 	USHORT_TO_FLOAT,
131
 	USHORT_TO_FLOAT,
128
 	USHORT_TO_DOUBLE,
132
 	USHORT_TO_DOUBLE,
129
 	USHORT_TO_CHAR,
133
 	USHORT_TO_CHAR,
156
 	INT_TO_UINT,
160
 	INT_TO_UINT,
157
 	INT_TO_LONG,
161
 	INT_TO_LONG,
158
 	INT_TO_ULONG,
162
 	INT_TO_ULONG,
163
+	INT_TO_USIZE,
159
 	INT_TO_FLOAT,
164
 	INT_TO_FLOAT,
160
 	INT_TO_DOUBLE,
165
 	INT_TO_DOUBLE,
161
 	INT_TO_CHAR,
166
 	INT_TO_CHAR,
195
 	UINT_TO_INT,
200
 	UINT_TO_INT,
196
 	UINT_TO_LONG,
201
 	UINT_TO_LONG,
197
 	UINT_TO_ULONG,
202
 	UINT_TO_ULONG,
203
+	UINT_TO_USIZE,
198
 	UINT_TO_FLOAT,
204
 	UINT_TO_FLOAT,
199
 	UINT_TO_DOUBLE,
205
 	UINT_TO_DOUBLE,
200
 	UINT_TO_CHAR,
206
 	UINT_TO_CHAR,
236
 	LONG_TO_INT,
242
 	LONG_TO_INT,
237
 	LONG_TO_UINT,
243
 	LONG_TO_UINT,
238
 	LONG_TO_ULONG,
244
 	LONG_TO_ULONG,
245
+	LONG_TO_USIZE,
239
 	LONG_TO_FLOAT,
246
 	LONG_TO_FLOAT,
240
 	LONG_TO_DOUBLE,
247
 	LONG_TO_DOUBLE,
241
 	LONG_TO_CHAR,
248
 	LONG_TO_CHAR,
275
 	ULONG_TO_INT,
282
 	ULONG_TO_INT,
276
 	ULONG_TO_UINT,
283
 	ULONG_TO_UINT,
277
 	ULONG_TO_LONG,
284
 	ULONG_TO_LONG,
285
+	ULONG_TO_USIZE,
278
 	ULONG_TO_FLOAT,
286
 	ULONG_TO_FLOAT,
279
 	ULONG_TO_DOUBLE,
287
 	ULONG_TO_DOUBLE,
280
 	ULONG_TO_CHAR,
288
 	ULONG_TO_CHAR,
293
 	ULONG_LOWEST_ZERO_BIT,
301
 	ULONG_LOWEST_ZERO_BIT,
294
 	ULONG_BIT_COUNT,
302
 	ULONG_BIT_COUNT,
295
 	
303
 	
304
+	USIZE_NOT,
305
+	USIZE_INC,
306
+	USIZE_DEC,
307
+	USIZE_ADD_USIZE,
308
+	USIZE_SUB_USIZE,
309
+	USIZE_MUL_USIZE,
310
+	USIZE_DIV_USIZE,
311
+	USIZE_MOD_USIZE,
312
+	USIZE_AND_USIZE,
313
+	USIZE_OR_USIZE,
314
+	USIZE_XOR_USIZE,
315
+	USIZE_SHL,
316
+	USIZE_SHR,
317
+	USIZE_COMPARE,
318
+	USIZE_TO_BYTE,
319
+	USIZE_TO_SBYTE,
320
+	USIZE_TO_SHORT,
321
+	USIZE_TO_USHORT,
322
+	USIZE_TO_INT,
323
+	USIZE_TO_UINT,
324
+	USIZE_TO_LONG,
325
+	USIZE_TO_ULONG,
326
+	USIZE_TO_FLOAT,
327
+	USIZE_TO_DOUBLE,
328
+	USIZE_TO_CHAR,
329
+	USIZE_TO_STRING,
330
+	USIZE_PARSE,
331
+	USIZE_PARSE_WITH_BASE,
332
+	USIZE_GET_MIN_VALUE,
333
+	USIZE_GET_MAX_VALUE,
334
+	USIZE_COUNT_LOW_ZEROES,
335
+	USIZE_COUNT_HIGH_ZEROES,
336
+	USIZE_COUNT_LOW_ONES,
337
+	USIZE_COUNT_HIGH_ONES,
338
+	USIZE_HIGHEST_ONE_BIT,
339
+	USIZE_LOWEST_ONE_BIT,
340
+	USIZE_HIGHEST_ZERO_BIT,
341
+	USIZE_LOWEST_ZERO_BIT,
342
+	USIZE_BIT_COUNT,
343
+	USIZE_BITS,
344
+	
296
 	FLOAT_NEG,
345
 	FLOAT_NEG,
297
 	FLOAT_INC,
346
 	FLOAT_INC,
298
 	FLOAT_DEC,
347
 	FLOAT_DEC,
310
 	FLOAT_TO_UINT,
359
 	FLOAT_TO_UINT,
311
 	FLOAT_TO_LONG,
360
 	FLOAT_TO_LONG,
312
 	FLOAT_TO_ULONG,
361
 	FLOAT_TO_ULONG,
362
+	FLOAT_TO_USIZE,
313
 	FLOAT_TO_DOUBLE,
363
 	FLOAT_TO_DOUBLE,
314
 	FLOAT_TO_STRING,
364
 	FLOAT_TO_STRING,
315
 	FLOAT_BITS,
365
 	FLOAT_BITS,
335
 	DOUBLE_TO_UINT,
385
 	DOUBLE_TO_UINT,
336
 	DOUBLE_TO_LONG,
386
 	DOUBLE_TO_LONG,
337
 	DOUBLE_TO_ULONG,
387
 	DOUBLE_TO_ULONG,
388
+	DOUBLE_TO_USIZE,
338
 	DOUBLE_TO_FLOAT,
389
 	DOUBLE_TO_FLOAT,
339
 	DOUBLE_TO_STRING,
390
 	DOUBLE_TO_STRING,
340
 	DOUBLE_BITS,
391
 	DOUBLE_BITS,
355
 	CHAR_TO_UINT,
406
 	CHAR_TO_UINT,
356
 	CHAR_TO_LONG,
407
 	CHAR_TO_LONG,
357
 	CHAR_TO_ULONG,
408
 	CHAR_TO_ULONG,
409
+	CHAR_TO_USIZE,
358
 	CHAR_TO_STRING,
410
 	CHAR_TO_STRING,
359
 	CHAR_GET_MIN_VALUE,
411
 	CHAR_GET_MIN_VALUE,
360
 	CHAR_GET_MAX_VALUE,
412
 	CHAR_GET_MAX_VALUE,

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

24
 import org.openzen.zenscript.codemodel.type.ITypeID;
24
 import org.openzen.zenscript.codemodel.type.ITypeID;
25
 import org.openzen.zenscript.codemodel.CompareType;
25
 import org.openzen.zenscript.codemodel.CompareType;
26
 import org.openzen.zenscript.codemodel.FunctionHeader;
26
 import org.openzen.zenscript.codemodel.FunctionHeader;
27
-import org.openzen.zenscript.codemodel.GenericMapper;
28
 import org.openzen.zenscript.codemodel.expression.ConstExpression;
27
 import org.openzen.zenscript.codemodel.expression.ConstExpression;
29
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
28
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
30
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
29
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
263
 			if (header.typeParameters != null) {
262
 			if (header.typeParameters != null) {
264
 				for (ITypeID resultHint : typeHints) {
263
 				for (ITypeID resultHint : typeHints) {
265
 					Map<TypeParameter, ITypeID> mapping = new HashMap<>();
264
 					Map<TypeParameter, ITypeID> mapping = new HashMap<>();
266
-					if (header.returnType.inferTypeParameters(scope.getMemberCache(), resultHint, mapping)) {
265
+					if (header.getReturnType().inferTypeParameters(scope.getMemberCache(), resultHint, mapping)) {
267
 						header = header.withGenericArguments(scope.getTypeRegistry(), scope.getLocalTypeParameters().getInner(scope.getTypeRegistry(), mapping));
266
 						header = header.withGenericArguments(scope.getTypeRegistry(), scope.getLocalTypeParameters().getInner(scope.getTypeRegistry(), mapping));
268
 						break;
267
 						break;
269
 					}
268
 					}
361
 				throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "This type has no " + name);
360
 				throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "This type has no " + name);
362
 			}
361
 			}
363
 			
362
 			
364
-			outer: for (TypeMember<FunctionalMemberRef> method : methods) {
363
+			for (TypeMember<FunctionalMemberRef> method : methods) {
365
 				if (!(method.member.isStatic() ? allowStatic : allowNonStatic)) {
364
 				if (!(method.member.isStatic() ? allowStatic : allowNonStatic)) {
366
 					message.append(method.member.isStatic() ? "Method must not be static" : "Method must be static").append('\n');
365
 					message.append(method.member.isStatic() ? "Method must not be static" : "Method must be static").append('\n');
367
 					continue;
366
 					continue;

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

69
 import org.openzen.zencode.shared.CompileException;
69
 import org.openzen.zencode.shared.CompileException;
70
 import org.openzen.zencode.shared.CompileExceptionCode;
70
 import org.openzen.zencode.shared.CompileExceptionCode;
71
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
71
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
72
+import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
72
 import org.openzen.zenscript.codemodel.member.IteratorMember;
73
 import org.openzen.zenscript.codemodel.member.IteratorMember;
73
 
74
 
74
 /**
75
 /**
149
 			case ULONG:
150
 			case ULONG:
150
 				visitULong();
151
 				visitULong();
151
 				break;
152
 				break;
153
+			case USIZE:
154
+				visitUSize();
155
+				break;
152
 			case FLOAT:
156
 			case FLOAT:
153
 				visitFloat();
157
 				visitFloat();
154
 				break;
158
 				break;
174
 
178
 
175
 		FunctionParameter[] indexGetParameters = new FunctionParameter[dimension];
179
 		FunctionParameter[] indexGetParameters = new FunctionParameter[dimension];
176
 		for (int i = 0; i < indexGetParameters.length; i++)
180
 		for (int i = 0; i < indexGetParameters.length; i++)
177
-			indexGetParameters[i] = new FunctionParameter(INT);
181
+			indexGetParameters[i] = new FunctionParameter(USIZE);
178
 		
182
 		
179
 		operator(
183
 		operator(
180
 				definition,
184
 				definition,
183
 				ARRAY_INDEXGET);
187
 				ARRAY_INDEXGET);
184
 		
188
 		
185
 		if (dimension == 1) {
189
 		if (dimension == 1) {
186
-			FunctionHeader sliceHeader = new FunctionHeader(array, new FunctionParameter(cache.getRegistry().getRange(INT, INT), "range"));
190
+			FunctionHeader sliceHeader = new FunctionHeader(array, new FunctionParameter(RangeTypeID.USIZE, "range"));
187
 			operator(
191
 			operator(
188
 					definition,
192
 					definition,
189
 					OperatorType.INDEXGET,
193
 					OperatorType.INDEXGET,
209
 
213
 
210
 		FunctionParameter[] initialValueConstructorParameters = new FunctionParameter[dimension + 1];
214
 		FunctionParameter[] initialValueConstructorParameters = new FunctionParameter[dimension + 1];
211
 		for (int i = 0; i < dimension; i++)
215
 		for (int i = 0; i < dimension; i++)
212
-			initialValueConstructorParameters[i] = new FunctionParameter(INT);
216
+			initialValueConstructorParameters[i] = new FunctionParameter(USIZE);
213
 		initialValueConstructorParameters[dimension] = new FunctionParameter(baseType);
217
 		initialValueConstructorParameters[dimension] = new FunctionParameter(baseType);
214
 		FunctionHeader initialValueConstructorHeader = new FunctionHeader(VOID, initialValueConstructorParameters);
218
 		FunctionHeader initialValueConstructorHeader = new FunctionHeader(VOID, initialValueConstructorParameters);
215
 		new ConstructorMember(
219
 		new ConstructorMember(
222
 		
226
 		
223
 		FunctionParameter[] lambdaConstructorParameters = new FunctionParameter[dimension + 1];
227
 		FunctionParameter[] lambdaConstructorParameters = new FunctionParameter[dimension + 1];
224
 		for (int i = 0; i < dimension; i++)
228
 		for (int i = 0; i < dimension; i++)
225
-			lambdaConstructorParameters[i] = new FunctionParameter(INT, null);
229
+			lambdaConstructorParameters[i] = new FunctionParameter(USIZE, null);
226
 		
230
 		
227
 		FunctionHeader lambdaConstructorFunction = new FunctionHeader(baseType, indexGetParameters);
231
 		FunctionHeader lambdaConstructorFunction = new FunctionHeader(baseType, indexGetParameters);
228
 		lambdaConstructorParameters[dimension] = new FunctionParameter(cache.getRegistry().getFunction(lambdaConstructorFunction), null);
232
 		lambdaConstructorParameters[dimension] = new FunctionParameter(cache.getRegistry().getFunction(lambdaConstructorFunction), null);
255
 			TypeParameter mappedConstructorParameter = new TypeParameter(BUILTIN, "T");
259
 			TypeParameter mappedConstructorParameter = new TypeParameter(BUILTIN, "T");
256
 			FunctionParameter[] projectionParameters = new FunctionParameter[dimension + 1];
260
 			FunctionParameter[] projectionParameters = new FunctionParameter[dimension + 1];
257
 			for (int i = 0; i < dimension; i++)
261
 			for (int i = 0; i < dimension; i++)
258
-				projectionParameters[i] = new FunctionParameter(INT);
262
+				projectionParameters[i] = new FunctionParameter(USIZE);
259
 			projectionParameters[dimension] = new FunctionParameter(registry.getGeneric(mappedConstructorParameter));
263
 			projectionParameters[dimension] = new FunctionParameter(registry.getGeneric(mappedConstructorParameter));
260
 			
264
 			
261
 			FunctionHeader mappedConstructorHeaderWithIndex = new FunctionHeader(baseType, projectionParameters);
265
 			FunctionHeader mappedConstructorHeaderWithIndex = new FunctionHeader(baseType, projectionParameters);
270
 		
274
 		
271
 		FunctionParameter[] indexSetParameters = new FunctionParameter[dimension + 1];
275
 		FunctionParameter[] indexSetParameters = new FunctionParameter[dimension + 1];
272
 		for (int i = 0; i < dimension; i++)
276
 		for (int i = 0; i < dimension; i++)
273
-			indexSetParameters[i] = new FunctionParameter(INT, null);
277
+			indexSetParameters[i] = new FunctionParameter(USIZE, null);
274
 		indexSetParameters[dimension] = new FunctionParameter(baseType, null);
278
 		indexSetParameters[dimension] = new FunctionParameter(baseType, null);
275
 
279
 
276
 		FunctionHeader indexSetHeader = new FunctionHeader(VOID, indexSetParameters);
280
 		FunctionHeader indexSetHeader = new FunctionHeader(VOID, indexSetParameters);
277
 		operator(definition, OperatorType.INDEXSET, indexSetHeader, ARRAY_INDEXSET);
281
 		operator(definition, OperatorType.INDEXSET, indexSetHeader, ARRAY_INDEXSET);
278
 		
282
 		
279
 		if (dimension == 1) {
283
 		if (dimension == 1) {
280
-			getter(definition, ARRAY_LENGTH, "length", INT);
284
+			getter(definition, ARRAY_LENGTH, "length", USIZE);
281
 		}
285
 		}
282
 
286
 
283
 		getter(definition, ARRAY_ISEMPTY, "isEmpty", BOOL);
287
 		getter(definition, ARRAY_ISEMPTY, "isEmpty", BOOL);
284
 		getter(definition, ARRAY_HASHCODE, "objectHashCode", INT);
288
 		getter(definition, ARRAY_HASHCODE, "objectHashCode", INT);
285
 		iterator(definition, ITERATOR_ARRAY_VALUES, baseType);
289
 		iterator(definition, ITERATOR_ARRAY_VALUES, baseType);
286
-		iterator(definition, ITERATOR_ARRAY_KEY_VALUES, INT, baseType);
290
+		iterator(definition, ITERATOR_ARRAY_KEY_VALUES, USIZE, baseType);
287
 		
291
 		
288
 		equals(definition, ARRAY_EQUALS, array);
292
 		equals(definition, ARRAY_EQUALS, array);
289
 		notequals(definition, ARRAY_NOTEQUALS, array);
293
 		notequals(definition, ARRAY_NOTEQUALS, array);
314
 				new FunctionHeader(BOOL, new FunctionParameter(keyType, "key")),
318
 				new FunctionHeader(BOOL, new FunctionParameter(keyType, "key")),
315
 				ASSOC_CONTAINS);
319
 				ASSOC_CONTAINS);
316
 		
320
 		
317
-		getter(builtin, BuiltinID.ASSOC_SIZE, "size", INT);
321
+		getter(builtin, BuiltinID.ASSOC_SIZE, "size", USIZE);
318
 		getter(builtin, BuiltinID.ASSOC_ISEMPTY, "isEmpty", BOOL);
322
 		getter(builtin, BuiltinID.ASSOC_ISEMPTY, "isEmpty", BOOL);
319
 		getter(builtin, BuiltinID.ASSOC_KEYS, "keys", cache.getRegistry().getArray(keyType, 1));
323
 		getter(builtin, BuiltinID.ASSOC_KEYS, "keys", cache.getRegistry().getArray(keyType, 1));
320
 		getter(builtin, BuiltinID.ASSOC_VALUES, "values", cache.getRegistry().getArray(valueType, 1));
324
 		getter(builtin, BuiltinID.ASSOC_VALUES, "values", cache.getRegistry().getArray(valueType, 1));
350
 		method(builtin, "contains", containsHeader, GENERICMAP_CONTAINS);
354
 		method(builtin, "contains", containsHeader, GENERICMAP_CONTAINS);
351
 		method(builtin, "addAll", new FunctionHeader(VOID, map), GENERICMAP_ADDALL);
355
 		method(builtin, "addAll", new FunctionHeader(VOID, map), GENERICMAP_ADDALL);
352
 		
356
 		
353
-		getter(builtin, GENERICMAP_SIZE, "size", INT);
357
+		getter(builtin, GENERICMAP_SIZE, "size", USIZE);
354
 		getter(builtin, GENERICMAP_ISEMPTY, "isEmpty", BOOL);
358
 		getter(builtin, GENERICMAP_ISEMPTY, "isEmpty", BOOL);
355
 		getter(builtin, GENERICMAP_HASHCODE, "objectHashCode", INT);
359
 		getter(builtin, GENERICMAP_HASHCODE, "objectHashCode", INT);
356
 		
360
 		
443
 		
447
 		
444
 		if (definition instanceof EnumDefinition) {
448
 		if (definition instanceof EnumDefinition) {
445
 			getter(definition, ENUM_NAME, "name", STRING);
449
 			getter(definition, ENUM_NAME, "name", STRING);
446
-			getter(definition, ENUM_ORDINAL, "ordinal", INT);
450
+			getter(definition, ENUM_ORDINAL, "ordinal", USIZE);
447
 			
451
 			
448
 			List<EnumConstantMember> enumConstants = ((EnumDefinition) definition).enumConstants;
452
 			List<EnumConstantMember> enumConstants = ((EnumDefinition) definition).enumConstants;
449
 			Expression[] constValues = new Expression[enumConstants.size()];
453
 			Expression[] constValues = new Expression[enumConstants.size()];
490
 
494
 
491
 	@Override
495
 	@Override
492
 	public Void visitRange(RangeTypeID range) {
496
 	public Void visitRange(RangeTypeID range) {
493
-		ITypeID fromType = range.from;
494
-		ITypeID toType = range.to;
497
+		ITypeID baseType = range.baseType;
495
 
498
 
496
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
499
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
497
-		getter(definition, RANGE_FROM, "from", fromType);
498
-		getter(definition, RANGE_TO, "to", toType);
499
-		if (range.from == range.to && (
500
-				   range.from == BYTE
501
-				|| range.from == SBYTE
502
-				|| range.from == SHORT
503
-				|| range.from == USHORT
504
-				|| range.from == INT
505
-				|| range.from == UINT
506
-				|| range.from == LONG
507
-				|| range.from == ULONG)) {
500
+		getter(definition, RANGE_FROM, "from", baseType);
501
+		getter(definition, RANGE_TO, "to", baseType);
502
+		if (baseType == BYTE
503
+				|| baseType == SBYTE
504
+				|| baseType == SHORT
505
+				|| baseType == USHORT
506
+				|| baseType == INT
507
+				|| baseType == UINT
508
+				|| baseType == LONG
509
+				|| baseType == ULONG
510
+				|| baseType == USIZE) {
508
 			
511
 			
509
-			iterator(definition, ITERATOR_INT_RANGE, range.from);
512
+			iterator(definition, ITERATOR_INT_RANGE, baseType);
510
 		}
513
 		}
511
 		
514
 		
512
 		processType(definition, range);
515
 		processType(definition, range);
564
 		castImplicit(builtin, BYTE_TO_UINT, UINT);
567
 		castImplicit(builtin, BYTE_TO_UINT, UINT);
565
 		castImplicit(builtin, BYTE_TO_LONG, LONG);
568
 		castImplicit(builtin, BYTE_TO_LONG, LONG);
566
 		castImplicit(builtin, BYTE_TO_ULONG, ULONG);
569
 		castImplicit(builtin, BYTE_TO_ULONG, ULONG);
570
+		castImplicit(builtin, BYTE_TO_USIZE, USIZE);
567
 		castImplicit(builtin, BYTE_TO_FLOAT, FLOAT);
571
 		castImplicit(builtin, BYTE_TO_FLOAT, FLOAT);
568
 		castImplicit(builtin, BYTE_TO_DOUBLE, DOUBLE);
572
 		castImplicit(builtin, BYTE_TO_DOUBLE, DOUBLE);
569
 		castExplicit(builtin, BYTE_TO_CHAR, CHAR);
573
 		castExplicit(builtin, BYTE_TO_CHAR, CHAR);
602
 		castImplicit(builtin, SBYTE_TO_UINT, UINT);
606
 		castImplicit(builtin, SBYTE_TO_UINT, UINT);
603
 		castImplicit(builtin, SBYTE_TO_LONG, LONG);
607
 		castImplicit(builtin, SBYTE_TO_LONG, LONG);
604
 		castImplicit(builtin, SBYTE_TO_ULONG, ULONG);
608
 		castImplicit(builtin, SBYTE_TO_ULONG, ULONG);
609
+		castImplicit(builtin, SBYTE_TO_USIZE, USIZE);
605
 		castImplicit(builtin, SBYTE_TO_FLOAT, FLOAT);
610
 		castImplicit(builtin, SBYTE_TO_FLOAT, FLOAT);
606
 		castImplicit(builtin, SBYTE_TO_DOUBLE, DOUBLE);
611
 		castImplicit(builtin, SBYTE_TO_DOUBLE, DOUBLE);
607
 		castExplicit(builtin, SBYTE_TO_CHAR, CHAR);
612
 		castExplicit(builtin, SBYTE_TO_CHAR, CHAR);
640
 		castImplicit(builtin, SHORT_TO_UINT, UINT);
645
 		castImplicit(builtin, SHORT_TO_UINT, UINT);
641
 		castImplicit(builtin, SHORT_TO_LONG, LONG);
646
 		castImplicit(builtin, SHORT_TO_LONG, LONG);
642
 		castImplicit(builtin, SHORT_TO_ULONG, ULONG);
647
 		castImplicit(builtin, SHORT_TO_ULONG, ULONG);
648
+		castImplicit(builtin, SHORT_TO_USIZE, USIZE);
643
 		castImplicit(builtin, SHORT_TO_FLOAT, FLOAT);
649
 		castImplicit(builtin, SHORT_TO_FLOAT, FLOAT);
644
 		castImplicit(builtin, SHORT_TO_DOUBLE, DOUBLE);
650
 		castImplicit(builtin, SHORT_TO_DOUBLE, DOUBLE);
645
 		castExplicit(builtin, SHORT_TO_CHAR, CHAR);
651
 		castExplicit(builtin, SHORT_TO_CHAR, CHAR);
677
 		castImplicit(builtin, USHORT_TO_UINT, UINT);
683
 		castImplicit(builtin, USHORT_TO_UINT, UINT);
678
 		castImplicit(builtin, USHORT_TO_LONG, LONG);
684
 		castImplicit(builtin, USHORT_TO_LONG, LONG);
679
 		castImplicit(builtin, USHORT_TO_ULONG, ULONG);
685
 		castImplicit(builtin, USHORT_TO_ULONG, ULONG);
686
+		castImplicit(builtin, USHORT_TO_USIZE, USIZE);
680
 		castImplicit(builtin, USHORT_TO_FLOAT, FLOAT);
687
 		castImplicit(builtin, USHORT_TO_FLOAT, FLOAT);
681
 		castImplicit(builtin, USHORT_TO_DOUBLE, DOUBLE);
688
 		castImplicit(builtin, USHORT_TO_DOUBLE, DOUBLE);
682
 		castExplicit(builtin, USHORT_TO_CHAR, CHAR);
689
 		castExplicit(builtin, USHORT_TO_CHAR, CHAR);
748
 		castImplicit(builtin, INT_TO_UINT, UINT);
755
 		castImplicit(builtin, INT_TO_UINT, UINT);
749
 		castImplicit(builtin, INT_TO_LONG, LONG);
756
 		castImplicit(builtin, INT_TO_LONG, LONG);
750
 		castImplicit(builtin, INT_TO_ULONG, ULONG);
757
 		castImplicit(builtin, INT_TO_ULONG, ULONG);
758
+		castImplicit(builtin, INT_TO_USIZE, USIZE);
751
 		castImplicit(builtin, INT_TO_FLOAT, FLOAT);
759
 		castImplicit(builtin, INT_TO_FLOAT, FLOAT);
752
 		castImplicit(builtin, INT_TO_DOUBLE, DOUBLE);
760
 		castImplicit(builtin, INT_TO_DOUBLE, DOUBLE);
753
 		castExplicit(builtin, INT_TO_CHAR, CHAR);
761
 		castExplicit(builtin, INT_TO_CHAR, CHAR);
826
 		castImplicit(builtin, UINT_TO_INT, INT);
834
 		castImplicit(builtin, UINT_TO_INT, INT);
827
 		castImplicit(builtin, UINT_TO_LONG, LONG);
835
 		castImplicit(builtin, UINT_TO_LONG, LONG);
828
 		castImplicit(builtin, UINT_TO_ULONG, ULONG);
836
 		castImplicit(builtin, UINT_TO_ULONG, ULONG);
837
+		castImplicit(builtin, UINT_TO_USIZE, USIZE);
829
 		castImplicit(builtin, UINT_TO_FLOAT, FLOAT);
838
 		castImplicit(builtin, UINT_TO_FLOAT, FLOAT);
830
 		castImplicit(builtin, UINT_TO_DOUBLE, DOUBLE);
839
 		castImplicit(builtin, UINT_TO_DOUBLE, DOUBLE);
831
 		castExplicit(builtin, UINT_TO_CHAR, CHAR);
840
 		castExplicit(builtin, UINT_TO_CHAR, CHAR);
897
 		castExplicit(builtin, LONG_TO_INT, INT);
906
 		castExplicit(builtin, LONG_TO_INT, INT);
898
 		castExplicit(builtin, LONG_TO_UINT, UINT);
907
 		castExplicit(builtin, LONG_TO_UINT, UINT);
899
 		castImplicit(builtin, LONG_TO_ULONG, ULONG);
908
 		castImplicit(builtin, LONG_TO_ULONG, ULONG);
909
+		castExplicit(builtin, LONG_TO_USIZE, USIZE);
900
 		castImplicit(builtin, LONG_TO_FLOAT, FLOAT);
910
 		castImplicit(builtin, LONG_TO_FLOAT, FLOAT);
901
 		castImplicit(builtin, LONG_TO_DOUBLE, DOUBLE);
911
 		castImplicit(builtin, LONG_TO_DOUBLE, DOUBLE);
902
 		castExplicit(builtin, LONG_TO_CHAR, CHAR);
912
 		castExplicit(builtin, LONG_TO_CHAR, CHAR);
966
 		castExplicit(builtin, ULONG_TO_INT, INT);
976
 		castExplicit(builtin, ULONG_TO_INT, INT);
967
 		castExplicit(builtin, ULONG_TO_UINT, UINT);
977
 		castExplicit(builtin, ULONG_TO_UINT, UINT);
968
 		castImplicit(builtin, ULONG_TO_LONG, LONG);
978
 		castImplicit(builtin, ULONG_TO_LONG, LONG);
979
+		castExplicit(builtin, ULONG_TO_USIZE, USIZE);
969
 		castImplicit(builtin, ULONG_TO_FLOAT, FLOAT);
980
 		castImplicit(builtin, ULONG_TO_FLOAT, FLOAT);
970
 		castImplicit(builtin, ULONG_TO_DOUBLE, DOUBLE);
981
 		castImplicit(builtin, ULONG_TO_DOUBLE, DOUBLE);
971
 		castExplicit(builtin, ULONG_TO_CHAR, CHAR);
982
 		castExplicit(builtin, ULONG_TO_CHAR, CHAR);
989
 		processType(builtin, ULONG);
1000
 		processType(builtin, ULONG);
990
 	}
1001
 	}
991
 	
1002
 	
1003
+	private void visitUSize() {
1004
+		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "usize", Modifiers.EXPORT, null);
1005
+		
1006
+		invert(builtin, USIZE_NOT, USIZE);
1007
+		inc(builtin, USIZE_DEC, USIZE);
1008
+		dec(builtin, USIZE_INC, USIZE);
1009
+
1010
+		add(builtin, USIZE_ADD_USIZE, USIZE, USIZE);
1011
+		add(builtin, ULONG_ADD_ULONG, ULONG, ULONG, USIZE_TO_ULONG);
1012
+		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT, USIZE_TO_FLOAT);
1013
+		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, USIZE_TO_DOUBLE);
1014
+		
1015
+		sub(builtin, USIZE_SUB_USIZE, USIZE, USIZE);
1016
+		sub(builtin, ULONG_SUB_ULONG, ULONG, ULONG, USIZE_TO_ULONG);
1017
+		sub(builtin, FLOAT_SUB_FLOAT, FLOAT, FLOAT, USIZE_TO_FLOAT);
1018
+		sub(builtin, DOUBLE_SUB_DOUBLE, DOUBLE, DOUBLE, USIZE_TO_DOUBLE);
1019
+		
1020
+		mul(builtin, USIZE_MUL_USIZE, USIZE, USIZE);
1021
+		mul(builtin, ULONG_MUL_ULONG, ULONG, ULONG, USIZE_TO_ULONG);
1022
+		mul(builtin, FLOAT_MUL_FLOAT, FLOAT, FLOAT, USIZE_TO_FLOAT);
1023
+		mul(builtin, DOUBLE_MUL_DOUBLE, DOUBLE, DOUBLE, USIZE_TO_DOUBLE);
1024
+		
1025
+		div(builtin, USIZE_DIV_USIZE, USIZE, USIZE);
1026
+		div(builtin, ULONG_DIV_ULONG, ULONG, ULONG, USIZE_TO_ULONG);
1027
+		div(builtin, FLOAT_DIV_FLOAT, FLOAT, FLOAT, USIZE_TO_FLOAT);
1028
+		div(builtin, DOUBLE_DIV_DOUBLE, DOUBLE, DOUBLE, USIZE_TO_DOUBLE);
1029
+		
1030
+		mod(builtin, USIZE_MOD_USIZE, USIZE, USIZE);
1031
+		
1032
+		or(builtin, USIZE_OR_USIZE, USIZE, USIZE);
1033
+		and(builtin, USIZE_AND_USIZE, USIZE, USIZE);
1034
+		xor(builtin, USIZE_XOR_USIZE, USIZE, USIZE);
1035
+		
1036
+		shl(builtin, USIZE_SHL, INT, USIZE);
1037
+		shr(builtin, USIZE_SHR, INT, USIZE);
1038
+		
1039
+		compare(builtin, USIZE_COMPARE, USIZE);
1040
+		compare(builtin, ULONG_COMPARE, ULONG, USIZE_TO_ULONG);
1041
+		compare(builtin, FLOAT_COMPARE, FLOAT, USIZE_TO_FLOAT);
1042
+		compare(builtin, DOUBLE_COMPARE, DOUBLE, USIZE_TO_DOUBLE);
1043
+		
1044
+		constant(builtin, USIZE_GET_MIN_VALUE, "MIN_VALUE", new ConstantUSizeExpression(BUILTIN, 0));
1045
+		constant(builtin, USIZE_GET_MAX_VALUE, "MAX_VALUE", new ConstantUSizeExpression(BUILTIN, -2L));
1046
+		constant(builtin, USIZE_BITS, "BITS", new ConstantUSizeExpression(BUILTIN, 32));
1047
+		
1048
+		castExplicit(builtin, USIZE_TO_BYTE, BYTE);
1049
+		castExplicit(builtin, USIZE_TO_SBYTE, SBYTE);
1050
+		castExplicit(builtin, USIZE_TO_SHORT, SHORT);
1051
+		castExplicit(builtin, USIZE_TO_USHORT, USHORT);
1052
+		castExplicit(builtin, USIZE_TO_INT, INT);
1053
+		castExplicit(builtin, USIZE_TO_UINT, UINT);
1054
+		castImplicit(builtin, USIZE_TO_LONG, LONG);
1055
+		castImplicit(builtin, USIZE_TO_ULONG, ULONG);
1056
+		castImplicit(builtin, USIZE_TO_FLOAT, FLOAT);
1057
+		castImplicit(builtin, USIZE_TO_DOUBLE, DOUBLE);
1058
+		castExplicit(builtin, USIZE_TO_CHAR, CHAR);
1059
+		castImplicit(builtin, USIZE_TO_STRING, STRING);
1060
+		
1061
+		staticMethod(builtin, USIZE_PARSE, "parse", USIZE, STRING);
1062
+		staticMethod(builtin, USIZE_PARSE_WITH_BASE, "parse", USIZE, STRING, INT);
1063
+		
1064
+		method(builtin, USIZE_COUNT_LOW_ZEROES, "countLowZeroes", INT);
1065
+		method(builtin, USIZE_COUNT_HIGH_ZEROES, "countHighZeroes", INT);
1066
+		method(builtin, USIZE_COUNT_LOW_ONES, "countLowOnes", INT);
1067
+		method(builtin, USIZE_COUNT_HIGH_ONES, "countHighOnes", INT);
1068
+		
1069
+		ITypeID optionalInt = registry.getOptional(INT);
1070
+		getter(builtin, USIZE_HIGHEST_ONE_BIT, "highestOneBit", optionalInt);
1071
+		getter(builtin, USIZE_LOWEST_ONE_BIT, "lowestOneBit", optionalInt);
1072
+		getter(builtin, USIZE_HIGHEST_ZERO_BIT, "highestZeroBit", optionalInt);
1073
+		getter(builtin, USIZE_LOWEST_ZERO_BIT, "lowestZeroBit", optionalInt);
1074
+		getter(builtin, USIZE_BIT_COUNT, "bitCount", INT);
1075
+		
1076
+		processType(builtin, USIZE);
1077
+	}
1078
+	
992
 	private void visitFloat() {
1079
 	private void visitFloat() {
993
 		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "float", Modifiers.EXPORT, null);
1080
 		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "float", Modifiers.EXPORT, null);
994
 		
1081
 		
1020
 		castExplicit(builtin, FLOAT_TO_USHORT, USHORT);
1107
 		castExplicit(builtin, FLOAT_TO_USHORT, USHORT);
1021
 		castExplicit(builtin, FLOAT_TO_INT, INT);
1108
 		castExplicit(builtin, FLOAT_TO_INT, INT);
1022
 		castExplicit(builtin, FLOAT_TO_UINT, UINT);
1109
 		castExplicit(builtin, FLOAT_TO_UINT, UINT);
1110
+		castExplicit(builtin, FLOAT_TO_LONG, LONG);
1023
 		castExplicit(builtin, FLOAT_TO_ULONG, ULONG);
1111
 		castExplicit(builtin, FLOAT_TO_ULONG, ULONG);
1024
-		castExplicit(builtin, FLOAT_TO_ULONG, ULONG);
1112
+		castExplicit(builtin, FLOAT_TO_USIZE, USIZE);
1025
 		castImplicit(builtin, FLOAT_TO_DOUBLE, DOUBLE);
1113
 		castImplicit(builtin, FLOAT_TO_DOUBLE, DOUBLE);
1026
 		castImplicit(builtin, FLOAT_TO_STRING, STRING);
1114
 		castImplicit(builtin, FLOAT_TO_STRING, STRING);
1027
 		
1115
 		
1028
 		staticMethod(builtin, FLOAT_PARSE, "parse", FLOAT, STRING);
1116
 		staticMethod(builtin, FLOAT_PARSE, "parse", FLOAT, STRING);
1029
-		staticMethod(builtin, FLOAT_FROM_BITS, "fromBits", FLOAT, INT);
1117
+		staticMethod(builtin, FLOAT_FROM_BITS, "fromBits", FLOAT, UINT);
1030
 		
1118
 		
1031
-		getter(builtin, FLOAT_BITS, "bits", INT);
1119
+		getter(builtin, FLOAT_BITS, "bits", UINT);
1032
 		
1120
 		
1033
 		processType(builtin, FLOAT);
1121
 		processType(builtin, FLOAT);
1034
 	}
1122
 	}
1057
 		castExplicit(builtin, DOUBLE_TO_UINT, UINT);
1145
 		castExplicit(builtin, DOUBLE_TO_UINT, UINT);
1058
 		castExplicit(builtin, DOUBLE_TO_ULONG, ULONG);
1146
 		castExplicit(builtin, DOUBLE_TO_ULONG, ULONG);
1059
 		castExplicit(builtin, DOUBLE_TO_ULONG, ULONG);
1147
 		castExplicit(builtin, DOUBLE_TO_ULONG, ULONG);
1148
+		castExplicit(builtin, DOUBLE_TO_USIZE, USIZE);
1060
 		castImplicit(builtin, DOUBLE_TO_FLOAT, FLOAT);
1149
 		castImplicit(builtin, DOUBLE_TO_FLOAT, FLOAT);
1061
 		castImplicit(builtin, DOUBLE_TO_STRING, STRING);
1150
 		castImplicit(builtin, DOUBLE_TO_STRING, STRING);
1062
 		
1151
 		
1063
 		staticMethod(builtin, DOUBLE_PARSE, "parse", DOUBLE, STRING);
1152
 		staticMethod(builtin, DOUBLE_PARSE, "parse", DOUBLE, STRING);
1064
-		staticMethod(builtin, DOUBLE_FROM_BITS, "fromBits", DOUBLE, LONG);
1153
+		staticMethod(builtin, DOUBLE_FROM_BITS, "fromBits", DOUBLE, ULONG);
1065
 		
1154
 		
1066
-		getter(builtin, DOUBLE_BITS, "bits", LONG);
1155
+		getter(builtin, DOUBLE_BITS, "bits", ULONG);
1067
 		
1156
 		
1068
 		processType(builtin, DOUBLE);
1157
 		processType(builtin, DOUBLE);
1069
 	}
1158
 	}
1084
 		castImplicit(builtin, CHAR_TO_UINT, UINT);
1173
 		castImplicit(builtin, CHAR_TO_UINT, UINT);
1085
 		castImplicit(builtin, CHAR_TO_LONG, LONG);
1174
 		castImplicit(builtin, CHAR_TO_LONG, LONG);
1086
 		castImplicit(builtin, CHAR_TO_ULONG, ULONG);
1175
 		castImplicit(builtin, CHAR_TO_ULONG, ULONG);
1176
+		castImplicit(builtin, CHAR_TO_USIZE, USIZE);
1087
 		castImplicit(builtin, CHAR_TO_STRING, STRING);
1177
 		castImplicit(builtin, CHAR_TO_STRING, STRING);
1088
 		
1178
 		
1089
 		getter(builtin, CHAR_GET_MIN_VALUE, "MIN_VALUE", CHAR);
1179
 		getter(builtin, CHAR_GET_MIN_VALUE, "MIN_VALUE", CHAR);
1102
 		constructor(builtin, STRING_CONSTRUCTOR_CHARACTERS, registry.getArray(CHAR, 1));
1192
 		constructor(builtin, STRING_CONSTRUCTOR_CHARACTERS, registry.getArray(CHAR, 1));
1103
 		
1193
 		
1104
 		add(builtin, STRING_ADD_STRING, STRING, STRING);
1194
 		add(builtin, STRING_ADD_STRING, STRING, STRING);
1105
-		indexGet(builtin, STRING_INDEXGET, INT, CHAR);
1106
-		indexGet(builtin, STRING_RANGEGET, registry.getRange(INT, INT), STRING);
1195
+		indexGet(builtin, STRING_INDEXGET, USIZE, CHAR);
1196
+		indexGet(builtin, STRING_RANGEGET, RangeTypeID.USIZE, STRING);
1107
 		compare(builtin, STRING_COMPARE, STRING);
1197
 		compare(builtin, STRING_COMPARE, STRING);
1108
 		
1198
 		
1109
-		getter(builtin, STRING_LENGTH, "length", INT);
1199
+		getter(builtin, STRING_LENGTH, "length", USIZE);
1110
 		getter(builtin, STRING_CHARACTERS, "characters", registry.getArray(CHAR, 1));
1200
 		getter(builtin, STRING_CHARACTERS, "characters", registry.getArray(CHAR, 1));
1111
 		getter(builtin, STRING_ISEMPTY, "isEmpty", BOOL);
1201
 		getter(builtin, STRING_ISEMPTY, "isEmpty", BOOL);
1112
 
1202
 

Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java → CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java View File

3
  * To change this template file, choose Tools | Templates
3
  * To change this template file, choose Tools | Templates
4
  * and open the template in the editor.
4
  * and open the template in the editor.
5
  */
5
  */
6
-package org.openzen.zenscript.constructor.module;
6
+package org.openzen.zenscript.compiler;
7
 
7
 
8
 import org.openzen.zenscript.compiler.SemanticModule;
8
 import org.openzen.zenscript.compiler.SemanticModule;
9
 import java.util.ArrayList;
9
 import java.util.ArrayList;
10
 import java.util.HashMap;
10
 import java.util.HashMap;
11
 import java.util.List;
11
 import java.util.List;
12
 import java.util.Map;
12
 import java.util.Map;
13
+import org.openzen.zencode.shared.CodePosition;
14
+import org.openzen.zencode.shared.CompileException;
15
+import org.openzen.zencode.shared.CompileExceptionCode;
13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
16
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14
 import org.openzen.zenscript.codemodel.annotations.NativeAnnotationDefinition;
17
 import org.openzen.zenscript.codemodel.annotations.NativeAnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.annotations.PreconditionAnnotationDefinition;
18
 import org.openzen.zenscript.codemodel.annotations.PreconditionAnnotationDefinition;
16
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
20
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
 import org.openzen.zenscript.compiler.CompilationUnit;
21
 import org.openzen.zenscript.compiler.CompilationUnit;
19
-import org.openzen.zenscript.constructor.ConstructorException;
20
 import org.openzen.zenscript.codemodel.type.ISymbol;
22
 import org.openzen.zenscript.codemodel.type.ISymbol;
21
 
23
 
22
 /**
24
 /**
45
 		
47
 		
46
 		for (Map.Entry<String, ISymbol> globalEntry : dependency.globals.entrySet()) {
48
 		for (Map.Entry<String, ISymbol> globalEntry : dependency.globals.entrySet()) {
47
 			if (globals.containsKey(globalEntry.getKey()))
49
 			if (globals.containsKey(globalEntry.getKey()))
48
-				throw new ConstructorException("Duplicate global: " + globalEntry.getKey());
50
+				throw new CompileException(CodePosition.META, CompileExceptionCode.DUPLICATE_GLOBAL, "Duplicate global: " + globalEntry.getKey());
49
 			
51
 			
50
 			globals.put(globalEntry.getKey(), globalEntry.getValue());
52
 			globals.put(globalEntry.getKey(), globalEntry.getValue());
51
 		}
53
 		}

+ 0
- 84
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java View File

10
 import java.io.FileInputStream;
10
 import java.io.FileInputStream;
11
 import java.io.IOException;
11
 import java.io.IOException;
12
 import java.util.ArrayList;
12
 import java.util.ArrayList;
13
-import java.util.Collections;
14
 import java.util.List;
13
 import java.util.List;
15
-import java.util.Map;
16
 import java.util.function.Consumer;
14
 import java.util.function.Consumer;
17
 import org.json.JSONArray;
15
 import org.json.JSONArray;
18
 import org.json.JSONObject;
16
 import org.json.JSONObject;
19
 import org.json.JSONTokener;
17
 import org.json.JSONTokener;
20
 import org.openzen.zencode.shared.CompileException;
18
 import org.openzen.zencode.shared.CompileException;
21
-import org.openzen.zenscript.codemodel.PackageDefinitions;
22
-import org.openzen.zenscript.codemodel.ScriptBlock;
23
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
19
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
24
-import org.openzen.zenscript.codemodel.context.ModuleTypeResolutionContext;
25
-import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
26
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
27
-import org.openzen.zenscript.constructor.module.ModuleSpace;
28
-import org.openzen.zenscript.compiler.SemanticModule;
29
-import org.openzen.zenscript.codemodel.type.ISymbol;
30
 import org.openzen.zenscript.parser.BracketExpressionParser;
20
 import org.openzen.zenscript.parser.BracketExpressionParser;
31
 import org.openzen.zenscript.parser.ParsedFile;
21
 import org.openzen.zenscript.parser.ParsedFile;
32
-import org.openzen.zenscript.parser.PrecompilationState;
33
 
22
 
34
 /**
23
 /**
35
  *
24
  *
86
 			}
75
 			}
87
 		}
76
 		}
88
 	}
77
 	}
89
-	
90
-	public static SemanticModule compileSyntaxToSemantic(
91
-			String name,
92
-			SemanticModule[] dependencies,
93
-			CompilingPackage pkg,
94
-			ParsedFile[] files,
95
-			ModuleSpace registry,
96
-			Consumer<CompileException> exceptionLogger) {
97
-		// We are considering all these files to be in the same package, so make
98
-		// a single PackageDefinition instance. If these files were in multiple
99
-		// packages, we'd need an instance for every package.
100
-		PackageDefinitions definitions = new PackageDefinitions();
101
-		for (ParsedFile file : files) {
102
-			// listDefinitions will merely register all definitions (classes,
103
-			// interfaces, functions ...) so they can later be available to
104
-			// the other files as well. It doesn't yet compile anything.
105
-			file.listDefinitions(definitions);
106
-		}
107
-		
108
-		ZSPackage rootPackage = registry.collectPackages();
109
-		List<ExpansionDefinition> expansions = registry.collectExpansions();
110
-		definitions.registerExpansionsTo(expansions);
111
-		
112
-		Map<String, ISymbol> globals = registry.collectGlobals();
113
-		boolean failed = false;
114
-		
115
-		ModuleTypeResolutionContext moduleContext = new ModuleTypeResolutionContext(
116
-				registry.compilationUnit.globalTypeRegistry,
117
-				registry.getAnnotations(),
118
-				rootPackage,
119
-				pkg,
120
-				globals);
121
-		
122
-		for (ParsedFile file : files) {
123
-			file.registerTypes(moduleContext, rootPackage, pkg);
124
-		}
125
-		
126
-		for (ParsedFile file : files) {
127
-			// compileMembers will register all definition members to their
128
-			// respective definitions, such as fields, constructors, methods...
129
-			// It doesn't yet compile the method contents.
130
-			try {
131
-				file.compileTypes(moduleContext, rootPackage, pkg);
132
-			} catch (CompileException ex) {
133
-				exceptionLogger.accept(ex);
134
-				failed = true;
135
-			}
136
-		}
137
-		
138
-		if (failed)
139
-			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
140
-		
141
-		// scripts will store all the script blocks encountered in the files
142
-		PrecompilationState precompiler = new PrecompilationState();
143
-		for (ParsedFile file : files) {
144
-			file.registerMembers(moduleContext, precompiler, rootPackage, pkg, expansions, globals);
145
-		}
146
-		
147
-		List<ScriptBlock> scripts = new ArrayList<>();
148
-		for (ParsedFile file : files) {
149
-			// compileCode will convert the parsed statements and expressions
150
-			// into semantic code. This semantic code can then be compiled
151
-			// to various targets.
152
-			try {
153
-				file.compileCode(moduleContext, precompiler, rootPackage, pkg, expansions, scripts, globals);
154
-			} catch (CompileException ex) {
155
-				exceptionLogger.accept(ex);
156
-				failed = true;
157
-			}
158
-		}
159
-		
160
-		return new SemanticModule(name, dependencies, SemanticModule.State.ASSEMBLED, rootPackage, pkg.getPackage(), definitions, scripts, registry.compilationUnit, expansions, registry.getAnnotations());
161
-	}
162
 }
78
 }

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

5
  */
5
  */
6
 package org.openzen.zenscript.constructor.module;
6
 package org.openzen.zenscript.constructor.module;
7
 
7
 
8
+import org.openzen.zenscript.compiler.ModuleSpace;
8
 import org.openzen.zenscript.compiler.SemanticModule;
9
 import org.openzen.zenscript.compiler.SemanticModule;
9
 import java.io.File;
10
 import java.io.File;
10
 import java.io.IOException;
11
 import java.io.IOException;
84
 			CompilingPackage compilingPackage = new CompilingPackage(pkg);
85
 			CompilingPackage compilingPackage = new CompilingPackage(pkg);
85
 			
86
 			
86
 			ParsedFile[] parsedFiles = module.parse(compilingPackage);
87
 			ParsedFile[] parsedFiles = module.parse(compilingPackage);
87
-			SemanticModule result = Module.compileSyntaxToSemantic(module.name, dependencies, compilingPackage, parsedFiles, space, exceptionLogger);
88
+			SemanticModule result = ParsedFile.compileSyntaxToSemantic(module.name, dependencies, compilingPackage, parsedFiles, space, exceptionLogger);
88
 			
89
 			
89
 			JSONObject globals = json.optJSONObject("globals");
90
 			JSONObject globals = json.optJSONObject("globals");
90
 			if (globals != null) {
91
 			if (globals != null) {

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java View File

138
 			if (compiledModules.contains(dependency.name))
138
 			if (compiledModules.contains(dependency.name))
139
 				continue;
139
 				continue;
140
 			compiledModules.add(dependency.name);
140
 			compiledModules.add(dependency.name);
141
-			System.out.println("== Compiling module " + dependency + " ==");
141
+			System.out.println("== Compiling module " + dependency.name + " ==");
142
 			
142
 			
143
 			if (compilingModules.contains(dependency.name)) {
143
 			if (compilingModules.contains(dependency.name)) {
144
 				StringBuilder message = new StringBuilder("Circular dependency:\n");
144
 				StringBuilder message = new StringBuilder("Circular dependency:\n");

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

887
 				case K_UINT:
887
 				case K_UINT:
888
 				case K_LONG:
888
 				case K_LONG:
889
 				case K_ULONG:
889
 				case K_ULONG:
890
+				case K_USIZE:
890
 				case K_FLOAT:
891
 				case K_FLOAT:
891
 				case K_DOUBLE:
892
 				case K_DOUBLE:
892
 				case K_CHAR:
893
 				case K_CHAR:

+ 9
- 12
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.javabytecode;
6
 package org.openzen.zenscript.javabytecode;
7
 
7
 
8
-import java.io.FileOutputStream;
9
-import java.io.IOException;
10
 import java.util.HashMap;
8
 import java.util.HashMap;
11
 import java.util.Map;
9
 import java.util.Map;
12
 import org.objectweb.asm.ClassWriter;
10
 import org.objectweb.asm.ClassWriter;
13
-import org.objectweb.asm.MethodVisitor;
14
 import org.objectweb.asm.Opcodes;
11
 import org.objectweb.asm.Opcodes;
15
 import org.objectweb.asm.Type;
12
 import org.objectweb.asm.Type;
16
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
89
 		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createRangeName(type);
86
 		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createRangeName(type);
90
 		ranges.put(signature, result);
87
 		ranges.put(signature, result);
91
 		
88
 		
92
-		createRangeClass(type.from, type.to, result.cls);
89
+		createRangeClass(type.baseType, result.cls);
93
 		return result;
90
 		return result;
94
 	}
91
 	}
95
 
92
 
110
         register(cls.internalName, ifaceWriter.toByteArray());
107
         register(cls.internalName, ifaceWriter.toByteArray());
111
     }
108
     }
112
 	
109
 	
113
-	private void createRangeClass(ITypeID from, ITypeID to, JavaClass cls) {
110
+	private void createRangeClass(ITypeID baseType, JavaClass cls) {
114
 		ClassWriter rangeWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
111
 		ClassWriter rangeWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
115
 		rangeWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, cls.internalName, null, "java/lang/Object", null);
112
 		rangeWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, cls.internalName, null, "java/lang/Object", null);
116
-		rangeWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "from", getDescriptor(from), null, null).visitEnd();
117
-		rangeWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "to", getDescriptor(to), null, null).visitEnd();
113
+		rangeWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "from", getDescriptor(baseType), null, null).visitEnd();
114
+		rangeWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "to", getDescriptor(baseType), null, null).visitEnd();
118
 		
115
 		
119
-		JavaMethod method = JavaMethod.getConstructor(cls, "(" + getDescriptor(from) + getDescriptor(to) + ")V", Opcodes.ACC_PUBLIC);
116
+		JavaMethod method = JavaMethod.getConstructor(cls, "(" + getDescriptor(baseType) + getDescriptor(baseType) + ")V", Opcodes.ACC_PUBLIC);
120
 		JavaWriter constructorWriter = new JavaWriter(rangeWriter, method, null, method.descriptor, null);
117
 		JavaWriter constructorWriter = new JavaWriter(rangeWriter, method, null, method.descriptor, null);
121
 		constructorWriter.loadObject(0);
118
 		constructorWriter.loadObject(0);
122
 		constructorWriter.invokeSpecial("java/lang/Object", "<init>", "()V");
119
 		constructorWriter.invokeSpecial("java/lang/Object", "<init>", "()V");
123
 		constructorWriter.loadObject(0);
120
 		constructorWriter.loadObject(0);
124
-		constructorWriter.load(getType(from), 1);
125
-		constructorWriter.putField(cls.internalName, "from", getDescriptor(from));
121
+		constructorWriter.load(getType(baseType), 1);
122
+		constructorWriter.putField(cls.internalName, "from", getDescriptor(baseType));
126
 		constructorWriter.loadObject(0);
123
 		constructorWriter.loadObject(0);
127
-		constructorWriter.load(getType(to), 2);
128
-		constructorWriter.putField(cls.internalName, "to", getDescriptor(from));
124
+		constructorWriter.load(getType(baseType), 2);
125
+		constructorWriter.putField(cls.internalName, "to", getDescriptor(baseType));
129
 		constructorWriter.ret();
126
 		constructorWriter.ret();
130
 		constructorWriter.end();
127
 		constructorWriter.end();
131
 		
128
 		

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

41
 				break;
41
 				break;
42
 			case INT:
42
 			case INT:
43
 			case UINT:
43
 			case UINT:
44
+			case USIZE:
44
 				method = INTEGER_VALUEOF;
45
 				method = INTEGER_VALUEOF;
45
 				break;
46
 				break;
46
 			case LONG:
47
 			case LONG:

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

402
 			case USHORT_NOT:
402
 			case USHORT_NOT:
403
 			case INT_NOT:
403
 			case INT_NOT:
404
 			case UINT_NOT:
404
 			case UINT_NOT:
405
+			case USIZE_NOT:
405
 				javaWriter.iNot();
406
 				javaWriter.iNot();
406
 				break;
407
 				break;
407
 			case SBYTE_NEG:
408
 			case SBYTE_NEG:
415
 			case USHORT_ADD_USHORT:
416
 			case USHORT_ADD_USHORT:
416
 			case INT_ADD_INT:
417
 			case INT_ADD_INT:
417
 			case UINT_ADD_UINT:
418
 			case UINT_ADD_UINT:
419
+			case USIZE_ADD_USIZE:
418
 				javaWriter.iAdd();
420
 				javaWriter.iAdd();
419
 				break;
421
 				break;
420
 			case BYTE_SUB_BYTE:
422
 			case BYTE_SUB_BYTE:
423
 			case USHORT_SUB_USHORT:
425
 			case USHORT_SUB_USHORT:
424
 			case INT_SUB_INT:
426
 			case INT_SUB_INT:
425
 			case UINT_SUB_UINT:
427
 			case UINT_SUB_UINT:
428
+			case USIZE_SUB_USIZE:
426
 				javaWriter.iSub();
429
 				javaWriter.iSub();
427
 				break;
430
 				break;
428
 			case BYTE_MUL_BYTE:
431
 			case BYTE_MUL_BYTE:
431
 			case USHORT_MUL_USHORT:
434
 			case USHORT_MUL_USHORT:
432
 			case INT_MUL_INT:
435
 			case INT_MUL_INT:
433
 			case UINT_MUL_UINT:
436
 			case UINT_MUL_UINT:
437
+			case USIZE_MUL_USIZE:
434
 				javaWriter.iMul();
438
 				javaWriter.iMul();
435
 				break;
439
 				break;
436
 			case SBYTE_DIV_SBYTE:
440
 			case SBYTE_DIV_SBYTE:
437
 			case SHORT_DIV_SHORT:
441
 			case SHORT_DIV_SHORT:
438
 			case INT_DIV_INT:
442
 			case INT_DIV_INT:
443
+			case USIZE_DIV_USIZE:
439
 				javaWriter.iDiv();
444
 				javaWriter.iDiv();
440
 				break;
445
 				break;
441
 			case SBYTE_MOD_SBYTE:
446
 			case SBYTE_MOD_SBYTE:
442
 			case SHORT_MOD_SHORT:
447
 			case SHORT_MOD_SHORT:
443
 			case INT_MOD_INT:
448
 			case INT_MOD_INT:
449
+			case USIZE_MOD_USIZE:
444
 				javaWriter.iRem();
450
 				javaWriter.iRem();
445
 				break;
451
 				break;
446
 			case BYTE_DIV_BYTE:
452
 			case BYTE_DIV_BYTE:
459
 			case USHORT_AND_USHORT:
465
 			case USHORT_AND_USHORT:
460
 			case INT_AND_INT:
466
 			case INT_AND_INT:
461
 			case UINT_AND_UINT:
467
 			case UINT_AND_UINT:
468
+			case USIZE_AND_USIZE:
462
 				javaWriter.iAnd();
469
 				javaWriter.iAnd();
463
 				break;
470
 				break;
464
 			case BYTE_OR_BYTE:
471
 			case BYTE_OR_BYTE:
467
 			case USHORT_OR_USHORT:
474
 			case USHORT_OR_USHORT:
468
 			case INT_OR_INT:
475
 			case INT_OR_INT:
469
 			case UINT_OR_UINT:
476
 			case UINT_OR_UINT:
477
+			case USIZE_OR_USIZE:
470
 				javaWriter.iOr();
478
 				javaWriter.iOr();
471
 				break;
479
 				break;
472
 			case BYTE_XOR_BYTE:
480
 			case BYTE_XOR_BYTE:
475
 			case USHORT_XOR_USHORT:
483
 			case USHORT_XOR_USHORT:
476
 			case INT_XOR_INT:
484
 			case INT_XOR_INT:
477
 			case UINT_XOR_UINT:
485
 			case UINT_XOR_UINT:
486
+			case USIZE_XOR_USIZE:
478
 				javaWriter.iXor();
487
 				javaWriter.iXor();
479
 				break;
488
 				break;
480
 			case INT_SHL:
489
 			case INT_SHL:
481
 			case UINT_SHL:
490
 			case UINT_SHL:
491
+			case USIZE_SHL:
482
 				javaWriter.iShl();
492
 				javaWriter.iShl();
483
 				break;
493
 				break;
484
 			case INT_SHR:
494
 			case INT_SHR:
486
 				break;
496
 				break;
487
 			case INT_USHR:
497
 			case INT_USHR:
488
 			case UINT_SHR:
498
 			case UINT_SHR:
499
+			case USIZE_SHR:
489
 				javaWriter.iUShr();
500
 				javaWriter.iUShr();
490
 				break;
501
 				break;
491
 			case INT_COUNT_LOW_ZEROES:
502
 			case INT_COUNT_LOW_ZEROES:
492
 			case UINT_COUNT_LOW_ZEROES:
503
 			case UINT_COUNT_LOW_ZEROES:
504
+			case USIZE_COUNT_LOW_ZEROES:
493
 				javaWriter.invokeStatic(INTEGER_NUMBER_OF_TRAILING_ZEROS);
505
 				javaWriter.invokeStatic(INTEGER_NUMBER_OF_TRAILING_ZEROS);
494
 				break;
506
 				break;
495
 			case INT_COUNT_HIGH_ZEROES:
507
 			case INT_COUNT_HIGH_ZEROES:
496
 			case UINT_COUNT_HIGH_ZEROES:
508
 			case UINT_COUNT_HIGH_ZEROES:
509
+			case USIZE_COUNT_HIGH_ZEROES:
497
 				javaWriter.invokeStatic(INTEGER_NUMBER_OF_LEADING_ZEROS);
510
 				javaWriter.invokeStatic(INTEGER_NUMBER_OF_LEADING_ZEROS);
498
 				break;
511
 				break;
499
 			case INT_COUNT_LOW_ONES:
512
 			case INT_COUNT_LOW_ONES:
500
 			case UINT_COUNT_LOW_ONES:
513
 			case UINT_COUNT_LOW_ONES:
514
+			case USIZE_COUNT_LOW_ONES:
501
 				javaWriter.iNot();
515
 				javaWriter.iNot();
502
 				javaWriter.invokeStatic(INTEGER_NUMBER_OF_TRAILING_ZEROS);
516
 				javaWriter.invokeStatic(INTEGER_NUMBER_OF_TRAILING_ZEROS);
503
 				break;
517
 				break;
504
 			case INT_COUNT_HIGH_ONES:
518
 			case INT_COUNT_HIGH_ONES:
505
 			case UINT_COUNT_HIGH_ONES:
519
 			case UINT_COUNT_HIGH_ONES:
520
+			case USIZE_COUNT_HIGH_ONES:
506
 				javaWriter.iNot();
521
 				javaWriter.iNot();
507
 				javaWriter.invokeStatic(INTEGER_NUMBER_OF_LEADING_ZEROS);
522
 				javaWriter.invokeStatic(INTEGER_NUMBER_OF_LEADING_ZEROS);
508
 				break;
523
 				break;
911
 				javaWriter.invokeStatic(INTEGER_PARSE_WITH_BASE);
926
 				javaWriter.invokeStatic(INTEGER_PARSE_WITH_BASE);
912
 				break;
927
 				break;
913
 			case UINT_PARSE:
928
 			case UINT_PARSE:
929
+			case USIZE_PARSE:
914
 				javaWriter.invokeStatic(INTEGER_PARSE_UNSIGNED);
930
 				javaWriter.invokeStatic(INTEGER_PARSE_UNSIGNED);
915
 				break;
931
 				break;
916
 			case UINT_PARSE_WITH_BASE:
932
 			case UINT_PARSE_WITH_BASE:
933
+			case USIZE_PARSE_WITH_BASE:
917
 				javaWriter.invokeStatic(INTEGER_PARSE_UNSIGNED_WITH_BASE);
934
 				javaWriter.invokeStatic(INTEGER_PARSE_UNSIGNED_WITH_BASE);
918
 				break;
935
 				break;
919
 			case LONG_PARSE:
936
 			case LONG_PARSE:
998
 			case BYTE_TO_USHORT:
1015
 			case BYTE_TO_USHORT:
999
 			case BYTE_TO_INT:
1016
 			case BYTE_TO_INT:
1000
 			case BYTE_TO_UINT:
1017
 			case BYTE_TO_UINT:
1018
+			case BYTE_TO_USIZE:
1001
 				javaWriter.constant(0xFF);
1019
 				javaWriter.constant(0xFF);
1002
 				javaWriter.iAnd();
1020
 				javaWriter.iAnd();
1003
 				break;
1021
 				break;
1031
 			case SBYTE_TO_USHORT:
1049
 			case SBYTE_TO_USHORT:
1032
 			case SBYTE_TO_INT:
1050
 			case SBYTE_TO_INT:
1033
 			case SBYTE_TO_UINT:
1051
 			case SBYTE_TO_UINT:
1052
+			case SBYTE_TO_USIZE:
1034
 				break;
1053
 				break;
1035
 			case SBYTE_TO_LONG:
1054
 			case SBYTE_TO_LONG:
1036
 			case SBYTE_TO_ULONG:
1055
 			case SBYTE_TO_ULONG:
1055
 			case SHORT_TO_USHORT:
1074
 			case SHORT_TO_USHORT:
1056
 			case SHORT_TO_INT:
1075
 			case SHORT_TO_INT:
1057
 			case SHORT_TO_UINT:
1076
 			case SHORT_TO_UINT:
1077
+			case SHORT_TO_USIZE:
1058
 				break;
1078
 				break;
1059
 			case SHORT_TO_LONG:
1079
 			case SHORT_TO_LONG:
1060
 			case SHORT_TO_ULONG:
1080
 			case SHORT_TO_ULONG:
1081
 				break;
1101
 				break;
1082
 			case USHORT_TO_INT:
1102
 			case USHORT_TO_INT:
1083
 			case USHORT_TO_UINT:
1103
 			case USHORT_TO_UINT:
1104
+			case USHORT_TO_USIZE:
1084
 				javaWriter.constant(0xFFFF);
1105
 				javaWriter.constant(0xFFFF);
1085
 				javaWriter.iAnd();
1106
 				javaWriter.iAnd();
1086
 				break;
1107
 				break;
1119
 			case INT_TO_USHORT:
1140
 			case INT_TO_USHORT:
1120
 				break;
1141
 				break;
1121
 			case INT_TO_UINT:
1142
 			case INT_TO_UINT:
1143
+			case INT_TO_USIZE:
1122
 				break;
1144
 				break;
1123
 			case INT_TO_LONG:
1145
 			case INT_TO_LONG:
1124
 			case INT_TO_ULONG:
1146
 			case INT_TO_ULONG:
1146
 				break;
1168
 				break;
1147
 			case UINT_TO_USHORT:
1169
 			case UINT_TO_USHORT:
1148
 			case UINT_TO_INT:
1170
 			case UINT_TO_INT:
1171
+			case UINT_TO_USIZE:
1149
 				break;
1172
 				break;
1150
 			case UINT_TO_LONG:
1173
 			case UINT_TO_LONG:
1151
 				javaWriter.i2l();
1174
 				javaWriter.i2l();
1187
 			case LONG_TO_USHORT:
1210
 			case LONG_TO_USHORT:
1188
 			case LONG_TO_INT:
1211
 			case LONG_TO_INT:
1189
 			case LONG_TO_UINT:
1212
 			case LONG_TO_UINT:
1213
+			case LONG_TO_USIZE:
1190
 				javaWriter.l2i();
1214
 				javaWriter.l2i();
1191
 				break;
1215
 				break;
1192
 			case LONG_TO_ULONG:
1216
 			case LONG_TO_ULONG:
1218
 			case ULONG_TO_USHORT:
1242
 			case ULONG_TO_USHORT:
1219
 			case ULONG_TO_INT:
1243
 			case ULONG_TO_INT:
1220
 			case ULONG_TO_UINT:
1244
 			case ULONG_TO_UINT:
1245
+			case ULONG_TO_USIZE:
1221
 				javaWriter.l2i();
1246
 				javaWriter.l2i();
1222
 				break;
1247
 				break;
1223
 			case ULONG_TO_LONG:
1248
 			case ULONG_TO_LONG:
1248
 			case FLOAT_TO_USHORT:
1273
 			case FLOAT_TO_USHORT:
1249
 			case FLOAT_TO_UINT:
1274
 			case FLOAT_TO_UINT:
1250
 			case FLOAT_TO_INT:
1275
 			case FLOAT_TO_INT:
1276
+			case FLOAT_TO_USIZE:
1251
 				javaWriter.f2i();
1277
 				javaWriter.f2i();
1252
 				break;
1278
 				break;
1253
 			case FLOAT_TO_LONG:
1279
 			case FLOAT_TO_LONG:
1274
 			case DOUBLE_TO_USHORT:
1300
 			case DOUBLE_TO_USHORT:
1275
 			case DOUBLE_TO_INT:
1301
 			case DOUBLE_TO_INT:
1276
 			case DOUBLE_TO_UINT:
1302
 			case DOUBLE_TO_UINT:
1303
+			case DOUBLE_TO_USIZE:
1277
 				javaWriter.d2i();
1304
 				javaWriter.d2i();
1278
 				break;
1305
 				break;
1279
 			case DOUBLE_TO_LONG:
1306
 			case DOUBLE_TO_LONG:
1295
 			case CHAR_TO_USHORT:
1322
 			case CHAR_TO_USHORT:
1296
 			case CHAR_TO_INT:
1323
 			case CHAR_TO_INT:
1297
 			case CHAR_TO_UINT:
1324
 			case CHAR_TO_UINT:
1325
+			case CHAR_TO_USIZE:
1298
 				break;
1326
 				break;
1299
 			case CHAR_TO_LONG:
1327
 			case CHAR_TO_LONG:
1300
 			case CHAR_TO_ULONG:
1328
 			case CHAR_TO_ULONG:
1415
 			case ULONG_GET_MAX_VALUE:
1443
 			case ULONG_GET_MAX_VALUE:
1416
 				javaWriter.constant(-1L);
1444
 				javaWriter.constant(-1L);
1417
 				break;
1445
 				break;
1446
+			case USIZE_GET_MIN_VALUE:
1447
+				javaWriter.iConst0();
1448
+				break;
1449
+			case USIZE_GET_MAX_VALUE:
1450
+				javaWriter.getStaticField(INTEGER_MAX_VALUE);
1451
+				break;
1452
+			case USIZE_BITS:
1453
+				javaWriter.constant(32);
1454
+				break;
1418
 			case FLOAT_GET_MIN_VALUE:
1455
 			case FLOAT_GET_MIN_VALUE:
1419
 				javaWriter.getStaticField(FLOAT_MIN_VALUE);
1456
 				javaWriter.getStaticField(FLOAT_MIN_VALUE);
1420
 				break;
1457
 				break;
1527
 		return null;
1564
 		return null;
1528
 	}
1565
 	}
1529
 
1566
 
1567
+	@Override
1568
+	public Void visitConstantUSize(ConstantUSizeExpression expression) {
1569
+		getJavaWriter().constant((int)expression.value);
1570
+		return null;
1571
+	}
1572
+
1530
     @Override
1573
     @Override
1531
     public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
1574
     public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
1532
 		javaWriter.loadObject(0);
1575
 		javaWriter.loadObject(0);
1747
 		switch (builtin) {
1790
 		switch (builtin) {
1748
 			case INT_HIGHEST_ONE_BIT:
1791
 			case INT_HIGHEST_ONE_BIT:
1749
 			case UINT_HIGHEST_ONE_BIT:
1792
 			case UINT_HIGHEST_ONE_BIT:
1793
+			case USIZE_HIGHEST_ONE_BIT:
1750
 				javaWriter.invokeStatic(INTEGER_HIGHEST_ONE_BIT);
1794
 				javaWriter.invokeStatic(INTEGER_HIGHEST_ONE_BIT);
1751
 				break;
1795
 				break;
1752
 			case INT_LOWEST_ONE_BIT:
1796
 			case INT_LOWEST_ONE_BIT:
1753
 			case UINT_LOWEST_ONE_BIT:
1797
 			case UINT_LOWEST_ONE_BIT:
1798
+			case USIZE_LOWEST_ONE_BIT:
1754
 				javaWriter.invokeStatic(INTEGER_LOWEST_ONE_BIT);
1799
 				javaWriter.invokeStatic(INTEGER_LOWEST_ONE_BIT);
1755
 				break;
1800
 				break;
1756
 			case INT_HIGHEST_ZERO_BIT:
1801
 			case INT_HIGHEST_ZERO_BIT:
1757
 			case UINT_HIGHEST_ZERO_BIT:
1802
 			case UINT_HIGHEST_ZERO_BIT:
1803
+			case USIZE_HIGHEST_ZERO_BIT:
1758
 				javaWriter.iNeg();
1804
 				javaWriter.iNeg();
1759
 				javaWriter.invokeStatic(INTEGER_HIGHEST_ONE_BIT);
1805
 				javaWriter.invokeStatic(INTEGER_HIGHEST_ONE_BIT);
1760
 				break;
1806
 				break;
1761
 			case INT_LOWEST_ZERO_BIT:
1807
 			case INT_LOWEST_ZERO_BIT:
1762
 			case UINT_LOWEST_ZERO_BIT:
1808
 			case UINT_LOWEST_ZERO_BIT:
1809
+			case USIZE_LOWEST_ZERO_BIT:
1763
 				javaWriter.iNeg();
1810
 				javaWriter.iNeg();
1764
 				javaWriter.invokeStatic(INTEGER_LOWEST_ONE_BIT);
1811
 				javaWriter.invokeStatic(INTEGER_LOWEST_ONE_BIT);
1765
 				break;
1812
 				break;
1766
 			case INT_BIT_COUNT:
1813
 			case INT_BIT_COUNT:
1767
 			case UINT_BIT_COUNT:
1814
 			case UINT_BIT_COUNT:
1815
+			case USIZE_BIT_COUNT:
1768
 				javaWriter.invokeStatic(INTEGER_BIT_COUNT);
1816
 				javaWriter.invokeStatic(INTEGER_BIT_COUNT);
1769
 				break;
1817
 				break;
1770
 			case LONG_HIGHEST_ONE_BIT:
1818
 			case LONG_HIGHEST_ONE_BIT:
1914
 			case RANGE_FROM: {
1962
 			case RANGE_FROM: {
1915
 				RangeTypeID type = (RangeTypeID)expression.target.type;
1963
 				RangeTypeID type = (RangeTypeID)expression.target.type;
1916
 				JavaClass cls = context.getTypeGenerator().synthesizeRange(type).cls;
1964
 				JavaClass cls = context.getTypeGenerator().synthesizeRange(type).cls;
1917
-				javaWriter.getField(cls.internalName, "from", context.getDescriptor(type.from));
1965
+				javaWriter.getField(cls.internalName, "from", context.getDescriptor(type.baseType));
1918
 				break;
1966
 				break;
1919
 			}
1967
 			}
1920
 			case RANGE_TO:
1968
 			case RANGE_TO:
1921
 				RangeTypeID type = (RangeTypeID)expression.target.type;
1969
 				RangeTypeID type = (RangeTypeID)expression.target.type;
1922
 				JavaClass cls = context.getTypeGenerator().synthesizeRange(type).cls;
1970
 				JavaClass cls = context.getTypeGenerator().synthesizeRange(type).cls;
1923
-				javaWriter.getField(cls.internalName, "to", context.getDescriptor(type.to));
1971
+				javaWriter.getField(cls.internalName, "to", context.getDescriptor(type.baseType));
1924
 				break;
1972
 				break;
1925
 		}
1973
 		}
1926
 
1974
 
2065
 
2113
 
2066
 	@Override
2114
 	@Override
2067
 	public Void visitNull(NullExpression expression) {
2115
 	public Void visitNull(NullExpression expression) {
2068
-		javaWriter.aConstNull();
2116
+		if (expression.type.withoutOptional() == BasicTypeID.USIZE)
2117
+			javaWriter.constant(-1); // special case: usize? null = -1
2118
+		else
2119
+			javaWriter.aConstNull();
2069
 		return null;
2120
 		return null;
2070
 	}
2121
 	}
2071
 
2122
 
2122
 		javaWriter.dup();
2173
 		javaWriter.dup();
2123
 		expression.from.accept(this);
2174
 		expression.from.accept(this);
2124
 		expression.to.accept(this);
2175
 		expression.to.accept(this);
2125
-		javaWriter.invokeSpecial(cls.cls.internalName, "<init>", "(" + context.getDescriptor(type.from) + context.getDescriptor(type.to) + ")V");
2176
+		javaWriter.invokeSpecial(cls.cls.internalName, "<init>", "(" + context.getDescriptor(type.baseType) + context.getDescriptor(type.baseType) + ")V");
2126
 
2177
 
2127
 		return null;
2178
 		return null;
2128
 	}
2179
 	}

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

6
 package org.openzen.zenscript.javabytecode.compiler;
6
 package org.openzen.zenscript.javabytecode.compiler;
7
 
7
 
8
 import org.objectweb.asm.Type;
8
 import org.objectweb.asm.Type;
9
-import org.openzen.zenscript.codemodel.expression.AndAndExpression;
10
-import org.openzen.zenscript.codemodel.expression.ArrayExpression;
11
-import org.openzen.zenscript.codemodel.expression.CompareExpression;
12
-import org.openzen.zenscript.codemodel.expression.CallExpression;
13
-import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14
-import org.openzen.zenscript.codemodel.expression.CapturedClosureExpression;
15
-import org.openzen.zenscript.codemodel.expression.CapturedDirectExpression;
16
-import org.openzen.zenscript.codemodel.expression.CapturedLocalVariableExpression;
17
-import org.openzen.zenscript.codemodel.expression.CapturedParameterExpression;
18
-import org.openzen.zenscript.codemodel.expression.CapturedThisExpression;
19
-import org.openzen.zenscript.codemodel.expression.CastExpression;
20
-import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
21
-import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
22
-import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
23
-import org.openzen.zenscript.codemodel.expression.ConstExpression;
24
-import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
25
-import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
26
-import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
27
-import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
28
-import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
29
-import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
30
-import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
31
-import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
32
-import org.openzen.zenscript.codemodel.expression.ConstantShortExpression;
33
-import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
34
-import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
35
-import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
36
-import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
37
-import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
38
-import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
39
-import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
40
-import org.openzen.zenscript.codemodel.expression.ExpressionVisitor;
41
-import org.openzen.zenscript.codemodel.expression.FunctionExpression;
42
-import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43
-import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44
-import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
-import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
46
-import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
47
-import org.openzen.zenscript.codemodel.expression.GetterExpression;
48
-import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
49
-import org.openzen.zenscript.codemodel.expression.GlobalExpression;
50
-import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
51
-import org.openzen.zenscript.codemodel.expression.IsExpression;
52
-import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
53
-import org.openzen.zenscript.codemodel.expression.MapExpression;
54
-import org.openzen.zenscript.codemodel.expression.MatchExpression;
55
-import org.openzen.zenscript.codemodel.expression.NewExpression;
56
-import org.openzen.zenscript.codemodel.expression.NullExpression;
57
-import org.openzen.zenscript.codemodel.expression.OrOrExpression;
58
-import org.openzen.zenscript.codemodel.expression.PanicExpression;
59
-import org.openzen.zenscript.codemodel.expression.PostCallExpression;
60
-import org.openzen.zenscript.codemodel.expression.RangeExpression;
61
-import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
62
-import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
63
-import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
64
-import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
65
-import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
66
-import org.openzen.zenscript.codemodel.expression.SetterExpression;
67
-import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
68
-import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
69
-import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
70
-import org.openzen.zenscript.codemodel.expression.ThisExpression;
71
-import org.openzen.zenscript.codemodel.expression.ThrowExpression;
72
-import org.openzen.zenscript.codemodel.expression.TryConvertExpression;
73
-import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpression;
74
-import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
75
-import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
76
-import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
9
+import org.openzen.zenscript.codemodel.expression.*;
77
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
10
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
78
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
11
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
79
 import org.openzen.zenscript.javashared.JavaParameterInfo;
12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
233
 		throw new UnsupportedOperationException("Invalid increment target");
166
 		throw new UnsupportedOperationException("Invalid increment target");
234
 	}
167
 	}
235
 
168
 
169
+	@Override
170
+	public Void visitConstantUSize(ConstantUSizeExpression expression) {
171
+		throw new UnsupportedOperationException("Invalid increment target");
172
+	}
173
+
236
 	@Override
174
 	@Override
237
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
175
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
238
 		throw new UnsupportedOperationException("Invalid increment target");
176
 		throw new UnsupportedOperationException("Invalid increment target");

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

6
 package org.openzen.zenscript.javabytecode.compiler;
6
 package org.openzen.zenscript.javabytecode.compiler;
7
 
7
 
8
 import org.objectweb.asm.Type;
8
 import org.objectweb.asm.Type;
9
-import org.openzen.zenscript.codemodel.expression.AndAndExpression;
10
-import org.openzen.zenscript.codemodel.expression.ArrayExpression;
11
-import org.openzen.zenscript.codemodel.expression.CompareExpression;
12
-import org.openzen.zenscript.codemodel.expression.CallExpression;
13
-import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14
-import org.openzen.zenscript.codemodel.expression.CapturedClosureExpression;
15
-import org.openzen.zenscript.codemodel.expression.CapturedDirectExpression;
16
-import org.openzen.zenscript.codemodel.expression.CapturedLocalVariableExpression;
17
-import org.openzen.zenscript.codemodel.expression.CapturedParameterExpression;
18
-import org.openzen.zenscript.codemodel.expression.CapturedThisExpression;
19
-import org.openzen.zenscript.codemodel.expression.CastExpression;
20
-import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
21
-import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
22
-import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
23
-import org.openzen.zenscript.codemodel.expression.ConstExpression;
24
-import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
25
-import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
26
-import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
27
-import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
28
-import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
29
-import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
30
-import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
31
-import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
32
-import org.openzen.zenscript.codemodel.expression.ConstantShortExpression;
33
-import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
34
-import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
35
-import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
36
-import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
37
-import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
38
-import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
39
-import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
40
-import org.openzen.zenscript.codemodel.expression.ExpressionVisitor;
41
-import org.openzen.zenscript.codemodel.expression.FunctionExpression;
42
-import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43
-import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44
-import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
-import org.openzen.zenscript.codemodel.expression.GetMatchingVariantField;
46
-import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
47
-import org.openzen.zenscript.codemodel.expression.GetterExpression;
48
-import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
49
-import org.openzen.zenscript.codemodel.expression.GlobalExpression;
50
-import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
51
-import org.openzen.zenscript.codemodel.expression.IsExpression;
52
-import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
53
-import org.openzen.zenscript.codemodel.expression.MapExpression;
54
-import org.openzen.zenscript.codemodel.expression.MatchExpression;
55
-import org.openzen.zenscript.codemodel.expression.NewExpression;
56
-import org.openzen.zenscript.codemodel.expression.NullExpression;
57
-import org.openzen.zenscript.codemodel.expression.OrOrExpression;
58
-import org.openzen.zenscript.codemodel.expression.PanicExpression;
59
-import org.openzen.zenscript.codemodel.expression.PostCallExpression;
60
-import org.openzen.zenscript.codemodel.expression.RangeExpression;
61
-import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
62
-import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
63
-import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
64
-import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
65
-import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
66
-import org.openzen.zenscript.codemodel.expression.SetterExpression;
67
-import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
68
-import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
69
-import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
70
-import org.openzen.zenscript.codemodel.expression.ThisExpression;
71
-import org.openzen.zenscript.codemodel.expression.ThrowExpression;
72
-import org.openzen.zenscript.codemodel.expression.TryConvertExpression;
73
-import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpression;
74
-import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
75
-import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
76
-import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
9
+import org.openzen.zenscript.codemodel.expression.*;
77
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
10
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
78
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
11
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
79
 import org.openzen.zenscript.javashared.JavaParameterInfo;
12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
233
 		throw new UnsupportedOperationException("Invalid increment target");
166
 		throw new UnsupportedOperationException("Invalid increment target");
234
 	}
167
 	}
235
 
168
 
169
+	@Override
170
+	public Void visitConstantUSize(ConstantUSizeExpression expression) {
171
+		throw new UnsupportedOperationException("Invalid increment target");
172
+	}
173
+
236
 	@Override
174
 	@Override
237
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
175
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
238
 		throw new UnsupportedOperationException("Invalid increment target");
176
 		throw new UnsupportedOperationException("Invalid increment target");

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

142
         statementVisitor.start();
142
         statementVisitor.start();
143
 		boolean returns = definition.statement.accept(statementVisitor);
143
 		boolean returns = definition.statement.accept(statementVisitor);
144
 		if (!returns) {
144
 		if (!returns) {
145
-			ITypeID type = definition.header.returnType;
145
+			ITypeID type = definition.header.getReturnType();
146
 			if (CompilerUtils.isPrimitive(type))
146
 			if (CompilerUtils.isPrimitive(type))
147
 				writer.iConst0();
147
 				writer.iConst0();
148
 			else if (type != BasicTypeID.VOID)
148
 			else if (type != BasicTypeID.VOID)

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

25
         for (FunctionParameter parameter : header.parameters) {
25
         for (FunctionParameter parameter : header.parameters) {
26
             signatureBuilder.append(getDescriptor(parameter.type));
26
             signatureBuilder.append(getDescriptor(parameter.type));
27
         }
27
         }
28
-        signatureBuilder.append(")").append(getDescriptor(header.returnType));
28
+        signatureBuilder.append(")").append(getDescriptor(header.getReturnType()));
29
         return signatureBuilder.toString();
29
         return signatureBuilder.toString();
30
     }
30
     }
31
 	
31
 	
42
 			descBuilder.append(getDescriptor(parameter.type));
42
 			descBuilder.append(getDescriptor(parameter.type));
43
         }
43
         }
44
         descBuilder.append(")");
44
         descBuilder.append(")");
45
-        descBuilder.append(getDescriptor(header.returnType));
45
+        descBuilder.append(getDescriptor(header.getReturnType()));
46
         return descBuilder.toString();
46
         return descBuilder.toString();
47
     }
47
     }
48
 }
48
 }

+ 3
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java View File

46
 			case UINT: return "UInt";
46
 			case UINT: return "UInt";
47
 			case LONG: return "Long";
47
 			case LONG: return "Long";
48
 			case ULONG: return "ULong";
48
 			case ULONG: return "ULong";
49
+			case USIZE: return "USize";
49
 			case FLOAT: return "Float";
50
 			case FLOAT: return "Float";
50
 			case DOUBLE: return "Double";
51
 			case DOUBLE: return "Double";
51
 			case CHAR: return "Char";
52
 			case CHAR: return "Char";
94
 		for (FunctionParameter parameter : function.header.parameters)
95
 		for (FunctionParameter parameter : function.header.parameters)
95
 			result.append(parameter.type.accept(this));
96
 			result.append(parameter.type.accept(this));
96
 		result.append("To");
97
 		result.append("To");
97
-		result.append(function.header.returnType.accept(this));
98
+		result.append(function.header.getReturnType().accept(this));
98
 		if (function.header.thrownType != null) {
99
 		if (function.header.thrownType != null) {
99
 			result.append("Throwing");
100
 			result.append("Throwing");
100
 			result.append(function.header.thrownType.accept(this));
101
 			result.append(function.header.thrownType.accept(this));
129
 	@Override
130
 	@Override
130
 	public String visitRange(RangeTypeID range) {
131
 	public String visitRange(RangeTypeID range) {
131
 		StringBuilder result = new StringBuilder();
132
 		StringBuilder result = new StringBuilder();
132
-		result.append(range.from.accept(this));
133
-		if (range.from != range.to)
134
-			result.append(range.to.accept(this));
133
+		result.append(range.baseType.accept(this));
135
 		result.append("Range");
134
 		result.append("Range");
136
 		return result.toString();
135
 		return result.toString();
137
 	}
136
 	}

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

33
 				case UINT: return "Ljava/lang/Integer;";
33
 				case UINT: return "Ljava/lang/Integer;";
34
 				case LONG: return "Ljava/lang/Long;";
34
 				case LONG: return "Ljava/lang/Long;";
35
 				case ULONG: return "Ljava/lang/Long;";
35
 				case ULONG: return "Ljava/lang/Long;";
36
+				case USIZE: return "I"; // special case: optional usize fits in an int where null = -1
36
 				case FLOAT: return "Ljava/lang/Float;";
37
 				case FLOAT: return "Ljava/lang/Float;";
37
 				case DOUBLE: return "Ljava/lang/Double;";
38
 				case DOUBLE: return "Ljava/lang/Double;";
38
 				case STRING: return "Ljava/lang/String;";
39
 				case STRING: return "Ljava/lang/String;";
52
 				case UINT: return "I";
53
 				case UINT: return "I";
53
 				case LONG: return "J";
54
 				case LONG: return "J";
54
 				case ULONG: return "J";
55
 				case ULONG: return "J";
56
+				case USIZE: return "I";
55
 				case FLOAT: return "F";
57
 				case FLOAT: return "F";
56
 				case DOUBLE: return "D";
58
 				case DOUBLE: return "D";
57
 				case STRING: return "Ljava/lang/String;";
59
 				case STRING: return "Ljava/lang/String;";
63
 
65
 
64
     @Override
66
     @Override
65
     public String visitArray(ArrayTypeID array) {
67
     public String visitArray(ArrayTypeID array) {
66
-		return "[" + array.elementType.accept(this);
68
+		if (array.elementType == BasicTypeID.BYTE)
69
+			return "[B"; // instead of int[], save memory, save compatibility
70
+		else if (array.elementType == BasicTypeID.USHORT)
71
+			return "[S"; // instead of int[], save memory
72
+		else
73
+			return "[" + array.elementType.accept(this);
67
     }
74
     }
68
 
75
 
69
     @Override
76
     @Override

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

33
 				case UINT: return "java/lang/Integer";
33
 				case UINT: return "java/lang/Integer";
34
 				case LONG: return "java/lang/Long";
34
 				case LONG: return "java/lang/Long";
35
 				case ULONG: return "java/lang/Long";
35
 				case ULONG: return "java/lang/Long";
36
+				case USIZE: return "java/lang/Integer";
36
 				case FLOAT: return "java/lang/Float";
37
 				case FLOAT: return "java/lang/Float";
37
 				case DOUBLE: return "java/lang/Double";
38
 				case DOUBLE: return "java/lang/Double";
38
 				case STRING: return "java/lang/String";
39
 				case STRING: return "java/lang/String";
52
 				case UINT: return "I";
53
 				case UINT: return "I";
53
 				case LONG: return "J";
54
 				case LONG: return "J";
54
 				case ULONG: return "J";
55
 				case ULONG: return "J";
56
+				case USIZE: return "I";
55
 				case FLOAT: return "F";
57
 				case FLOAT: return "F";
56
 				case DOUBLE: return "D";
58
 				case DOUBLE: return "D";
57
 				case STRING: return "java/lang/String";
59
 				case STRING: return "java/lang/String";

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

76
 		for (FunctionParameter parameter : function.header.parameters)
76
 		for (FunctionParameter parameter : function.header.parameters)
77
 			result.append(parameter.type.accept(this));
77
 			result.append(parameter.type.accept(this));
78
 		result.append("To");
78
 		result.append("To");
79
-		result.append(function.header.returnType.accept(this));
79
+		result.append(function.header.getReturnType().accept(this));
80
 		result.append("Function");
80
 		result.append("Function");
81
 		return result.toString();
81
 		return result.toString();
82
 	}
82
 	}
93
 
93
 
94
 	@Override
94
 	@Override
95
 	public String visitRange(RangeTypeID range) {
95
 	public String visitRange(RangeTypeID range) {
96
-		return range.from == range.to
97
-				? range.from.accept(this) + "Range"
98
-				: range.from.accept(this) + range.to.accept(this) + "Range";
96
+		return range.baseType.accept(this) + "Range";
99
 	}
97
 	}
100
 
98
 
101
 	@Override
99
 	@Override

+ 4
- 3
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java View File

30
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
30
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
31
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
31
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
32
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
32
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
33
+import org.openzen.zenscript.codemodel.type.member.BuiltinID;
33
 import org.openzen.zenscript.javashared.JavaTypeNameVisitor;
34
 import org.openzen.zenscript.javashared.JavaTypeNameVisitor;
34
 import org.openzen.zenscript.javashared.JavaClass;
35
 import org.openzen.zenscript.javashared.JavaClass;
35
 import org.openzen.zenscript.javashared.JavaField;
36
 import org.openzen.zenscript.javashared.JavaField;
299
 					true,
300
 					true,
300
 					context.getMethodDescriptor(header),
301
 					context.getMethodDescriptor(header),
301
 					JavaModifiers.getJavaModifiers(member.modifiers),
302
 					JavaModifiers.getJavaModifiers(member.modifiers),
302
-					header.returnType instanceof GenericTypeID);
303
+					header.getReturnType() instanceof GenericTypeID);
303
 		} else if (method == null) {
304
 		} else if (method == null) {
304
 			method = new JavaMethod(
305
 			method = new JavaMethod(
305
 					cls,
306
 					cls,
308
 					true,
309
 					true,
309
 					context.getMethodDescriptor(header),
310
 					context.getMethodDescriptor(header),
310
 					JavaModifiers.getJavaModifiers(member.modifiers),
311
 					JavaModifiers.getJavaModifiers(member.modifiers),
311
-					header.returnType instanceof GenericTypeID);
312
+					header.getReturnType() instanceof GenericTypeID);
312
 		}
313
 		}
313
 		
314
 		
314
-		if (method.compile) {
315
+		if (method.compile && member.getBuiltin() != BuiltinID.CLASS_DEFAULT_CONSTRUCTOR) {
315
 			if (DEBUG_EMPTY && cls.empty)
316
 			if (DEBUG_EMPTY && cls.empty)
316
 				System.out.println("Class " + cls.fullName + " not empty because of " + member.describe());
317
 				System.out.println("Class " + cls.fullName + " not empty because of " + member.describe());
317
 			
318
 			

+ 1
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java View File

44
 			return;
44
 			return;
45
 			
45
 			
46
 		HighLevelDefinition definition = ((DefinitionTypeID)type).definition;
46
 		HighLevelDefinition definition = ((DefinitionTypeID)type).definition;
47
+		System.out.println("Preparing " + definition.name);
47
 		definition.accept(this);
48
 		definition.accept(this);
48
 	}
49
 	}
49
 	
50
 	

+ 20
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java View File

55
 			cls.addInstanceMethod("appendUInt", "append", "(I)Ljava/lang/StringBuilder;");
55
 			cls.addInstanceMethod("appendUInt", "append", "(I)Ljava/lang/StringBuilder;");
56
 			cls.addInstanceMethod("appendLong", "append", "(J)Ljava/lang/StringBuilder;");
56
 			cls.addInstanceMethod("appendLong", "append", "(J)Ljava/lang/StringBuilder;");
57
 			cls.addInstanceMethod("appendULong", "append", "(J)Ljava/lang/StringBuilder;");
57
 			cls.addInstanceMethod("appendULong", "append", "(J)Ljava/lang/StringBuilder;");
58
+			cls.addInstanceMethod("appendUSize", "append", "(I)Ljava/lang/StringBuilder;");
58
 			cls.addInstanceMethod("appendFloat", "append", "(F)Ljava/lang/StringBuilder;");
59
 			cls.addInstanceMethod("appendFloat", "append", "(F)Ljava/lang/StringBuilder;");
59
 			cls.addInstanceMethod("appendDouble", "append", "(D)Ljava/lang/StringBuilder;");
60
 			cls.addInstanceMethod("appendDouble", "append", "(D)Ljava/lang/StringBuilder;");
60
 			cls.addInstanceMethod("appendChar", "append", "(C)Ljava/lang/StringBuilder;");
61
 			cls.addInstanceMethod("appendChar", "append", "(C)Ljava/lang/StringBuilder;");
110
 			cls.addMethod("max", JavaMethod.getNativeStatic(math, "max", "(II)I"));
111
 			cls.addMethod("max", JavaMethod.getNativeStatic(math, "max", "(II)I"));
111
 			cls.addMethod("toHexString", JavaMethod.getNativeExpansion(integer, "toHexString", "(I)Ljava/lang/String;"));
112
 			cls.addMethod("toHexString", JavaMethod.getNativeExpansion(integer, "toHexString", "(I)Ljava/lang/String;"));
112
 			nativeClasses.put("stdlib::Integer", cls);
113
 			nativeClasses.put("stdlib::Integer", cls);
114
+			nativeClasses.put("stdlib::USize", cls);
113
 		}
115
 		}
114
 		
116
 		
115
 		{
117
 		{
188
 			cls.addInstanceMethod("readSlice", "read", "([CII)I");
190
 			cls.addInstanceMethod("readSlice", "read", "([CII)I");
189
 			nativeClasses.put("io::StringReader", cls);
191
 			nativeClasses.put("io::StringReader", cls);
190
 		}
192
 		}
193
+		
194
+		{
195
+			JavaNativeClass cls = new JavaNativeClass(new JavaClass("java.io", "InputStream", JavaClass.Kind.INTERFACE), true);
196
+			cls.addInstanceMethod("destructor", "close", "()V");
197
+			cls.addInstanceMethod("read", "read", "()I");
198
+			cls.addInstanceMethod("readArray", "read", "([B)I");
199
+			cls.addInstanceMethod("readSlice", "read", "([BII)I");
200
+			nativeClasses.put("io::InputStream", cls);
201
+		}
202
+		
203
+		{
204
+			JavaNativeClass cls = new JavaNativeClass(new JavaClass("java.io", "OutputStream", JavaClass.Kind.INTERFACE), true);
205
+			cls.addInstanceMethod("destructor", "close", "()V");
206
+			cls.addInstanceMethod("write", "write", "()I");
207
+			cls.addInstanceMethod("writeArray", "write", "([B)V");
208
+			cls.addInstanceMethod("writeSlice", "write", "([BII)V");
209
+			nativeClasses.put("io::OutputStream", cls);
210
+		}
191
 	}
211
 	}
192
 	
212
 	
193
 	private final String filename;
213
 	private final String filename;

+ 1
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java View File

161
 		if (nativeTag != null && nativeClass != null)
161
 		if (nativeTag != null && nativeClass != null)
162
 			method = nativeClass.getMethod(nativeTag.value);
162
 			method = nativeClass.getMethod(nativeTag.value);
163
 		if (method == null)
163
 		if (method == null)
164
-			method = new JavaMethod(cls, getKind(member), name, true, context.getMethodDescriptor(header), JavaModifiers.getJavaModifiers(member.modifiers), header.returnType instanceof GenericTypeID); 
164
+			method = new JavaMethod(cls, getKind(member), name, true, context.getMethodDescriptor(header), JavaModifiers.getJavaModifiers(member.modifiers), header.getReturnType() instanceof GenericTypeID); 
165
 		
165
 		
166
 		if (method.compile) {
166
 		if (method.compile) {
167
 			if (DEBUG_EMPTY && cls.empty)
167
 			if (DEBUG_EMPTY && cls.empty)

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

33
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
33
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
34
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
34
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
35
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
35
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
36
+import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
36
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
37
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
37
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
38
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
38
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
39
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
223
 		return false;
224
 		return false;
224
 	}
225
 	}
225
 
226
 
227
+	@Override
228
+	public Boolean visitConstantUSize(ConstantUSizeExpression expression) {
229
+		return false;
230
+	}
231
+
226
 	@Override
232
 	@Override
227
 	public Boolean visitConstructorThisCall(ConstructorThisCallExpression expression) {
233
 	public Boolean visitConstructorThisCall(ConstructorThisCallExpression expression) {
228
 		return true;
234
 		return true;

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

7
 
7
 
8
 import org.openzen.zenscript.codemodel.FunctionHeader;
8
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionParameter;
9
 import org.openzen.zenscript.codemodel.FunctionParameter;
10
-import org.openzen.zenscript.codemodel.Modifiers;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
10
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
12
 import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
39
 			
38
 			
40
 			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
39
 			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
41
 				result.append(" as ");
40
 				result.append(" as ");
42
-				result.append(header.returnType.accept(typeFormatter));
41
+				result.append(header.getReturnType().accept(typeFormatter));
43
 			}
42
 			}
44
 			
43
 			
45
 			parameterIndex++;
44
 			parameterIndex++;
46
 		}
45
 		}
47
 		result.append(")");
46
 		result.append(")");
48
-		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.UNDETERMINED) {
47
+		if (!settings.showAnyInFunctionHeaders || header.getReturnType() != BasicTypeID.UNDETERMINED) {
49
 			result.append(" as ");
48
 			result.append(" as ");
50
-			result.append(header.returnType.accept(typeFormatter));
49
+			result.append(header.getReturnType().accept(typeFormatter));
51
 		}
50
 		}
52
 	}
51
 	}
53
 	
52
 	

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

190
 				output.append(",\n");
190
 				output.append(",\n");
191
 			}
191
 			}
192
 			output.append("\t").append(constant.name);
192
 			output.append("\t").append(constant.name);
193
-			if (constant.constructor != null) {
194
-				
193
+			if (constant.constructor != null && constant.constructor.arguments.arguments.length > 0) {
195
 				output.append("(");
194
 				output.append("(");
196
 				boolean first = true;
195
 				boolean first = true;
197
 				for (Expression argument : constant.constructor.arguments.arguments) {
196
 				for (Expression argument : constant.constructor.arguments.arguments) {

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

71
 		else
71
 		else
72
 			JavaSourceUtils.formatTypeParameters(scope.typeVisitor, output, expansionTypeParameters, header.typeParameters);
72
 			JavaSourceUtils.formatTypeParameters(scope.typeVisitor, output, expansionTypeParameters, header.typeParameters);
73
 		
73
 		
74
-		output.append(header.returnType.accept(scope.typeVisitor));
74
+		output.append(header.getReturnType().accept(scope.typeVisitor));
75
 		output.append(" ");
75
 		output.append(" ");
76
 		output.append(method.name);
76
 		output.append(method.name);
77
 		formatParameters(member.isStatic(), expansionTypeParameters, header);
77
 		formatParameters(member.isStatic(), expansionTypeParameters, header);

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

93
 		
93
 		
94
 		modifiers(member.modifiers);
94
 		modifiers(member.modifiers);
95
 		JavaSourceUtils.formatTypeParameters(scope.typeVisitor, output, header.typeParameters, true);
95
 		JavaSourceUtils.formatTypeParameters(scope.typeVisitor, output, header.typeParameters, true);
96
-		output.append(header.returnType.accept(scope.typeVisitor));
96
+		output.append(header.getReturnType().accept(scope.typeVisitor));
97
 		output.append(" ");
97
 		output.append(" ");
98
 		output.append(method.name);
98
 		output.append(method.name);
99
 		formatParameters(member.isStatic(), header);
99
 		formatParameters(member.isStatic(), header);

+ 58
- 6
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java View File

40
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
40
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
41
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
41
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
42
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
42
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
43
+import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
43
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
44
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
44
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
45
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
45
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
46
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
95
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
96
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
96
 import org.openzen.zenscript.javashared.JavaClass;
97
 import org.openzen.zenscript.javashared.JavaClass;
97
 import org.openzen.zenscript.javashared.JavaField;
98
 import org.openzen.zenscript.javashared.JavaField;
98
-import org.openzen.zenscript.javashared.JavaNativeTranslation;
99
 import org.openzen.zenscript.javashared.JavaNativeTranslator;
99
 import org.openzen.zenscript.javashared.JavaNativeTranslator;
100
 import org.openzen.zenscript.javashared.JavaMethod;
100
 import org.openzen.zenscript.javashared.JavaMethod;
101
 import org.openzen.zenscript.javashared.JavaVariantOption;
101
 import org.openzen.zenscript.javashared.JavaVariantOption;
362
 		return new ExpressionString("(short)" + Integer.toString(expression.value), JavaOperator.CAST);
362
 		return new ExpressionString("(short)" + Integer.toString(expression.value), JavaOperator.CAST);
363
 	}
363
 	}
364
 
364
 
365
+	@Override
366
+	public ExpressionString visitConstantUSize(ConstantUSizeExpression expression) {
367
+		return new ExpressionString(Integer.toString((int)expression.value), JavaOperator.CAST);
368
+	}
369
+
365
 	@Override
370
 	@Override
366
 	public ExpressionString visitConstructorThisCall(ConstructorThisCallExpression expression) {
371
 	public ExpressionString visitConstructorThisCall(ConstructorThisCallExpression expression) {
367
 		StringBuilder result = new StringBuilder();
372
 		StringBuilder result = new StringBuilder();
539
 
544
 
540
 	@Override
545
 	@Override
541
 	public ExpressionString visitNull(NullExpression expression) {
546
 	public ExpressionString visitNull(NullExpression expression) {
547
+		if (expression.type.withoutOptional() == BasicTypeID.USIZE)
548
+			return new ExpressionString("-1", JavaOperator.PRIMARY); // usize? null = -1
549
+		
542
 		return new ExpressionString("null", JavaOperator.PRIMARY);
550
 		return new ExpressionString("null", JavaOperator.PRIMARY);
543
 	}
551
 	}
544
 
552
 
1044
 			case ULONG_COUNT_HIGH_ZEROES: return callAsStatic("Long.numberOfLeadingZeros", call);
1052
 			case ULONG_COUNT_HIGH_ZEROES: return callAsStatic("Long.numberOfLeadingZeros", call);
1045
 			case ULONG_COUNT_LOW_ONES: return new ExpressionString("Long.numberOfTrailingZeros(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1053
 			case ULONG_COUNT_LOW_ONES: return new ExpressionString("Long.numberOfTrailingZeros(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1046
 			case ULONG_COUNT_HIGH_ONES: return new ExpressionString("Long.numberOfLeadingZeros(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1054
 			case ULONG_COUNT_HIGH_ONES: return new ExpressionString("Long.numberOfLeadingZeros(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1055
+			case USIZE_NOT: return unaryPrefix(call, JavaOperator.INVERT);
1056
+			case USIZE_ADD_USIZE: return binary(call, JavaOperator.ADD);
1057
+			case USIZE_SUB_USIZE: return binary(call, JavaOperator.SUB);
1058
+			case USIZE_MUL_USIZE: return binary(call, JavaOperator.MUL);
1059
+			case USIZE_DIV_USIZE: return binary(call, JavaOperator.DIV);
1060
+			case USIZE_MOD_USIZE: return binary(call, JavaOperator.MOD);
1061
+			case USIZE_AND_USIZE: return binary(call, JavaOperator.AND);
1062
+			case USIZE_OR_USIZE: return binary(call, JavaOperator.OR);
1063
+			case USIZE_XOR_USIZE: return binary(call, JavaOperator.XOR);
1064
+			case USIZE_SHL: return binary(call, JavaOperator.SHL);
1065
+			case USIZE_SHR: return binary(call, JavaOperator.USHR);
1066
+			case USIZE_COUNT_LOW_ZEROES: return callAsStatic("Integer.numberOfTrailingZeros", call);
1067
+			case USIZE_COUNT_HIGH_ZEROES: return callAsStatic("Integer.numberOfLeadingZeros", call);
1068
+			case USIZE_COUNT_LOW_ONES: return new ExpressionString("Integer.numberOfTrailingZeros(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1069
+			case USIZE_COUNT_HIGH_ONES: return new ExpressionString("Integer.numberOfLeadingZeros(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1047
 			case FLOAT_NEG: return unaryPrefix(call, JavaOperator.NEG);
1070
 			case FLOAT_NEG: return unaryPrefix(call, JavaOperator.NEG);
1048
 			case FLOAT_ADD_FLOAT: return binary(call, JavaOperator.ADD);
1071
 			case FLOAT_ADD_FLOAT: return binary(call, JavaOperator.ADD);
1049
 			case FLOAT_SUB_FLOAT: return binary(call, JavaOperator.SUB);
1072
 			case FLOAT_SUB_FLOAT: return binary(call, JavaOperator.SUB);
1148
 			case FUNCTION_NOTSAME: return binary(call, JavaOperator.NOTEQUALS);
1171
 			case FUNCTION_NOTSAME: return binary(call, JavaOperator.NOTEQUALS);
1149
 			case OBJECT_SAME: return binary(call, JavaOperator.EQUALS);
1172
 			case OBJECT_SAME: return binary(call, JavaOperator.EQUALS);
1150
 			case OBJECT_NOTSAME: return binary(call, JavaOperator.NOTEQUALS);
1173
 			case OBJECT_NOTSAME: return binary(call, JavaOperator.NOTEQUALS);
1151
-			case OPTIONAL_IS_NULL: return call.target.accept(this).unaryPostfix(JavaOperator.EQUALS, " == null");
1152
-			case OPTIONAL_IS_NOT_NULL: return call.target.accept(this).unaryPostfix(JavaOperator.NOTEQUALS, " != null");
1174
+			case OPTIONAL_IS_NULL: return call.target.type.withoutOptional() == BasicTypeID.USIZE
1175
+					? call.target.accept(this).unaryPostfix(JavaOperator.NOTEQUALS, " < 0")
1176
+					: call.target.accept(this).unaryPostfix(JavaOperator.EQUALS, " == null");
1177
+			case OPTIONAL_IS_NOT_NULL: return call.target.type.withoutOptional() == BasicTypeID.USIZE
1178
+					? call.target.accept(this).unaryPostfix(JavaOperator.NOTEQUALS, " >= 0")
1179
+					: call.target.accept(this).unaryPostfix(JavaOperator.NOTEQUALS, " != null");
1153
 			case AUTOOP_NOTEQUALS:
1180
 			case AUTOOP_NOTEQUALS:
1154
 				throw new UnsupportedOperationException("Not yet supported!");
1181
 				throw new UnsupportedOperationException("Not yet supported!");
1155
 		}
1182
 		}
1168
 			case SHORT_PARSE_WITH_BASE: return callStatic("Short.parseShort", call);
1195
 			case SHORT_PARSE_WITH_BASE: return callStatic("Short.parseShort", call);
1169
 			case USHORT_PARSE: return callStatic("Integer.parseShort", call);
1196
 			case USHORT_PARSE: return callStatic("Integer.parseShort", call);
1170
 			case USHORT_PARSE_WITH_BASE: return callStatic("Integer.parseShort", call);
1197
 			case USHORT_PARSE_WITH_BASE: return callStatic("Integer.parseShort", call);
1171
-			case INT_PARSE: return callStatic("Integer.parseInt", call);
1172
-			case INT_PARSE_WITH_BASE: return callStatic("Integer.parseInt", call);
1198
+			case INT_PARSE:
1199
+			case USIZE_PARSE:
1200
+				return callStatic("Integer.parseInt", call);
1201
+			case INT_PARSE_WITH_BASE:
1202
+			case USIZE_PARSE_WITH_BASE:
1203
+				return callStatic("Integer.parseInt", call);
1173
 			case UINT_PARSE: return callStatic("Integer.parseUnsignedInt", call);
1204
 			case UINT_PARSE: return callStatic("Integer.parseUnsignedInt", call);
1174
 			case UINT_PARSE_WITH_BASE: return callStatic("Integer.parseUnsignedInt", call);
1205
 			case UINT_PARSE_WITH_BASE: return callStatic("Integer.parseUnsignedInt", call);
1175
 			case LONG_PARSE: return callStatic("Long.parseLong", call);
1206
 			case LONG_PARSE: return callStatic("Long.parseLong", call);
1197
 					call.left.accept(this).unaryPostfix(JavaOperator.AND_FFFF),
1228
 					call.left.accept(this).unaryPostfix(JavaOperator.AND_FFFF),
1198
 					call.right.accept(this).unaryPostfix(JavaOperator.AND_FFFF),
1229
 					call.right.accept(this).unaryPostfix(JavaOperator.AND_FFFF),
1199
 					call.comparison);
1230
 					call.comparison);
1200
-			case INT_COMPARE: return compare(call.left, call.right, call.comparison);
1231
+			case INT_COMPARE:
1232
+			case USIZE_COMPARE:
1233
+				return compare(call.left, call.right, call.comparison);
1201
 			case UINT_COMPARE: return compare(callAsStatic("Integer.compareUnsigned", call.left, call.right), call.comparison);
1234
 			case UINT_COMPARE: return compare(callAsStatic("Integer.compareUnsigned", call.left, call.right), call.comparison);
1202
 			case LONG_COMPARE: return compare(call.left, call.right, call.comparison);
1235
 			case LONG_COMPARE: return compare(call.left, call.right, call.comparison);
1203
 			case ULONG_COMPARE: return compare(callAsStatic("Long.compareUnsigned", call.left, call.right), call.comparison);
1236
 			case ULONG_COMPARE: return compare(callAsStatic("Long.compareUnsigned", call.left, call.right), call.comparison);
1221
 		switch (builtin) {
1254
 		switch (builtin) {
1222
 			case INT_HIGHEST_ONE_BIT:
1255
 			case INT_HIGHEST_ONE_BIT:
1223
 			case UINT_HIGHEST_ONE_BIT:
1256
 			case UINT_HIGHEST_ONE_BIT:
1257
+			case USIZE_HIGHEST_ONE_BIT:
1224
 				return callAsStatic("Integer.highestOneBit", call);
1258
 				return callAsStatic("Integer.highestOneBit", call);
1225
 			case INT_LOWEST_ONE_BIT:
1259
 			case INT_LOWEST_ONE_BIT:
1226
 			case UINT_LOWEST_ONE_BIT:
1260
 			case UINT_LOWEST_ONE_BIT:
1261
+			case USIZE_LOWEST_ONE_BIT:
1227
 				return callAsStatic("Integer.lowestOneBit", call);
1262
 				return callAsStatic("Integer.lowestOneBit", call);
1228
 			case INT_HIGHEST_ZERO_BIT:
1263
 			case INT_HIGHEST_ZERO_BIT:
1229
 			case UINT_HIGHEST_ZERO_BIT:
1264
 			case UINT_HIGHEST_ZERO_BIT:
1265
+			case USIZE_HIGHEST_ZERO_BIT:
1230
 				return new ExpressionString("Integer.highestOneBit(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1266
 				return new ExpressionString("Integer.highestOneBit(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1231
 			case INT_LOWEST_ZERO_BIT:
1267
 			case INT_LOWEST_ZERO_BIT:
1232
 			case UINT_LOWEST_ZERO_BIT:
1268
 			case UINT_LOWEST_ZERO_BIT:
1269
+			case USIZE_LOWEST_ZERO_BIT:
1233
 				return new ExpressionString("Integer.lowestOneBit(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1270
 				return new ExpressionString("Integer.lowestOneBit(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1234
 			case INT_BIT_COUNT:
1271
 			case INT_BIT_COUNT:
1235
 			case UINT_BIT_COUNT:
1272
 			case UINT_BIT_COUNT:
1273
+			case USIZE_BIT_COUNT:
1236
 				return callAsStatic("Integer.bitCount", call);
1274
 				return callAsStatic("Integer.bitCount", call);
1237
 			case LONG_HIGHEST_ONE_BIT:
1275
 			case LONG_HIGHEST_ONE_BIT:
1238
 			case ULONG_HIGHEST_ONE_BIT:
1276
 			case ULONG_HIGHEST_ONE_BIT:
1321
 			case LONG_GET_MAX_VALUE: return new ExpressionString("Long.MAX_VALUE", JavaOperator.MEMBER);
1359
 			case LONG_GET_MAX_VALUE: return new ExpressionString("Long.MAX_VALUE", JavaOperator.MEMBER);
1322
 			case ULONG_GET_MIN_VALUE: return new ExpressionString("0", JavaOperator.PRIMARY);
1360
 			case ULONG_GET_MIN_VALUE: return new ExpressionString("0", JavaOperator.PRIMARY);
1323
 			case ULONG_GET_MAX_VALUE: return new ExpressionString("-1", JavaOperator.PRIMARY);
1361
 			case ULONG_GET_MAX_VALUE: return new ExpressionString("-1", JavaOperator.PRIMARY);
1362
+			case USIZE_GET_MIN_VALUE: return new ExpressionString("0", JavaOperator.PRIMARY);
1363
+			case USIZE_GET_MAX_VALUE: return new ExpressionString("Integer.MAX_VALUE", JavaOperator.MEMBER);
1364
+			case USIZE_BITS: return new ExpressionString("32", JavaOperator.PRIMARY);
1324
 			case FLOAT_GET_MIN_VALUE: return new ExpressionString("Float.MIN_VALUE", JavaOperator.MEMBER);
1365
 			case FLOAT_GET_MIN_VALUE: return new ExpressionString("Float.MIN_VALUE", JavaOperator.MEMBER);
1325
 			case FLOAT_GET_MAX_VALUE: return new ExpressionString("Float.MAX_VALUE", JavaOperator.MEMBER);
1366
 			case FLOAT_GET_MAX_VALUE: return new ExpressionString("Float.MAX_VALUE", JavaOperator.MEMBER);
1326
 			case DOUBLE_GET_MIN_VALUE: return new ExpressionString("Double.MIN_VALUE", JavaOperator.MEMBER);
1367
 			case DOUBLE_GET_MIN_VALUE: return new ExpressionString("Double.MIN_VALUE", JavaOperator.MEMBER);
1342
 			case BYTE_TO_USHORT: return castPostfix(cast, JavaOperator.AND_FF);
1383
 			case BYTE_TO_USHORT: return castPostfix(cast, JavaOperator.AND_FF);
1343
 			case BYTE_TO_INT: return castPostfix(cast, JavaOperator.AND_FF);
1384
 			case BYTE_TO_INT: return castPostfix(cast, JavaOperator.AND_FF);
1344
 			case BYTE_TO_UINT: return castPostfix(cast, JavaOperator.AND_FF);
1385
 			case BYTE_TO_UINT: return castPostfix(cast, JavaOperator.AND_FF);
1386
+			case BYTE_TO_USIZE: return castPostfix(cast, JavaOperator.AND_FF);
1345
 			case BYTE_TO_LONG: return castPostfix(cast, JavaOperator.AND_FFL);
1387
 			case BYTE_TO_LONG: return castPostfix(cast, JavaOperator.AND_FFL);
1346
 			case BYTE_TO_ULONG: return castPostfix(cast, JavaOperator.AND_FFL);
1388
 			case BYTE_TO_ULONG: return castPostfix(cast, JavaOperator.AND_FFL);
1347
 			case BYTE_TO_FLOAT: cast(castPostfix(cast, JavaOperator.AND_FF), "float");
1389
 			case BYTE_TO_FLOAT: cast(castPostfix(cast, JavaOperator.AND_FF), "float");
1353
 			case SBYTE_TO_USHORT: return castImplicit(cast, "int");
1395
 			case SBYTE_TO_USHORT: return castImplicit(cast, "int");
1354
 			case SBYTE_TO_INT: return castImplicit(cast, "int");
1396
 			case SBYTE_TO_INT: return castImplicit(cast, "int");
1355
 			case SBYTE_TO_UINT: return castImplicit(cast, "int");
1397
 			case SBYTE_TO_UINT: return castImplicit(cast, "int");
1398
+			case SBYTE_TO_USIZE: return castImplicit(cast, "int");
1356
 			case SBYTE_TO_LONG: return castImplicit(cast, "long");
1399
 			case SBYTE_TO_LONG: return castImplicit(cast, "long");
1357
 			case SBYTE_TO_ULONG: return castImplicit(cast, "long");
1400
 			case SBYTE_TO_ULONG: return castImplicit(cast, "long");
1358
 			case SBYTE_TO_FLOAT: return castImplicit(cast, "float");
1401
 			case SBYTE_TO_FLOAT: return castImplicit(cast, "float");
1364
 			case SHORT_TO_USHORT: return castImplicit(cast, "int");
1407
 			case SHORT_TO_USHORT: return castImplicit(cast, "int");
1365
 			case SHORT_TO_INT: return castImplicit(cast, "int");
1408
 			case SHORT_TO_INT: return castImplicit(cast, "int");
1366
 			case SHORT_TO_UINT: return castImplicit(cast, "int");
1409
 			case SHORT_TO_UINT: return castImplicit(cast, "int");
1410
+			case SHORT_TO_USIZE: return castImplicit(cast, "int");
1367
 			case SHORT_TO_LONG: return castImplicit(cast, "long");
1411
 			case SHORT_TO_LONG: return castImplicit(cast, "long");
1368
 			case SHORT_TO_ULONG: return castImplicit(cast, "long");
1412
 			case SHORT_TO_ULONG: return castImplicit(cast, "long");
1369
 			case SHORT_TO_FLOAT: return castImplicit(cast, "float");
1413
 			case SHORT_TO_FLOAT: return castImplicit(cast, "float");
1377
 			case USHORT_TO_UINT: return castPostfix(cast, JavaOperator.AND_FFFF);
1421
 			case USHORT_TO_UINT: return castPostfix(cast, JavaOperator.AND_FFFF);
1378
 			case USHORT_TO_LONG: return castPostfix(cast, JavaOperator.AND_FFFFL);
1422
 			case USHORT_TO_LONG: return castPostfix(cast, JavaOperator.AND_FFFFL);
1379
 			case USHORT_TO_ULONG: return castPostfix(cast, JavaOperator.AND_FFFFL);
1423
 			case USHORT_TO_ULONG: return castPostfix(cast, JavaOperator.AND_FFFFL);
1424
+			case USHORT_TO_USIZE: return castPostfix(cast, JavaOperator.AND_FFFF);
1380
 			case USHORT_TO_FLOAT: return cast.isImplicit ? cast.target.accept(this) : cast(castPostfix(cast, JavaOperator.AND_FFFF), "float");
1425
 			case USHORT_TO_FLOAT: return cast.isImplicit ? cast.target.accept(this) : cast(castPostfix(cast, JavaOperator.AND_FFFF), "float");
1381
 			case USHORT_TO_DOUBLE: return cast.isImplicit ? cast.target.accept(this) : cast(castPostfix(cast, JavaOperator.AND_FFFF), "double");
1426
 			case USHORT_TO_DOUBLE: return cast.isImplicit ? cast.target.accept(this) : cast(castPostfix(cast, JavaOperator.AND_FFFF), "double");
1382
 			case USHORT_TO_CHAR: return castImplicit(cast, "char");
1427
 			case USHORT_TO_CHAR: return castImplicit(cast, "char");
1392
 			case INT_TO_DOUBLE: return castImplicit(cast, "double");
1437
 			case INT_TO_DOUBLE: return castImplicit(cast, "double");
1393
 			case INT_TO_CHAR: return cast(cast, "char");
1438
 			case INT_TO_CHAR: return cast(cast, "char");
1394
 			case INT_TO_STRING: return callStatic("Integer.toString", cast.target);
1439
 			case INT_TO_STRING: return callStatic("Integer.toString", cast.target);
1440
+			case INT_TO_USIZE: return cast.target.accept(this);
1395
 			case UINT_TO_BYTE: return cast.target.accept(this);
1441
 			case UINT_TO_BYTE: return cast.target.accept(this);
1396
 			case UINT_TO_SBYTE: return cast(cast, "byte");
1442
 			case UINT_TO_SBYTE: return cast(cast, "byte");
1397
 			case UINT_TO_SHORT: return cast(cast, "short");
1443
 			case UINT_TO_SHORT: return cast(cast, "short");
1399
 			case UINT_TO_INT: return cast.target.accept(this);
1445
 			case UINT_TO_INT: return cast.target.accept(this);
1400
 			case UINT_TO_LONG: return castImplicit(cast, "long");
1446
 			case UINT_TO_LONG: return castImplicit(cast, "long");
1401
 			case UINT_TO_ULONG: return castPostfix(cast, JavaOperator.AND_8FL);
1447
 			case UINT_TO_ULONG: return castPostfix(cast, JavaOperator.AND_8FL);
1448
+			case UINT_TO_USIZE: return cast.target.accept(this);
1402
 			case UINT_TO_FLOAT: return cast(castPostfix(cast, JavaOperator.AND_8FL), "float");
1449
 			case UINT_TO_FLOAT: return cast(castPostfix(cast, JavaOperator.AND_8FL), "float");
1403
 			case UINT_TO_DOUBLE: return cast(castPostfix(cast, JavaOperator.AND_8FL), "double");
1450
 			case UINT_TO_DOUBLE: return cast(castPostfix(cast, JavaOperator.AND_8FL), "double");
1404
 			case UINT_TO_CHAR: return cast(cast, "char");
1451
 			case UINT_TO_CHAR: return cast(cast, "char");
1410
 			case LONG_TO_INT: return cast(cast, "int");
1457
 			case LONG_TO_INT: return cast(cast, "int");
1411
 			case LONG_TO_UINT: return cast(cast, "int");
1458
 			case LONG_TO_UINT: return cast(cast, "int");
1412
 			case LONG_TO_ULONG: return cast.target.accept(this);
1459
 			case LONG_TO_ULONG: return cast.target.accept(this);
1460
+			case LONG_TO_USIZE: return cast(cast, "int");
1413
 			case LONG_TO_FLOAT: return castImplicit(cast, "float");
1461
 			case LONG_TO_FLOAT: return castImplicit(cast, "float");
1414
 			case LONG_TO_DOUBLE: return castImplicit(cast, "double");
1462
 			case LONG_TO_DOUBLE: return castImplicit(cast, "double");
1415
 			case LONG_TO_CHAR: return cast(cast, "char");
1463
 			case LONG_TO_CHAR: return cast(cast, "char");
1421
 			case ULONG_TO_INT: return cast(cast, "int");
1469
 			case ULONG_TO_INT: return cast(cast, "int");
1422
 			case ULONG_TO_UINT: return cast(cast, "int");
1470
 			case ULONG_TO_UINT: return cast(cast, "int");
1423
 			case ULONG_TO_LONG: return cast.target.accept(this);
1471
 			case ULONG_TO_LONG: return cast.target.accept(this);
1472
+			case ULONG_TO_USIZE: return cast(cast, "int");
1424
 			case ULONG_TO_FLOAT: return castImplicit(cast, "float"); // TODO: this is incorrect!
1473
 			case ULONG_TO_FLOAT: return castImplicit(cast, "float"); // TODO: this is incorrect!
1425
 			case ULONG_TO_DOUBLE: return castImplicit(cast, "double"); // TODO: this is incorrect!
1474
 			case ULONG_TO_DOUBLE: return castImplicit(cast, "double"); // TODO: this is incorrect!
1426
 			case ULONG_TO_CHAR: return cast(cast, "char");
1475
 			case ULONG_TO_CHAR: return cast(cast, "char");
1433
 			case FLOAT_TO_UINT: return cast(cast, "int");
1482
 			case FLOAT_TO_UINT: return cast(cast, "int");
1434
 			case FLOAT_TO_LONG: return cast(cast, "long");
1483
 			case FLOAT_TO_LONG: return cast(cast, "long");
1435
 			case FLOAT_TO_ULONG: return cast(cast, "long");
1484
 			case FLOAT_TO_ULONG: return cast(cast, "long");
1485
+			case FLOAT_TO_USIZE: return cast(cast, "int");
1436
 			case FLOAT_TO_DOUBLE: return castImplicit(cast, "double");
1486
 			case FLOAT_TO_DOUBLE: return castImplicit(cast, "double");
1437
 			case FLOAT_TO_STRING: return callStatic("Float.toString", cast.target);
1487
 			case FLOAT_TO_STRING: return callStatic("Float.toString", cast.target);
1438
 			case DOUBLE_TO_BYTE: return cast(cast, "int");
1488
 			case DOUBLE_TO_BYTE: return cast(cast, "int");
1443
 			case DOUBLE_TO_UINT: return cast(cast, "int");
1493
 			case DOUBLE_TO_UINT: return cast(cast, "int");
1444
 			case DOUBLE_TO_LONG: return cast(cast, "long");
1494
 			case DOUBLE_TO_LONG: return cast(cast, "long");
1445
 			case DOUBLE_TO_ULONG: return cast(cast, "long");
1495
 			case DOUBLE_TO_ULONG: return cast(cast, "long");
1496
+			case DOUBLE_TO_USIZE: return cast(cast, "int");
1446
 			case DOUBLE_TO_FLOAT: return cast(cast, "float");
1497
 			case DOUBLE_TO_FLOAT: return cast(cast, "float");
1447
 			case DOUBLE_TO_STRING: return callStatic("Double.toString", cast.target);
1498
 			case DOUBLE_TO_STRING: return callStatic("Double.toString", cast.target);
1448
 			case CHAR_TO_BYTE: return cast.target.accept(this);
1499
 			case CHAR_TO_BYTE: return cast.target.accept(this);
1453
 			case CHAR_TO_UINT: return castImplicit(cast, "int");
1504
 			case CHAR_TO_UINT: return castImplicit(cast, "int");
1454
 			case CHAR_TO_LONG: return castImplicit(cast, "long");
1505
 			case CHAR_TO_LONG: return castImplicit(cast, "long");
1455
 			case CHAR_TO_ULONG: return castImplicit(cast, "long");
1506
 			case CHAR_TO_ULONG: return castImplicit(cast, "long");
1507
+			case CHAR_TO_USIZE: return castImplicit(cast, "int");
1456
 			case CHAR_TO_STRING: return callStatic("Character.toString", cast.target);
1508
 			case CHAR_TO_STRING: return callStatic("Character.toString", cast.target);
1457
 			case ENUM_TO_STRING: return cast.target.accept(this).unaryPostfix(JavaOperator.TOSTRING);
1509
 			case ENUM_TO_STRING: return cast.target.accept(this).unaryPostfix(JavaOperator.TOSTRING);
1458
 		}
1510
 		}

+ 11
- 11
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java View File

108
 			writer.write(pkg.fullName);
108
 			writer.write(pkg.fullName);
109
 			writer.write(";\n\n");
109
 			writer.write(";\n\n");
110
 			
110
 			
111
-			JavaClass[] imports = importer.getUsedImports();
112
-			if (imports.length > 0) {
113
-				for (JavaClass import_ : imports) {
114
-					if (import_.pkg.equals("java.lang"))
115
-						continue;
116
-					
117
-					writer.write("import ");
118
-					writer.write(import_.fullName);
119
-					writer.write(";\n");
120
-				}
111
+			boolean hasImports = false;
112
+			for (JavaClass import_ : importer.getUsedImports()) {
113
+				if (import_.pkg.equals("java.lang"))
114
+					continue;
121
 
115
 
122
-				writer.write("\n");
116
+				writer.write("import ");
117
+				writer.write(import_.fullName);
118
+				writer.write(";\n");
119
+				hasImports = true;
123
 			}
120
 			}
121
+
122
+			if (hasImports)
123
+				writer.write("\n");
124
 			
124
 			
125
 			writer.write(contents.toString());
125
 			writer.write(contents.toString());
126
 		} catch (IOException ex) {
126
 		} catch (IOException ex) {

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

30
 		JavaClass cls = definition.getTag(JavaClass.class);
30
 		JavaClass cls = definition.getTag(JavaClass.class);
31
 		if (cls == null)
31
 		if (cls == null)
32
 			throw new IllegalStateException("Missing source class tag on " + definition.name);
32
 			throw new IllegalStateException("Missing source class tag on " + definition.name);
33
-		if (cls.pkg.equals(this.cls.pkg))
34
-			return cls.getClassName();
35
 		
33
 		
36
 		return importType(cls);
34
 		return importType(cls);
37
 	}
35
 	}
42
 			usedImports.add(imported);
40
 			usedImports.add(imported);
43
 			return imported.fullName.equals(cls.outer.fullName) ? cls.getName() : cls.fullName;
41
 			return imported.fullName.equals(cls.outer.fullName) ? cls.getName() : cls.fullName;
44
 		}
42
 		}
43
+		if (cls.pkg.equals(this.cls.pkg))
44
+			return cls.getClassName();
45
 		
45
 		
46
 		imports.put(cls.outer.getName(), cls.outer);
46
 		imports.put(cls.outer.getName(), cls.outer);
47
 		usedImports.add(cls.outer);
47
 		usedImports.add(cls.outer);

+ 5
- 5
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java View File

63
 			}
63
 			}
64
 			contents.append("> ");
64
 			contents.append("> ");
65
 		}
65
 		}
66
-		contents.append(function.header.returnType.accept(typeVisitor));
66
+		contents.append(function.header.getReturnType().accept(typeVisitor));
67
 		contents.append(' ');
67
 		contents.append(' ');
68
 		contents.append("invoke(");
68
 		contents.append("invoke(");
69
 		boolean first = true;
69
 		boolean first = true;
100
 		
100
 		
101
 		StringBuilder contents = new StringBuilder();
101
 		StringBuilder contents = new StringBuilder();
102
 		contents.append("public final class ").append(result.cls.getName()).append(" {\n");
102
 		contents.append("public final class ").append(result.cls.getName()).append(" {\n");
103
-		contents.append(settings.indent).append("public final ").append(type.from.accept(typeVisitor)).append(" from;\n");
104
-		contents.append(settings.indent).append("public final ").append(type.to.accept(typeVisitor)).append(" to;\n");
103
+		contents.append(settings.indent).append("public final ").append(type.baseType.accept(typeVisitor)).append(" from;\n");
104
+		contents.append(settings.indent).append("public final ").append(type.baseType.accept(typeVisitor)).append(" to;\n");
105
 		contents.append(settings.indent).append("\n");
105
 		contents.append(settings.indent).append("\n");
106
 		contents.append(settings.indent)
106
 		contents.append(settings.indent)
107
 				.append("public ")
107
 				.append("public ")
108
 				.append(result.cls.getName())
108
 				.append(result.cls.getName())
109
 				.append("(")
109
 				.append("(")
110
-				.append(type.from.accept(typeVisitor))
110
+				.append(type.baseType.accept(typeVisitor))
111
 				.append(" from, ")
111
 				.append(" from, ")
112
-				.append(type.to.accept(typeVisitor))
112
+				.append(type.baseType.accept(typeVisitor))
113
 				.append(" to) {\n");
113
 				.append(" to) {\n");
114
 		contents.append(settings.indent).append(settings.indent).append("this.from = from;\n");
114
 		contents.append(settings.indent).append(settings.indent).append("this.from = from;\n");
115
 		contents.append(settings.indent).append(settings.indent).append("this.to = to;\n");
115
 		contents.append(settings.indent).append(settings.indent).append("this.to = to;\n");

+ 13
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java View File

61
 			case UINT: return "int";
61
 			case UINT: return "int";
62
 			case LONG: return "long";
62
 			case LONG: return "long";
63
 			case ULONG: return "long";
63
 			case ULONG: return "long";
64
+			case USIZE: return "int";
64
 			case FLOAT: return "float";
65
 			case FLOAT: return "float";
65
 			case DOUBLE: return "double";
66
 			case DOUBLE: return "double";
66
 			case CHAR: return "char";
67
 			case CHAR: return "char";
73
 	@Override
74
 	@Override
74
 	public String visitArray(ArrayTypeID array) {
75
 	public String visitArray(ArrayTypeID array) {
75
 		StringBuilder result = new StringBuilder();
76
 		StringBuilder result = new StringBuilder();
76
-		result.append(array.elementType.accept(this));
77
+		
78
+		if (array.elementType == BasicTypeID.BYTE) {
79
+			result.append("byte");
80
+		} else if (array.elementType == BasicTypeID.USHORT) {
81
+			result.append("short");
82
+		} else {
83
+			result.append(array.elementType.accept(this));
84
+		}
85
+		
77
 		for (int i = 0; i < array.dimension; i++)
86
 		for (int i = 0; i < array.dimension; i++)
78
 			result.append("[]");
87
 			result.append("[]");
79
 		
88
 		
170
 
179
 
171
 	@Override
180
 	@Override
172
 	public String visitModified(ModifiedTypeID optional) {
181
 	public String visitModified(ModifiedTypeID optional) {
182
+		if (optional.isOptional() && optional.withoutOptional() == BasicTypeID.USIZE)
183
+			return "int"; // usize? is an int
184
+		
173
 		return optional.baseType.accept(new JavaSourceObjectTypeVisitor(importer, typeGenerator));
185
 		return optional.baseType.accept(new JavaSourceObjectTypeVisitor(importer, typeGenerator));
174
 	}
186
 	}
175
 
187
 

+ 1
- 0
Parser/build.gradle View File

16
 dependencies {
16
 dependencies {
17
     compile project(':Shared')
17
     compile project(':Shared')
18
 	compile project(':CodeModel')
18
 	compile project(':CodeModel')
19
+	compile project(':CompilerShared')
19
 }
20
 }

+ 1
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java View File

120
 	K_UINT(true, "uint"),
120
 	K_UINT(true, "uint"),
121
 	K_LONG(true, "long"),
121
 	K_LONG(true, "long"),
122
 	K_ULONG(true, "ulong"),
122
 	K_ULONG(true, "ulong"),
123
+	K_USIZE(true, "usize"),
123
 	K_FLOAT(true, "float"),
124
 	K_FLOAT(true, "float"),
124
 	K_DOUBLE(true, "double"),
125
 	K_DOUBLE(true, "double"),
125
 	K_CHAR(true, "char"),
126
 	K_CHAR(true, "char"),

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

8
 import java.io.File;
8
 import java.io.File;
9
 import java.io.IOException;
9
 import java.io.IOException;
10
 import java.util.ArrayList;
10
 import java.util.ArrayList;
11
+import java.util.Collections;
11
 import java.util.List;
12
 import java.util.List;
12
 import java.util.Map;
13
 import java.util.Map;
14
+import java.util.function.Consumer;
13
 import org.openzen.zencode.shared.CodePosition;
15
 import org.openzen.zencode.shared.CodePosition;
14
 import org.openzen.zencode.shared.CompileException;
16
 import org.openzen.zencode.shared.CompileException;
15
 import org.openzen.zencode.shared.CompileExceptionCode;
17
 import org.openzen.zencode.shared.CompileExceptionCode;
33
 import org.openzen.zenscript.codemodel.scope.GlobalScriptScope;
35
 import org.openzen.zenscript.codemodel.scope.GlobalScriptScope;
34
 import org.openzen.zenscript.codemodel.type.ISymbol;
36
 import org.openzen.zenscript.codemodel.type.ISymbol;
35
 import org.openzen.zenscript.codemodel.scope.StatementScope;
37
 import org.openzen.zenscript.codemodel.scope.StatementScope;
38
+import org.openzen.zenscript.compiler.ModuleSpace;
39
+import org.openzen.zenscript.compiler.SemanticModule;
36
 import org.openzen.zenscript.parser.statements.ParsedStatement;
40
 import org.openzen.zenscript.parser.statements.ParsedStatement;
37
 
41
 
38
 /**
42
 /**
40
  * @author Hoofdgebruiker
44
  * @author Hoofdgebruiker
41
  */
45
  */
42
 public class ParsedFile {
46
 public class ParsedFile {
47
+	public static SemanticModule compileSyntaxToSemantic(
48
+			String name,
49
+			SemanticModule[] dependencies,
50
+			CompilingPackage pkg,
51
+			ParsedFile[] files,
52
+			ModuleSpace registry,
53
+			Consumer<CompileException> exceptionLogger) {
54
+		// We are considering all these files to be in the same package, so make
55
+		// a single PackageDefinition instance. If these files were in multiple
56
+		// packages, we'd need an instance for every package.
57
+		PackageDefinitions definitions = new PackageDefinitions();
58
+		for (ParsedFile file : files) {
59
+			// listDefinitions will merely register all definitions (classes,
60
+			// interfaces, functions ...) so they can later be available to
61
+			// the other files as well. It doesn't yet compile anything.
62
+			file.listDefinitions(definitions);
63
+		}
64
+		
65
+		ZSPackage rootPackage = registry.collectPackages();
66
+		List<ExpansionDefinition> expansions = registry.collectExpansions();
67
+		definitions.registerExpansionsTo(expansions);
68
+		
69
+		Map<String, ISymbol> globals = registry.collectGlobals();
70
+		boolean failed = false;
71
+		
72
+		ModuleTypeResolutionContext moduleContext = new ModuleTypeResolutionContext(
73
+				registry.compilationUnit.globalTypeRegistry,
74
+				registry.getAnnotations(),
75
+				rootPackage,
76
+				pkg,
77
+				globals);
78
+		
79
+		for (ParsedFile file : files) {
80
+			file.registerTypes(moduleContext, rootPackage, pkg);
81
+		}
82
+		
83
+		for (ParsedFile file : files) {
84
+			// compileMembers will register all definition members to their
85
+			// respective definitions, such as fields, constructors, methods...
86
+			// It doesn't yet compile the method contents.
87
+			try {
88
+				file.compileTypes(moduleContext, rootPackage, pkg);
89
+			} catch (CompileException ex) {
90
+				exceptionLogger.accept(ex);
91
+				failed = true;
92
+			}
93
+		}
94
+		
95
+		if (failed)
96
+			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
97
+		
98
+		// scripts will store all the script blocks encountered in the files
99
+		PrecompilationState precompiler = new PrecompilationState();
100
+		for (ParsedFile file : files) {
101
+			file.registerMembers(moduleContext, precompiler, rootPackage, pkg, expansions, globals);
102
+		}
103
+		
104
+		List<ScriptBlock> scripts = new ArrayList<>();
105
+		for (ParsedFile file : files) {
106
+			// compileCode will convert the parsed statements and expressions
107
+			// into semantic code. This semantic code can then be compiled
108
+			// to various targets.
109
+			try {
110
+				file.compileCode(moduleContext, precompiler, rootPackage, pkg, expansions, scripts, globals);
111
+			} catch (CompileException ex) {
112
+				exceptionLogger.accept(ex);
113
+				failed = true;
114
+			}
115
+		}
116
+		
117
+		return new SemanticModule(name, dependencies, SemanticModule.State.ASSEMBLED, rootPackage, pkg.getPackage(), definitions, scripts, registry.compilationUnit, expansions, registry.getAnnotations());
118
+	}
119
+	
43
 	public static ParsedFile parse(CompilingPackage compilingPackage, BracketExpressionParser bracketParser, File file) throws IOException {
120
 	public static ParsedFile parse(CompilingPackage compilingPackage, BracketExpressionParser bracketParser, File file) throws IOException {
44
 		return parse(compilingPackage, bracketParser, new FileSourceFile(file.getName(), file));
121
 		return parse(compilingPackage, bracketParser, new FileSourceFile(file.getName(), file));
45
 	}
122
 	}

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

70
 		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
70
 		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
71
 		compiled.setCode(body.compile(innerScope, compiled.header));
71
 		compiled.setCode(body.compile(innerScope, compiled.header));
72
 		
72
 		
73
-		if (compiled.header.returnType == BasicTypeID.UNDETERMINED) {
74
-			compiled.header.returnType = compiled.statement.getReturnType();
73
+		if (compiled.header.getReturnType() == BasicTypeID.UNDETERMINED) {
74
+			compiled.header.setReturnType(compiled.statement.getReturnType());
75
 		}
75
 		}
76
 	}
76
 	}
77
 
77
 

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java View File

69
 		StatementScope innerScope = new LambdaScope(scope, closure, header);
69
 		StatementScope innerScope = new LambdaScope(scope, closure, header);
70
 		Statement statements = body.compile(innerScope, header);
70
 		Statement statements = body.compile(innerScope, header);
71
 		
71
 		
72
-		if (header.returnType == BasicTypeID.UNDETERMINED) {
73
-			header.returnType = statements.getReturnType();
72
+		if (header.getReturnType() == BasicTypeID.UNDETERMINED) {
73
+			header.setReturnType(statements.getReturnType());
74
 		}
74
 		}
75
 		if (!scope.genericInferenceMap.isEmpty()) {
75
 		if (!scope.genericInferenceMap.isEmpty()) {
76
 			// perform type parameter inference
76
 			// perform type parameter inference
77
 			ITypeID returnType = statements.getReturnType();
77
 			ITypeID returnType = statements.getReturnType();
78
 			Map<TypeParameter, ITypeID> inferredTypes = new HashMap<>();
78
 			Map<TypeParameter, ITypeID> inferredTypes = new HashMap<>();
79
-			if (!returnType.inferTypeParameters(scope.getMemberCache(), genericHeader.returnType, inferredTypes))
79
+			if (!returnType.inferTypeParameters(scope.getMemberCache(), genericHeader.getReturnType(), inferredTypes))
80
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
80
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
81
 			
81
 			
82
 			scope.genericInferenceMap.putAll(inferredTypes);
82
 			scope.genericInferenceMap.putAll(inferredTypes);

+ 3
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java View File

17
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
17
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
18
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
18
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
19
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
19
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
20
+import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
20
 import org.openzen.zenscript.codemodel.expression.Expression;
21
 import org.openzen.zenscript.codemodel.expression.Expression;
21
 import org.openzen.zenscript.codemodel.expression.switchvalue.IntSwitchValue;
22
 import org.openzen.zenscript.codemodel.expression.switchvalue.IntSwitchValue;
22
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
23
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
59
 						return new ConstantLongExpression(position, value);
60
 						return new ConstantLongExpression(position, value);
60
 					case ULONG:
61
 					case ULONG:
61
 						return new ConstantULongExpression(position, value);
62
 						return new ConstantULongExpression(position, value);
63
+					case USIZE:
64
+						return new ConstantUSizeExpression(position, value);
62
 					case CHAR:
65
 					case CHAR:
63
 						return new ConstantCharExpression(position, (char) value);
66
 						return new ConstantCharExpression(position, (char) value);
64
 					default:
67
 					default:

+ 7
- 5
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionRange.java View File

38
 		for (ITypeID hint : scope.hints) {
38
 		for (ITypeID hint : scope.hints) {
39
 			if (hint instanceof RangeTypeID) {
39
 			if (hint instanceof RangeTypeID) {
40
 				RangeTypeID rangeHint = (RangeTypeID) hint;
40
 				RangeTypeID rangeHint = (RangeTypeID) hint;
41
-				if (!fromHints.contains(rangeHint.from))
42
-					fromHints.add(rangeHint.from);
43
-				if (!toHints.contains(rangeHint.to))
44
-					toHints.add(rangeHint.to);
41
+				if (!fromHints.contains(rangeHint.baseType))
42
+					fromHints.add(rangeHint.baseType);
43
+				if (!toHints.contains(rangeHint.baseType))
44
+					toHints.add(rangeHint.baseType);
45
 			}
45
 			}
46
 		}
46
 		}
47
 		
47
 		
48
 		Expression from = this.from.compile(scope.withHints(fromHints)).eval();
48
 		Expression from = this.from.compile(scope.withHints(fromHints)).eval();
49
 		Expression to = this.to.compile(scope.withHints(toHints)).eval();
49
 		Expression to = this.to.compile(scope.withHints(toHints)).eval();
50
-		return new RangeExpression(position, scope.getTypeRegistry(), from, to);
50
+		
51
+		ITypeID baseType = scope.getTypeMembers(from.type).union(to.type);
52
+		return new RangeExpression(position, scope.getTypeRegistry().getRange(baseType), from, to);
51
 	}
53
 	}
52
 
54
 
53
 	@Override
55
 	@Override

+ 8
- 2
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedFunctionalMember.java View File

75
 		getCompiled().annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
75
 		getCompiled().annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
76
 		getCompiled().setBody(body.compile(innerScope, getCompiled().header));
76
 		getCompiled().setBody(body.compile(innerScope, getCompiled().header));
77
 		
77
 		
78
-		if (getCompiled().header.returnType == BasicTypeID.UNDETERMINED)
79
-			getCompiled().header.returnType = getCompiled().body.getReturnType();
78
+		if (getCompiled().header.getReturnType() == BasicTypeID.UNDETERMINED) {
79
+			ITypeID returnType = getCompiled().body.getReturnType();
80
+			if (returnType == null) {
81
+				throw new CompileException(position, CompileExceptionCode.CANNOT_INFER_RETURN_TYPE, "Method return type could not be inferred");
82
+			} else {
83
+				getCompiled().header.setReturnType(returnType);
84
+			}
85
+		}
80
 	}
86
 	}
81
 	
87
 	
82
 	protected abstract void fillOverride(TypeScope scope, ITypeID baseType);
88
 	protected abstract void fillOverride(TypeScope scope, ITypeID baseType);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java View File

28
 	
28
 	
29
 	@Override
29
 	@Override
30
 	public Statement compile(StatementScope scope, FunctionHeader header) {
30
 	public Statement compile(StatementScope scope, FunctionHeader header) {
31
-		if (header.returnType == BasicTypeID.VOID) {
31
+		if (header.getReturnType() == BasicTypeID.VOID) {
32
 			Expression value = this.value.compile(new ExpressionScope(scope)).eval();
32
 			Expression value = this.value.compile(new ExpressionScope(scope)).eval();
33
 			return new ExpressionStatement(value.position, value);
33
 			return new ExpressionStatement(value.position, value);
34
 		} else {
34
 		} else {
35
 			Expression returnValue = value
35
 			Expression returnValue = value
36
-					.compile(new ExpressionScope(scope, header.returnType))
36
+					.compile(new ExpressionScope(scope, header.getReturnType()))
37
 					.eval()
37
 					.eval()
38
-					.castImplicit(value.position, scope, header.returnType);
38
+					.castImplicit(value.position, scope, header.getReturnType());
39
 			return new ReturnStatement(value.position, returnValue);
39
 			return new ReturnStatement(value.position, returnValue);
40
 		}
40
 		}
41
 	}
41
 	}

+ 4
- 5
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementReturn.java View File

11
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
11
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
12
 import org.openzen.zenscript.codemodel.scope.StatementScope;
12
 import org.openzen.zenscript.codemodel.scope.StatementScope;
13
 import org.openzen.zenscript.parser.ParsedAnnotation;
13
 import org.openzen.zenscript.parser.ParsedAnnotation;
14
-import org.openzen.zenscript.parser.PrecompilationState;
15
 import org.openzen.zenscript.parser.expression.ParsedExpression;
14
 import org.openzen.zenscript.parser.expression.ParsedExpression;
16
 
15
 
17
 public class ParsedStatementReturn extends ParsedStatement {
16
 public class ParsedStatementReturn extends ParsedStatement {
30
 	@Override
29
 	@Override
31
 	public Statement compile(StatementScope scope) {
30
 	public Statement compile(StatementScope scope) {
32
 		if (expression == null) {
31
 		if (expression == null) {
33
-			if (scope.getFunctionHeader().returnType == BasicTypeID.VOID)
32
+			if (scope.getFunctionHeader().getReturnType() == BasicTypeID.VOID)
34
 				return new ReturnStatement(position, null);
33
 				return new ReturnStatement(position, null);
35
 			else
34
 			else
36
 				throw new CompileException(position, CompileExceptionCode.RETURN_VALUE_REQUIRED, "Return value is required");
35
 				throw new CompileException(position, CompileExceptionCode.RETURN_VALUE_REQUIRED, "Return value is required");
37
-		} else if (scope.getFunctionHeader().returnType == BasicTypeID.VOID) {
36
+		} else if (scope.getFunctionHeader().getReturnType() == BasicTypeID.VOID) {
38
 			throw new CompileException(position, CompileExceptionCode.RETURN_VALUE_VOID, "Cannot return a value from a void function");
37
 			throw new CompileException(position, CompileExceptionCode.RETURN_VALUE_VOID, "Cannot return a value from a void function");
39
 		} else {
38
 		} else {
40
 			Expression value = expression
39
 			Expression value = expression
41
-					.compile(new ExpressionScope(scope, scope.getFunctionHeader().returnType))
40
+					.compile(new ExpressionScope(scope, scope.getFunctionHeader().getReturnType()))
42
 					.eval()
41
 					.eval()
43
-					.castImplicit(position, scope, scope.getFunctionHeader().returnType);
42
+					.castImplicit(position, scope, scope.getFunctionHeader().getReturnType());
44
 			return result(new ReturnStatement(position, value), scope);
43
 			return result(new ReturnStatement(position, value), scope);
45
 		}
44
 		}
46
 	}
45
 	}

+ 6
- 3
Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java View File

35
 	}
35
 	}
36
 	
36
 	
37
 	public static IParsedType tryParse(ZSTokenParser tokens) {
37
 	public static IParsedType tryParse(ZSTokenParser tokens) {
38
+		CodePosition position = tokens.getPosition();
38
 		int modifiers = 0;
39
 		int modifiers = 0;
39
 		while (true) {
40
 		while (true) {
40
 			if (tokens.optional(ZSTokenType.K_CONST) != null) {
41
 			if (tokens.optional(ZSTokenType.K_CONST) != null) {
88
 				tokens.next();
89
 				tokens.next();
89
 				result = ParsedTypeBasic.ULONG;
90
 				result = ParsedTypeBasic.ULONG;
90
 				break;
91
 				break;
92
+			case K_USIZE:
93
+				tokens.next();
94
+				result = ParsedTypeBasic.USIZE;
95
+				break;
91
 			case K_FLOAT:
96
 			case K_FLOAT:
92
 				tokens.next();
97
 				tokens.next();
93
 				result = ParsedTypeBasic.FLOAT;
98
 				result = ParsedTypeBasic.FLOAT;
105
 				result = ParsedTypeBasic.STRING;
110
 				result = ParsedTypeBasic.STRING;
106
 				break;
111
 				break;
107
 			case K_FUNCTION: {
112
 			case K_FUNCTION: {
108
-				CodePosition position = tokens.getPosition();
109
 				tokens.next();
113
 				tokens.next();
110
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
114
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
111
 				result = new ParsedFunctionType(position, header);
115
 				result = new ParsedFunctionType(position, header);
112
 				break;
116
 				break;
113
 			}
117
 			}
114
 			case T_IDENTIFIER: {
118
 			case T_IDENTIFIER: {
115
-				CodePosition position = tokens.getPosition();
116
 				List<ParsedNamedType.ParsedNamePart> name = new ArrayList<>();
119
 				List<ParsedNamedType.ParsedNamePart> name = new ArrayList<>();
117
 				do {
120
 				do {
118
 					String namePart = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
121
 					String namePart = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
132
 				case T_DOT2: {
135
 				case T_DOT2: {
133
 					tokens.next();
136
 					tokens.next();
134
 					IParsedType to = parse(tokens);
137
 					IParsedType to = parse(tokens);
135
-					result = new ParsedTypeRange(result, to);
138
+					result = new ParsedTypeRange(position, result, to);
136
 					break;
139
 					break;
137
 				}
140
 				}
138
 				case T_SQOPEN:
141
 				case T_SQOPEN:

+ 1
- 0
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeBasic.java View File

24
 	UINT(BasicTypeID.UINT),
24
 	UINT(BasicTypeID.UINT),
25
 	LONG(BasicTypeID.LONG),
25
 	LONG(BasicTypeID.LONG),
26
 	ULONG(BasicTypeID.ULONG),
26
 	ULONG(BasicTypeID.ULONG),
27
+	USIZE(BasicTypeID.USIZE),
27
 	FLOAT(BasicTypeID.FLOAT),
28
 	FLOAT(BasicTypeID.FLOAT),
28
 	DOUBLE(BasicTypeID.DOUBLE),
29
 	DOUBLE(BasicTypeID.DOUBLE),
29
 	CHAR(BasicTypeID.CHAR),
30
 	CHAR(BasicTypeID.CHAR),

+ 14
- 7
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeRange.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.parser.type;
6
 package org.openzen.zenscript.parser.type;
7
 
7
 
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zencode.shared.CompileExceptionCode;
8
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
11
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
9
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
10
-import org.openzen.zenscript.codemodel.type.member.TypeMembers;
11
-import org.openzen.zenscript.codemodel.scope.BaseScope;
12
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
13
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
13
 
14
 
14
 /**
15
 /**
16
  * @author Hoofdgebruiker
17
  * @author Hoofdgebruiker
17
  */
18
  */
18
 public class ParsedTypeRange implements IParsedType {
19
 public class ParsedTypeRange implements IParsedType {
20
+	private final CodePosition position;
19
 	private final IParsedType from;
21
 	private final IParsedType from;
20
 	private final IParsedType to;
22
 	private final IParsedType to;
21
 	private final int modifiers;
23
 	private final int modifiers;
22
 	
24
 	
23
-	public ParsedTypeRange(IParsedType from, IParsedType to) {
25
+	public ParsedTypeRange(CodePosition position, IParsedType from, IParsedType to) {
26
+		this.position = position;
24
 		this.from = from;
27
 		this.from = from;
25
 		this.to = to;
28
 		this.to = to;
26
 		this.modifiers = 0;
29
 		this.modifiers = 0;
27
 	}
30
 	}
28
 	
31
 	
29
-	private ParsedTypeRange(IParsedType from, IParsedType to, int modifiers) {
32
+	private ParsedTypeRange(CodePosition position, IParsedType from, IParsedType to, int modifiers) {
33
+		this.position = position;
30
 		this.from = from;
34
 		this.from = from;
31
 		this.to = to;
35
 		this.to = to;
32
 		this.modifiers = modifiers;
36
 		this.modifiers = modifiers;
34
 
38
 
35
 	@Override
39
 	@Override
36
 	public IParsedType withOptional() {
40
 	public IParsedType withOptional() {
37
-		return new ParsedTypeRange(from, to, modifiers | ModifiedTypeID.MODIFIER_OPTIONAL);
41
+		return new ParsedTypeRange(position, from, to, modifiers | ModifiedTypeID.MODIFIER_OPTIONAL);
38
 	}
42
 	}
39
 
43
 
40
 	@Override
44
 	@Override
41
 	public IParsedType withModifiers(int modifiers) {
45
 	public IParsedType withModifiers(int modifiers) {
42
-		return new ParsedTypeRange(from, to, this.modifiers | modifiers);
46
+		return new ParsedTypeRange(position, from, to, this.modifiers | modifiers);
43
 	}
47
 	}
44
 	
48
 	
45
 	@Override
49
 	@Override
46
 	public ITypeID compile(TypeResolutionContext context) {
50
 	public ITypeID compile(TypeResolutionContext context) {
47
 		ITypeID from = this.from.compile(context);
51
 		ITypeID from = this.from.compile(context);
48
 		ITypeID to = this.to.compile(context);
52
 		ITypeID to = this.to.compile(context);
49
-		return context.getTypeRegistry().getModified(modifiers, context.getTypeRegistry().getRange(from, to));
53
+		if (from != to)
54
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_TYPE, "from and to in a range must be the same type");
55
+		
56
+		return context.getTypeRegistry().getModified(modifiers, context.getTypeRegistry().getRange(from));
50
 	}
57
 	}
51
 }
58
 }

+ 1
- 2
ScriptingExample/build.gradle View File

18
 	compile project(':JavaBytecodeCompiler')
18
 	compile project(':JavaBytecodeCompiler')
19
 	compile project(':JavaShared')
19
 	compile project(':JavaShared')
20
 	compile project(':CodeFormatter')
20
 	compile project(':CodeFormatter')
21
-	compile project(':Validator')
22
-	compile project(':Constructor')
21
+	compile project(':ScriptingHost')
23
 }
22
 }

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

22
 import org.openzen.zenscript.formatter.ScriptFormattingSettings;
22
 import org.openzen.zenscript.formatter.ScriptFormattingSettings;
23
 import org.openzen.zenscript.javabytecode.JavaCompiler;
23
 import org.openzen.zenscript.javabytecode.JavaCompiler;
24
 import org.openzen.zenscript.javabytecode.JavaModule;
24
 import org.openzen.zenscript.javabytecode.JavaModule;
25
-import org.openzen.zenscript.constructor.Module;
26
-import org.openzen.zenscript.constructor.module.ModuleSpace;
25
+import org.openzen.zenscript.compiler.ModuleSpace;
27
 import org.openzen.zenscript.lexer.ZSToken;
26
 import org.openzen.zenscript.lexer.ZSToken;
28
 import org.openzen.zenscript.lexer.ZSTokenParser;
27
 import org.openzen.zenscript.lexer.ZSTokenParser;
29
 import org.openzen.zenscript.lexer.ZSTokenType;
28
 import org.openzen.zenscript.lexer.ZSTokenType;
37
      * @param args the command line arguments
36
      * @param args the command line arguments
38
      */
37
      */
39
     public static void main(String[] args) throws IOException {
38
     public static void main(String[] args) throws IOException {
39
+		
40
 		System.out.println();
40
 		System.out.println();
41
 		File inputDirectory = new File("scripts");
41
 		File inputDirectory = new File("scripts");
42
 		File[] inputFiles = Optional.ofNullable(inputDirectory.listFiles((dir, name) -> name.endsWith(".zs"))).orElseGet(() -> new File[0]);
42
 		File[] inputFiles = Optional.ofNullable(inputDirectory.listFiles((dir, name) -> name.endsWith(".zs"))).orElseGet(() -> new File[0]);
107
 		for (Map.Entry<String, ISymbol> global : registry.collectGlobals().entrySet()) {
107
 		for (Map.Entry<String, ISymbol> global : registry.collectGlobals().entrySet()) {
108
 			space.addGlobal(global.getKey(), global.getValue());
108
 			space.addGlobal(global.getKey(), global.getValue());
109
 		}
109
 		}
110
-		SemanticModule result = Module.compileSyntaxToSemantic(
110
+		SemanticModule result = ParsedFile.compileSyntaxToSemantic(
111
 				"scripts",
111
 				"scripts",
112
 				new SemanticModule[0],
112
 				new SemanticModule[0],
113
 				compiling,
113
 				compiling,

+ 2
- 3
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java View File

1
 package org.openzen.zencode.shared;
1
 package org.openzen.zencode.shared;
2
 
2
 
3
-import org.openzen.zencode.shared.CodePosition;
4
-import org.openzen.zencode.shared.VirtualSourceFile;
5
-
6
 public final class CodePosition {
3
 public final class CodePosition {
7
     public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
4
     public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
8
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
5
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
6
+	public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
7
+	
9
     public final SourceFile file;
8
     public final SourceFile file;
10
     public final int fromLine;
9
     public final int fromLine;
11
     public final int fromLineOffset;
10
     public final int fromLineOffset;

+ 3
- 1
Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java View File

66
 	VAR_WITHOUT_TYPE_OR_INITIALIZER(),
66
 	VAR_WITHOUT_TYPE_OR_INITIALIZER(),
67
 	NO_BRACKET_PARSER(),
67
 	NO_BRACKET_PARSER(),
68
 	INVALID_BRACKET_EXPRESSION(),
68
 	INVALID_BRACKET_EXPRESSION(),
69
-	VARIANT_OPTION_NOT_AN_EXPRESSION
69
+	VARIANT_OPTION_NOT_AN_EXPRESSION,
70
+	DUPLICATE_GLOBAL,
71
+	CANNOT_INFER_RETURN_TYPE
70
 }
72
 }

+ 9
- 4
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java View File

226
 		return null;
226
 		return null;
227
 	}
227
 	}
228
 
228
 
229
+	@Override
230
+	public Void visitConstantUSize(ConstantUSizeExpression expression) {
231
+		return null;
232
+	}
233
+
229
 	@Override
234
 	@Override
230
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
235
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
231
 		if (!scope.isConstructor()) {
236
 		if (!scope.isConstructor()) {
485
 		expression.to.accept(this);
490
 		expression.to.accept(this);
486
 		
491
 		
487
 		RangeTypeID rangeType = (RangeTypeID) expression.type;
492
 		RangeTypeID rangeType = (RangeTypeID) expression.type;
488
-		if (expression.from.type != rangeType.from) {
489
-			validator.logError(ValidationLogEntry.Code.INVALID_OPERAND_TYPE, expression.position, "From operand is not a " + rangeType.from.toString());
493
+		if (expression.from.type != rangeType.baseType) {
494
+			validator.logError(ValidationLogEntry.Code.INVALID_OPERAND_TYPE, expression.position, "From operand is not a " + rangeType.baseType.toString());
490
 		}
495
 		}
491
-		if (expression.to.type != rangeType.to) {
492
-			validator.logError(ValidationLogEntry.Code.INVALID_OPERAND_TYPE, expression.position, "To operand is not a " + rangeType.to.toString());
496
+		if (expression.to.type != rangeType.baseType) {
497
+			validator.logError(ValidationLogEntry.Code.INVALID_OPERAND_TYPE, expression.position, "To operand is not a " + rangeType.baseType.toString());
493
 		}
498
 		}
494
 		return null;
499
 		return null;
495
 	}
500
 	}

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

152
 					validator,
152
 					validator,
153
 					new StatementExpressionScope()));
153
 					new StatementExpressionScope()));
154
 			
154
 			
155
-			if (statement.value.type != scope.getFunctionHeader().returnType) {
155
+			if (statement.value.type != scope.getFunctionHeader().getReturnType()) {
156
 				validator.logError(ValidationLogEntry.Code.INVALID_RETURN_TYPE, statement.position, "Invalid return type: " + statement.value.type.toString());
156
 				validator.logError(ValidationLogEntry.Code.INVALID_RETURN_TYPE, statement.position, "Invalid return type: " + statement.value.type.toString());
157
 			}
157
 			}
158
-		} else if (scope.getFunctionHeader().returnType != BasicTypeID.VOID) {
158
+		} else if (scope.getFunctionHeader().getReturnType() != BasicTypeID.VOID) {
159
 			validator.logError(ValidationLogEntry.Code.INVALID_RETURN_TYPE, statement.position, "Missing return value");
159
 			validator.logError(ValidationLogEntry.Code.INVALID_RETURN_TYPE, statement.position, "Missing return value");
160
 		}
160
 		}
161
 		
161
 		

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

90
 
90
 
91
 	@Override
91
 	@Override
92
 	public Void visitRange(RangeTypeID range) {
92
 	public Void visitRange(RangeTypeID range) {
93
-		range.from.accept(this);
94
-		range.to.accept(this);
93
+		range.baseType.accept(this);
95
 		return null;
94
 		return null;
96
 	}
95
 	}
97
 
96
 

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

51
 	
51
 	
52
 	public static void validateHeader(Validator target, CodePosition position, FunctionHeader header) {
52
 	public static void validateHeader(Validator target, CodePosition position, FunctionHeader header) {
53
 		TypeValidator typeValidator = new TypeValidator(target, position);
53
 		TypeValidator typeValidator = new TypeValidator(target, position);
54
-		header.returnType.accept(typeValidator);
54
+		header.getReturnType().accept(typeValidator);
55
 		
55
 		
56
 		Set<String> parameterNames = new HashSet<>();
56
 		Set<String> parameterNames = new HashSet<>();
57
 		int i = 0;
57
 		int i = 0;

Loading…
Cancel
Save