|
@@ -5,32 +5,19 @@
|
5
|
5
|
*/
|
6
|
6
|
package org.openzen.zenscript.javabytecode;
|
7
|
7
|
|
8
|
|
-import java.util.*;
|
9
|
|
-
|
10
|
|
-import org.objectweb.asm.ClassWriter;
|
11
|
|
-import org.objectweb.asm.Opcodes;
|
12
|
|
-import org.openzen.zencode.shared.CodePosition;
|
13
|
|
-import org.openzen.zencode.shared.SourceFile;
|
|
8
|
+import org.objectweb.asm.*;
|
|
9
|
+import org.openzen.zencode.shared.*;
|
14
|
10
|
import org.openzen.zencode.shared.logging.*;
|
15
|
|
-import org.openzen.zenscript.codemodel.FunctionHeader;
|
16
|
|
-import org.openzen.zenscript.codemodel.FunctionParameter;
|
17
|
|
-import org.openzen.zenscript.codemodel.HighLevelDefinition;
|
18
|
|
-import org.openzen.zenscript.codemodel.ScriptBlock;
|
19
|
|
-import org.openzen.zenscript.codemodel.SemanticModule;
|
20
|
|
-import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
|
21
|
|
-import org.openzen.zenscript.codemodel.statement.Statement;
|
22
|
|
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
|
23
|
|
-import org.openzen.zenscript.javabytecode.compiler.JavaClassWriter;
|
24
|
|
-import org.openzen.zenscript.javabytecode.compiler.JavaScriptFile;
|
25
|
|
-import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
|
26
|
|
-import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
|
27
|
|
-import org.openzen.zenscript.javabytecode.compiler.definitions.JavaDefinitionVisitor;
|
28
|
|
-import org.openzen.zenscript.javashared.JavaClass;
|
29
|
|
-import org.openzen.zenscript.javashared.JavaCompileSpace;
|
30
|
|
-import org.openzen.zenscript.javashared.JavaMethod;
|
31
|
|
-import org.openzen.zenscript.javashared.JavaParameterInfo;
|
32
|
|
-import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionMemberVisitor;
|
33
|
|
-import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
|
|
11
|
+import org.openzen.zenscript.codemodel.*;
|
|
12
|
+import org.openzen.zenscript.codemodel.definition.*;
|
|
13
|
+import org.openzen.zenscript.codemodel.statement.*;
|
|
14
|
+import org.openzen.zenscript.codemodel.type.*;
|
|
15
|
+import org.openzen.zenscript.javabytecode.compiler.*;
|
|
16
|
+import org.openzen.zenscript.javabytecode.compiler.definitions.*;
|
|
17
|
+import org.openzen.zenscript.javashared.*;
|
|
18
|
+import org.openzen.zenscript.javashared.prepare.*;
|
|
19
|
+
|
|
20
|
+import java.util.*;
|
34
|
21
|
|
35
|
22
|
/**
|
36
|
23
|
* @author Hoofdgebruiker
|
|
@@ -55,22 +42,37 @@ public class JavaCompiler {
|
55
|
42
|
|
56
|
43
|
for (HighLevelDefinition definition : module.definitions.getAll()) {
|
57
|
44
|
final String className = getClassName(getFilename(definition));
|
58
|
|
- String filename = className + "_" + (definition.name == null ? "generated" : definition.name) + "_" + expansionCounter++;
|
59
|
|
- JavaPrepareDefinitionVisitor definitionPreparer = new JavaPrepareDefinitionVisitor(context, target, filename, null, filename);
|
60
|
|
- definition.accept(definitionPreparer);
|
|
45
|
+ final String filename;
|
|
46
|
+ if(definition instanceof FunctionDefinition) {
|
|
47
|
+ filename = className;
|
|
48
|
+ } else {
|
|
49
|
+ filename = className + "_" + (definition.name == null ? "generated" : definition.name) + "_" + expansionCounter++;
|
|
50
|
+ }
|
|
51
|
+ JavaPrepareDefinitionVisitor definitionPreparer = new JavaPrepareDefinitionVisitor(context, target, filename, null, filename);
|
|
52
|
+ definition.accept(definitionPreparer);
|
61
|
53
|
}
|
62
|
54
|
|
63
|
55
|
for (HighLevelDefinition definition : module.definitions.getAll()) {
|
64
|
56
|
JavaPrepareDefinitionMemberVisitor memberPreparer = new JavaPrepareDefinitionMemberVisitor(context, target);
|
65
|
57
|
definition.accept(memberPreparer);
|
66
|
58
|
}
|
67
|
|
-
|
68
|
|
- for (HighLevelDefinition definition : module.definitions.getAll()) {
|
69
|
|
- JavaClass cls = definition instanceof ExpansionDefinition ? context.getJavaExpansionClass(definition) : context.getJavaClass(definition);
|
70
|
|
- JavaScriptFile scriptFile = getScriptFile(scriptBlocks, cls.fullName);
|
|
59
|
+
|
|
60
|
+ for(HighLevelDefinition definition : module.definitions.getAll()) {
|
|
61
|
+ final String internalName;
|
|
62
|
+ final JavaScriptFile scriptFile;
|
|
63
|
+ if(definition instanceof FunctionDefinition) {
|
|
64
|
+ internalName = getClassName(getFilename(definition));
|
|
65
|
+ scriptFile = getScriptFile(scriptBlocks, module.modulePackage.fullName + "/" + internalName);
|
|
66
|
+ scriptFilesThatAreActuallyUsedInScripts.add(scriptFile);
|
|
67
|
+ } else {
|
|
68
|
+ JavaClass cls = definition instanceof ExpansionDefinition ? context.getJavaExpansionClass(definition) : context
|
|
69
|
+ .getJavaClass(definition);
|
|
70
|
+ scriptFile = getScriptFile(scriptBlocks, cls.fullName);
|
|
71
|
+ internalName = cls.internalName;
|
|
72
|
+ }
|
71
|
73
|
scriptFile.classWriter.visitSource(definition.position.getFilename(), null);
|
72
|
|
- target.addClass(cls.internalName, definition.accept(new JavaDefinitionVisitor(context, scriptFile.classWriter)));
|
73
|
|
- }
|
|
74
|
+ target.addClass(internalName, definition.accept(new JavaDefinitionVisitor(context, scriptFile.classWriter)));
|
|
75
|
+ }
|
74
|
76
|
|
75
|
77
|
FunctionHeader scriptHeader = new FunctionHeader(BasicTypeID.VOID, module.parameters);
|
76
|
78
|
String scriptDescriptor = context.getMethodDescriptor(scriptHeader);
|