Browse Source

- Added support for zipped packages

- Simplified compilation process somewhat; removed CompilationUnit class and work more module-oriented instead
Stan Hebben 6 years ago
parent
commit
e0118ed3c2
83 changed files with 871 additions and 179 deletions
  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 View File

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

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

142
 				isDestructible = true;
142
 				isDestructible = true;
143
 			if (member instanceof FieldMember) {
143
 			if (member instanceof FieldMember) {
144
 				FieldMember field = (FieldMember)member;
144
 				FieldMember field = (FieldMember)member;
145
-				if (field.type.isDestructible(scanning))
145
+				if (field.getType().isDestructible(scanning))
146
 					isDestructible = true;
146
 					isDestructible = true;
147
 			}
147
 			}
148
 			if ((member instanceof ImplementationMember) && ((ImplementationMember)member).type.isDestructible())
148
 			if ((member instanceof ImplementationMember) && ((ImplementationMember)member).type.isDestructible())

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

212
 			if (member.body == null)
212
 			if (member.body == null)
213
 				return null;
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
 			member.body = process(member.body, scope);
216
 			member.body = process(member.body, scope);
217
 			return null;
217
 			return null;
218
 		}
218
 		}

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

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

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

11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
 import org.openzen.zenscript.codemodel.GenericName;
13
 import org.openzen.zenscript.codemodel.GenericName;
14
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.codemodel.type.StoredType;
16
 import org.openzen.zenscript.codemodel.type.StoredType;
16
 import org.openzen.zenscript.codemodel.type.TypeID;
17
 import org.openzen.zenscript.codemodel.type.TypeID;
17
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
18
 import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
18
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
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
 		this.type = type;
32
 		this.type = type;
33
 		this.parameters = parameters;
33
 		this.parameters = parameters;
34
 	}
34
 	}
35
+	
36
+	@Override
37
+	public ZSPackage getRootPackage() {
38
+		return outer.getRootPackage();
39
+	}
35
 
40
 
36
 	@Override
41
 	@Override
37
 	public GlobalTypeRegistry getTypeRegistry() {
42
 	public GlobalTypeRegistry getTypeRegistry() {

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

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

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

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

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

37
 	public ZSPackage(ZSPackage parent, String name) {
37
 	public ZSPackage(ZSPackage parent, String name) {
38
 		this.parent = parent;
38
 		this.parent = parent;
39
 		this.name = name;
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
 	private final Map<String, ZSPackage> subPackages = new HashMap<>();
43
 	private final Map<String, ZSPackage> subPackages = new HashMap<>();

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java View File

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java View File

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

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

46
 	public void setBody(Statement body) {
46
 	public void setBody(Statement body) {
47
 		this.body = body;
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
 	@Override
56
 	@Override
100
 	public void setOverrides(GetterMemberRef override) {
103
 	public void setOverrides(GetterMemberRef override) {
101
 		this.overrides = override;
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
 	@Override
110
 	@Override
111
 	
114
 	
112
 	@Override
115
 	@Override
113
 	public FunctionHeader getHeader() {
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 View File

15
  * @author Hoofdgebruiker
15
  * @author Hoofdgebruiker
16
  */
16
  */
17
 public abstract class PropertyMember extends DefinitionMember {
17
 public abstract class PropertyMember extends DefinitionMember {
18
-	public StoredType type;
18
+	private StoredType type;
19
 	public final BuiltinID builtin;
19
 	public final BuiltinID builtin;
20
 	
20
 	
21
 	public PropertyMember(CodePosition position, HighLevelDefinition definition, int modifiers, StoredType type, BuiltinID builtin) {
21
 	public PropertyMember(CodePosition position, HighLevelDefinition definition, int modifiers, StoredType type, BuiltinID builtin) {
22
 		super(position, definition, modifiers);
22
 		super(position, definition, modifiers);
23
 		
23
 		
24
+		if (type == null)
25
+			throw new NullPointerException();
26
+		
24
 		this.type = type;
27
 		this.type = type;
25
 		this.builtin = builtin;
28
 		this.builtin = builtin;
26
 	}
29
 	}
29
 		return type;
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
 	@Override
42
 	@Override
33
 	public BuiltinID getBuiltin() {
43
 	public BuiltinID getBuiltin() {
34
 		return builtin;
44
 		return builtin;

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

105
 	public void setOverrides(SetterMemberRef overrides) {
105
 	public void setOverrides(SetterMemberRef overrides) {
106
 		this.overrides = overrides;
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
 			parameter = new FunctionParameter(overrides.getType(), "value");
110
 			parameter = new FunctionParameter(overrides.getType(), "value");
111
 		}
111
 		}
112
 	}
112
 	}
118
 	
118
 	
119
 	@Override
119
 	@Override
120
 	public FunctionHeader getHeader() {
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 View File

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

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

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

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

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

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

25
 import org.openzen.zenscript.codemodel.statement.VarStatement;
25
 import org.openzen.zenscript.codemodel.statement.VarStatement;
26
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
26
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
27
 import org.openzen.zenscript.codemodel.GenericName;
27
 import org.openzen.zenscript.codemodel.GenericName;
28
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
28
 import org.openzen.zenscript.codemodel.type.StoredType;
29
 import org.openzen.zenscript.codemodel.type.StoredType;
29
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
30
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
30
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
31
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
116
 		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
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
 	@Override
125
 	@Override
120
 	public LocalMemberCache getMemberCache() {
126
 	public LocalMemberCache getMemberCache() {
121
 		return outer.getMemberCache();
127
 		return outer.getMemberCache();

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

21
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
21
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
22
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
22
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
23
 import org.openzen.zenscript.codemodel.GenericName;
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
 import org.openzen.zenscript.codemodel.type.ISymbol;
27
 import org.openzen.zenscript.codemodel.type.ISymbol;
25
 import org.openzen.zenscript.codemodel.type.StoredType;
28
 import org.openzen.zenscript.codemodel.type.StoredType;
26
 import org.openzen.zenscript.codemodel.type.TypeID;
29
 import org.openzen.zenscript.codemodel.type.TypeID;
35
  */
38
  */
36
 public class FileScope extends BaseScope {
39
 public class FileScope extends BaseScope {
37
 	private final TypeResolutionContext context;
40
 	private final TypeResolutionContext context;
41
+	private final ZSPackage root;
38
 	private final LocalMemberCache memberCache;
42
 	private final LocalMemberCache memberCache;
39
 	private final Map<String, ISymbol> globals;
43
 	private final Map<String, ISymbol> globals;
40
 	private final TypeMemberPreparer preparer;
44
 	private final TypeMemberPreparer preparer;
47
 		this.context = context;
51
 		this.context = context;
48
 		this.globals = globals;
52
 		this.globals = globals;
49
 		this.preparer = preparer;
53
 		this.preparer = preparer;
54
+		this.root = context.getRootPackage();
50
 		
55
 		
51
 		memberCache = new LocalMemberCache(context.getTypeRegistry(), expansions);
56
 		memberCache = new LocalMemberCache(context.getTypeRegistry(), expansions);
52
 	}
57
 	}
53
 	
58
 	
59
+	@Override
60
+	public ZSPackage getRootPackage() {
61
+		return root;
62
+	}
63
+	
54
 	@Override
64
 	@Override
55
 	public LocalMemberCache getMemberCache() {
65
 	public LocalMemberCache getMemberCache() {
56
 		return memberCache;
66
 		return memberCache;
65
 		if (globals.containsKey(name.name)) {
75
 		if (globals.containsKey(name.name)) {
66
 			IPartialExpression resolution = globals.get(name.name).getExpression(position, this, name.arguments);
76
 			IPartialExpression resolution = globals.get(name.name).getExpression(position, this, name.arguments);
67
 			return new PartialGlobalExpression(position, name.name, resolution, name.arguments);
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
 		return null;
86
 		return null;

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

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

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

18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
19
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
19
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
20
 import org.openzen.zenscript.codemodel.GenericName;
20
 import org.openzen.zenscript.codemodel.GenericName;
21
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
21
 import org.openzen.zenscript.codemodel.type.StoredType;
22
 import org.openzen.zenscript.codemodel.type.StoredType;
22
 import org.openzen.zenscript.codemodel.type.TypeID;
23
 import org.openzen.zenscript.codemodel.type.TypeID;
23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
24
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
53
 		typeParameterMap = outer.getLocalTypeParameters().getInner(outer.getTypeRegistry(), header.typeParameters);
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
 	@Override
62
 	@Override
57
 	public LocalMemberCache getMemberCache() {
63
 	public LocalMemberCache getMemberCache() {
58
 		return outer.getMemberCache();
64
 		return outer.getMemberCache();

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

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

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

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

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

17
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
17
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
18
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
18
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
19
 import org.openzen.zenscript.codemodel.GenericName;
19
 import org.openzen.zenscript.codemodel.GenericName;
20
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
20
 import org.openzen.zenscript.codemodel.type.StoredType;
21
 import org.openzen.zenscript.codemodel.type.StoredType;
21
 import org.openzen.zenscript.codemodel.type.TypeID;
22
 import org.openzen.zenscript.codemodel.type.TypeID;
22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
23
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
41
 		
42
 		
42
 		members = outer.getTypeMembers(implementation.type.stored(BorrowStorageTag.THIS));
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
 	@Override
51
 	@Override
46
 	public LocalMemberCache getMemberCache() {
52
 	public LocalMemberCache getMemberCache() {

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

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

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

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/InvalidStatement.java View File

32
 		super(ex.position, null);
32
 		super(ex.position, null);
33
 		
33
 		
34
 		this.code = ex.code;
34
 		this.code = ex.code;
35
-		this.message = ex.getMessage();
35
+		this.message = ex.message;
36
 	}
36
 	}
37
 
37
 
38
 	@Override
38
 	@Override

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

481
 					FunctionParameter[] parameters = new FunctionParameter[fields.size()];
481
 					FunctionParameter[] parameters = new FunctionParameter[fields.size()];
482
 					for (int i = 0; i < parameters.length; i++) {
482
 					for (int i = 0; i < parameters.length; i++) {
483
 						FieldMember field = fields.get(i);
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
 					constructors.addMethod(new ConstructorMember(
487
 					constructors.addMethod(new ConstructorMember(

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

467
 		if (toType.equals(value.type))
467
 		if (toType.equals(value.type))
468
 			return value;
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
 		return new StorageCastExpression(position, value, toType);
473
 		return new StorageCastExpression(position, value, toType);
474
 	}
474
 	}

+ 0
- 22
CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompilationUnit.java View File

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

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

+ 5
- 4
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java View File

17
 import org.openzen.zenscript.codemodel.annotations.PreconditionAnnotationDefinition;
17
 import org.openzen.zenscript.codemodel.annotations.PreconditionAnnotationDefinition;
18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
20
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
20
 import org.openzen.zenscript.codemodel.type.ISymbol;
21
 import org.openzen.zenscript.codemodel.type.ISymbol;
21
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
22
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
22
 
23
 
25
  * @author Hoofdgebruiker
26
  * @author Hoofdgebruiker
26
  */
27
  */
27
 public final class ModuleSpace {
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
 	public final ZSPackage globalsPackage = new ZSPackage(null, "");
31
 	public final ZSPackage globalsPackage = new ZSPackage(null, "");
31
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
32
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
32
 	private final Map<String, ISymbol> globals = new HashMap<>();
33
 	private final Map<String, ISymbol> globals = new HashMap<>();
33
 	private final AnnotationDefinition[] annotations;
34
 	private final AnnotationDefinition[] annotations;
34
 	private final StorageType[] storageTypes;
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
 		annotations.add(NativeAnnotationDefinition.INSTANCE);
40
 		annotations.add(NativeAnnotationDefinition.INSTANCE);
40
 		annotations.add(PreconditionAnnotationDefinition.INSTANCE);
41
 		annotations.add(PreconditionAnnotationDefinition.INSTANCE);

+ 11
- 10
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java View File

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

+ 6
- 3
Constructor/src/main/java/org/openzen/zenscript/constructor/Main.java View File

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

+ 5
- 5
Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java View File

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

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

19
 import org.openzen.zenscript.codemodel.Module;
19
 import org.openzen.zenscript.codemodel.Module;
20
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
20
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
21
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
21
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
22
-import org.openzen.zenscript.compiler.CompilationUnit;
22
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
23
 import org.openzen.zenscript.constructor.ConstructorException;
23
 import org.openzen.zenscript.constructor.ConstructorException;
24
 import org.openzen.zenscript.constructor.JSONUtils;
24
 import org.openzen.zenscript.constructor.JSONUtils;
25
 import org.openzen.zenscript.constructor.ParsedModule;
25
 import org.openzen.zenscript.constructor.ParsedModule;
51
 	}
51
 	}
52
 
52
 
53
 	@Override
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
 		if (!directory.exists())
55
 		if (!directory.exists())
56
 			throw new ConstructorException("Error: module directory not found: " + directory);
56
 			throw new ConstructorException("Error: module directory not found: " + directory);
57
 		
57
 		
74
 			}
74
 			}
75
 
75
 
76
 			// TODO: annotation type registration
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
 			SemanticModule[] dependencies = new SemanticModule[dependencyNames.size()];
78
 			SemanticModule[] dependencies = new SemanticModule[dependencyNames.size()];
79
 			for (int i = 0; i < dependencies.length; i++) {
79
 			for (int i = 0; i < dependencies.length; i++) {
80
 				String dependencyName = dependencyNames.get(i);
80
 				String dependencyName = dependencyNames.get(i);
89
 			}
89
 			}
90
 
90
 
91
 			ParsedModule parsedModule = new ParsedModule(moduleName, directory, jsonFile, exceptionLogger);
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
 			Module module = new Module(moduleName);
93
 			Module module = new Module(moduleName);
94
 			CompilingPackage compilingPackage = new CompilingPackage(pkg, module);
94
 			CompilingPackage compilingPackage = new CompilingPackage(pkg, module);
95
 			
95
 			
96
 			ParsedFile[] parsedFiles = parsedModule.parse(compilingPackage);
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
 			JSONObject globals = json.optJSONObject("globals");
99
 			JSONObject globals = json.optJSONObject("globals");
100
 			if (globals != null) {
100
 			if (globals != null) {

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

7
 
7
 
8
 import java.util.function.Consumer;
8
 import java.util.function.Consumer;
9
 import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10
 import org.openzen.zenscript.compiler.SemanticModule;
11
 import org.openzen.zenscript.compiler.SemanticModule;
11
-import org.openzen.zenscript.compiler.CompilationUnit;
12
 import org.openzen.zenscript.constructor.ModuleLoader;
12
 import org.openzen.zenscript.constructor.ModuleLoader;
13
 
13
 
14
 /**
14
 /**
18
 public interface ModuleReference {
18
 public interface ModuleReference {
19
 	public String getName();
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
 	public SourcePackage getRootPackage();
23
 	public SourcePackage getRootPackage();
24
 }
24
 }

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

5
  */
5
  */
6
 package org.openzen.zenscript.ide.codemodel;
6
 package org.openzen.zenscript.ide.codemodel;
7
 
7
 
8
-import java.io.File;
9
 import java.util.ArrayList;
8
 import java.util.ArrayList;
10
 import java.util.Collections;
9
 import java.util.Collections;
11
 import java.util.HashMap;
10
 import java.util.HashMap;
12
-import java.util.HashSet;
13
 import java.util.List;
11
 import java.util.List;
14
 import java.util.Map;
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
 import org.openzen.zenscript.constructor.ModuleLoader;
15
 import org.openzen.zenscript.constructor.ModuleLoader;
22
-import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
23
-import org.openzen.zenscript.constructor.module.ModuleReference;
24
 import org.openzen.zenscript.ide.host.DevelopmentHost;
16
 import org.openzen.zenscript.ide.host.DevelopmentHost;
25
 import org.openzen.zenscript.ide.host.IDEModule;
17
 import org.openzen.zenscript.ide.host.IDEModule;
26
 import org.openzen.zenscript.ide.host.IDESourceFile;
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
 	public IDECodeSpace(DevelopmentHost host) {
28
 	public IDECodeSpace(DevelopmentHost host) {
41
 		this.host = host;
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
 		for (IDEModule module : host.getModules()) {
37
 		for (IDEModule module : host.getModules()) {

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

10
 import java.util.Set;
10
 import java.util.Set;
11
 import java.util.Stack;
11
 import java.util.Stack;
12
 import java.util.function.Consumer;
12
 import java.util.function.Consumer;
13
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
 import org.openzen.zenscript.compiler.Target;
15
 import org.openzen.zenscript.compiler.Target;
14
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
16
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
15
 import org.openzen.zenscript.constructor.Library;
17
 import org.openzen.zenscript.constructor.Library;
18
 import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
20
 import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
19
 import org.openzen.zenscript.constructor.module.ModuleReference;
21
 import org.openzen.zenscript.constructor.module.ModuleReference;
20
 import org.openzen.zenscript.compiler.SemanticModule;
22
 import org.openzen.zenscript.compiler.SemanticModule;
21
-import org.openzen.zenscript.compiler.CompilationUnit;
22
 import org.openzen.zenscript.ide.host.IDETarget;
23
 import org.openzen.zenscript.ide.host.IDETarget;
23
 import org.openzen.zenscript.ide.ui.view.output.ErrorOutputSpan;
24
 import org.openzen.zenscript.ide.ui.view.output.ErrorOutputSpan;
24
 import org.openzen.zenscript.ide.ui.view.output.OutputLine;
25
 import org.openzen.zenscript.ide.ui.view.output.OutputLine;
66
 	}
67
 	}
67
 	
68
 	
68
 	private ZenCodeCompiler buildInternal(Consumer<OutputLine> output) {
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
 			String[] lines = Strings.split(exception.getMessage(), '\n');
75
 			String[] lines = Strings.split(exception.getMessage(), '\n');
72
 			for (String line : lines) {
76
 			for (String line : lines) {
73
 				output.accept(new OutputLine(new ErrorOutputSpan(line)));
77
 				output.accept(new OutputLine(new ErrorOutputSpan(line)));

+ 24
- 0
JavaAnnotations/build.gradle View File

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 View File

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

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

28
 
28
 
29
 	@Override
29
 	@Override
30
 	public JavaCompiler createCompiler(SemanticModule module) {
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
 	@Override
34
 	@Override

+ 43
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeModule.java View File

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

25
 
25
 
26
 	@Override
26
 	@Override
27
 	public JavaCompiler createCompiler(SemanticModule module) {
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
 	@Override
31
 	@Override

+ 87
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunUnit.java View File

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

27
 import org.openzen.zenscript.javabytecode.compiler.definitions.JavaDefinitionVisitor;
27
 import org.openzen.zenscript.javabytecode.compiler.definitions.JavaDefinitionVisitor;
28
 import org.openzen.zenscript.javashared.JavaBaseCompiler;
28
 import org.openzen.zenscript.javashared.JavaBaseCompiler;
29
 import org.openzen.zenscript.javashared.JavaClass;
29
 import org.openzen.zenscript.javashared.JavaClass;
30
+import org.openzen.zenscript.javashared.JavaCompileSpace;
31
+import org.openzen.zenscript.javashared.JavaCompiledModule;
30
 import org.openzen.zenscript.javashared.JavaContext;
32
 import org.openzen.zenscript.javashared.JavaContext;
31
 import org.openzen.zenscript.javashared.JavaMethod;
33
 import org.openzen.zenscript.javashared.JavaMethod;
32
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionMemberVisitor;
34
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionMemberVisitor;
64
 		return context;
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
 	@Override
118
 	@Override
68
 	public ZenCodeCompilingModule addModule(SemanticModule module) {
119
 	public ZenCodeCompilingModule addModule(SemanticModule module) {
69
 		context.addModule(module.module);
120
 		context.addModule(module.module);

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

68
                     constructorWriter.loadObject(0);
68
                     constructorWriter.loadObject(0);
69
                 field.initializer.accept(expressionVisitor);
69
                 field.initializer.accept(expressionVisitor);
70
                 if (staticFields)
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
                 else
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 View File

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

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

1
 package org.openzen.zenscript.javashared;
1
 package org.openzen.zenscript.javashared;
2
 
2
 
3
+import org.openzen.zenscript.compiler.SemanticModule;
3
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
4
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
4
 
5
 
5
 /*
6
 /*
13
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
14
  */
15
  */
15
 public abstract class JavaBaseCompiler implements ZenCodeCompiler {
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 View File

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

5
  */
5
  */
6
 package org.openzen.zenscript.javashared;
6
 package org.openzen.zenscript.javashared;
7
 
7
 
8
+import java.util.ArrayList;
8
 import java.util.HashMap;
9
 import java.util.HashMap;
10
+import java.util.List;
9
 import java.util.Map;
11
 import java.util.Map;
12
+import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zenscript.codemodel.FunctionParameter;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.Module;
15
 import org.openzen.zenscript.codemodel.Module;
14
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
17
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
15
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
18
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
16
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
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
 		this.module = module;
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
 	public void setClassInfo(HighLevelDefinition definition, JavaClass cls) {
50
 	public void setClassInfo(HighLevelDefinition definition, JavaClass cls) {
39
 		classes.put(definition, cls);
51
 		classes.put(definition, cls);
40
 	}
52
 	}

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

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

+ 27
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/SimpleJavaCompileSpace.java View File

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

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

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

130
 			cls.addInstanceMethod("lastIndexOf", "lastIndexOf", "(I)I");
130
 			cls.addInstanceMethod("lastIndexOf", "lastIndexOf", "(I)I");
131
 			cls.addInstanceMethod("lastIndexOfFrom", "lastIndexOf", "(II)I");
131
 			cls.addInstanceMethod("lastIndexOfFrom", "lastIndexOf", "(II)I");
132
 			cls.addInstanceMethod("trim", "trim", "()Ljava/lang/String;");
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
 			cls.addMethod("fromAsciiBytes", new JavaMethod((expression, translator) -> {
135
 			cls.addMethod("fromAsciiBytes", new JavaMethod((expression, translator) -> {
134
 				CallStaticExpression call = (CallStaticExpression)expression;
136
 				CallStaticExpression call = (CallStaticExpression)expression;
135
 				return translator.bytesAsciiToString(call.arguments.arguments[0]);
137
 				return translator.bytesAsciiToString(call.arguments.arguments[0]);

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

60
 	
60
 	
61
 	@Override
61
 	@Override
62
 	public Void visitConst(ConstMember member) {
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
 		module.setFieldInfo(member, field);
64
 		module.setFieldInfo(member, field);
65
 		
65
 		
66
 		if (DEBUG_EMPTY && cls.empty)
66
 		if (DEBUG_EMPTY && cls.empty)
73
 	@Override
73
 	@Override
74
 	public Void visitField(FieldMember member) {
74
 	public Void visitField(FieldMember member) {
75
 		// TODO: expansion fields
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
 		module.setFieldInfo(member, field);
77
 		module.setFieldInfo(member, field);
78
 		
78
 		
79
 		if (member.hasAutoGetter() || member.hasAutoSetter())
79
 		if (member.hasAutoGetter() || member.hasAutoSetter())
104
 
104
 
105
 	@Override
105
 	@Override
106
 	public Void visitGetter(GetterMember member) {
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
 		return null;
108
 		return null;
109
 	}
109
 	}
110
 
110
 
111
 	@Override
111
 	@Override
112
 	public Void visitSetter(SetterMember member) {
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
 		return null;
114
 		return null;
115
 	}
115
 	}
116
 
116
 

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

12
 import org.openzen.zenscript.codemodel.type.StoredType;
12
 import org.openzen.zenscript.codemodel.type.StoredType;
13
 import org.openzen.zenscript.formattershared.ExpressionString;
13
 import org.openzen.zenscript.formattershared.ExpressionString;
14
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
14
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
15
+import org.openzen.zenscript.javashared.JavaTypeUtils;
15
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
16
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
16
 
17
 
17
 /**
18
 /**

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

78
 	}
78
 	}
79
 	
79
 	
80
 	private JavaSourceFileScope createScope(HighLevelDefinition definition) {
80
 	private JavaSourceFileScope createScope(HighLevelDefinition definition) {
81
-		GlobalTypeRegistry typeRegistry = semanticModule.compilationUnit.globalTypeRegistry;
81
+		GlobalTypeRegistry typeRegistry = semanticModule.registry;
82
 		DefinitionTypeID thisType = typeRegistry.getForMyDefinition(definition);
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
 		return new JavaSourceFileScope(file.importer, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition, thisType, compiler.context);
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 View File

81
 	public Void visitConst(ConstMember member) {
81
 	public Void visitConst(ConstMember member) {
82
 		begin(ElementType.FIELD);
82
 		begin(ElementType.FIELD);
83
 		modifiers(member.getEffectiveModifiers() | Modifiers.STATIC | Modifiers.FINAL);
83
 		modifiers(member.getEffectiveModifiers() | Modifiers.STATIC | Modifiers.FINAL);
84
-		output.append(scope.type(member.type));
84
+		output.append(scope.type(member.getType()));
85
 		output.append(" ");
85
 		output.append(" ");
86
 		output.append(member.name);
86
 		output.append(member.name);
87
 		output.append(" = ");
87
 		output.append(" = ");
107
 		
107
 		
108
 		this.modifiers(modifiers);
108
 		this.modifiers(modifiers);
109
 		
109
 		
110
-		output.append(scope.type(member.type));
110
+		output.append(scope.type(member.getType()));
111
 		output.append(" ");
111
 		output.append(" ");
112
 		output.append(member.name);
112
 		output.append(member.name);
113
 		if (member.initializer != null) {
113
 		if (member.initializer != null) {
139
 
139
 
140
 	@Override
140
 	@Override
141
 	public Void visitGetter(GetterMember member) {
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
 		return null;
143
 		return null;
144
 	}
144
 	}
145
 
145
 
146
 	@Override
146
 	@Override
147
 	public Void visitSetter(SetterMember member) {
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
 		return null;
149
 		return null;
150
 	}
150
 	}
151
 
151
 

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

114
 		
114
 		
115
 		output.append(indent);
115
 		output.append(indent);
116
 		modifiers(member.getEffectiveModifiers() | Modifiers.STATIC | Modifiers.FINAL);
116
 		modifiers(member.getEffectiveModifiers() | Modifiers.STATIC | Modifiers.FINAL);
117
-		output.append(scope.type(member.type));
117
+		output.append(scope.type(member.getType()));
118
 		output.append(" ");
118
 		output.append(" ");
119
 		output.append(member.name);
119
 		output.append(member.name);
120
 		output.append(" = ");
120
 		output.append(" = ");
140
 		
140
 		
141
 		this.modifiers(modifiers);
141
 		this.modifiers(modifiers);
142
 		
142
 		
143
-		output.append(scope.type(member.type));
143
+		output.append(scope.type(member.getType()));
144
 		output.append(" ");
144
 		output.append(" ");
145
 		output.append(member.name);
145
 		output.append(member.name);
146
 		if (member.initializer != null) {
146
 		if (member.initializer != null) {
190
 
190
 
191
 	@Override
191
 	@Override
192
 	public Void visitGetter(GetterMember member) {
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
 		return null;
194
 		return null;
195
 	}
195
 	}
196
 
196
 
197
 	@Override
197
 	@Override
198
 	public Void visitSetter(SetterMember member) {
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
 		return null;
200
 		return null;
201
 	}
201
 	}
202
 
202
 

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

14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
 import org.openzen.zenscript.codemodel.ScriptBlock;
15
 import org.openzen.zenscript.codemodel.ScriptBlock;
16
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
16
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
17
-import org.openzen.zenscript.compiler.CompilationUnit;
17
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
18
 import org.openzen.zenscript.compiler.SemanticModule;
18
 import org.openzen.zenscript.compiler.SemanticModule;
19
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
19
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
20
 import org.openzen.zenscript.compiler.ZenCodeCompilingModule;
20
 import org.openzen.zenscript.compiler.ZenCodeCompilingModule;
34
 	public final JavaSourceContext context;
34
 	public final JavaSourceContext context;
35
 	private final List<SourceModule> modules = new ArrayList<>();
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
 		if (!directory.exists())
38
 		if (!directory.exists())
39
 			directory.mkdirs();
39
 			directory.mkdirs();
40
 		
40
 		
41
 		settings = new JavaSourceFormattingSettings.Builder().build();
41
 		settings = new JavaSourceFormattingSettings.Builder().build();
42
-		context = new JavaSourceContext(compilationUnit.globalTypeRegistry, directory, settings);
42
+		context = new JavaSourceContext(registry, directory, settings);
43
 		helperGenerator = new JavaSourceSyntheticHelperGenerator(context, directory, settings);
43
 		helperGenerator = new JavaSourceSyntheticHelperGenerator(context, directory, settings);
44
 		
44
 		
45
 		this.directory = directory;
45
 		this.directory = directory;

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

127
 		this.scope = scope;
127
 		this.scope = scope;
128
 		context = scope.context;
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
 	@Override
138
 	@Override
132
 	public ExpressionString visitAndAnd(AndAndExpression expression) {
139
 	public ExpressionString visitAndAnd(AndAndExpression expression) {
157
 			return visitBuiltinCompare(expression, expression.operator.getBuiltin());
164
 			return visitBuiltinCompare(expression, expression.operator.getBuiltin());
158
 		
165
 		
159
 		StringBuilder output = new StringBuilder();
166
 		StringBuilder output = new StringBuilder();
160
-		output.append(expression.left.accept(this).value);
167
+		output.append(getValue(expression.left).value);
161
 		output.append(".compareTo(");
168
 		output.append(".compareTo(");
162
 		output.append(expression.right.accept(this));
169
 		output.append(expression.right.accept(this));
163
 		output.append(") ");
170
 		output.append(") ");
188
 				output.append(scope.type(method.cls));
195
 				output.append(scope.type(method.cls));
189
 				output.append('.');
196
 				output.append('.');
190
 				output.append(method.name);
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
 				return new ExpressionString(output.toString(), JavaOperator.CALL);
199
 				return new ExpressionString(output.toString(), JavaOperator.CALL);
193
 			}
200
 			}
194
 			case INSTANCE: {
201
 			case INSTANCE: {
195
 				StringBuilder output = new StringBuilder();
202
 				StringBuilder output = new StringBuilder();
196
-				output.append(target.accept(this).value);
203
+				output.append(getValue(target).value);
197
 				output.append('.');
204
 				output.append('.');
198
 				output.append(method.name);
205
 				output.append(method.name);
199
 				FormattingUtils.formatCall(output, this.target, scope, arguments);
206
 				FormattingUtils.formatCall(output, this.target, scope, arguments);
428
 	public ExpressionString visitGetField(GetFieldExpression expression) {
435
 	public ExpressionString visitGetField(GetFieldExpression expression) {
429
 		StringBuilder result = new StringBuilder();
436
 		StringBuilder result = new StringBuilder();
430
 		if (!(expression.target instanceof ThisExpression && !scope.hasLocalVariable(expression.field.member.name))) {
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
 			result.append('.');
439
 			result.append('.');
433
 		}
440
 		}
434
 		result.append(expression.field.member.name);
441
 		result.append(expression.field.member.name);
464
 		if (expression.getter.member.builtin != null)
471
 		if (expression.getter.member.builtin != null)
465
 			return visitBuiltinGetter(expression, expression.getter.member.builtin);
472
 			return visitBuiltinGetter(expression, expression.getter.member.builtin);
466
 		
473
 		
467
-		ExpressionString target = expression.target.accept(this);
474
+		ExpressionString target = getValue(expression.target);
468
 		if (context.hasJavaField(expression.getter)) {
475
 		if (context.hasJavaField(expression.getter)) {
469
 			JavaField field = context.getJavaField(expression.getter);
476
 			JavaField field = context.getJavaField(expression.getter);
470
 			if (target.value.equals("this") && !scope.hasLocalVariable(field.name))
477
 			if (target.value.equals("this") && !scope.hasLocalVariable(field.name))
656
 	@Override
663
 	@Override
657
 	public ExpressionString visitSetter(SetterExpression expression) {
664
 	public ExpressionString visitSetter(SetterExpression expression) {
658
 		return new ExpressionString(
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
 				JavaOperator.ASSIGN);
667
 				JavaOperator.ASSIGN);
661
 	}
668
 	}
662
 
669
 

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

106
 		contents.append(settings.indent).append(settings.indent).append("this.value = value;\n");
106
 		contents.append(settings.indent).append(settings.indent).append("this.value = value;\n");
107
 		contents.append(settings.indent).append("}\n");
107
 		contents.append(settings.indent).append("}\n");
108
 		contents.append(settings.indent).append("\n");
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
 		contents.append(settings.indent).append("public synchronized void addRef() {\n");
113
 		contents.append(settings.indent).append("public synchronized void addRef() {\n");
110
 		contents.append(settings.indent).append(settings.indent).append("refcount++;\n");
114
 		contents.append(settings.indent).append(settings.indent).append("refcount++;\n");
111
 		contents.append(settings.indent).append("}\n");
115
 		contents.append(settings.indent).append("}\n");

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

28
 
28
 
29
 	@Override
29
 	@Override
30
 	public ZenCodeCompiler createCompiler(SemanticModule module) {
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
 	@Override
34
 	@Override

+ 9
- 10
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java View File

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

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

48
 			return;
48
 			return;
49
 		typesCompiled = true;
49
 		typesCompiled = true;
50
 		
50
 		
51
-		System.out.println("compileTypes " + getCompiled().name);
51
+		//System.out.println("compileTypes " + getCompiled().name);
52
 		linkTypesLocal(context);
52
 		linkTypesLocal(context);
53
 	}
53
 	}
54
 	
54
 	

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java View File

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

+ 5
- 5
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedConst.java View File

77
 		
77
 		
78
 		if (expression != null) {
78
 		if (expression != null) {
79
 			Expression initializer = expression
79
 			Expression initializer = expression
80
-					.compile(new ExpressionScope(scope, compiled.type))
80
+					.compile(new ExpressionScope(scope, compiled.getType()))
81
 					.eval()
81
 					.eval()
82
-					.castImplicit(position, scope, compiled.type);
82
+					.castImplicit(position, scope, compiled.getType());
83
 			compiled.value = initializer;
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
 			throw new CompileException(position, CompileExceptionCode.PRECOMPILE_FAILED, "No type or initializer given");
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 View File

92
 		
92
 		
93
 		if (expression != null) {
93
 		if (expression != null) {
94
 			Expression initializer = expression
94
 			Expression initializer = expression
95
-					.compile(new ExpressionScope(scope, compiled.type))
95
+					.compile(new ExpressionScope(scope, compiled.getType()))
96
 					.eval()
96
 					.eval()
97
-					.castImplicit(position, scope, compiled.type);
97
+					.castImplicit(position, scope, compiled.getType());
98
 			compiled.setInitializer(initializer);
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
 			throw new CompileException(position, CompileExceptionCode.PRECOMPILE_FAILED, "Could not infer type since no initializer is given");
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 View File

13
 import org.openzen.zenscript.codemodel.Modifiers;
13
 import org.openzen.zenscript.codemodel.Modifiers;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
 import org.openzen.zenscript.codemodel.member.GetterMember;
15
 import org.openzen.zenscript.codemodel.member.GetterMember;
16
+import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
16
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
18
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
18
 import org.openzen.zenscript.codemodel.scope.TypeScope;
19
 import org.openzen.zenscript.codemodel.scope.TypeScope;
84
 	}
85
 	}
85
 
86
 
86
 	private void fillOverride(TypeScope scope, StoredType baseType) {
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
 	@Override
93
 	@Override
95
 		
98
 		
96
 		inferHeaders(scope);
99
 		inferHeaders(scope);
97
 		
100
 		
98
-		FunctionHeader header = new FunctionHeader(compiled.type);
101
+		FunctionHeader header = new FunctionHeader(compiled.getType());
99
 		FunctionScope innerScope = new FunctionScope(scope, header);
102
 		FunctionScope innerScope = new FunctionScope(scope, header);
100
 		compiled.annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
103
 		compiled.annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
101
 		compiled.setBody(body.compile(innerScope, header));
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 View File

43
 			return;
43
 			return;
44
 		typesCompiled = true;
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
 		innerDefinition.linkTypes(context);
47
 		innerDefinition.linkTypes(context);
48
 	}
48
 	}
49
 
49
 

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedSetter.java View File

95
 		
95
 		
96
 		inferHeaders(scope);
96
 		inferHeaders(scope);
97
 		
97
 		
98
-		FunctionHeader header = new FunctionHeader(compiled.type);
98
+		FunctionHeader header = new FunctionHeader(compiled.getType());
99
 		FunctionScope innerScope = new FunctionScope(
99
 		FunctionScope innerScope = new FunctionScope(
100
 				scope,
100
 				scope,
101
 				header,
101
 				header,

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

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

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

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

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

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

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

1
 package org.openzen.zenscript.scriptingexample;
1
 package org.openzen.zenscript.scriptingexample;
2
 
2
 
3
 import java.io.File;
3
 import java.io.File;
4
-import java.io.IOException;
5
 import java.util.ArrayList;
4
 import java.util.ArrayList;
6
 import java.util.Collections;
5
 import java.util.Collections;
7
 import java.util.HashMap;
6
 import java.util.HashMap;
16
 import org.openzen.zenscript.codemodel.ScriptBlock;
15
 import org.openzen.zenscript.codemodel.ScriptBlock;
17
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
16
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
18
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
 import org.openzen.zenscript.codemodel.type.ISymbol;
19
 import org.openzen.zenscript.codemodel.type.ISymbol;
20
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
20
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
21
-import org.openzen.zenscript.compiler.CompilationUnit;
22
 import org.openzen.zenscript.compiler.SemanticModule;
21
 import org.openzen.zenscript.compiler.SemanticModule;
23
 import org.openzen.zenscript.formatter.FileFormatter;
22
 import org.openzen.zenscript.formatter.FileFormatter;
24
 import org.openzen.zenscript.formatter.ScriptFormattingSettings;
23
 import org.openzen.zenscript.formatter.ScriptFormattingSettings;
50
 		CompilingPackage compilingPkg = new CompilingPackage(pkg, module);
49
 		CompilingPackage compilingPkg = new CompilingPackage(pkg, module);
51
 		ParsedFile[] parsedFiles = parse(compilingPkg, inputFiles);
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
 		ZSPackage global = new ZSPackage(null, "");
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
 		//formatFiles(pkg, module);
60
 		//formatFiles(pkg, module);
59
 		
61
 		
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
 		for (Map.Entry<String, ISymbol> global : registry.collectGlobals().entrySet()) {
115
 		for (Map.Entry<String, ISymbol> global : registry.collectGlobals().entrySet()) {
114
 			space.addGlobal(global.getKey(), global.getValue());
116
 			space.addGlobal(global.getKey(), global.getValue());
115
 		}
117
 		}
116
 		SemanticModule result = ParsedFile.compileSyntaxToSemantic(
118
 		SemanticModule result = ParsedFile.compileSyntaxToSemantic(
117
-				"scripts",
118
 				new SemanticModule[0],
119
 				new SemanticModule[0],
119
 				compiling,
120
 				compiling,
120
 				files,
121
 				files,
129
 	}
130
 	}
130
 	
131
 	
131
 	private static JavaModule compileSemanticToJava(GlobalRegistry registry, SemanticModule module) {
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
 		registry.register(compiler.getContext());
134
 		registry.register(compiler.getContext());
134
 		
135
 		
135
 		ZenCodeCompilingModule compiling = compiler.addModule(module);
136
 		ZenCodeCompilingModule compiling = compiler.addModule(module);

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

5
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
5
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
6
     public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
6
     public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
7
     public static final CodePosition UNKNOWN = new CodePosition(new VirtualSourceFile("unknown"), 0, 0, 0, 0);
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
     public final SourceFile file;
10
     public final SourceFile file;
9
     public final int fromLine;
11
     public final int fromLine;
10
     public final int fromLineOffset;
12
     public final int fromLineOffset;

+ 3
- 0
Shared/src/main/java/org/openzen/zencode/shared/CompileException.java View File

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

+ 1
- 0
Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java View File

23
         throw new AssertionError("Cannot update literal source files");
23
         throw new AssertionError("Cannot update literal source files");
24
     }
24
     }
25
     
25
     
26
+	@Override
26
     public String getFilename() {
27
     public String getFilename() {
27
         return filename;
28
         return filename;
28
     }
29
     }

+ 5
- 0
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java View File

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

+ 7
- 7
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java View File

81
 				Modifiers.PUBLIC | Modifiers.PROTECTED | Modifiers.PRIVATE,
81
 				Modifiers.PUBLIC | Modifiers.PROTECTED | Modifiers.PRIVATE,
82
 				member.position,
82
 				member.position,
83
 				"Invalid modifier");
83
 				"Invalid modifier");
84
-		if (member.type != member.value.type) {
84
+		if (member.getType() != member.value.type) {
85
 			validator.logError(
85
 			validator.logError(
86
 					ValidationLogEntry.Code.INVALID_TYPE,
86
 					ValidationLogEntry.Code.INVALID_TYPE,
87
 					member.position,
87
 					member.position,
100
 					"Duplicate field name: " + member.name);
100
 					"Duplicate field name: " + member.name);
101
 		}
101
 		}
102
 		fieldNames.add(member.name);
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
 		if (member.initializer != null) {
105
 		if (member.initializer != null) {
106
 			member.initializer.accept(new ExpressionValidator(validator, new FieldInitializerScope(member)));
106
 			member.initializer.accept(new ExpressionValidator(validator, new FieldInitializerScope(member)));
159
 	@Override
159
 	@Override
160
 	public Void visitGetter(GetterMember member) {
160
 	public Void visitGetter(GetterMember member) {
161
 		ValidationUtils.validateIdentifier(validator, member.position, member.name);
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
 		return null;
164
 		return null;
165
 	}
165
 	}
166
 
166
 
167
 	@Override
167
 	@Override
168
 	public Void visitSetter(SetterMember member) {
168
 	public Void visitSetter(SetterMember member) {
169
 		ValidationUtils.validateIdentifier(validator, member.position, member.name);
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
 		validateSetter(member, new MethodStatementScope(new FunctionHeader(BasicTypeID.VOID, member.parameter), member.getAccessScope()));
171
 		validateSetter(member, new MethodStatementScope(new FunctionHeader(BasicTypeID.VOID, member.parameter), member.getAccessScope()));
172
 		return null;
172
 		return null;
173
 	}
173
 	}
321
 			StatementValidator statementValidator = new StatementValidator(validator, scope);
321
 			StatementValidator statementValidator = new StatementValidator(validator, scope);
322
 			member.body.accept(statementValidator);
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
 		if (member.body != null) {
335
 		if (member.body != null) {
336
 			StatementValidator statementValidator = new StatementValidator(validator, scope);
336
 			StatementValidator statementValidator = new StatementValidator(validator, scope);
337
 			member.body.accept(statementValidator);
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 View File

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

Loading…
Cancel
Save