Parcourir la source

New Codestyle in JavaBytecodeCompiler

- Tabs instead of spaces
kindlich il y a 6 ans
Parent
révision
beb8ef3696
Aucune clé connue n'a été trouvée dans la base pour cette signature
30 fichiers modifiés avec 2774 ajouts et 2923 suppressions
  1. 6
    6
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java
  2. 0
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeImplementation.java
  3. 2
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTarget.java
  4. 5
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTargetType.java
  5. 2
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTarget.java
  6. 5
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTargetType.java
  7. 3
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaClassInfo.java
  8. 24
    26
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  9. 1
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaFieldInfo.java
  10. 12
    12
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaLocalVariableInfo.java
  11. 11
    12
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaMethodInfo.java
  12. 13
    12
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaModule.java
  13. 1
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaParameterInfo.java
  14. 150
    157
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  15. 31
    31
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaCapturedExpressionVisitor.java
  16. 3
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaClassWriter.java
  17. 706
    685
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  18. 67
    67
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachVisitor.java
  19. 2
    14
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java
  20. 20
    87
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  21. 20
    87
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  22. 3
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaScriptFile.java
  23. 308
    308
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  24. 1
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaSwitchLabel.java
  25. 75
    75
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java
  26. 42
    42
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeVisitor.java
  27. 944
    952
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  28. 107
    109
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  29. 10
    10
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaInitializedVariables.java
  30. 200
    200
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java

+ 6
- 6
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java Voir le fichier

@@ -1,12 +1,12 @@
1 1
 package org.openzen.zenscript.implementations;
2 2
 
3 3
 public class IntRange {
4
-    public final int from;
5
-    public final int to;
4
+	public final int from;
5
+	public final int to;
6 6
 
7 7
 
8
-    public IntRange(int from, int to) {
9
-        this.from = from;
10
-        this.to = to;
11
-    }
8
+	public IntRange(int from, int to) {
9
+		this.from = from;
10
+		this.to = to;
11
+	}
12 12
 }

+ 0
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeImplementation.java Voir le fichier

@@ -8,7 +8,6 @@ package org.openzen.zenscript.javabytecode;
8 8
 import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
9 9
 
10 10
 /**
11
- *
12 11
  * @author Hoofdgebruiker
13 12
  */
14 13
 public interface JavaBytecodeImplementation {

+ 2
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTarget.java Voir le fichier

@@ -10,20 +10,19 @@ import org.openzen.zenscript.compiler.SemanticModule;
10 10
 import org.openzen.zenscript.compiler.Target;
11 11
 
12 12
 /**
13
- *
14 13
  * @author Hoofdgebruiker
15 14
  */
16 15
 public class JavaBytecodeJarTarget implements Target {
17 16
 	private final String module;
18 17
 	private final String name;
19 18
 	private final boolean debugCompiler;
20
-	
19
+
21 20
 	public JavaBytecodeJarTarget(JSONObject definition) {
22 21
 		module = definition.getString("module");
23 22
 		name = definition.optString("name", "Java Bytecode: " + module);
24 23
 		debugCompiler = definition.optBoolean("debugCompiler", false);
25 24
 	}
26
-	
25
+
27 26
 	@Override
28 27
 	public JavaCompiler createCompiler(SemanticModule module) {
29 28
 		return new JavaCompiler(debugCompiler);

+ 5
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTargetType.java Voir le fichier

@@ -5,19 +5,20 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode;
7 7
 
8
-import java.io.File;
9 8
 import org.json.JSONObject;
10 9
 import org.openzen.zenscript.compiler.Target;
11 10
 import org.openzen.zenscript.compiler.TargetType;
12 11
 
12
+import java.io.File;
13
+
13 14
 /**
14
- *
15 15
  * @author Hoofdgebruiker
16 16
  */
17 17
 public class JavaBytecodeJarTargetType implements TargetType {
18 18
 	public static final JavaBytecodeJarTargetType INSTANCE = new JavaBytecodeJarTargetType();
19
-	
20
-	private JavaBytecodeJarTargetType() {}
19
+
20
+	private JavaBytecodeJarTargetType() {
21
+	}
21 22
 
22 23
 	@Override
23 24
 	public Target create(File projectDir, JSONObject definition) {

+ 2
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTarget.java Voir le fichier

@@ -10,20 +10,19 @@ import org.openzen.zenscript.compiler.SemanticModule;
10 10
 import org.openzen.zenscript.compiler.Target;
11 11
 
12 12
 /**
13
- *
14 13
  * @author Hoofdgebruiker
15 14
  */
16 15
 public class JavaBytecodeRunTarget implements Target {
17 16
 	private final String module;
18 17
 	private final String name;
19 18
 	private final boolean debugCompiler;
20
-	
19
+
21 20
 	public JavaBytecodeRunTarget(JSONObject definition) {
22 21
 		module = definition.getString("module");
23 22
 		name = definition.optString("name", "Java Run: " + module);
24 23
 		debugCompiler = definition.optBoolean("debugCompiler", false);
25 24
 	}
26
-	
25
+
27 26
 	@Override
28 27
 	public JavaCompiler createCompiler(SemanticModule module) {
29 28
 		return new JavaCompiler(debugCompiler);

+ 5
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTargetType.java Voir le fichier

@@ -5,19 +5,20 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode;
7 7
 
8
-import java.io.File;
9 8
 import org.json.JSONObject;
10 9
 import org.openzen.zenscript.compiler.Target;
11 10
 import org.openzen.zenscript.compiler.TargetType;
12 11
 
12
+import java.io.File;
13
+
13 14
 /**
14
- *
15 15
  * @author Hoofdgebruiker
16 16
  */
17 17
 public class JavaBytecodeRunTargetType implements TargetType {
18 18
 	public static final JavaBytecodeRunTargetType INSTANCE = new JavaBytecodeRunTargetType();
19
-	
20
-	private JavaBytecodeRunTargetType() {}
19
+
20
+	private JavaBytecodeRunTargetType() {
21
+	}
21 22
 
22 23
 	@Override
23 24
 	public Target create(File projectDir, JSONObject definition) {

+ 3
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaClassInfo.java Voir le fichier

@@ -8,21 +8,20 @@ package org.openzen.zenscript.javabytecode;
8 8
 import org.objectweb.asm.Type;
9 9
 
10 10
 /**
11
- *
12 11
  * @author Hoofdgebruiker
13 12
  */
14 13
 public class JavaClassInfo {
15 14
 	public static JavaClassInfo get(Class<?> cls) {
16 15
 		return new JavaClassInfo(Type.getInternalName(cls), cls.isEnum());
17 16
 	}
18
-	
17
+
19 18
 	public final String internalClassName;
20 19
 	public final boolean isEnum;
21
-	
20
+
22 21
 	public JavaClassInfo(String internalClassName) {
23 22
 		this(internalClassName, false);
24 23
 	}
25
-	
24
+
26 25
 	public JavaClassInfo(String internalClassName, boolean isEnum) {
27 26
 		this.internalClassName = internalClassName;
28 27
 		this.isEnum = isEnum;

+ 24
- 26
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Voir le fichier

@@ -5,9 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode;
7 7
 
8
-import java.util.HashMap;
9
-import java.util.Map;
10
-
11 8
 import org.objectweb.asm.ClassWriter;
12 9
 import org.objectweb.asm.Opcodes;
13 10
 import org.openzen.zencode.shared.SourceFile;
@@ -15,16 +12,17 @@ import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 12
 import org.openzen.zenscript.codemodel.ScriptBlock;
16 13
 import org.openzen.zenscript.codemodel.statement.Statement;
17 14
 import org.openzen.zenscript.compiler.SemanticModule;
18
-
15
+import org.openzen.zenscript.compiler.ZenCodeCompiler;
19 16
 import org.openzen.zenscript.javabytecode.compiler.JavaClassWriter;
20 17
 import org.openzen.zenscript.javabytecode.compiler.JavaScriptFile;
21
-import org.openzen.zenscript.javabytecode.compiler.definitions.JavaDefinitionVisitor;
22 18
 import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
23 19
 import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
24
-import org.openzen.zenscript.compiler.ZenCodeCompiler;
20
+import org.openzen.zenscript.javabytecode.compiler.definitions.JavaDefinitionVisitor;
21
+
22
+import java.util.HashMap;
23
+import java.util.Map;
25 24
 
26 25
 /**
27
- *
28 26
  * @author Hoofdgebruiker
29 27
  */
30 28
 public class JavaCompiler implements ZenCodeCompiler {
@@ -34,31 +32,31 @@ public class JavaCompiler implements ZenCodeCompiler {
34 32
 	private int generatedScriptBlockCounter = 0;
35 33
 	private boolean finished = false;
36 34
 	private JavaModule compiled = null;
37
-	
35
+
38 36
 	public JavaCompiler() {
39 37
 		this(false);
40 38
 	}
41
-	
39
+
42 40
 	public JavaCompiler(boolean debug) {
43 41
 		target = new JavaModule();
44
-		
42
+
45 43
 		scriptsClassWriter = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
46 44
 		scriptsClassWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "Scripts", null, "java/lang/Object", null);
47 45
 	}
48
-	
46
+
49 47
 	@Override
50 48
 	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
51 49
 		String className = getClassName(definition.position.filename);
52 50
 		JavaScriptFile scriptFile = getScriptFile(className);
53 51
 		target.register(definition.name, definition.accept(new JavaDefinitionVisitor(scriptFile.classWriter)));
54 52
 	}
55
-	
53
+
56 54
 	@Override
57 55
 	public void addScriptBlock(ScriptBlock script) {
58 56
 		final SourceFile sourceFile = script.getTag(SourceFile.class);
59 57
 		final String className = getClassName(sourceFile == null ? null : sourceFile.getFilename());
60 58
 		JavaScriptFile scriptFile = getScriptFile(className);
61
-		
59
+
62 60
 		String methodName = scriptFile.scriptMethods.isEmpty() ? "run" : "run" + scriptFile.scriptMethods.size();
63 61
 
64 62
 		// convert scripts into methods (add them to a Scripts class?)
@@ -66,7 +64,7 @@ public class JavaCompiler implements ZenCodeCompiler {
66 64
 		final JavaClassWriter visitor = scriptFile.classWriter;
67 65
 		JavaMethodInfo method = new JavaMethodInfo(new JavaClassInfo(className), methodName, "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
68 66
 		scriptFile.scriptMethods.add(method);
69
-		
67
+
70 68
 		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(new JavaWriter(visitor, method, null, null, null));
71 69
 		statementVisitor.start();
72 70
 		for (Statement statement : script.statements) {
@@ -75,7 +73,7 @@ public class JavaCompiler implements ZenCodeCompiler {
75 73
 		target.register("Scripts", scriptsClassWriter.toByteArray());
76 74
 		statementVisitor.end();
77 75
 	}
78
-	
76
+
79 77
 	private String getClassName(String filename) {
80 78
 		if (filename == null) {
81 79
 			return "generatedBlock" + (generatedScriptBlockCounter++);
@@ -85,50 +83,50 @@ public class JavaCompiler implements ZenCodeCompiler {
85 83
 			return filename.substring(0, filename.lastIndexOf('.')).replace("/", "_");
86 84
 		}
87 85
 	}
88
-	
86
+
89 87
 	private JavaScriptFile getScriptFile(String className) {
90 88
 		if (!scriptBlocks.containsKey(className)) {
91 89
 			JavaClassWriter scriptFileWriter = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
92 90
 			scriptFileWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", null);
93 91
 			scriptBlocks.put(className, new JavaScriptFile(scriptFileWriter));
94 92
 		}
95
-		
93
+
96 94
 		return scriptBlocks.get(className);
97 95
 	}
98
-	
96
+
99 97
 	@Override
100 98
 	public void finish() {
101 99
 		finishAndGetModule();
102 100
 	}
103
-	
101
+
104 102
 	@Override
105 103
 	public void run() {
106 104
 		if (compiled == null)
107 105
 			throw new IllegalStateException("Not yet built!");
108
-		
109
-		
106
+
107
+
110 108
 	}
111
-	
109
+
112 110
 	public JavaModule finishAndGetModule() {
113 111
 		if (finished)
114 112
 			throw new IllegalStateException("Already finished!");
115 113
 		finished = true;
116
-		
114
+
117 115
 		JavaMethodInfo runMethod = new JavaMethodInfo(new JavaClassInfo("Scripts"), "run", "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
118 116
 		final JavaWriter runWriter = new JavaWriter(scriptsClassWriter, runMethod, null, null, null);
119 117
 		runWriter.start();
120 118
 		for (Map.Entry<String, JavaScriptFile> entry : scriptBlocks.entrySet()) {
121 119
 			for (JavaMethodInfo method : entry.getValue().scriptMethods)
122 120
 				runWriter.invokeStatic(method);
123
-			
121
+
124 122
 			entry.getValue().classWriter.visitEnd();
125 123
 			target.register(entry.getKey(), entry.getValue().classWriter.toByteArray());
126 124
 		}
127 125
 		runWriter.ret();
128 126
 		runWriter.end();
129
-		
127
+
130 128
 		target.register("Scripts", scriptsClassWriter.toByteArray());
131
-		
129
+
132 130
 		return target;
133 131
 	}
134 132
 }

+ 1
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaFieldInfo.java Voir le fichier

@@ -6,14 +6,13 @@
6 6
 package org.openzen.zenscript.javabytecode;
7 7
 
8 8
 /**
9
- *
10 9
  * @author Hoofdgebruiker
11 10
  */
12 11
 public class JavaFieldInfo {
13 12
 	public final JavaClassInfo javaClass;
14 13
 	public final String name;
15 14
 	public final String signature;
16
-	
15
+
17 16
 	public JavaFieldInfo(JavaClassInfo javaClass, String name, String signature) {
18 17
 		this.javaClass = javaClass;
19 18
 		this.name = name;

+ 12
- 12
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaLocalVariableInfo.java Voir le fichier

@@ -4,17 +4,17 @@ import org.objectweb.asm.Label;
4 4
 import org.objectweb.asm.Type;
5 5
 
6 6
 public class JavaLocalVariableInfo {
7
-    public final Type type;
8
-    public final int local;
9
-    public final Label start;
10
-    public final String name;
11
-    public Label end;
7
+	public final Type type;
8
+	public final int local;
9
+	public final Label start;
10
+	public final String name;
11
+	public Label end;
12 12
 
13
-    public JavaLocalVariableInfo(Type type, int local, Label start, String name) {
14
-        this.type = type;
15
-        this.local = local;
16
-        this.start = start;
17
-        this.end = start;
18
-        this.name = name;
19
-    }
13
+	public JavaLocalVariableInfo(Type type, int local, Label start, String name) {
14
+		this.type = type;
15
+		this.local = local;
16
+		this.start = start;
17
+		this.end = start;
18
+		this.name = name;
19
+	}
20 20
 }

+ 11
- 12
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaMethodInfo.java Voir le fichier

@@ -9,33 +9,32 @@ import org.objectweb.asm.Opcodes;
9 9
 import org.objectweb.asm.Type;
10 10
 
11 11
 /**
12
- *
13 12
  * @author Hoofdgebruiker
14 13
  */
15 14
 public class JavaMethodInfo {
16 15
 	public static JavaMethodInfo get(int modifiers, Class owner, String name, Class result, Class... arguments) {
17
-        StringBuilder descriptor = new StringBuilder();
18
-        descriptor.append('(');
19
-        for (Class argument : arguments) {
20
-            descriptor.append(Type.getDescriptor(argument));
21
-        }
22
-        descriptor.append(')');
23
-        descriptor.append(result == null ? 'V' : Type.getDescriptor(result));
16
+		StringBuilder descriptor = new StringBuilder();
17
+		descriptor.append('(');
18
+		for (Class argument : arguments) {
19
+			descriptor.append(Type.getDescriptor(argument));
20
+		}
21
+		descriptor.append(')');
22
+		descriptor.append(result == null ? 'V' : Type.getDescriptor(result));
24 23
 		return new JavaMethodInfo(new JavaClassInfo(Type.getInternalName(owner)), name, descriptor.toString(), modifiers);
25
-    }
26
-	
24
+	}
25
+
27 26
 	public final JavaClassInfo javaClass;
28 27
 	public final String name;
29 28
 	public final String descriptor;
30 29
 	public final int modifiers;
31
-	
30
+
32 31
 	public JavaMethodInfo(JavaClassInfo javaClass, String name, String signature, int modifiers) {
33 32
 		this.javaClass = javaClass;
34 33
 		this.name = name;
35 34
 		this.descriptor = signature;
36 35
 		this.modifiers = modifiers;
37 36
 	}
38
-	
37
+
39 38
 	public boolean isStatic() {
40 39
 		return (modifiers & Opcodes.ACC_STATIC) > 0;
41 40
 	}

+ 13
- 12
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaModule.java Voir le fichier

@@ -5,7 +5,9 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode;
7 7
 
8
-import java.io.*;
8
+import java.io.File;
9
+import java.io.FileOutputStream;
10
+import java.io.IOException;
9 11
 import java.lang.reflect.InvocationTargetException;
10 12
 import java.util.HashMap;
11 13
 import java.util.Map;
@@ -13,44 +15,43 @@ import java.util.logging.Level;
13 15
 import java.util.logging.Logger;
14 16
 
15 17
 /**
16
- *
17 18
  * @author Hoofdgebruiker
18 19
  */
19 20
 public class JavaModule {
20 21
 	public static final Map<String, byte[]> classes = new HashMap<>();
21
-	
22
+
22 23
 	public JavaModule() {
23
-		
24
+
24 25
 	}
25
-	
26
+
26 27
 	public void register(String classname, byte[] bytecode) {
27
-		if(bytecode == null) return;
28
+		if (bytecode == null) return;
28 29
 		classes.put(classname, bytecode);
29
-		try(FileOutputStream writer = new FileOutputStream(new File(classname + ".class"))) {
30
+		try (FileOutputStream writer = new FileOutputStream(new File(classname + ".class"))) {
30 31
 			writer.write(bytecode);
31 32
 		} catch (IOException e) {
32 33
 			e.printStackTrace();
33 34
 		}
34 35
 	}
35
-	
36
+
36 37
 	public void execute() {
37 38
 		ScriptClassLoader classLoader = new ScriptClassLoader();
38
-		
39
+
39 40
 		try {
40 41
 			classLoader.loadClass("Scripts").getMethod("run").invoke(null);
41 42
 		} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException | IllegalAccessException | SecurityException | IllegalArgumentException ex) {
42 43
 			Logger.getLogger(JavaModule.class.getName()).log(Level.SEVERE, null, ex);
43 44
 		}
44 45
 	}
45
-	
46
+
46 47
 	public class ScriptClassLoader extends ClassLoader {
47 48
 		private final Map<String, Class> customClasses = new HashMap<>();
48 49
 
49 50
 		@Override
50 51
 		public Class<?> loadClass(String name) throws ClassNotFoundException {
51
-			if(customClasses.containsKey(name))
52
+			if (customClasses.containsKey(name))
52 53
 				return customClasses.get(name);
53
-			if(classes.containsKey(name)) {
54
+			if (classes.containsKey(name)) {
54 55
 				final byte[] bytes = classes.get(name);
55 56
 				customClasses.put(name, defineClass(name, bytes, 0, bytes.length, null));
56 57
 				return customClasses.get(name);

+ 1
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaParameterInfo.java Voir le fichier

@@ -8,13 +8,12 @@ package org.openzen.zenscript.javabytecode;
8 8
 import org.objectweb.asm.Type;
9 9
 
10 10
 /**
11
- *
12 11
  * @author Hoofdgebruiker
13 12
  */
14 13
 public class JavaParameterInfo {
15 14
 	public final int index;
16 15
 	public final Type type;
17
-	
16
+
18 17
 	public JavaParameterInfo(int index, Type type) {
19 18
 		this.index = index;
20 19
 		this.type = type;

+ 150
- 157
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java Voir le fichier

@@ -8,13 +8,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
8 8
 import org.openzen.zenscript.codemodel.FunctionParameter;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10 10
 import org.openzen.zenscript.codemodel.Modifiers;
11
-import org.openzen.zenscript.codemodel.expression.switchvalue.CharSwitchValue;
12
-import org.openzen.zenscript.codemodel.expression.switchvalue.EnumConstantSwitchValue;
13
-import org.openzen.zenscript.codemodel.expression.switchvalue.IntSwitchValue;
14
-import org.openzen.zenscript.codemodel.expression.switchvalue.StringSwitchValue;
15
-import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
16
-import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValueVisitor;
17
-import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
11
+import org.openzen.zenscript.codemodel.expression.switchvalue.*;
18 12
 import org.openzen.zenscript.codemodel.member.FieldMember;
19 13
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20 14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -22,162 +16,161 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
22 16
 import org.openzen.zenscript.javabytecode.JavaModule;
23 17
 import org.openzen.zenscript.javabytecode.JavaParameterInfo;
24 18
 
25
-import java.io.FileNotFoundException;
26 19
 import java.io.FileOutputStream;
27 20
 import java.io.IOException;
28 21
 import java.util.HashMap;
29 22
 import java.util.Map;
30 23
 
31 24
 public class CompilerUtils {
32
-    public static String calcDesc(FunctionHeader header, boolean isEnum) {
33
-        StringBuilder descBuilder = new StringBuilder("(");
34
-        if (isEnum)
35
-            descBuilder.append("Ljava/lang/String;I");
36
-        for (FunctionParameter parameter : header.parameters) {
37
-            //descBuilder.append(Type.getDescriptor(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
38
-            descBuilder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
39
-        }
40
-        descBuilder.append(")");
41
-        descBuilder.append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
42
-        return descBuilder.toString();
43
-    }
44
-
45
-    public static String calcSign(FunctionHeader header, boolean isEnum) {
46
-        StringBuilder signatureBuilder = new StringBuilder("(");
47
-        for (FunctionParameter parameter : header.parameters) {
48
-            signatureBuilder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
49
-        }
50
-        signatureBuilder.append(")").append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
51
-        return signatureBuilder.toString();
52
-    }
53
-
54
-    public static boolean isPrimitive(ITypeID id) {
55
-        if (id instanceof BasicTypeID) {
56
-            switch ((BasicTypeID) id) {
57
-                case BOOL:
58
-                case BYTE:
59
-                case SBYTE:
60
-                case SHORT:
61
-                case USHORT:
62
-                case INT:
63
-                case UINT:
64
-                case LONG:
65
-                case ULONG:
66
-                case FLOAT:
67
-                case DOUBLE:
68
-                case CHAR:
69
-                    return true;
70
-            }
71
-        }
72
-        return false;
73
-    }
74
-
75
-    public static int calcAccess(int modifiers) {
76
-        int out = 0;
77
-        if (Modifiers.isStatic(modifiers))
78
-            out |= Opcodes.ACC_STATIC;
79
-        if (Modifiers.isFinal(modifiers))
80
-            out |= Opcodes.ACC_FINAL;
81
-        if (Modifiers.isPublic(modifiers))
82
-            out |= Opcodes.ACC_PUBLIC;
83
-        if (Modifiers.isPrivate(modifiers))
84
-            out |= Opcodes.ACC_PRIVATE;
85
-        if (Modifiers.isProtected(modifiers))
86
-            out |= Opcodes.ACC_PROTECTED;
87
-        if (Modifiers.isAbstract(modifiers))
88
-            out |= Opcodes.ACC_ABSTRACT;
89
-        return out;
90
-    }
91
-
92
-    public static String calcClasName(CodePosition position) {
93
-        return position.filename.substring(0, position.filename.lastIndexOf('.')).replace("/", "_");
94
-    }
95
-
96
-    public static void tagMethodParameters(FunctionHeader header, boolean isStatic) {
97
-        JavaTypeVisitor typeVisitor = new JavaTypeVisitor();
98
-        for (int i = 0; i < header.parameters.length; i++) {
99
-            FunctionParameter parameter = header.parameters[i];
100
-            Type parameterType = parameter.type.accept(typeVisitor);
101
-            parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isStatic ? i : i + 1, parameterType));
102
-        }
103
-    }
104
-
105
-    public static void tagConstructorParameters(FunctionHeader header, boolean isEnum) {
106
-        JavaTypeVisitor typeVisitor = new JavaTypeVisitor();
107
-        for (int i = 0; i < header.parameters.length; i++) {
108
-            FunctionParameter parameter = header.parameters[i];
109
-            Type parameterType = parameter.type.accept(typeVisitor);
110
-            parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isEnum ? i + 3 : i + 1, parameterType));
111
-        }
112
-    }
113
-
114
-    public static void writeDefaultFieldInitializers(JavaWriter constructorWriter, HighLevelDefinition definition, boolean staticFields) {
115
-        JavaExpressionVisitor expressionVisitor = new JavaExpressionVisitor(constructorWriter);
116
-        for (final IDefinitionMember definitionMember : definition.members) {
117
-            if (!(definitionMember instanceof FieldMember))
118
-                continue;
119
-
120
-            FieldMember field = (FieldMember) definitionMember;
121
-            if (field.isStatic() == staticFields && field.initializer != null) {
122
-                if (!staticFields)
123
-                    constructorWriter.loadObject(0);
124
-                field.initializer.accept(expressionVisitor);
125
-                if (staticFields)
126
-                    constructorWriter.putStaticField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));
127
-                else
128
-                    constructorWriter.putField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));
129
-            }
130
-        }
131
-    }
132
-
133
-    private static final Map<String, String> lambdas = new HashMap<>();
134
-    private static int lambdaCounter = 0;
135
-    private static int lambdaICounter = 0;
136
-    public static String getLambdaInterface(final FunctionHeader header) {
137
-        StringBuilder builder = new StringBuilder("(");
138
-        for (FunctionParameter parameter : header.parameters) {
139
-            builder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
140
-        }
141
-
142
-        //final String identifier = header.toString();
143
-        final String identifier = builder.append(")").append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor()).toString();
144
-        if(!lambdas.containsKey(identifier)) {
145
-            final String name = "lambdaInterface" + ++lambdaICounter;
146
-            lambdas.put(identifier, name);
147
-            createLambdaInterface(header, name);
148
-        }
149
-        return lambdas.get(identifier);
150
-    }
151
-
152
-    private static void createLambdaInterface(FunctionHeader header, String name) {
153
-        ClassWriter ifaceWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
154
-        ifaceWriter.visitAnnotation("java/lang/FunctionalInterface", true).visitEnd();
155
-        ifaceWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, name, null, "java/lang/Object", null);
156
-
157
-        ifaceWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "accept", calcDesc(header, false), calcSign(header, false), null).visitEnd();
158
-
159
-        ifaceWriter.visitEnd();
160
-
161
-        JavaModule.classes.putIfAbsent(name, ifaceWriter.toByteArray());
162
-
163
-        try (FileOutputStream out = new FileOutputStream(name + ".class")){
164
-            out.write(ifaceWriter.toByteArray());
165
-        } catch (IOException e) {
166
-            e.printStackTrace();
167
-        }
168
-    }
169
-
170
-
171
-    public static String getLambdaCounter() {
172
-        return "lambda" + ++lambdaCounter;
173
-    }
174
-
175
-
176
-
177
-    public static int getKeyForSwitch(SwitchValue expression) {
25
+	public static String calcDesc(FunctionHeader header, boolean isEnum) {
26
+		StringBuilder descBuilder = new StringBuilder("(");
27
+		if (isEnum)
28
+			descBuilder.append("Ljava/lang/String;I");
29
+		for (FunctionParameter parameter : header.parameters) {
30
+			//descBuilder.append(Type.getDescriptor(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
31
+			descBuilder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
32
+		}
33
+		descBuilder.append(")");
34
+		descBuilder.append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
35
+		return descBuilder.toString();
36
+	}
37
+
38
+	public static String calcSign(FunctionHeader header, boolean isEnum) {
39
+		StringBuilder signatureBuilder = new StringBuilder("(");
40
+		for (FunctionParameter parameter : header.parameters) {
41
+			signatureBuilder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
42
+		}
43
+		signatureBuilder.append(")").append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
44
+		return signatureBuilder.toString();
45
+	}
46
+
47
+	public static boolean isPrimitive(ITypeID id) {
48
+		if (id instanceof BasicTypeID) {
49
+			switch ((BasicTypeID) id) {
50
+				case BOOL:
51
+				case BYTE:
52
+				case SBYTE:
53
+				case SHORT:
54
+				case USHORT:
55
+				case INT:
56
+				case UINT:
57
+				case LONG:
58
+				case ULONG:
59
+				case FLOAT:
60
+				case DOUBLE:
61
+				case CHAR:
62
+					return true;
63
+			}
64
+		}
65
+		return false;
66
+	}
67
+
68
+	public static int calcAccess(int modifiers) {
69
+		int out = 0;
70
+		if (Modifiers.isStatic(modifiers))
71
+			out |= Opcodes.ACC_STATIC;
72
+		if (Modifiers.isFinal(modifiers))
73
+			out |= Opcodes.ACC_FINAL;
74
+		if (Modifiers.isPublic(modifiers))
75
+			out |= Opcodes.ACC_PUBLIC;
76
+		if (Modifiers.isPrivate(modifiers))
77
+			out |= Opcodes.ACC_PRIVATE;
78
+		if (Modifiers.isProtected(modifiers))
79
+			out |= Opcodes.ACC_PROTECTED;
80
+		if (Modifiers.isAbstract(modifiers))
81
+			out |= Opcodes.ACC_ABSTRACT;
82
+		return out;
83
+	}
84
+
85
+	public static String calcClasName(CodePosition position) {
86
+		return position.filename.substring(0, position.filename.lastIndexOf('.')).replace("/", "_");
87
+	}
88
+
89
+	public static void tagMethodParameters(FunctionHeader header, boolean isStatic) {
90
+		JavaTypeVisitor typeVisitor = new JavaTypeVisitor();
91
+		for (int i = 0; i < header.parameters.length; i++) {
92
+			FunctionParameter parameter = header.parameters[i];
93
+			Type parameterType = parameter.type.accept(typeVisitor);
94
+			parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isStatic ? i : i + 1, parameterType));
95
+		}
96
+	}
97
+
98
+	public static void tagConstructorParameters(FunctionHeader header, boolean isEnum) {
99
+		JavaTypeVisitor typeVisitor = new JavaTypeVisitor();
100
+		for (int i = 0; i < header.parameters.length; i++) {
101
+			FunctionParameter parameter = header.parameters[i];
102
+			Type parameterType = parameter.type.accept(typeVisitor);
103
+			parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isEnum ? i + 3 : i + 1, parameterType));
104
+		}
105
+	}
106
+
107
+	public static void writeDefaultFieldInitializers(JavaWriter constructorWriter, HighLevelDefinition definition, boolean staticFields) {
108
+		JavaExpressionVisitor expressionVisitor = new JavaExpressionVisitor(constructorWriter);
109
+		for (final IDefinitionMember definitionMember : definition.members) {
110
+			if (!(definitionMember instanceof FieldMember))
111
+				continue;
112
+
113
+			FieldMember field = (FieldMember) definitionMember;
114
+			if (field.isStatic() == staticFields && field.initializer != null) {
115
+				if (!staticFields)
116
+					constructorWriter.loadObject(0);
117
+				field.initializer.accept(expressionVisitor);
118
+				if (staticFields)
119
+					constructorWriter.putStaticField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));
120
+				else
121
+					constructorWriter.putField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));
122
+			}
123
+		}
124
+	}
125
+
126
+	private static final Map<String, String> lambdas = new HashMap<>();
127
+	private static int lambdaCounter = 0;
128
+	private static int lambdaICounter = 0;
129
+
130
+	public static String getLambdaInterface(final FunctionHeader header) {
131
+		StringBuilder builder = new StringBuilder("(");
132
+		for (FunctionParameter parameter : header.parameters) {
133
+			builder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
134
+		}
135
+
136
+		//final String identifier = header.toString();
137
+		final String identifier = builder.append(")").append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor()).toString();
138
+		if (!lambdas.containsKey(identifier)) {
139
+			final String name = "lambdaInterface" + ++lambdaICounter;
140
+			lambdas.put(identifier, name);
141
+			createLambdaInterface(header, name);
142
+		}
143
+		return lambdas.get(identifier);
144
+	}
145
+
146
+	private static void createLambdaInterface(FunctionHeader header, String name) {
147
+		ClassWriter ifaceWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
148
+		ifaceWriter.visitAnnotation("java/lang/FunctionalInterface", true).visitEnd();
149
+		ifaceWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, name, null, "java/lang/Object", null);
150
+
151
+		ifaceWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "accept", calcDesc(header, false), calcSign(header, false), null).visitEnd();
152
+
153
+		ifaceWriter.visitEnd();
154
+
155
+		JavaModule.classes.putIfAbsent(name, ifaceWriter.toByteArray());
156
+
157
+		try (FileOutputStream out = new FileOutputStream(name + ".class")) {
158
+			out.write(ifaceWriter.toByteArray());
159
+		} catch (IOException e) {
160
+			e.printStackTrace();
161
+		}
162
+	}
163
+
164
+
165
+	public static String getLambdaCounter() {
166
+		return "lambda" + ++lambdaCounter;
167
+	}
168
+
169
+
170
+	public static int getKeyForSwitch(SwitchValue expression) {
178 171
 		return expression.accept(new SwitchKeyVisitor());
179
-    }
180
-	
172
+	}
173
+
181 174
 	private static class SwitchKeyVisitor implements SwitchValueVisitor<Integer> {
182 175
 
183 176
 		@Override
@@ -187,7 +180,7 @@ public class CompilerUtils {
187 180
 
188 181
 		@Override
189 182
 		public Integer acceptChar(CharSwitchValue value) {
190
-			return (int)value.value;
183
+			return (int) value.value;
191 184
 		}
192 185
 
193 186
 		@Override

+ 31
- 31
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaCapturedExpressionVisitor.java Voir le fichier

@@ -4,35 +4,35 @@ import org.openzen.zenscript.codemodel.expression.*;
4 4
 
5 5
 public class JavaCapturedExpressionVisitor implements CapturedExpressionVisitor<Void> {
6 6
 
7
-    public final JavaExpressionVisitor expressionVisitor;
8
-
9
-    public JavaCapturedExpressionVisitor(JavaExpressionVisitor expressionVisitor) {
10
-        this.expressionVisitor = expressionVisitor;
11
-    }
12
-
13
-    @Override
14
-    public Void visitCapturedThis(CapturedThisExpression expression) {
15
-        return null;
16
-    }
17
-
18
-    @Override
19
-    public Void visitCapturedParameter(CapturedParameterExpression expression) {
20
-        return new GetFunctionParameterExpression(expression.position, expression.parameter).accept(expressionVisitor);
21
-    }
22
-
23
-    @Override
24
-    public Void visitCapturedLocal(CapturedLocalVariableExpression expression) {
25
-        return new GetLocalVariableExpression(expression.position, expression.variable)
26
-                .accept(expressionVisitor);
27
-    }
28
-
29
-    @Override
30
-    public Void visitCapturedDirect(CapturedDirectExpression expression) {
31
-        return expression.value.accept(expressionVisitor);
32
-    }
33
-
34
-    @Override
35
-    public Void visitRecaptured(CapturedClosureExpression expression) {
36
-        return expression.value.accept(this);
37
-    }
7
+	public final JavaExpressionVisitor expressionVisitor;
8
+
9
+	public JavaCapturedExpressionVisitor(JavaExpressionVisitor expressionVisitor) {
10
+		this.expressionVisitor = expressionVisitor;
11
+	}
12
+
13
+	@Override
14
+	public Void visitCapturedThis(CapturedThisExpression expression) {
15
+		return null;
16
+	}
17
+
18
+	@Override
19
+	public Void visitCapturedParameter(CapturedParameterExpression expression) {
20
+		return new GetFunctionParameterExpression(expression.position, expression.parameter).accept(expressionVisitor);
21
+	}
22
+
23
+	@Override
24
+	public Void visitCapturedLocal(CapturedLocalVariableExpression expression) {
25
+		return new GetLocalVariableExpression(expression.position, expression.variable)
26
+				.accept(expressionVisitor);
27
+	}
28
+
29
+	@Override
30
+	public Void visitCapturedDirect(CapturedDirectExpression expression) {
31
+		return expression.value.accept(expressionVisitor);
32
+	}
33
+
34
+	@Override
35
+	public Void visitRecaptured(CapturedClosureExpression expression) {
36
+		return expression.value.accept(this);
37
+	}
38 38
 }

+ 3
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaClassWriter.java Voir le fichier

@@ -3,7 +3,7 @@ package org.openzen.zenscript.javabytecode.compiler;
3 3
 import org.objectweb.asm.ClassWriter;
4 4
 
5 5
 public class JavaClassWriter extends ClassWriter {
6
-    public JavaClassWriter(int flags) {
7
-        super(flags);
8
-    }
6
+	public JavaClassWriter(int flags) {
7
+		super(flags);
8
+	}
9 9
 }

+ 706
- 685
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 67
- 67
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachVisitor.java Voir le fichier

@@ -8,54 +8,54 @@ import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
8 8
 
9 9
 public class JavaForeachVisitor implements ForeachIteratorVisitor<Void> {
10 10
 
11
-    private final JavaWriter javaWriter;
12
-    private final VarStatement[] variables;
13
-    private final Statement content;
14
-    private final Label startLabel;
15
-    private final Label endLabel;
16
-    private final JavaStatementVisitor statementVisitor;
17
-
18
-    public JavaForeachVisitor(JavaStatementVisitor statementVisitor, VarStatement[] variables, Statement content, Label start, Label end) {
19
-        this.statementVisitor = statementVisitor;
20
-        this.javaWriter = statementVisitor.getJavaWriter();
21
-        this.variables = variables;
22
-        this.content = content;
23
-        this.startLabel = start;
24
-        this.endLabel = end;
25
-    }
26
-
27
-    @Override
28
-    public Void visitIntRange() {
29
-        javaWriter.dup();
30
-        javaWriter.getField("org/openzen/zenscript/implementations/IntRange", "to", "I");
31
-        javaWriter.swap();
32
-        javaWriter.getField("org/openzen/zenscript/implementations/IntRange", "from", "I");
33
-
34
-        final int z = variables[0].getTag(JavaLocalVariableInfo.class).local;
35
-        javaWriter.storeInt(z);
36
-        javaWriter.label(startLabel);
37
-        javaWriter.dup();
38
-        javaWriter.loadInt(z);
39
-        javaWriter.ifICmpLE(endLabel);
40
-
41
-        content.accept(statementVisitor);
42
-        javaWriter.iinc(z);
43
-
44
-
45
-        return null;
46
-    }
47
-
48
-    @Override
49
-    public Void visitArrayValueIterator() {
50
-        handleArray(javaWriter.local(int.class), variables[0].getTag(JavaLocalVariableInfo.class));
51
-        return null;
52
-    }
53
-
54
-    @Override
55
-    public Void visitArrayKeyValueIterator() {
56
-        handleArray(variables[0].getTag(JavaLocalVariableInfo.class).local, variables[1].getTag(JavaLocalVariableInfo.class));
57
-        return null;
58
-    }
11
+	private final JavaWriter javaWriter;
12
+	private final VarStatement[] variables;
13
+	private final Statement content;
14
+	private final Label startLabel;
15
+	private final Label endLabel;
16
+	private final JavaStatementVisitor statementVisitor;
17
+
18
+	public JavaForeachVisitor(JavaStatementVisitor statementVisitor, VarStatement[] variables, Statement content, Label start, Label end) {
19
+		this.statementVisitor = statementVisitor;
20
+		this.javaWriter = statementVisitor.getJavaWriter();
21
+		this.variables = variables;
22
+		this.content = content;
23
+		this.startLabel = start;
24
+		this.endLabel = end;
25
+	}
26
+
27
+	@Override
28
+	public Void visitIntRange() {
29
+		javaWriter.dup();
30
+		javaWriter.getField("org/openzen/zenscript/implementations/IntRange", "to", "I");
31
+		javaWriter.swap();
32
+		javaWriter.getField("org/openzen/zenscript/implementations/IntRange", "from", "I");
33
+
34
+		final int z = variables[0].getTag(JavaLocalVariableInfo.class).local;
35
+		javaWriter.storeInt(z);
36
+		javaWriter.label(startLabel);
37
+		javaWriter.dup();
38
+		javaWriter.loadInt(z);
39
+		javaWriter.ifICmpLE(endLabel);
40
+
41
+		content.accept(statementVisitor);
42
+		javaWriter.iinc(z);
43
+
44
+
45
+		return null;
46
+	}
47
+
48
+	@Override
49
+	public Void visitArrayValueIterator() {
50
+		handleArray(javaWriter.local(int.class), variables[0].getTag(JavaLocalVariableInfo.class));
51
+		return null;
52
+	}
53
+
54
+	@Override
55
+	public Void visitArrayKeyValueIterator() {
56
+		handleArray(variables[0].getTag(JavaLocalVariableInfo.class).local, variables[1].getTag(JavaLocalVariableInfo.class));
57
+		return null;
58
+	}
59 59
 
60 60
 	@Override
61 61
 	public Void visitStringCharacterIterator() {
@@ -63,30 +63,30 @@ public class JavaForeachVisitor implements ForeachIteratorVisitor<Void> {
63 63
 		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
64 64
 	}
65 65
 
66
-    private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {
67
-        javaWriter.iConst0();
68
-        javaWriter.storeInt(z);
66
+	private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {
67
+		javaWriter.iConst0();
68
+		javaWriter.storeInt(z);
69 69
 
70
-        javaWriter.label(startLabel);
71
-        javaWriter.dup();
72
-        javaWriter.dup();
73
-        javaWriter.arrayLength();
74
-        javaWriter.loadInt(z);
70
+		javaWriter.label(startLabel);
71
+		javaWriter.dup();
72
+		javaWriter.dup();
73
+		javaWriter.arrayLength();
74
+		javaWriter.loadInt(z);
75 75
 
76
-        javaWriter.ifICmpLE(endLabel);
77
-        javaWriter.loadInt(z);
76
+		javaWriter.ifICmpLE(endLabel);
77
+		javaWriter.loadInt(z);
78 78
 
79 79
 
80
-        javaWriter.arrayLoad(arrayTypeInfo.type);
81
-        javaWriter.store(arrayTypeInfo.type, arrayTypeInfo.local);
82
-        content.accept(statementVisitor);
83
-        javaWriter.iinc(z);
84
-    }
80
+		javaWriter.arrayLoad(arrayTypeInfo.type);
81
+		javaWriter.store(arrayTypeInfo.type, arrayTypeInfo.local);
82
+		content.accept(statementVisitor);
83
+		javaWriter.iinc(z);
84
+	}
85 85
 
86
-    @Override
87
-    public Void visitCustomIterator() {
88
-        return null;
89
-    }
86
+	@Override
87
+	public Void visitCustomIterator() {
88
+		return null;
89
+	}
90 90
 
91 91
 	@Override
92 92
 	public Void visitAssocKeyIterator() {

+ 2
- 14
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java Voir le fichier

@@ -5,26 +5,14 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode.compiler;
7 7
 
8
-import org.openzen.zenscript.codemodel.type.ArrayTypeID;
9
-import org.openzen.zenscript.codemodel.type.AssocTypeID;
10
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
11
-import org.openzen.zenscript.codemodel.type.ConstTypeID;
12
-import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
-import org.openzen.zenscript.codemodel.type.FunctionTypeID;
14
-import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
15
-import org.openzen.zenscript.codemodel.type.GenericTypeID;
16
-import org.openzen.zenscript.codemodel.type.ITypeVisitor;
17
-import org.openzen.zenscript.codemodel.type.IteratorTypeID;
18
-import org.openzen.zenscript.codemodel.type.OptionalTypeID;
19
-import org.openzen.zenscript.codemodel.type.RangeTypeID;
8
+import org.openzen.zenscript.codemodel.type.*;
20 9
 
21 10
 /**
22
- *
23 11
  * @author Hoofdgebruiker
24 12
  */
25 13
 public class JavaOptionalTypeClassVisitor implements ITypeVisitor<Class> {
26 14
 	private final JavaTypeClassVisitor base;
27
-	
15
+
28 16
 	public JavaOptionalTypeClassVisitor(JavaTypeClassVisitor base) {
29 17
 		this.base = base;
30 18
 	}

+ 20
- 87
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java Voir le fichier

@@ -6,84 +6,17 @@
6 6
 package org.openzen.zenscript.javabytecode.compiler;
7 7
 
8 8
 import org.objectweb.asm.Type;
9
-import org.openzen.zenscript.codemodel.expression.AndAndExpression;
10
-import org.openzen.zenscript.codemodel.expression.ArrayExpression;
11
-import org.openzen.zenscript.codemodel.expression.CompareExpression;
12
-import org.openzen.zenscript.codemodel.expression.CallExpression;
13
-import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14
-import org.openzen.zenscript.codemodel.expression.CapturedClosureExpression;
15
-import org.openzen.zenscript.codemodel.expression.CapturedDirectExpression;
16
-import org.openzen.zenscript.codemodel.expression.CapturedLocalVariableExpression;
17
-import org.openzen.zenscript.codemodel.expression.CapturedParameterExpression;
18
-import org.openzen.zenscript.codemodel.expression.CapturedThisExpression;
19
-import org.openzen.zenscript.codemodel.expression.CastExpression;
20
-import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
21
-import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
22
-import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
23
-import org.openzen.zenscript.codemodel.expression.ConstExpression;
24
-import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
25
-import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
26
-import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
27
-import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
28
-import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
29
-import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
30
-import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
31
-import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
32
-import org.openzen.zenscript.codemodel.expression.ConstantShortExpression;
33
-import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
34
-import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
35
-import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
36
-import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
37
-import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
38
-import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
39
-import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
40
-import org.openzen.zenscript.codemodel.expression.ExpressionVisitor;
41
-import org.openzen.zenscript.codemodel.expression.FunctionExpression;
42
-import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43
-import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44
-import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
-import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46
-import org.openzen.zenscript.codemodel.expression.GetterExpression;
47
-import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
48
-import org.openzen.zenscript.codemodel.expression.GlobalExpression;
49
-import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
50
-import org.openzen.zenscript.codemodel.expression.IsExpression;
51
-import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
52
-import org.openzen.zenscript.codemodel.expression.MapExpression;
53
-import org.openzen.zenscript.codemodel.expression.MatchExpression;
54
-import org.openzen.zenscript.codemodel.expression.NewExpression;
55
-import org.openzen.zenscript.codemodel.expression.NullExpression;
56
-import org.openzen.zenscript.codemodel.expression.OrOrExpression;
57
-import org.openzen.zenscript.codemodel.expression.PanicExpression;
58
-import org.openzen.zenscript.codemodel.expression.PostCallExpression;
59
-import org.openzen.zenscript.codemodel.expression.RangeExpression;
60
-import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
61
-import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
62
-import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
63
-import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
64
-import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
65
-import org.openzen.zenscript.codemodel.expression.SetterExpression;
66
-import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
67
-import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
68
-import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
69
-import org.openzen.zenscript.codemodel.expression.ThisExpression;
70
-import org.openzen.zenscript.codemodel.expression.ThrowExpression;
71
-import org.openzen.zenscript.codemodel.expression.TryConvertExpression;
72
-import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpression;
73
-import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
74
-import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
75
-import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
9
+import org.openzen.zenscript.codemodel.expression.*;
76 10
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
77 11
 import org.openzen.zenscript.javabytecode.JavaParameterInfo;
78 12
 
79 13
 /**
80
- *
81 14
  * @author Hoofdgebruiker
82 15
  */
83 16
 public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
84 17
 	private final JavaExpressionVisitor expressionCompiler;
85 18
 	private final JavaWriter javaWriter;
86
-	
19
+
87 20
 	public JavaPreDecrementVisitor(JavaExpressionVisitor expressionCompiler) {
88 21
 		this.expressionCompiler = expressionCompiler;
89 22
 		javaWriter = expressionCompiler.getJavaWriter();
@@ -158,7 +91,7 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
158 91
 	public Void visitConditional(ConditionalExpression expression) {
159 92
 		throw new UnsupportedOperationException("Invalid increment target");
160 93
 	}
161
-	
94
+
162 95
 	@Override
163 96
 	public Void visitConst(ConstExpression expression) {
164 97
 		throw new UnsupportedOperationException("Invalid increment target");
@@ -252,22 +185,22 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
252 185
 	@Override
253 186
 	public Void visitGetField(GetFieldExpression expression) {
254 187
 		Type objectType = expression.target.type.accept(new JavaTypeVisitor());
255
-		
188
+
256 189
 		int local = javaWriter.local(objectType);
257 190
 		expression.target.accept(expressionCompiler);
258 191
 		javaWriter.dup();
259 192
 		javaWriter.store(objectType, local);
260
-		
261
-        if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
262
-            throw new IllegalStateException("Missing field info on a field member!");
263
-		
193
+
194
+		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
195
+			throw new IllegalStateException("Missing field info on a field member!");
196
+
264 197
 		javaWriter.iConst1();
265 198
 		javaWriter.iSub();
266
-		
199
+
267 200
 		javaWriter.load(objectType, local);
268
-        if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
269
-            throw new IllegalStateException("Missing field info on a field member!");
270
-		
201
+		if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
202
+			throw new IllegalStateException("Missing field info on a field member!");
203
+
271 204
 		return null;
272 205
 	}
273 206
 
@@ -286,14 +219,14 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
286 219
 	@Override
287 220
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
288 221
 		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
289
-            throw new IllegalStateException("Missing field info on a field member!");
290
-		
222
+			throw new IllegalStateException("Missing field info on a field member!");
223
+
291 224
 		javaWriter.iConst1();
292 225
 		javaWriter.iAdd();
293
-		
226
+
294 227
 		if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
295
-            throw new IllegalStateException("Missing field info on a field member!");
296
-		
228
+			throw new IllegalStateException("Missing field info on a field member!");
229
+
297 230
 		return null;
298 231
 	}
299 232
 
@@ -351,7 +284,7 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
351 284
 	public Void visitOrOr(OrOrExpression expression) {
352 285
 		throw new UnsupportedOperationException("Invalid increment target");
353 286
 	}
354
-	
287
+
355 288
 	@Override
356 289
 	public Void visitPanic(PanicExpression expression) {
357 290
 		throw new UnsupportedOperationException("Invalid increment target");
@@ -366,7 +299,7 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
366 299
 	public Void visitRange(RangeExpression expression) {
367 300
 		throw new UnsupportedOperationException("Invalid increment target");
368 301
 	}
369
-	
302
+
370 303
 	@Override
371 304
 	public Void visitSameObject(SameObjectExpression expression) {
372 305
 		throw new UnsupportedOperationException("Invalid increment target");
@@ -406,7 +339,7 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
406 339
 	public Void visitStaticSetter(StaticSetterExpression expression) {
407 340
 		throw new UnsupportedOperationException("Invalid increment target");
408 341
 	}
409
-	
342
+
410 343
 	@Override
411 344
 	public Void visitSupertypeCast(SupertypeCastExpression expression) {
412 345
 		throw new UnsupportedOperationException("Invalid increment target");

+ 20
- 87
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java Voir le fichier

@@ -6,84 +6,17 @@
6 6
 package org.openzen.zenscript.javabytecode.compiler;
7 7
 
8 8
 import org.objectweb.asm.Type;
9
-import org.openzen.zenscript.codemodel.expression.AndAndExpression;
10
-import org.openzen.zenscript.codemodel.expression.ArrayExpression;
11
-import org.openzen.zenscript.codemodel.expression.CompareExpression;
12
-import org.openzen.zenscript.codemodel.expression.CallExpression;
13
-import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14
-import org.openzen.zenscript.codemodel.expression.CapturedClosureExpression;
15
-import org.openzen.zenscript.codemodel.expression.CapturedDirectExpression;
16
-import org.openzen.zenscript.codemodel.expression.CapturedLocalVariableExpression;
17
-import org.openzen.zenscript.codemodel.expression.CapturedParameterExpression;
18
-import org.openzen.zenscript.codemodel.expression.CapturedThisExpression;
19
-import org.openzen.zenscript.codemodel.expression.CastExpression;
20
-import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
21
-import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
22
-import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
23
-import org.openzen.zenscript.codemodel.expression.ConstExpression;
24
-import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
25
-import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
26
-import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
27
-import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
28
-import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
29
-import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
30
-import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
31
-import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
32
-import org.openzen.zenscript.codemodel.expression.ConstantShortExpression;
33
-import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
34
-import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
35
-import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
36
-import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
37
-import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
38
-import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
39
-import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
40
-import org.openzen.zenscript.codemodel.expression.ExpressionVisitor;
41
-import org.openzen.zenscript.codemodel.expression.FunctionExpression;
42
-import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43
-import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44
-import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
-import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46
-import org.openzen.zenscript.codemodel.expression.GetterExpression;
47
-import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
48
-import org.openzen.zenscript.codemodel.expression.GlobalExpression;
49
-import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
50
-import org.openzen.zenscript.codemodel.expression.IsExpression;
51
-import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
52
-import org.openzen.zenscript.codemodel.expression.MapExpression;
53
-import org.openzen.zenscript.codemodel.expression.MatchExpression;
54
-import org.openzen.zenscript.codemodel.expression.NewExpression;
55
-import org.openzen.zenscript.codemodel.expression.NullExpression;
56
-import org.openzen.zenscript.codemodel.expression.OrOrExpression;
57
-import org.openzen.zenscript.codemodel.expression.PanicExpression;
58
-import org.openzen.zenscript.codemodel.expression.PostCallExpression;
59
-import org.openzen.zenscript.codemodel.expression.RangeExpression;
60
-import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
61
-import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
62
-import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
63
-import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
64
-import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
65
-import org.openzen.zenscript.codemodel.expression.SetterExpression;
66
-import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
67
-import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
68
-import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
69
-import org.openzen.zenscript.codemodel.expression.ThisExpression;
70
-import org.openzen.zenscript.codemodel.expression.ThrowExpression;
71
-import org.openzen.zenscript.codemodel.expression.TryConvertExpression;
72
-import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpression;
73
-import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
74
-import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
75
-import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
9
+import org.openzen.zenscript.codemodel.expression.*;
76 10
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
77 11
 import org.openzen.zenscript.javabytecode.JavaParameterInfo;
78 12
 
79 13
 /**
80
- *
81 14
  * @author Hoofdgebruiker
82 15
  */
83 16
 public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
84 17
 	private final JavaExpressionVisitor expressionCompiler;
85 18
 	private final JavaWriter javaWriter;
86
-	
19
+
87 20
 	public JavaPreIncrementVisitor(JavaExpressionVisitor expressionCompiler) {
88 21
 		this.expressionCompiler = expressionCompiler;
89 22
 		javaWriter = expressionCompiler.getJavaWriter();
@@ -158,7 +91,7 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
158 91
 	public Void visitConditional(ConditionalExpression expression) {
159 92
 		throw new UnsupportedOperationException("Invalid increment target");
160 93
 	}
161
-	
94
+
162 95
 	@Override
163 96
 	public Void visitConst(ConstExpression expression) {
164 97
 		throw new UnsupportedOperationException("Invalid increment target");
@@ -252,23 +185,23 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
252 185
 	@Override
253 186
 	public Void visitGetField(GetFieldExpression expression) {
254 187
 		Type objectType = expression.target.type.accept(new JavaTypeVisitor());
255
-		
188
+
256 189
 		int local = javaWriter.local(objectType);
257 190
 		expression.target.accept(expressionCompiler);
258 191
 		javaWriter.dup();
259 192
 		javaWriter.store(objectType, local);
260
-		
261
-        if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
262
-            throw new IllegalStateException("Missing field info on a field member!");
263
-		
193
+
194
+		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
195
+			throw new IllegalStateException("Missing field info on a field member!");
196
+
264 197
 		javaWriter.iConst1();
265 198
 		javaWriter.iAdd();
266
-		
199
+
267 200
 		javaWriter.load(objectType, local);
268 201
 		javaWriter.dupX1();
269
-        if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
270
-            throw new IllegalStateException("Missing field info on a field member!");
271
-		
202
+		if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
203
+			throw new IllegalStateException("Missing field info on a field member!");
204
+
272 205
 		return null;
273 206
 	}
274 207
 
@@ -291,15 +224,15 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
291 224
 	@Override
292 225
 	public Void visitGetStaticField(GetStaticFieldExpression expression) {
293 226
 		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
294
-            throw new IllegalStateException("Missing field info on a field member!");
295
-		
227
+			throw new IllegalStateException("Missing field info on a field member!");
228
+
296 229
 		javaWriter.iConst1();
297 230
 		javaWriter.iAdd();
298 231
 		javaWriter.dup();
299
-		
232
+
300 233
 		if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
301
-            throw new IllegalStateException("Missing field info on a field member!");
302
-		
234
+			throw new IllegalStateException("Missing field info on a field member!");
235
+
303 236
 		return null;
304 237
 	}
305 238
 
@@ -357,7 +290,7 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
357 290
 	public Void visitOrOr(OrOrExpression expression) {
358 291
 		throw new UnsupportedOperationException("Invalid increment target");
359 292
 	}
360
-	
293
+
361 294
 	@Override
362 295
 	public Void visitPanic(PanicExpression expression) {
363 296
 		throw new UnsupportedOperationException("Invalid increment target");
@@ -372,7 +305,7 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
372 305
 	public Void visitRange(RangeExpression expression) {
373 306
 		throw new UnsupportedOperationException("Invalid increment target");
374 307
 	}
375
-	
308
+
376 309
 	@Override
377 310
 	public Void visitSameObject(SameObjectExpression expression) {
378 311
 		throw new UnsupportedOperationException("Invalid increment target");
@@ -412,7 +345,7 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
412 345
 	public Void visitStaticSetter(StaticSetterExpression expression) {
413 346
 		throw new UnsupportedOperationException("Invalid increment target");
414 347
 	}
415
-	
348
+
416 349
 	@Override
417 350
 	public Void visitSupertypeCast(SupertypeCastExpression expression) {
418 351
 		throw new UnsupportedOperationException("Invalid increment target");

+ 3
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaScriptFile.java Voir le fichier

@@ -5,18 +5,18 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode.compiler;
7 7
 
8
+import org.openzen.zenscript.javabytecode.JavaMethodInfo;
9
+
8 10
 import java.util.ArrayList;
9 11
 import java.util.List;
10
-import org.openzen.zenscript.javabytecode.JavaMethodInfo;
11 12
 
12 13
 /**
13
- *
14 14
  * @author Hoofdgebruiker
15 15
  */
16 16
 public class JavaScriptFile {
17 17
 	public final JavaClassWriter classWriter;
18 18
 	public final List<JavaMethodInfo> scriptMethods;
19
-	
19
+
20 20
 	public JavaScriptFile(JavaClassWriter classWriter) {
21 21
 		this.classWriter = classWriter;
22 22
 		this.scriptMethods = new ArrayList<>();

+ 308
- 308
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java Voir le fichier

@@ -12,312 +12,312 @@ import java.util.Arrays;
12 12
 import java.util.List;
13 13
 
14 14
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
15
-    private final JavaWriter javaWriter;
16
-    public JavaExpressionVisitor expressionVisitor;
17
-
18
-    /**
19
-     * @param javaWriter the method writer that compiles the statement
20
-     */
21
-    public JavaStatementVisitor(JavaWriter javaWriter) {
22
-        this.javaWriter = javaWriter;
23
-        this.expressionVisitor = new JavaExpressionVisitor(javaWriter);
24
-    }
25
-
26
-    public JavaStatementVisitor(JavaExpressionVisitor expressionVisitor) {
27
-        this.javaWriter = expressionVisitor.getJavaWriter();
28
-        this.expressionVisitor = expressionVisitor;
29
-    }
30
-
31
-    @Override
32
-    public Boolean visitBlock(BlockStatement statement) {
33
-        Boolean returns = false;
34
-        for (Statement statement1 : statement.statements) {
35
-            returns = statement1.accept(this);
36
-        }
37
-        return returns;
38
-    }
39
-
40
-    @Override
41
-    public Boolean visitBreak(BreakStatement statement) {
42
-        javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_end"));
43
-        return false;
44
-    }
45
-
46
-    @Override
47
-    public Boolean visitContinue(ContinueStatement statement) {
48
-        javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_start"));
49
-        return false;
50
-    }
51
-
52
-    @Override
53
-    public Boolean visitDoWhile(DoWhileStatement statement) {
54
-        Label start = new Label();
55
-        Label end = new Label();
56
-        if (statement.label == null)
57
-            statement.label = javaWriter.createLabelName() + "DoWhile";
58
-        javaWriter.putNamedLabel(start, statement.label + "_start");
59
-        javaWriter.putNamedLabel(end, statement.label + "_end");
60
-        javaWriter.label(start);
61
-        statement.content.accept(this);
62
-
63
-        statement.condition.accept(expressionVisitor);
64
-        javaWriter.ifNE(start);
65
-
66
-        //Only needed for break statements, should be nop if not used
67
-        javaWriter.label(end);
68
-        return false;
69
-    }
70
-
71
-    @Override
72
-    public Boolean visitEmpty(EmptyStatement statement) {
73
-        //No-Op
74
-        return false;
75
-    }
76
-
77
-    @Override
78
-    public Boolean visitExpression(ExpressionStatement statement) {
79
-        statement.expression.accept(expressionVisitor);
80
-        return false;
81
-    }
82
-
83
-    @Override
84
-    public Boolean visitForeach(ForeachStatement statement) {
85
-        //Create Labels
86
-        Label start = new Label();
87
-        Label end = new Label();
88
-        if (statement.label == null) {
89
-            statement.label = javaWriter.createLabelName() + "ForEach";
90
-        }
91
-        javaWriter.putNamedLabel(start, statement.label + "_start");
92
-        javaWriter.putNamedLabel(end, statement.label + "_end");
93
-
94
-
95
-        //Compile Array/Collection
96
-        statement.list.accept(expressionVisitor);
97
-
98
-        //Create local variables
99
-        for (VarStatement variable : statement.loopVariables) {
100
-            final Type type = Type.getType(variable.type.accept(JavaTypeClassVisitor.INSTANCE));
101
-            final Label variableStart = new Label();
102
-            final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, javaWriter.local(type), variableStart, variable.name);
103
-            info.end = end;
104
-            variable.setTag(JavaLocalVariableInfo.class, info);
105
-            javaWriter.addVariableInfo(info);
106
-        }
107
-
108
-        //javaWriter.label(min);
109
-        statement.iterator.target.acceptForIterator(new JavaForeachVisitor(this, statement.loopVariables, statement.content, start, end));
110
-        javaWriter.goTo(start);
111
-        javaWriter.label(end);
112
-        return false;
113
-    }
114
-
115
-    @Override
116
-    public Boolean visitIf(IfStatement statement) {
117
-        statement.condition.accept(expressionVisitor);
118
-        Label onElse = null;
119
-        Label end = new Label();
120
-        final boolean hasElse = statement.onElse != null;
121
-        if (hasElse) {
122
-            onElse = new Label();
123
-            javaWriter.ifEQ(onElse);
124
-        } else {
125
-            javaWriter.ifEQ(end);
126
-        }
127
-        statement.onThen.accept(this);
128
-        if (hasElse) {
129
-            javaWriter.goTo(end);
130
-            javaWriter.label(onElse);
131
-            statement.onElse.accept(this);
132
-        }
133
-        javaWriter.label(end);
134
-        return false;
135
-    }
136
-
137
-    @Override
138
-    public Boolean visitLock(LockStatement statement) {
139
-        return false;
140
-    }
141
-
142
-    @Override
143
-    public Boolean visitReturn(ReturnStatement statement) {
144
-        statement.value.accept(expressionVisitor);
145
-        javaWriter.returnType(Type.getType(statement.value.type.accept(JavaTypeClassVisitor.INSTANCE)));
146
-        return true;
147
-    }
148
-
149
-    @Override
150
-    public Boolean visitSwitch(SwitchStatement statement) {
151
-
152
-        final Label start = new Label();
153
-        final Label end = new Label();
154
-
155
-        if (statement.label == null)
156
-            statement.label = javaWriter.createLabelName() + "Switch";
157
-
158
-        javaWriter.putNamedLabel(start, statement.label + "_start");
159
-        javaWriter.putNamedLabel(end, statement.label + "_end");
160
-
161
-
162
-        javaWriter.label(start);
163
-        statement.value.accept(expressionVisitor);
164
-        if (statement.value.type == BasicTypeID.STRING)
165
-            javaWriter.invokeVirtual(new JavaMethodInfo(new JavaClassInfo("java/lang/Object"), "hashCode", "()I", 0));
166
-        boolean out = false;
167
-
168
-        final boolean hasNoDefault = hasNoDefault(statement);
169
-
170
-        final List<SwitchCase> cases = statement.cases;
171
-        final JavaSwitchLabel[] switchLabels = new JavaSwitchLabel[hasNoDefault ? cases.size() : cases.size() - 1];
172
-        final Label defaultLabel = new Label();
173
-
174
-        int i = 0;
175
-        for (final SwitchCase switchCase : cases) {
176
-            if (switchCase.value != null) {
177
-                switchLabels[i++] = new JavaSwitchLabel(CompilerUtils.getKeyForSwitch(switchCase.value), new Label());
178
-            }
179
-        }
180
-
181
-        JavaSwitchLabel[] sortedSwitchLabels = Arrays.copyOf(switchLabels, switchLabels.length);
182
-        Arrays.sort(sortedSwitchLabels, (a, b) -> a.key - b.key);
183
-
184
-        javaWriter.lookupSwitch(defaultLabel, sortedSwitchLabels);
185
-
186
-        i = 0;
187
-        for (final SwitchCase switchCase : cases) {
188
-            if (hasNoDefault || switchCase.value != null) {
189
-                javaWriter.label(switchLabels[i++].label);
190
-            } else {
191
-                javaWriter.label(defaultLabel);
192
-            }
193
-            for (Statement statement1 : switchCase.statements) {
194
-                out |= statement1.accept(this);
195
-            }
196
-        }
197
-
198
-        if (hasNoDefault)
199
-            javaWriter.label(defaultLabel);
200
-
201
-        javaWriter.label(end);
202
-
203
-
204
-        //throw new UnsupportedOperationException("Not yet implemented!");
205
-        return out;
206
-    }
207
-
208
-    private boolean hasNoDefault(SwitchStatement switchStatement) {
209
-        for (SwitchCase switchCase : switchStatement.cases)
210
-            if (switchCase.value == null) return false;
211
-        return true;
212
-    }
213
-
214
-    @Override
215
-    public Boolean visitThrow(ThrowStatement statement) {
216
-        statement.value.accept(expressionVisitor);
217
-        javaWriter.aThrow();
218
-        return false;
219
-    }
220
-
221
-    @Override
222
-    public Boolean visitTryCatch(TryCatchStatement statement) {
223
-        final Label tryCatchStart = new Label();
224
-        final Label tryFinish = new Label();
225
-        final Label tryCatchFinish = new Label();
226
-        final Label finallyStart = new Label();
227
-
228
-        javaWriter.label(tryCatchStart);
229
-        //TODO Check for returns or breaks out of the try-catch and inject finally block before them
230
-        statement.content.accept(this);
231
-        javaWriter.label(tryFinish);
232
-        if (statement.finallyClause != null)
233
-            statement.finallyClause.accept(this);
234
-        javaWriter.goTo(tryCatchFinish);
235
-
236
-        for (CatchClause catchClause : statement.catchClauses) {
237
-            final Label catchStart = new Label();
238
-            javaWriter.label(catchStart);
239
-
240
-            //final Type exceptionType = Type.getType(RuntimeException.class);
241
-            final Type exceptionType = Type.getType(catchClause.exceptionVariable.type.accept(JavaTypeClassVisitor.INSTANCE));
242
-            final int local = javaWriter.local(exceptionType);
243
-            javaWriter.store(exceptionType, local);
244
-
245
-            catchClause.content.accept(this);
246
-            final Label catchFinish = new Label();
247
-            javaWriter.label(catchFinish);
248
-
249
-            if (statement.finallyClause != null) {
250
-                statement.finallyClause.accept(this);
251
-                javaWriter.tryCatch(catchStart, catchFinish, finallyStart, null);
252
-            }
253
-
254
-            javaWriter.tryCatch(tryCatchStart, tryFinish, catchStart, exceptionType.getInternalName());
255
-            javaWriter.goTo(tryCatchFinish);
256
-        }
257
-
258
-        if (statement.finallyClause != null) {
259
-            javaWriter.label(finallyStart);
260
-            final int local = javaWriter.local(Object.class);
261
-            javaWriter.storeObject(local);
262
-            statement.finallyClause.accept(this);
263
-            javaWriter.loadObject(local);
264
-            javaWriter.aThrow();
265
-            javaWriter.tryCatch(tryCatchStart, tryFinish, finallyStart, null);
266
-        }
267
-        javaWriter.label(tryCatchFinish);
268
-
269
-        return false;
270
-    }
271
-
272
-    @Override
273
-    public Boolean visitVar(VarStatement statement) {
274
-
275
-        if (statement.initializer != null) {
276
-            statement.initializer.accept(expressionVisitor);
277
-        }
278
-
279
-        Type type = statement.type.accept(JavaTypeVisitor.INSTANCE);
280
-        int local = javaWriter.local(type);
281
-        if (statement.initializer != null)
282
-            javaWriter.store(type, local);
283
-        final Label variableStart = new Label();
284
-        javaWriter.label(variableStart);
285
-        final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, local, variableStart, statement.name);
286
-        statement.setTag(JavaLocalVariableInfo.class, info);
287
-        javaWriter.addVariableInfo(info);
288
-        return false;
289
-    }
290
-
291
-    @Override
292
-    public Boolean visitWhile(WhileStatement statement) {
293
-        Label start = new Label();
294
-        Label end = new Label();
295
-
296
-        if (statement.label == null) {
297
-            statement.label = javaWriter.createLabelName() + "WhileDo";
298
-        }
299
-        javaWriter.putNamedLabel(start, statement.label + "_start");
300
-        javaWriter.putNamedLabel(end, statement.label + "_end");
301
-
302
-        javaWriter.label(start);
303
-        statement.condition.accept(expressionVisitor);
304
-        javaWriter.ifEQ(end);
305
-        statement.content.accept(this);
306
-        javaWriter.goTo(start);
307
-        javaWriter.label(end);
308
-        return false;
309
-    }
310
-
311
-    public void start() {
312
-        javaWriter.start();
313
-    }
314
-
315
-    public void end() {
316
-        javaWriter.ret();
317
-        javaWriter.end();
318
-    }
319
-
320
-    public JavaWriter getJavaWriter() {
321
-        return javaWriter;
322
-    }
15
+	private final JavaWriter javaWriter;
16
+	public JavaExpressionVisitor expressionVisitor;
17
+
18
+	/**
19
+	 * @param javaWriter the method writer that compiles the statement
20
+	 */
21
+	public JavaStatementVisitor(JavaWriter javaWriter) {
22
+		this.javaWriter = javaWriter;
23
+		this.expressionVisitor = new JavaExpressionVisitor(javaWriter);
24
+	}
25
+
26
+	public JavaStatementVisitor(JavaExpressionVisitor expressionVisitor) {
27
+		this.javaWriter = expressionVisitor.getJavaWriter();
28
+		this.expressionVisitor = expressionVisitor;
29
+	}
30
+
31
+	@Override
32
+	public Boolean visitBlock(BlockStatement statement) {
33
+		Boolean returns = false;
34
+		for (Statement statement1 : statement.statements) {
35
+			returns = statement1.accept(this);
36
+		}
37
+		return returns;
38
+	}
39
+
40
+	@Override
41
+	public Boolean visitBreak(BreakStatement statement) {
42
+		javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_end"));
43
+		return false;
44
+	}
45
+
46
+	@Override
47
+	public Boolean visitContinue(ContinueStatement statement) {
48
+		javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_start"));
49
+		return false;
50
+	}
51
+
52
+	@Override
53
+	public Boolean visitDoWhile(DoWhileStatement statement) {
54
+		Label start = new Label();
55
+		Label end = new Label();
56
+		if (statement.label == null)
57
+			statement.label = javaWriter.createLabelName() + "DoWhile";
58
+		javaWriter.putNamedLabel(start, statement.label + "_start");
59
+		javaWriter.putNamedLabel(end, statement.label + "_end");
60
+		javaWriter.label(start);
61
+		statement.content.accept(this);
62
+
63
+		statement.condition.accept(expressionVisitor);
64
+		javaWriter.ifNE(start);
65
+
66
+		//Only needed for break statements, should be nop if not used
67
+		javaWriter.label(end);
68
+		return false;
69
+	}
70
+
71
+	@Override
72
+	public Boolean visitEmpty(EmptyStatement statement) {
73
+		//No-Op
74
+		return false;
75
+	}
76
+
77
+	@Override
78
+	public Boolean visitExpression(ExpressionStatement statement) {
79
+		statement.expression.accept(expressionVisitor);
80
+		return false;
81
+	}
82
+
83
+	@Override
84
+	public Boolean visitForeach(ForeachStatement statement) {
85
+		//Create Labels
86
+		Label start = new Label();
87
+		Label end = new Label();
88
+		if (statement.label == null) {
89
+			statement.label = javaWriter.createLabelName() + "ForEach";
90
+		}
91
+		javaWriter.putNamedLabel(start, statement.label + "_start");
92
+		javaWriter.putNamedLabel(end, statement.label + "_end");
93
+
94
+
95
+		//Compile Array/Collection
96
+		statement.list.accept(expressionVisitor);
97
+
98
+		//Create local variables
99
+		for (VarStatement variable : statement.loopVariables) {
100
+			final Type type = Type.getType(variable.type.accept(JavaTypeClassVisitor.INSTANCE));
101
+			final Label variableStart = new Label();
102
+			final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, javaWriter.local(type), variableStart, variable.name);
103
+			info.end = end;
104
+			variable.setTag(JavaLocalVariableInfo.class, info);
105
+			javaWriter.addVariableInfo(info);
106
+		}
107
+
108
+		//javaWriter.label(min);
109
+		statement.iterator.target.acceptForIterator(new JavaForeachVisitor(this, statement.loopVariables, statement.content, start, end));
110
+		javaWriter.goTo(start);
111
+		javaWriter.label(end);
112
+		return false;
113
+	}
114
+
115
+	@Override
116
+	public Boolean visitIf(IfStatement statement) {
117
+		statement.condition.accept(expressionVisitor);
118
+		Label onElse = null;
119
+		Label end = new Label();
120
+		final boolean hasElse = statement.onElse != null;
121
+		if (hasElse) {
122
+			onElse = new Label();
123
+			javaWriter.ifEQ(onElse);
124
+		} else {
125
+			javaWriter.ifEQ(end);
126
+		}
127
+		statement.onThen.accept(this);
128
+		if (hasElse) {
129
+			javaWriter.goTo(end);
130
+			javaWriter.label(onElse);
131
+			statement.onElse.accept(this);
132
+		}
133
+		javaWriter.label(end);
134
+		return false;
135
+	}
136
+
137
+	@Override
138
+	public Boolean visitLock(LockStatement statement) {
139
+		return false;
140
+	}
141
+
142
+	@Override
143
+	public Boolean visitReturn(ReturnStatement statement) {
144
+		statement.value.accept(expressionVisitor);
145
+		javaWriter.returnType(Type.getType(statement.value.type.accept(JavaTypeClassVisitor.INSTANCE)));
146
+		return true;
147
+	}
148
+
149
+	@Override
150
+	public Boolean visitSwitch(SwitchStatement statement) {
151
+
152
+		final Label start = new Label();
153
+		final Label end = new Label();
154
+
155
+		if (statement.label == null)
156
+			statement.label = javaWriter.createLabelName() + "Switch";
157
+
158
+		javaWriter.putNamedLabel(start, statement.label + "_start");
159
+		javaWriter.putNamedLabel(end, statement.label + "_end");
160
+
161
+
162
+		javaWriter.label(start);
163
+		statement.value.accept(expressionVisitor);
164
+		if (statement.value.type == BasicTypeID.STRING)
165
+			javaWriter.invokeVirtual(new JavaMethodInfo(new JavaClassInfo("java/lang/Object"), "hashCode", "()I", 0));
166
+		boolean out = false;
167
+
168
+		final boolean hasNoDefault = hasNoDefault(statement);
169
+
170
+		final List<SwitchCase> cases = statement.cases;
171
+		final JavaSwitchLabel[] switchLabels = new JavaSwitchLabel[hasNoDefault ? cases.size() : cases.size() - 1];
172
+		final Label defaultLabel = new Label();
173
+
174
+		int i = 0;
175
+		for (final SwitchCase switchCase : cases) {
176
+			if (switchCase.value != null) {
177
+				switchLabels[i++] = new JavaSwitchLabel(CompilerUtils.getKeyForSwitch(switchCase.value), new Label());
178
+			}
179
+		}
180
+
181
+		JavaSwitchLabel[] sortedSwitchLabels = Arrays.copyOf(switchLabels, switchLabels.length);
182
+		Arrays.sort(sortedSwitchLabels, (a, b) -> a.key - b.key);
183
+
184
+		javaWriter.lookupSwitch(defaultLabel, sortedSwitchLabels);
185
+
186
+		i = 0;
187
+		for (final SwitchCase switchCase : cases) {
188
+			if (hasNoDefault || switchCase.value != null) {
189
+				javaWriter.label(switchLabels[i++].label);
190
+			} else {
191
+				javaWriter.label(defaultLabel);
192
+			}
193
+			for (Statement statement1 : switchCase.statements) {
194
+				out |= statement1.accept(this);
195
+			}
196
+		}
197
+
198
+		if (hasNoDefault)
199
+			javaWriter.label(defaultLabel);
200
+
201
+		javaWriter.label(end);
202
+
203
+
204
+		//throw new UnsupportedOperationException("Not yet implemented!");
205
+		return out;
206
+	}
207
+
208
+	private boolean hasNoDefault(SwitchStatement switchStatement) {
209
+		for (SwitchCase switchCase : switchStatement.cases)
210
+			if (switchCase.value == null) return false;
211
+		return true;
212
+	}
213
+
214
+	@Override
215
+	public Boolean visitThrow(ThrowStatement statement) {
216
+		statement.value.accept(expressionVisitor);
217
+		javaWriter.aThrow();
218
+		return false;
219
+	}
220
+
221
+	@Override
222
+	public Boolean visitTryCatch(TryCatchStatement statement) {
223
+		final Label tryCatchStart = new Label();
224
+		final Label tryFinish = new Label();
225
+		final Label tryCatchFinish = new Label();
226
+		final Label finallyStart = new Label();
227
+
228
+		javaWriter.label(tryCatchStart);
229
+		//TODO Check for returns or breaks out of the try-catch and inject finally block before them
230
+		statement.content.accept(this);
231
+		javaWriter.label(tryFinish);
232
+		if (statement.finallyClause != null)
233
+			statement.finallyClause.accept(this);
234
+		javaWriter.goTo(tryCatchFinish);
235
+
236
+		for (CatchClause catchClause : statement.catchClauses) {
237
+			final Label catchStart = new Label();
238
+			javaWriter.label(catchStart);
239
+
240
+			//final Type exceptionType = Type.getType(RuntimeException.class);
241
+			final Type exceptionType = Type.getType(catchClause.exceptionVariable.type.accept(JavaTypeClassVisitor.INSTANCE));
242
+			final int local = javaWriter.local(exceptionType);
243
+			javaWriter.store(exceptionType, local);
244
+
245
+			catchClause.content.accept(this);
246
+			final Label catchFinish = new Label();
247
+			javaWriter.label(catchFinish);
248
+
249
+			if (statement.finallyClause != null) {
250
+				statement.finallyClause.accept(this);
251
+				javaWriter.tryCatch(catchStart, catchFinish, finallyStart, null);
252
+			}
253
+
254
+			javaWriter.tryCatch(tryCatchStart, tryFinish, catchStart, exceptionType.getInternalName());
255
+			javaWriter.goTo(tryCatchFinish);
256
+		}
257
+
258
+		if (statement.finallyClause != null) {
259
+			javaWriter.label(finallyStart);
260
+			final int local = javaWriter.local(Object.class);
261
+			javaWriter.storeObject(local);
262
+			statement.finallyClause.accept(this);
263
+			javaWriter.loadObject(local);
264
+			javaWriter.aThrow();
265
+			javaWriter.tryCatch(tryCatchStart, tryFinish, finallyStart, null);
266
+		}
267
+		javaWriter.label(tryCatchFinish);
268
+
269
+		return false;
270
+	}
271
+
272
+	@Override
273
+	public Boolean visitVar(VarStatement statement) {
274
+
275
+		if (statement.initializer != null) {
276
+			statement.initializer.accept(expressionVisitor);
277
+		}
278
+
279
+		Type type = statement.type.accept(JavaTypeVisitor.INSTANCE);
280
+		int local = javaWriter.local(type);
281
+		if (statement.initializer != null)
282
+			javaWriter.store(type, local);
283
+		final Label variableStart = new Label();
284
+		javaWriter.label(variableStart);
285
+		final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, local, variableStart, statement.name);
286
+		statement.setTag(JavaLocalVariableInfo.class, info);
287
+		javaWriter.addVariableInfo(info);
288
+		return false;
289
+	}
290
+
291
+	@Override
292
+	public Boolean visitWhile(WhileStatement statement) {
293
+		Label start = new Label();
294
+		Label end = new Label();
295
+
296
+		if (statement.label == null) {
297
+			statement.label = javaWriter.createLabelName() + "WhileDo";
298
+		}
299
+		javaWriter.putNamedLabel(start, statement.label + "_start");
300
+		javaWriter.putNamedLabel(end, statement.label + "_end");
301
+
302
+		javaWriter.label(start);
303
+		statement.condition.accept(expressionVisitor);
304
+		javaWriter.ifEQ(end);
305
+		statement.content.accept(this);
306
+		javaWriter.goTo(start);
307
+		javaWriter.label(end);
308
+		return false;
309
+	}
310
+
311
+	public void start() {
312
+		javaWriter.start();
313
+	}
314
+
315
+	public void end() {
316
+		javaWriter.ret();
317
+		javaWriter.end();
318
+	}
319
+
320
+	public JavaWriter getJavaWriter() {
321
+		return javaWriter;
322
+	}
323 323
 }

+ 1
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaSwitchLabel.java Voir le fichier

@@ -8,13 +8,12 @@ package org.openzen.zenscript.javabytecode.compiler;
8 8
 import org.objectweb.asm.Label;
9 9
 
10 10
 /**
11
- *
12 11
  * @author Hoofdgebruiker
13 12
  */
14 13
 public class JavaSwitchLabel {
15 14
 	public final int key;
16 15
 	public final Label label;
17
-	
16
+
18 17
 	public JavaSwitchLabel(int key, Label label) {
19 18
 		this.key = key;
20 19
 		this.label = label;

+ 75
- 75
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java Voir le fichier

@@ -9,92 +9,92 @@ import java.util.Map;
9 9
 
10 10
 public class JavaTypeClassVisitor implements ITypeVisitor<Class> {
11 11
 
12
-    public static final JavaTypeClassVisitor INSTANCE = new JavaTypeClassVisitor();
12
+	public static final JavaTypeClassVisitor INSTANCE = new JavaTypeClassVisitor();
13 13
 	private final JavaOptionalTypeClassVisitor optional = new JavaOptionalTypeClassVisitor(this);
14 14
 
15
-    @Override
16
-    public Class visitBasic(BasicTypeID basic) {
17
-        switch (basic) {
18
-            case VOID:
19
-                return void.class;
20
-            case NULL:
21
-            case UNDETERMINED:
22
-                return Object.class;
23
-            case BOOL:
24
-                return boolean.class;
25
-            case BYTE:
26
-            case SBYTE:
27
-                return byte.class;
28
-            case SHORT:
29
-            case USHORT:
30
-                return short.class;
31
-            case INT:
32
-            case UINT:
33
-                return int.class;
34
-            case LONG:
35
-            case ULONG:
36
-                return long.class;
37
-            case FLOAT:
38
-                return float.class;
39
-            case DOUBLE:
40
-                return double.class;
41
-            case CHAR:
42
-                return char.class;
43
-            case STRING:
44
-                return String.class;
45
-        }
46
-        return Object.class;
47
-    }
15
+	@Override
16
+	public Class visitBasic(BasicTypeID basic) {
17
+		switch (basic) {
18
+			case VOID:
19
+				return void.class;
20
+			case NULL:
21
+			case UNDETERMINED:
22
+				return Object.class;
23
+			case BOOL:
24
+				return boolean.class;
25
+			case BYTE:
26
+			case SBYTE:
27
+				return byte.class;
28
+			case SHORT:
29
+			case USHORT:
30
+				return short.class;
31
+			case INT:
32
+			case UINT:
33
+				return int.class;
34
+			case LONG:
35
+			case ULONG:
36
+				return long.class;
37
+			case FLOAT:
38
+				return float.class;
39
+			case DOUBLE:
40
+				return double.class;
41
+			case CHAR:
42
+				return char.class;
43
+			case STRING:
44
+				return String.class;
45
+		}
46
+		return Object.class;
47
+	}
48 48
 
49
-    @Override
50
-    public Class visitArray(ArrayTypeID array) {
51
-        return Array.newInstance(array.elementType.accept(this), 0).getClass();
52
-    }
49
+	@Override
50
+	public Class visitArray(ArrayTypeID array) {
51
+		return Array.newInstance(array.elementType.accept(this), 0).getClass();
52
+	}
53 53
 
54
-    @Override
55
-    public Class visitAssoc(AssocTypeID assoc) {
56
-        return Map.class;
57
-    }
54
+	@Override
55
+	public Class visitAssoc(AssocTypeID assoc) {
56
+		return Map.class;
57
+	}
58 58
 
59
-    @Override
60
-    public Class visitIterator(IteratorTypeID iterator) {
61
-        return Iterator.class;
62
-    }
59
+	@Override
60
+	public Class visitIterator(IteratorTypeID iterator) {
61
+		return Iterator.class;
62
+	}
63 63
 
64
-    @Override
65
-    public Class visitFunction(FunctionTypeID function) {
66
-        try {
67
-            return new JavaModule().new ScriptClassLoader().loadClass(CompilerUtils.getLambdaInterface(function.header));
68
-        } catch (ClassNotFoundException e) {
69
-            return null;
70
-        }
71
-        //return function.header.returnType.accept(this);
72
-    }
64
+	@Override
65
+	public Class visitFunction(FunctionTypeID function) {
66
+		try {
67
+			return new JavaModule().new ScriptClassLoader().loadClass(CompilerUtils.getLambdaInterface(function.header));
68
+		} catch (ClassNotFoundException e) {
69
+			return null;
70
+		}
71
+		//return function.header.returnType.accept(this);
72
+	}
73 73
 
74
-    @Override
75
-    public Class visitDefinition(DefinitionTypeID definition) {
76
-        return null;
77
-    }
74
+	@Override
75
+	public Class visitDefinition(DefinitionTypeID definition) {
76
+		return null;
77
+	}
78 78
 
79
-    @Override
80
-    public Class visitGeneric(GenericTypeID generic) {
81
-        return null;
82
-    }
79
+	@Override
80
+	public Class visitGeneric(GenericTypeID generic) {
81
+		return null;
82
+	}
83 83
 
84
-    @Override
85
-    public Class visitRange(RangeTypeID range) {
86
-        return null;
87
-    }
84
+	@Override
85
+	public Class visitRange(RangeTypeID range) {
86
+		return null;
87
+	}
88 88
 
89
-    @Override
90
-    public Class visitConst(ConstTypeID type) {
91
-        return type.baseType.accept(this);
92
-    }
89
+	@Override
90
+	public Class visitConst(ConstTypeID type) {
91
+		return type.baseType.accept(this);
92
+	}
93 93
 
94
-    @Override
95
-    public Class visitOptional(OptionalTypeID optional) {
96
-        return optional.baseType.accept(this.optional);
97
-    }
94
+	@Override
95
+	public Class visitOptional(OptionalTypeID optional) {
96
+		return optional.baseType.accept(this.optional);
97
+	}
98 98
 
99 99
 	@Override
100 100
 	public Class visitGenericMap(GenericMapTypeID map) {

+ 42
- 42
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeVisitor.java Voir le fichier

@@ -4,58 +4,58 @@ import org.objectweb.asm.Type;
4 4
 import org.openzen.zenscript.codemodel.type.*;
5 5
 
6 6
 public class JavaTypeVisitor implements ITypeVisitor<Type> {
7
-    public static final JavaTypeVisitor INSTANCE = new JavaTypeVisitor();
7
+	public static final JavaTypeVisitor INSTANCE = new JavaTypeVisitor();
8 8
 
9
-    @Override
10
-    public Type visitBasic(BasicTypeID basic) {
11
-        return Type.getType(basic.accept(JavaTypeClassVisitor.INSTANCE));
12
-    }
9
+	@Override
10
+	public Type visitBasic(BasicTypeID basic) {
11
+		return Type.getType(basic.accept(JavaTypeClassVisitor.INSTANCE));
12
+	}
13 13
 
14
-    @Override
15
-    public Type visitArray(ArrayTypeID array) {
16
-        return Type.getType(array.accept(JavaTypeClassVisitor.INSTANCE));
17
-    }
14
+	@Override
15
+	public Type visitArray(ArrayTypeID array) {
16
+		return Type.getType(array.accept(JavaTypeClassVisitor.INSTANCE));
17
+	}
18 18
 
19
-    @Override
20
-    public Type visitAssoc(AssocTypeID assoc) {
21
-        return Type.getType(assoc.accept(JavaTypeClassVisitor.INSTANCE));
22
-    }
19
+	@Override
20
+	public Type visitAssoc(AssocTypeID assoc) {
21
+		return Type.getType(assoc.accept(JavaTypeClassVisitor.INSTANCE));
22
+	}
23 23
 
24
-    @Override
25
-    public Type visitIterator(IteratorTypeID iterator) {
26
-        return Type.getType(iterator.accept(JavaTypeClassVisitor.INSTANCE));
27
-    }
24
+	@Override
25
+	public Type visitIterator(IteratorTypeID iterator) {
26
+		return Type.getType(iterator.accept(JavaTypeClassVisitor.INSTANCE));
27
+	}
28 28
 
29
-    @Override
30
-    public Type visitFunction(FunctionTypeID function) {
31
-        Class clazz = function.accept(JavaTypeClassVisitor.INSTANCE);
32
-        return clazz != null ? Type.getType(clazz) : Type.getType("L" + CompilerUtils.getLambdaInterface(function.header) + ";");
33
-    }
29
+	@Override
30
+	public Type visitFunction(FunctionTypeID function) {
31
+		Class clazz = function.accept(JavaTypeClassVisitor.INSTANCE);
32
+		return clazz != null ? Type.getType(clazz) : Type.getType("L" + CompilerUtils.getLambdaInterface(function.header) + ";");
33
+	}
34 34
 
35
-    @Override
36
-    public Type visitDefinition(DefinitionTypeID definition) {
37
-        return Type.getType("L" + definition + ";");
38
-    }
35
+	@Override
36
+	public Type visitDefinition(DefinitionTypeID definition) {
37
+		return Type.getType("L" + definition + ";");
38
+	}
39 39
 
40
-    @Override
41
-    public Type visitGeneric(GenericTypeID generic) {
42
-        return Type.getType(generic.accept(JavaTypeClassVisitor.INSTANCE));
43
-    }
40
+	@Override
41
+	public Type visitGeneric(GenericTypeID generic) {
42
+		return Type.getType(generic.accept(JavaTypeClassVisitor.INSTANCE));
43
+	}
44 44
 
45
-    @Override
46
-    public Type visitRange(RangeTypeID range) {
47
-        return Type.getType(range.accept(JavaTypeClassVisitor.INSTANCE));
48
-    }
45
+	@Override
46
+	public Type visitRange(RangeTypeID range) {
47
+		return Type.getType(range.accept(JavaTypeClassVisitor.INSTANCE));
48
+	}
49 49
 
50
-    @Override
51
-    public Type visitConst(ConstTypeID type) {
52
-        return Type.getType(type.accept(JavaTypeClassVisitor.INSTANCE));
53
-    }
50
+	@Override
51
+	public Type visitConst(ConstTypeID type) {
52
+		return Type.getType(type.accept(JavaTypeClassVisitor.INSTANCE));
53
+	}
54 54
 
55
-    @Override
56
-    public Type visitOptional(OptionalTypeID optional) {
57
-        return Type.getType(optional.accept(JavaTypeClassVisitor.INSTANCE));
58
-    }
55
+	@Override
56
+	public Type visitOptional(OptionalTypeID optional) {
57
+		return Type.getType(optional.accept(JavaTypeClassVisitor.INSTANCE));
58
+	}
59 59
 
60 60
 	@Override
61 61
 	public Type visitGenericMap(GenericMapTypeID map) {

+ 944
- 952
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 107
- 109
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java Voir le fichier

@@ -3,7 +3,6 @@ package org.openzen.zenscript.javabytecode.compiler.definitions;
3 3
 import org.objectweb.asm.ClassWriter;
4 4
 import org.objectweb.asm.Opcodes;
5 5
 import org.objectweb.asm.Type;
6
-import org.openzen.zenscript.codemodel.FunctionParameter;
7 6
 import org.openzen.zenscript.codemodel.definition.*;
8 7
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
9 8
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -11,7 +10,6 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
11 10
 import org.openzen.zenscript.javabytecode.JavaClassInfo;
12 11
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
13 12
 import org.openzen.zenscript.javabytecode.JavaModule;
14
-import org.openzen.zenscript.javabytecode.JavaParameterInfo;
15 13
 import org.openzen.zenscript.javabytecode.compiler.*;
16 14
 
17 15
 
@@ -22,7 +20,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
22 20
 			"forName",
23 21
 			"(Ljava/lang/String;)Ljava/lang/Class;",
24 22
 			Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
25
-	
23
+
26 24
 	private static final JavaClassInfo T_ENUM = new JavaClassInfo("java/lang/Enum");
27 25
 	private static final JavaMethodInfo ENUM_VALUEOF = new JavaMethodInfo(
28 26
 			T_ENUM,
@@ -30,127 +28,127 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
30 28
 			"(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;",
31 29
 			Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
32 30
 
33
-    private final JavaClassWriter outerWriter;
31
+	private final JavaClassWriter outerWriter;
34 32
 
35
-    public JavaDefinitionVisitor(JavaClassWriter outerWriter) {
33
+	public JavaDefinitionVisitor(JavaClassWriter outerWriter) {
36 34
 
37
-        this.outerWriter = outerWriter;
38
-    }
35
+		this.outerWriter = outerWriter;
36
+	}
39 37
 
40
-    @Override
41
-    public byte[] visitClass(ClassDefinition definition) {
42
-        //Classes will always be created in a new File/Class
38
+	@Override
39
+	public byte[] visitClass(ClassDefinition definition) {
40
+		//Classes will always be created in a new File/Class
43 41
 
44
-        final Type superType;
45
-        if (definition.superType == null)
46
-            superType = Type.getType(Object.class);
47
-        else
48
-            superType = Type.getType(definition.superType.accept(JavaTypeClassVisitor.INSTANCE));
42
+		final Type superType;
43
+		if (definition.superType == null)
44
+			superType = Type.getType(Object.class);
45
+		else
46
+			superType = Type.getType(definition.superType.accept(JavaTypeClassVisitor.INSTANCE));
49 47
 
50 48
 		JavaClassInfo toClass = new JavaClassInfo(definition.name);
51
-        JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
49
+		JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
52 50
 
53
-        //TODO: Calculate signature from generic parameters
54
-        //TODO: Interfaces?
55
-        String signature = null;
51
+		//TODO: Calculate signature from generic parameters
52
+		//TODO: Interfaces?
53
+		String signature = null;
56 54
 
57 55
 
58
-        writer.visit(Opcodes.V1_8, definition.modifiers, definition.name, signature, superType.getInternalName(), null);
59
-		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(writer, toClass, definition); 
60
-        for (IDefinitionMember member : definition.members) {
61
-            member.accept(memberVisitor);
62
-        }
56
+		writer.visit(Opcodes.V1_8, definition.modifiers, definition.name, signature, superType.getInternalName(), null);
57
+		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(writer, toClass, definition);
58
+		for (IDefinitionMember member : definition.members) {
59
+			member.accept(memberVisitor);
60
+		}
63 61
 		memberVisitor.end();
64
-        writer.visitEnd();
65
-        return writer.toByteArray();
66
-    }
62
+		writer.visitEnd();
63
+		return writer.toByteArray();
64
+	}
67 65
 
68
-    @Override
69
-    public byte[] visitInterface(InterfaceDefinition definition) {
66
+	@Override
67
+	public byte[] visitInterface(InterfaceDefinition definition) {
70 68
 		JavaClassInfo toClass = new JavaClassInfo(definition.name);
71
-        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
69
+		ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
72 70
 
73
-        //TODO: Calculate signature from generic parameters
74
-        //TODO: Extending Interfaces?
75
-        String signature = null;
76
-        writer.visit(Opcodes.V1_8, definition.modifiers | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, definition.name, signature, Type.getInternalName(Object.class), null);
71
+		//TODO: Calculate signature from generic parameters
72
+		//TODO: Extending Interfaces?
73
+		String signature = null;
74
+		writer.visit(Opcodes.V1_8, definition.modifiers | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, definition.name, signature, Type.getInternalName(Object.class), null);
77 75
 		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(writer, toClass, definition);
78
-        for (IDefinitionMember member : definition.members) {
79
-            member.accept(memberVisitor);
80
-        }
76
+		for (IDefinitionMember member : definition.members) {
77
+			member.accept(memberVisitor);
78
+		}
81 79
 		memberVisitor.end();
82
-        writer.visitEnd();
83
-        return writer.toByteArray();
84
-    }
80
+		writer.visitEnd();
81
+		return writer.toByteArray();
82
+	}
85 83
 
86
-    @Override
87
-    public byte[] visitEnum(EnumDefinition definition) {
84
+	@Override
85
+	public byte[] visitEnum(EnumDefinition definition) {
88 86
 		System.out.println("Compiling enum " + definition.name + " in " + definition.position.filename);
89
-		
90
-        final Type superType;
91
-        if (definition.superType == null)
92
-            superType = Type.getType(Object.class);
93
-        else
94
-            superType = Type.getType(definition.superType.accept(JavaTypeClassVisitor.INSTANCE));
95 87
 
96
-        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
88
+		final Type superType;
89
+		if (definition.superType == null)
90
+			superType = Type.getType(Object.class);
91
+		else
92
+			superType = Type.getType(definition.superType.accept(JavaTypeClassVisitor.INSTANCE));
93
+
94
+		ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
97 95
 
98
-        writer.visit(Opcodes.V1_8, Opcodes.ACC_ENUM | Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL, definition.name, "Ljava/lang/Enum<L" + definition.name + ";>;", superType.getInternalName(), null);
96
+		writer.visit(Opcodes.V1_8, Opcodes.ACC_ENUM | Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL, definition.name, "Ljava/lang/Enum<L" + definition.name + ";>;", superType.getInternalName(), null);
99 97
 
100 98
 		JavaClassInfo toClass = new JavaClassInfo(definition.name, true);
101 99
 
102
-        //Enum Stuff(required!)
103
-        writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, "$VALUES", "[L" + definition.name + ";", null, null).visitEnd();
100
+		//Enum Stuff(required!)
101
+		writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, "$VALUES", "[L" + definition.name + ";", null, null).visitEnd();
102
+
103
+		final JavaMemberVisitor visitor = new JavaMemberVisitor(writer, toClass, definition);
104
+		for (IDefinitionMember member : definition.members) {
105
+			member.accept(visitor);
106
+		}
104 107
 
105
-        final JavaMemberVisitor visitor = new JavaMemberVisitor(writer, toClass, definition);
106
-        for (IDefinitionMember member : definition.members) {
107
-            member.accept(visitor);
108
-        }
109
-		
110 108
 		JavaClassInfo arrayClass = new JavaClassInfo("[L" + definition.name + ";");
111 109
 		JavaMethodInfo arrayClone = new JavaMethodInfo(arrayClass, "clone", "()Ljava/lang/Object;", Opcodes.ACC_PUBLIC);
112 110
 
113 111
 		JavaMethodInfo valuesMethodInfo = new JavaMethodInfo(toClass, "values", "()[L" + definition.name + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
114
-        JavaWriter valuesWriter = new JavaWriter(writer, true, valuesMethodInfo, definition, null, null);
115
-        valuesWriter.start();
116
-        valuesWriter.getStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
117
-        valuesWriter.invokeVirtual(arrayClone);
118
-        valuesWriter.checkCast("[L" + definition.name + ";");
119
-        valuesWriter.returnObject();
120
-        valuesWriter.end();
112
+		JavaWriter valuesWriter = new JavaWriter(writer, true, valuesMethodInfo, definition, null, null);
113
+		valuesWriter.start();
114
+		valuesWriter.getStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
115
+		valuesWriter.invokeVirtual(arrayClone);
116
+		valuesWriter.checkCast("[L" + definition.name + ";");
117
+		valuesWriter.returnObject();
118
+		valuesWriter.end();
121 119
 
122 120
 		JavaMethodInfo valueOfMethodInfo = new JavaMethodInfo(toClass, "valueOf", "(Ljava/lang/String;)L" + definition.name + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
123
-        JavaWriter valueOfWriter = new JavaWriter(writer, true, valueOfMethodInfo, definition, null, null);
124
-        valueOfWriter.start();
125
-        valueOfWriter.invokeStatic(CLASS_FORNAME);
126
-        valueOfWriter.loadObject(0);
127
-        valueOfWriter.invokeStatic(ENUM_VALUEOF);
128
-        valueOfWriter.checkCast("L" + definition.name + ";");
129
-        valueOfWriter.returnObject();
130
-        valueOfWriter.end();
131
-
132
-
133
-        writer.visitEnd();
134
-        return writer.toByteArray();
135
-    }
136
-
137
-    @Override
138
-    public byte[] visitStruct(StructDefinition definition) {
139
-        return null;
140
-    }
141
-
142
-    @Override
143
-    public byte[] visitFunction(FunctionDefinition definition) {
121
+		JavaWriter valueOfWriter = new JavaWriter(writer, true, valueOfMethodInfo, definition, null, null);
122
+		valueOfWriter.start();
123
+		valueOfWriter.invokeStatic(CLASS_FORNAME);
124
+		valueOfWriter.loadObject(0);
125
+		valueOfWriter.invokeStatic(ENUM_VALUEOF);
126
+		valueOfWriter.checkCast("L" + definition.name + ";");
127
+		valueOfWriter.returnObject();
128
+		valueOfWriter.end();
129
+
130
+
131
+		writer.visitEnd();
132
+		return writer.toByteArray();
133
+	}
134
+
135
+	@Override
136
+	public byte[] visitStruct(StructDefinition definition) {
137
+		return null;
138
+	}
139
+
140
+	@Override
141
+	public byte[] visitFunction(FunctionDefinition definition) {
144 142
 		CompilerUtils.tagMethodParameters(definition.header, true);
145
-		
146
-        final String signature = CompilerUtils.calcSign(definition.header, false);
147
-		
143
+
144
+		final String signature = CompilerUtils.calcSign(definition.header, false);
145
+
148 146
 		final JavaClassInfo toClass = new JavaClassInfo(CompilerUtils.calcClasName(definition.position));
149 147
 		final JavaMethodInfo methodInfo = new JavaMethodInfo(toClass, definition.name, CompilerUtils.calcDesc(definition.header, false), CompilerUtils.calcAccess(definition.modifiers) | Opcodes.ACC_STATIC);
150 148
 
151 149
 		final JavaWriter writer = new JavaWriter(outerWriter, true, methodInfo, definition, signature, null);
152
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(writer);
153
-        statementVisitor.start();
150
+		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(writer);
151
+		statementVisitor.start();
154 152
 		boolean returns = definition.statement.accept(statementVisitor);
155 153
 		if (!returns) {
156 154
 			ITypeID type = definition.header.returnType;
@@ -159,25 +157,25 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
159 157
 			else if (type != BasicTypeID.VOID)
160 158
 				writer.aConstNull();
161 159
 			writer.returnType(type.accept(JavaTypeVisitor.INSTANCE));
162
-        }
163
-
164
-        statementVisitor.end();
165
-		
166
-        definition.setTag(JavaMethodInfo.class, methodInfo);
167
-        definition.caller.setTag(JavaMethodInfo.class, methodInfo);
168
-        return null;
169
-    }
170
-
171
-    @Override
172
-    public byte[] visitExpansion(ExpansionDefinition definition) {
173
-        return null;
174
-    }
175
-
176
-    @Override
177
-    public byte[] visitAlias(AliasDefinition definition) {
178
-        //TODO would that work?
179
-        return JavaModule.classes.get(definition.name);
180
-    }
160
+		}
161
+
162
+		statementVisitor.end();
163
+
164
+		definition.setTag(JavaMethodInfo.class, methodInfo);
165
+		definition.caller.setTag(JavaMethodInfo.class, methodInfo);
166
+		return null;
167
+	}
168
+
169
+	@Override
170
+	public byte[] visitExpansion(ExpansionDefinition definition) {
171
+		return null;
172
+	}
173
+
174
+	@Override
175
+	public byte[] visitAlias(AliasDefinition definition) {
176
+		//TODO would that work?
177
+		return JavaModule.classes.get(definition.name);
178
+	}
181 179
 
182 180
 	@Override
183 181
 	public byte[] visitVariant(VariantDefinition variant) {

+ 10
- 10
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaInitializedVariables.java Voir le fichier

@@ -6,16 +6,16 @@ import java.util.ArrayList;
6 6
 import java.util.List;
7 7
 
8 8
 public class JavaInitializedVariables {
9
-    public final List<FieldMember> fields;
10
-    public final String owner;
9
+	public final List<FieldMember> fields;
10
+	public final String owner;
11 11
 
12
-    public JavaInitializedVariables(String owner) {
13
-        this.owner = owner;
14
-        fields = new ArrayList<>();
15
-    }
12
+	public JavaInitializedVariables(String owner) {
13
+		this.owner = owner;
14
+		fields = new ArrayList<>();
15
+	}
16 16
 
17
-    public JavaInitializedVariables(List<FieldMember> fields, String owner) {
18
-        this.fields = fields;
19
-        this.owner = owner;
20
-    }
17
+	public JavaInitializedVariables(List<FieldMember> fields, String owner) {
18
+		this.fields = fields;
19
+		this.owner = owner;
20
+	}
21 21
 }

+ 200
- 200
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java Voir le fichier

@@ -19,195 +19,195 @@ import org.openzen.zenscript.javabytecode.compiler.*;
19 19
 import java.util.List;
20 20
 
21 21
 public class JavaMemberVisitor implements MemberVisitor<Void> {
22
-    private final ClassWriter writer;
23
-    private final JavaClassInfo toClass;
24
-    private final HighLevelDefinition definition;
25
-    private final JavaStatementVisitor clinitStatementVisitor;
26
-    private EnumDefinition enumDefinition = null;
27
-
28
-    public JavaMemberVisitor(ClassWriter writer, JavaClassInfo toClass, HighLevelDefinition definition) {
29
-        this.writer = writer;
30
-        this.toClass = toClass;
31
-        this.definition = definition;
32
-
33
-        final JavaWriter javaWriter = new JavaWriter(writer, new JavaMethodInfo(toClass, "<clinit>", "()V", 0), definition, null, null);
34
-        this.clinitStatementVisitor = new JavaStatementVisitor(javaWriter);
35
-        this.clinitStatementVisitor.start();
36
-        CompilerUtils.writeDefaultFieldInitializers(javaWriter, definition, true);
37
-    }
38
-	
22
+	private final ClassWriter writer;
23
+	private final JavaClassInfo toClass;
24
+	private final HighLevelDefinition definition;
25
+	private final JavaStatementVisitor clinitStatementVisitor;
26
+	private EnumDefinition enumDefinition = null;
27
+
28
+	public JavaMemberVisitor(ClassWriter writer, JavaClassInfo toClass, HighLevelDefinition definition) {
29
+		this.writer = writer;
30
+		this.toClass = toClass;
31
+		this.definition = definition;
32
+
33
+		final JavaWriter javaWriter = new JavaWriter(writer, new JavaMethodInfo(toClass, "<clinit>", "()V", 0), definition, null, null);
34
+		this.clinitStatementVisitor = new JavaStatementVisitor(javaWriter);
35
+		this.clinitStatementVisitor.start();
36
+		CompilerUtils.writeDefaultFieldInitializers(javaWriter, definition, true);
37
+	}
38
+
39 39
 	@Override
40 40
 	public Void visitConst(ConstMember member) {
41
-        //TODO calc signature
42
-        String signature = null;
43
-        final String descriptor = Type.getDescriptor(member.type.accept(JavaTypeClassVisitor.INSTANCE));
44
-        writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
45
-        member.setTag(JavaFieldInfo.class, new JavaFieldInfo(toClass, member.name, descriptor));
46
-        return null;
47
-	}
48
-
49
-    @Override
50
-    public Void visitField(FieldMember member) {
51
-
52
-        //TODO calc signature
53
-        String signature = null;
54
-        final String descriptor = Type.getDescriptor(member.type.accept(JavaTypeClassVisitor.INSTANCE));
55
-        writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
56
-        member.setTag(JavaFieldInfo.class, new JavaFieldInfo(toClass, member.name, descriptor));
57
-        return null;
58
-    }
59
-
60
-    @Override
61
-    public Void visitConstructor(ConstructorMember member) {
62
-        final boolean isEnum = definition instanceof EnumDefinition;
63
-        String descriptor = CompilerUtils.calcDesc(member.header, isEnum);
64
-        final JavaMethodInfo method = new JavaMethodInfo(toClass, "<init>", descriptor, isEnum ? Opcodes.ACC_PRIVATE : CompilerUtils.calcAccess(member.modifiers));
65
-
66
-        final Label constructorStart = new Label();
67
-        final Label constructorEnd = new Label();
68
-        final JavaWriter constructorWriter = new JavaWriter(writer, method, definition, CompilerUtils.calcSign(member.header, isEnum), null);
69
-        constructorWriter.label(constructorStart);
70
-        CompilerUtils.tagConstructorParameters(member.header, isEnum);
71
-        for (FunctionParameter parameter : member.header.parameters) {
72
-            constructorWriter.nameVariable(
73
-                    parameter.getTag(JavaParameterInfo.class).index,
74
-                    parameter.name,
75
-                    constructorStart,
76
-                    constructorEnd,
77
-                    Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
78
-        }
79
-
80
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(constructorWriter);
81
-        statementVisitor.start();
82
-
83
-        if (!member.isConstructorForwarded()) {
84
-            if (isEnum) {
85
-                System.out.println("Writing enum constructor");
86
-                constructorWriter.getVisitor().newLocal(Type.getType(String.class));
87
-                constructorWriter.getVisitor().newLocal(Type.getType(int.class));
88
-                constructorWriter.loadObject(0);
89
-                constructorWriter.loadObject(1);
90
-                constructorWriter.loadInt(2);
91
-                constructorWriter.invokeSpecial(Type.getInternalName(Enum.class), "<init>", "(Ljava/lang/String;I)V");
92
-            } else if (definition.superType == null) {
93
-                System.out.println("Writing regular constructor");
94
-                constructorWriter.load(Type.getType(Object.class), 0);
95
-                constructorWriter.invokeSpecial(Type.getInternalName(Object.class), "<init>", "()V");
96
-            }
97
-
98
-            CompilerUtils.writeDefaultFieldInitializers(constructorWriter, definition, false);
99
-        }
100
-
101
-        member.body.accept(statementVisitor);
102
-        constructorWriter.label(constructorEnd);
103
-        statementVisitor.end();
104
-        return null;
105
-    }
106
-	
41
+		//TODO calc signature
42
+		String signature = null;
43
+		final String descriptor = Type.getDescriptor(member.type.accept(JavaTypeClassVisitor.INSTANCE));
44
+		writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
45
+		member.setTag(JavaFieldInfo.class, new JavaFieldInfo(toClass, member.name, descriptor));
46
+		return null;
47
+	}
48
+
49
+	@Override
50
+	public Void visitField(FieldMember member) {
51
+
52
+		//TODO calc signature
53
+		String signature = null;
54
+		final String descriptor = Type.getDescriptor(member.type.accept(JavaTypeClassVisitor.INSTANCE));
55
+		writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
56
+		member.setTag(JavaFieldInfo.class, new JavaFieldInfo(toClass, member.name, descriptor));
57
+		return null;
58
+	}
59
+
60
+	@Override
61
+	public Void visitConstructor(ConstructorMember member) {
62
+		final boolean isEnum = definition instanceof EnumDefinition;
63
+		String descriptor = CompilerUtils.calcDesc(member.header, isEnum);
64
+		final JavaMethodInfo method = new JavaMethodInfo(toClass, "<init>", descriptor, isEnum ? Opcodes.ACC_PRIVATE : CompilerUtils.calcAccess(member.modifiers));
65
+
66
+		final Label constructorStart = new Label();
67
+		final Label constructorEnd = new Label();
68
+		final JavaWriter constructorWriter = new JavaWriter(writer, method, definition, CompilerUtils.calcSign(member.header, isEnum), null);
69
+		constructorWriter.label(constructorStart);
70
+		CompilerUtils.tagConstructorParameters(member.header, isEnum);
71
+		for (FunctionParameter parameter : member.header.parameters) {
72
+			constructorWriter.nameVariable(
73
+					parameter.getTag(JavaParameterInfo.class).index,
74
+					parameter.name,
75
+					constructorStart,
76
+					constructorEnd,
77
+					Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
78
+		}
79
+
80
+		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(constructorWriter);
81
+		statementVisitor.start();
82
+
83
+		if (!member.isConstructorForwarded()) {
84
+			if (isEnum) {
85
+				System.out.println("Writing enum constructor");
86
+				constructorWriter.getVisitor().newLocal(Type.getType(String.class));
87
+				constructorWriter.getVisitor().newLocal(Type.getType(int.class));
88
+				constructorWriter.loadObject(0);
89
+				constructorWriter.loadObject(1);
90
+				constructorWriter.loadInt(2);
91
+				constructorWriter.invokeSpecial(Type.getInternalName(Enum.class), "<init>", "(Ljava/lang/String;I)V");
92
+			} else if (definition.superType == null) {
93
+				System.out.println("Writing regular constructor");
94
+				constructorWriter.load(Type.getType(Object.class), 0);
95
+				constructorWriter.invokeSpecial(Type.getInternalName(Object.class), "<init>", "()V");
96
+			}
97
+
98
+			CompilerUtils.writeDefaultFieldInitializers(constructorWriter, definition, false);
99
+		}
100
+
101
+		member.body.accept(statementVisitor);
102
+		constructorWriter.label(constructorEnd);
103
+		statementVisitor.end();
104
+		return null;
105
+	}
106
+
107 107
 	@Override
108 108
 	public Void visitDestructor(DestructorMember member) {
109 109
 		final JavaMethodInfo method = new JavaMethodInfo(toClass, "close", "()V", Opcodes.ACC_PUBLIC);
110 110
 
111
-        final Label constructorStart = new Label();
112
-        final Label constructorEnd = new Label();
113
-        final JavaWriter destructorWriter = new JavaWriter(writer, method, definition, null, null);
114
-        destructorWriter.label(constructorStart);
111
+		final Label constructorStart = new Label();
112
+		final Label constructorEnd = new Label();
113
+		final JavaWriter destructorWriter = new JavaWriter(writer, method, definition, null, null);
114
+		destructorWriter.label(constructorStart);
115 115
 
116
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(destructorWriter);
117
-        statementVisitor.start();
116
+		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(destructorWriter);
117
+		statementVisitor.start();
118 118
 		// TODO: destruction of members (to be done when memory tags are implemented)
119
-        member.body.accept(statementVisitor);
120
-        destructorWriter.label(constructorEnd);
121
-        statementVisitor.end();
122
-        return null;
123
-	}
124
-
125
-    @Override
126
-    public Void visitMethod(MethodMember member) {
127
-        CompilerUtils.tagMethodParameters(member.header, member.isStatic());
128
-
129
-        final boolean isAbstract = member.body == null || Modifiers.isAbstract(member.modifiers);
130
-        int modifiers = (isAbstract ? Opcodes.ACC_ABSTRACT : 0)
131
-                | (member.isStatic() ? Opcodes.ACC_STATIC : 0)
132
-                | CompilerUtils.calcAccess(member.modifiers);
133
-        final JavaMethodInfo method = new JavaMethodInfo(
134
-                toClass,
135
-                member.name,
136
-                CompilerUtils.calcSign(member.header, false),
137
-                modifiers);
138
-
139
-        final Label methodStart = new Label();
140
-        final Label methodEnd = new Label();
141
-        final JavaWriter methodWriter = new JavaWriter(writer, method, definition, CompilerUtils.calcSign(member.header, false), null);
142
-        methodWriter.label(methodStart);
143
-        for (final FunctionParameter parameter : member.header.parameters) {
144
-            methodWriter.nameParameter(0, parameter.name);
145
-            if (!isAbstract)
146
-                methodWriter.nameVariable(parameter.getTag(JavaParameterInfo.class).index, parameter.name, methodStart, methodEnd, Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
147
-        }
148
-
149
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(methodWriter);
150
-
151
-        if (!isAbstract) {
152
-            statementVisitor.start();
153
-            member.body.accept(statementVisitor);
154
-            methodWriter.label(methodEnd);
155
-            statementVisitor.end();
156
-        }
157
-
158
-        member.setTag(JavaMethodInfo.class, method);
159
-        return null;
160
-    }
161
-
162
-    @Override
163
-    public Void visitGetter(GetterMember member) {
164
-        return null;
165
-    }
166
-
167
-    @Override
168
-    public Void visitSetter(SetterMember member) {
169
-        return null;
170
-    }
171
-
172
-    @Override
173
-    public Void visitOperator(OperatorMember member) {
174
-        return null;
175
-    }
176
-
177
-    @Override
178
-    public Void visitCaster(CasterMember member) {
179
-        return null;
180
-    }
181
-
182
-    @Override
183
-    public Void visitCustomIterator(CustomIteratorMember member) {
184
-        return null;
185
-    }
186
-
187
-    @Override
188
-    public Void visitCaller(CallerMember member) {
189
-        return null;
190
-    }
191
-
192
-    @Override
193
-    public Void visitImplementation(ImplementationMember member) {
194
-        return null;
195
-    }
196
-
197
-    @Override
198
-    public Void visitInnerDefinition(InnerDefinitionMember member) {
199
-        return null;
200
-    }
201
-
202
-    @Override
203
-    public Void visitStaticInitializer(StaticInitializerMember member) {
204
-        member.body.accept(clinitStatementVisitor);
205
-        return null;
206
-    }
207
-
208
-    public void end() {
209
-
210
-        if (enumDefinition != null) {
119
+		member.body.accept(statementVisitor);
120
+		destructorWriter.label(constructorEnd);
121
+		statementVisitor.end();
122
+		return null;
123
+	}
124
+
125
+	@Override
126
+	public Void visitMethod(MethodMember member) {
127
+		CompilerUtils.tagMethodParameters(member.header, member.isStatic());
128
+
129
+		final boolean isAbstract = member.body == null || Modifiers.isAbstract(member.modifiers);
130
+		int modifiers = (isAbstract ? Opcodes.ACC_ABSTRACT : 0)
131
+				| (member.isStatic() ? Opcodes.ACC_STATIC : 0)
132
+				| CompilerUtils.calcAccess(member.modifiers);
133
+		final JavaMethodInfo method = new JavaMethodInfo(
134
+				toClass,
135
+				member.name,
136
+				CompilerUtils.calcSign(member.header, false),
137
+				modifiers);
138
+
139
+		final Label methodStart = new Label();
140
+		final Label methodEnd = new Label();
141
+		final JavaWriter methodWriter = new JavaWriter(writer, method, definition, CompilerUtils.calcSign(member.header, false), null);
142
+		methodWriter.label(methodStart);
143
+		for (final FunctionParameter parameter : member.header.parameters) {
144
+			methodWriter.nameParameter(0, parameter.name);
145
+			if (!isAbstract)
146
+				methodWriter.nameVariable(parameter.getTag(JavaParameterInfo.class).index, parameter.name, methodStart, methodEnd, Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
147
+		}
148
+
149
+		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(methodWriter);
150
+
151
+		if (!isAbstract) {
152
+			statementVisitor.start();
153
+			member.body.accept(statementVisitor);
154
+			methodWriter.label(methodEnd);
155
+			statementVisitor.end();
156
+		}
157
+
158
+		member.setTag(JavaMethodInfo.class, method);
159
+		return null;
160
+	}
161
+
162
+	@Override
163
+	public Void visitGetter(GetterMember member) {
164
+		return null;
165
+	}
166
+
167
+	@Override
168
+	public Void visitSetter(SetterMember member) {
169
+		return null;
170
+	}
171
+
172
+	@Override
173
+	public Void visitOperator(OperatorMember member) {
174
+		return null;
175
+	}
176
+
177
+	@Override
178
+	public Void visitCaster(CasterMember member) {
179
+		return null;
180
+	}
181
+
182
+	@Override
183
+	public Void visitCustomIterator(CustomIteratorMember member) {
184
+		return null;
185
+	}
186
+
187
+	@Override
188
+	public Void visitCaller(CallerMember member) {
189
+		return null;
190
+	}
191
+
192
+	@Override
193
+	public Void visitImplementation(ImplementationMember member) {
194
+		return null;
195
+	}
196
+
197
+	@Override
198
+	public Void visitInnerDefinition(InnerDefinitionMember member) {
199
+		return null;
200
+	}
201
+
202
+	@Override
203
+	public Void visitStaticInitializer(StaticInitializerMember member) {
204
+		member.body.accept(clinitStatementVisitor);
205
+		return null;
206
+	}
207
+
208
+	public void end() {
209
+
210
+		if (enumDefinition != null) {
211 211
 			for (EnumConstantMember constant : enumDefinition.enumConstants) {
212 212
 				writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_ENUM, constant.name, "L" + definition.name + ";", null, null).visitEnd();
213 213
 				final String internalName = constant.constructor.type.accept(JavaTypeVisitor.INSTANCE).getInternalName();
@@ -222,25 +222,25 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
222 222
 
223 223
 				clinitWriter.invokeSpecial(internalName, "<init>", CompilerUtils.calcDesc(constant.constructor.constructor.header, true));
224 224
 				clinitWriter.putStaticField(internalName, constant.name, "L" + internalName + ";");
225
-				
225
+
226 226
 				enumDefinition = (EnumDefinition) constant.definition;
227 227
 			}
228
-			
229
-            final JavaWriter clinitWriter = clinitStatementVisitor.getJavaWriter();
230
-            final List<EnumConstantMember> enumConstants = enumDefinition.enumConstants;
231
-            clinitWriter.constant(enumConstants.size());
232
-            clinitWriter.newArray(Type.getType("L" + definition.name + ";"));
233
-
234
-            for (EnumConstantMember enumConstant : enumConstants) {
235
-                clinitWriter.dup();
236
-                clinitWriter.constant(enumConstant.value);
237
-                clinitWriter.getStaticField(definition.name, enumConstant.name, "L" + definition.name + ";");
238
-                clinitWriter.arrayStore(Type.getType("L" + definition.name + ";"));
239
-            }
240
-            clinitWriter.putStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
241
-        }
242
-
243
-
244
-        clinitStatementVisitor.end();
245
-    }
228
+
229
+			final JavaWriter clinitWriter = clinitStatementVisitor.getJavaWriter();
230
+			final List<EnumConstantMember> enumConstants = enumDefinition.enumConstants;
231
+			clinitWriter.constant(enumConstants.size());
232
+			clinitWriter.newArray(Type.getType("L" + definition.name + ";"));
233
+
234
+			for (EnumConstantMember enumConstant : enumConstants) {
235
+				clinitWriter.dup();
236
+				clinitWriter.constant(enumConstant.value);
237
+				clinitWriter.getStaticField(definition.name, enumConstant.name, "L" + definition.name + ";");
238
+				clinitWriter.arrayStore(Type.getType("L" + definition.name + ";"));
239
+			}
240
+			clinitWriter.putStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
241
+		}
242
+
243
+
244
+		clinitStatementVisitor.end();
245
+	}
246 246
 }

Loading…
Annuler
Enregistrer