Browse Source

- Fix various bugs in the new system

- Slightly improved the way modules are compiled
Stan Hebben 6 years ago
parent
commit
cf2a752723
21 changed files with 186 additions and 113 deletions
  1. 9
    11
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  2. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionParameter.java
  3. 6
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/Module.java
  4. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java
  5. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java
  6. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberGroup.java
  7. 4
    3
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  8. 1
    8
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompiler.java
  9. 21
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompilingModule.java
  10. 20
    12
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  11. 13
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompiledModule.java
  12. 8
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java
  13. 2
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java
  14. 16
    4
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java
  15. 2
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java
  16. 7
    10
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  17. 5
    6
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  18. 49
    29
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  19. 6
    16
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java
  20. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java
  21. 6
    4
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java

+ 9
- 11
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java View File

46
 		
46
 		
47
 		minParameters = 0;
47
 		minParameters = 0;
48
 		maxParameters = 0;
48
 		maxParameters = 0;
49
-		hasUnknowns = returnType == BasicTypeID.UNDETERMINED.stored;
49
+		hasUnknowns = returnType.type == BasicTypeID.UNDETERMINED;
50
 	}
50
 	}
51
 	
51
 	
52
 	public FunctionHeader(BasicTypeID returnType) {
52
 	public FunctionHeader(BasicTypeID returnType) {
123
 	}
123
 	}
124
 	
124
 	
125
 	public boolean isDenormalized() {
125
 	public boolean isDenormalized() {
126
-		if (returnType.getNormalized() != returnType)
126
+		if (!returnType.getNormalized().equals(returnType))
127
 			return true;
127
 			return true;
128
 		for (FunctionParameter parameter : parameters)
128
 		for (FunctionParameter parameter : parameters)
129
 			if (parameter.type.getNormalized() != parameter.type)
129
 			if (parameter.type.getNormalized() != parameter.type)
138
 		
138
 		
139
 		FunctionParameter[] normalizedParameters = new FunctionParameter[parameters.length];
139
 		FunctionParameter[] normalizedParameters = new FunctionParameter[parameters.length];
140
 		for (int i = 0; i < normalizedParameters.length; i++)
140
 		for (int i = 0; i < normalizedParameters.length; i++)
141
-			normalizedParameters[i] = parameters[i].normalized(registry);
141
+			normalizedParameters[i] = parameters[i].normalize(registry);
142
 		return new FunctionHeader(typeParameters, returnType.getNormalized(), thrownType == null ? null : thrownType.getNormalized(), storage, normalizedParameters);
142
 		return new FunctionHeader(typeParameters, returnType.getNormalized(), thrownType == null ? null : thrownType.getNormalized(), storage, normalizedParameters);
143
 	}
143
 	}
144
 	
144
 	
154
 		return false;
154
 		return false;
155
 	}
155
 	}
156
 	
156
 	
157
-	public FunctionHeader withReturnType(StoredType returnType) {
158
-		return new FunctionHeader(typeParameters, returnType, thrownType, storage, parameters);
159
-	}
160
-	
161
 	public FunctionHeader inferFromOverride(GlobalTypeRegistry registry, FunctionHeader overridden) {
157
 	public FunctionHeader inferFromOverride(GlobalTypeRegistry registry, FunctionHeader overridden) {
162
 		TypeParameter[] resultTypeParameters = typeParameters;
158
 		TypeParameter[] resultTypeParameters = typeParameters;
163
 		StoredType resultReturnType = this.returnType;
159
 		StoredType resultReturnType = this.returnType;
188
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
184
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
189
 			return false;
185
 			return false;
190
 		
186
 		
191
-		FunctionHeader header = fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
187
+		FunctionHeader header = fillGenericArguments(scope, arguments.typeArguments);
192
 		for (int i = 0; i < header.parameters.length; i++) {
188
 		for (int i = 0; i < header.parameters.length; i++) {
193
 			if (!arguments.arguments[i].type.equals(header.parameters[i].type))
189
 			if (!arguments.arguments[i].type.equals(header.parameters[i].type))
194
 				return false;
190
 				return false;
201
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
197
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
202
 			return false;
198
 			return false;
203
 		
199
 		
204
-		FunctionHeader header = fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
200
+		FunctionHeader header = fillGenericArguments(scope, arguments.typeArguments);
205
 		for (int i = 0; i < header.parameters.length; i++) {
201
 		for (int i = 0; i < header.parameters.length; i++) {
206
 			if (!scope.getTypeMembers(arguments.arguments[i].type).canCastImplicit(header.parameters[i].type))
202
 			if (!scope.getTypeMembers(arguments.arguments[i].type).canCastImplicit(header.parameters[i].type))
207
 				return false;
203
 				return false;
221
 			}
217
 			}
222
 			result.append('>');
218
 			result.append('>');
223
 		}
219
 		}
220
+		if (storage != null)
221
+			result.append(storage);
224
 		result.append('(');
222
 		result.append('(');
225
 		for (int i = 0; i < parameters.length; i++) {
223
 		for (int i = 0; i < parameters.length; i++) {
226
 			if (i > 0)
224
 			if (i > 0)
388
 		return new FunctionHeader(typeParameters, returnType, thrownType == null ? null : thrownType.instance(mapper), storage, parameters);
386
 		return new FunctionHeader(typeParameters, returnType, thrownType == null ? null : thrownType.instance(mapper), storage, parameters);
389
 	}
387
 	}
390
 	
388
 	
391
-	public FunctionHeader fillGenericArguments(GlobalTypeRegistry registry, StoredType[] arguments, GenericMapper typeParameterMapping) {
389
+	public FunctionHeader fillGenericArguments(TypeScope scope, StoredType[] arguments) {
392
 		if (arguments == null || arguments.length == 0)
390
 		if (arguments == null || arguments.length == 0)
393
 			return this;
391
 			return this;
394
 		
392
 		
395
 		Map<TypeParameter, StoredType> typeArguments = StoredType.getMapping(typeParameters, arguments);
393
 		Map<TypeParameter, StoredType> typeArguments = StoredType.getMapping(typeParameters, arguments);
396
-		GenericMapper mapper = typeParameterMapping.getInner(registry, typeArguments);
394
+		GenericMapper mapper = scope.getLocalTypeParameters().getInner(scope.getTypeRegistry(), typeArguments);
397
 		
395
 		
398
 		StoredType returnType = this.returnType.instance(mapper);
396
 		StoredType returnType = this.returnType.instance(mapper);
399
 		FunctionParameter[] parameters = new FunctionParameter[this.parameters.length];
397
 		FunctionParameter[] parameters = new FunctionParameter[this.parameters.length];

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

54
 		this.variadic = variadic;
54
 		this.variadic = variadic;
55
 	}
55
 	}
56
 	
56
 	
57
-	public FunctionParameter normalized(GlobalTypeRegistry registry) {
57
+	public FunctionParameter normalize(GlobalTypeRegistry registry) {
58
 		FunctionParameter result = new FunctionParameter(type.getNormalized(), name, defaultValue, variadic);
58
 		FunctionParameter result = new FunctionParameter(type.getNormalized(), name, defaultValue, variadic);
59
 		result.annotations = this.annotations;
59
 		result.annotations = this.annotations;
60
 		return result;
60
 		return result;

+ 6
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/Module.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel;
6
 package org.openzen.zenscript.codemodel;
7
 
7
 
8
-import org.openzen.zencode.shared.Taggable;
9
-
10
 /**
8
 /**
11
  *
9
  *
12
  * @author Hoofdgebruiker
10
  * @author Hoofdgebruiker
13
  */
11
  */
14
-public class Module extends Taggable {
12
+public class Module {
15
 	public static final Module BUILTIN = new Module("builtin");
13
 	public static final Module BUILTIN = new Module("builtin");
16
 	
14
 	
17
 	public final String name;
15
 	public final String name;
19
 	public Module(String name) {
17
 	public Module(String name) {
20
 		this.name = name;
18
 		this.name = name;
21
 	}
19
 	}
20
+	
21
+	@Override
22
+	public String toString() {
23
+		return name;
24
+	}
22
 }
25
 }

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

61
 				type,
61
 				type,
62
 				member,
62
 				member,
63
 				compiledArguments,
63
 				compiledArguments,
64
-				compiledArguments.getNumberOfTypeArguments() == 0 ? member.getHeader() : member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments, scope.getLocalTypeParameters()));
64
+				compiledArguments.getNumberOfTypeArguments() == 0 ? member.getHeader() : member.getHeader().fillGenericArguments(scope, compiledArguments.typeArguments));
65
 	}
65
 	}
66
 	
66
 	
67
 	public Expression not(Expression value) throws CompileException {
67
 	public Expression not(Expression value) throws CompileException {

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

47
 		return annotations;
47
 		return annotations;
48
 	}
48
 	}
49
 	
49
 	
50
+	@Override
51
+	public String toString() {
52
+		return describe();
53
+	}
54
+	
50
 	public boolean isStatic() {
55
 	public boolean isStatic() {
51
 		return Modifiers.isStatic(getEffectiveModifiers());
56
 		return Modifiers.isStatic(getEffectiveModifiers());
52
 	}
57
 	}

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

287
 	
287
 	
288
 	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) throws CompileException {
288
 	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) throws CompileException {
289
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, allowStaticUsage);
289
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, allowStaticUsage);
290
-		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
290
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope, arguments.typeArguments);
291
 		for (int i = 0; i < arguments.arguments.length; i++) {
291
 		for (int i = 0; i < arguments.arguments.length; i++) {
292
 			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
292
 			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
293
 		}
293
 		}
316
 			CompareType compareType) throws CompileException
316
 			CompareType compareType) throws CompileException
317
 	{
317
 	{
318
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, false);
318
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, false);
319
-		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
319
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope, arguments.typeArguments);
320
 		return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
320
 		return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
321
 	}
321
 	}
322
 	
322
 	
323
 	public Expression callStatic(CodePosition position, TypeID target, TypeScope scope, CallArguments arguments) throws CompileException {
323
 	public Expression callStatic(CodePosition position, TypeID target, TypeScope scope, CallArguments arguments) throws CompileException {
324
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, false, true);
324
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, false, true);
325
-		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
325
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope, arguments.typeArguments);
326
 		return method.callStatic(position, target, instancedHeader, arguments, scope);
326
 		return method.callStatic(position, target, instancedHeader, arguments, scope);
327
 	}
327
 	}
328
 	
328
 	

+ 4
- 3
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java View File

136
 		if (state != State.VALIDATED)
136
 		if (state != State.VALIDATED)
137
 			throw new IllegalStateException("Module is not yet validated");
137
 			throw new IllegalStateException("Module is not yet validated");
138
 		
138
 		
139
-		compiler.addModule(this);
139
+		ZenCodeCompilingModule module = compiler.addModule(this);
140
 		for (HighLevelDefinition definition : definitions.getAll()) {
140
 		for (HighLevelDefinition definition : definitions.getAll()) {
141
-			compiler.addDefinition(definition, this);
141
+			module.addDefinition(definition);
142
 		}
142
 		}
143
 		for (ScriptBlock script : scripts) {
143
 		for (ScriptBlock script : scripts) {
144
-			compiler.addScriptBlock(script);
144
+			module.addScriptBlock(script);
145
 		}
145
 		}
146
+		module.finish();
146
 	}
147
 	}
147
 	
148
 	
148
 	public ModuleContext getContext() {
149
 	public ModuleContext getContext() {

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

5
  */
5
  */
6
 package org.openzen.zenscript.compiler;
6
 package org.openzen.zenscript.compiler;
7
 
7
 
8
-import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
-import org.openzen.zenscript.codemodel.ScriptBlock;
10
-
11
 /**
8
 /**
12
  *
9
  *
13
  * @author Hoofdgebruiker
10
  * @author Hoofdgebruiker
14
  */
11
  */
15
 public interface ZenCodeCompiler {
12
 public interface ZenCodeCompiler {
16
-	void addModule(SemanticModule module);
17
-	
18
-	void addDefinition(HighLevelDefinition definition, SemanticModule module);
19
-	
20
-	void addScriptBlock(ScriptBlock script);
13
+	ZenCodeCompilingModule addModule(SemanticModule module);
21
 	
14
 	
22
 	void finish();
15
 	void finish();
23
 	
16
 	

+ 21
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompilingModule.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.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.ScriptBlock;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface ZenCodeCompilingModule {
16
+	void addDefinition(HighLevelDefinition definition);
17
+	
18
+	void addScriptBlock(ScriptBlock script);
19
+	
20
+	void finish();
21
+}

+ 20
- 12
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java View File

19
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
20
 import org.openzen.zenscript.compiler.SemanticModule;
20
 import org.openzen.zenscript.compiler.SemanticModule;
21
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
21
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
22
+import org.openzen.zenscript.compiler.ZenCodeCompilingModule;
22
 import org.openzen.zenscript.javabytecode.compiler.JavaClassWriter;
23
 import org.openzen.zenscript.javabytecode.compiler.JavaClassWriter;
23
 import org.openzen.zenscript.javabytecode.compiler.JavaScriptFile;
24
 import org.openzen.zenscript.javabytecode.compiler.JavaScriptFile;
24
 import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
25
 import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
64
 	}
65
 	}
65
 	
66
 	
66
 	@Override
67
 	@Override
67
-	public void addModule(SemanticModule module) {
68
+	public ZenCodeCompilingModule addModule(SemanticModule module) {
68
 		context.addModule(module.module);
69
 		context.addModule(module.module);
69
-	}
70
-
71
-	@Override
72
-	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
73
-		JavaPrepareDefinitionVisitor preparer = new JavaPrepareDefinitionVisitor(context, context.getJavaModule(module.module), definition.position.getFilename(), null);
74
-		definition.accept(preparer);
75
 		
70
 		
76
-		definitions.add(definition);
77
-	}
71
+		return new ZenCodeCompilingModule() {
72
+			@Override
73
+			public void addDefinition(HighLevelDefinition definition) {
74
+				JavaPrepareDefinitionVisitor preparer = new JavaPrepareDefinitionVisitor(context, context.getJavaModule(module.module), definition.position.getFilename(), null);
75
+				definition.accept(preparer);
78
 
76
 
79
-	@Override
80
-	public void addScriptBlock(ScriptBlock script) {
81
-		scripts.add(script);
77
+				definitions.add(definition);
78
+			}
79
+
80
+			@Override
81
+			public void addScriptBlock(ScriptBlock script) {
82
+				scripts.add(script);
83
+			}
84
+
85
+			@Override
86
+			public void finish() {
87
+				
88
+			}
89
+		};
82
 	}
90
 	}
83
 
91
 
84
 	private String getClassName(String filename) {
92
 	private String getClassName(String filename) {

+ 13
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompiledModule.java View File

23
 	public final Module module;
23
 	public final Module module;
24
 	
24
 	
25
 	private final Map<HighLevelDefinition, JavaClass> classes = new HashMap<>();
25
 	private final Map<HighLevelDefinition, JavaClass> classes = new HashMap<>();
26
+	private final Map<HighLevelDefinition, JavaClass> expansionClasses = new HashMap<>();
26
 	private final Map<HighLevelDefinition, JavaNativeClass> nativeClasses = new HashMap<>();
27
 	private final Map<HighLevelDefinition, JavaNativeClass> nativeClasses = new HashMap<>();
27
 	private final Map<ImplementationMember, JavaImplementation> implementations = new HashMap<>();
28
 	private final Map<ImplementationMember, JavaImplementation> implementations = new HashMap<>();
28
 	private final Map<IDefinitionMember, JavaField> fields = new HashMap<>();
29
 	private final Map<IDefinitionMember, JavaField> fields = new HashMap<>();
38
 		classes.put(definition, cls);
39
 		classes.put(definition, cls);
39
 	}
40
 	}
40
 	
41
 	
42
+	public void setExpansionClassInfo(HighLevelDefinition definition, JavaClass cls) {
43
+		expansionClasses.put(definition, cls);
44
+	}
45
+	
41
 	public JavaClass getClassInfo(HighLevelDefinition definition) {
46
 	public JavaClass getClassInfo(HighLevelDefinition definition) {
42
 		JavaClass cls = classes.get(definition);
47
 		JavaClass cls = classes.get(definition);
43
 		if (cls == null)
48
 		if (cls == null)
46
 		return cls;
51
 		return cls;
47
 	}
52
 	}
48
 	
53
 	
54
+	public JavaClass getExpansionClassInfo(HighLevelDefinition definition) {
55
+		JavaClass cls = expansionClasses.get(definition);
56
+		if (cls == null)
57
+			return getClassInfo(definition);
58
+		
59
+		return cls;
60
+	}
61
+	
49
 	public JavaClass optClassInfo(HighLevelDefinition definition) {
62
 	public JavaClass optClassInfo(HighLevelDefinition definition) {
50
 		return classes.get(definition);
63
 		return classes.get(definition);
51
 	}
64
 	}

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

102
 		return getJavaModule(definition.module).getClassInfo(definition);
102
 		return getJavaModule(definition.module).getClassInfo(definition);
103
 	}
103
 	}
104
 	
104
 	
105
+	public JavaClass getJavaExpansionClass(HighLevelDefinition definition) {
106
+		return getJavaModule(definition.module).getExpansionClassInfo(definition);
107
+	}
108
+	
105
 	public JavaClass optJavaClass(HighLevelDefinition definition) {
109
 	public JavaClass optJavaClass(HighLevelDefinition definition) {
106
 		return getJavaModule(definition.module).optClassInfo(definition);
110
 		return getJavaModule(definition.module).optClassInfo(definition);
107
 	}
111
 	}
118
 		getJavaModule(definition.module).setClassInfo(definition, cls);
122
 		getJavaModule(definition.module).setClassInfo(definition, cls);
119
 	}
123
 	}
120
 	
124
 	
125
+	public void setJavaExpansionClass(HighLevelDefinition definition, JavaClass cls) {
126
+		getJavaModule(definition.module).setExpansionClassInfo(definition, cls);
127
+	}
128
+	
121
 	public void setJavaNativeClass(HighLevelDefinition definition, JavaNativeClass cls) {
129
 	public void setJavaNativeClass(HighLevelDefinition definition, JavaNativeClass cls) {
122
 		getJavaModule(definition.module).setNativeClassInfo(definition, cls);
130
 		getJavaModule(definition.module).setNativeClassInfo(definition, cls);
123
 	}
131
 	}

+ 2
- 0
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;
11
 import org.openzen.zenscript.codemodel.OperatorType;
12
 import org.openzen.zenscript.codemodel.OperatorType;
12
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
13
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
13
 import org.openzen.zenscript.codemodel.member.CallerMember;
14
 import org.openzen.zenscript.codemodel.member.CallerMember;
298
 		
299
 		
299
 		if (member.getOverrides() != null) {
300
 		if (member.getOverrides() != null) {
300
 			DefinitionMemberRef base = member.getOverrides();
301
 			DefinitionMemberRef base = member.getOverrides();
302
+			
301
 			JavaMethod baseMethod = context.getJavaMethod(base.getTarget());
303
 			JavaMethod baseMethod = context.getJavaMethod(base.getTarget());
302
 			method = new JavaMethod(
304
 			method = new JavaMethod(
303
 					cls,
305
 					cls,

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

45
 	public void prepare(TypeID type) {
45
 	public void prepare(TypeID type) {
46
 		if (!(type instanceof DefinitionTypeID))
46
 		if (!(type instanceof DefinitionTypeID))
47
 			return;
47
 			return;
48
-			
48
+		
49
 		HighLevelDefinition definition = ((DefinitionTypeID)type).definition;
49
 		HighLevelDefinition definition = ((DefinitionTypeID)type).definition;
50
-		System.out.println("Preparing " + definition.name);
50
+		prepare(definition);
51
+	}
52
+	
53
+	public void prepare(HighLevelDefinition definition) {
54
+		if (isPrepared(definition))
55
+			return;
56
+		if (definition.module != module.module)
57
+			throw new IllegalArgumentException("Definition is not in the same module as the current module!");
58
+		
59
+		System.out.println("~~ Preparing " + definition.name);
51
 		definition.accept(this);
60
 		definition.accept(this);
52
 	}
61
 	}
53
 	
62
 	
103
 			return context.getJavaClass(definition);
112
 			return context.getJavaClass(definition);
104
 		
113
 		
105
 		JavaNativeClass nativeClass = context.getJavaNativeClass(definition);
114
 		JavaNativeClass nativeClass = context.getJavaNativeClass(definition);
106
-		JavaClass cls = context.getJavaClass(definition);
115
+		JavaClass cls = context.getJavaExpansionClass(definition);
107
 		visitExpansionMembers(definition, cls, nativeClass);
116
 		visitExpansionMembers(definition, cls, nativeClass);
108
 		return cls;
117
 		return cls;
109
 	}
118
 	}
133
 		if (nativeClass == null) {
142
 		if (nativeClass == null) {
134
 			visitClassMembers(definition, cls, null, startsEmpty);
143
 			visitClassMembers(definition, cls, null, startsEmpty);
135
 		} else {
144
 		} else {
136
-			visitExpansionMembers(definition, cls, nativeClass);
145
+			cls.membersPrepared = true;
146
+			JavaClass expansionCls = context.getJavaExpansionClass(definition);
147
+			visitExpansionMembers(definition, expansionCls, nativeClass);
148
+			cls.empty = expansionCls.empty;
137
 		}
149
 		}
138
 		return cls;
150
 		return cls;
139
 	}
151
 	}

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

347
 			cls.destructible = definition.isDestructible();
347
 			cls.destructible = definition.isDestructible();
348
 			context.setJavaClass(definition, cls);
348
 			context.setJavaClass(definition, cls);
349
 		} else {
349
 		} else {
350
-			cls = outerClass == null ? new JavaClass(definition.pkg.fullName, filename, kind) : new JavaClass(outerClass, filename, kind);
350
+			cls = outerClass == null ? new JavaClass(definition.pkg.fullName, definition.name + "Expansion", kind) : new JavaClass(outerClass, definition.name + "Expansion", kind);
351
 			
351
 			
352
 			context.setJavaClass(definition, nativeClass.cls);
352
 			context.setJavaClass(definition, nativeClass.cls);
353
+			context.setJavaExpansionClass(definition, cls);
353
 			context.setJavaNativeClass(definition, nativeClass);
354
 			context.setJavaNativeClass(definition, nativeClass);
354
 			
355
 			
355
 			if (nativeClass.nonDestructible)
356
 			if (nativeClass.nonDestructible)

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

7
 
7
 
8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.List;
9
 import java.util.List;
10
-import java.util.Map;
11
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.Modifiers;
12
 import org.openzen.zenscript.codemodel.Modifiers;
33
 import org.openzen.zenscript.codemodel.type.TypeID;
32
 import org.openzen.zenscript.codemodel.type.TypeID;
34
 import org.openzen.zenscript.compiler.CompileScope;
33
 import org.openzen.zenscript.compiler.CompileScope;
35
 import org.openzen.zenscript.compiler.SemanticModule;
34
 import org.openzen.zenscript.compiler.SemanticModule;
36
-import org.openzen.zenscript.javashared.JavaNativeClass;
37
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
35
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
38
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
36
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
39
 import org.openzen.zenscript.javashared.JavaClass;
37
 import org.openzen.zenscript.javashared.JavaClass;
53
 	private final JavaSourceFormattingSettings settings;
51
 	private final JavaSourceFormattingSettings settings;
54
 	private final List<ExpansionDefinition> expansions;
52
 	private final List<ExpansionDefinition> expansions;
55
 	private final StringBuilder output;
53
 	private final StringBuilder output;
56
-	private final Map<HighLevelDefinition, SemanticModule> modules;
57
 	private final JavaContext context;
54
 	private final JavaContext context;
58
 	private final JavaCompiledModule module;
55
 	private final JavaCompiledModule module;
56
+	private final SemanticModule semanticModule;
59
 	
57
 	
60
 	public JavaDefinitionVisitor(
58
 	public JavaDefinitionVisitor(
61
 			String indent,
59
 			String indent,
65
 			JavaSourceFile file,
63
 			JavaSourceFile file,
66
 			StringBuilder output,
64
 			StringBuilder output,
67
 			List<ExpansionDefinition> expansions,
65
 			List<ExpansionDefinition> expansions,
68
-			Map<HighLevelDefinition, SemanticModule> modules)
66
+			SemanticModule semanticModule)
69
 	{
67
 	{
70
 		this.indent = indent;
68
 		this.indent = indent;
71
 		this.compiler = compiler;
69
 		this.compiler = compiler;
74
 		this.settings = compiler.settings;
72
 		this.settings = compiler.settings;
75
 		this.output = output;
73
 		this.output = output;
76
 		this.expansions = expansions;
74
 		this.expansions = expansions;
77
-		this.modules = modules;
78
 		this.context = compiler.context;
75
 		this.context = compiler.context;
79
 		this.module = module;
76
 		this.module = module;
77
+		this.semanticModule = semanticModule;
80
 	}
78
 	}
81
 	
79
 	
82
 	private JavaSourceFileScope createScope(HighLevelDefinition definition) {
80
 	private JavaSourceFileScope createScope(HighLevelDefinition definition) {
83
-		SemanticModule module = modules.get(definition.getOutermost());
84
-		GlobalTypeRegistry typeRegistry = module.compilationUnit.globalTypeRegistry;
81
+		GlobalTypeRegistry typeRegistry = semanticModule.compilationUnit.globalTypeRegistry;
85
 		DefinitionTypeID thisType = typeRegistry.getForMyDefinition(definition);
82
 		DefinitionTypeID thisType = typeRegistry.getForMyDefinition(definition);
86
 		
83
 		
87
-		CompileScope scope = new CompileScope(module.compilationUnit.globalTypeRegistry, module.expansions, module.annotations, module.storageTypes);
84
+		CompileScope scope = new CompileScope(semanticModule.compilationUnit.globalTypeRegistry, semanticModule.expansions, semanticModule.annotations, semanticModule.storageTypes);
88
 		return new JavaSourceFileScope(file.importer, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition, thisType, compiler.context);
85
 		return new JavaSourceFileScope(file.importer, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition, thisType, compiler.context);
89
 	}
86
 	}
90
 	
87
 	
103
 	@Override
100
 	@Override
104
 	public Void visitClass(ClassDefinition definition) {
101
 	public Void visitClass(ClassDefinition definition) {
105
 		JavaSourceFileScope scope = createScope(definition);
102
 		JavaSourceFileScope scope = createScope(definition);
106
-		JavaClass cls = context.getJavaClass(definition);
103
+		JavaClass cls = context.getJavaExpansionClass(definition);
107
 		
104
 		
108
 		output.append(indent);
105
 		output.append(indent);
109
 		convertModifiers(definition.modifiers);
106
 		convertModifiers(definition.modifiers);
401
 				member.accept(memberCompiler);
398
 				member.accept(memberCompiler);
402
 			memberCompiler.finish();
399
 			memberCompiler.finish();
403
 		} else {
400
 		} else {
404
-			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(compiler, module, file, settings, indent + settings.indent, output, scope, scope.isInterface, definition, modules);
401
+			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(compiler, module, file, settings, indent + settings.indent, output, scope, scope.isInterface, definition, semanticModule);
405
 			for (IDefinitionMember member : definition.members)
402
 			for (IDefinitionMember member : definition.members)
406
 				member.accept(memberCompiler);
403
 				member.accept(memberCompiler);
407
 			
404
 			

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

9
 import java.util.ArrayList;
9
 import java.util.ArrayList;
10
 import java.util.Collections;
10
 import java.util.Collections;
11
 import java.util.List;
11
 import java.util.List;
12
-import java.util.Map;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
 import org.openzen.zenscript.codemodel.FunctionParameter;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
53
 	private final JavaSourceFile file;
52
 	private final JavaSourceFile file;
54
 	private final List<FieldMember> fields = new ArrayList<>();
53
 	private final List<FieldMember> fields = new ArrayList<>();
55
 	private final boolean isInterface;
54
 	private final boolean isInterface;
56
-	private final Map<HighLevelDefinition, SemanticModule> modules;
57
 	private final JavaContext context;
55
 	private final JavaContext context;
58
 	public boolean hasDestructor = false;
56
 	public boolean hasDestructor = false;
59
 	private final JavaCompiledModule module;
57
 	private final JavaCompiledModule module;
58
+	private final SemanticModule semanticModule;
60
 	
59
 	
61
 	public JavaMemberCompiler(
60
 	public JavaMemberCompiler(
62
 			JavaSourceCompiler compiler,
61
 			JavaSourceCompiler compiler,
68
 			JavaSourceFileScope scope,
67
 			JavaSourceFileScope scope,
69
 			boolean isInterface,
68
 			boolean isInterface,
70
 			HighLevelDefinition definition,
69
 			HighLevelDefinition definition,
71
-			Map<HighLevelDefinition, SemanticModule> modules)
70
+			SemanticModule semanticModule)
72
 	{
71
 	{
73
 		super(settings, indent, output, scope, null, definition);
72
 		super(settings, indent, output, scope, null, definition);
74
 		
73
 		
75
 		this.file = file;
74
 		this.file = file;
76
 		this.isInterface = isInterface;
75
 		this.isInterface = isInterface;
77
 		this.compiler = compiler;
76
 		this.compiler = compiler;
78
-		this.modules = modules;
79
 		this.context = compiler.context;
77
 		this.context = compiler.context;
80
 		this.module = module;
78
 		this.module = module;
79
+		this.semanticModule = semanticModule;
81
 	}
80
 	}
82
 	
81
 	
83
 	private void compileMethod(DefinitionMember member, FunctionHeader header, Statement body) {
82
 	private void compileMethod(DefinitionMember member, FunctionHeader header, Statement body) {
243
 			
242
 			
244
 			begin(ElementType.INNERCLASS);
243
 			begin(ElementType.INNERCLASS);
245
 			output.append("private class ").append(implementationName).append(" implements ").append(scope.type(member.type)).append(" {\n");
244
 			output.append("private class ").append(implementationName).append(" implements ").append(scope.type(member.type)).append(" {\n");
246
-			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(compiler, module, file, settings, indent + settings.indent, output, scope, isInterface, definition, modules);
245
+			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(compiler, module, file, settings, indent + settings.indent, output, scope, isInterface, definition, semanticModule);
247
 			for (IDefinitionMember m : member.members) {
246
 			for (IDefinitionMember m : member.members) {
248
 				m.accept(memberCompiler);
247
 				m.accept(memberCompiler);
249
 			}
248
 			}
266
 				file,
265
 				file,
267
 				output,
266
 				output,
268
 				Collections.emptyList(),
267
 				Collections.emptyList(),
269
-				modules);
268
+				semanticModule);
270
 		member.innerDefinition.accept(visitor);
269
 		member.innerDefinition.accept(visitor);
271
 		return null;
270
 		return null;
272
 	}
271
 	}

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

6
 package org.openzen.zenscript.javasource;
6
 package org.openzen.zenscript.javasource;
7
 
7
 
8
 import java.io.File;
8
 import java.io.File;
9
+import java.util.ArrayList;
9
 import java.util.HashMap;
10
 import java.util.HashMap;
11
+import java.util.List;
10
 import java.util.Map;
12
 import java.util.Map;
11
 import org.openzen.zencode.shared.SourceFile;
13
 import org.openzen.zencode.shared.SourceFile;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
 import org.openzen.zenscript.compiler.CompilationUnit;
17
 import org.openzen.zenscript.compiler.CompilationUnit;
16
 import org.openzen.zenscript.compiler.SemanticModule;
18
 import org.openzen.zenscript.compiler.SemanticModule;
17
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
19
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
20
+import org.openzen.zenscript.compiler.ZenCodeCompilingModule;
18
 import org.openzen.zenscript.javashared.JavaBaseCompiler;
21
 import org.openzen.zenscript.javashared.JavaBaseCompiler;
19
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
22
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
20
 import org.openzen.zenscript.javashared.JavaClass;
23
 import org.openzen.zenscript.javashared.JavaClass;
28
 	public final JavaSourceSyntheticHelperGenerator helperGenerator;
31
 	public final JavaSourceSyntheticHelperGenerator helperGenerator;
29
 	
32
 	
30
 	private final File directory;
33
 	private final File directory;
31
-	private final Map<File, JavaSourceFile> sourceFiles = new HashMap<>();
32
 	public final JavaSourceContext context;
34
 	public final JavaSourceContext context;
35
+	private final List<SourceModule> modules = new ArrayList<>();
33
 	
36
 	
34
 	public JavaSourceCompiler(File directory, CompilationUnit compilationUnit) {
37
 	public JavaSourceCompiler(File directory, CompilationUnit compilationUnit) {
35
 		if (!directory.exists())
38
 		if (!directory.exists())
43
 	}
46
 	}
44
 	
47
 	
45
 	@Override
48
 	@Override
46
-	public void addModule(SemanticModule module) {
49
+	public ZenCodeCompilingModule addModule(SemanticModule module) {
47
 		context.addModule(module.module);
50
 		context.addModule(module.module);
48
-	}
49
-	
50
-	@Override
51
-	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
52
-		String filename = getFilename(definition);
53
-		JavaPrepareDefinitionVisitor prepare = new JavaPrepareDefinitionVisitor(context, context.getJavaModule(module.module), filename, null);
54
-		JavaClass cls = definition.accept(prepare);
55
-		
56
-		File file = new File(getDirectory(definition.pkg), cls.getName() + ".java");
57
-		System.out.println("Compiling " + definition.name + " as " + cls.fullName);
58
-		JavaSourceFile sourceFile = sourceFiles.get(file);
59
-		if (sourceFile == null)
60
-			sourceFiles.put(file, sourceFile = new JavaSourceFile(this, file, cls, module.module, definition.pkg));
61
-		
62
-		sourceFile.add(definition, module);
63
-	}
64
-	
65
-	@Override
66
-	public void addScriptBlock(ScriptBlock script) {
67
-		
51
+		SourceModule result = new SourceModule(module);
52
+		modules.add(result);
53
+		return result;
68
 	}
54
 	}
69
 	
55
 	
70
 	@Override
56
 	@Override
71
 	public void finish() {
57
 	public void finish() {
72
-		for (JavaSourceFile sourceFile : sourceFiles.values()) {
73
-			sourceFile.prepare(context);
74
-		}
75
-		
76
-		for (JavaSourceFile sourceFile : sourceFiles.values())
77
-			sourceFile.write();
78
-		
79
 		helperGenerator.write();
58
 		helperGenerator.write();
80
 	}
59
 	}
81
 	
60
 	
107
 			return definition.name == null ? "Expansion" : definition.name;
86
 			return definition.name == null ? "Expansion" : definition.name;
108
 		}
87
 		}
109
 	}
88
 	}
89
+	
90
+	private class SourceModule implements ZenCodeCompilingModule {
91
+		private final Map<File, JavaSourceFile> sourceFiles = new HashMap<>();
92
+		private final SemanticModule module;
93
+		
94
+		public SourceModule(SemanticModule module) {
95
+			this.module = module;
96
+		}
97
+
98
+		@Override
99
+		public void addDefinition(HighLevelDefinition definition) {
100
+			String filename = getFilename(definition);
101
+			JavaPrepareDefinitionVisitor prepare = new JavaPrepareDefinitionVisitor(context, context.getJavaModule(module.module), filename, null);
102
+			JavaClass cls = definition.accept(prepare);
103
+
104
+			File file = new File(getDirectory(definition.pkg), cls.getName() + ".java");
105
+			System.out.println("Compiling " + definition.name + " as " + cls.fullName);
106
+			JavaSourceFile sourceFile = sourceFiles.get(file);
107
+			if (sourceFile == null)
108
+				sourceFiles.put(file, sourceFile = new JavaSourceFile(JavaSourceCompiler.this, file, cls, module, definition.pkg));
109
+
110
+			sourceFile.add(definition);
111
+		}
112
+
113
+		@Override
114
+		public void addScriptBlock(ScriptBlock script) {
115
+			// TODO: implement this too
116
+		}
117
+
118
+		@Override
119
+		public void finish() {
120
+			for (JavaSourceFile sourceFile : sourceFiles.values()) {
121
+				sourceFile.prepare(context);
122
+			}
123
+
124
+			for (JavaSourceFile sourceFile : sourceFiles.values())
125
+				sourceFile.write();
126
+
127
+		}
128
+		
129
+	}
110
 }
130
 }

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

15
 import java.io.Writer;
15
 import java.io.Writer;
16
 import java.nio.charset.StandardCharsets;
16
 import java.nio.charset.StandardCharsets;
17
 import java.util.ArrayList;
17
 import java.util.ArrayList;
18
-import java.util.HashMap;
19
-import java.util.HashSet;
20
 import java.util.List;
18
 import java.util.List;
21
-import java.util.Map;
22
-import java.util.Set;
23
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
19
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
24
-import org.openzen.zenscript.codemodel.Module;
25
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
20
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
26
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
27
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
22
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
40
 	private final JavaClass cls;
35
 	private final JavaClass cls;
41
 	private final StringBuilder contents = new StringBuilder();
36
 	private final StringBuilder contents = new StringBuilder();
42
 	private final ZSPackage pkg;
37
 	private final ZSPackage pkg;
43
-	private final Module module;
38
+	private final SemanticModule module;
44
 	
39
 	
45
 	private HighLevelDefinition mainDefinition;
40
 	private HighLevelDefinition mainDefinition;
46
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
41
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
47
 	
42
 	
48
-	private final Map<HighLevelDefinition, SemanticModule> modules = new HashMap<>();
49
-	private final Set<String> existing = new HashSet<>();
50
-	
51
-	public JavaSourceFile(JavaSourceCompiler compiler, File file, JavaClass cls, Module module, ZSPackage pkg) {
43
+	public JavaSourceFile(JavaSourceCompiler compiler, File file, JavaClass cls, SemanticModule module, ZSPackage pkg) {
52
 		this.compiler = compiler;
44
 		this.compiler = compiler;
53
 		this.pkg = pkg;
45
 		this.pkg = pkg;
54
 		this.cls = cls;
46
 		this.cls = cls;
62
 		return cls.getName();
54
 		return cls.getName();
63
 	}
55
 	}
64
 	
56
 	
65
-	public void add(HighLevelDefinition definition, SemanticModule module) {
57
+	public void add(HighLevelDefinition definition) {
66
 		if (definition instanceof ExpansionDefinition) {
58
 		if (definition instanceof ExpansionDefinition) {
67
 			expansions.add((ExpansionDefinition)definition);
59
 			expansions.add((ExpansionDefinition)definition);
68
 		} else if (mainDefinition != null) {
60
 		} else if (mainDefinition != null) {
70
 		} else {
62
 		} else {
71
 			mainDefinition = definition;
63
 			mainDefinition = definition;
72
 		}
64
 		}
73
-		
74
-		modules.put(definition, module);
75
 	}
65
 	}
76
 	
66
 	
77
 	public void prepare(JavaContext context) {
67
 	public void prepare(JavaContext context) {
78
-		JavaPrepareDefinitionMemberVisitor visitor = new JavaPrepareDefinitionMemberVisitor(context, context.getJavaModule(module));
68
+		JavaPrepareDefinitionMemberVisitor visitor = new JavaPrepareDefinitionMemberVisitor(context, context.getJavaModule(module.module));
79
 		
69
 		
80
 		if (mainDefinition != null)
70
 		if (mainDefinition != null)
81
 			mainDefinition.accept(visitor);
71
 			mainDefinition.accept(visitor);
109
 		JavaDefinitionVisitor visitor = new JavaDefinitionVisitor(
99
 		JavaDefinitionVisitor visitor = new JavaDefinitionVisitor(
110
 				"",
100
 				"",
111
 				compiler,
101
 				compiler,
112
-				compiler.context.getJavaModule(module),
102
+				compiler.context.getJavaModule(module.module),
113
 				cls,
103
 				cls,
114
 				this,
104
 				this,
115
 				contents,
105
 				contents,
116
 				expansions,
106
 				expansions,
117
-				modules);
107
+				module);
118
 		definition.accept(visitor);
108
 		definition.accept(visitor);
119
 		
109
 		
120
 		if (!file.getParentFile().exists())
110
 		if (!file.getParentFile().exists())

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

72
 					type,
72
 					type,
73
 					member,
73
 					member,
74
 					compiledArguments,
74
 					compiledArguments,
75
-					member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments, scope.getLocalTypeParameters()));
75
+					member.getHeader().fillGenericArguments(scope, compiledArguments.typeArguments));
76
 		} catch (CompileException ex) {
76
 		} catch (CompileException ex) {
77
 			return new InvalidExpression(type, ex);
77
 			return new InvalidExpression(type, ex);
78
 		}
78
 		}

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

25
 import org.openzen.zenscript.javabytecode.JavaCompiler;
25
 import org.openzen.zenscript.javabytecode.JavaCompiler;
26
 import org.openzen.zenscript.javabytecode.JavaModule;
26
 import org.openzen.zenscript.javabytecode.JavaModule;
27
 import org.openzen.zenscript.compiler.ModuleSpace;
27
 import org.openzen.zenscript.compiler.ModuleSpace;
28
+import org.openzen.zenscript.compiler.ZenCodeCompilingModule;
28
 import org.openzen.zenscript.lexer.ParseException;
29
 import org.openzen.zenscript.lexer.ParseException;
29
 import org.openzen.zenscript.lexer.ZSToken;
30
 import org.openzen.zenscript.lexer.ZSToken;
30
 import org.openzen.zenscript.lexer.ZSTokenParser;
31
 import org.openzen.zenscript.lexer.ZSTokenParser;
131
 		JavaCompiler compiler = new JavaCompiler(module.compilationUnit.globalTypeRegistry, false, null);
132
 		JavaCompiler compiler = new JavaCompiler(module.compilationUnit.globalTypeRegistry, false, null);
132
 		registry.register(compiler.getContext());
133
 		registry.register(compiler.getContext());
133
 		
134
 		
134
-		compiler.getContext().addModule(module.module);
135
-		
135
+		ZenCodeCompilingModule compiling = compiler.addModule(module);
136
 		for (HighLevelDefinition definition : module.definitions.getAll()) {
136
 		for (HighLevelDefinition definition : module.definitions.getAll()) {
137
-			compiler.addDefinition(definition, module);
137
+			compiling.addDefinition(definition);
138
 		}
138
 		}
139
 		for (ScriptBlock script : module.scripts) {
139
 		for (ScriptBlock script : module.scripts) {
140
-			compiler.addScriptBlock(script);
140
+			compiling.addScriptBlock(script);
141
 		}
141
 		}
142
+		compiling.finish();
143
+		
142
 		return compiler.finishAndGetModule();
144
 		return compiler.finishAndGetModule();
143
 	}
145
 	}
144
 	
146
 	

Loading…
Cancel
Save