Explorar el Código

- 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 hace 6 años
padre
commit
0298420bb2
Se han modificado 71 ficheros con 663 adiciones y 424 borrados
  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 Ver fichero

@@ -36,6 +36,7 @@ import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
36 36
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
37 37
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
38 38
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
39
+import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
39 40
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
40 41
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
41 42
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
@@ -391,6 +392,11 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
391 392
 	public ExpressionString visitConstantShort(ConstantShortExpression expression) {
392 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 401
 	@Override
396 402
 	public ExpressionString visitConstantString(ConstantStringExpression expression) {
@@ -402,17 +408,17 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
402 408
 
403 409
 	@Override
404 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 414
 	@Override
409 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 419
 	@Override
414 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 424
 	@Override

+ 3
- 3
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java Ver fichero

@@ -80,15 +80,15 @@ public class FormattingUtils {
80 80
 			
81 81
 			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
82 82
 				result.append(" as ");
83
-				result.append(header.returnType.accept(typeFormatter));
83
+				result.append(header.getReturnType().accept(typeFormatter));
84 84
 			}
85 85
 			
86 86
 			parameterIndex++;
87 87
 		}
88 88
 		result.append(")");
89
-		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.UNDETERMINED) {
89
+		if (!settings.showAnyInFunctionHeaders || header.getReturnType() != BasicTypeID.UNDETERMINED) {
90 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 Ver fichero

@@ -97,7 +97,7 @@ public class TypeFormatter implements ITypeVisitor<String>, GenericParameterBoun
97 97
 
98 98
 	@Override
99 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 103
 	@Override

+ 12
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Ver fichero

@@ -27,7 +27,7 @@ public class FunctionHeader {
27 27
 	private static final FunctionParameter[] NO_PARAMETERS = new FunctionParameter[0];
28 28
 	
29 29
 	public final TypeParameter[] typeParameters;
30
-	public ITypeID returnType;
30
+	private ITypeID returnType;
31 31
 	public final FunctionParameter[] parameters;
32 32
 	public final ITypeID thrownType;
33 33
 	
@@ -96,6 +96,17 @@ public class FunctionHeader {
96 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 110
 	public boolean isDenormalized() {
100 111
 		if (returnType.getNormalized() != returnType)
101 112
 			return true;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java Ver fichero

@@ -21,7 +21,7 @@ public class CallExpression extends Expression {
21 21
 	public final FunctionHeader instancedHeader;
22 22
 	
23 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 26
 		this.target = target;
27 27
 		this.member = member;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java Ver fichero

@@ -22,7 +22,7 @@ public class CallStaticExpression extends Expression {
22 22
 	public final FunctionHeader instancedHeader;
23 23
 	
24 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 27
 		this.member = member;
28 28
 		this.target = target;

+ 39
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUSizeExpression.java Ver fichero

@@ -0,0 +1,39 @@
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 Ver fichero

@@ -66,6 +66,8 @@ public interface ExpressionVisitor<T> {
66 66
 	
67 67
 	public T visitConstantUShort(ConstantUShortExpression expression);
68 68
 	
69
+	public T visitConstantUSize(ConstantUSizeExpression expression);
70
+	
69 71
 	public T visitConstructorThisCall(ConstructorThisCallExpression expression);
70 72
 	
71 73
 	public T visitConstructorSuperCall(ConstructorSuperCallExpression expression);

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PostCallExpression.java Ver fichero

@@ -22,7 +22,7 @@ public class PostCallExpression extends Expression {
22 22
 	public final FunctionHeader instancedHeader;
23 23
 	
24 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 27
 		if (member.getOperator() != OperatorType.DECREMENT && member.getOperator() != OperatorType.INCREMENT)
28 28
 			throw new IllegalArgumentException("Operator must be increment or decrement");

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

@@ -9,6 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.scope.TypeScope;
10 10
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
12 13
 
13 14
 /**
14 15
  *
@@ -18,8 +19,8 @@ public class RangeExpression extends Expression {
18 19
 	public final Expression from;
19 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 25
 		this.from = from;
25 26
 		this.to = to;
@@ -46,6 +47,11 @@ public class RangeExpression extends Expression {
46 47
 
47 48
 	@Override
48 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 Ver fichero

@@ -61,13 +61,6 @@ public class ExpressionScope extends BaseScope {
61 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 64
 	private ExpressionScope(
72 65
 			BaseScope scope,
73 66
 			List<ITypeID> hints,

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

@@ -26,6 +26,7 @@ public enum BasicTypeID implements ITypeID {
26 26
 	UINT("uint"),
27 27
 	LONG("long"),
28 28
 	ULONG("ulong"),
29
+	USIZE("usize"),
29 30
 	FLOAT("float"),
30 31
 	DOUBLE("double"),
31 32
 	CHAR("char"),

+ 4
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java Ver fichero

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

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

@@ -37,6 +37,7 @@ public class GlobalTypeRegistry {
37 37
 		arrayTypes.put(ArrayTypeID.CHAR, ArrayTypeID.CHAR);
38 38
 		
39 39
 		rangeTypes.put(RangeTypeID.INT, RangeTypeID.INT);
40
+		rangeTypes.put(RangeTypeID.USIZE, RangeTypeID.USIZE);
40 41
 	}
41 42
 	
42 43
 	public ArrayTypeID getArray(ITypeID baseType, int dimension) {
@@ -89,8 +90,8 @@ public class GlobalTypeRegistry {
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 95
 		if (rangeTypes.containsKey(id)) {
95 96
 			return rangeTypes.get(id);
96 97
 		} else {

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java Ver fichero

@@ -149,7 +149,7 @@ public interface ITypeID {
149 149
 				if (functionType.header.parameters.length != function.header.parameters.length)
150 150
 					return false;
151 151
 				
152
-				if (!match(functionType.header.returnType, function.header.returnType))
152
+				if (!match(functionType.header.getReturnType(), function.header.getReturnType()))
153 153
 					return false;
154 154
 				
155 155
 				for (int i = 0; i < function.header.parameters.length; i++) {
@@ -199,7 +199,7 @@ public interface ITypeID {
199 199
 		public Boolean visitRange(RangeTypeID range) {
200 200
 			if (type instanceof RangeTypeID) {
201 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 203
 			} else {
204 204
 				return false;
205 205
 			}

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

@@ -14,20 +14,19 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
14 14
  * @author Hoofdgebruiker
15 15
  */
16 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 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 27
 			normalized = this;
29 28
 		} else {
30
-			normalized = registry.getRange(from.getNormalized(), to.getNormalized());
29
+			normalized = registry.getRange(baseType.getNormalized());
31 30
 		}
32 31
 	}
33 32
 	
@@ -38,9 +37,7 @@ public class RangeTypeID implements ITypeID {
38 37
 	
39 38
 	@Override
40 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 43
 	@Override
@@ -70,7 +67,7 @@ public class RangeTypeID implements ITypeID {
70 67
 
71 68
 	@Override
72 69
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
73
-		return from.hasInferenceBlockingTypeParameters(parameters) || to.hasInferenceBlockingTypeParameters(parameters);
70
+		return baseType.hasInferenceBlockingTypeParameters(parameters);
74 71
 	}
75 72
 
76 73
 	@Override
@@ -80,15 +77,13 @@ public class RangeTypeID implements ITypeID {
80 77
 
81 78
 	@Override
82 79
 	public void extractTypeParameters(List<TypeParameter> typeParameters) {
83
-		from.extractTypeParameters(typeParameters);
84
-		to.extractTypeParameters(typeParameters);
80
+		baseType.extractTypeParameters(typeParameters);
85 81
 	}
86 82
 
87 83
 	@Override
88 84
 	public int hashCode() {
89 85
 		int hash = 5;
90
-		hash = 89 * hash + from.hashCode();
91
-		hash = 89 * hash + to.hashCode();
86
+		hash = 89 * hash + baseType.hashCode();
92 87
 		return hash;
93 88
 	}
94 89
 
@@ -104,11 +99,11 @@ public class RangeTypeID implements ITypeID {
104 99
 			return false;
105 100
 		}
106 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 105
 	@Override
111 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 Ver fichero

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

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

@@ -38,6 +38,7 @@ public enum BuiltinID {
38 38
 	BYTE_TO_UINT,
39 39
 	BYTE_TO_LONG,
40 40
 	BYTE_TO_ULONG,
41
+	BYTE_TO_USIZE,
41 42
 	BYTE_TO_FLOAT,
42 43
 	BYTE_TO_DOUBLE,
43 44
 	BYTE_TO_CHAR,
@@ -67,6 +68,7 @@ public enum BuiltinID {
67 68
 	SBYTE_TO_UINT,
68 69
 	SBYTE_TO_LONG,
69 70
 	SBYTE_TO_ULONG,
71
+	SBYTE_TO_USIZE,
70 72
 	SBYTE_TO_FLOAT,
71 73
 	SBYTE_TO_DOUBLE,
72 74
 	SBYTE_TO_CHAR,
@@ -96,6 +98,7 @@ public enum BuiltinID {
96 98
 	SHORT_TO_UINT,
97 99
 	SHORT_TO_LONG,
98 100
 	SHORT_TO_ULONG,
101
+	SHORT_TO_USIZE,
99 102
 	SHORT_TO_FLOAT,
100 103
 	SHORT_TO_DOUBLE,
101 104
 	SHORT_TO_CHAR,
@@ -124,6 +127,7 @@ public enum BuiltinID {
124 127
 	USHORT_TO_UINT,
125 128
 	USHORT_TO_LONG,
126 129
 	USHORT_TO_ULONG,
130
+	USHORT_TO_USIZE,
127 131
 	USHORT_TO_FLOAT,
128 132
 	USHORT_TO_DOUBLE,
129 133
 	USHORT_TO_CHAR,
@@ -156,6 +160,7 @@ public enum BuiltinID {
156 160
 	INT_TO_UINT,
157 161
 	INT_TO_LONG,
158 162
 	INT_TO_ULONG,
163
+	INT_TO_USIZE,
159 164
 	INT_TO_FLOAT,
160 165
 	INT_TO_DOUBLE,
161 166
 	INT_TO_CHAR,
@@ -195,6 +200,7 @@ public enum BuiltinID {
195 200
 	UINT_TO_INT,
196 201
 	UINT_TO_LONG,
197 202
 	UINT_TO_ULONG,
203
+	UINT_TO_USIZE,
198 204
 	UINT_TO_FLOAT,
199 205
 	UINT_TO_DOUBLE,
200 206
 	UINT_TO_CHAR,
@@ -236,6 +242,7 @@ public enum BuiltinID {
236 242
 	LONG_TO_INT,
237 243
 	LONG_TO_UINT,
238 244
 	LONG_TO_ULONG,
245
+	LONG_TO_USIZE,
239 246
 	LONG_TO_FLOAT,
240 247
 	LONG_TO_DOUBLE,
241 248
 	LONG_TO_CHAR,
@@ -275,6 +282,7 @@ public enum BuiltinID {
275 282
 	ULONG_TO_INT,
276 283
 	ULONG_TO_UINT,
277 284
 	ULONG_TO_LONG,
285
+	ULONG_TO_USIZE,
278 286
 	ULONG_TO_FLOAT,
279 287
 	ULONG_TO_DOUBLE,
280 288
 	ULONG_TO_CHAR,
@@ -293,6 +301,47 @@ public enum BuiltinID {
293 301
 	ULONG_LOWEST_ZERO_BIT,
294 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 345
 	FLOAT_NEG,
297 346
 	FLOAT_INC,
298 347
 	FLOAT_DEC,
@@ -310,6 +359,7 @@ public enum BuiltinID {
310 359
 	FLOAT_TO_UINT,
311 360
 	FLOAT_TO_LONG,
312 361
 	FLOAT_TO_ULONG,
362
+	FLOAT_TO_USIZE,
313 363
 	FLOAT_TO_DOUBLE,
314 364
 	FLOAT_TO_STRING,
315 365
 	FLOAT_BITS,
@@ -335,6 +385,7 @@ public enum BuiltinID {
335 385
 	DOUBLE_TO_UINT,
336 386
 	DOUBLE_TO_LONG,
337 387
 	DOUBLE_TO_ULONG,
388
+	DOUBLE_TO_USIZE,
338 389
 	DOUBLE_TO_FLOAT,
339 390
 	DOUBLE_TO_STRING,
340 391
 	DOUBLE_BITS,
@@ -355,6 +406,7 @@ public enum BuiltinID {
355 406
 	CHAR_TO_UINT,
356 407
 	CHAR_TO_LONG,
357 408
 	CHAR_TO_ULONG,
409
+	CHAR_TO_USIZE,
358 410
 	CHAR_TO_STRING,
359 411
 	CHAR_GET_MIN_VALUE,
360 412
 	CHAR_GET_MAX_VALUE,

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

@@ -24,7 +24,6 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
24 24
 import org.openzen.zenscript.codemodel.type.ITypeID;
25 25
 import org.openzen.zenscript.codemodel.CompareType;
26 26
 import org.openzen.zenscript.codemodel.FunctionHeader;
27
-import org.openzen.zenscript.codemodel.GenericMapper;
28 27
 import org.openzen.zenscript.codemodel.expression.ConstExpression;
29 28
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
30 29
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
@@ -263,7 +262,7 @@ public class DefinitionMemberGroup {
263 262
 			if (header.typeParameters != null) {
264 263
 				for (ITypeID resultHint : typeHints) {
265 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 266
 						header = header.withGenericArguments(scope.getTypeRegistry(), scope.getLocalTypeParameters().getInner(scope.getTypeRegistry(), mapping));
268 267
 						break;
269 268
 					}
@@ -361,7 +360,7 @@ public class DefinitionMemberGroup {
361 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 364
 				if (!(method.member.isStatic() ? allowStatic : allowNonStatic)) {
366 365
 					message.append(method.member.isStatic() ? "Method must not be static" : "Method must be static").append('\n');
367 366
 					continue;

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

@@ -69,6 +69,7 @@ import static org.openzen.zencode.shared.CodePosition.BUILTIN;
69 69
 import org.openzen.zencode.shared.CompileException;
70 70
 import org.openzen.zencode.shared.CompileExceptionCode;
71 71
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
72
+import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
72 73
 import org.openzen.zenscript.codemodel.member.IteratorMember;
73 74
 
74 75
 /**
@@ -149,6 +150,9 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
149 150
 			case ULONG:
150 151
 				visitULong();
151 152
 				break;
153
+			case USIZE:
154
+				visitUSize();
155
+				break;
152 156
 			case FLOAT:
153 157
 				visitFloat();
154 158
 				break;
@@ -174,7 +178,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
174 178
 
175 179
 		FunctionParameter[] indexGetParameters = new FunctionParameter[dimension];
176 180
 		for (int i = 0; i < indexGetParameters.length; i++)
177
-			indexGetParameters[i] = new FunctionParameter(INT);
181
+			indexGetParameters[i] = new FunctionParameter(USIZE);
178 182
 		
179 183
 		operator(
180 184
 				definition,
@@ -183,7 +187,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
183 187
 				ARRAY_INDEXGET);
184 188
 		
185 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 191
 			operator(
188 192
 					definition,
189 193
 					OperatorType.INDEXGET,
@@ -209,7 +213,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
209 213
 
210 214
 		FunctionParameter[] initialValueConstructorParameters = new FunctionParameter[dimension + 1];
211 215
 		for (int i = 0; i < dimension; i++)
212
-			initialValueConstructorParameters[i] = new FunctionParameter(INT);
216
+			initialValueConstructorParameters[i] = new FunctionParameter(USIZE);
213 217
 		initialValueConstructorParameters[dimension] = new FunctionParameter(baseType);
214 218
 		FunctionHeader initialValueConstructorHeader = new FunctionHeader(VOID, initialValueConstructorParameters);
215 219
 		new ConstructorMember(
@@ -222,7 +226,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
222 226
 		
223 227
 		FunctionParameter[] lambdaConstructorParameters = new FunctionParameter[dimension + 1];
224 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 231
 		FunctionHeader lambdaConstructorFunction = new FunctionHeader(baseType, indexGetParameters);
228 232
 		lambdaConstructorParameters[dimension] = new FunctionParameter(cache.getRegistry().getFunction(lambdaConstructorFunction), null);
@@ -255,7 +259,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
255 259
 			TypeParameter mappedConstructorParameter = new TypeParameter(BUILTIN, "T");
256 260
 			FunctionParameter[] projectionParameters = new FunctionParameter[dimension + 1];
257 261
 			for (int i = 0; i < dimension; i++)
258
-				projectionParameters[i] = new FunctionParameter(INT);
262
+				projectionParameters[i] = new FunctionParameter(USIZE);
259 263
 			projectionParameters[dimension] = new FunctionParameter(registry.getGeneric(mappedConstructorParameter));
260 264
 			
261 265
 			FunctionHeader mappedConstructorHeaderWithIndex = new FunctionHeader(baseType, projectionParameters);
@@ -270,20 +274,20 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
270 274
 		
271 275
 		FunctionParameter[] indexSetParameters = new FunctionParameter[dimension + 1];
272 276
 		for (int i = 0; i < dimension; i++)
273
-			indexSetParameters[i] = new FunctionParameter(INT, null);
277
+			indexSetParameters[i] = new FunctionParameter(USIZE, null);
274 278
 		indexSetParameters[dimension] = new FunctionParameter(baseType, null);
275 279
 
276 280
 		FunctionHeader indexSetHeader = new FunctionHeader(VOID, indexSetParameters);
277 281
 		operator(definition, OperatorType.INDEXSET, indexSetHeader, ARRAY_INDEXSET);
278 282
 		
279 283
 		if (dimension == 1) {
280
-			getter(definition, ARRAY_LENGTH, "length", INT);
284
+			getter(definition, ARRAY_LENGTH, "length", USIZE);
281 285
 		}
282 286
 
283 287
 		getter(definition, ARRAY_ISEMPTY, "isEmpty", BOOL);
284 288
 		getter(definition, ARRAY_HASHCODE, "objectHashCode", INT);
285 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 292
 		equals(definition, ARRAY_EQUALS, array);
289 293
 		notequals(definition, ARRAY_NOTEQUALS, array);
@@ -314,7 +318,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
314 318
 				new FunctionHeader(BOOL, new FunctionParameter(keyType, "key")),
315 319
 				ASSOC_CONTAINS);
316 320
 		
317
-		getter(builtin, BuiltinID.ASSOC_SIZE, "size", INT);
321
+		getter(builtin, BuiltinID.ASSOC_SIZE, "size", USIZE);
318 322
 		getter(builtin, BuiltinID.ASSOC_ISEMPTY, "isEmpty", BOOL);
319 323
 		getter(builtin, BuiltinID.ASSOC_KEYS, "keys", cache.getRegistry().getArray(keyType, 1));
320 324
 		getter(builtin, BuiltinID.ASSOC_VALUES, "values", cache.getRegistry().getArray(valueType, 1));
@@ -350,7 +354,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
350 354
 		method(builtin, "contains", containsHeader, GENERICMAP_CONTAINS);
351 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 358
 		getter(builtin, GENERICMAP_ISEMPTY, "isEmpty", BOOL);
355 359
 		getter(builtin, GENERICMAP_HASHCODE, "objectHashCode", INT);
356 360
 		
@@ -443,7 +447,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
443 447
 		
444 448
 		if (definition instanceof EnumDefinition) {
445 449
 			getter(definition, ENUM_NAME, "name", STRING);
446
-			getter(definition, ENUM_ORDINAL, "ordinal", INT);
450
+			getter(definition, ENUM_ORDINAL, "ordinal", USIZE);
447 451
 			
448 452
 			List<EnumConstantMember> enumConstants = ((EnumDefinition) definition).enumConstants;
449 453
 			Expression[] constValues = new Expression[enumConstants.size()];
@@ -490,23 +494,22 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
490 494
 
491 495
 	@Override
492 496
 	public Void visitRange(RangeTypeID range) {
493
-		ITypeID fromType = range.from;
494
-		ITypeID toType = range.to;
497
+		ITypeID baseType = range.baseType;
495 498
 
496 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 515
 		processType(definition, range);
@@ -564,6 +567,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
564 567
 		castImplicit(builtin, BYTE_TO_UINT, UINT);
565 568
 		castImplicit(builtin, BYTE_TO_LONG, LONG);
566 569
 		castImplicit(builtin, BYTE_TO_ULONG, ULONG);
570
+		castImplicit(builtin, BYTE_TO_USIZE, USIZE);
567 571
 		castImplicit(builtin, BYTE_TO_FLOAT, FLOAT);
568 572
 		castImplicit(builtin, BYTE_TO_DOUBLE, DOUBLE);
569 573
 		castExplicit(builtin, BYTE_TO_CHAR, CHAR);
@@ -602,6 +606,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
602 606
 		castImplicit(builtin, SBYTE_TO_UINT, UINT);
603 607
 		castImplicit(builtin, SBYTE_TO_LONG, LONG);
604 608
 		castImplicit(builtin, SBYTE_TO_ULONG, ULONG);
609
+		castImplicit(builtin, SBYTE_TO_USIZE, USIZE);
605 610
 		castImplicit(builtin, SBYTE_TO_FLOAT, FLOAT);
606 611
 		castImplicit(builtin, SBYTE_TO_DOUBLE, DOUBLE);
607 612
 		castExplicit(builtin, SBYTE_TO_CHAR, CHAR);
@@ -640,6 +645,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
640 645
 		castImplicit(builtin, SHORT_TO_UINT, UINT);
641 646
 		castImplicit(builtin, SHORT_TO_LONG, LONG);
642 647
 		castImplicit(builtin, SHORT_TO_ULONG, ULONG);
648
+		castImplicit(builtin, SHORT_TO_USIZE, USIZE);
643 649
 		castImplicit(builtin, SHORT_TO_FLOAT, FLOAT);
644 650
 		castImplicit(builtin, SHORT_TO_DOUBLE, DOUBLE);
645 651
 		castExplicit(builtin, SHORT_TO_CHAR, CHAR);
@@ -677,6 +683,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
677 683
 		castImplicit(builtin, USHORT_TO_UINT, UINT);
678 684
 		castImplicit(builtin, USHORT_TO_LONG, LONG);
679 685
 		castImplicit(builtin, USHORT_TO_ULONG, ULONG);
686
+		castImplicit(builtin, USHORT_TO_USIZE, USIZE);
680 687
 		castImplicit(builtin, USHORT_TO_FLOAT, FLOAT);
681 688
 		castImplicit(builtin, USHORT_TO_DOUBLE, DOUBLE);
682 689
 		castExplicit(builtin, USHORT_TO_CHAR, CHAR);
@@ -748,6 +755,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
748 755
 		castImplicit(builtin, INT_TO_UINT, UINT);
749 756
 		castImplicit(builtin, INT_TO_LONG, LONG);
750 757
 		castImplicit(builtin, INT_TO_ULONG, ULONG);
758
+		castImplicit(builtin, INT_TO_USIZE, USIZE);
751 759
 		castImplicit(builtin, INT_TO_FLOAT, FLOAT);
752 760
 		castImplicit(builtin, INT_TO_DOUBLE, DOUBLE);
753 761
 		castExplicit(builtin, INT_TO_CHAR, CHAR);
@@ -826,6 +834,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
826 834
 		castImplicit(builtin, UINT_TO_INT, INT);
827 835
 		castImplicit(builtin, UINT_TO_LONG, LONG);
828 836
 		castImplicit(builtin, UINT_TO_ULONG, ULONG);
837
+		castImplicit(builtin, UINT_TO_USIZE, USIZE);
829 838
 		castImplicit(builtin, UINT_TO_FLOAT, FLOAT);
830 839
 		castImplicit(builtin, UINT_TO_DOUBLE, DOUBLE);
831 840
 		castExplicit(builtin, UINT_TO_CHAR, CHAR);
@@ -897,6 +906,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
897 906
 		castExplicit(builtin, LONG_TO_INT, INT);
898 907
 		castExplicit(builtin, LONG_TO_UINT, UINT);
899 908
 		castImplicit(builtin, LONG_TO_ULONG, ULONG);
909
+		castExplicit(builtin, LONG_TO_USIZE, USIZE);
900 910
 		castImplicit(builtin, LONG_TO_FLOAT, FLOAT);
901 911
 		castImplicit(builtin, LONG_TO_DOUBLE, DOUBLE);
902 912
 		castExplicit(builtin, LONG_TO_CHAR, CHAR);
@@ -966,6 +976,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
966 976
 		castExplicit(builtin, ULONG_TO_INT, INT);
967 977
 		castExplicit(builtin, ULONG_TO_UINT, UINT);
968 978
 		castImplicit(builtin, ULONG_TO_LONG, LONG);
979
+		castExplicit(builtin, ULONG_TO_USIZE, USIZE);
969 980
 		castImplicit(builtin, ULONG_TO_FLOAT, FLOAT);
970 981
 		castImplicit(builtin, ULONG_TO_DOUBLE, DOUBLE);
971 982
 		castExplicit(builtin, ULONG_TO_CHAR, CHAR);
@@ -989,6 +1000,82 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
989 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 1079
 	private void visitFloat() {
993 1080
 		ClassDefinition builtin = new ClassDefinition(BUILTIN, null, "float", Modifiers.EXPORT, null);
994 1081
 		
@@ -1020,15 +1107,16 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1020 1107
 		castExplicit(builtin, FLOAT_TO_USHORT, USHORT);
1021 1108
 		castExplicit(builtin, FLOAT_TO_INT, INT);
1022 1109
 		castExplicit(builtin, FLOAT_TO_UINT, UINT);
1110
+		castExplicit(builtin, FLOAT_TO_LONG, LONG);
1023 1111
 		castExplicit(builtin, FLOAT_TO_ULONG, ULONG);
1024
-		castExplicit(builtin, FLOAT_TO_ULONG, ULONG);
1112
+		castExplicit(builtin, FLOAT_TO_USIZE, USIZE);
1025 1113
 		castImplicit(builtin, FLOAT_TO_DOUBLE, DOUBLE);
1026 1114
 		castImplicit(builtin, FLOAT_TO_STRING, STRING);
1027 1115
 		
1028 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 1121
 		processType(builtin, FLOAT);
1034 1122
 	}
@@ -1057,13 +1145,14 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1057 1145
 		castExplicit(builtin, DOUBLE_TO_UINT, UINT);
1058 1146
 		castExplicit(builtin, DOUBLE_TO_ULONG, ULONG);
1059 1147
 		castExplicit(builtin, DOUBLE_TO_ULONG, ULONG);
1148
+		castExplicit(builtin, DOUBLE_TO_USIZE, USIZE);
1060 1149
 		castImplicit(builtin, DOUBLE_TO_FLOAT, FLOAT);
1061 1150
 		castImplicit(builtin, DOUBLE_TO_STRING, STRING);
1062 1151
 		
1063 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 1157
 		processType(builtin, DOUBLE);
1069 1158
 	}
@@ -1084,6 +1173,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1084 1173
 		castImplicit(builtin, CHAR_TO_UINT, UINT);
1085 1174
 		castImplicit(builtin, CHAR_TO_LONG, LONG);
1086 1175
 		castImplicit(builtin, CHAR_TO_ULONG, ULONG);
1176
+		castImplicit(builtin, CHAR_TO_USIZE, USIZE);
1087 1177
 		castImplicit(builtin, CHAR_TO_STRING, STRING);
1088 1178
 		
1089 1179
 		getter(builtin, CHAR_GET_MIN_VALUE, "MIN_VALUE", CHAR);
@@ -1102,11 +1192,11 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1102 1192
 		constructor(builtin, STRING_CONSTRUCTOR_CHARACTERS, registry.getArray(CHAR, 1));
1103 1193
 		
1104 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 1197
 		compare(builtin, STRING_COMPARE, STRING);
1108 1198
 		
1109
-		getter(builtin, STRING_LENGTH, "length", INT);
1199
+		getter(builtin, STRING_LENGTH, "length", USIZE);
1110 1200
 		getter(builtin, STRING_CHARACTERS, "characters", registry.getArray(CHAR, 1));
1111 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 Ver fichero

@@ -3,20 +3,22 @@
3 3
  * To change this template file, choose Tools | Templates
4 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 8
 import org.openzen.zenscript.compiler.SemanticModule;
9 9
 import java.util.ArrayList;
10 10
 import java.util.HashMap;
11 11
 import java.util.List;
12 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 16
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14 17
 import org.openzen.zenscript.codemodel.annotations.NativeAnnotationDefinition;
15 18
 import org.openzen.zenscript.codemodel.annotations.PreconditionAnnotationDefinition;
16 19
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
17 20
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18 21
 import org.openzen.zenscript.compiler.CompilationUnit;
19
-import org.openzen.zenscript.constructor.ConstructorException;
20 22
 import org.openzen.zenscript.codemodel.type.ISymbol;
21 23
 
22 24
 /**
@@ -45,7 +47,7 @@ public final class ModuleSpace {
45 47
 		
46 48
 		for (Map.Entry<String, ISymbol> globalEntry : dependency.globals.entrySet()) {
47 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 52
 			globals.put(globalEntry.getKey(), globalEntry.getValue());
51 53
 		}

+ 0
- 84
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java Ver fichero

@@ -10,26 +10,15 @@ import java.io.File;
10 10
 import java.io.FileInputStream;
11 11
 import java.io.IOException;
12 12
 import java.util.ArrayList;
13
-import java.util.Collections;
14 13
 import java.util.List;
15
-import java.util.Map;
16 14
 import java.util.function.Consumer;
17 15
 import org.json.JSONArray;
18 16
 import org.json.JSONObject;
19 17
 import org.json.JSONTokener;
20 18
 import org.openzen.zencode.shared.CompileException;
21
-import org.openzen.zenscript.codemodel.PackageDefinitions;
22
-import org.openzen.zenscript.codemodel.ScriptBlock;
23 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 20
 import org.openzen.zenscript.parser.BracketExpressionParser;
31 21
 import org.openzen.zenscript.parser.ParsedFile;
32
-import org.openzen.zenscript.parser.PrecompilationState;
33 22
 
34 23
 /**
35 24
  *
@@ -86,77 +75,4 @@ public class Module {
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 Ver fichero

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.constructor.module;
7 7
 
8
+import org.openzen.zenscript.compiler.ModuleSpace;
8 9
 import org.openzen.zenscript.compiler.SemanticModule;
9 10
 import java.io.File;
10 11
 import java.io.IOException;
@@ -84,7 +85,7 @@ public class DirectoryModuleReference implements ModuleReference {
84 85
 			CompilingPackage compilingPackage = new CompilingPackage(pkg);
85 86
 			
86 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 90
 			JSONObject globals = json.optJSONObject("globals");
90 91
 			if (globals != null) {

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

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

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

@@ -887,6 +887,7 @@ public class SourceEditor implements DComponent {
887 887
 				case K_UINT:
888 888
 				case K_LONG:
889 889
 				case K_ULONG:
890
+				case K_USIZE:
890 891
 				case K_FLOAT:
891 892
 				case K_DOUBLE:
892 893
 				case K_CHAR:

+ 9
- 12
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java Ver fichero

@@ -5,12 +5,9 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode;
7 7
 
8
-import java.io.FileOutputStream;
9
-import java.io.IOException;
10 8
 import java.util.HashMap;
11 9
 import java.util.Map;
12 10
 import org.objectweb.asm.ClassWriter;
13
-import org.objectweb.asm.MethodVisitor;
14 11
 import org.objectweb.asm.Opcodes;
15 12
 import org.objectweb.asm.Type;
16 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
@@ -89,7 +86,7 @@ public class JavaBytecodeContext extends JavaContext {
89 86
 		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createRangeName(type);
90 87
 		ranges.put(signature, result);
91 88
 		
92
-		createRangeClass(type.from, type.to, result.cls);
89
+		createRangeClass(type.baseType, result.cls);
93 90
 		return result;
94 91
 	}
95 92
 
@@ -110,22 +107,22 @@ public class JavaBytecodeContext extends JavaContext {
110 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 111
 		ClassWriter rangeWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
115 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 117
 		JavaWriter constructorWriter = new JavaWriter(rangeWriter, method, null, method.descriptor, null);
121 118
 		constructorWriter.loadObject(0);
122 119
 		constructorWriter.invokeSpecial("java/lang/Object", "<init>", "()V");
123 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 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 126
 		constructorWriter.ret();
130 127
 		constructorWriter.end();
131 128
 		

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

@@ -41,6 +41,7 @@ public class JavaBoxingTypeVisitor implements ITypeVisitor<Void> {
41 41
 				break;
42 42
 			case INT:
43 43
 			case UINT:
44
+			case USIZE:
44 45
 				method = INTEGER_VALUEOF;
45 46
 				break;
46 47
 			case LONG:

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

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

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

@@ -6,74 +6,7 @@
6 6
 package org.openzen.zenscript.javabytecode.compiler;
7 7
 
8 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 10
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
78 11
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
79 12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
@@ -233,6 +166,11 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
233 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 174
 	@Override
237 175
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
238 176
 		throw new UnsupportedOperationException("Invalid increment target");

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

@@ -6,74 +6,7 @@
6 6
 package org.openzen.zenscript.javabytecode.compiler;
7 7
 
8 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 10
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
78 11
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
79 12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
@@ -233,6 +166,11 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
233 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 174
 	@Override
237 175
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
238 176
 		throw new UnsupportedOperationException("Invalid increment target");

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

@@ -142,7 +142,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
142 142
         statementVisitor.start();
143 143
 		boolean returns = definition.statement.accept(statementVisitor);
144 144
 		if (!returns) {
145
-			ITypeID type = definition.header.returnType;
145
+			ITypeID type = definition.header.getReturnType();
146 146
 			if (CompilerUtils.isPrimitive(type))
147 147
 				writer.iConst0();
148 148
 			else if (type != BasicTypeID.VOID)

+ 2
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java Ver fichero

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

+ 3
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java Ver fichero

@@ -46,6 +46,7 @@ public class JavaSyntheticTypeSignatureConverter implements ITypeVisitor<String>
46 46
 			case UINT: return "UInt";
47 47
 			case LONG: return "Long";
48 48
 			case ULONG: return "ULong";
49
+			case USIZE: return "USize";
49 50
 			case FLOAT: return "Float";
50 51
 			case DOUBLE: return "Double";
51 52
 			case CHAR: return "Char";
@@ -94,7 +95,7 @@ public class JavaSyntheticTypeSignatureConverter implements ITypeVisitor<String>
94 95
 		for (FunctionParameter parameter : function.header.parameters)
95 96
 			result.append(parameter.type.accept(this));
96 97
 		result.append("To");
97
-		result.append(function.header.returnType.accept(this));
98
+		result.append(function.header.getReturnType().accept(this));
98 99
 		if (function.header.thrownType != null) {
99 100
 			result.append("Throwing");
100 101
 			result.append(function.header.thrownType.accept(this));
@@ -129,9 +130,7 @@ public class JavaSyntheticTypeSignatureConverter implements ITypeVisitor<String>
129 130
 	@Override
130 131
 	public String visitRange(RangeTypeID range) {
131 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 134
 		result.append("Range");
136 135
 		return result.toString();
137 136
 	}

+ 8
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java Ver fichero

@@ -33,6 +33,7 @@ public class JavaTypeDescriptorVisitor implements ITypeVisitor<String> {
33 33
 				case UINT: return "Ljava/lang/Integer;";
34 34
 				case LONG: return "Ljava/lang/Long;";
35 35
 				case ULONG: return "Ljava/lang/Long;";
36
+				case USIZE: return "I"; // special case: optional usize fits in an int where null = -1
36 37
 				case FLOAT: return "Ljava/lang/Float;";
37 38
 				case DOUBLE: return "Ljava/lang/Double;";
38 39
 				case STRING: return "Ljava/lang/String;";
@@ -52,6 +53,7 @@ public class JavaTypeDescriptorVisitor implements ITypeVisitor<String> {
52 53
 				case UINT: return "I";
53 54
 				case LONG: return "J";
54 55
 				case ULONG: return "J";
56
+				case USIZE: return "I";
55 57
 				case FLOAT: return "F";
56 58
 				case DOUBLE: return "D";
57 59
 				case STRING: return "Ljava/lang/String;";
@@ -63,7 +65,12 @@ public class JavaTypeDescriptorVisitor implements ITypeVisitor<String> {
63 65
 
64 66
     @Override
65 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 76
     @Override

+ 2
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java Ver fichero

@@ -33,6 +33,7 @@ public class JavaTypeInternalNameVisitor implements ITypeVisitor<String> {
33 33
 				case UINT: return "java/lang/Integer";
34 34
 				case LONG: return "java/lang/Long";
35 35
 				case ULONG: return "java/lang/Long";
36
+				case USIZE: return "java/lang/Integer";
36 37
 				case FLOAT: return "java/lang/Float";
37 38
 				case DOUBLE: return "java/lang/Double";
38 39
 				case STRING: return "java/lang/String";
@@ -52,6 +53,7 @@ public class JavaTypeInternalNameVisitor implements ITypeVisitor<String> {
52 53
 				case UINT: return "I";
53 54
 				case LONG: return "J";
54 55
 				case ULONG: return "J";
56
+				case USIZE: return "I";
55 57
 				case FLOAT: return "F";
56 58
 				case DOUBLE: return "D";
57 59
 				case STRING: return "java/lang/String";

+ 2
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeNameVisitor.java Ver fichero

@@ -76,7 +76,7 @@ public class JavaTypeNameVisitor implements ITypeVisitor<String> {
76 76
 		for (FunctionParameter parameter : function.header.parameters)
77 77
 			result.append(parameter.type.accept(this));
78 78
 		result.append("To");
79
-		result.append(function.header.returnType.accept(this));
79
+		result.append(function.header.getReturnType().accept(this));
80 80
 		result.append("Function");
81 81
 		return result.toString();
82 82
 	}
@@ -93,9 +93,7 @@ public class JavaTypeNameVisitor implements ITypeVisitor<String> {
93 93
 
94 94
 	@Override
95 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 99
 	@Override

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

@@ -30,6 +30,7 @@ import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
30 30
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
31 31
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
32 32
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
33
+import org.openzen.zenscript.codemodel.type.member.BuiltinID;
33 34
 import org.openzen.zenscript.javashared.JavaTypeNameVisitor;
34 35
 import org.openzen.zenscript.javashared.JavaClass;
35 36
 import org.openzen.zenscript.javashared.JavaField;
@@ -299,7 +300,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
299 300
 					true,
300 301
 					context.getMethodDescriptor(header),
301 302
 					JavaModifiers.getJavaModifiers(member.modifiers),
302
-					header.returnType instanceof GenericTypeID);
303
+					header.getReturnType() instanceof GenericTypeID);
303 304
 		} else if (method == null) {
304 305
 			method = new JavaMethod(
305 306
 					cls,
@@ -308,10 +309,10 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
308 309
 					true,
309 310
 					context.getMethodDescriptor(header),
310 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 316
 			if (DEBUG_EMPTY && cls.empty)
316 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 Ver fichero

@@ -44,6 +44,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
44 44
 			return;
45 45
 			
46 46
 		HighLevelDefinition definition = ((DefinitionTypeID)type).definition;
47
+		System.out.println("Preparing " + definition.name);
47 48
 		definition.accept(this);
48 49
 	}
49 50
 	

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

@@ -55,6 +55,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
55 55
 			cls.addInstanceMethod("appendUInt", "append", "(I)Ljava/lang/StringBuilder;");
56 56
 			cls.addInstanceMethod("appendLong", "append", "(J)Ljava/lang/StringBuilder;");
57 57
 			cls.addInstanceMethod("appendULong", "append", "(J)Ljava/lang/StringBuilder;");
58
+			cls.addInstanceMethod("appendUSize", "append", "(I)Ljava/lang/StringBuilder;");
58 59
 			cls.addInstanceMethod("appendFloat", "append", "(F)Ljava/lang/StringBuilder;");
59 60
 			cls.addInstanceMethod("appendDouble", "append", "(D)Ljava/lang/StringBuilder;");
60 61
 			cls.addInstanceMethod("appendChar", "append", "(C)Ljava/lang/StringBuilder;");
@@ -110,6 +111,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
110 111
 			cls.addMethod("max", JavaMethod.getNativeStatic(math, "max", "(II)I"));
111 112
 			cls.addMethod("toHexString", JavaMethod.getNativeExpansion(integer, "toHexString", "(I)Ljava/lang/String;"));
112 113
 			nativeClasses.put("stdlib::Integer", cls);
114
+			nativeClasses.put("stdlib::USize", cls);
113 115
 		}
114 116
 		
115 117
 		{
@@ -188,6 +190,24 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
188 190
 			cls.addInstanceMethod("readSlice", "read", "([CII)I");
189 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 213
 	private final String filename;

+ 1
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java Ver fichero

@@ -161,7 +161,7 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
161 161
 		if (nativeTag != null && nativeClass != null)
162 162
 			method = nativeClass.getMethod(nativeTag.value);
163 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 166
 		if (method.compile) {
167 167
 			if (DEBUG_EMPTY && cls.empty)

+ 6
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java Ver fichero

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

+ 3
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java Ver fichero

@@ -7,7 +7,6 @@ package org.openzen.zenscript.javasource;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.FunctionHeader;
9 9
 import org.openzen.zenscript.codemodel.FunctionParameter;
10
-import org.openzen.zenscript.codemodel.Modifiers;
11 10
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12 11
 import org.openzen.zenscript.codemodel.expression.Expression;
13 12
 import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
@@ -39,15 +38,15 @@ public class FormattingUtils {
39 38
 			
40 39
 			if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
41 40
 				result.append(" as ");
42
-				result.append(header.returnType.accept(typeFormatter));
41
+				result.append(header.getReturnType().accept(typeFormatter));
43 42
 			}
44 43
 			
45 44
 			parameterIndex++;
46 45
 		}
47 46
 		result.append(")");
48
-		if (!settings.showAnyInFunctionHeaders || header.returnType != BasicTypeID.UNDETERMINED) {
47
+		if (!settings.showAnyInFunctionHeaders || header.getReturnType() != BasicTypeID.UNDETERMINED) {
49 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 Ver fichero

@@ -190,8 +190,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
190 190
 				output.append(",\n");
191 191
 			}
192 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 194
 				output.append("(");
196 195
 				boolean first = true;
197 196
 				for (Expression argument : constant.constructor.arguments.arguments) {

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java Ver fichero

@@ -71,7 +71,7 @@ public class JavaExpansionMemberCompiler extends BaseMemberCompiler {
71 71
 		else
72 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 75
 		output.append(" ");
76 76
 		output.append(method.name);
77 77
 		formatParameters(member.isStatic(), expansionTypeParameters, header);

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Ver fichero

@@ -93,7 +93,7 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
93 93
 		
94 94
 		modifiers(member.modifiers);
95 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 97
 		output.append(" ");
98 98
 		output.append(method.name);
99 99
 		formatParameters(member.isStatic(), header);

+ 58
- 6
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java Ver fichero

@@ -40,6 +40,7 @@ import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
40 40
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
41 41
 import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
42 42
 import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
43
+import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
43 44
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
44 45
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
45 46
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
@@ -95,7 +96,6 @@ import org.openzen.zenscript.formattershared.StatementFormattingTarget;
95 96
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
96 97
 import org.openzen.zenscript.javashared.JavaClass;
97 98
 import org.openzen.zenscript.javashared.JavaField;
98
-import org.openzen.zenscript.javashared.JavaNativeTranslation;
99 99
 import org.openzen.zenscript.javashared.JavaNativeTranslator;
100 100
 import org.openzen.zenscript.javashared.JavaMethod;
101 101
 import org.openzen.zenscript.javashared.JavaVariantOption;
@@ -362,6 +362,11 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
362 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 370
 	@Override
366 371
 	public ExpressionString visitConstructorThisCall(ConstructorThisCallExpression expression) {
367 372
 		StringBuilder result = new StringBuilder();
@@ -539,6 +544,9 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
539 544
 
540 545
 	@Override
541 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 550
 		return new ExpressionString("null", JavaOperator.PRIMARY);
543 551
 	}
544 552
 
@@ -1044,6 +1052,21 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1044 1052
 			case ULONG_COUNT_HIGH_ZEROES: return callAsStatic("Long.numberOfLeadingZeros", call);
1045 1053
 			case ULONG_COUNT_LOW_ONES: return new ExpressionString("Long.numberOfTrailingZeros(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1046 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 1070
 			case FLOAT_NEG: return unaryPrefix(call, JavaOperator.NEG);
1048 1071
 			case FLOAT_ADD_FLOAT: return binary(call, JavaOperator.ADD);
1049 1072
 			case FLOAT_SUB_FLOAT: return binary(call, JavaOperator.SUB);
@@ -1148,8 +1171,12 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1148 1171
 			case FUNCTION_NOTSAME: return binary(call, JavaOperator.NOTEQUALS);
1149 1172
 			case OBJECT_SAME: return binary(call, JavaOperator.EQUALS);
1150 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 1180
 			case AUTOOP_NOTEQUALS:
1154 1181
 				throw new UnsupportedOperationException("Not yet supported!");
1155 1182
 		}
@@ -1168,8 +1195,12 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1168 1195
 			case SHORT_PARSE_WITH_BASE: return callStatic("Short.parseShort", call);
1169 1196
 			case USHORT_PARSE: return callStatic("Integer.parseShort", call);
1170 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 1204
 			case UINT_PARSE: return callStatic("Integer.parseUnsignedInt", call);
1174 1205
 			case UINT_PARSE_WITH_BASE: return callStatic("Integer.parseUnsignedInt", call);
1175 1206
 			case LONG_PARSE: return callStatic("Long.parseLong", call);
@@ -1197,7 +1228,9 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1197 1228
 					call.left.accept(this).unaryPostfix(JavaOperator.AND_FFFF),
1198 1229
 					call.right.accept(this).unaryPostfix(JavaOperator.AND_FFFF),
1199 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 1234
 			case UINT_COMPARE: return compare(callAsStatic("Integer.compareUnsigned", call.left, call.right), call.comparison);
1202 1235
 			case LONG_COMPARE: return compare(call.left, call.right, call.comparison);
1203 1236
 			case ULONG_COMPARE: return compare(callAsStatic("Long.compareUnsigned", call.left, call.right), call.comparison);
@@ -1221,18 +1254,23 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1221 1254
 		switch (builtin) {
1222 1255
 			case INT_HIGHEST_ONE_BIT:
1223 1256
 			case UINT_HIGHEST_ONE_BIT:
1257
+			case USIZE_HIGHEST_ONE_BIT:
1224 1258
 				return callAsStatic("Integer.highestOneBit", call);
1225 1259
 			case INT_LOWEST_ONE_BIT:
1226 1260
 			case UINT_LOWEST_ONE_BIT:
1261
+			case USIZE_LOWEST_ONE_BIT:
1227 1262
 				return callAsStatic("Integer.lowestOneBit", call);
1228 1263
 			case INT_HIGHEST_ZERO_BIT:
1229 1264
 			case UINT_HIGHEST_ZERO_BIT:
1265
+			case USIZE_HIGHEST_ZERO_BIT:
1230 1266
 				return new ExpressionString("Integer.highestOneBit(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1231 1267
 			case INT_LOWEST_ZERO_BIT:
1232 1268
 			case UINT_LOWEST_ZERO_BIT:
1269
+			case USIZE_LOWEST_ZERO_BIT:
1233 1270
 				return new ExpressionString("Integer.lowestOneBit(~" + call.target.accept(this).value + ")", JavaOperator.CALL);
1234 1271
 			case INT_BIT_COUNT:
1235 1272
 			case UINT_BIT_COUNT:
1273
+			case USIZE_BIT_COUNT:
1236 1274
 				return callAsStatic("Integer.bitCount", call);
1237 1275
 			case LONG_HIGHEST_ONE_BIT:
1238 1276
 			case ULONG_HIGHEST_ONE_BIT:
@@ -1321,6 +1359,9 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1321 1359
 			case LONG_GET_MAX_VALUE: return new ExpressionString("Long.MAX_VALUE", JavaOperator.MEMBER);
1322 1360
 			case ULONG_GET_MIN_VALUE: return new ExpressionString("0", JavaOperator.PRIMARY);
1323 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 1365
 			case FLOAT_GET_MIN_VALUE: return new ExpressionString("Float.MIN_VALUE", JavaOperator.MEMBER);
1325 1366
 			case FLOAT_GET_MAX_VALUE: return new ExpressionString("Float.MAX_VALUE", JavaOperator.MEMBER);
1326 1367
 			case DOUBLE_GET_MIN_VALUE: return new ExpressionString("Double.MIN_VALUE", JavaOperator.MEMBER);
@@ -1342,6 +1383,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1342 1383
 			case BYTE_TO_USHORT: return castPostfix(cast, JavaOperator.AND_FF);
1343 1384
 			case BYTE_TO_INT: return castPostfix(cast, JavaOperator.AND_FF);
1344 1385
 			case BYTE_TO_UINT: return castPostfix(cast, JavaOperator.AND_FF);
1386
+			case BYTE_TO_USIZE: return castPostfix(cast, JavaOperator.AND_FF);
1345 1387
 			case BYTE_TO_LONG: return castPostfix(cast, JavaOperator.AND_FFL);
1346 1388
 			case BYTE_TO_ULONG: return castPostfix(cast, JavaOperator.AND_FFL);
1347 1389
 			case BYTE_TO_FLOAT: cast(castPostfix(cast, JavaOperator.AND_FF), "float");
@@ -1353,6 +1395,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1353 1395
 			case SBYTE_TO_USHORT: return castImplicit(cast, "int");
1354 1396
 			case SBYTE_TO_INT: return castImplicit(cast, "int");
1355 1397
 			case SBYTE_TO_UINT: return castImplicit(cast, "int");
1398
+			case SBYTE_TO_USIZE: return castImplicit(cast, "int");
1356 1399
 			case SBYTE_TO_LONG: return castImplicit(cast, "long");
1357 1400
 			case SBYTE_TO_ULONG: return castImplicit(cast, "long");
1358 1401
 			case SBYTE_TO_FLOAT: return castImplicit(cast, "float");
@@ -1364,6 +1407,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1364 1407
 			case SHORT_TO_USHORT: return castImplicit(cast, "int");
1365 1408
 			case SHORT_TO_INT: return castImplicit(cast, "int");
1366 1409
 			case SHORT_TO_UINT: return castImplicit(cast, "int");
1410
+			case SHORT_TO_USIZE: return castImplicit(cast, "int");
1367 1411
 			case SHORT_TO_LONG: return castImplicit(cast, "long");
1368 1412
 			case SHORT_TO_ULONG: return castImplicit(cast, "long");
1369 1413
 			case SHORT_TO_FLOAT: return castImplicit(cast, "float");
@@ -1377,6 +1421,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1377 1421
 			case USHORT_TO_UINT: return castPostfix(cast, JavaOperator.AND_FFFF);
1378 1422
 			case USHORT_TO_LONG: return castPostfix(cast, JavaOperator.AND_FFFFL);
1379 1423
 			case USHORT_TO_ULONG: return castPostfix(cast, JavaOperator.AND_FFFFL);
1424
+			case USHORT_TO_USIZE: return castPostfix(cast, JavaOperator.AND_FFFF);
1380 1425
 			case USHORT_TO_FLOAT: return cast.isImplicit ? cast.target.accept(this) : cast(castPostfix(cast, JavaOperator.AND_FFFF), "float");
1381 1426
 			case USHORT_TO_DOUBLE: return cast.isImplicit ? cast.target.accept(this) : cast(castPostfix(cast, JavaOperator.AND_FFFF), "double");
1382 1427
 			case USHORT_TO_CHAR: return castImplicit(cast, "char");
@@ -1392,6 +1437,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1392 1437
 			case INT_TO_DOUBLE: return castImplicit(cast, "double");
1393 1438
 			case INT_TO_CHAR: return cast(cast, "char");
1394 1439
 			case INT_TO_STRING: return callStatic("Integer.toString", cast.target);
1440
+			case INT_TO_USIZE: return cast.target.accept(this);
1395 1441
 			case UINT_TO_BYTE: return cast.target.accept(this);
1396 1442
 			case UINT_TO_SBYTE: return cast(cast, "byte");
1397 1443
 			case UINT_TO_SHORT: return cast(cast, "short");
@@ -1399,6 +1445,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1399 1445
 			case UINT_TO_INT: return cast.target.accept(this);
1400 1446
 			case UINT_TO_LONG: return castImplicit(cast, "long");
1401 1447
 			case UINT_TO_ULONG: return castPostfix(cast, JavaOperator.AND_8FL);
1448
+			case UINT_TO_USIZE: return cast.target.accept(this);
1402 1449
 			case UINT_TO_FLOAT: return cast(castPostfix(cast, JavaOperator.AND_8FL), "float");
1403 1450
 			case UINT_TO_DOUBLE: return cast(castPostfix(cast, JavaOperator.AND_8FL), "double");
1404 1451
 			case UINT_TO_CHAR: return cast(cast, "char");
@@ -1410,6 +1457,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1410 1457
 			case LONG_TO_INT: return cast(cast, "int");
1411 1458
 			case LONG_TO_UINT: return cast(cast, "int");
1412 1459
 			case LONG_TO_ULONG: return cast.target.accept(this);
1460
+			case LONG_TO_USIZE: return cast(cast, "int");
1413 1461
 			case LONG_TO_FLOAT: return castImplicit(cast, "float");
1414 1462
 			case LONG_TO_DOUBLE: return castImplicit(cast, "double");
1415 1463
 			case LONG_TO_CHAR: return cast(cast, "char");
@@ -1421,6 +1469,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1421 1469
 			case ULONG_TO_INT: return cast(cast, "int");
1422 1470
 			case ULONG_TO_UINT: return cast(cast, "int");
1423 1471
 			case ULONG_TO_LONG: return cast.target.accept(this);
1472
+			case ULONG_TO_USIZE: return cast(cast, "int");
1424 1473
 			case ULONG_TO_FLOAT: return castImplicit(cast, "float"); // TODO: this is incorrect!
1425 1474
 			case ULONG_TO_DOUBLE: return castImplicit(cast, "double"); // TODO: this is incorrect!
1426 1475
 			case ULONG_TO_CHAR: return cast(cast, "char");
@@ -1433,6 +1482,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1433 1482
 			case FLOAT_TO_UINT: return cast(cast, "int");
1434 1483
 			case FLOAT_TO_LONG: return cast(cast, "long");
1435 1484
 			case FLOAT_TO_ULONG: return cast(cast, "long");
1485
+			case FLOAT_TO_USIZE: return cast(cast, "int");
1436 1486
 			case FLOAT_TO_DOUBLE: return castImplicit(cast, "double");
1437 1487
 			case FLOAT_TO_STRING: return callStatic("Float.toString", cast.target);
1438 1488
 			case DOUBLE_TO_BYTE: return cast(cast, "int");
@@ -1443,6 +1493,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1443 1493
 			case DOUBLE_TO_UINT: return cast(cast, "int");
1444 1494
 			case DOUBLE_TO_LONG: return cast(cast, "long");
1445 1495
 			case DOUBLE_TO_ULONG: return cast(cast, "long");
1496
+			case DOUBLE_TO_USIZE: return cast(cast, "int");
1446 1497
 			case DOUBLE_TO_FLOAT: return cast(cast, "float");
1447 1498
 			case DOUBLE_TO_STRING: return callStatic("Double.toString", cast.target);
1448 1499
 			case CHAR_TO_BYTE: return cast.target.accept(this);
@@ -1453,6 +1504,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1453 1504
 			case CHAR_TO_UINT: return castImplicit(cast, "int");
1454 1505
 			case CHAR_TO_LONG: return castImplicit(cast, "long");
1455 1506
 			case CHAR_TO_ULONG: return castImplicit(cast, "long");
1507
+			case CHAR_TO_USIZE: return castImplicit(cast, "int");
1456 1508
 			case CHAR_TO_STRING: return callStatic("Character.toString", cast.target);
1457 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 Ver fichero

@@ -108,19 +108,19 @@ public class JavaSourceFile {
108 108
 			writer.write(pkg.fullName);
109 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 125
 			writer.write(contents.toString());
126 126
 		} catch (IOException ex) {

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceImporter.java Ver fichero

@@ -30,8 +30,6 @@ public class JavaSourceImporter {
30 30
 		JavaClass cls = definition.getTag(JavaClass.class);
31 31
 		if (cls == null)
32 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 34
 		return importType(cls);
37 35
 	}
@@ -42,6 +40,8 @@ public class JavaSourceImporter {
42 40
 			usedImports.add(imported);
43 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 46
 		imports.put(cls.outer.getName(), cls.outer);
47 47
 		usedImports.add(cls.outer);

+ 5
- 5
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java Ver fichero

@@ -63,7 +63,7 @@ public class JavaSourceSyntheticTypeGenerator implements JavaSyntheticClassGener
63 63
 			}
64 64
 			contents.append("> ");
65 65
 		}
66
-		contents.append(function.header.returnType.accept(typeVisitor));
66
+		contents.append(function.header.getReturnType().accept(typeVisitor));
67 67
 		contents.append(' ');
68 68
 		contents.append("invoke(");
69 69
 		boolean first = true;
@@ -100,16 +100,16 @@ public class JavaSourceSyntheticTypeGenerator implements JavaSyntheticClassGener
100 100
 		
101 101
 		StringBuilder contents = new StringBuilder();
102 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 105
 		contents.append(settings.indent).append("\n");
106 106
 		contents.append(settings.indent)
107 107
 				.append("public ")
108 108
 				.append(result.cls.getName())
109 109
 				.append("(")
110
-				.append(type.from.accept(typeVisitor))
110
+				.append(type.baseType.accept(typeVisitor))
111 111
 				.append(" from, ")
112
-				.append(type.to.accept(typeVisitor))
112
+				.append(type.baseType.accept(typeVisitor))
113 113
 				.append(" to) {\n");
114 114
 		contents.append(settings.indent).append(settings.indent).append("this.from = from;\n");
115 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 Ver fichero

@@ -61,6 +61,7 @@ public class JavaSourceTypeVisitor implements ITypeVisitor<String>, GenericParam
61 61
 			case UINT: return "int";
62 62
 			case LONG: return "long";
63 63
 			case ULONG: return "long";
64
+			case USIZE: return "int";
64 65
 			case FLOAT: return "float";
65 66
 			case DOUBLE: return "double";
66 67
 			case CHAR: return "char";
@@ -73,7 +74,15 @@ public class JavaSourceTypeVisitor implements ITypeVisitor<String>, GenericParam
73 74
 	@Override
74 75
 	public String visitArray(ArrayTypeID array) {
75 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 86
 		for (int i = 0; i < array.dimension; i++)
78 87
 			result.append("[]");
79 88
 		
@@ -170,6 +179,9 @@ public class JavaSourceTypeVisitor implements ITypeVisitor<String>, GenericParam
170 179
 
171 180
 	@Override
172 181
 	public String visitModified(ModifiedTypeID optional) {
182
+		if (optional.isOptional() && optional.withoutOptional() == BasicTypeID.USIZE)
183
+			return "int"; // usize? is an int
184
+		
173 185
 		return optional.baseType.accept(new JavaSourceObjectTypeVisitor(importer, typeGenerator));
174 186
 	}
175 187
 

+ 1
- 0
Parser/build.gradle Ver fichero

@@ -16,4 +16,5 @@ if (!hasProperty('mainClass')) {
16 16
 dependencies {
17 17
     compile project(':Shared')
18 18
 	compile project(':CodeModel')
19
+	compile project(':CompilerShared')
19 20
 }

+ 1
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java Ver fichero

@@ -120,6 +120,7 @@ public enum ZSTokenType implements TokenType {
120 120
 	K_UINT(true, "uint"),
121 121
 	K_LONG(true, "long"),
122 122
 	K_ULONG(true, "ulong"),
123
+	K_USIZE(true, "usize"),
123 124
 	K_FLOAT(true, "float"),
124 125
 	K_DOUBLE(true, "double"),
125 126
 	K_CHAR(true, "char"),

+ 77
- 0
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java Ver fichero

@@ -8,8 +8,10 @@ package org.openzen.zenscript.parser;
8 8
 import java.io.File;
9 9
 import java.io.IOException;
10 10
 import java.util.ArrayList;
11
+import java.util.Collections;
11 12
 import java.util.List;
12 13
 import java.util.Map;
14
+import java.util.function.Consumer;
13 15
 import org.openzen.zencode.shared.CodePosition;
14 16
 import org.openzen.zencode.shared.CompileException;
15 17
 import org.openzen.zencode.shared.CompileExceptionCode;
@@ -33,6 +35,8 @@ import org.openzen.zenscript.codemodel.scope.FileScope;
33 35
 import org.openzen.zenscript.codemodel.scope.GlobalScriptScope;
34 36
 import org.openzen.zenscript.codemodel.type.ISymbol;
35 37
 import org.openzen.zenscript.codemodel.scope.StatementScope;
38
+import org.openzen.zenscript.compiler.ModuleSpace;
39
+import org.openzen.zenscript.compiler.SemanticModule;
36 40
 import org.openzen.zenscript.parser.statements.ParsedStatement;
37 41
 
38 42
 /**
@@ -40,6 +44,79 @@ import org.openzen.zenscript.parser.statements.ParsedStatement;
40 44
  * @author Hoofdgebruiker
41 45
  */
42 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 120
 	public static ParsedFile parse(CompilingPackage compilingPackage, BracketExpressionParser bracketParser, File file) throws IOException {
44 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 Ver fichero

@@ -70,8 +70,8 @@ public class ParsedFunction extends ParsedDefinition {
70 70
 		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
71 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 Ver fichero

@@ -69,14 +69,14 @@ public class ParsedExpressionFunction extends ParsedExpression {
69 69
 		StatementScope innerScope = new LambdaScope(scope, closure, header);
70 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 75
 		if (!scope.genericInferenceMap.isEmpty()) {
76 76
 			// perform type parameter inference
77 77
 			ITypeID returnType = statements.getReturnType();
78 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 80
 				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
81 81
 			
82 82
 			scope.genericInferenceMap.putAll(inferredTypes);

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

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

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

@@ -38,16 +38,18 @@ public class ParsedExpressionRange extends ParsedExpression {
38 38
 		for (ITypeID hint : scope.hints) {
39 39
 			if (hint instanceof RangeTypeID) {
40 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 48
 		Expression from = this.from.compile(scope.withHints(fromHints)).eval();
49 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 55
 	@Override

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

@@ -75,8 +75,14 @@ public abstract class ParsedFunctionalMember extends ParsedDefinitionMember {
75 75
 		getCompiled().annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
76 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 88
 	protected abstract void fillOverride(TypeScope scope, ITypeID baseType);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java Ver fichero

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

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

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

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

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

@@ -24,6 +24,7 @@ public enum ParsedTypeBasic implements IParsedType {
24 24
 	UINT(BasicTypeID.UINT),
25 25
 	LONG(BasicTypeID.LONG),
26 26
 	ULONG(BasicTypeID.ULONG),
27
+	USIZE(BasicTypeID.USIZE),
27 28
 	FLOAT(BasicTypeID.FLOAT),
28 29
 	DOUBLE(BasicTypeID.DOUBLE),
29 30
 	CHAR(BasicTypeID.CHAR),

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

@@ -5,10 +5,11 @@
5 5
  */
6 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 11
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
9 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 13
 import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
13 14
 
14 15
 /**
@@ -16,17 +17,20 @@ import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
16 17
  * @author Hoofdgebruiker
17 18
  */
18 19
 public class ParsedTypeRange implements IParsedType {
20
+	private final CodePosition position;
19 21
 	private final IParsedType from;
20 22
 	private final IParsedType to;
21 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 27
 		this.from = from;
25 28
 		this.to = to;
26 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 34
 		this.from = from;
31 35
 		this.to = to;
32 36
 		this.modifiers = modifiers;
@@ -34,18 +38,21 @@ public class ParsedTypeRange implements IParsedType {
34 38
 
35 39
 	@Override
36 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 44
 	@Override
41 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 49
 	@Override
46 50
 	public ITypeID compile(TypeResolutionContext context) {
47 51
 		ITypeID from = this.from.compile(context);
48 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 Ver fichero

@@ -18,6 +18,5 @@ dependencies {
18 18
 	compile project(':JavaBytecodeCompiler')
19 19
 	compile project(':JavaShared')
20 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 Ver fichero

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

+ 2
- 3
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java Ver fichero

@@ -1,11 +1,10 @@
1 1
 package org.openzen.zencode.shared;
2 2
 
3
-import org.openzen.zencode.shared.CodePosition;
4
-import org.openzen.zencode.shared.VirtualSourceFile;
5
-
6 3
 public final class CodePosition {
7 4
     public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
8 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 8
     public final SourceFile file;
10 9
     public final int fromLine;
11 10
     public final int fromLineOffset;

+ 3
- 1
Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java Ver fichero

@@ -66,5 +66,7 @@ public enum CompileExceptionCode {
66 66
 	VAR_WITHOUT_TYPE_OR_INITIALIZER(),
67 67
 	NO_BRACKET_PARSER(),
68 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 Ver fichero

@@ -226,6 +226,11 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
226 226
 		return null;
227 227
 	}
228 228
 
229
+	@Override
230
+	public Void visitConstantUSize(ConstantUSizeExpression expression) {
231
+		return null;
232
+	}
233
+
229 234
 	@Override
230 235
 	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
231 236
 		if (!scope.isConstructor()) {
@@ -485,11 +490,11 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
485 490
 		expression.to.accept(this);
486 491
 		
487 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 499
 		return null;
495 500
 	}

+ 2
- 2
Validator/src/main/java/org/openzen/zenscript/validator/visitors/StatementValidator.java Ver fichero

@@ -152,10 +152,10 @@ public class StatementValidator implements StatementVisitor<Void> {
152 152
 					validator,
153 153
 					new StatementExpressionScope()));
154 154
 			
155
-			if (statement.value.type != scope.getFunctionHeader().returnType) {
155
+			if (statement.value.type != scope.getFunctionHeader().getReturnType()) {
156 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 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 Ver fichero

@@ -90,8 +90,7 @@ public class TypeValidator implements ITypeVisitor<Void> {
90 90
 
91 91
 	@Override
92 92
 	public Void visitRange(RangeTypeID range) {
93
-		range.from.accept(this);
94
-		range.to.accept(this);
93
+		range.baseType.accept(this);
95 94
 		return null;
96 95
 	}
97 96
 

+ 1
- 1
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java Ver fichero

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

Loading…
Cancelar
Guardar