Bladeren bron

- Added support for zipped packages

- Simplified compilation process somewhat; removed CompilationUnit class and work more module-oriented instead
Stan Hebben 6 jaren geleden
bovenliggende
commit
e0118ed3c2
83 gewijzigde bestanden met toevoegingen van 871 en 179 verwijderingen
  1. 4
    5
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java
  2. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  3. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationProcessor.java
  4. 15
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/FileResolutionContext.java
  5. 6
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java
  6. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/ModuleTypeResolutionContext.java
  7. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/TypeResolutionContext.java
  8. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  9. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java
  10. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java
  11. 8
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java
  12. 11
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/PropertyMember.java
  13. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java
  14. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java
  15. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java
  16. 6
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java
  17. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java
  18. 16
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java
  19. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java
  20. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java
  21. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java
  22. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java
  23. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java
  24. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java
  25. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java
  26. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/InvalidStatement.java
  27. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  28. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  29. 0
    22
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompilationUnit.java
  30. 9
    1
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java
  31. 5
    4
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java
  32. 11
    10
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  33. 6
    3
      Constructor/src/main/java/org/openzen/zenscript/constructor/Main.java
  34. 5
    5
      Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java
  35. 5
    5
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  36. 2
    2
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java
  37. 6
    15
      IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeSpace.java
  38. 7
    3
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  39. 24
    0
      JavaAnnotations/build.gradle
  40. 23
    0
      JavaAnnotations/src/main/java/org/openzen/zencode/java/ZenCodeGlobals.java
  41. 164
    0
      JavaAnnotations/src/main/java/org/openzen/zencode/java/ZenCodeType.java
  42. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTarget.java
  43. 43
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeModule.java
  44. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTarget.java
  45. 87
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunUnit.java
  46. 51
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  47. 2
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  48. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  49. 2
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaBaseCompiler.java
  50. 16
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompileSpace.java
  51. 12
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompiledModule.java
  52. 4
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java
  53. 27
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/SimpleJavaCompileSpace.java
  54. 4
    5
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java
  55. 2
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java
  56. 4
    4
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java
  57. 1
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java
  58. 7
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  59. 4
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java
  60. 4
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  61. 3
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  62. 13
    6
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  63. 4
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java
  64. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTarget.java
  65. 9
    10
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  66. 82
    0
      Parser/src/main/java/org/openzen/zenscript/parser/ZippedPackage.java
  67. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java
  68. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java
  69. 5
    5
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedConst.java
  70. 5
    5
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedField.java
  71. 5
    5
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedGetter.java
  72. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedInnerDefinition.java
  73. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedSetter.java
  74. 7
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java
  75. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementSwitch.java
  76. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeGenericMap.java
  77. 10
    9
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  78. 2
    0
      Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java
  79. 3
    0
      Shared/src/main/java/org/openzen/zencode/shared/CompileException.java
  80. 1
    0
      Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java
  81. 5
    0
      Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java
  82. 7
    7
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java
  83. 6
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java

+ 4
- 5
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java Bestand weergeven

@@ -5,7 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.formatter;
7 7
 
8
-import org.openzen.zenscript.codemodel.Modifiers;
9 8
 import org.openzen.zenscript.codemodel.member.CallerMember;
10 9
 import org.openzen.zenscript.codemodel.member.CasterMember;
11 10
 import org.openzen.zenscript.codemodel.member.ConstMember;
@@ -62,7 +61,7 @@ public class MemberFormatter implements MemberVisitor<Void> {
62 61
 		output.append("const")
63 62
 				.append(member.name)
64 63
 				.append(" as ")
65
-				.append(typeFormatter.format(member.type))
64
+				.append(typeFormatter.format(member.getType()))
66 65
 				.append(" = ")
67 66
 				.append(member.value.accept(new ExpressionFormatter(settings, typeFormatter, indent)))
68 67
 				.append(";\n");
@@ -76,7 +75,7 @@ public class MemberFormatter implements MemberVisitor<Void> {
76 75
 		output.append(member.isFinal() ? "val " : "var ")
77 76
 				.append(member.name)
78 77
 				.append(" as ")
79
-				.append(typeFormatter.format(member.type));
78
+				.append(typeFormatter.format(member.getType()));
80 79
 		
81 80
 		if (member.initializer != null) {
82 81
 			output.append(" = ")
@@ -122,7 +121,7 @@ public class MemberFormatter implements MemberVisitor<Void> {
122 121
 		output.append("get ");
123 122
 		output.append(member.name);
124 123
 		output.append(" as ");
125
-		output.append(typeFormatter.format(member.type));
124
+		output.append(typeFormatter.format(member.getType()));
126 125
 		formatBody(member.body);
127 126
 		return null;
128 127
 	}
@@ -134,7 +133,7 @@ public class MemberFormatter implements MemberVisitor<Void> {
134 133
 		output.append("set ");
135 134
 		output.append(member.name);
136 135
 		output.append(" as ");
137
-		output.append(typeFormatter.format(member.type));
136
+		output.append(typeFormatter.format(member.getType()));
138 137
 		formatBody(member.body);
139 138
 		return null;
140 139
 	}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java Bestand weergeven

@@ -142,7 +142,7 @@ public abstract class HighLevelDefinition extends Taggable {
142 142
 				isDestructible = true;
143 143
 			if (member instanceof FieldMember) {
144 144
 				FieldMember field = (FieldMember)member;
145
-				if (field.type.isDestructible(scanning))
145
+				if (field.getType().isDestructible(scanning))
146 146
 					isDestructible = true;
147 147
 			}
148 148
 			if ((member instanceof ImplementationMember) && ((ImplementationMember)member).type.isDestructible())

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationProcessor.java Bestand weergeven

@@ -212,7 +212,7 @@ public class AnnotationProcessor implements ModuleProcessor {
212 212
 			if (member.body == null)
213 213
 				return null;
214 214
 			
215
-			StatementScope scope = new FunctionScope(this.scope, new FunctionHeader(member.type));
215
+			StatementScope scope = new FunctionScope(this.scope, new FunctionHeader(member.getType()));
216 216
 			member.body = process(member.body, scope);
217 217
 			return null;
218 218
 		}

+ 15
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/FileResolutionContext.java Bestand weergeven

@@ -13,6 +13,7 @@ import org.openzen.zencode.shared.CompileExceptionCode;
13 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14 14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15 15
 import org.openzen.zenscript.codemodel.GenericName;
16
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
16 17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17 18
 import org.openzen.zenscript.codemodel.type.InvalidTypeID;
18 19
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -27,15 +28,25 @@ public class FileResolutionContext implements TypeResolutionContext {
27 28
 	private final ModuleTypeResolutionContext module;
28 29
 	private final CompilingPackage modulePackage;
29 30
 	private final Map<String, HighLevelDefinition> imports = new HashMap<>();
31
+	private final ZSPackage root;
30 32
 	
31
-	public FileResolutionContext(ModuleTypeResolutionContext module, CompilingPackage modulePackage) {
33
+	public FileResolutionContext(ModuleTypeResolutionContext module, ZSPackage root, CompilingPackage modulePackage) {
32 34
 		this.module = module;
35
+		this.root = root;
33 36
 		this.modulePackage = modulePackage;
34 37
 	}
35 38
 	
36 39
 	public void addImport(String name, HighLevelDefinition definition) {
40
+		if (definition == null)
41
+			throw new NullPointerException();
42
+		
37 43
 		imports.put(name, definition);
38 44
 	}
45
+	
46
+	@Override
47
+	public ZSPackage getRootPackage() {
48
+		return root;
49
+	}
39 50
 
40 51
 	@Override
41 52
 	public GlobalTypeRegistry getTypeRegistry() {
@@ -51,7 +62,7 @@ public class FileResolutionContext implements TypeResolutionContext {
51 62
 	public TypeID getType(CodePosition position, List<GenericName> name) {
52 63
 		if (imports.containsKey(name.get(0).name)) {
53 64
 			HighLevelDefinition definition = imports.get(name.get(0).name);
54
-			if (definition.getNumberOfGenericParameters() != name.get(0).arguments.length)
65
+			if (definition.getNumberOfGenericParameters() != name.get(0).getNumberOfArguments())
55 66
 				return new InvalidTypeID(position, CompileExceptionCode.INVALID_TYPE_ARGUMENTS, "Invalid number of type arguments");
56 67
 			
57 68
 			return GenericName.getInnerType(
@@ -59,6 +70,8 @@ public class FileResolutionContext implements TypeResolutionContext {
59 70
 					getTypeRegistry().getForDefinition(definition, name.get(0).arguments),
60 71
 					name,
61 72
 					1);
73
+		} else if (root.contains(name.get(0).name)) {
74
+			return root.getType(position, this, name);
62 75
 		}
63 76
 		
64 77
 		TypeID moduleType = modulePackage.getType(this, name);

+ 6
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java Bestand weergeven

@@ -11,12 +11,12 @@ import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12 12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13 13
 import org.openzen.zenscript.codemodel.GenericName;
14
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
14 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15 16
 import org.openzen.zenscript.codemodel.type.StoredType;
16 17
 import org.openzen.zenscript.codemodel.type.TypeID;
17 18
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
18 19
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
19
-import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
20 20
 
21 21
 /**
22 22
  *
@@ -32,6 +32,11 @@ public class LocalTypeResolutionContext implements TypeResolutionContext {
32 32
 		this.type = type;
33 33
 		this.parameters = parameters;
34 34
 	}
35
+	
36
+	@Override
37
+	public ZSPackage getRootPackage() {
38
+		return outer.getRootPackage();
39
+	}
35 40
 
36 41
 	@Override
37 42
 	public GlobalTypeRegistry getTypeRegistry() {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/ModuleTypeResolutionContext.java Bestand weergeven

@@ -53,6 +53,11 @@ public class ModuleTypeResolutionContext implements TypeResolutionContext {
53 53
 			this.storageTypes.put(storageType.getName(), storageType);
54 54
 	}
55 55
 	
56
+	@Override
57
+	public ZSPackage getRootPackage() {
58
+		return rootPackage;
59
+	}
60
+	
56 61
 	@Override
57 62
 	public GlobalTypeRegistry getTypeRegistry() {
58 63
 		return registry;

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/TypeResolutionContext.java Bestand weergeven

@@ -9,6 +9,7 @@ import java.util.List;
9 9
 import org.openzen.zencode.shared.CodePosition;
10 10
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11 11
 import org.openzen.zenscript.codemodel.GenericName;
12
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
12 13
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 14
 import org.openzen.zenscript.codemodel.type.StoredType;
14 15
 import org.openzen.zenscript.codemodel.type.TypeID;
@@ -19,6 +20,8 @@ import org.openzen.zenscript.codemodel.type.storage.StorageTag;
19 20
  * @author Hoofdgebruiker
20 21
  */
21 22
 public interface TypeResolutionContext {
23
+	ZSPackage getRootPackage();
24
+	
22 25
 	GlobalTypeRegistry getTypeRegistry();
23 26
 	
24 27
 	AnnotationDefinition getAnnotation(String name);

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java Bestand weergeven

@@ -37,7 +37,7 @@ public class ZSPackage {
37 37
 	public ZSPackage(ZSPackage parent, String name) {
38 38
 		this.parent = parent;
39 39
 		this.name = name;
40
-		this.fullName = parent == null ? name : parent.fullName + "." + name;
40
+		this.fullName = parent == null || parent.fullName.isEmpty() ? name : parent.fullName + "." + name;
41 41
 	}
42 42
 	
43 43
 	private final Map<String, ZSPackage> subPackages = new HashMap<>();

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java Bestand weergeven

@@ -71,7 +71,7 @@ public class ConstMember extends PropertyMember {
71 71
 
72 72
 	@Override
73 73
 	public void normalize(TypeScope scope) {
74
-		type = type.getNormalized();
74
+		setType(getType().getNormalized());
75 75
 		value = value.normalize(scope);
76 76
 	}
77 77
 

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java Bestand weergeven

@@ -162,7 +162,7 @@ public class FieldMember extends PropertyMember {
162 162
 
163 163
 	@Override
164 164
 	public void normalize(TypeScope scope) {
165
-		type = type.getNormalized();
165
+		setType(getType().getNormalized());
166 166
 		if (initializer != null)
167 167
 			initializer = initializer.normalize(scope);
168 168
 	}

+ 8
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java Bestand weergeven

@@ -46,8 +46,11 @@ public class GetterMember extends PropertyMember {
46 46
 	public void setBody(Statement body) {
47 47
 		this.body = body;
48 48
 		
49
-		if (type.type == BasicTypeID.UNDETERMINED)
50
-			type = body.getReturnType();
49
+		if (getType().type == BasicTypeID.UNDETERMINED) {
50
+			StoredType returnType = body.getReturnType();
51
+			if (returnType != null)
52
+				setType(returnType);
53
+		}
51 54
 	}
52 55
 	
53 56
 	@Override
@@ -100,8 +103,8 @@ public class GetterMember extends PropertyMember {
100 103
 	public void setOverrides(GetterMemberRef override) {
101 104
 		this.overrides = override;
102 105
 		
103
-		if (type.type == BasicTypeID.UNDETERMINED)
104
-			type = override.getType();
106
+		if (getType().type == BasicTypeID.UNDETERMINED)
107
+			setType(override.getType());
105 108
 	}
106 109
 
107 110
 	@Override
@@ -111,6 +114,6 @@ public class GetterMember extends PropertyMember {
111 114
 	
112 115
 	@Override
113 116
 	public FunctionHeader getHeader() {
114
-		return new FunctionHeader(type);
117
+		return new FunctionHeader(getType());
115 118
 	}
116 119
 }

+ 11
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/PropertyMember.java Bestand weergeven

@@ -15,12 +15,15 @@ import org.openzen.zenscript.codemodel.type.member.BuiltinID;
15 15
  * @author Hoofdgebruiker
16 16
  */
17 17
 public abstract class PropertyMember extends DefinitionMember {
18
-	public StoredType type;
18
+	private StoredType type;
19 19
 	public final BuiltinID builtin;
20 20
 	
21 21
 	public PropertyMember(CodePosition position, HighLevelDefinition definition, int modifiers, StoredType type, BuiltinID builtin) {
22 22
 		super(position, definition, modifiers);
23 23
 		
24
+		if (type == null)
25
+			throw new NullPointerException();
26
+		
24 27
 		this.type = type;
25 28
 		this.builtin = builtin;
26 29
 	}
@@ -29,6 +32,13 @@ public abstract class PropertyMember extends DefinitionMember {
29 32
 		return type;
30 33
 	}
31 34
 	
35
+	public void setType(StoredType type) {
36
+		if (type == null)
37
+			throw new NullPointerException();
38
+		
39
+		this.type = type;
40
+	}
41
+	
32 42
 	@Override
33 43
 	public BuiltinID getBuiltin() {
34 44
 		return builtin;

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java Bestand weergeven

@@ -105,8 +105,8 @@ public class SetterMember extends PropertyMember {
105 105
 	public void setOverrides(SetterMemberRef overrides) {
106 106
 		this.overrides = overrides;
107 107
 		
108
-		if (type.type == BasicTypeID.UNDETERMINED) {
109
-			type = overrides.getType();
108
+		if (getType().type == BasicTypeID.UNDETERMINED) {
109
+			setType(overrides.getType());
110 110
 			parameter = new FunctionParameter(overrides.getType(), "value");
111 111
 		}
112 112
 	}
@@ -118,6 +118,6 @@ public class SetterMember extends PropertyMember {
118 118
 	
119 119
 	@Override
120 120
 	public FunctionHeader getHeader() {
121
-		return new FunctionHeader(BasicTypeID.VOID, type);
121
+		return new FunctionHeader(BasicTypeID.VOID, getType());
122 122
 	}
123 123
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java Bestand weergeven

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
14 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
16 16
 import org.openzen.zenscript.codemodel.GenericName;
17
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
17 18
 import org.openzen.zenscript.codemodel.type.StoredType;
18 19
 import org.openzen.zenscript.codemodel.type.TypeID;
19 20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -31,6 +32,11 @@ public class BlockScope extends StatementScope {
31 32
 		this.parent = parent;
32 33
 	}
33 34
 	
35
+	@Override
36
+	public ZSPackage getRootPackage() {
37
+		return parent.getRootPackage();
38
+	}
39
+	
34 40
 	@Override
35 41
 	public LocalMemberCache getMemberCache() {
36 42
 		return parent.getMemberCache();

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java Bestand weergeven

@@ -18,6 +18,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
18 18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
19 19
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
20 20
 import org.openzen.zenscript.codemodel.GenericName;
21
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
21 22
 import org.openzen.zenscript.codemodel.type.StoredType;
22 23
 import org.openzen.zenscript.codemodel.type.TypeID;
23 24
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -39,6 +40,11 @@ public class CompileTypeScope extends BaseScope {
39 40
 			for (TypeParameter parameter : parameters)
40 41
 				typeParameters.put(parameter.name, parameter);
41 42
 	}
43
+	
44
+	@Override
45
+	public ZSPackage getRootPackage() {
46
+		return outer.getRootPackage();
47
+	}
42 48
 
43 49
 	@Override
44 50
 	public LocalMemberCache getMemberCache() {

+ 6
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java Bestand weergeven

@@ -28,13 +28,13 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
28 28
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
29 29
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
30 30
 import org.openzen.zenscript.codemodel.GenericName;
31
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
31 32
 import org.openzen.zenscript.codemodel.type.StoredType;
32 33
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
33 34
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
34 35
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
35 36
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
36 37
 import org.openzen.zenscript.codemodel.type.TypeID;
37
-import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
38 38
 import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
39 39
 
40 40
 /**
@@ -86,6 +86,11 @@ public class DefinitionScope extends BaseScope {
86 86
 		innerTypes.put(name, innerType);
87 87
 	}
88 88
 	
89
+	@Override
90
+	public ZSPackage getRootPackage() {
91
+		return outer.getRootPackage();
92
+	}
93
+	
89 94
 	@Override
90 95
 	public LocalMemberCache getMemberCache() {
91 96
 		return outer.getMemberCache();

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java Bestand weergeven

@@ -25,6 +25,7 @@ import org.openzen.zenscript.codemodel.statement.LoopStatement;
25 25
 import org.openzen.zenscript.codemodel.statement.VarStatement;
26 26
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
27 27
 import org.openzen.zenscript.codemodel.GenericName;
28
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
28 29
 import org.openzen.zenscript.codemodel.type.StoredType;
29 30
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
30 31
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
@@ -116,6 +117,11 @@ public class ExpressionScope extends BaseScope {
116 117
 		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
117 118
 	}
118 119
 	
120
+	@Override
121
+	public ZSPackage getRootPackage() {
122
+		return outer.getRootPackage();
123
+	}
124
+	
119 125
 	@Override
120 126
 	public LocalMemberCache getMemberCache() {
121 127
 		return outer.getMemberCache();

+ 16
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java Bestand weergeven

@@ -21,6 +21,9 @@ import org.openzen.zenscript.codemodel.partial.PartialGlobalExpression;
21 21
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
22 22
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
23 23
 import org.openzen.zenscript.codemodel.GenericName;
24
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
25
+import org.openzen.zenscript.codemodel.expression.InvalidExpression;
26
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
24 27
 import org.openzen.zenscript.codemodel.type.ISymbol;
25 28
 import org.openzen.zenscript.codemodel.type.StoredType;
26 29
 import org.openzen.zenscript.codemodel.type.TypeID;
@@ -35,6 +38,7 @@ import org.openzen.zenscript.codemodel.type.storage.StorageTag;
35 38
  */
36 39
 public class FileScope extends BaseScope {
37 40
 	private final TypeResolutionContext context;
41
+	private final ZSPackage root;
38 42
 	private final LocalMemberCache memberCache;
39 43
 	private final Map<String, ISymbol> globals;
40 44
 	private final TypeMemberPreparer preparer;
@@ -47,10 +51,16 @@ public class FileScope extends BaseScope {
47 51
 		this.context = context;
48 52
 		this.globals = globals;
49 53
 		this.preparer = preparer;
54
+		this.root = context.getRootPackage();
50 55
 		
51 56
 		memberCache = new LocalMemberCache(context.getTypeRegistry(), expansions);
52 57
 	}
53 58
 	
59
+	@Override
60
+	public ZSPackage getRootPackage() {
61
+		return root;
62
+	}
63
+	
54 64
 	@Override
55 65
 	public LocalMemberCache getMemberCache() {
56 66
 		return memberCache;
@@ -65,6 +75,12 @@ public class FileScope extends BaseScope {
65 75
 		if (globals.containsKey(name.name)) {
66 76
 			IPartialExpression resolution = globals.get(name.name).getExpression(position, this, name.arguments);
67 77
 			return new PartialGlobalExpression(position, name.name, resolution, name.arguments);
78
+		} else if (root.contains(name.name)) {
79
+			try {
80
+				return root.getMember(position, context.getTypeRegistry(), name);
81
+			} catch (CompileException ex) {
82
+				return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
83
+			}
68 84
 		}
69 85
 		
70 86
 		return null;

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java Bestand weergeven

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.statement.ForeachStatement;
17 17
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
18 18
 import org.openzen.zenscript.codemodel.statement.VarStatement;
19 19
 import org.openzen.zenscript.codemodel.GenericName;
20
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
20 21
 import org.openzen.zenscript.codemodel.type.StoredType;
21 22
 import org.openzen.zenscript.codemodel.type.TypeID;
22 23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -35,6 +36,11 @@ public class ForeachScope extends StatementScope {
35 36
 		this.statement = statement;
36 37
 		this.outer = outer;
37 38
 	}
39
+	
40
+	@Override
41
+	public ZSPackage getRootPackage() {
42
+		return outer.getRootPackage();
43
+	}
38 44
 
39 45
 	@Override
40 46
 	public LocalMemberCache getMemberCache() {

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java Bestand weergeven

@@ -18,6 +18,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
18 18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
19 19
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
20 20
 import org.openzen.zenscript.codemodel.GenericName;
21
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
21 22
 import org.openzen.zenscript.codemodel.type.StoredType;
22 23
 import org.openzen.zenscript.codemodel.type.TypeID;
23 24
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -53,6 +54,11 @@ public class FunctionScope extends StatementScope {
53 54
 		typeParameterMap = outer.getLocalTypeParameters().getInner(outer.getTypeRegistry(), header.typeParameters);
54 55
 	}
55 56
 	
57
+	@Override
58
+	public ZSPackage getRootPackage() {
59
+		return outer.getRootPackage();
60
+	}
61
+	
56 62
 	@Override
57 63
 	public LocalMemberCache getMemberCache() {
58 64
 		return outer.getMemberCache();

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java Bestand weergeven

@@ -18,6 +18,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
18 18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
19 19
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
20 20
 import org.openzen.zenscript.codemodel.GenericName;
21
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
21 22
 import org.openzen.zenscript.codemodel.type.StoredType;
22 23
 import org.openzen.zenscript.codemodel.type.TypeID;
23 24
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -40,6 +41,11 @@ public class GenericFunctionScope extends BaseScope {
40 41
 				this.parameters.put(parameter.name, parameter);
41 42
 	}
42 43
 	
44
+	@Override
45
+	public ZSPackage getRootPackage() {
46
+		return outer.getRootPackage();
47
+	}
48
+	
43 49
 	@Override
44 50
 	public LocalMemberCache getMemberCache() {
45 51
 		return outer.getMemberCache();

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java Bestand weergeven

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
14 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
16 16
 import org.openzen.zenscript.codemodel.GenericName;
17
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
17 18
 import org.openzen.zenscript.codemodel.type.StoredType;
18 19
 import org.openzen.zenscript.codemodel.type.TypeID;
19 20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -30,6 +31,11 @@ public class GlobalScriptScope extends StatementScope {
30 31
 	public GlobalScriptScope(BaseScope file) {
31 32
 		this.file = file;
32 33
 	}
34
+	
35
+	@Override
36
+	public ZSPackage getRootPackage() {
37
+		return file.getRootPackage();
38
+	}
33 39
 
34 40
 	@Override
35 41
 	public LocalMemberCache getMemberCache() {

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java Bestand weergeven

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17 17
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
18 18
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
19 19
 import org.openzen.zenscript.codemodel.GenericName;
20
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
20 21
 import org.openzen.zenscript.codemodel.type.StoredType;
21 22
 import org.openzen.zenscript.codemodel.type.TypeID;
22 23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -41,6 +42,11 @@ public class ImplementationScope extends BaseScope {
41 42
 		
42 43
 		members = outer.getTypeMembers(implementation.type.stored(BorrowStorageTag.THIS));
43 44
 	}
45
+	
46
+	@Override
47
+	public ZSPackage getRootPackage() {
48
+		return outer.getRootPackage();
49
+	}
44 50
 
45 51
 	@Override
46 52
 	public LocalMemberCache getMemberCache() {

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java Bestand weergeven

@@ -20,6 +20,7 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
20 20
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
21 21
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
22 22
 import org.openzen.zenscript.codemodel.GenericName;
23
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
23 24
 import org.openzen.zenscript.codemodel.type.StoredType;
24 25
 import org.openzen.zenscript.codemodel.type.TypeID;
25 26
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -41,6 +42,11 @@ public class LambdaScope extends StatementScope {
41 42
 		this.closure = closure;
42 43
 	}
43 44
 	
45
+	@Override
46
+	public ZSPackage getRootPackage() {
47
+		return outer.getRootPackage();
48
+	}
49
+	
44 50
 	@Override
45 51
 	public LocalMemberCache getMemberCache() {
46 52
 		return outer.getMemberCache();

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java Bestand weergeven

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
14 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
16 16
 import org.openzen.zenscript.codemodel.GenericName;
17
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
17 18
 import org.openzen.zenscript.codemodel.type.StoredType;
18 19
 import org.openzen.zenscript.codemodel.type.TypeID;
19 20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -32,6 +33,11 @@ public class LoopScope extends StatementScope {
32 33
 		this.statement = statement;
33 34
 		this.outer = outer;
34 35
 	}
36
+	
37
+	@Override
38
+	public ZSPackage getRootPackage() {
39
+		return outer.getRootPackage();
40
+	}
35 41
 
36 42
 	@Override
37 43
 	public LocalMemberCache getMemberCache() {

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/InvalidStatement.java Bestand weergeven

@@ -32,7 +32,7 @@ public class InvalidStatement extends Statement {
32 32
 		super(ex.position, null);
33 33
 		
34 34
 		this.code = ex.code;
35
-		this.message = ex.getMessage();
35
+		this.message = ex.message;
36 36
 	}
37 37
 
38 38
 	@Override

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java Bestand weergeven

@@ -481,7 +481,7 @@ public class TypeMemberBuilder implements TypeVisitorWithContext<Void, Void, Run
481 481
 					FunctionParameter[] parameters = new FunctionParameter[fields.size()];
482 482
 					for (int i = 0; i < parameters.length; i++) {
483 483
 						FieldMember field = fields.get(i);
484
-						parameters[i] = new FunctionParameter(field.type, field.name, field.initializer, false);
484
+						parameters[i] = new FunctionParameter(field.getType(), field.name, field.initializer, false);
485 485
 					}
486 486
 					
487 487
 					constructors.addMethod(new ConstructorMember(

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java Bestand weergeven

@@ -467,8 +467,8 @@ public final class TypeMembers {
467 467
 		if (toType.equals(value.type))
468 468
 			return value;
469 469
 		
470
-		if (!(toType.type instanceof StringTypeID))
471
-			System.out.println(position + ": " + value.type.getActualStorage() + " -> " + toType.getActualStorage());
470
+		//if (!(toType.type instanceof StringTypeID))
471
+		//	System.out.println(position + ": " + value.type.getActualStorage() + " -> " + toType.getActualStorage());
472 472
 		
473 473
 		return new StorageCastExpression(position, value, toType);
474 474
 	}

+ 0
- 22
CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompilationUnit.java Bestand weergeven

@@ -1,22 +0,0 @@
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.compiler;
7
-
8
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
9
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10
-
11
-/**
12
- *
13
- * @author Hoofdgebruiker
14
- */
15
-public class CompilationUnit {
16
-	public final ZSPackage stdlib = new ZSPackage(null, "stdlib");
17
-	public final GlobalTypeRegistry globalTypeRegistry = new GlobalTypeRegistry(stdlib);
18
-	
19
-	public CompilationUnit() {
20
-		
21
-	}
22
-}

+ 9
- 1
CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java Bestand weergeven

@@ -15,6 +15,7 @@ import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15 15
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
16 16
 import org.openzen.zenscript.codemodel.scope.TypeScope;
17 17
 import org.openzen.zenscript.codemodel.GenericName;
18
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
18 19
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19 20
 import org.openzen.zenscript.codemodel.type.StoredType;
20 21
 import org.openzen.zenscript.codemodel.type.TypeID;
@@ -33,11 +34,13 @@ public class CompileScope implements TypeScope {
33 34
 	private final GlobalTypeRegistry globalRegistry;
34 35
 	private final List<ExpansionDefinition> expansions;
35 36
 	private final LocalMemberCache cache;
37
+	private final ZSPackage rootPackage;
36 38
 	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
37 39
 	private final Map<String, StorageType> storageTypes = new HashMap<>();
38 40
 	
39
-	public CompileScope(GlobalTypeRegistry globalRegistry, List<ExpansionDefinition> expansions, AnnotationDefinition[] annotations, StorageType[] storageTypes) {
41
+	public CompileScope(GlobalTypeRegistry globalRegistry, ZSPackage rootPackage, List<ExpansionDefinition> expansions, AnnotationDefinition[] annotations, StorageType[] storageTypes) {
40 42
 		this.globalRegistry = globalRegistry;
43
+		this.rootPackage = rootPackage;
41 44
 		this.expansions = expansions;
42 45
 		this.cache = new LocalMemberCache(globalRegistry, expansions);
43 46
 		
@@ -46,6 +49,11 @@ public class CompileScope implements TypeScope {
46 49
 		for (StorageType type : storageTypes)
47 50
 			this.storageTypes.put(type.getName(), type);
48 51
 	}
52
+	
53
+	@Override
54
+	public ZSPackage getRootPackage() {
55
+		return rootPackage;
56
+	}
49 57
 
50 58
 	@Override
51 59
 	public GlobalTypeRegistry getTypeRegistry() {

+ 5
- 4
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java Bestand weergeven

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.annotations.NativeAnnotationDefinition;
17 17
 import org.openzen.zenscript.codemodel.annotations.PreconditionAnnotationDefinition;
18 18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19 19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
20
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
20 21
 import org.openzen.zenscript.codemodel.type.ISymbol;
21 22
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
22 23
 
@@ -25,16 +26,16 @@ import org.openzen.zenscript.codemodel.type.storage.StorageType;
25 26
  * @author Hoofdgebruiker
26 27
  */
27 28
 public final class ModuleSpace {
28
-	private final ZSPackage rootPackage = new ZSPackage(null, "");
29
-	public final CompilationUnit compilationUnit;
29
+	public final ZSPackage rootPackage = new ZSPackage(null, "");
30
+	public final GlobalTypeRegistry registry;
30 31
 	public final ZSPackage globalsPackage = new ZSPackage(null, "");
31 32
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
32 33
 	private final Map<String, ISymbol> globals = new HashMap<>();
33 34
 	private final AnnotationDefinition[] annotations;
34 35
 	private final StorageType[] storageTypes;
35 36
 	
36
-	public ModuleSpace(CompilationUnit compilationUnit, List<AnnotationDefinition> annotations, StorageType[] storageTypes) {
37
-		this.compilationUnit = compilationUnit;
37
+	public ModuleSpace(GlobalTypeRegistry registry, List<AnnotationDefinition> annotations, StorageType[] storageTypes) {
38
+		this.registry = registry;
38 39
 		
39 40
 		annotations.add(NativeAnnotationDefinition.INSTANCE);
40 41
 		annotations.add(PreconditionAnnotationDefinition.INSTANCE);

+ 11
- 10
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java Bestand weergeven

@@ -21,6 +21,7 @@ import org.openzen.zenscript.codemodel.context.ModuleTypeResolutionContext;
21 21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
22 22
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
23 23
 import org.openzen.zenscript.codemodel.scope.FileScope;
24
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
24 25
 import org.openzen.zenscript.codemodel.type.ISymbol;
25 26
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
26 27
 import org.openzen.zenscript.validator.ValidationLogEntry;
@@ -31,6 +32,8 @@ import org.openzen.zenscript.validator.Validator;
31 32
  * @author Hoofdgebruiker
32 33
  */
33 34
 public class SemanticModule {
35
+	public static final SemanticModule[] NONE = new SemanticModule[0];
36
+	
34 37
 	public final String name;
35 38
 	public final SemanticModule[] dependencies;
36 39
 	
@@ -42,13 +45,12 @@ public class SemanticModule {
42 45
 	public final List<ScriptBlock> scripts;
43 46
 	public final Map<String, ISymbol> globals = new HashMap<>();
44 47
 	
45
-	public final CompilationUnit compilationUnit;
48
+	public final GlobalTypeRegistry registry;
46 49
 	public final List<ExpansionDefinition> expansions;
47 50
 	public final AnnotationDefinition[] annotations;
48 51
 	public final StorageType[] storageTypes;
49 52
 	
50 53
 	public SemanticModule(
51
-			String name,
52 54
 			Module module,
53 55
 			SemanticModule[] dependencies,
54 56
 			State state,
@@ -56,12 +58,12 @@ public class SemanticModule {
56 58
 			ZSPackage modulePackage,
57 59
 			PackageDefinitions definitions,
58 60
 			List<ScriptBlock> scripts,
59
-			CompilationUnit compilationUnit,
61
+			GlobalTypeRegistry registry,
60 62
 			List<ExpansionDefinition> expansions,
61 63
 			AnnotationDefinition[] annotations,
62 64
 			StorageType[] storageTypes)
63 65
 	{
64
-		this.name = name;
66
+		this.name = module.name;
65 67
 		this.module = module;
66 68
 		this.dependencies = dependencies;
67 69
 		
@@ -71,7 +73,7 @@ public class SemanticModule {
71 73
 		this.definitions = definitions;
72 74
 		this.scripts = scripts;
73 75
 		
74
-		this.compilationUnit = compilationUnit;
76
+		this.registry = registry;
75 77
 		this.expansions = expansions;
76 78
 		this.annotations = annotations;
77 79
 		this.storageTypes = storageTypes;
@@ -85,7 +87,7 @@ public class SemanticModule {
85 87
 		if (state != State.ASSEMBLED)
86 88
 			throw new IllegalStateException("Module is invalid");
87 89
 		
88
-		ModuleTypeResolutionContext context = new ModuleTypeResolutionContext(compilationUnit.globalTypeRegistry, annotations, storageTypes, rootPackage, null, globals);
90
+		ModuleTypeResolutionContext context = new ModuleTypeResolutionContext(registry, annotations, storageTypes, rootPackage, null, globals);
89 91
 		AnnotationProcessor annotationProcessor = new AnnotationProcessor(context, expansions);
90 92
 		List<ScriptBlock> processedScripts = new ArrayList<>();
91 93
 		FileScope fileScope = new FileScope(context, expansions, globals, member -> {});
@@ -99,7 +101,6 @@ public class SemanticModule {
99 101
 		}
100 102
 		
101 103
 		return new SemanticModule(
102
-				name,
103 104
 				module,
104 105
 				dependencies,
105 106
 				State.NORMALIZED,
@@ -107,7 +108,7 @@ public class SemanticModule {
107 108
 				modulePackage,
108 109
 				definitions,
109 110
 				processedScripts,
110
-				compilationUnit,
111
+				registry,
111 112
 				expansions,
112 113
 				annotations,
113 114
 				storageTypes);
@@ -117,7 +118,7 @@ public class SemanticModule {
117 118
 		if (state != State.NORMALIZED)
118 119
 			throw new IllegalStateException("Module is not yet normalized");
119 120
 		
120
-		Validator validator = new Validator(compilationUnit.globalTypeRegistry, expansions, annotations);
121
+		Validator validator = new Validator(registry, expansions, annotations);
121 122
 		for (ScriptBlock script : scripts) {
122 123
 			validator.validate(script);
123 124
 		}
@@ -147,7 +148,7 @@ public class SemanticModule {
147 148
 	}
148 149
 	
149 150
 	public ModuleContext getContext() {
150
-		return new ModuleContext(compilationUnit.globalTypeRegistry, module, expansions, rootPackage);
151
+		return new ModuleContext(registry, module, expansions, rootPackage);
151 152
 	}
152 153
 	
153 154
 	public enum State {

+ 6
- 3
Constructor/src/main/java/org/openzen/zenscript/constructor/Main.java Bestand weergeven

@@ -1,10 +1,11 @@
1 1
 package org.openzen.zenscript.constructor;
2 2
 
3 3
 import java.io.File;
4
-import org.openzen.zenscript.compiler.CompilationUnit;
5 4
 import java.io.IOException;
6 5
 import java.util.function.Consumer;
7 6
 import org.openzen.zencode.shared.CompileException;
7
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
8
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
8 9
 import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
9 10
 import org.openzen.zenscript.constructor.module.ModuleReference;
10 11
 
@@ -23,9 +24,11 @@ public class Main {
23 24
 		Consumer<CompileException> exceptionLogger = exception -> System.err.println(exception.toString());
24 25
 		
25 26
 		File currentDirectory = new File(arguments.directory);
26
-		CompilationUnit compilationUnit = new CompilationUnit();
27
+		ZSPackage root = ZSPackage.createRoot();
28
+		ZSPackage stdlib = new ZSPackage(root, "stdlib");
29
+		GlobalTypeRegistry registry = new GlobalTypeRegistry(stdlib);
27 30
 		
28
-		ModuleLoader moduleLoader = new ModuleLoader(compilationUnit, exceptionLogger);
31
+		ModuleLoader moduleLoader = new ModuleLoader(registry, exceptionLogger);
29 32
 		moduleLoader.register("stdlib", new DirectoryModuleReference("stdlib", new File("../../StdLibs/stdlib"), true));
30 33
 		
31 34
 		Project project = new Project(currentDirectory);

+ 5
- 5
Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java Bestand weergeven

@@ -5,13 +5,13 @@
5 5
  */
6 6
 package org.openzen.zenscript.constructor;
7 7
 
8
-import org.openzen.zenscript.compiler.CompilationUnit;
9 8
 import java.util.HashMap;
10 9
 import java.util.HashSet;
11 10
 import java.util.Map;
12 11
 import java.util.Stack;
13 12
 import java.util.function.Consumer;
14 13
 import org.openzen.zencode.shared.CompileException;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15 15
 import org.openzen.zenscript.constructor.module.ModuleReference;
16 16
 import org.openzen.zenscript.compiler.SemanticModule;
17 17
 
@@ -26,11 +26,11 @@ public class ModuleLoader {
26 26
 	private final HashSet<String> compilingModulesSet = new HashSet<>();
27 27
 	private final Stack<String> compilingModulesStack = new Stack<>();
28 28
 	
29
-	private final CompilationUnit compilationUnit;
29
+	private final GlobalTypeRegistry registry;
30 30
 	private final Consumer<CompileException> exceptionLogger;
31 31
 	
32
-	public ModuleLoader(CompilationUnit compilationUnit, Consumer<CompileException> exceptionLogger) {
33
-		this.compilationUnit = compilationUnit;
32
+	public ModuleLoader(GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger) {
33
+		this.registry = registry;
34 34
 		this.exceptionLogger = exceptionLogger;
35 35
 	}
36 36
 	
@@ -53,7 +53,7 @@ public class ModuleLoader {
53 53
 		compilingModulesSet.add(name);
54 54
 		compilingModulesStack.add(name);
55 55
 		
56
-		SemanticModule module = modules.get(name).load(this, compilationUnit, exceptionLogger);
56
+		SemanticModule module = modules.get(name).load(this, registry, exceptionLogger);
57 57
 		moduleCache.put(name, module);
58 58
 		
59 59
 		compilingModulesSet.remove(name);

+ 5
- 5
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java Bestand weergeven

@@ -19,7 +19,7 @@ import org.openzen.zencode.shared.FileSourceFile;
19 19
 import org.openzen.zenscript.codemodel.Module;
20 20
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
21 21
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
22
-import org.openzen.zenscript.compiler.CompilationUnit;
22
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
23 23
 import org.openzen.zenscript.constructor.ConstructorException;
24 24
 import org.openzen.zenscript.constructor.JSONUtils;
25 25
 import org.openzen.zenscript.constructor.ParsedModule;
@@ -51,7 +51,7 @@ public class DirectoryModuleReference implements ModuleReference {
51 51
 	}
52 52
 
53 53
 	@Override
54
-	public SemanticModule load(ModuleLoader loader, CompilationUnit unit, Consumer<CompileException> exceptionLogger) {
54
+	public SemanticModule load(ModuleLoader loader, GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger) {
55 55
 		if (!directory.exists())
56 56
 			throw new ConstructorException("Error: module directory not found: " + directory);
57 57
 		
@@ -74,7 +74,7 @@ public class DirectoryModuleReference implements ModuleReference {
74 74
 			}
75 75
 
76 76
 			// TODO: annotation type registration
77
-			ModuleSpace space = new ModuleSpace(unit, new ArrayList<>(), StorageType.getStandard());
77
+			ModuleSpace space = new ModuleSpace(registry, new ArrayList<>(), StorageType.getStandard());
78 78
 			SemanticModule[] dependencies = new SemanticModule[dependencyNames.size()];
79 79
 			for (int i = 0; i < dependencies.length; i++) {
80 80
 				String dependencyName = dependencyNames.get(i);
@@ -89,12 +89,12 @@ public class DirectoryModuleReference implements ModuleReference {
89 89
 			}
90 90
 
91 91
 			ParsedModule parsedModule = new ParsedModule(moduleName, directory, jsonFile, exceptionLogger);
92
-			ZSPackage pkg = isStdlib ? unit.globalTypeRegistry.stdlib : new ZSPackage(null, parsedModule.packageName);
92
+			ZSPackage pkg = isStdlib ? registry.stdlib : new ZSPackage(null, parsedModule.packageName);
93 93
 			Module module = new Module(moduleName);
94 94
 			CompilingPackage compilingPackage = new CompilingPackage(pkg, module);
95 95
 			
96 96
 			ParsedFile[] parsedFiles = parsedModule.parse(compilingPackage);
97
-			SemanticModule result = ParsedFile.compileSyntaxToSemantic(parsedModule.name, dependencies, compilingPackage, parsedFiles, space, exceptionLogger);
97
+			SemanticModule result = ParsedFile.compileSyntaxToSemantic(dependencies, compilingPackage, parsedFiles, space, exceptionLogger);
98 98
 			
99 99
 			JSONObject globals = json.optJSONObject("globals");
100 100
 			if (globals != null) {

+ 2
- 2
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java Bestand weergeven

@@ -7,8 +7,8 @@ package org.openzen.zenscript.constructor.module;
7 7
 
8 8
 import java.util.function.Consumer;
9 9
 import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10 11
 import org.openzen.zenscript.compiler.SemanticModule;
11
-import org.openzen.zenscript.compiler.CompilationUnit;
12 12
 import org.openzen.zenscript.constructor.ModuleLoader;
13 13
 
14 14
 /**
@@ -18,7 +18,7 @@ import org.openzen.zenscript.constructor.ModuleLoader;
18 18
 public interface ModuleReference {
19 19
 	public String getName();
20 20
 	
21
-	public SemanticModule load(ModuleLoader loader, CompilationUnit unit, Consumer<CompileException> exceptionLogger);
21
+	public SemanticModule load(ModuleLoader loader, GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger);
22 22
 	
23 23
 	public SourcePackage getRootPackage();
24 24
 }

+ 6
- 15
IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeSpace.java Bestand weergeven

@@ -5,29 +5,17 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.codemodel;
7 7
 
8
-import java.io.File;
9 8
 import java.util.ArrayList;
10 9
 import java.util.Collections;
11 10
 import java.util.HashMap;
12
-import java.util.HashSet;
13 11
 import java.util.List;
14 12
 import java.util.Map;
15
-import java.util.Set;
16
-import java.util.function.Consumer;
17
-import org.openzen.zenscript.compiler.CompilationUnit;
18
-import org.openzen.zenscript.compiler.SemanticModule;
19
-import org.openzen.zenscript.compiler.ZenCodeCompiler;
20
-import org.openzen.zenscript.constructor.Library;
13
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
21 15
 import org.openzen.zenscript.constructor.ModuleLoader;
22
-import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
23
-import org.openzen.zenscript.constructor.module.ModuleReference;
24 16
 import org.openzen.zenscript.ide.host.DevelopmentHost;
25 17
 import org.openzen.zenscript.ide.host.IDEModule;
26 18
 import org.openzen.zenscript.ide.host.IDESourceFile;
27
-import org.openzen.zenscript.ide.ui.view.output.ErrorOutputSpan;
28
-import org.openzen.zenscript.ide.ui.view.output.OutputLine;
29
-import org.openzen.zenscript.validator.ValidationLogEntry;
30
-import stdlib.Strings;
31 19
 
32 20
 /**
33 21
  *
@@ -40,7 +28,10 @@ public class IDECodeSpace {
40 28
 	public IDECodeSpace(DevelopmentHost host) {
41 29
 		this.host = host;
42 30
 		
43
-		ModuleLoader loader = new ModuleLoader(new CompilationUnit(), exception -> {
31
+		ZSPackage root = ZSPackage.createRoot();
32
+		ZSPackage stdlib = new ZSPackage(root, "stdlib");
33
+		GlobalTypeRegistry registry = new GlobalTypeRegistry(stdlib);
34
+		ModuleLoader loader = new ModuleLoader(registry, exception -> {
44 35
 			
45 36
 		});
46 37
 		for (IDEModule module : host.getModules()) {

+ 7
- 3
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java Bestand weergeven

@@ -10,6 +10,8 @@ import java.util.HashSet;
10 10
 import java.util.Set;
11 11
 import java.util.Stack;
12 12
 import java.util.function.Consumer;
13
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 15
 import org.openzen.zenscript.compiler.Target;
14 16
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
15 17
 import org.openzen.zenscript.constructor.Library;
@@ -18,7 +20,6 @@ import org.openzen.zenscript.constructor.Project;
18 20
 import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
19 21
 import org.openzen.zenscript.constructor.module.ModuleReference;
20 22
 import org.openzen.zenscript.compiler.SemanticModule;
21
-import org.openzen.zenscript.compiler.CompilationUnit;
22 23
 import org.openzen.zenscript.ide.host.IDETarget;
23 24
 import org.openzen.zenscript.ide.ui.view.output.ErrorOutputSpan;
24 25
 import org.openzen.zenscript.ide.ui.view.output.OutputLine;
@@ -66,8 +67,11 @@ public class LocalTarget implements IDETarget {
66 67
 	}
67 68
 	
68 69
 	private ZenCodeCompiler buildInternal(Consumer<OutputLine> output) {
69
-		CompilationUnit compilationUnit = new CompilationUnit();
70
-		ModuleLoader moduleLoader = new ModuleLoader(compilationUnit, exception -> {
70
+		ZSPackage root = ZSPackage.createRoot();
71
+		ZSPackage stdlibPackage = new ZSPackage(root, "stdlib");
72
+		GlobalTypeRegistry registry = new GlobalTypeRegistry(stdlibPackage);
73
+		
74
+		ModuleLoader moduleLoader = new ModuleLoader(registry, exception -> {
71 75
 			String[] lines = Strings.split(exception.getMessage(), '\n');
72 76
 			for (String line : lines) {
73 77
 				output.accept(new OutputLine(new ErrorOutputSpan(line)));

+ 24
- 0
JavaAnnotations/build.gradle Bestand weergeven

@@ -0,0 +1,24 @@
1
+// Note: "common.gradle" in the root project contains additional initialization
2
+//   for this project. This initialization is applied in the "build.gradle"
3
+//   of the root project.
4
+
5
+// NetBeans will automatically add "run" and "debug" tasks relying on the
6
+// "mainClass" property. You may however define the property prior executing
7
+// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
8
+//
9
+// Note however, that you may define your own "run" and "debug" task if you
10
+// prefer. In this case NetBeans will not add these tasks but you may rely on
11
+// your own implementation.
12
+if (!hasProperty('mainClass')) {
13
+    ext.mainClass = ''
14
+}
15
+
16
+dependencies {
17
+    // TODO: Add dependencies here
18
+    //   but note that JUnit should have already been added in parent.gradle.
19
+    //   By default, only the Maven Central Repository is specified in
20
+    //   parent.gradle.
21
+    //
22
+    // You can read more about how to add dependency here:
23
+    //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
24
+}

+ 23
- 0
JavaAnnotations/src/main/java/org/openzen/zencode/java/ZenCodeGlobals.java Bestand weergeven

@@ -0,0 +1,23 @@
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.zencode.java;
7
+
8
+import java.lang.annotation.ElementType;
9
+import java.lang.annotation.Retention;
10
+import java.lang.annotation.RetentionPolicy;
11
+import java.lang.annotation.Target;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public interface ZenCodeGlobals {
18
+	@Retention(RetentionPolicy.RUNTIME)
19
+	@Target({ElementType.FIELD, ElementType.METHOD})
20
+	@interface Global {
21
+		String value() default "";
22
+	}
23
+}

+ 164
- 0
JavaAnnotations/src/main/java/org/openzen/zencode/java/ZenCodeType.java Bestand weergeven

@@ -0,0 +1,164 @@
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.zencode.java;
7
+
8
+import java.lang.annotation.ElementType;
9
+import java.lang.annotation.Retention;
10
+import java.lang.annotation.RetentionPolicy;
11
+import java.lang.annotation.Target;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public interface ZenCodeType {
18
+	@Retention(RetentionPolicy.RUNTIME)
19
+	@Target(ElementType.TYPE)
20
+	@interface Expansion {
21
+		String value();
22
+	}
23
+	
24
+	@Retention(RetentionPolicy.RUNTIME)
25
+	@Target(ElementType.TYPE)
26
+	@interface Name {
27
+		String value();
28
+	}
29
+	
30
+	@Retention(RetentionPolicy.RUNTIME)
31
+	@Target(ElementType.TYPE)
32
+	@interface Struct {}
33
+	
34
+	@Retention(RetentionPolicy.RUNTIME)
35
+	@Target(ElementType.FIELD)
36
+	@interface Field {
37
+		String value() default "";
38
+	}
39
+	
40
+	@Retention(RetentionPolicy.RUNTIME)
41
+	@Target(ElementType.METHOD)
42
+	@interface Method {
43
+		String value() default "";
44
+	}
45
+	
46
+	@Retention(RetentionPolicy.RUNTIME)
47
+	@Target(ElementType.METHOD)
48
+	@interface Operator {
49
+		OperatorType value();
50
+	}
51
+	
52
+	@Retention(RetentionPolicy.RUNTIME)
53
+	@Target(ElementType.METHOD)
54
+	@interface Getter {
55
+		String value() default "";
56
+	}
57
+	
58
+	@Retention(RetentionPolicy.RUNTIME)
59
+	@Target(ElementType.METHOD)
60
+	@interface Setter {
61
+		String value() default "";
62
+	}
63
+	
64
+	@Retention(RetentionPolicy.RUNTIME)
65
+	@Target(ElementType.METHOD)
66
+	@interface Caster {
67
+		boolean implicit() default false;
68
+	}
69
+	
70
+	@Retention(RetentionPolicy.RUNTIME)
71
+	@Target(ElementType.TYPE_USE)
72
+	@interface Nullable {}
73
+	
74
+	@Retention(RetentionPolicy.RUNTIME)
75
+	@Target(ElementType.TYPE_USE)
76
+	@interface Unsigned {}
77
+	
78
+	@Retention(RetentionPolicy.RUNTIME)
79
+	@Target(ElementType.TYPE_USE)
80
+	@interface USize {}
81
+	
82
+	@Retention(RetentionPolicy.RUNTIME)
83
+	@Target(ElementType.TYPE_USE)
84
+	@interface NullableUSize {}
85
+	
86
+	@Retention(RetentionPolicy.RUNTIME)
87
+	@Target(ElementType.TYPE_USE)
88
+	@interface BorrowForCall {}
89
+	
90
+	@Retention(RetentionPolicy.RUNTIME)
91
+	@Target(ElementType.TYPE_USE)
92
+	@interface BorrowForThis {}
93
+	
94
+	@Retention(RetentionPolicy.RUNTIME)
95
+	@Target(ElementType.PARAMETER)
96
+	@interface Optional {}
97
+	
98
+	@Retention(RetentionPolicy.RUNTIME)
99
+	@Target(ElementType.PARAMETER)
100
+	@interface OptionalInt {
101
+		int value() default 0;
102
+	}
103
+	
104
+	@Retention(RetentionPolicy.RUNTIME)
105
+	@Target(ElementType.PARAMETER)
106
+	@interface OptionalLong {
107
+		long value() default 0;
108
+	}
109
+	
110
+	@Retention(RetentionPolicy.RUNTIME)
111
+	@Target(ElementType.PARAMETER)
112
+	@interface OptionalFloat {
113
+		float value() default 0;
114
+	}
115
+	
116
+	@Retention(RetentionPolicy.RUNTIME)
117
+	@Target(ElementType.PARAMETER)
118
+	@interface OptionalDouble {
119
+		double value() default 0;
120
+	}
121
+	
122
+	@Retention(RetentionPolicy.RUNTIME)
123
+	@Target(ElementType.PACKAGE)
124
+	@interface OptionalString {
125
+		String value() default "";
126
+	}
127
+	
128
+	enum OperatorType {
129
+		ADD,		// binary + (addition)
130
+		SUB,		// binary - (subtraction)
131
+		MUL,			// binary * (multiplication)
132
+		DIV,		// binary / (division)
133
+		MOD,		// binary % (modulo)
134
+		CAT,		// binary ~ (concatenation)
135
+		OR,			// binary | (or)
136
+		AND,		// binary & (and)
137
+		XOR,		// binary ^ (xor)
138
+		NEG,		// unary - (negation)
139
+		INVERT,		// unary ~ (bitwise not)
140
+		NOT,		// unary ! (logical not)
141
+		INDEXSET,	// indexed set (array[x, y] = z will be translated to array.INDEXSET(x, y, z)
142
+		INDEXGET,	// indexed get (array[x, y] will be translated to array.INDEXGET(x, y)
143
+		CONTAINS,	// contains (x in y will be translated to y.CONTAINS(x)
144
+		COMPARE,	// comparison (x < y will be translated to x.COMPARE(y) < 0)
145
+		MEMBERGETTER, // member getter (x.name will be translated to x.MEMBERGETTER("name") if there is no member name in x)
146
+		MEMBERSETTER, // member setter (x.name = y will be translated to x.MEMBERSETTER("name", y) if there is no member name in x)
147
+		EQUALS,		// equality operator ==
148
+		NOTEQUALS,	// inequality operator != (note that by default, the inverse of equals will be used)
149
+		SHL,			// binary << (shift left)
150
+		SHR,		// binary >> (shift right)
151
+		
152
+		ADDASSIGN,	// += (by default, x += y will be translated to x = x + y unless this operator is implemented)
153
+		SUBASSIGN,	// -= (by default, x -= y will be translated to x = x - y unless this operator is implemented)
154
+		MULASSIGN,	// *= (by default, x *= y will be translated to x = x * y unless this operator is implemented)
155
+		DIVASSIGN,	// /= (by default, x /= y will be translated to x = x / y unless this operator is implemented)
156
+		MODASSIGN,	// %= (by default, x %= y will be translated to x = x % y unless this operator is implemented)
157
+		CATASSIGN,	// ~= (by default, x ~= y will be translated to x = x ~ y unless this operator is implemented)
158
+		ORASSIGN,	// |= (by default, x |= y will be translated to x = x | y unless this operator is implemented)
159
+		ANDASSIGN,	// &= (by default, x &= y will be translated to x = x & y unless this operator is implemented)
160
+		XORASSIGN,	// ^= (by default, x ^= y will be translated to x = x ^ y unless this operator is implemented)
161
+		SHLASSIGN,	// >>= (by default, x >>= y will be translated to x = x >> y unless this operator is implemented)
162
+		SHRASSIGN	// <<= (by default, x <<= y will be translated to x = x << y unless this operator is implemented)
163
+	}
164
+}

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTarget.java Bestand weergeven

@@ -28,7 +28,7 @@ public class JavaBytecodeJarTarget implements Target {
28 28
 
29 29
 	@Override
30 30
 	public JavaCompiler createCompiler(SemanticModule module) {
31
-		return new JavaCompiler(module.compilationUnit.globalTypeRegistry, debugCompiler, file);
31
+		return new JavaCompiler(module.registry, debugCompiler, file);
32 32
 	}
33 33
 
34 34
 	@Override

+ 43
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeModule.java Bestand weergeven

@@ -0,0 +1,43 @@
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.javabytecode;
7
+
8
+import java.util.ArrayList;
9
+import java.util.HashMap;
10
+import java.util.List;
11
+import java.util.Map;
12
+import org.openzen.zenscript.codemodel.Module;
13
+import org.openzen.zenscript.javashared.JavaCompiledModule;
14
+import org.openzen.zenscript.javashared.JavaMethod;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public class JavaBytecodeModule extends JavaCompiledModule {
21
+	private final Map<String, byte[]> classes = new HashMap<>();
22
+	private final List<JavaMethod> scripts = new ArrayList<>();
23
+	
24
+	public JavaBytecodeModule(Module module) {
25
+		super(module);
26
+	}
27
+	
28
+	public void addClass(String name, byte[] bytecode) {
29
+		classes.put(name, bytecode);
30
+	}
31
+	
32
+	public void addScript(JavaMethod method) {
33
+		scripts.add(method);
34
+	}
35
+	
36
+	public Map<String, byte[]> getClasses() {
37
+		return classes;
38
+	}
39
+	
40
+	public List<JavaMethod> getScripts() {
41
+		return scripts;
42
+	}
43
+}

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTarget.java Bestand weergeven

@@ -25,7 +25,7 @@ public class JavaBytecodeRunTarget implements Target {
25 25
 
26 26
 	@Override
27 27
 	public JavaCompiler createCompiler(SemanticModule module) {
28
-		return new JavaCompiler(module.compilationUnit.globalTypeRegistry, debugCompiler, null);
28
+		return new JavaCompiler(module.registry, debugCompiler, null);
29 29
 	}
30 30
 
31 31
 	@Override

+ 87
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunUnit.java Bestand weergeven

@@ -0,0 +1,87 @@
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.javabytecode;
7
+
8
+import java.lang.reflect.InvocationTargetException;
9
+import java.util.ArrayList;
10
+import java.util.HashMap;
11
+import java.util.List;
12
+import java.util.Map;
13
+import java.util.logging.Level;
14
+import java.util.logging.Logger;
15
+import org.objectweb.asm.ClassWriter;
16
+import org.objectweb.asm.Opcodes;
17
+import org.openzen.zenscript.javabytecode.compiler.JavaClassWriter;
18
+import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
19
+import org.openzen.zenscript.javashared.JavaClass;
20
+import org.openzen.zenscript.javashared.JavaMethod;
21
+
22
+/**
23
+ *
24
+ * @author Hoofdgebruiker
25
+ */
26
+public class JavaBytecodeRunUnit {
27
+	private final Map<String, byte[]> classes = new HashMap<>();
28
+	private final List<JavaMethod> scripts = new ArrayList<>();
29
+	
30
+	private boolean scriptsWritten = false;
31
+	
32
+	public void add(JavaBytecodeModule module) {
33
+		scriptsWritten = false;
34
+		
35
+		for (Map.Entry<String, byte[]> classEntry : module.getClasses().entrySet())
36
+			classes.put(classEntry.getKey().replace('/', '.'), classEntry.getValue());
37
+		
38
+		scripts.addAll(module.getScripts());
39
+	}
40
+	
41
+	public void run() {
42
+		if (!scriptsWritten)
43
+			writeScripts();
44
+		
45
+		ScriptClassLoader classLoader = new ScriptClassLoader();
46
+
47
+		try {
48
+			classLoader.loadClass("Scripts").getMethod("run").invoke(null);
49
+		} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException | IllegalAccessException | SecurityException | IllegalArgumentException ex) {
50
+			Logger.getLogger(JavaModule.class.getName()).log(Level.SEVERE, null, ex);
51
+		}
52
+	}
53
+	
54
+	private void writeScripts() {
55
+		JavaClassWriter scriptsClassWriter = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
56
+		scriptsClassWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "Scripts", null, "java/lang/Object", null);
57
+		
58
+		JavaMethod runMethod = JavaMethod.getStatic(new JavaClass("script", "Scripts", JavaClass.Kind.CLASS), "run", "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
59
+		final JavaWriter runWriter = new JavaWriter(scriptsClassWriter, runMethod, null, null, null);
60
+		runWriter.start();
61
+		for (JavaMethod method : scripts)
62
+			runWriter.invokeStatic(method);
63
+		
64
+		runWriter.ret();
65
+		runWriter.end();
66
+		
67
+		classes.put("Scripts", scriptsClassWriter.toByteArray());
68
+	}
69
+
70
+	public class ScriptClassLoader extends ClassLoader {
71
+		private final Map<String, Class> customClasses = new HashMap<>();
72
+
73
+		@Override
74
+		public Class<?> loadClass(String name) throws ClassNotFoundException {
75
+			//System.out.println("LoadClass " + name);
76
+			
77
+			if (customClasses.containsKey(name))
78
+				return customClasses.get(name);
79
+			if (classes.containsKey(name)) {
80
+				final byte[] bytes = classes.get(name);
81
+				customClasses.put(name, defineClass(name, bytes, 0, bytes.length, null));
82
+				return customClasses.get(name);
83
+			}
84
+			return super.loadClass(name);
85
+		}
86
+	}
87
+}

+ 51
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Bestand weergeven

@@ -27,6 +27,8 @@ import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
27 27
 import org.openzen.zenscript.javabytecode.compiler.definitions.JavaDefinitionVisitor;
28 28
 import org.openzen.zenscript.javashared.JavaBaseCompiler;
29 29
 import org.openzen.zenscript.javashared.JavaClass;
30
+import org.openzen.zenscript.javashared.JavaCompileSpace;
31
+import org.openzen.zenscript.javashared.JavaCompiledModule;
30 32
 import org.openzen.zenscript.javashared.JavaContext;
31 33
 import org.openzen.zenscript.javashared.JavaMethod;
32 34
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionMemberVisitor;
@@ -64,6 +66,55 @@ public class JavaCompiler extends JavaBaseCompiler implements ZenCodeCompiler {
64 66
 		return context;
65 67
 	}
66 68
 	
69
+	//@Override
70
+	public JavaBytecodeModule compile(SemanticModule module, JavaCompileSpace space) {
71
+		context.addModule(module.module);
72
+		
73
+		JavaBytecodeModule target = new JavaBytecodeModule(module.module);
74
+		for (HighLevelDefinition definition : module.definitions.getAll()) {
75
+			JavaPrepareDefinitionMemberVisitor memberPreparer = new JavaPrepareDefinitionMemberVisitor(context, context.getJavaModule(definition.module));
76
+			definition.accept(memberPreparer);
77
+		}
78
+		
79
+		for (HighLevelDefinition definition : module.definitions.getAll()) {
80
+			String className = getClassName(definition.position.getFilename());
81
+			JavaScriptFile scriptFile = getScriptFile(className);
82
+			
83
+			target.addClass(definition.name, definition.accept(new JavaDefinitionVisitor(context, scriptFile.classWriter)));
84
+		}
85
+		
86
+		for (ScriptBlock script : module.scripts) {
87
+			final SourceFile sourceFile = script.getTag(SourceFile.class);
88
+			final String className = getClassName(sourceFile == null ? null : sourceFile.getFilename());
89
+			JavaScriptFile scriptFile = getScriptFile(script.pkg.fullName + "/" + className);
90
+
91
+			String methodName = scriptFile.scriptMethods.isEmpty() ? "run" : "run" + scriptFile.scriptMethods.size();
92
+
93
+			// convert scripts into methods (add them to a Scripts class?)
94
+			// (TODO: can we break very long scripts into smaller methods? for the extreme scripts)
95
+			final JavaClassWriter visitor = scriptFile.classWriter;
96
+			JavaMethod method = JavaMethod.getStatic(new JavaClass(script.pkg.fullName, className, JavaClass.Kind.CLASS), methodName, "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
97
+			scriptFile.scriptMethods.add(method);
98
+
99
+			final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, context.getJavaModule(script.module), new JavaWriter(visitor, method, null, null, null));
100
+			statementVisitor.start();
101
+			for (Statement statement : script.statements) {
102
+				statement.accept(statementVisitor);
103
+			}
104
+			statementVisitor.end();
105
+		}
106
+		
107
+		for (Map.Entry<String, JavaScriptFile> entry : scriptBlocks.entrySet()) {
108
+			for (JavaMethod method : entry.getValue().scriptMethods)
109
+				target.addScript(method);
110
+
111
+			entry.getValue().classWriter.visitEnd();
112
+			target.addClass(entry.getKey(), entry.getValue().classWriter.toByteArray());
113
+		}
114
+
115
+		return target;
116
+	}
117
+	
67 118
 	@Override
68 119
 	public ZenCodeCompilingModule addModule(SemanticModule module) {
69 120
 		context.addModule(module.module);

+ 2
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java Bestand weergeven

@@ -68,9 +68,9 @@ public class CompilerUtils {
68 68
                     constructorWriter.loadObject(0);
69 69
                 field.initializer.accept(expressionVisitor);
70 70
                 if (staticFields)
71
-                    constructorWriter.putStaticField(definition.name, field.name, context.getDescriptor(field.type));
71
+                    constructorWriter.putStaticField(definition.name, field.name, context.getDescriptor(field.getType()));
72 72
                 else
73
-                    constructorWriter.putField(definition.name, field.name, context.getDescriptor(field.type));
73
+                    constructorWriter.putField(definition.name, field.name, context.getDescriptor(field.getType()));
74 74
             }
75 75
         }
76 76
     }

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java Bestand weergeven

@@ -30,7 +30,7 @@ public class JavaWriter {
30 30
     private final LocalVariablesSorter visitor;
31 31
     private final List<JavaLocalVariableInfo> localVariableInfos = new ArrayList<>();
32 32
     public final ClassVisitor clazzVisitor;
33
-    private boolean debug = true;
33
+    private boolean debug = false;
34 34
     private boolean nameVariables = true;
35 35
     private int labelIndex = 1;
36 36
     private Map<Label, String> labelNames = new HashMap<>();

+ 2
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaBaseCompiler.java Bestand weergeven

@@ -1,5 +1,6 @@
1 1
 package org.openzen.zenscript.javashared;
2 2
 
3
+import org.openzen.zenscript.compiler.SemanticModule;
3 4
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
4 5
 
5 6
 /*
@@ -13,5 +14,5 @@ import org.openzen.zenscript.compiler.ZenCodeCompiler;
13 14
  * @author Hoofdgebruiker
14 15
  */
15 16
 public abstract class JavaBaseCompiler implements ZenCodeCompiler {
16
-	
17
+	//public abstract JavaCompiledModule compile(SemanticModule module, JavaCompileSpace space);
17 18
 }

+ 16
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompileSpace.java Bestand weergeven

@@ -0,0 +1,16 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javashared;
7
+
8
+import org.openzen.zenscript.codemodel.Module;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface JavaCompileSpace {
15
+	public JavaCompiledModule getCompiled(Module module);
16
+}

+ 12
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompiledModule.java Bestand weergeven

@@ -5,8 +5,11 @@
5 5
  */
6 6
 package org.openzen.zenscript.javashared;
7 7
 
8
+import java.util.ArrayList;
8 9
 import java.util.HashMap;
10
+import java.util.List;
9 11
 import java.util.Map;
12
+import org.openzen.zencode.shared.CodePosition;
10 13
 import org.openzen.zenscript.codemodel.FunctionParameter;
11 14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 15
 import org.openzen.zenscript.codemodel.Module;
@@ -14,6 +17,8 @@ import org.openzen.zenscript.codemodel.definition.VariantDefinition;
14 17
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
15 18
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
16 19
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
20
+import org.openzen.zenscript.codemodel.statement.BlockStatement;
21
+import org.openzen.zenscript.codemodel.statement.Statement;
17 22
 
18 23
 /**
19 24
  *
@@ -35,6 +40,13 @@ public class JavaCompiledModule {
35 40
 		this.module = module;
36 41
 	}
37 42
 	
43
+	/*public Statement generateModuleDefinitionMethod() {
44
+		List<Statement> statements = new ArrayList<>();
45
+		
46
+		
47
+		return new BlockStatement(CodePosition.GENERATED, statements.toArray(new Statement[statements.size()]));
48
+	}*/
49
+	
38 50
 	public void setClassInfo(HighLevelDefinition definition, JavaClass cls) {
39 51
 		classes.put(definition, cls);
40 52
 	}

+ 4
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java Bestand weergeven

@@ -86,6 +86,10 @@ public abstract class JavaContext {
86 86
 	
87 87
 	public abstract String getDescriptor(StoredType type);
88 88
 	
89
+	public void registerModule(JavaCompiledModule module) {
90
+		modules.put(module.module, module);
91
+	}
92
+	
89 93
 	public void addModule(Module module) {
90 94
 		modules.put(module, new JavaCompiledModule(module));
91 95
 	}

+ 27
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/SimpleJavaCompileSpace.java Bestand weergeven

@@ -0,0 +1,27 @@
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.javashared;
7
+
8
+import java.util.HashMap;
9
+import java.util.Map;
10
+import org.openzen.zenscript.codemodel.Module;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class SimpleJavaCompileSpace implements JavaCompileSpace {
17
+	private final Map<Module, JavaCompiledModule> modules = new HashMap<>();
18
+	
19
+	public void register(JavaCompiledModule module) {
20
+		modules.put(module.module, module);
21
+	}
22
+	
23
+	@Override
24
+	public JavaCompiledModule getCompiled(Module module) {
25
+		return modules.get(module);
26
+	}
27
+}

+ 4
- 5
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java Bestand weergeven

@@ -8,7 +8,6 @@ package org.openzen.zenscript.javashared.prepare;
8 8
 import org.openzen.zenscript.javashared.JavaNativeClass;
9 9
 import org.openzen.zencode.shared.StringExpansion;
10 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
-import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 11
 import org.openzen.zenscript.codemodel.OperatorType;
13 12
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
14 13
 import org.openzen.zenscript.codemodel.member.CallerMember;
@@ -76,13 +75,13 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
76 75
 			System.out.println("Class " + cls.fullName + " not empty because of const " + member.name);
77 76
 		
78 77
 		cls.empty = false;
79
-		module.setFieldInfo(member, new JavaField(cls, member.name, context.getDescriptor(member.type)));
78
+		module.setFieldInfo(member, new JavaField(cls, member.name, context.getDescriptor(member.getType())));
80 79
 		return null;
81 80
 	}
82 81
 	
83 82
 	@Override
84 83
 	public Void visitField(FieldMember member) {
85
-		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.type));
84
+		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.getType()));
86 85
 		module.setFieldInfo(member, field);
87 86
 		if (member.hasAutoGetter()) {
88 87
 			visitGetter(member.autoGetter);
@@ -119,13 +118,13 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
119 118
 
120 119
 	@Override
121 120
 	public Void visitGetter(GetterMember member) {
122
-		visitFunctional(member, new FunctionHeader(member.type), "get" + StringExpansion.capitalize(member.name));
121
+		visitFunctional(member, new FunctionHeader(member.getType()), "get" + StringExpansion.capitalize(member.name));
123 122
 		return null;
124 123
 	}
125 124
 
126 125
 	@Override
127 126
 	public Void visitSetter(SetterMember member) {
128
-		visitFunctional(member, new FunctionHeader(BasicTypeID.VOID, member.type), "set" + StringExpansion.capitalize(member.name));
127
+		visitFunctional(member, new FunctionHeader(BasicTypeID.VOID, member.getType()), "set" + StringExpansion.capitalize(member.name));
129 128
 		return null;
130 129
 	}
131 130
 

+ 2
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java Bestand weergeven

@@ -130,6 +130,8 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
130 130
 			cls.addInstanceMethod("lastIndexOf", "lastIndexOf", "(I)I");
131 131
 			cls.addInstanceMethod("lastIndexOfFrom", "lastIndexOf", "(II)I");
132 132
 			cls.addInstanceMethod("trim", "trim", "()Ljava/lang/String;");
133
+			cls.addInstanceMethod("startsWith", "startsWith", "(Ljava/lang/String;)Z");
134
+			cls.addInstanceMethod("endsWith", "endsWith", "(Ljava/lang/String;)Z");
133 135
 			cls.addMethod("fromAsciiBytes", new JavaMethod((expression, translator) -> {
134 136
 				CallStaticExpression call = (CallStaticExpression)expression;
135 137
 				return translator.bytesAsciiToString(call.arguments.arguments[0]);

+ 4
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java Bestand weergeven

@@ -60,7 +60,7 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
60 60
 	
61 61
 	@Override
62 62
 	public Void visitConst(ConstMember member) {
63
-		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.type));
63
+		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.getType()));
64 64
 		module.setFieldInfo(member, field);
65 65
 		
66 66
 		if (DEBUG_EMPTY && cls.empty)
@@ -73,7 +73,7 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
73 73
 	@Override
74 74
 	public Void visitField(FieldMember member) {
75 75
 		// TODO: expansion fields
76
-		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.type));
76
+		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.getType()));
77 77
 		module.setFieldInfo(member, field);
78 78
 		
79 79
 		if (member.hasAutoGetter() || member.hasAutoSetter())
@@ -104,13 +104,13 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
104 104
 
105 105
 	@Override
106 106
 	public Void visitGetter(GetterMember member) {
107
-		visitFunctional(member, new FunctionHeader(member.type), "get" + StringExpansion.capitalize(member.name));
107
+		visitFunctional(member, new FunctionHeader(member.getType()), "get" + StringExpansion.capitalize(member.name));
108 108
 		return null;
109 109
 	}
110 110
 
111 111
 	@Override
112 112
 	public Void visitSetter(SetterMember member) {
113
-		visitFunctional(member, new FunctionHeader(BasicTypeID.VOID, member.type), "set" + StringExpansion.capitalize(member.name));
113
+		visitFunctional(member, new FunctionHeader(BasicTypeID.VOID, member.getType()), "set" + StringExpansion.capitalize(member.name));
114 114
 		return null;
115 115
 	}
116 116
 

+ 1
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/FormattingUtils.java Bestand weergeven

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
12 12
 import org.openzen.zenscript.codemodel.type.StoredType;
13 13
 import org.openzen.zenscript.formattershared.ExpressionString;
14 14
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
15
+import org.openzen.zenscript.javashared.JavaTypeUtils;
15 16
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
16 17
 
17 18
 /**

+ 7
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java Bestand weergeven

@@ -78,10 +78,15 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
78 78
 	}
79 79
 	
80 80
 	private JavaSourceFileScope createScope(HighLevelDefinition definition) {
81
-		GlobalTypeRegistry typeRegistry = semanticModule.compilationUnit.globalTypeRegistry;
81
+		GlobalTypeRegistry typeRegistry = semanticModule.registry;
82 82
 		DefinitionTypeID thisType = typeRegistry.getForMyDefinition(definition);
83 83
 		
84
-		CompileScope scope = new CompileScope(semanticModule.compilationUnit.globalTypeRegistry, semanticModule.expansions, semanticModule.annotations, semanticModule.storageTypes);
84
+		CompileScope scope = new CompileScope(
85
+				semanticModule.registry,
86
+				semanticModule.rootPackage,
87
+				semanticModule.expansions,
88
+				semanticModule.annotations,
89
+				semanticModule.storageTypes);
85 90
 		return new JavaSourceFileScope(file.importer, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition, thisType, compiler.context);
86 91
 	}
87 92
 	

+ 4
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java Bestand weergeven

@@ -81,7 +81,7 @@ public class JavaExpansionMemberCompiler extends BaseMemberCompiler {
81 81
 	public Void visitConst(ConstMember member) {
82 82
 		begin(ElementType.FIELD);
83 83
 		modifiers(member.getEffectiveModifiers() | Modifiers.STATIC | Modifiers.FINAL);
84
-		output.append(scope.type(member.type));
84
+		output.append(scope.type(member.getType()));
85 85
 		output.append(" ");
86 86
 		output.append(member.name);
87 87
 		output.append(" = ");
@@ -107,7 +107,7 @@ public class JavaExpansionMemberCompiler extends BaseMemberCompiler {
107 107
 		
108 108
 		this.modifiers(modifiers);
109 109
 		
110
-		output.append(scope.type(member.type));
110
+		output.append(scope.type(member.getType()));
111 111
 		output.append(" ");
112 112
 		output.append(member.name);
113 113
 		if (member.initializer != null) {
@@ -139,13 +139,13 @@ public class JavaExpansionMemberCompiler extends BaseMemberCompiler {
139 139
 
140 140
 	@Override
141 141
 	public Void visitGetter(GetterMember member) {
142
-		compileMethod(member, new FunctionHeader(member.type), member.body);
142
+		compileMethod(member, new FunctionHeader(member.getType()), member.body);
143 143
 		return null;
144 144
 	}
145 145
 
146 146
 	@Override
147 147
 	public Void visitSetter(SetterMember member) {
148
-		compileMethod(member, new FunctionHeader(BasicTypeID.VOID, new FunctionParameter(member.type, "value")), member.body);
148
+		compileMethod(member, new FunctionHeader(BasicTypeID.VOID, new FunctionParameter(member.getType(), "value")), member.body);
149 149
 		return null;
150 150
 	}
151 151
 

+ 4
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Bestand weergeven

@@ -114,7 +114,7 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
114 114
 		
115 115
 		output.append(indent);
116 116
 		modifiers(member.getEffectiveModifiers() | Modifiers.STATIC | Modifiers.FINAL);
117
-		output.append(scope.type(member.type));
117
+		output.append(scope.type(member.getType()));
118 118
 		output.append(" ");
119 119
 		output.append(member.name);
120 120
 		output.append(" = ");
@@ -140,7 +140,7 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
140 140
 		
141 141
 		this.modifiers(modifiers);
142 142
 		
143
-		output.append(scope.type(member.type));
143
+		output.append(scope.type(member.getType()));
144 144
 		output.append(" ");
145 145
 		output.append(member.name);
146 146
 		if (member.initializer != null) {
@@ -190,13 +190,13 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
190 190
 
191 191
 	@Override
192 192
 	public Void visitGetter(GetterMember member) {
193
-		compileMethod(member, new FunctionHeader(member.type), member.body);
193
+		compileMethod(member, new FunctionHeader(member.getType()), member.body);
194 194
 		return null;
195 195
 	}
196 196
 
197 197
 	@Override
198 198
 	public Void visitSetter(SetterMember member) {
199
-		compileMethod(member, new FunctionHeader(BasicTypeID.VOID, new FunctionParameter(member.type, "value")), member.body);
199
+		compileMethod(member, new FunctionHeader(BasicTypeID.VOID, new FunctionParameter(member.getType(), "value")), member.body);
200 200
 		return null;
201 201
 	}
202 202
 

+ 3
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java Bestand weergeven

@@ -14,7 +14,7 @@ import org.openzen.zencode.shared.SourceFile;
14 14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 15
 import org.openzen.zenscript.codemodel.ScriptBlock;
16 16
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
17
-import org.openzen.zenscript.compiler.CompilationUnit;
17
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
18 18
 import org.openzen.zenscript.compiler.SemanticModule;
19 19
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
20 20
 import org.openzen.zenscript.compiler.ZenCodeCompilingModule;
@@ -34,12 +34,12 @@ public class JavaSourceCompiler extends JavaBaseCompiler implements ZenCodeCompi
34 34
 	public final JavaSourceContext context;
35 35
 	private final List<SourceModule> modules = new ArrayList<>();
36 36
 	
37
-	public JavaSourceCompiler(File directory, CompilationUnit compilationUnit) {
37
+	public JavaSourceCompiler(File directory, GlobalTypeRegistry registry) {
38 38
 		if (!directory.exists())
39 39
 			directory.mkdirs();
40 40
 		
41 41
 		settings = new JavaSourceFormattingSettings.Builder().build();
42
-		context = new JavaSourceContext(compilationUnit.globalTypeRegistry, directory, settings);
42
+		context = new JavaSourceContext(registry, directory, settings);
43 43
 		helperGenerator = new JavaSourceSyntheticHelperGenerator(context, directory, settings);
44 44
 		
45 45
 		this.directory = directory;

+ 13
- 6
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java Bestand weergeven

@@ -127,6 +127,13 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
127 127
 		this.scope = scope;
128 128
 		context = scope.context;
129 129
 	}
130
+	
131
+	private ExpressionString getValue(Expression expression) {
132
+		ExpressionString source = expression.accept(this);
133
+		if (JavaTypeUtils.isShared(expression.type) && !(expression instanceof ThisExpression))
134
+			source = source.unaryPostfix(JavaOperator.CALL, ".get()");
135
+		return source;
136
+	}
130 137
 
131 138
 	@Override
132 139
 	public ExpressionString visitAndAnd(AndAndExpression expression) {
@@ -157,7 +164,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
157 164
 			return visitBuiltinCompare(expression, expression.operator.getBuiltin());
158 165
 		
159 166
 		StringBuilder output = new StringBuilder();
160
-		output.append(expression.left.accept(this).value);
167
+		output.append(getValue(expression.left).value);
161 168
 		output.append(".compareTo(");
162 169
 		output.append(expression.right.accept(this));
163 170
 		output.append(") ");
@@ -188,12 +195,12 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
188 195
 				output.append(scope.type(method.cls));
189 196
 				output.append('.');
190 197
 				output.append(method.name);
191
-				FormattingUtils.formatExpansionCall(output, this.target, scope, target.accept(this), arguments);
198
+				FormattingUtils.formatExpansionCall(output, this.target, scope, getValue(target), arguments);
192 199
 				return new ExpressionString(output.toString(), JavaOperator.CALL);
193 200
 			}
194 201
 			case INSTANCE: {
195 202
 				StringBuilder output = new StringBuilder();
196
-				output.append(target.accept(this).value);
203
+				output.append(getValue(target).value);
197 204
 				output.append('.');
198 205
 				output.append(method.name);
199 206
 				FormattingUtils.formatCall(output, this.target, scope, arguments);
@@ -428,7 +435,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
428 435
 	public ExpressionString visitGetField(GetFieldExpression expression) {
429 436
 		StringBuilder result = new StringBuilder();
430 437
 		if (!(expression.target instanceof ThisExpression && !scope.hasLocalVariable(expression.field.member.name))) {
431
-			result.append(expression.target.accept(this));
438
+			result.append(getValue(expression.target));
432 439
 			result.append('.');
433 440
 		}
434 441
 		result.append(expression.field.member.name);
@@ -464,7 +471,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
464 471
 		if (expression.getter.member.builtin != null)
465 472
 			return visitBuiltinGetter(expression, expression.getter.member.builtin);
466 473
 		
467
-		ExpressionString target = expression.target.accept(this);
474
+		ExpressionString target = getValue(expression.target);
468 475
 		if (context.hasJavaField(expression.getter)) {
469 476
 			JavaField field = context.getJavaField(expression.getter);
470 477
 			if (target.value.equals("this") && !scope.hasLocalVariable(field.name))
@@ -656,7 +663,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
656 663
 	@Override
657 664
 	public ExpressionString visitSetter(SetterExpression expression) {
658 665
 		return new ExpressionString(
659
-				expression.target.accept(this) + "." + expression.setter.member.name + " = " + expression.value.accept(this),
666
+				getValue(expression.target) + "." + expression.setter.member.name + " = " + expression.value.accept(this),
660 667
 				JavaOperator.ASSIGN);
661 668
 	}
662 669
 

+ 4
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java Bestand weergeven

@@ -106,6 +106,10 @@ public class JavaSourceSyntheticTypeGenerator implements JavaSyntheticClassGener
106 106
 		contents.append(settings.indent).append(settings.indent).append("this.value = value;\n");
107 107
 		contents.append(settings.indent).append("}\n");
108 108
 		contents.append(settings.indent).append("\n");
109
+		contents.append(settings.indent).append("public T get() {\n");
110
+		contents.append(settings.indent).append(settings.indent).append("return value;\n");
111
+		contents.append(settings.indent).append("}\n");
112
+		contents.append(settings.indent).append("\n");
109 113
 		contents.append(settings.indent).append("public synchronized void addRef() {\n");
110 114
 		contents.append(settings.indent).append(settings.indent).append("refcount++;\n");
111 115
 		contents.append(settings.indent).append("}\n");

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTarget.java Bestand weergeven

@@ -28,7 +28,7 @@ public class JavaSourceTarget implements Target {
28 28
 
29 29
 	@Override
30 30
 	public ZenCodeCompiler createCompiler(SemanticModule module) {
31
-		return new JavaSourceCompiler(output, module.compilationUnit);
31
+		return new JavaSourceCompiler(output, module.registry);
32 32
 	}
33 33
 
34 34
 	@Override

+ 9
- 10
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java Bestand weergeven

@@ -45,7 +45,6 @@ import org.openzen.zenscript.parser.statements.ParsedStatement;
45 45
  */
46 46
 public class ParsedFile {
47 47
 	public static SemanticModule compileSyntaxToSemantic(
48
-			String name,
49 48
 			SemanticModule[] dependencies,
50 49
 			CompilingPackage pkg,
51 50
 			ParsedFile[] files,
@@ -70,7 +69,7 @@ public class ParsedFile {
70 69
 		boolean failed = false;
71 70
 		
72 71
 		ModuleTypeResolutionContext moduleContext = new ModuleTypeResolutionContext(
73
-				registry.compilationUnit.globalTypeRegistry,
72
+				registry.registry,
74 73
 				registry.getAnnotations(),
75 74
 				registry.getStorageTypes(),
76 75
 				rootPackage,
@@ -89,7 +88,7 @@ public class ParsedFile {
89 88
 		}
90 89
 		
91 90
 		if (failed)
92
-			return new SemanticModule(name, pkg.module, dependencies, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations(), registry.getStorageTypes());
91
+			return new SemanticModule(pkg.module, dependencies, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.registry, expansions, registry.getAnnotations(), registry.getStorageTypes());
93 92
 		
94 93
 		// scripts will store all the script blocks encountered in the files
95 94
 		PrecompilationState precompiler = new PrecompilationState();
@@ -106,7 +105,6 @@ public class ParsedFile {
106 105
 		}
107 106
 		
108 107
 		return new SemanticModule(
109
-				name,
110 108
 				pkg.module,
111 109
 				dependencies,
112 110
 				SemanticModule.State.ASSEMBLED,
@@ -114,7 +112,7 @@ public class ParsedFile {
114 112
 				pkg.getPackage(),
115 113
 				definitions,
116 114
 				scripts,
117
-				registry.compilationUnit,
115
+				registry.registry,
118 116
 				expansions,
119 117
 				registry.getAnnotations(),
120 118
 				registry.getStorageTypes());
@@ -229,7 +227,7 @@ public class ParsedFile {
229 227
 			ModuleTypeResolutionContext moduleContext,
230 228
 			ZSPackage rootPackage,
231 229
 			CompilingPackage modulePackage) {
232
-		FileResolutionContext context = new FileResolutionContext(moduleContext, modulePackage);
230
+		FileResolutionContext context = new FileResolutionContext(moduleContext, rootPackage, modulePackage);
233 231
 		loadImports(context, rootPackage, modulePackage);
234 232
 		
235 233
 		for (ParsedDefinition definition : this.definitions) {
@@ -242,7 +240,7 @@ public class ParsedFile {
242 240
 			ModuleTypeResolutionContext moduleContext,
243 241
 			ZSPackage rootPackage,
244 242
 			CompilingPackage modulePackage) {
245
-		FileResolutionContext context = new FileResolutionContext(moduleContext, modulePackage);
243
+		FileResolutionContext context = new FileResolutionContext(moduleContext, rootPackage, modulePackage);
246 244
 		loadImports(context, rootPackage, modulePackage);
247 245
 		
248 246
 		for (ParsedDefinition definition : this.definitions) {
@@ -262,7 +260,7 @@ public class ParsedFile {
262 260
 			CompilingPackage modulePackage,
263 261
 			List<ExpansionDefinition> expansions,
264 262
 			Map<String, ISymbol> globals) {
265
-		FileResolutionContext context = new FileResolutionContext(moduleContext, modulePackage);
263
+		FileResolutionContext context = new FileResolutionContext(moduleContext, rootPackage, modulePackage);
266 264
 		loadImports(context, rootPackage, modulePackage);
267 265
 		
268 266
 		FileScope scope = new FileScope(context, expansions, globals, precompiler);
@@ -280,7 +278,7 @@ public class ParsedFile {
280 278
 			List<ScriptBlock> scripts,
281 279
 			Map<String, ISymbol> globals,
282 280
 			Consumer<CompileException> exceptionLogger) {
283
-		FileResolutionContext context = new FileResolutionContext(moduleContext, modulePackage);
281
+		FileResolutionContext context = new FileResolutionContext(moduleContext, rootPackage, modulePackage);
284 282
 		loadImports(context, rootPackage, modulePackage);
285 283
 		
286 284
 		FileScope scope = new FileScope(context, expansions, globals, precompiler);
@@ -319,7 +317,8 @@ public class ParsedFile {
319 317
 			//if (definition == null)
320 318
 			//	importErrors.add(new CompileException(importEntry.position, CompileExceptionCode.IMPORT_NOT_FOUND, "Could not find type " + importEntry.toString()));
321 319
 			
322
-			context.addImport(importEntry.getName(), definition);
320
+			if (definition != null)
321
+				context.addImport(importEntry.getName(), definition);
323 322
 		}
324 323
 	}
325 324
 }

+ 82
- 0
Parser/src/main/java/org/openzen/zenscript/parser/ZippedPackage.java Bestand weergeven

@@ -0,0 +1,82 @@
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.parser;
7
+
8
+import java.io.BufferedInputStream;
9
+import java.io.IOException;
10
+import java.io.InputStream;
11
+import java.nio.charset.StandardCharsets;
12
+import java.util.ArrayList;
13
+import java.util.HashMap;
14
+import java.util.List;
15
+import java.util.Map;
16
+import java.util.zip.ZipEntry;
17
+import java.util.zip.ZipInputStream;
18
+import org.openzen.zencode.shared.LiteralSourceFile;
19
+import org.openzen.zencode.shared.SourceFile;
20
+import org.openzen.zenscript.codemodel.Module;
21
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
22
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
23
+import org.openzen.zenscript.compiler.ModuleSpace;
24
+import org.openzen.zenscript.compiler.SemanticModule;
25
+import org.openzen.zenscript.lexer.ParseException;
26
+
27
+/**
28
+ *
29
+ * @author Hoofdgebruiker
30
+ */
31
+public class ZippedPackage {
32
+	private Map<String, List<SourceFile>> files = new HashMap<>();
33
+	
34
+	public ZippedPackage(InputStream input) throws IOException {
35
+		try (ZipInputStream zipInput = new ZipInputStream(new BufferedInputStream(input))) {
36
+			ZipEntry entry = zipInput.getNextEntry();
37
+			while (entry != null) {
38
+				int slash = entry.getName().indexOf("/src/");
39
+				if (slash > 0) {
40
+					String moduleName = entry.getName().substring(0, slash);
41
+					String filename = entry.getName().substring(slash + 5);
42
+					if (!files.containsKey(moduleName))
43
+						files.put(moduleName, new ArrayList<>());
44
+					
45
+					byte[] data = new byte[(int)entry.getSize()];
46
+					int read = 0;
47
+					while (read < data.length)
48
+						read += zipInput.read(data, read, data.length - read);
49
+					
50
+					files.get(moduleName).add(new LiteralSourceFile(filename, new String(data, StandardCharsets.UTF_8)));
51
+				}
52
+				
53
+				zipInput.closeEntry();
54
+				entry = zipInput.getNextEntry();
55
+			}
56
+		}
57
+	}
58
+	
59
+	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies) throws ParseException {
60
+		return loadModule(space, name, bracketParser, dependencies, new ZSPackage(space.rootPackage, name));
61
+	}
62
+	
63
+	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, ZSPackage pkg) throws ParseException {
64
+		List<SourceFile> sourceFiles = files.get(name);
65
+		if (sourceFiles == null)
66
+			return null; // no such module
67
+		
68
+		Module scriptModule = new Module(name);
69
+		CompilingPackage scriptPackage = new CompilingPackage(pkg, scriptModule);
70
+		ParsedFile[] files = new ParsedFile[sourceFiles.size()];
71
+		for (int i = 0; i < files.length; i++)
72
+			files[i] = ParsedFile.parse(scriptPackage, bracketParser, sourceFiles.get(i));
73
+		
74
+		SemanticModule scripts = ParsedFile.compileSyntaxToSemantic(
75
+				dependencies,
76
+				scriptPackage,
77
+				files,
78
+				space,
79
+				ex -> ex.printStackTrace());
80
+		return scripts.normalize();
81
+	}
82
+}

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java Bestand weergeven

@@ -48,7 +48,7 @@ public abstract class BaseParsedDefinition extends ParsedDefinition {
48 48
 			return;
49 49
 		typesCompiled = true;
50 50
 		
51
-		System.out.println("compileTypes " + getCompiled().name);
51
+		//System.out.println("compileTypes " + getCompiled().name);
52 52
 		linkTypesLocal(context);
53 53
 	}
54 54
 	

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java Bestand weergeven

@@ -54,10 +54,10 @@ public class ParsedNewExpression extends ParsedExpression{
54 54
 		try {
55 55
 			TypeMembers members = scope.getTypeMembers(type);
56 56
 			TypeMemberGroup constructors = members.getOrCreateGroup(OperatorType.CONSTRUCTOR);
57
-			for (TypeMember<FunctionalMemberRef> member : constructors.getMethodMembers()) {
57
+			/*for (TypeMember<FunctionalMemberRef> member : constructors.getMethodMembers()) {
58 58
 				if (member.member.getBuiltin() == BuiltinID.ARRAY_CONSTRUCTOR_PROJECTED)
59 59
 					System.out.println("X");
60
-			}
60
+			}*/
61 61
 
62 62
 			List<StoredType>[] predictedTypes = constructors.predictCallTypes(scope, scope.hints, arguments.arguments.size());
63 63
 			CallArguments compiledArguments = arguments.compileCall(position, scope, null, constructors);

+ 5
- 5
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedConst.java Bestand weergeven

@@ -77,14 +77,14 @@ public class ParsedConst extends ParsedDefinitionMember {
77 77
 		
78 78
 		if (expression != null) {
79 79
 			Expression initializer = expression
80
-					.compile(new ExpressionScope(scope, compiled.type))
80
+					.compile(new ExpressionScope(scope, compiled.getType()))
81 81
 					.eval()
82
-					.castImplicit(position, scope, compiled.type);
82
+					.castImplicit(position, scope, compiled.getType());
83 83
 			compiled.value = initializer;
84 84
 			
85
-			if (compiled.type.isBasic(BasicTypeID.UNDETERMINED))
86
-				compiled.type = initializer.type;
87
-		} else if (compiled.type.isBasic(BasicTypeID.UNDETERMINED)) {
85
+			if (compiled.getType().isBasic(BasicTypeID.UNDETERMINED))
86
+				compiled.setType(initializer.type);
87
+		} else if (compiled.getType().isBasic(BasicTypeID.UNDETERMINED)) {
88 88
 			throw new CompileException(position, CompileExceptionCode.PRECOMPILE_FAILED, "No type or initializer given");
89 89
 		}
90 90
 	}

+ 5
- 5
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedField.java Bestand weergeven

@@ -92,14 +92,14 @@ public class ParsedField extends ParsedDefinitionMember {
92 92
 		
93 93
 		if (expression != null) {
94 94
 			Expression initializer = expression
95
-					.compile(new ExpressionScope(scope, compiled.type))
95
+					.compile(new ExpressionScope(scope, compiled.getType()))
96 96
 					.eval()
97
-					.castImplicit(position, scope, compiled.type);
97
+					.castImplicit(position, scope, compiled.getType());
98 98
 			compiled.setInitializer(initializer);
99 99
 			
100
-			if (compiled.type.isBasic(BasicTypeID.UNDETERMINED))
101
-				compiled.type = initializer.type;
102
-		} else if (compiled.type.isBasic(BasicTypeID.UNDETERMINED)) {
100
+			if (compiled.getType().isBasic(BasicTypeID.UNDETERMINED))
101
+				compiled.setType(initializer.type);
102
+		} else if (compiled.getType().isBasic(BasicTypeID.UNDETERMINED)) {
103 103
 			throw new CompileException(position, CompileExceptionCode.PRECOMPILE_FAILED, "Could not infer type since no initializer is given");
104 104
 		}
105 105
 	}

+ 5
- 5
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedGetter.java Bestand weergeven

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.HighLevelDefinition;
13 13
 import org.openzen.zenscript.codemodel.Modifiers;
14 14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15 15
 import org.openzen.zenscript.codemodel.member.GetterMember;
16
+import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
16 17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17 18
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
18 19
 import org.openzen.zenscript.codemodel.scope.TypeScope;
@@ -84,7 +85,9 @@ public class ParsedGetter extends ParsedDefinitionMember {
84 85
 	}
85 86
 
86 87
 	private void fillOverride(TypeScope scope, StoredType baseType) {
87
-		compiled.setOverrides(scope.getTypeMembers(baseType).getOrCreateGroup(name, false).getGetter());
88
+		GetterMemberRef getter = scope.getTypeMembers(baseType).getOrCreateGroup(name, false).getGetter();
89
+		if (getter != null)
90
+			compiled.setOverrides(getter);
88 91
 	}
89 92
 	
90 93
 	@Override
@@ -95,12 +98,9 @@ public class ParsedGetter extends ParsedDefinitionMember {
95 98
 		
96 99
 		inferHeaders(scope);
97 100
 		
98
-		FunctionHeader header = new FunctionHeader(compiled.type);
101
+		FunctionHeader header = new FunctionHeader(compiled.getType());
99 102
 		FunctionScope innerScope = new FunctionScope(scope, header);
100 103
 		compiled.annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
101 104
 		compiled.setBody(body.compile(innerScope, header));
102
-		
103
-		if (compiled.type.isBasic(BasicTypeID.UNDETERMINED))
104
-			compiled.type = compiled.body.getReturnType();
105 105
 	}
106 106
 }

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedInnerDefinition.java Bestand weergeven

@@ -43,7 +43,7 @@ public class ParsedInnerDefinition extends ParsedDefinitionMember {
43 43
 			return;
44 44
 		typesCompiled = true;
45 45
 		
46
-		System.out.println("compileTypes " + definition.name + "::" + innerDefinition.getCompiled().name);
46
+		//System.out.println("compileTypes " + definition.name + "::" + innerDefinition.getCompiled().name);
47 47
 		innerDefinition.linkTypes(context);
48 48
 	}
49 49
 

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedSetter.java Bestand weergeven

@@ -95,7 +95,7 @@ public class ParsedSetter extends ParsedDefinitionMember {
95 95
 		
96 96
 		inferHeaders(scope);
97 97
 		
98
-		FunctionHeader header = new FunctionHeader(compiled.type);
98
+		FunctionHeader header = new FunctionHeader(compiled.getType());
99 99
 		FunctionScope innerScope = new FunctionScope(
100 100
 				scope,
101 101
 				header,

+ 7
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java Bestand weergeven

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.statement.CatchClause;
17 17
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
18 18
 import org.openzen.zenscript.codemodel.statement.VarStatement;
19 19
 import org.openzen.zenscript.codemodel.GenericName;
20
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
20 21
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
21 22
 import org.openzen.zenscript.codemodel.scope.StatementScope;
22 23
 import org.openzen.zenscript.codemodel.statement.VariableID;
@@ -57,7 +58,12 @@ public class ParsedCatchClause {
57 58
 			this.outer = outer;
58 59
 			this.exceptionVariable = exceptionVariable;
59 60
 		}
60
-	
61
+
62
+		@Override
63
+		public ZSPackage getRootPackage() {
64
+			return outer.getRootPackage();
65
+		}
66
+		
61 67
 		@Override
62 68
 		public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
63 69
 			if (name.hasNoArguments() && exceptionVariable.name.equals(name.name))

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementSwitch.java Bestand weergeven

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.statement.LoopStatement;
17 17
 import org.openzen.zenscript.codemodel.statement.Statement;
18 18
 import org.openzen.zenscript.codemodel.statement.SwitchStatement;
19 19
 import org.openzen.zenscript.codemodel.GenericName;
20
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
20 21
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
21 22
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
22 23
 import org.openzen.zenscript.codemodel.scope.StatementScope;
@@ -73,6 +74,11 @@ public class ParsedStatementSwitch extends ParsedStatement {
73 74
 			this.outer = outer;
74 75
 			this.target = target;
75 76
 		}
77
+
78
+		@Override
79
+		public ZSPackage getRootPackage() {
80
+			return outer.getRootPackage();
81
+		}
76 82
 	
77 83
 		@Override
78 84
 		public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeGenericMap.java Bestand weergeven

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
13 13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14 14
 import org.openzen.zenscript.codemodel.GenericName;
15
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
15 16
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16 17
 import org.openzen.zenscript.codemodel.type.InvalidTypeID;
17 18
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -67,6 +68,11 @@ public class ParsedTypeGenericMap implements IParsedType {
67 68
 			this.outer = outer;
68 69
 			this.parameter = parameter;
69 70
 		}
71
+
72
+		@Override
73
+		public ZSPackage getRootPackage() {
74
+			return outer.getRootPackage();
75
+		}
70 76
 		
71 77
 		@Override
72 78
 		public GlobalTypeRegistry getTypeRegistry() {

+ 10
- 9
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java Bestand weergeven

@@ -1,7 +1,6 @@
1 1
 package org.openzen.zenscript.scriptingexample;
2 2
 
3 3
 import java.io.File;
4
-import java.io.IOException;
5 4
 import java.util.ArrayList;
6 5
 import java.util.Collections;
7 6
 import java.util.HashMap;
@@ -16,9 +15,9 @@ import org.openzen.zenscript.codemodel.Module;
16 15
 import org.openzen.zenscript.codemodel.ScriptBlock;
17 16
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
18 17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19 19
 import org.openzen.zenscript.codemodel.type.ISymbol;
20 20
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
21
-import org.openzen.zenscript.compiler.CompilationUnit;
22 21
 import org.openzen.zenscript.compiler.SemanticModule;
23 22
 import org.openzen.zenscript.formatter.FileFormatter;
24 23
 import org.openzen.zenscript.formatter.ScriptFormattingSettings;
@@ -50,10 +49,13 @@ public class Main {
50 49
 		CompilingPackage compilingPkg = new CompilingPackage(pkg, module);
51 50
 		ParsedFile[] parsedFiles = parse(compilingPkg, inputFiles);
52 51
 		
53
-		CompilationUnit compileUnit = new CompilationUnit();
52
+		ZSPackage root = ZSPackage.createRoot();
53
+		ZSPackage stdlib = new ZSPackage(root, "stdlib");
54
+		GlobalTypeRegistry typeRegistry = new GlobalTypeRegistry(stdlib);
55
+		
54 56
 		ZSPackage global = new ZSPackage(null, "");
55
-		GlobalRegistry registry = new GlobalRegistry(compileUnit.globalTypeRegistry, global);
56
-		SemanticModule semantic = compileSyntaxToSemantic(compileUnit, compilingPkg, parsedFiles, registry);
57
+		GlobalRegistry registry = new GlobalRegistry(typeRegistry, global);
58
+		SemanticModule semantic = compileSyntaxToSemantic(typeRegistry, compilingPkg, parsedFiles, registry);
57 59
 		
58 60
 		//formatFiles(pkg, module);
59 61
 		
@@ -108,13 +110,12 @@ public class Main {
108 110
 		}
109 111
 	}
110 112
 	
111
-	private static SemanticModule compileSyntaxToSemantic(CompilationUnit compileUnit, CompilingPackage compiling, ParsedFile[] files, GlobalRegistry registry) {
112
-		ModuleSpace space = new ModuleSpace(compileUnit, new ArrayList<>(), StorageType.getStandard());
113
+	private static SemanticModule compileSyntaxToSemantic(GlobalTypeRegistry typeRegistry, CompilingPackage compiling, ParsedFile[] files, GlobalRegistry registry) {
114
+		ModuleSpace space = new ModuleSpace(typeRegistry, new ArrayList<>(), StorageType.getStandard());
113 115
 		for (Map.Entry<String, ISymbol> global : registry.collectGlobals().entrySet()) {
114 116
 			space.addGlobal(global.getKey(), global.getValue());
115 117
 		}
116 118
 		SemanticModule result = ParsedFile.compileSyntaxToSemantic(
117
-				"scripts",
118 119
 				new SemanticModule[0],
119 120
 				compiling,
120 121
 				files,
@@ -129,7 +130,7 @@ public class Main {
129 130
 	}
130 131
 	
131 132
 	private static JavaModule compileSemanticToJava(GlobalRegistry registry, SemanticModule module) {
132
-		JavaCompiler compiler = new JavaCompiler(module.compilationUnit.globalTypeRegistry, false, null);
133
+		JavaCompiler compiler = new JavaCompiler(module.registry, false, null);
133 134
 		registry.register(compiler.getContext());
134 135
 		
135 136
 		ZenCodeCompilingModule compiling = compiler.addModule(module);

+ 2
- 0
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java Bestand weergeven

@@ -5,6 +5,8 @@ public final class CodePosition {
5 5
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
6 6
     public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
7 7
     public static final CodePosition UNKNOWN = new CodePosition(new VirtualSourceFile("unknown"), 0, 0, 0, 0);
8
+    public static final CodePosition GENERATED = new CodePosition(new VirtualSourceFile("generated"), 0, 0, 0, 0);
9
+	
8 10
     public final SourceFile file;
9 11
     public final int fromLine;
10 12
     public final int fromLineOffset;

+ 3
- 0
Shared/src/main/java/org/openzen/zencode/shared/CompileException.java Bestand weergeven

@@ -7,11 +7,14 @@ public final class CompileException extends Exception {
7 7
     
8 8
     public final CodePosition position;
9 9
     public final CompileExceptionCode code;
10
+	public final String message;
10 11
     
11 12
     public CompileException(CodePosition position, CompileExceptionCode code, String message) {
12 13
         super(position.toString() + ": [" + code.toString() + "] " + message);
14
+		
13 15
         this.position = position;
14 16
         this.code = code;
17
+		this.message = message;
15 18
     }
16 19
     
17 20
     public CodePosition getPosition() {

+ 1
- 0
Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java Bestand weergeven

@@ -23,6 +23,7 @@ public final class LiteralSourceFile implements SourceFile {
23 23
         throw new AssertionError("Cannot update literal source files");
24 24
     }
25 25
     
26
+	@Override
26 27
     public String getFilename() {
27 28
         return filename;
28 29
     }

+ 5
- 0
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java Bestand weergeven

@@ -24,6 +24,11 @@ public class ValidationLogEntry {
24 24
 		this.message = message;
25 25
 	}
26 26
 	
27
+	@Override
28
+	public String toString() {
29
+		return kind + " " + position + ": " + message; 
30
+	}
31
+	
27 32
 	public static enum Kind {
28 33
 		ERROR,
29 34
 		WARNING

+ 7
- 7
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java Bestand weergeven

@@ -81,7 +81,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
81 81
 				Modifiers.PUBLIC | Modifiers.PROTECTED | Modifiers.PRIVATE,
82 82
 				member.position,
83 83
 				"Invalid modifier");
84
-		if (member.type != member.value.type) {
84
+		if (member.getType() != member.value.type) {
85 85
 			validator.logError(
86 86
 					ValidationLogEntry.Code.INVALID_TYPE,
87 87
 					member.position,
@@ -100,7 +100,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
100 100
 					"Duplicate field name: " + member.name);
101 101
 		}
102 102
 		fieldNames.add(member.name);
103
-		new TypeValidator(validator, member.position).validate(TypeContext.FIELD_TYPE, member.type);
103
+		new TypeValidator(validator, member.position).validate(TypeContext.FIELD_TYPE, member.getType());
104 104
 		
105 105
 		if (member.initializer != null) {
106 106
 			member.initializer.accept(new ExpressionValidator(validator, new FieldInitializerScope(member)));
@@ -159,15 +159,15 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
159 159
 	@Override
160 160
 	public Void visitGetter(GetterMember member) {
161 161
 		ValidationUtils.validateIdentifier(validator, member.position, member.name);
162
-		new TypeValidator(validator, member.position).validate(TypeContext.GETTER_TYPE, member.type);
163
-		validateGetter(member, new MethodStatementScope(new FunctionHeader(member.type), member.getAccessScope()));
162
+		new TypeValidator(validator, member.position).validate(TypeContext.GETTER_TYPE, member.getType());
163
+		validateGetter(member, new MethodStatementScope(new FunctionHeader(member.getType()), member.getAccessScope()));
164 164
 		return null;
165 165
 	}
166 166
 
167 167
 	@Override
168 168
 	public Void visitSetter(SetterMember member) {
169 169
 		ValidationUtils.validateIdentifier(validator, member.position, member.name);
170
-		new TypeValidator(validator, member.position).validate(TypeContext.SETTER_TYPE, member.type);
170
+		new TypeValidator(validator, member.position).validate(TypeContext.SETTER_TYPE, member.getType());
171 171
 		validateSetter(member, new MethodStatementScope(new FunctionHeader(BasicTypeID.VOID, member.parameter), member.getAccessScope()));
172 172
 		return null;
173 173
 	}
@@ -321,7 +321,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
321 321
 			StatementValidator statementValidator = new StatementValidator(validator, scope);
322 322
 			member.body.accept(statementValidator);
323 323
 			
324
-			validateThrow(member, new FunctionHeader(member.type), member.body);
324
+			validateThrow(member, new FunctionHeader(member.getType()), member.body);
325 325
 		}
326 326
 	}
327 327
 	
@@ -335,7 +335,7 @@ public class DefinitionMemberValidator implements MemberVisitor<Void> {
335 335
 		if (member.body != null) {
336 336
 			StatementValidator statementValidator = new StatementValidator(validator, scope);
337 337
 			member.body.accept(statementValidator);
338
-			validateThrow(member, new FunctionHeader(BasicTypeID.VOID, member.type), member.body);
338
+			validateThrow(member, new FunctionHeader(BasicTypeID.VOID, member.getType()), member.body);
339 339
 		}
340 340
 	}
341 341
 	

+ 6
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java Bestand weergeven

@@ -28,6 +28,7 @@ import org.openzen.zenscript.codemodel.member.EnumConstantMember;
28 28
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
29 29
 import org.openzen.zenscript.codemodel.scope.TypeScope;
30 30
 import org.openzen.zenscript.codemodel.GenericName;
31
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
31 32
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
32 33
 import org.openzen.zenscript.codemodel.type.StoredType;
33 34
 import org.openzen.zenscript.codemodel.type.TypeID;
@@ -222,6 +223,11 @@ public class DefinitionValidator implements DefinitionVisitor<Void> {
222 223
 			for (AnnotationDefinition annotation : annotations)
223 224
 				this.annotations.put(annotation.getAnnotationName(), annotation);
224 225
 		}
226
+
227
+		@Override
228
+		public ZSPackage getRootPackage() {
229
+			throw new UnsupportedOperationException();
230
+		}
225 231
 		
226 232
 		@Override
227 233
 		public LocalMemberCache getMemberCache() {

Laden…
Annuleren
Opslaan