Pārlūkot izejas kodu

Moved Java compile-time tags to non-global state

Stan Hebben 6 gadus atpakaļ
vecāks
revīzija
f1bb71b3a1
51 mainītis faili ar 606 papildinājumiem un 299 dzēšanām
  1. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/WhitespaceInfo.java
  2. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/WhitespacePostComment.java
  3. 3
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeTag.java
  4. 4
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java
  5. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/CasterMemberRef.java
  6. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/DefinitionMemberRef.java
  7. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FunctionalMemberRef.java
  8. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ImplementationMemberRef.java
  9. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/IteratorMemberRef.java
  10. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/PropertyRef.java
  11. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/VariantOptionRef.java
  12. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java
  13. 1
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  14. 2
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompiler.java
  15. 1
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  16. 19
    10
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  17. 6
    5
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  18. 35
    61
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  19. 4
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java
  20. 10
    17
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  21. 10
    15
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  22. 5
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  23. 16
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  24. 8
    9
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  25. 15
    13
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  26. 1
    0
      JavaShared/build.gradle
  27. 17
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaBaseCompiler.java
  28. 4
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java
  29. 132
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompiledModule.java
  30. 77
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java
  31. 1
    4
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java
  32. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java
  33. 14
    12
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java
  34. 22
    19
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java
  35. 25
    18
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java
  36. 11
    5
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java
  37. 35
    12
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  38. 1
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java
  39. 16
    7
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  40. 9
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  41. 16
    15
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  42. 21
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java
  43. 5
    6
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceImporter.java
  44. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java
  45. 3
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java
  46. 5
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/scope/JavaSourceStatementScope.java
  47. 17
    24
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java
  48. 6
    2
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  49. 1
    1
      Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java
  50. 4
    0
      Shared/src/main/java/org/openzen/zencode/shared/Tag.java
  51. 3
    3
      Shared/src/main/java/org/openzen/zencode/shared/Taggable.java

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/WhitespaceInfo.java Parādīt failu

@@ -7,13 +7,14 @@ package org.openzen.zenscript.codemodel;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10
+import org.openzen.zencode.shared.Tag;
10 11
 import stdlib.Strings;
11 12
 
12 13
 /**
13 14
  *
14 15
  * @author Hoofdgebruiker
15 16
  */
16
-public class WhitespaceInfo {
17
+public class WhitespaceInfo implements Tag {
17 18
 	public static WhitespaceInfo from(String whitespaceBefore, String lineAfter, boolean skipLineBefore) {
18 19
 		int numNewLines = 0;
19 20
 		for (char c : whitespaceBefore.toCharArray())

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/WhitespacePostComment.java Parādīt failu

@@ -7,13 +7,14 @@ package org.openzen.zenscript.codemodel;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10
+import org.openzen.zencode.shared.Tag;
10 11
 import stdlib.Strings;
11 12
 
12 13
 /**
13 14
  *
14 15
  * @author Hoofdgebruiker
15 16
  */
16
-public class WhitespacePostComment {
17
+public class WhitespacePostComment implements Tag {
17 18
 	public static WhitespacePostComment fromWhitespace(String whitespace) {
18 19
 		List<String> comments = new ArrayList<>();
19 20
 		for (String line : Strings.split(whitespace, '\n')) {

+ 3
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeTag.java Parādīt failu

@@ -5,11 +5,13 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.annotations;
7 7
 
8
+import org.openzen.zencode.shared.Tag;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker
11 13
  */
12
-public class NativeTag {
14
+public class NativeTag implements Tag {
13 15
 	public final String value;
14 16
 	
15 17
 	public NativeTag(String value) {

+ 4
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IDefinitionMember.java Parādīt failu

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.Tag;
9 10
 import org.openzen.zenscript.codemodel.AccessScope;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.GenericMapper;
@@ -43,11 +44,11 @@ public interface IDefinitionMember {
43 44
 	
44 45
 	public <C, R> R accept(C context, MemberVisitorWithContext<C, R> visitor);
45 46
 	
46
-	public <T> T getTag(Class<T> tag);
47
+	public <T extends Tag> T getTag(Class<T> tag);
47 48
 	
48
-	public <T> void setTag(Class<T> tag, T value);
49
+	public <T extends Tag> void setTag(Class<T> tag, T value);
49 50
 
50
-	<T> boolean hasTag(Class<T> tag);
51
+	<T extends Tag> boolean hasTag(Class<T> tag);
51 52
 	
52 53
 	DefinitionMemberRef getOverrides();
53 54
 

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/CasterMemberRef.java Parādīt failu

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.Tag;
9 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 11
 import org.openzen.zenscript.codemodel.Modifiers;
11 12
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
@@ -46,7 +47,7 @@ public class CasterMemberRef implements DefinitionMemberRef {
46 47
 	}
47 48
 
48 49
 	@Override
49
-	public <T> T getTag(Class<T> type) {
50
+	public <T extends Tag> T getTag(Class<T> type) {
50 51
 		return member.getTag(type);
51 52
 	}
52 53
 	

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/DefinitionMemberRef.java Parādīt failu

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.Tag;
9 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 11
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11 12
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
@@ -20,11 +21,11 @@ public interface DefinitionMemberRef {
20 21
 	
21 22
 	String describe();
22 23
 	
23
-	default <T> T getTag(Class<T> type) {
24
+	default <T extends Tag> T getTag(Class<T> type) {
24 25
 		return getTarget().getTag(type);
25 26
 	}
26 27
 	
27
-	default boolean hasTag(Class<?> type) {
28
+	default <T extends Tag> boolean hasTag(Class<T> type) {
28 29
 		return getTarget().hasTag(type);
29 30
 	}
30 31
 	

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FunctionalMemberRef.java Parādīt failu

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.Tag;
9 10
 import org.openzen.zenscript.codemodel.CompareType;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.GenericMapper;
@@ -91,7 +92,7 @@ public class FunctionalMemberRef implements DefinitionMemberRef {
91 92
 	}
92 93
 	
93 94
 	@Override
94
-	public <T> T getTag(Class<T> cls) {
95
+	public <T extends Tag> T getTag(Class<T> cls) {
95 96
 		return target.getTag(cls);
96 97
 	}
97 98
 	

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/ImplementationMemberRef.java Parādīt failu

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.Tag;
9 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 11
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11 12
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
@@ -43,7 +44,7 @@ public class ImplementationMemberRef implements DefinitionMemberRef {
43 44
 	}
44 45
 
45 46
 	@Override
46
-	public <T> T getTag(Class<T> type) {
47
+	public <T extends Tag> T getTag(Class<T> type) {
47 48
 		return member.getTag(type);
48 49
 	}
49 50
 

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/IteratorMemberRef.java Parādīt failu

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.Tag;
9 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 11
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
11 12
 import org.openzen.zenscript.codemodel.member.IteratorMember;
@@ -43,7 +44,7 @@ public class IteratorMemberRef implements DefinitionMemberRef {
43 44
 	}
44 45
 
45 46
 	@Override
46
-	public <T> T getTag(Class<T> type) {
47
+	public <T extends Tag> T getTag(Class<T> type) {
47 48
 		return target.getTag(type);
48 49
 	}
49 50
 	

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/PropertyRef.java Parādīt failu

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.Tag;
9 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 11
 import org.openzen.zenscript.codemodel.GenericMapper;
11 12
 import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
@@ -66,7 +67,7 @@ public abstract class PropertyRef implements DefinitionMemberRef {
66 67
 	}
67 68
 
68 69
 	@Override
69
-	public final <T> T getTag(Class<T> type) {
70
+	public final <T extends Tag> T getTag(Class<T> type) {
70 71
 		return member.getTag(type);
71 72
 	}
72 73
 	

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/VariantOptionRef.java Parādīt failu

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8
+import org.openzen.zencode.shared.Tag;
8 9
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
9 10
 import org.openzen.zenscript.codemodel.type.StoredType;
10 11
 
@@ -31,7 +32,7 @@ public class VariantOptionRef {
31 32
 		return types[index];
32 33
 	}
33 34
 	
34
-	public <T> T getTag(Class<T> type) {
35
+	public <T extends Tag> T getTag(Class<T> type) {
35 36
 		return option.getTag(type);
36 37
 	}
37 38
 

+ 0
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java Parādīt failu

@@ -38,8 +38,6 @@ public class FunctionScope extends StatementScope {
38 38
 		this.outer = outer;
39 39
 		this.header = header;
40 40
 		this.thisType = outer.getThisType() == null || header.storage == null ? outer.getThisType() : outer.getThisType().type.stored(header.storage);
41
-		if (header.storage != null)
42
-			System.out.println("Storage is " + header.storage);
43 41
 		
44 42
 		if (outer.getLocalTypeParameters() == null)
45 43
 			throw new NullPointerException();

+ 1
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java Parādīt failu

@@ -136,6 +136,7 @@ public class SemanticModule {
136 136
 		if (state != State.VALIDATED)
137 137
 			throw new IllegalStateException("Module is not yet validated");
138 138
 		
139
+		compiler.addModule(this);
139 140
 		for (HighLevelDefinition definition : definitions.getAll()) {
140 141
 			compiler.addDefinition(definition, this);
141 142
 		}

+ 2
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompiler.java Parādīt failu

@@ -13,6 +13,8 @@ import org.openzen.zenscript.codemodel.ScriptBlock;
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public interface ZenCodeCompiler {
16
+	void addModule(SemanticModule module);
17
+	
16 18
 	void addDefinition(HighLevelDefinition definition, SemanticModule module);
17 19
 	
18 20
 	void addScriptBlock(ScriptBlock script);

+ 1
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java Parādīt failu

@@ -104,6 +104,7 @@ public class LocalTarget implements IDETarget {
104 104
 			stdlib.validate(validationLogger);
105 105
 			if (!stdlib.isValid())
106 106
 				return compiler;
107
+			
107 108
 			stdlib.compile(compiler);
108 109
 			compiledModules.add(stdlib.name);
109 110
 			

+ 19
- 10
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Parādīt failu

@@ -7,13 +7,16 @@ package org.openzen.zenscript.javabytecode;
7 7
 
8 8
 import java.io.File;
9 9
 import java.util.ArrayList;
10
-
10
+import java.util.HashMap;
11
+import java.util.List;
12
+import java.util.Map;
11 13
 import org.objectweb.asm.ClassWriter;
12 14
 import org.objectweb.asm.Opcodes;
13 15
 import org.openzen.zencode.shared.SourceFile;
14 16
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 17
 import org.openzen.zenscript.codemodel.ScriptBlock;
16 18
 import org.openzen.zenscript.codemodel.statement.Statement;
19
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17 20
 import org.openzen.zenscript.compiler.SemanticModule;
18 21
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
19 22
 import org.openzen.zenscript.javabytecode.compiler.JavaClassWriter;
@@ -21,12 +24,9 @@ import org.openzen.zenscript.javabytecode.compiler.JavaScriptFile;
21 24
 import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
22 25
 import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
23 26
 import org.openzen.zenscript.javabytecode.compiler.definitions.JavaDefinitionVisitor;
24
-
25
-import java.util.HashMap;
26
-import java.util.List;
27
-import java.util.Map;
28
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
27
+import org.openzen.zenscript.javashared.JavaBaseCompiler;
29 28
 import org.openzen.zenscript.javashared.JavaClass;
29
+import org.openzen.zenscript.javashared.JavaContext;
30 30
 import org.openzen.zenscript.javashared.JavaMethod;
31 31
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionMemberVisitor;
32 32
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
@@ -34,7 +34,7 @@ import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
34 34
 /**
35 35
  * @author Hoofdgebruiker
36 36
  */
37
-public class JavaCompiler implements ZenCodeCompiler {
37
+public class JavaCompiler extends JavaBaseCompiler implements ZenCodeCompiler {
38 38
 	private final JavaModule target;
39 39
 	private final Map<String, JavaScriptFile> scriptBlocks = new HashMap<>();
40 40
 	private final JavaClassWriter scriptsClassWriter;
@@ -58,10 +58,19 @@ public class JavaCompiler implements ZenCodeCompiler {
58 58
 		scriptsClassWriter = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
59 59
 		scriptsClassWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "Scripts", null, "java/lang/Object", null);
60 60
 	}
61
+	
62
+	public JavaContext getContext() {
63
+		return context;
64
+	}
65
+	
66
+	@Override
67
+	public void addModule(SemanticModule module) {
68
+		context.addModule(module.module);
69
+	}
61 70
 
62 71
 	@Override
63 72
 	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
64
-		JavaPrepareDefinitionVisitor preparer = new JavaPrepareDefinitionVisitor(definition.position.getFilename(), null);
73
+		JavaPrepareDefinitionVisitor preparer = new JavaPrepareDefinitionVisitor(context, context.getJavaModule(module.module), definition.position.getFilename(), null);
65 74
 		definition.accept(preparer);
66 75
 		
67 76
 		definitions.add(definition);
@@ -116,7 +125,7 @@ public class JavaCompiler implements ZenCodeCompiler {
116 125
 		finished = true;
117 126
 		
118 127
 		for (HighLevelDefinition definition : definitions) {
119
-			JavaPrepareDefinitionMemberVisitor memberPreparer = new JavaPrepareDefinitionMemberVisitor(context);
128
+			JavaPrepareDefinitionMemberVisitor memberPreparer = new JavaPrepareDefinitionMemberVisitor(context, context.getJavaModule(definition.module));
120 129
 			definition.accept(memberPreparer);
121 130
 		}
122 131
 		
@@ -140,7 +149,7 @@ public class JavaCompiler implements ZenCodeCompiler {
140 149
 			JavaMethod method = JavaMethod.getStatic(new JavaClass(script.pkg.fullName, className, JavaClass.Kind.CLASS), methodName, "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
141 150
 			scriptFile.scriptMethods.add(method);
142 151
 
143
-			final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, new JavaWriter(visitor, method, null, null, null));
152
+			final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, context.getJavaModule(script.module), new JavaWriter(visitor, method, null, null, null));
144 153
 			statementVisitor.start();
145 154
 			for (Statement statement : script.statements) {
146 155
 				statement.accept(statementVisitor);

+ 6
- 5
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java Parādīt failu

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.type.TypeID;
13 13
 import org.openzen.zenscript.javashared.JavaParameterInfo;
14 14
 
15 15
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
16
+import org.openzen.zenscript.javashared.JavaCompiledModule;
16 17
 
17 18
 public class CompilerUtils {
18 19
 	private CompilerUtils() {}
@@ -39,24 +40,24 @@ public class CompilerUtils {
39 40
 		return out;
40 41
 	}
41 42
 
42
-    public static void tagMethodParameters(JavaBytecodeContext context, FunctionHeader header, boolean isStatic) {
43
+    public static void tagMethodParameters(JavaBytecodeContext context, JavaCompiledModule module, FunctionHeader header, boolean isStatic) {
43 44
         for (int i = 0; i < header.parameters.length; i++) {
44 45
             FunctionParameter parameter = header.parameters[i];
45 46
             String parameterType = context.getDescriptor(parameter.type);
46
-            parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isStatic ? i : i + 1, parameterType));
47
+            module.setParameterInfo(parameter, new JavaParameterInfo(isStatic ? i : i + 1, parameterType));
47 48
         }
48 49
     }
49 50
 
50
-    public static void tagConstructorParameters(JavaBytecodeContext context, FunctionHeader header, boolean isEnum) {
51
+    public static void tagConstructorParameters(JavaBytecodeContext context, JavaCompiledModule module, FunctionHeader header, boolean isEnum) {
51 52
         for (int i = 0; i < header.parameters.length; i++) {
52 53
             FunctionParameter parameter = header.parameters[i];
53 54
             String parameterType = context.getDescriptor(parameter.type);
54
-            parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isEnum ? i + 3 : i + 1, parameterType));
55
+			module.setParameterInfo(parameter, new JavaParameterInfo(isEnum ? i + 3 : i + 1, parameterType));
55 56
         }
56 57
     }
57 58
 
58 59
     public static void writeDefaultFieldInitializers(JavaBytecodeContext context, JavaWriter constructorWriter, HighLevelDefinition definition, boolean staticFields) {
59
-        JavaExpressionVisitor expressionVisitor = new JavaExpressionVisitor(context, constructorWriter);
60
+        JavaExpressionVisitor expressionVisitor = new JavaExpressionVisitor(context, context.getJavaModule(definition.module), constructorWriter);
60 61
         for (final IDefinitionMember definitionMember : definition.members) {
61 62
             if (!(definitionMember instanceof FieldMember))
62 63
                 continue;

+ 35
- 61
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Parādīt failu

@@ -11,7 +11,6 @@ import org.objectweb.asm.Type;
11 11
 import org.openzen.zenscript.codemodel.CompareType;
12 12
 import org.openzen.zenscript.codemodel.expression.*;
13 13
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
14
-import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
15 14
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
16 15
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
17 16
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
@@ -26,6 +25,7 @@ import org.openzen.zenscript.codemodel.type.storage.BorrowStorageTag;
26 25
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
27 26
 import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
28 27
 import org.openzen.zenscript.javashared.JavaClass;
28
+import org.openzen.zenscript.javashared.JavaCompiledModule;
29 29
 import org.openzen.zenscript.javashared.JavaField;
30 30
 import org.openzen.zenscript.javashared.JavaMethod;
31 31
 import org.openzen.zenscript.javashared.JavaTypeUtils;
@@ -155,10 +155,12 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
155 155
 	protected final JavaWriter javaWriter;
156 156
 	private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
157 157
 	private final JavaBytecodeContext context;
158
+	private final JavaCompiledModule module;
158 159
 
159
-    public JavaExpressionVisitor(JavaBytecodeContext context, JavaWriter javaWriter) {
160
+    public JavaExpressionVisitor(JavaBytecodeContext context, JavaCompiledModule module, JavaWriter javaWriter) {
160 161
         this.javaWriter = javaWriter;
161 162
 		this.context = context;
163
+		this.module = module;
162 164
     }
163 165
 
164 166
     @Override
@@ -1427,9 +1429,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1427 1429
 	public Void visitConst(ConstExpression expression) {
1428 1430
 		BuiltinID builtin = expression.constant.member.builtin;
1429 1431
 		if (builtin == null) {
1430
-			if (!checkAndGetFieldInfo(expression.constant, true))
1431
-				throw new IllegalStateException("Call target has no field info!");
1432
-
1432
+			javaWriter.getStaticField(context.getJavaField(expression.constant));
1433 1433
 			return null;
1434 1434
 		}
1435 1435
 
@@ -1511,7 +1511,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1511 1511
 				break;
1512 1512
 			case ENUM_VALUES: {
1513 1513
 				DefinitionTypeID type = (DefinitionTypeID) expression.type.type;
1514
-				JavaClass cls = type.definition.getTag(JavaClass.class);
1514
+				JavaClass cls = context.getJavaClass(type.definition);
1515 1515
 				javaWriter.invokeStatic(JavaMethod.getNativeStatic(cls, "values", "()[L" + cls.internalName + ";"));
1516 1516
 				break;
1517 1517
 			}
@@ -1651,12 +1651,12 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1651 1651
 
1652 1652
 	@Override
1653 1653
 	public Void visitFunction(FunctionExpression expression) {
1654
-		CompilerUtils.tagMethodParameters(context, expression.header, false);
1654
+		CompilerUtils.tagMethodParameters(context, module, expression.header, false);
1655 1655
 
1656
-        if (expression.header.parameters.length == 0 && expression.body instanceof ReturnStatement && expression.body.hasTag(MatchExpression.class) && expression.closure.captures.isEmpty()) {
1656
+        /*if (expression.header.parameters.length == 0 && expression.body instanceof ReturnStatement && expression.body.hasTag(MatchExpression.class) && expression.closure.captures.isEmpty()) {
1657 1657
             ((ReturnStatement) expression.body).value.accept(this);
1658 1658
             return null;
1659
-        }
1659
+        }*/
1660 1660
 		
1661 1661
 		final String descriptor = context.getMethodDescriptor(expression.header);
1662 1662
         final String signature = context.getMethodSignature(expression.header);
@@ -1702,7 +1702,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1702 1702
         functionWriter.start();
1703 1703
 
1704 1704
 
1705
-		final JavaStatementVisitor CSV = new JavaStatementVisitor(context, new JavaExpressionVisitor(context, functionWriter) {
1705
+		final JavaStatementVisitor CSV = new JavaStatementVisitor(context, new JavaExpressionVisitor(context, module, functionWriter) {
1706 1706
 			@Override
1707 1707
 			public Void visitGetLocalVariable(GetLocalVariableExpression varExpression) {
1708 1708
 				final int position = calculateMemberPosition(varExpression, expression);
@@ -1772,14 +1772,13 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1772 1772
 	@Override
1773 1773
 	public Void visitGetField(GetFieldExpression expression) {
1774 1774
 		expression.accept(this);
1775
-		if (!checkAndGetFieldInfo(expression.field, false))
1776
-			throw new IllegalStateException("Missing field info on a field member!");
1775
+		getField(expression.field);
1777 1776
 		return null;
1778 1777
 	}
1779 1778
 
1780 1779
 	@Override
1781 1780
 	public Void visitGetFunctionParameter(GetFunctionParameterExpression expression) {
1782
-		JavaParameterInfo parameter = expression.parameter.getTag(JavaParameterInfo.class);
1781
+		JavaParameterInfo parameter = module.getParameterInfo(expression.parameter);
1783 1782
 
1784 1783
 		if (parameter == null)
1785 1784
 			throw new RuntimeException(expression.position.toString() + ": Could not resolve lambda parameter" + expression.parameter);
@@ -1791,9 +1790,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1791 1790
 	@Override
1792 1791
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
1793 1792
 		final Label label = new Label();
1794
-		final JavaLocalVariableInfo tag = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
1795
-		if (tag == null)
1796
-			throw new RuntimeException("Missing tag @ " + expression.position);
1793
+		final JavaLocalVariableInfo tag = javaWriter.getLocalVariable(expression.variable.variable);
1797 1794
 		
1798 1795
 		tag.end = label;
1799 1796
 		javaWriter.load(tag.type, tag.local);
@@ -1805,7 +1802,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1805 1802
 	public Void visitGetMatchingVariantField(GetMatchingVariantField expression) {
1806 1803
 		javaWriter.loadObject(0);
1807 1804
 		final StoredType type = expression.value.option.getParameterType(expression.index);
1808
-		final JavaVariantOption tag = expression.value.option.getTag(JavaVariantOption.class);
1805
+		final JavaVariantOption tag = context.getJavaVariantOption(expression.value.option);
1809 1806
 		javaWriter.checkCast(tag.variantOptionClass.internalName);
1810 1807
 		javaWriter.getField(new JavaField(tag.variantOptionClass, "field" + expression.index, context.getDescriptor(type)));
1811 1808
 		return null;
@@ -1813,8 +1810,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1813 1810
 
1814 1811
 	@Override
1815 1812
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
1816
-		if (!checkAndGetFieldInfo(expression.field, true))
1817
-			throw new IllegalStateException("Missing field info on a field member!");
1813
+		javaWriter.getStaticField(context.getJavaField(expression.field));
1818 1814
 		return null;
1819 1815
 	}
1820 1816
 
@@ -1824,8 +1820,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1824 1820
 		
1825 1821
 		BuiltinID builtin = expression.getter.member.builtin;
1826 1822
 		if (builtin == null) {
1827
-			if (expression.getter.hasTag(JavaField.class)) {
1828
-				javaWriter.getField(expression.getter.getTag(JavaField.class));
1823
+			if (context.hasJavaField(expression.getter)) {
1824
+				javaWriter.getField(context.getJavaField(expression.getter));
1829 1825
 				return null;
1830 1826
 			}
1831 1827
 			if (!checkAndExecuteMethodInfo(expression.getter, expression.type))
@@ -2075,7 +2071,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2075 2071
 		for (MatchExpression.Case aCase : expression.cases) {
2076 2072
 			if (aCase.key instanceof VariantOptionSwitchValue) {
2077 2073
 				VariantOptionSwitchValue variantOptionSwitchValue = (VariantOptionSwitchValue) aCase.key;
2078
-				JavaVariantOption option = variantOptionSwitchValue.option.getTag(JavaVariantOption.class);
2074
+				JavaVariantOption option = context.getJavaVariantOption(variantOptionSwitchValue.option);
2079 2075
 				javaWriter.invokeVirtual(JavaMethod.getNativeVirtual(option.variantClass, "getDenominator", "()I"));
2080 2076
 				break;
2081 2077
 			}
@@ -2132,7 +2128,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2132 2128
     @Override
2133 2129
     public Void visitNew(NewExpression expression) {
2134 2130
 		// TODO: this code is incorrect!
2135
-		JavaMethod method = expression.constructor.getTag(JavaMethod.class);
2131
+		JavaMethod method = context.getJavaMethod(expression.constructor);
2136 2132
 
2137 2133
         final String type;
2138 2134
         if (expression.type.type instanceof DefinitionTypeID)
@@ -2244,15 +2240,14 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2244 2240
 	public Void visitSetField(SetFieldExpression expression) {
2245 2241
 		expression.target.accept(this);
2246 2242
 		expression.value.accept(this);
2247
-		if (!checkAndPutFieldInfo(expression.field, false))
2248
-			throw new IllegalStateException("Missing field info on a field member!");
2243
+		putField(expression.field);
2249 2244
 		return null;
2250 2245
 	}
2251 2246
 
2252 2247
     @Override
2253 2248
     public Void visitSetFunctionParameter(SetFunctionParameterExpression expression) {
2254 2249
         expression.value.accept(this);
2255
-        JavaParameterInfo parameter = expression.parameter.getTag(JavaParameterInfo.class);
2250
+        JavaParameterInfo parameter = module.getParameterInfo(expression.parameter);
2256 2251
         javaWriter.store(context.getType(expression.type), parameter.index);
2257 2252
         return null;
2258 2253
     }
@@ -2262,7 +2257,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2262 2257
 		expression.value.accept(this);
2263 2258
 		Label label = new Label();
2264 2259
 		javaWriter.label(label);
2265
-		final JavaLocalVariableInfo tag = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
2260
+		final JavaLocalVariableInfo tag = javaWriter.getLocalVariable(expression.variable.variable);
2266 2261
 		tag.end = label;
2267 2262
 
2268 2263
 		javaWriter.store(tag.type, tag.local);
@@ -2273,10 +2268,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2273 2268
 	@Override
2274 2269
 	public Void visitSetStaticField(SetStaticFieldExpression expression) {
2275 2270
 		expression.value.accept(this);
2276
-		
2277
-		if (!checkAndPutFieldInfo(expression.field, true))
2278
-			throw new IllegalStateException("Missing field info on a field member!");
2279
-		
2271
+		javaWriter.putStaticField(context.getJavaField(expression.field));
2280 2272
 		return null;
2281 2273
 	}
2282 2274
 
@@ -2289,8 +2281,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2289 2281
 	public Void visitStaticGetter(StaticGetterExpression expression) {
2290 2282
 		BuiltinID builtin = expression.getter.member.builtin;
2291 2283
 		if (builtin == null) {
2292
-			if (expression.getter.hasTag(JavaField.class)) {
2293
-				javaWriter.getStaticField(expression.getter.getTag(JavaField.class));
2284
+			if (context.hasJavaField(expression.getter)) {
2285
+				javaWriter.getStaticField(context.getJavaField(expression.getter));
2294 2286
 				return null;
2295 2287
 			}
2296 2288
 			
@@ -2369,7 +2361,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2369 2361
 				break;
2370 2362
 			case ENUM_VALUES: {
2371 2363
 				DefinitionTypeID type = (DefinitionTypeID) expression.type.type;
2372
-				JavaClass cls = type.definition.getTag(JavaClass.class);
2364
+				JavaClass cls = context.getJavaClass(type.definition);
2373 2365
 				javaWriter.invokeStatic(JavaMethod.getNativeStatic(cls, "values", "()[L" + cls.internalName + ";"));
2374 2366
 				break;
2375 2367
 			}
@@ -2441,7 +2433,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2441 2433
 
2442 2434
 	@Override
2443 2435
 	public Void visitVariantValue(VariantValueExpression expression) {
2444
-		JavaVariantOption tag = expression.option.getTag(JavaVariantOption.class);
2436
+		JavaVariantOption tag = context.getJavaVariantOption(expression.option);
2445 2437
 		final String internalName = tag.variantOptionClass.internalName;
2446 2438
 		javaWriter.newObject(internalName);
2447 2439
 		javaWriter.dup();
@@ -2475,7 +2467,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2475 2467
 
2476 2468
     //Will return true if a JavaMethodInfo.class tag exists, and will compile that tag
2477 2469
     private boolean checkAndExecuteMethodInfo(DefinitionMemberRef member, StoredType resultType) {
2478
-        JavaMethod methodInfo = member.getTag(JavaMethod.class);
2470
+        JavaMethod methodInfo = context.getJavaMethod(member);
2479 2471
         if (methodInfo == null)
2480 2472
             return false;
2481 2473
 
@@ -2491,39 +2483,21 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2491 2483
     }
2492 2484
 
2493 2485
     //Will return true if a JavaFieldInfo.class tag exists, and will compile that tag
2494
-    public boolean checkAndPutFieldInfo(FieldMemberRef field, boolean isStatic) {
2495
-		JavaField fieldInfo = field.getTag(JavaField.class);
2496
-        if (fieldInfo == null)
2497
-            return false;
2498
-        //TODO Remove isStatic
2499
-        if (field.isStatic() || isStatic) {
2486
+    public void putField(FieldMemberRef field) {
2487
+		JavaField fieldInfo = context.getJavaField(field);
2488
+        if (field.isStatic()) {
2500 2489
             getJavaWriter().putStaticField(fieldInfo);
2501 2490
         } else {
2502 2491
             getJavaWriter().putField(fieldInfo);
2503
-        }
2504
-        return true;
2492
+		}
2505 2493
     }
2506 2494
 
2507
-	public boolean checkAndGetFieldInfo(ConstMemberRef field, boolean isStatic) {
2508
-		final JavaField fieldInfo = field.getTag(JavaField.class);
2509
-		if (fieldInfo == null)
2510
-			return false;
2511
-
2512
-		getJavaWriter().getStaticField(fieldInfo);
2513
-		return true;
2514
-	}
2515
-
2516
-	public boolean checkAndGetFieldInfo(FieldMemberRef field, boolean isStatic) {
2517
-		final JavaField fieldInfo = field.getTag(JavaField.class);
2518
-		if (fieldInfo == null)
2519
-			return false;
2520
-
2521
-		//TODO Remove isStatic
2522
-		if (field.isStatic() || isStatic) {
2495
+	public void getField(FieldMemberRef field) {
2496
+		final JavaField fieldInfo = context.getJavaField(field);
2497
+		if (field.isStatic()) {
2523 2498
 			getJavaWriter().getStaticField(fieldInfo);
2524 2499
 		} else {
2525 2500
 			getJavaWriter().getField(fieldInfo);
2526 2501
 		}
2527
-		return true;
2528 2502
 	}
2529 2503
 }

+ 4
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java Parādīt failu

@@ -29,7 +29,7 @@ public class JavaForeachWriter {
29 29
 		javaWriter.swap();
30 30
 		javaWriter.getField("zsynthetic/IntRange", "from", "I");
31 31
 
32
-		final int z = variables[0].variable.getTag(JavaLocalVariableInfo.class).local;
32
+		final int z = javaWriter.getLocalVariable(variables[0].variable).local;
33 33
 		javaWriter.storeInt(z);
34 34
 		javaWriter.label(startLabel);
35 35
 		javaWriter.dup();
@@ -41,17 +41,17 @@ public class JavaForeachWriter {
41 41
 	}
42 42
 
43 43
 	public void visitArrayValueIterator() {
44
-		handleArray(javaWriter.local(int.class), variables[0].variable.getTag(JavaLocalVariableInfo.class));
44
+		handleArray(javaWriter.local(int.class), javaWriter.getLocalVariable(variables[0].variable));
45 45
 	}
46 46
 
47 47
 	public void visitArrayKeyValueIterator() {
48
-		handleArray(variables[0].variable.getTag(JavaLocalVariableInfo.class).local, variables[1].variable.getTag(JavaLocalVariableInfo.class));
48
+		handleArray(javaWriter.getLocalVariable(variables[0].variable).local, javaWriter.getLocalVariable(variables[1].variable));
49 49
 	}
50 50
 
51 51
 	public void visitStringCharacterIterator() {
52 52
 		//TODO UNTESTED!
53 53
 		javaWriter.invokeSpecial("java/lang/String", "toCharArray()", "()[C");
54
-		handleArray(javaWriter.local(int.class), variables[0].variable.getTag(JavaLocalVariableInfo.class));
54
+		handleArray(javaWriter.local(int.class), javaWriter.getLocalVariable(variables[0].variable));
55 55
 	}
56 56
 
57 57
 	private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {

+ 10
- 17
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java Parādīt failu

@@ -8,8 +8,7 @@ package org.openzen.zenscript.javabytecode.compiler;
8 8
 import org.objectweb.asm.Type;
9 9
 import org.openzen.zenscript.codemodel.expression.*;
10 10
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
11
-import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
12
-import org.openzen.zenscript.javashared.JavaParameterInfo;
11
+import org.openzen.zenscript.javashared.JavaCompiledModule;
13 12
 
14 13
 /**
15 14
  *
@@ -18,11 +17,13 @@ import org.openzen.zenscript.javashared.JavaParameterInfo;
18 17
 public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
19 18
 	private final JavaExpressionVisitor expressionCompiler;
20 19
 	private final JavaWriter javaWriter;
20
+	private final JavaCompiledModule module;
21 21
 	private final JavaBytecodeContext context;
22 22
 	
23
-	public JavaPreDecrementVisitor(JavaBytecodeContext context, JavaExpressionVisitor expressionCompiler) {
23
+	public JavaPreDecrementVisitor(JavaBytecodeContext context, JavaCompiledModule module, JavaExpressionVisitor expressionCompiler) {
24 24
 		this.expressionCompiler = expressionCompiler;
25 25
 		this.context = context;
26
+		this.module = module;
26 27
 		javaWriter = expressionCompiler.getJavaWriter();
27 28
 	}
28 29
 
@@ -200,28 +201,25 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
200 201
 		javaWriter.dup();
201 202
 		javaWriter.store(objectType, local);
202 203
 		
203
-        if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
204
-            throw new IllegalStateException("Missing field info on a field member!");
204
+        expressionCompiler.getField(expression.field);
205 205
 		
206 206
 		javaWriter.iConst1();
207 207
 		javaWriter.iSub();
208 208
 		
209 209
 		javaWriter.load(objectType, local);
210
-        if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
211
-            throw new IllegalStateException("Missing field info on a field member!");
212
-		
210
+        expressionCompiler.putField(expression.field);
213 211
 		return null;
214 212
 	}
215 213
 
216 214
 	@Override
217 215
 	public Void visitGetFunctionParameter(GetFunctionParameterExpression expression) {
218
-		javaWriter.idec(expression.parameter.getTag(JavaParameterInfo.class).index);
216
+		javaWriter.idec(module.getParameterInfo(expression.parameter).index);
219 217
 		return null;
220 218
 	}
221 219
 	
222 220
 	@Override
223 221
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
224
-		javaWriter.idec(expression.variable.variable.getTag(JavaLocalVariableInfo.class).local);
222
+		javaWriter.idec(javaWriter.getLocalVariable(expression.variable.variable).local);
225 223
 		return null;
226 224
 	}
227 225
 
@@ -232,15 +230,10 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
232 230
 
233 231
 	@Override
234 232
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
235
-		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
236
-            throw new IllegalStateException("Missing field info on a field member!");
237
-		
233
+		expressionCompiler.getField(expression.field);
238 234
 		javaWriter.iConst1();
239 235
 		javaWriter.iAdd();
240
-		
241
-		if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
242
-            throw new IllegalStateException("Missing field info on a field member!");
243
-		
236
+		expressionCompiler.putField(expression.field);
244 237
 		return null;
245 238
 	}
246 239
 

+ 10
- 15
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java Parādīt failu

@@ -9,6 +9,7 @@ import org.objectweb.asm.Type;
9 9
 import org.openzen.zenscript.codemodel.expression.*;
10 10
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
11 11
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
12
+import org.openzen.zenscript.javashared.JavaCompiledModule;
12 13
 import org.openzen.zenscript.javashared.JavaParameterInfo;
13 14
 
14 15
 /**
@@ -18,11 +19,13 @@ import org.openzen.zenscript.javashared.JavaParameterInfo;
18 19
 public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
19 20
 	private final JavaExpressionVisitor expressionCompiler;
20 21
 	private final JavaBytecodeContext context;
22
+	private final JavaCompiledModule module;
21 23
 	private final JavaWriter javaWriter;
22 24
 	
23
-	public JavaPreIncrementVisitor(JavaBytecodeContext context, JavaExpressionVisitor expressionCompiler) {
25
+	public JavaPreIncrementVisitor(JavaBytecodeContext context, JavaCompiledModule module, JavaExpressionVisitor expressionCompiler) {
24 26
 		this.expressionCompiler = expressionCompiler;
25 27
 		this.context = context;
28
+		this.module = module;
26 29
 		javaWriter = expressionCompiler.getJavaWriter();
27 30
 	}
28 31
 
@@ -200,23 +203,20 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
200 203
 		javaWriter.dup();
201 204
 		javaWriter.store(objectType, local);
202 205
 		
203
-        if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
204
-            throw new IllegalStateException("Missing field info on a field member!");
206
+        expressionCompiler.getField(expression.field);
205 207
 		
206 208
 		javaWriter.iConst1();
207 209
 		javaWriter.iAdd();
208 210
 		
209 211
 		javaWriter.load(objectType, local);
210 212
 		javaWriter.dupX1();
211
-        if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
212
-            throw new IllegalStateException("Missing field info on a field member!");
213
-		
213
+        expressionCompiler.putField(expression.field);
214 214
 		return null;
215 215
 	}
216 216
 
217 217
 	@Override
218 218
 	public Void visitGetFunctionParameter(GetFunctionParameterExpression expression) {
219
-		JavaParameterInfo parameter = expression.parameter.getTag(JavaParameterInfo.class);
219
+		JavaParameterInfo parameter = module.getParameterInfo(expression.parameter);
220 220
 		javaWriter.iinc(parameter.index);
221 221
 		javaWriter.load(parameter);
222 222
 		return null;
@@ -224,7 +224,7 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
224 224
 
225 225
 	@Override
226 226
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
227
-		JavaLocalVariableInfo localVariable = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
227
+		JavaLocalVariableInfo localVariable = javaWriter.getLocalVariable(expression.variable.variable);
228 228
 		javaWriter.iinc(localVariable.local);
229 229
 		javaWriter.load(localVariable);
230 230
 		return null;
@@ -237,16 +237,11 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
237 237
 
238 238
 	@Override
239 239
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
240
-		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
241
-            throw new IllegalStateException("Missing field info on a field member!");
242
-		
240
+		expressionCompiler.getField(expression.field);
243 241
 		javaWriter.iConst1();
244 242
 		javaWriter.iAdd();
245 243
 		javaWriter.dup();
246
-		
247
-		if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
248
-            throw new IllegalStateException("Missing field info on a field member!");
249
-		
244
+		expressionCompiler.putField(expression.field);
250 245
 		return null;
251 246
 	}
252 247
 

+ 5
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java Parādīt failu

@@ -9,6 +9,7 @@ import java.util.Arrays;
9 9
 import java.util.List;
10 10
 import org.openzen.zenscript.codemodel.type.StringTypeID;
11 11
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
12
+import org.openzen.zenscript.javashared.JavaCompiledModule;
12 13
 
13 14
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
14 15
     private final JavaWriter javaWriter;
@@ -18,10 +19,10 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
18 19
     /**
19 20
      * @param javaWriter the method writer that compiles the statement
20 21
      */
21
-    public JavaStatementVisitor(JavaBytecodeContext context, JavaWriter javaWriter) {
22
+    public JavaStatementVisitor(JavaBytecodeContext context, JavaCompiledModule module, JavaWriter javaWriter) {
22 23
         this.javaWriter = javaWriter;
23 24
 		this.context = context;
24
-        this.expressionVisitor = new JavaExpressionVisitor(context, javaWriter);
25
+        this.expressionVisitor = new JavaExpressionVisitor(context, module, javaWriter);
25 26
     }
26 27
 
27 28
     public JavaStatementVisitor(JavaBytecodeContext context, JavaExpressionVisitor expressionVisitor) {
@@ -103,7 +104,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
103 104
             final Label variableStart = new Label();
104 105
             final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, javaWriter.local(type), variableStart, variable.name);
105 106
             info.end = end;
106
-            variable.variable.setTag(JavaLocalVariableInfo.class, info);
107
+			javaWriter.setLocalVariable(variable.variable, info);
107 108
             javaWriter.addVariableInfo(info);
108 109
         }
109 110
 
@@ -311,7 +312,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
311 312
 		final Label variableStart = new Label();
312 313
 		javaWriter.label(variableStart);
313 314
 		final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, local, variableStart, statement.name);
314
-		statement.variable.setTag(JavaLocalVariableInfo.class, info);
315
+		javaWriter.setLocalVariable(statement.variable, info);
315 316
 		javaWriter.addVariableInfo(info);
316 317
 		return false;
317 318
 	}

+ 16
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java Parādīt failu

@@ -10,6 +10,8 @@ import static org.objectweb.asm.Opcodes.*;
10 10
 import org.objectweb.asm.commons.LocalVariablesSorter;
11 11
 import org.openzen.zencode.shared.CodePosition;
12 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.statement.VarStatement;
14
+import org.openzen.zenscript.codemodel.statement.VariableID;
13 15
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
14 16
 import org.openzen.zenscript.javashared.JavaParameterInfo;
15 17
 import org.openzen.zenscript.javashared.JavaClass;
@@ -32,7 +34,8 @@ public class JavaWriter {
32 34
     private boolean nameVariables = true;
33 35
     private int labelIndex = 1;
34 36
     private Map<Label, String> labelNames = new HashMap<>();
35
-
37
+	private final Map<VariableID, JavaLocalVariableInfo> localVariables = new HashMap<>();
38
+	
36 39
     public JavaWriter(
37 40
             ClassVisitor visitor,
38 41
             boolean nameVariables,
@@ -58,6 +61,18 @@ public class JavaWriter {
58 61
     public JavaWriter(ClassVisitor visitor, JavaMethod method, HighLevelDefinition forDefinition, String signature, String[] exceptions, String... annotations) {
59 62
         this(visitor, true, method, forDefinition, signature, exceptions, annotations);
60 63
     }
64
+	
65
+	public void setLocalVariable(VariableID variable, JavaLocalVariableInfo info) {
66
+		localVariables.put(variable, info);
67
+	}
68
+	
69
+	public JavaLocalVariableInfo getLocalVariable(VariableID variable) {
70
+		JavaLocalVariableInfo result = localVariables.get(variable);
71
+		if (result == null)
72
+			throw new IllegalStateException("Local variable unknown");
73
+		
74
+		return result;
75
+	}
61 76
 
62 77
     public void enableDebug() {
63 78
         debug = true;

+ 8
- 9
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java Parādīt failu

@@ -45,7 +45,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
45 45
 	public byte[] visitClass(ClassDefinition definition) {
46 46
         final String superTypeInternalName = definition.getSuperType() == null ? "java/lang/Object" : context.getInternalName(definition.getSuperType());
47 47
 
48
-		JavaClass toClass = definition.getTag(JavaClass.class);
48
+		JavaClass toClass = context.getJavaClass(definition);
49 49
 		JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
50 50
 
51 51
         //TODO: Calculate signature from generic parameters
@@ -68,7 +68,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
68 68
 
69 69
 	@Override
70 70
 	public byte[] visitInterface(InterfaceDefinition definition) {
71
-		JavaClass toClass = definition.getTag(JavaClass.class);
71
+		JavaClass toClass = context.getJavaClass(definition);
72 72
 		ClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
73 73
 
74 74
 		//TODO: Calculate signature from generic parameters
@@ -95,7 +95,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
95 95
 
96 96
 		ClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
97 97
 
98
-		JavaClass toClass = definition.getTag(JavaClass.class);
98
+		JavaClass toClass = context.getJavaClass(definition);
99 99
 		writer.visit(Opcodes.V1_8, Opcodes.ACC_ENUM | Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL, toClass.internalName, "Ljava/lang/Enum<L" + toClass.internalName + ";>;", superTypeInternalName, null);
100 100
 
101 101
 		//Enum Stuff(required!)
@@ -136,14 +136,13 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
136 136
 
137 137
 	@Override
138 138
 	public byte[] visitFunction(FunctionDefinition definition) {
139
-		CompilerUtils.tagMethodParameters(context, definition.header, true);
139
+		CompilerUtils.tagMethodParameters(context, context.getJavaModule(definition.module), definition.header, true);
140 140
 
141 141
         final String signature = context.getMethodSignature(definition.header);
142
-
143
-		final JavaMethod method = definition.caller.getTag(JavaMethod.class);
142
+		final JavaMethod method = context.getJavaMethod(definition.caller);
144 143
 
145 144
 		final JavaWriter writer = new JavaWriter(outerWriter, true, method, definition, signature, null);
146
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, writer);
145
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, context.getJavaModule(definition.module), writer);
147 146
         statementVisitor.start();
148 147
 		boolean returns = definition.caller.body.accept(statementVisitor);
149 148
 		if (!returns) {
@@ -171,7 +170,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
171 170
 
172 171
 	@Override
173 172
 	public byte[] visitVariant(VariantDefinition variant) {
174
-		final JavaClass toClass = variant.getTag(JavaClass.class);
173
+		final JavaClass toClass = context.getJavaClass(variant);
175 174
 		final JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
176 175
 
177 176
 		final String variantName = variant.name;
@@ -188,7 +187,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
188 187
 		final List<VariantDefinition.Option> options = variant.options;
189 188
 		//Each option is one of the possible child classes
190 189
 		for (final VariantDefinition.Option option : options) {
191
-			JavaVariantOption optionTag = option.getTag(JavaVariantOption.class);
190
+			JavaVariantOption optionTag = context.getJavaVariantOption(option);
192 191
 			final JavaClassWriter optionWriter = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
193 192
 			final String optionClassName = variantName + "$" + option.name;
194 193
 			JavaClassWriter.registerSuperClass(optionClassName, variantName);

+ 15
- 13
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java Parādīt failu

@@ -10,12 +10,12 @@ import org.openzen.zenscript.codemodel.Modifiers;
10 10
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.member.*;
13
-import org.openzen.zenscript.javashared.JavaParameterInfo;
14 13
 import org.openzen.zenscript.javabytecode.compiler.*;
15 14
 
16 15
 import java.util.List;
17 16
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
18 17
 import org.openzen.zenscript.javashared.JavaClass;
18
+import org.openzen.zenscript.javashared.JavaCompiledModule;
19 19
 import org.openzen.zenscript.javashared.JavaField;
20 20
 import org.openzen.zenscript.javashared.JavaMethod;
21 21
 
@@ -26,29 +26,31 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
26 26
     private final HighLevelDefinition definition;
27 27
     private final JavaStatementVisitor clinitStatementVisitor;
28 28
     private EnumDefinition enumDefinition = null;
29
+	private final JavaCompiledModule javaModule;
29 30
 
30 31
     public JavaMemberVisitor(JavaBytecodeContext context, ClassWriter writer, JavaClass toClass, HighLevelDefinition definition) {
31 32
         this.writer = writer;
32 33
         this.toClass = toClass;
33 34
         this.definition = definition;
34 35
 		this.context = context;
36
+		javaModule = context.getJavaModule(definition.module);
35 37
 
36 38
         final JavaWriter javaWriter = new JavaWriter(writer, new JavaMethod(toClass, JavaMethod.Kind.STATICINIT, "<clinit>", true, "()V", 0, false), definition, null, null);
37
-        this.clinitStatementVisitor = new JavaStatementVisitor(context, javaWriter);
39
+        this.clinitStatementVisitor = new JavaStatementVisitor(context, javaModule, javaWriter);
38 40
         this.clinitStatementVisitor.start();
39 41
         CompilerUtils.writeDefaultFieldInitializers(context, javaWriter, definition, true);
40 42
     }
41 43
 
42 44
 	@Override
43 45
 	public Void visitConst(ConstMember member) {
44
-		JavaField field = member.getTag(JavaField.class);
46
+		JavaField field = context.getJavaField(member);
45 47
         writer.visitField(CompilerUtils.calcAccess(member.getEffectiveModifiers()), field.name, field.descriptor, field.signature, null).visitEnd();
46 48
         return null;
47 49
 	}
48 50
 
49 51
 	@Override
50 52
 	public Void visitField(FieldMember member) {
51
-		JavaField field = member.getTag(JavaField.class);
53
+		JavaField field = context.getJavaField(member);
52 54
         writer.visitField(CompilerUtils.calcAccess(member.getEffectiveModifiers()), field.name, field.descriptor, field.signature, null).visitEnd();
53 55
         return null;
54 56
     }
@@ -56,23 +58,23 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
56 58
     @Override
57 59
     public Void visitConstructor(ConstructorMember member) {
58 60
         final boolean isEnum = definition instanceof EnumDefinition;
59
-        final JavaMethod method = member.getTag(JavaMethod.class);
61
+        final JavaMethod method = context.getJavaMethod(member);
60 62
 
61 63
         final Label constructorStart = new Label();
62 64
         final Label constructorEnd = new Label();
63 65
         final JavaWriter constructorWriter = new JavaWriter(writer, method, definition, context.getMethodSignature(member.header), null);
64 66
         constructorWriter.label(constructorStart);
65
-        CompilerUtils.tagConstructorParameters(context, member.header, isEnum);
67
+        CompilerUtils.tagConstructorParameters(context, javaModule, member.header, isEnum);
66 68
         for (FunctionParameter parameter : member.header.parameters) {
67 69
             constructorWriter.nameVariable(
68
-                    parameter.getTag(JavaParameterInfo.class).index,
70
+                    javaModule.getParameterInfo(parameter).index,
69 71
                     parameter.name,
70 72
                     constructorStart,
71 73
                     constructorEnd,
72 74
                     context.getType(parameter.type));
73 75
         }
74 76
 
75
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, constructorWriter);
77
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, javaModule, constructorWriter);
76 78
         statementVisitor.start();
77 79
 
78 80
 		if (!member.isConstructorForwarded()) {
@@ -106,7 +108,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
106 108
 		final JavaWriter destructorWriter = new JavaWriter(writer, method, definition, null, null);
107 109
 		destructorWriter.label(constructorStart);
108 110
 
109
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, destructorWriter);
111
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, javaModule, destructorWriter);
110 112
         statementVisitor.start();
111 113
 		// TODO: destruction of members (to be done when memory tags are implemented)
112 114
 		member.body.accept(statementVisitor);
@@ -117,10 +119,10 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
117 119
 
118 120
     @Override
119 121
     public Void visitMethod(MethodMember member) {
120
-        CompilerUtils.tagMethodParameters(context, member.header, member.isStatic());
122
+        CompilerUtils.tagMethodParameters(context, javaModule, member.header, member.isStatic());
121 123
 
122 124
         final boolean isAbstract = member.body == null || Modifiers.isAbstract(member.getEffectiveModifiers());
123
-        final JavaMethod method = member.getTag(JavaMethod.class);
125
+        final JavaMethod method = context.getJavaMethod(member);
124 126
 
125 127
 		final Label methodStart = new Label();
126 128
 		final Label methodEnd = new Label();
@@ -129,10 +131,10 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
129 131
 		for (final FunctionParameter parameter : member.header.parameters) {
130 132
 			methodWriter.nameParameter(0, parameter.name);
131 133
 			if (!isAbstract)
132
-				methodWriter.nameVariable(parameter.getTag(JavaParameterInfo.class).index, parameter.name, methodStart, methodEnd, context.getType(parameter.type));
134
+				methodWriter.nameVariable(javaModule.getParameterInfo(parameter).index, parameter.name, methodStart, methodEnd, context.getType(parameter.type));
133 135
 		}
134 136
 
135
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, methodWriter);
137
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, javaModule, methodWriter);
136 138
 
137 139
 		if (!isAbstract) {
138 140
 			statementVisitor.start();

+ 1
- 0
JavaShared/build.gradle Parādīt failu

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

+ 17
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaBaseCompiler.java Parādīt failu

@@ -0,0 +1,17 @@
1
+package org.openzen.zenscript.javashared;
2
+
3
+import org.openzen.zenscript.compiler.ZenCodeCompiler;
4
+
5
+/*
6
+ * To change this license header, choose License Headers in Project Properties.
7
+ * To change this template file, choose Tools | Templates
8
+ * and open the template in the editor.
9
+ */
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public abstract class JavaBaseCompiler implements ZenCodeCompiler {
16
+	
17
+}

+ 4
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java Parādīt failu

@@ -134,6 +134,10 @@ public class JavaClass implements Comparable<JavaClass> {
134 134
 		return kind == Kind.ENUM;
135 135
 	}
136 136
 	
137
+	public boolean isInterface() {
138
+		return kind == Kind.INTERFACE;
139
+	}
140
+	
137 141
 	public enum Kind {
138 142
 		CLASS,
139 143
 		INTERFACE,

+ 132
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompiledModule.java Parādīt failu

@@ -0,0 +1,132 @@
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.FunctionParameter;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.Module;
13
+import org.openzen.zenscript.codemodel.definition.VariantDefinition;
14
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
15
+import org.openzen.zenscript.codemodel.member.ImplementationMember;
16
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
17
+
18
+/**
19
+ *
20
+ * @author Hoofdgebruiker
21
+ */
22
+public class JavaCompiledModule {
23
+	public final Module module;
24
+	
25
+	private final Map<HighLevelDefinition, JavaClass> classes = new HashMap<>();
26
+	private final Map<HighLevelDefinition, JavaNativeClass> nativeClasses = new HashMap<>();
27
+	private final Map<ImplementationMember, JavaImplementation> implementations = new HashMap<>();
28
+	private final Map<IDefinitionMember, JavaField> fields = new HashMap<>();
29
+	private final Map<IDefinitionMember, JavaMethod> methods = new HashMap<>();
30
+	private final Map<FunctionParameter, JavaParameterInfo> parameters = new HashMap<>();
31
+	private final Map<VariantDefinition.Option, JavaVariantOption> variantOptions = new HashMap<>();
32
+	
33
+	public JavaCompiledModule(Module module) {
34
+		this.module = module;
35
+	}
36
+	
37
+	public void setClassInfo(HighLevelDefinition definition, JavaClass cls) {
38
+		classes.put(definition, cls);
39
+	}
40
+	
41
+	public JavaClass getClassInfo(HighLevelDefinition definition) {
42
+		JavaClass cls = classes.get(definition);
43
+		if (cls == null)
44
+			throw new IllegalStateException("Missing class info for class " + definition.name);
45
+		
46
+		return cls;
47
+	}
48
+	
49
+	public JavaClass optClassInfo(HighLevelDefinition definition) {
50
+		return classes.get(definition);
51
+	}
52
+	
53
+	public boolean hasClassInfo(HighLevelDefinition definition) {
54
+		return classes.containsKey(definition);
55
+	}
56
+	
57
+	public void setNativeClassInfo(HighLevelDefinition definition, JavaNativeClass cls) {
58
+		nativeClasses.put(definition, cls);
59
+	}
60
+	
61
+	public JavaNativeClass getNativeClassInfo(HighLevelDefinition definition) {
62
+		return nativeClasses.get(definition);
63
+	}
64
+	
65
+	public void setVariantOption(VariantDefinition.Option option, JavaVariantOption value) {
66
+		variantOptions.put(option, value);
67
+	}
68
+	
69
+	public JavaVariantOption getVariantOption(VariantDefinition.Option option) {
70
+		JavaVariantOption result = variantOptions.get(option);
71
+		if (result == null)
72
+			throw new IllegalStateException("Variant option unknown: " + option.name);
73
+		
74
+		return result;
75
+	}
76
+	
77
+	public void setImplementationInfo(ImplementationMember member, JavaImplementation implementation) {
78
+		implementations.put(member, implementation);
79
+	}
80
+	
81
+	public JavaImplementation getImplementationInfo(ImplementationMember member) {
82
+		JavaImplementation implementation = implementations.get(member);
83
+		if (implementation == null)
84
+			throw new IllegalStateException("Implementation unknown: " + member.type);
85
+		
86
+		return implementation;
87
+	}
88
+	
89
+	public void setFieldInfo(IDefinitionMember member, JavaField field) {
90
+		fields.put(member, field);
91
+	}
92
+	
93
+	public JavaField optFieldInfo(IDefinitionMember member) {
94
+		return fields.get(member);
95
+	}
96
+	
97
+	public JavaField getFieldInfo(IDefinitionMember member) {
98
+		JavaField field = fields.get(member);
99
+		if (field == null)
100
+			throw new IllegalStateException("Missing field info for field " + member.getDefinition().name + "." + member.describe());
101
+		
102
+		return field;
103
+	}
104
+	
105
+	public void setMethodInfo(IDefinitionMember member, JavaMethod method) {
106
+		methods.put(member, method);
107
+	}
108
+	
109
+	public JavaMethod getMethodInfo(DefinitionMemberRef member) {
110
+		return getMethodInfo(member.getTarget());
111
+	}
112
+	
113
+	public JavaMethod getMethodInfo(IDefinitionMember member) {
114
+		JavaMethod method = methods.get(member);
115
+		if (method == null)
116
+			throw new IllegalStateException("Missing field info for field " + member.getDefinition().name + "." + member.describe());
117
+		
118
+		return method;
119
+	}
120
+	
121
+	public void setParameterInfo(FunctionParameter parameter, JavaParameterInfo info) {
122
+		parameters.put(parameter, info);
123
+	}
124
+	
125
+	public JavaParameterInfo getParameterInfo(FunctionParameter parameter) {
126
+		JavaParameterInfo info = parameters.get(parameter);
127
+		if (info == null)
128
+			throw new IllegalStateException("Missing parameter info for parameter " + parameter.name);
129
+		
130
+		return info;
131
+	}
132
+}

+ 77
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java Parādīt failu

@@ -12,7 +12,13 @@ import java.util.Map;
12 12
 import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
14 14
 import org.openzen.zenscript.codemodel.FunctionParameter;
15
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
16
+import org.openzen.zenscript.codemodel.Module;
17
+import org.openzen.zenscript.codemodel.definition.VariantDefinition;
15 18
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
19
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20
+import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
21
+import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
16 22
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
17 23
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
18 24
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
@@ -32,6 +38,8 @@ public abstract class JavaContext {
32 38
 	private final Map<String, JavaSynthesizedRange> ranges = new HashMap<>();
33 39
 	private boolean useShared = false;
34 40
 	
41
+	private final Map<Module, JavaCompiledModule> modules = new HashMap<>();
42
+	
35 43
 	public JavaContext(GlobalTypeRegistry registry) {
36 44
 		this.registry = registry;
37 45
 		
@@ -73,11 +81,79 @@ public abstract class JavaContext {
73 81
 	}
74 82
 	
75 83
 	protected abstract JavaSyntheticClassGenerator getTypeGenerator();
76
-			
84
+		
77 85
 	public abstract String getDescriptor(TypeID type);
78 86
 	
79 87
 	public abstract String getDescriptor(StoredType type);
80 88
 	
89
+	public void addModule(Module module) {
90
+		modules.put(module, new JavaCompiledModule(module));
91
+	}
92
+	
93
+	public JavaCompiledModule getJavaModule(Module module) {
94
+		JavaCompiledModule javaModule = modules.get(module);
95
+		if (javaModule == null)
96
+			throw new IllegalStateException("Module not yet registered: " + module.name);
97
+		
98
+		return javaModule;
99
+	}
100
+	
101
+	public JavaClass getJavaClass(HighLevelDefinition definition) {
102
+		return getJavaModule(definition.module).getClassInfo(definition);
103
+	}
104
+	
105
+	public JavaClass optJavaClass(HighLevelDefinition definition) {
106
+		return getJavaModule(definition.module).optClassInfo(definition);
107
+	}
108
+	
109
+	public JavaNativeClass getJavaNativeClass(HighLevelDefinition definition) {
110
+		return getJavaModule(definition.module).getNativeClassInfo(definition);
111
+	}
112
+	
113
+	public boolean hasJavaClass(HighLevelDefinition definition) {
114
+		return getJavaModule(definition.module).hasClassInfo(definition);
115
+	}
116
+	
117
+	public void setJavaClass(HighLevelDefinition definition, JavaClass cls) {
118
+		getJavaModule(definition.module).setClassInfo(definition, cls);
119
+	}
120
+	
121
+	public void setJavaNativeClass(HighLevelDefinition definition, JavaNativeClass cls) {
122
+		getJavaModule(definition.module).setNativeClassInfo(definition, cls);
123
+	}
124
+	
125
+	public boolean hasJavaField(DefinitionMemberRef member) {
126
+		HighLevelDefinition definition = member.getTarget().getDefinition();
127
+		return getJavaModule(definition.module).optFieldInfo(member.getTarget()) != null;
128
+	}
129
+	
130
+	public JavaField getJavaField(IDefinitionMember member) {
131
+		HighLevelDefinition definition = member.getDefinition();
132
+		return getJavaModule(definition.module).getFieldInfo(member);
133
+	}
134
+	
135
+	public JavaField getJavaField(DefinitionMemberRef member) {
136
+		return getJavaField(member.getTarget());
137
+	}
138
+	
139
+	public JavaMethod getJavaMethod(IDefinitionMember member) {
140
+		HighLevelDefinition definition = member.getDefinition();
141
+		return getJavaModule(definition.module).getMethodInfo(member);
142
+	}
143
+	
144
+	public JavaMethod getJavaMethod(DefinitionMemberRef member) {
145
+		return getJavaMethod(member.getTarget());
146
+	}
147
+	
148
+	public JavaVariantOption getJavaVariantOption(VariantDefinition.Option option) {
149
+		HighLevelDefinition definition = option.variant;
150
+		return getJavaModule(definition.module).getVariantOption(option);
151
+	}
152
+	
153
+	public JavaVariantOption getJavaVariantOption(VariantOptionRef member) {
154
+		return getJavaVariantOption(member.getOption());
155
+	}
156
+	
81 157
 	public void useShared() {
82 158
 		if (useShared)
83 159
 			return;

+ 1
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java Parādīt failu

@@ -106,10 +106,7 @@ public class JavaTypeDescriptorVisitor implements TypeVisitor<String> {
106 106
 
107 107
     @Override
108 108
     public String visitDefinition(DefinitionTypeID definition) {
109
-		JavaClass cls = definition.definition.getTag(JavaClass.class);
110
-		if (cls == null)
111
-			throw new IllegalStateException("Class not yet initialized: " + definition.definition.name);
112
-		
109
+		JavaClass cls = context.getJavaClass(definition.definition);
113 110
 		return "L" + cls.internalName + ";";
114 111
     }
115 112
 

+ 1
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java Parādīt failu

@@ -88,7 +88,7 @@ public class JavaTypeInternalNameVisitor implements TypeVisitorWithContext<Store
88 88
 
89 89
     @Override
90 90
     public String visitDefinition(StoredType context, DefinitionTypeID definition) {
91
-		return definition.definition.getTag(JavaClass.class).internalName;
91
+		return this.context.getJavaClass(definition.definition).internalName;
92 92
     }
93 93
 
94 94
     @Override

+ 14
- 12
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java Parādīt failu

@@ -33,6 +33,7 @@ import org.openzen.zenscript.codemodel.type.GenericTypeID;
33 33
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
34 34
 import org.openzen.zenscript.javashared.JavaTypeNameVisitor;
35 35
 import org.openzen.zenscript.javashared.JavaClass;
36
+import org.openzen.zenscript.javashared.JavaCompiledModule;
36 37
 import org.openzen.zenscript.javashared.JavaField;
37 38
 import org.openzen.zenscript.javashared.JavaContext;
38 39
 import org.openzen.zenscript.javashared.JavaImplementation;
@@ -47,17 +48,20 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
47 48
 	private static final boolean DEBUG_EMPTY = true;
48 49
 	
49 50
 	private final JavaContext context;
51
+	private final JavaCompiledModule module;
50 52
 	private final JavaClass cls;
51 53
 	private final JavaNativeClass nativeClass;
52 54
 	private final JavaPrepareDefinitionMemberVisitor memberPreparer;
53 55
 	
54 56
 	public JavaPrepareClassMethodVisitor(
55 57
 			JavaContext context,
58
+			JavaCompiledModule module,
56 59
 			JavaClass cls,
57 60
 			JavaNativeClass nativeClass,
58 61
 			JavaPrepareDefinitionMemberVisitor memberPreparer,
59 62
 			boolean startsEmpty) {
60 63
 		this.context = context;
64
+		this.module = module;
61 65
 		this.cls = cls;
62 66
 		this.nativeClass = nativeClass;
63 67
 		this.memberPreparer = memberPreparer;
@@ -71,20 +75,21 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
71 75
 			System.out.println("Class " + cls.fullName + " not empty because of const " + member.name);
72 76
 		
73 77
 		cls.empty = false;
74
-		member.setTag(JavaField.class, new JavaField(cls, member.name, context.getDescriptor(member.type)));
78
+		module.setFieldInfo(member, new JavaField(cls, member.name, context.getDescriptor(member.type)));
75 79
 		return null;
76 80
 	}
77 81
 	
78 82
 	@Override
79 83
 	public Void visitField(FieldMember member) {
80 84
 		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.type));
81
-		member.setTag(JavaField.class, field);
85
+		module.setFieldInfo(member, field);
82 86
 		if (member.hasAutoGetter()) {
83 87
 			visitGetter(member.autoGetter);
84
-			member.autoGetter.setTag(JavaField.class, field);
88
+			module.setFieldInfo(member.autoGetter, field);
85 89
 		}
86 90
 		if (member.hasAutoSetter()) {
87 91
 			visitSetter(member.autoSetter);
92
+			module.setFieldInfo(member.autoSetter, field);
88 93
 		}
89 94
 		
90 95
 		return null;
@@ -152,7 +157,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
152 157
 		memberPreparer.prepare(member.type);
153 158
 		
154 159
 		if (canMergeImplementation(member)) {
155
-			member.setTag(JavaImplementation.class, new JavaImplementation(true, cls));
160
+			module.setImplementationInfo(member, new JavaImplementation(true, cls));
156 161
 			for (IDefinitionMember m : member.members)
157 162
 				m.accept(this);
158 163
 		} else {
@@ -162,9 +167,9 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
162 167
 			cls.empty = false;
163 168
 			
164 169
 			JavaClass implementationClass = new JavaClass(cls, JavaTypeNameVisitor.INSTANCE.process(member.type) + "Implementation", JavaClass.Kind.CLASS);
165
-			member.setTag(JavaImplementation.class, new JavaImplementation(false, implementationClass));
170
+			module.setImplementationInfo(member, new JavaImplementation(false, implementationClass));
166 171
 			
167
-			JavaPrepareClassMethodVisitor visitor = new JavaPrepareClassMethodVisitor(context, implementationClass, null, memberPreparer, true);
172
+			JavaPrepareClassMethodVisitor visitor = new JavaPrepareClassMethodVisitor(context, module, implementationClass, null, memberPreparer, true);
168 173
 			for (IDefinitionMember m : member.members)
169 174
 				m.accept(visitor);
170 175
 		}
@@ -177,7 +182,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
177 182
 
178 183
 	@Override
179 184
 	public Void visitInnerDefinition(InnerDefinitionMember member) {
180
-		JavaPrepareDefinitionMemberVisitor innerDefinitionPrepare = new JavaPrepareDefinitionMemberVisitor(context);
185
+		JavaPrepareDefinitionMemberVisitor innerDefinitionPrepare = new JavaPrepareDefinitionMemberVisitor(context, module);
181 186
 		member.innerDefinition.accept(innerDefinitionPrepare);
182 187
 		
183 188
 		if (DEBUG_EMPTY && cls.empty)
@@ -293,10 +298,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
293 298
 		
294 299
 		if (member.getOverrides() != null) {
295 300
 			DefinitionMemberRef base = member.getOverrides();
296
-			JavaMethod baseMethod = base.getTarget().getTag(JavaMethod.class);
297
-			if (baseMethod == null)
298
-				throw new IllegalStateException("Base method not yet prepared!");
299
-			
301
+			JavaMethod baseMethod = context.getJavaMethod(base.getTarget());
300 302
 			method = new JavaMethod(
301 303
 					cls,
302 304
 					baseMethod.kind,
@@ -323,6 +325,6 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
323 325
 			cls.empty = false;
324 326
 		}
325 327
 		
326
-		member.setTag(JavaMethod.class, method);
328
+		module.setMethodInfo(member, method);
327 329
 	}
328 330
 }

+ 22
- 19
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java Parādīt failu

@@ -20,6 +20,7 @@ import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20 20
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
21 21
 import org.openzen.zenscript.codemodel.type.TypeID;
22 22
 import org.openzen.zenscript.javashared.JavaClass;
23
+import org.openzen.zenscript.javashared.JavaCompiledModule;
23 24
 import org.openzen.zenscript.javashared.JavaContext;
24 25
 import org.openzen.zenscript.javashared.JavaMethod;
25 26
 import org.openzen.zenscript.javashared.JavaModifiers;
@@ -30,13 +31,15 @@ import org.openzen.zenscript.javashared.JavaModifiers;
30 31
  */
31 32
 public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<JavaClass> {
32 33
 	private final JavaContext context;
34
+	private final JavaCompiledModule module;
33 35
 	
34
-	public JavaPrepareDefinitionMemberVisitor(JavaContext context) {
36
+	public JavaPrepareDefinitionMemberVisitor(JavaContext context, JavaCompiledModule module) {
35 37
 		this.context = context;
38
+		this.module = module;
36 39
 	}
37 40
 	
38 41
 	private boolean isPrepared(HighLevelDefinition definition) {
39
-		return definition.getTag(JavaClass.class).membersPrepared;
42
+		return context.getJavaClass(definition).membersPrepared;
40 43
 	}
41 44
 	
42 45
 	public void prepare(TypeID type) {
@@ -51,7 +54,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
51 54
 	@Override
52 55
 	public JavaClass visitClass(ClassDefinition definition) {
53 56
 		if (isPrepared(definition))
54
-			return definition.getTag(JavaClass.class);
57
+			return context.getJavaClass(definition);
55 58
 		
56 59
 		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
57 60
 	}
@@ -59,7 +62,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
59 62
 	@Override
60 63
 	public JavaClass visitInterface(InterfaceDefinition definition) {
61 64
 		if (isPrepared(definition))
62
-			return definition.getTag(JavaClass.class);
65
+			return context.getJavaClass(definition);
63 66
 		
64 67
 		for (TypeID baseType : definition.baseInterfaces)
65 68
 			prepare(baseType);
@@ -70,7 +73,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
70 73
 	@Override
71 74
 	public JavaClass visitEnum(EnumDefinition definition) {
72 75
 		if (isPrepared(definition))
73
-			return definition.getTag(JavaClass.class);
76
+			return context.getJavaClass(definition);
74 77
 		
75 78
 		return visitClassCompiled(definition, false, JavaClass.Kind.ENUM);
76 79
 	}
@@ -78,7 +81,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
78 81
 	@Override
79 82
 	public JavaClass visitStruct(StructDefinition definition) {
80 83
 		if (isPrepared(definition))
81
-			return definition.getTag(JavaClass.class);
84
+			return context.getJavaClass(definition);
82 85
 		
83 86
 		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
84 87
 	}
@@ -86,21 +89,21 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
86 89
 	@Override
87 90
 	public JavaClass visitFunction(FunctionDefinition definition) {
88 91
 		if (isPrepared(definition))
89
-			return definition.getTag(JavaClass.class);
92
+			return context.getJavaClass(definition);
90 93
 		
91
-		JavaClass cls = definition.getTag(JavaClass.class);
94
+		JavaClass cls = context.getJavaClass(definition);
92 95
 		JavaMethod method = JavaMethod.getStatic(cls, definition.name, context.getMethodDescriptor(definition.header), JavaModifiers.getJavaModifiers(definition.modifiers));
93
-		definition.caller.setTag(JavaMethod.class, method);
96
+		module.setMethodInfo(definition.caller, method);
94 97
 		return cls;
95 98
 	}
96 99
 
97 100
 	@Override
98 101
 	public JavaClass visitExpansion(ExpansionDefinition definition) {
99 102
 		if (isPrepared(definition))
100
-			return definition.getTag(JavaClass.class);
103
+			return context.getJavaClass(definition);
101 104
 		
102
-		JavaNativeClass nativeClass = definition.getTag(JavaNativeClass.class);
103
-		JavaClass cls = definition.getTag(JavaClass.class);
105
+		JavaNativeClass nativeClass = context.getJavaNativeClass(definition);
106
+		JavaClass cls = context.getJavaClass(definition);
104 107
 		visitExpansionMembers(definition, cls, nativeClass);
105 108
 		return cls;
106 109
 	}
@@ -113,10 +116,10 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
113 116
 
114 117
 	@Override
115 118
 	public JavaClass visitVariant(VariantDefinition variant) {
116
-		if (isPrepared(variant))
117
-			return variant.getTag(JavaClass.class);
119
+		JavaClass cls = context.getJavaClass(variant);
120
+		if (cls.membersPrepared)
121
+			return cls;
118 122
 		
119
-		JavaClass cls = variant.getTag(JavaClass.class);
120 123
 		visitClassMembers(variant, cls, null, false);
121 124
 		return cls;
122 125
 	}
@@ -125,8 +128,8 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
125 128
 		if (definition.getSuperType() != null)
126 129
 			prepare(definition.getSuperType());
127 130
 		
128
-		JavaNativeClass nativeClass = definition.getTag(JavaNativeClass.class);
129
-		JavaClass cls = definition.getTag(JavaClass.class);
131
+		JavaNativeClass nativeClass = context.getJavaNativeClass(definition);
132
+		JavaClass cls = context.getJavaClass(definition);
130 133
 		if (nativeClass == null) {
131 134
 			visitClassMembers(definition, cls, null, startsEmpty);
132 135
 		} else {
@@ -137,7 +140,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
137 140
 	
138 141
 	private void visitClassMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass, boolean startsEmpty) {
139 142
 		System.out.println("Preparing " + cls.internalName);
140
-		JavaPrepareClassMethodVisitor methodVisitor = new JavaPrepareClassMethodVisitor(context, cls, nativeClass, this, startsEmpty);
143
+		JavaPrepareClassMethodVisitor methodVisitor = new JavaPrepareClassMethodVisitor(context, module, cls, nativeClass, this, startsEmpty);
141 144
 		for (IDefinitionMember member : definition.members) {
142 145
 			member.accept(methodVisitor);
143 146
 		}
@@ -146,7 +149,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
146 149
 	
147 150
 	private void visitExpansionMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass) {
148 151
 		System.out.println("Preparing " + cls.internalName);
149
-		JavaPrepareExpansionMethodVisitor methodVisitor = new JavaPrepareExpansionMethodVisitor(context, cls, nativeClass);
152
+		JavaPrepareExpansionMethodVisitor methodVisitor = new JavaPrepareExpansionMethodVisitor(context, module, cls, nativeClass);
150 153
 		for (IDefinitionMember member : definition.members) {
151 154
 			member.accept(methodVisitor);
152 155
 		}

+ 25
- 18
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java Parādīt failu

@@ -29,6 +29,8 @@ import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
29 29
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
30 30
 import org.openzen.zenscript.codemodel.type.TypeID;
31 31
 import org.openzen.zenscript.javashared.JavaClass;
32
+import org.openzen.zenscript.javashared.JavaCompiledModule;
33
+import org.openzen.zenscript.javashared.JavaContext;
32 34
 import org.openzen.zenscript.javashared.JavaMethod;
33 35
 import org.openzen.zenscript.javashared.JavaVariantOption;
34 36
 
@@ -227,16 +229,20 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
227 229
 		}
228 230
 	}
229 231
 	
232
+	private final JavaContext context;
230 233
 	private final String filename;
231 234
 	private final JavaClass outerClass;
235
+	private final JavaCompiledModule module;
232 236
 	
233
-	public JavaPrepareDefinitionVisitor(String filename, JavaClass outerClass) {
237
+	public JavaPrepareDefinitionVisitor(JavaContext context, JavaCompiledModule module, String filename, JavaClass outerClass) {
238
+		this.context = context;
234 239
 		this.filename = filename;
235 240
 		this.outerClass = outerClass;
241
+		this.module = module;
236 242
 	}
237 243
 	
238 244
 	private boolean isPrepared(HighLevelDefinition definition) {
239
-		return definition.hasTag(JavaClass.class);
245
+		return context.hasJavaClass(definition);
240 246
 	}
241 247
 	
242 248
 	public void prepare(TypeID type) {
@@ -250,7 +256,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
250 256
 	@Override
251 257
 	public JavaClass visitClass(ClassDefinition definition) {
252 258
 		if (isPrepared(definition))
253
-			return definition.getTag(JavaClass.class);
259
+			return context.getJavaClass(definition);
254 260
 		
255 261
 		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
256 262
 	}
@@ -258,7 +264,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
258 264
 	@Override
259 265
 	public JavaClass visitInterface(InterfaceDefinition definition) {
260 266
 		if (isPrepared(definition))
261
-			return definition.getTag(JavaClass.class);
267
+			return context.getJavaClass(definition);
262 268
 		
263 269
 		for (TypeID baseType : definition.baseInterfaces)
264 270
 			prepare(baseType);
@@ -269,7 +275,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
269 275
 	@Override
270 276
 	public JavaClass visitEnum(EnumDefinition definition) {
271 277
 		if (isPrepared(definition))
272
-			return definition.getTag(JavaClass.class);
278
+			return context.getJavaClass(definition);
273 279
 		
274 280
 		return visitClassCompiled(definition, false, JavaClass.Kind.ENUM);
275 281
 	}
@@ -277,7 +283,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
277 283
 	@Override
278 284
 	public JavaClass visitStruct(StructDefinition definition) {
279 285
 		if (isPrepared(definition))
280
-			return definition.getTag(JavaClass.class);
286
+			return context.getJavaClass(definition);
281 287
 		
282 288
 		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
283 289
 	}
@@ -285,25 +291,25 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
285 291
 	@Override
286 292
 	public JavaClass visitFunction(FunctionDefinition definition) {
287 293
 		if (isPrepared(definition))
288
-			return definition.getTag(JavaClass.class);
294
+			return context.getJavaClass(definition);
289 295
 		
290 296
 		JavaClass cls = new JavaClass(definition.pkg.fullName, JavaClass.getNameFromFile(filename), JavaClass.Kind.CLASS);
291
-		definition.setTag(JavaClass.class, cls);
297
+		context.setJavaClass(definition, cls);
292 298
 		return cls;
293 299
 	}
294 300
 
295 301
 	@Override
296 302
 	public JavaClass visitExpansion(ExpansionDefinition definition) {
297 303
 		if (isPrepared(definition))
298
-			return definition.getTag(JavaClass.class);
304
+			return context.getJavaClass(definition);
299 305
 		
300 306
 		NativeTag nativeTag = definition.getTag(NativeTag.class);
301 307
 		if (nativeTag != null) {
302
-			definition.setTag(JavaNativeClass.class, nativeClasses.get(nativeTag.value));
308
+			context.setJavaNativeClass(definition, nativeClasses.get(nativeTag.value));
303 309
 		}
304 310
 		
305 311
 		JavaClass cls = new JavaClass(definition.pkg.fullName, JavaClass.getNameFromFile(filename), JavaClass.Kind.CLASS);
306
-		definition.setTag(JavaClass.class, cls);
312
+		context.setJavaClass(definition, cls);
307 313
 		return cls;
308 314
 	}
309 315
 
@@ -316,14 +322,14 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
316 322
 	@Override
317 323
 	public JavaClass visitVariant(VariantDefinition variant) {
318 324
 		if (isPrepared(variant))
319
-			return variant.getTag(JavaClass.class);
325
+			return context.getJavaClass(variant);
320 326
 		
321 327
 		JavaClass cls = new JavaClass(variant.pkg.fullName, variant.name, JavaClass.Kind.CLASS);
322
-		variant.setTag(JavaClass.class, cls);
328
+		context.setJavaClass(variant, cls);
323 329
 		
324 330
 		for (VariantDefinition.Option option : variant.options) {
325 331
 			JavaClass variantCls = new JavaClass(cls, option.name, JavaClass.Kind.CLASS);
326
-			option.setTag(JavaVariantOption.class, new JavaVariantOption(cls, variantCls));
332
+			module.setVariantOption(option, new JavaVariantOption(cls, variantCls));
327 333
 		}
328 334
 		
329 335
 		return cls;
@@ -339,11 +345,12 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
339 345
 		if (nativeClass == null) {
340 346
 			cls = outerClass == null ? new JavaClass(definition.pkg.fullName, definition.name, kind) : new JavaClass(outerClass, definition.name, kind);
341 347
 			cls.destructible = definition.isDestructible();
342
-			definition.setTag(JavaClass.class, cls);
348
+			context.setJavaClass(definition, cls);
343 349
 		} else {
344 350
 			cls = outerClass == null ? new JavaClass(definition.pkg.fullName, filename, kind) : new JavaClass(outerClass, filename, kind);
345
-			definition.setTag(JavaClass.class, nativeClass.cls);
346
-			definition.setTag(JavaNativeClass.class, nativeClass);
351
+			
352
+			context.setJavaClass(definition, nativeClass.cls);
353
+			context.setJavaNativeClass(definition, nativeClass);
347 354
 			
348 355
 			if (nativeClass.nonDestructible)
349 356
 				cls.destructible = false;
@@ -351,7 +358,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
351 358
 		
352 359
 		for (IDefinitionMember member : definition.members) {
353 360
 			if (member instanceof InnerDefinitionMember) {
354
-				((InnerDefinitionMember) member).innerDefinition.accept(new JavaPrepareDefinitionVisitor(filename, cls));
361
+				((InnerDefinitionMember) member).innerDefinition.accept(new JavaPrepareDefinitionVisitor(context, module, filename, cls));
355 362
 			}
356 363
 		}
357 364
 		

+ 11
- 5
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java Parādīt failu

@@ -31,6 +31,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
31 31
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
32 32
 import org.openzen.zenscript.javashared.JavaTypeNameVisitor;
33 33
 import org.openzen.zenscript.javashared.JavaClass;
34
+import org.openzen.zenscript.javashared.JavaCompiledModule;
34 35
 import org.openzen.zenscript.javashared.JavaField;
35 36
 import org.openzen.zenscript.javashared.JavaContext;
36 37
 import org.openzen.zenscript.javashared.JavaImplementation;
@@ -45,10 +46,12 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
45 46
 	private static final boolean DEBUG_EMPTY = true;
46 47
 	
47 48
 	private final JavaContext context;
49
+	private final JavaCompiledModule module;
48 50
 	private final JavaClass cls;
49 51
 	private final JavaNativeClass nativeClass;
50 52
 	
51
-	public JavaPrepareExpansionMethodVisitor(JavaContext context, JavaClass cls, JavaNativeClass nativeClass) {
53
+	public JavaPrepareExpansionMethodVisitor(JavaContext context, JavaCompiledModule module, JavaClass cls, JavaNativeClass nativeClass) {
54
+		this.module = module;
52 55
 		this.cls = cls;
53 56
 		this.nativeClass = nativeClass;
54 57
 		this.context = context;
@@ -57,7 +60,8 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
57 60
 	
58 61
 	@Override
59 62
 	public Void visitConst(ConstMember member) {
60
-		member.setTag(JavaField.class, new JavaField(cls, member.name, context.getDescriptor(member.type)));
63
+		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.type));
64
+		module.setFieldInfo(member, field);
61 65
 		
62 66
 		if (DEBUG_EMPTY && cls.empty)
63 67
 			System.out.println("Class " + cls.fullName + " not empty because of const");
@@ -69,7 +73,9 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
69 73
 	@Override
70 74
 	public Void visitField(FieldMember member) {
71 75
 		// TODO: expansion fields
72
-		member.setTag(JavaField.class, new JavaField(cls, member.name, context.getDescriptor(member.type)));
76
+		JavaField field = new JavaField(cls, member.name, context.getDescriptor(member.type));
77
+		module.setFieldInfo(member, field);
78
+		
73 79
 		if (member.hasAutoGetter() || member.hasAutoSetter())
74 80
 			cls.empty = false;
75 81
 		return null;
@@ -135,7 +141,7 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
135 141
 	@Override
136 142
 	public Void visitImplementation(ImplementationMember member) {
137 143
 		JavaClass implementationClass = new JavaClass(cls, JavaTypeNameVisitor.INSTANCE.process(member.type) + "Implementation", JavaClass.Kind.CLASS);
138
-		member.setTag(JavaImplementation.class, new JavaImplementation(false, implementationClass));
144
+		module.setImplementationInfo(member, new JavaImplementation(false, implementationClass));
139 145
 		for (IDefinitionMember implementedMember : member.members)
140 146
 			implementedMember.accept(this);
141 147
 		
@@ -170,7 +176,7 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
170 176
 			cls.empty = false;
171 177
 		}
172 178
 		
173
-		member.setTag(JavaMethod.class, method);
179
+		module.setMethodInfo(member, method);
174 180
 	}
175 181
 	
176 182
 	private JavaMethod.Kind getKind(DefinitionMember member) {

+ 35
- 12
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java Parādīt failu

@@ -37,6 +37,8 @@ import org.openzen.zenscript.javashared.JavaNativeClass;
37 37
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
38 38
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
39 39
 import org.openzen.zenscript.javashared.JavaClass;
40
+import org.openzen.zenscript.javashared.JavaCompiledModule;
41
+import org.openzen.zenscript.javashared.JavaContext;
40 42
 import org.openzen.zenscript.javashared.JavaImplementation;
41 43
 
42 44
 /**
@@ -52,10 +54,13 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
52 54
 	private final List<ExpansionDefinition> expansions;
53 55
 	private final StringBuilder output;
54 56
 	private final Map<HighLevelDefinition, SemanticModule> modules;
57
+	private final JavaContext context;
58
+	private final JavaCompiledModule module;
55 59
 	
56 60
 	public JavaDefinitionVisitor(
57 61
 			String indent,
58 62
 			JavaSourceCompiler compiler,
63
+			JavaCompiledModule module,
59 64
 			JavaClass cls,
60 65
 			JavaSourceFile file,
61 66
 			StringBuilder output,
@@ -70,6 +75,8 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
70 75
 		this.output = output;
71 76
 		this.expansions = expansions;
72 77
 		this.modules = modules;
78
+		this.context = compiler.context;
79
+		this.module = module;
73 80
 	}
74 81
 	
75 82
 	private JavaSourceFileScope createScope(HighLevelDefinition definition) {
@@ -80,11 +87,23 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
80 87
 		CompileScope scope = new CompileScope(module.compilationUnit.globalTypeRegistry, module.expansions, module.annotations, module.storageTypes);
81 88
 		return new JavaSourceFileScope(file.importer, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition, thisType, compiler.context);
82 89
 	}
90
+	
91
+	private List<ImplementationMember> getMergedImplementations(HighLevelDefinition definition) {
92
+		List<ImplementationMember> result = new ArrayList<>();
93
+		for (IDefinitionMember member : definition.members) {
94
+			if (member instanceof ImplementationMember) {
95
+				JavaImplementation implementation = module.getImplementationInfo((ImplementationMember) member);
96
+				if (implementation.inline)
97
+					result.add((ImplementationMember)member);
98
+			}
99
+		}
100
+		return result;
101
+	}
83 102
 
84 103
 	@Override
85 104
 	public Void visitClass(ClassDefinition definition) {
86 105
 		JavaSourceFileScope scope = createScope(definition);
87
-		JavaClass cls = definition.getTag(JavaClass.class);
106
+		JavaClass cls = context.getJavaClass(definition);
88 107
 		
89 108
 		output.append(indent);
90 109
 		convertModifiers(definition.modifiers);
@@ -94,15 +113,8 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
94 113
 			output.append(" extends ");
95 114
 			output.append(scope.type(definition.getSuperType()));
96 115
 		}
97
-		List<ImplementationMember> mergedImplementations = new ArrayList<>();
98
-		for (IDefinitionMember member : definition.members) {
99
-			if (member instanceof ImplementationMember) {
100
-				JavaImplementation implementation = ((ImplementationMember) member).getTag(JavaImplementation.class);
101
-				if (implementation.inline)
102
-					mergedImplementations.add((ImplementationMember)member);
103
-			}
104
-		}
105 116
 		
117
+		List<ImplementationMember> mergedImplementations = getMergedImplementations(definition);
106 118
 		if (mergedImplementations.size() > 0 || cls.destructible) {
107 119
 			output.append(" implements ");
108 120
 			boolean first = true;
@@ -136,7 +148,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
136 148
 	@Override
137 149
 	public Void visitInterface(InterfaceDefinition definition) {
138 150
 		JavaSourceFileScope scope = createScope(definition);
139
-		JavaClass cls = definition.getTag(JavaClass.class);
151
+		JavaClass cls = context.getJavaClass(definition);
140 152
 		
141 153
 		output.append(indent);
142 154
 		convertModifiers(definition.modifiers | Modifiers.VIRTUAL); // to prevent 'final'
@@ -160,6 +172,17 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
160 172
 			output.append(scope.type(base));
161 173
 		}
162 174
 		
175
+		List<ImplementationMember> mergedImplementations = getMergedImplementations(definition);
176
+		for (ImplementationMember member : mergedImplementations) {
177
+			if (firstExtends) {
178
+				firstExtends = false;
179
+				output.append(" extends ");
180
+			} else {
181
+				output.append(", ");
182
+			}
183
+			output.append(scope.type(member.type));
184
+		}
185
+		
163 186
 		output.append(" {\n");
164 187
 		compileMembers(scope, definition);
165 188
 		compileExpansions();
@@ -367,7 +390,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
367 390
 	}
368 391
 	
369 392
 	private void compileMembers(JavaSourceFileScope scope, HighLevelDefinition definition) {
370
-		if (definition.hasTag(JavaNativeClass.class)) {
393
+		if (context.getJavaNativeClass(definition) != null) {
371 394
 			StoredType[] typeParameters = new StoredType[definition.getNumberOfGenericParameters()];
372 395
 			for (int i = 0; i < typeParameters.length; i++)
373 396
 				typeParameters[i] = scope.semanticScope.getTypeRegistry().getGeneric(definition.typeParameters[i]).stored(definition.typeParameters[i].storage);
@@ -378,7 +401,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
378 401
 				member.accept(memberCompiler);
379 402
 			memberCompiler.finish();
380 403
 		} else {
381
-			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(compiler, file, settings, indent + settings.indent, output, scope, scope.isInterface, definition, modules);
404
+			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(compiler, module, file, settings, indent + settings.indent, output, scope, scope.isInterface, definition, modules);
382 405
 			for (IDefinitionMember member : definition.members)
383 406
 				member.accept(memberCompiler);
384 407
 			

+ 1
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java Parādīt failu

@@ -57,9 +57,7 @@ public class JavaExpansionMemberCompiler extends BaseMemberCompiler {
57 57
 	}
58 58
 	
59 59
 	private void compileMethod(DefinitionMember member, FunctionHeader header, Statement body) {
60
-		JavaMethod method = member.getTag(JavaMethod.class);
61
-		if (method == null)
62
-			throw new AssertionError();
60
+		JavaMethod method = scope.context.getJavaMethod(member);
63 61
 		if (!method.compile)
64 62
 			return;
65 63
 		

+ 16
- 7
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Parādīt failu

@@ -39,6 +39,8 @@ import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
39 39
 import org.openzen.zenscript.compiler.SemanticModule;
40 40
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
41 41
 import org.openzen.zenscript.javashared.JavaClass;
42
+import org.openzen.zenscript.javashared.JavaCompiledModule;
43
+import org.openzen.zenscript.javashared.JavaContext;
42 44
 import org.openzen.zenscript.javashared.JavaImplementation;
43 45
 import org.openzen.zenscript.javashared.JavaMethod;
44 46
 
@@ -52,10 +54,13 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
52 54
 	private final List<FieldMember> fields = new ArrayList<>();
53 55
 	private final boolean isInterface;
54 56
 	private final Map<HighLevelDefinition, SemanticModule> modules;
57
+	private final JavaContext context;
55 58
 	public boolean hasDestructor = false;
59
+	private final JavaCompiledModule module;
56 60
 	
57 61
 	public JavaMemberCompiler(
58 62
 			JavaSourceCompiler compiler,
63
+			JavaCompiledModule module,
59 64
 			JavaSourceFile file,
60 65
 			JavaSourceFormattingSettings settings,
61 66
 			String indent,
@@ -71,12 +76,12 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
71 76
 		this.isInterface = isInterface;
72 77
 		this.compiler = compiler;
73 78
 		this.modules = modules;
79
+		this.context = compiler.context;
80
+		this.module = module;
74 81
 	}
75 82
 	
76 83
 	private void compileMethod(DefinitionMember member, FunctionHeader header, Statement body) {
77
-		JavaMethod method = member.getTag(JavaMethod.class);
78
-		if (method == null)
79
-			throw new AssertionError();
84
+		JavaMethod method = module.getMethodInfo(member);
80 85
 		if (!method.compile)
81 86
 			return;
82 87
 		
@@ -222,7 +227,7 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
222 227
 
223 228
 	@Override
224 229
 	public Void visitImplementation(ImplementationMember member) {
225
-		JavaImplementation implementation = member.getTag(JavaImplementation.class);
230
+		JavaImplementation implementation = module.getImplementationInfo(member);
226 231
 		if (implementation.inline) {
227 232
 			for (IDefinitionMember m : member.members) {
228 233
 				m.accept(this);
@@ -238,7 +243,7 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
238 243
 			
239 244
 			begin(ElementType.INNERCLASS);
240 245
 			output.append("private class ").append(implementationName).append(" implements ").append(scope.type(member.type)).append(" {\n");
241
-			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(compiler, file, settings, indent + settings.indent, output, scope, isInterface, definition, modules);
246
+			JavaMemberCompiler memberCompiler = new JavaMemberCompiler(compiler, module, file, settings, indent + settings.indent, output, scope, isInterface, definition, modules);
242 247
 			for (IDefinitionMember m : member.members) {
243 248
 				m.accept(memberCompiler);
244 249
 			}
@@ -249,10 +254,14 @@ public class JavaMemberCompiler extends BaseMemberCompiler {
249 254
 
250 255
 	@Override
251 256
 	public Void visitInnerDefinition(InnerDefinitionMember member) {
252
-		JavaClass cls = member.innerDefinition.getTag(JavaClass.class);
257
+		JavaClass cls = context.optJavaClass(member.innerDefinition);
258
+		if (cls == null)
259
+			return null;
260
+		
253 261
 		JavaDefinitionVisitor visitor = new JavaDefinitionVisitor(
254
-				indent,
262
+				indent, 
255 263
 				compiler,
264
+				module,
256 265
 				cls,
257 266
 				file,
258 267
 				output,

+ 9
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java Parādīt failu

@@ -15,6 +15,7 @@ import org.openzen.zenscript.codemodel.definition.ZSPackage;
15 15
 import org.openzen.zenscript.compiler.CompilationUnit;
16 16
 import org.openzen.zenscript.compiler.SemanticModule;
17 17
 import org.openzen.zenscript.compiler.ZenCodeCompiler;
18
+import org.openzen.zenscript.javashared.JavaBaseCompiler;
18 19
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
19 20
 import org.openzen.zenscript.javashared.JavaClass;
20 21
 
@@ -22,7 +23,7 @@ import org.openzen.zenscript.javashared.JavaClass;
22 23
  *
23 24
  * @author Hoofdgebruiker
24 25
  */
25
-public class JavaSourceCompiler implements ZenCodeCompiler {
26
+public class JavaSourceCompiler extends JavaBaseCompiler implements ZenCodeCompiler {
26 27
 	public final JavaSourceFormattingSettings settings;
27 28
 	public final JavaSourceSyntheticHelperGenerator helperGenerator;
28 29
 	
@@ -41,17 +42,22 @@ public class JavaSourceCompiler implements ZenCodeCompiler {
41 42
 		this.directory = directory;
42 43
 	}
43 44
 	
45
+	@Override
46
+	public void addModule(SemanticModule module) {
47
+		context.addModule(module.module);
48
+	}
49
+	
44 50
 	@Override
45 51
 	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
46 52
 		String filename = getFilename(definition);
47
-		JavaPrepareDefinitionVisitor prepare = new JavaPrepareDefinitionVisitor(filename, null);
53
+		JavaPrepareDefinitionVisitor prepare = new JavaPrepareDefinitionVisitor(context, context.getJavaModule(module.module), filename, null);
48 54
 		JavaClass cls = definition.accept(prepare);
49 55
 		
50 56
 		File file = new File(getDirectory(definition.pkg), cls.getName() + ".java");
51 57
 		System.out.println("Compiling " + definition.name + " as " + cls.fullName);
52 58
 		JavaSourceFile sourceFile = sourceFiles.get(file);
53 59
 		if (sourceFile == null)
54
-			sourceFiles.put(file, sourceFile = new JavaSourceFile(this, file, cls, definition.pkg));
60
+			sourceFiles.put(file, sourceFile = new JavaSourceFile(this, file, cls, module.module, definition.pkg));
55 61
 		
56 62
 		sourceFile.add(definition, module);
57 63
 	}

+ 16
- 15
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java Parādīt failu

@@ -99,6 +99,8 @@ import org.openzen.zenscript.formattershared.ExpressionString;
99 99
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
100 100
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
101 101
 import org.openzen.zenscript.javashared.JavaClass;
102
+import org.openzen.zenscript.javashared.JavaCompiledModule;
103
+import org.openzen.zenscript.javashared.JavaContext;
102 104
 import org.openzen.zenscript.javashared.JavaField;
103 105
 import org.openzen.zenscript.javashared.JavaNativeTranslator;
104 106
 import org.openzen.zenscript.javashared.JavaMethod;
@@ -118,10 +120,12 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
118 120
 	
119 121
 	public final JavaSourceStatementScope scope;
120 122
 	public final StatementFormattingTarget target;
123
+	private final JavaContext context;
121 124
 	
122 125
 	public JavaSourceExpressionFormatter(StatementFormattingTarget target, JavaSourceStatementScope scope) {
123 126
 		this.target = target;
124 127
 		this.scope = scope;
128
+		context = scope.context;
125 129
 	}
126 130
 
127 131
 	@Override
@@ -168,10 +172,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
168 172
 		if (expression.member.getBuiltin() != null) {
169 173
 			return visitBuiltinCall(expression, expression.member.getBuiltin());
170 174
 		} else {
171
-			JavaMethod method = expression.member.getTag(JavaMethod.class);
172
-			if (method == null)
173
-				throw new IllegalStateException("No source method tag for " + expression.member.getCanonicalName() + "!");
174
-			
175
+			JavaMethod method = context.getJavaMethod(expression.member);
175 176
 			if (method.kind == JavaMethod.Kind.COMPILED) {
176 177
 				return (ExpressionString) method.translation.translate(expression, this);
177 178
 			} else {
@@ -208,7 +209,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
208 209
 		if (expression.member.getBuiltin() != null)
209 210
 			return visitBuiltinCallStatic(expression, expression.member.getBuiltin());
210 211
 		
211
-		JavaMethod method = expression.member.getTag(JavaMethod.class);
212
+		JavaMethod method = context.getJavaMethod(expression.member);
212 213
 		if (method == null)
213 214
 			throw new IllegalStateException("No source method tag for " + expression.member.getCanonicalName() + "!");
214 215
 		
@@ -258,7 +259,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
258 259
 			}
259 260
 		}
260 261
 		
261
-		JavaMethod method = expression.member.getTag(JavaMethod.class);
262
+		JavaMethod method = context.getJavaMethod(expression.member);
262 263
 		if (method == null)
263 264
 			throw new RuntimeException(expression.position + ": No tag for caster");
264 265
 		
@@ -304,7 +305,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
304 305
 			return visitBuiltinConstant(expression, expression.constant.member.builtin);
305 306
 		
306 307
 		return new ExpressionString(
307
-				scope.type(expression.constant.member.definition.getTag(JavaClass.class)) + "." + expression.constant.member.name, 
308
+				scope.type(expression.constant.member.definition) + "." + expression.constant.member.name, 
308 309
 				JavaOperator.MEMBER);
309 310
 	}
310 311
 
@@ -451,7 +452,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
451 452
 
452 453
 	@Override
453 454
 	public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {
454
-		JavaField field = expression.field.getTag(JavaField.class);
455
+		JavaField field = context.getJavaField(expression.field);
455 456
 		if (field == null)
456 457
 			throw new RuntimeException(expression.position + ": Missing field tag");
457 458
 		
@@ -464,15 +465,15 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
464 465
 			return visitBuiltinGetter(expression, expression.getter.member.builtin);
465 466
 		
466 467
 		ExpressionString target = expression.target.accept(this);
467
-		if (expression.getter.member.hasTag(JavaField.class)) {
468
-			JavaField field = expression.getter.member.getTag(JavaField.class);
468
+		if (context.hasJavaField(expression.getter)) {
469
+			JavaField field = context.getJavaField(expression.getter);
469 470
 			if (target.value.equals("this") && !scope.hasLocalVariable(field.name))
470 471
 				return new ExpressionString(field.name, JavaOperator.PRIMARY);
471 472
 			
472 473
 			return target.unaryPostfix(JavaOperator.MEMBER, "." + field.name);
473 474
 		}
474 475
 		
475
-		JavaMethod method = expression.getter.getTag(JavaMethod.class);
476
+		JavaMethod method = context.getJavaMethod(expression.getter);
476 477
 		StringBuilder result = new StringBuilder();
477 478
 		if (!target.value.equals("this") || scope.hasLocalVariable(method.name)) {
478 479
 			result.append(target.value);
@@ -551,7 +552,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
551 552
 			}
552 553
 		}
553 554
 		
554
-		JavaMethod method = expression.constructor.getTag(JavaMethod.class);
555
+		JavaMethod method = context.getJavaMethod(expression.constructor);
555 556
 		switch (method.kind) {
556 557
 			case EXPANSION: {
557 558
 				StringBuilder output = new StringBuilder();
@@ -637,7 +638,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
637 638
 
638 639
 	@Override
639 640
 	public ExpressionString visitSetStaticField(SetStaticFieldExpression expression) {
640
-		JavaField field = expression.field.getTag(JavaField.class);
641
+		JavaField field = context.getJavaField(expression.field);
641 642
 		if (field == null)
642 643
 			throw new RuntimeException(expression.position + ": Missing field tag");
643 644
 		
@@ -708,7 +709,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
708 709
 	}
709 710
 	
710 711
 	private String constructThisName(DefinitionTypeID type) {
711
-		JavaClass cls = type.definition.getTag(JavaClass.class);
712
+		JavaClass cls = context.getJavaClass(type.definition);
712 713
 		return cls.getClassName();
713 714
 	}
714 715
 
@@ -758,7 +759,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
758 759
 	
759 760
 	@Override
760 761
 	public ExpressionString visitVariantValue(VariantValueExpression expression) {
761
-		JavaVariantOption option = expression.option.getTag(JavaVariantOption.class);
762
+		JavaVariantOption option = context.getJavaVariantOption(expression.option);
762 763
 		
763 764
 		StringBuilder result = new StringBuilder();
764 765
 		result.append("new ").append(scope.type(option.variantOptionClass));

+ 21
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java Parādīt failu

@@ -1,3 +1,4 @@
1
+
1 2
 /*
2 3
  * To change this license header, choose License Headers in Project Properties.
3 4
  * To change this template file, choose Tools | Templates
@@ -20,6 +21,8 @@ import java.util.List;
20 21
 import java.util.Map;
21 22
 import java.util.Set;
22 23
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
24
+import org.openzen.zenscript.codemodel.Module;
25
+import org.openzen.zenscript.codemodel.annotations.NativeTag;
23 26
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
24 27
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
25 28
 import org.openzen.zenscript.compiler.SemanticModule;
@@ -37,6 +40,7 @@ public class JavaSourceFile {
37 40
 	private final JavaClass cls;
38 41
 	private final StringBuilder contents = new StringBuilder();
39 42
 	private final ZSPackage pkg;
43
+	private final Module module;
40 44
 	
41 45
 	private HighLevelDefinition mainDefinition;
42 46
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
@@ -44,13 +48,14 @@ public class JavaSourceFile {
44 48
 	private final Map<HighLevelDefinition, SemanticModule> modules = new HashMap<>();
45 49
 	private final Set<String> existing = new HashSet<>();
46 50
 	
47
-	public JavaSourceFile(JavaSourceCompiler compiler, File file, JavaClass cls, ZSPackage pkg) {
51
+	public JavaSourceFile(JavaSourceCompiler compiler, File file, JavaClass cls, Module module, ZSPackage pkg) {
48 52
 		this.compiler = compiler;
49 53
 		this.pkg = pkg;
50 54
 		this.cls = cls;
55
+		this.module = module;
51 56
 		this.file = file;
52 57
 		
53
-		importer = new JavaSourceImporter(cls);
58
+		importer = new JavaSourceImporter(compiler.context, cls);
54 59
 	}
55 60
 	
56 61
 	public String getName() {
@@ -70,7 +75,7 @@ public class JavaSourceFile {
70 75
 	}
71 76
 	
72 77
 	public void prepare(JavaContext context) {
73
-		JavaPrepareDefinitionMemberVisitor visitor = new JavaPrepareDefinitionMemberVisitor(context);
78
+		JavaPrepareDefinitionMemberVisitor visitor = new JavaPrepareDefinitionMemberVisitor(context, context.getJavaModule(module));
74 79
 		
75 80
 		if (mainDefinition != null)
76 81
 			mainDefinition.accept(visitor);
@@ -79,10 +84,21 @@ public class JavaSourceFile {
79 84
 			expansion.accept(visitor);
80 85
 	}
81 86
 	
87
+	private boolean isEmpty(HighLevelDefinition definition) {
88
+		JavaClass cls = compiler.context.getJavaClass(definition);
89
+		if (!cls.empty)
90
+			return false;
91
+		
92
+		if (cls.isInterface() && definition.getTag(NativeTag.class) == null)
93
+			return false;
94
+		
95
+		return true;
96
+	}
97
+	
82 98
 	public void write() {
83 99
 		System.out.println("Calling write on " + file.getName());
84 100
 		
85
-		if (mainDefinition == null || mainDefinition.getTag(JavaClass.class).empty) {
101
+		if (mainDefinition == null || isEmpty(mainDefinition)) {
86 102
 			if (expansions.isEmpty())
87 103
 				return;
88 104
 			
@@ -93,6 +109,7 @@ public class JavaSourceFile {
93 109
 		JavaDefinitionVisitor visitor = new JavaDefinitionVisitor(
94 110
 				"",
95 111
 				compiler,
112
+				compiler.context.getJavaModule(module),
96 113
 				cls,
97 114
 				this,
98 115
 				contents,

+ 5
- 6
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceImporter.java Parādīt failu

@@ -12,6 +12,7 @@ import java.util.Map;
12 12
 import java.util.Set;
13 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14 14
 import org.openzen.zenscript.javashared.JavaClass;
15
+import org.openzen.zenscript.javashared.JavaContext;
15 16
 
16 17
 /**
17 18
  *
@@ -21,17 +22,15 @@ public class JavaSourceImporter {
21 22
 	private final JavaClass cls;
22 23
 	private final Map<String, JavaClass> imports = new HashMap<>();
23 24
 	private final Set<JavaClass> usedImports = new HashSet<>();
25
+	private final JavaContext context;
24 26
 	
25
-	public JavaSourceImporter(JavaClass cls) {
27
+	public JavaSourceImporter(JavaContext context, JavaClass cls) {
26 28
 		this.cls = cls;
29
+		this.context = context;
27 30
 	}
28 31
 	
29 32
 	public String importType(HighLevelDefinition definition) {
30
-		JavaClass cls = definition.getTag(JavaClass.class);
31
-		if (cls == null)
32
-			throw new IllegalStateException("Missing source class tag on " + definition.name);
33
-		
34
-		return importType(cls);
33
+		return importType(context.getJavaClass(definition));
35 34
 	}
36 35
 	
37 36
 	public String importType(JavaClass cls) {

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java Parādīt failu

@@ -159,7 +159,7 @@ public class JavaSourceStatementFormatter implements StatementFormatter.Formatte
159 159
 			
160 160
 			DefinitionTypeID variantType = statement.value.type.asDefinition();
161 161
 			HighLevelDefinition variant = variantType.definition;
162
-			String variantTypeName = scope.type(variant.getTag(JavaClass.class));
162
+			String variantTypeName = scope.type(variant);
163 163
 			for (SwitchCase switchCase : statement.cases) {
164 164
 				VariantOptionSwitchValue switchValue = (VariantOptionSwitchValue)switchCase.value;
165 165
 				String header = switchValue == null ? "default:" : "case " + switchValue.option.getName() + ":";

+ 3
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java Parādīt failu

@@ -35,7 +35,7 @@ public class JavaSourceSyntheticTypeGenerator implements JavaSyntheticClassGener
35 35
 	
36 36
 	@Override
37 37
 	public void synthesizeFunction(JavaSynthesizedFunction function) {
38
-		JavaSourceImporter importer = new JavaSourceImporter(function.cls);
38
+		JavaSourceImporter importer = new JavaSourceImporter(context, function.cls);
39 39
 		JavaSourceTypeVisitor typeVisitor = new JavaSourceTypeVisitor(importer, context);
40 40
 		
41 41
 		StringBuilder contents = new StringBuilder();
@@ -69,7 +69,7 @@ public class JavaSourceSyntheticTypeGenerator implements JavaSyntheticClassGener
69 69
 	
70 70
 	@Override
71 71
 	public void synthesizeRange(JavaSynthesizedRange range) {
72
-		JavaSourceImporter importer = new JavaSourceImporter(range.cls);
72
+		JavaSourceImporter importer = new JavaSourceImporter(context, range.cls);
73 73
 		JavaSourceTypeVisitor typeVisitor = new JavaSourceTypeVisitor(importer, context);
74 74
 		
75 75
 		StringBuilder contents = new StringBuilder();
@@ -95,7 +95,7 @@ public class JavaSourceSyntheticTypeGenerator implements JavaSyntheticClassGener
95 95
 	
96 96
 	@Override
97 97
 	public void synthesizeShared() {
98
-		JavaSourceImporter importer = new JavaSourceImporter(JavaClass.SHARED);
98
+		JavaSourceImporter importer = new JavaSourceImporter(context, JavaClass.SHARED);
99 99
 		
100 100
 		StringBuilder contents = new StringBuilder();
101 101
 		contents.append("public final class Shared<T extends AutoCloseable> {\n");

+ 5
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/scope/JavaSourceStatementScope.java Parādīt failu

@@ -9,6 +9,7 @@ import java.util.HashSet;
9 9
 import java.util.Set;
10 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.FunctionParameter;
12
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
13 14
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
14 15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
@@ -97,6 +98,10 @@ public class JavaSourceStatementScope {
97 98
 		return fileScope.importer.importType(cls);
98 99
 	}
99 100
 	
101
+	public String type(HighLevelDefinition definition) {
102
+		return type(context.getJavaClass(definition));
103
+	}
104
+	
100 105
 	public void addLocalVariable(String localVariable) {
101 106
 		localVariables.add(localVariable);
102 107
 	}

+ 17
- 24
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java Parādīt failu

@@ -39,6 +39,8 @@ import org.openzen.zenscript.javashared.JavaMethod;
39 39
 import org.openzen.zenscript.codemodel.type.TypeID;
40 40
 import org.openzen.zenscript.codemodel.type.storage.AutoStorageTag;
41 41
 import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
42
+import org.openzen.zenscript.javashared.JavaCompiledModule;
43
+import org.openzen.zenscript.javashared.JavaContext;
42 44
 
43 45
 /**
44 46
  *
@@ -50,6 +52,12 @@ public class GlobalRegistry {
50 52
 	private final ZSPackage javaIo = rootPackage.getOrCreatePackage("java").getOrCreatePackage("io");
51 53
 	private final ZSPackage javaLang = rootPackage.getOrCreatePackage("java").getOrCreatePackage("lang");
52 54
 	
55
+	private final Module MODULE = new Module("scriptingExample");
56
+	private final ClassDefinition PRINTSTREAM = new ClassDefinition(CodePosition.NATIVE, MODULE, javaIo, "PrintStream", Modifiers.PUBLIC);
57
+	private final ClassDefinition SYSTEM = new ClassDefinition(CodePosition.NATIVE, MODULE, javaLang, "System", Modifiers.PUBLIC);
58
+	private final MethodMember PRINTSTREAM_PRINTLN;
59
+	private final GetterMember SYSTEM_OUT;
60
+	
53 61
 	public GlobalRegistry(GlobalTypeRegistry registry, ZSPackage globals) {
54 62
 		PRINTSTREAM_PRINTLN = new MethodMember(
55 63
 			CodePosition.NATIVE,
@@ -66,32 +74,23 @@ public class GlobalRegistry {
66 74
 			"out",
67 75
 			DefinitionTypeID.forType(registry, SYSTEM).stored(AutoStorageTag.INSTANCE),
68 76
 			null);
77
+	}
78
+	
79
+	public void register(JavaContext context) {
80
+		context.addModule(MODULE);
81
+		JavaCompiledModule javaModule = context.getJavaModule(MODULE);
82
+		
83
+		JavaClass jSystem = new JavaClass("java.lang", "System", JavaClass.Kind.CLASS);
84
+		javaModule.setFieldInfo(SYSTEM_OUT, new JavaField(jSystem, "out", "Ljava/io/PrintStream;"));
69 85
 		
70 86
 		JavaClass jPrintStream = new JavaClass("java.io", "PrintStream", JavaClass.Kind.CLASS);
71 87
 		JavaMethod printstreamPrintln = JavaMethod.getNativeVirtual(jPrintStream, "println", "(Ljava/lang/String;)V");
72
-		PRINTSTREAM_PRINTLN.setTag(JavaMethod.class, printstreamPrintln);
73
-		
74
-		JavaClass jSystem = new JavaClass("java.lang", "System", JavaClass.Kind.CLASS);
75
-		SYSTEM_OUT.setTag(JavaField.class, new JavaField(jSystem, "out", "Ljava/io/PrintStream;"));
88
+		javaModule.setMethodInfo(PRINTSTREAM_PRINTLN, printstreamPrintln);
76 89
 	}
77 90
 	
78 91
 	public ZSPackage collectPackages() {
79 92
 		// register packages here
80 93
 		
81
-		{
82
-			// eg. package my.package with a class MyClass with a single native method test() returning a string
83
-			// the visitors can then during compilation check if a method is an instance of NativeMethodMember and treat it accordingly
84
-			ZSPackage packageMyPackage = rootPackage.getOrCreatePackage("my").getOrCreatePackage("test");
85
-			ClassDefinition myClassDefinition = new ClassDefinition(CodePosition.NATIVE, MODULE, packageMyPackage, "MyClass", Modifiers.PUBLIC, null);
86
-			JavaClass myClassInfo = new JavaClass("my.test", "MyClass", JavaClass.Kind.CLASS);
87
-			
88
-			MethodMember member = new MethodMember(CodePosition.NATIVE, myClassDefinition, Modifiers.PUBLIC, "test", new FunctionHeader(StringTypeID.UNIQUE), null);
89
-			member.setTag(JavaMethod.class, JavaMethod.getNativeVirtual(myClassInfo, "test", "()Ljava/lang/String;"));
90
-			myClassDefinition.addMember(member);
91
-			
92
-			packageMyPackage.register(myClassDefinition);
93
-		}
94
-		
95 94
 		return rootPackage;
96 95
 	}
97 96
 	
@@ -110,12 +109,6 @@ public class GlobalRegistry {
110 109
 		return globals;
111 110
 	}
112 111
 	
113
-	private final Module MODULE = new Module("scriptingExample");
114
-	private final ClassDefinition PRINTSTREAM = new ClassDefinition(CodePosition.NATIVE, MODULE, javaIo, "PrintStream", Modifiers.PUBLIC);
115
-	private final ClassDefinition SYSTEM = new ClassDefinition(CodePosition.NATIVE, MODULE, javaLang, "System", Modifiers.PUBLIC);
116
-	private final MethodMember PRINTSTREAM_PRINTLN;
117
-	private final GetterMember SYSTEM_OUT;
118
-	
119 112
 	private class PrintlnSymbol implements ISymbol {
120 113
 
121 114
 		@Override

+ 6
- 2
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java Parādīt failu

@@ -57,7 +57,7 @@ public class Main {
57 57
 		//formatFiles(pkg, module);
58 58
 		
59 59
 		if (semantic.isValid()) {
60
-			JavaModule javaModule = compileSemanticToJava(semantic);
60
+			JavaModule javaModule = compileSemanticToJava(registry, semantic);
61 61
 			javaModule.execute();
62 62
 		} else {
63 63
 			System.out.println("There were compilation errors");
@@ -127,8 +127,12 @@ public class Main {
127 127
 		return result;
128 128
 	}
129 129
 	
130
-	private static JavaModule compileSemanticToJava(SemanticModule module) {
130
+	private static JavaModule compileSemanticToJava(GlobalRegistry registry, SemanticModule module) {
131 131
 		JavaCompiler compiler = new JavaCompiler(module.compilationUnit.globalTypeRegistry, false, null);
132
+		registry.register(compiler.getContext());
133
+		
134
+		compiler.getContext().addModule(module.module);
135
+		
132 136
 		for (HighLevelDefinition definition : module.definitions.getAll()) {
133 137
 			compiler.addDefinition(definition, module);
134 138
 		}

+ 1
- 1
Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java Parādīt failu

@@ -3,7 +3,7 @@ package org.openzen.zencode.shared;
3 3
 import java.io.IOException;
4 4
 import java.io.Reader;
5 5
 
6
-public interface SourceFile {
6
+public interface SourceFile extends Tag {
7 7
     String getFilename();
8 8
     
9 9
     Reader open() throws IOException;

+ 4
- 0
Shared/src/main/java/org/openzen/zencode/shared/Tag.java Parādīt failu

@@ -0,0 +1,4 @@
1
+package org.openzen.zencode.shared;
2
+
3
+public interface Tag {
4
+}

+ 3
- 3
Shared/src/main/java/org/openzen/zencode/shared/Taggable.java Parādīt failu

@@ -6,15 +6,15 @@ import java.util.Map;
6 6
 public class Taggable {
7 7
     private final Map<Class<?>, Object> tags = new HashMap<Class<?>, Object>();
8 8
     
9
-    public <T> void setTag(Class<T> typeOfT, T tag) {
9
+    public <T extends Tag> void setTag(Class<T> typeOfT, T tag) {
10 10
         tags.put(typeOfT, tag);
11 11
     }
12 12
     
13
-    public <T> T getTag(Class<T> typeOfT) {
13
+    public <T extends Tag> T getTag(Class<T> typeOfT) {
14 14
         return (T)(tags.get(typeOfT));
15 15
     }
16 16
     
17
-    public <T> boolean hasTag(Class<T> typeOfT) {
17
+    public <T extends Tag> boolean hasTag(Class<T> typeOfT) {
18 18
         return tags.containsKey(typeOfT);
19 19
     }
20 20
     

Notiek ielāde…
Atcelt
Saglabāt