Browse Source

some minor changes

kindlich 6 years ago
parent
commit
15e1277aaa
No known key found for this signature in database

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaModule.java View File

17
  * @author Hoofdgebruiker
17
  * @author Hoofdgebruiker
18
  */
18
  */
19
 public class JavaModule {
19
 public class JavaModule {
20
-	private final Map<String, byte[]> classes = new HashMap<>();
20
+	public static final Map<String, byte[]> classes = new HashMap<>();
21
 	
21
 	
22
 	public JavaModule() {
22
 	public JavaModule() {
23
 		
23
 		

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

29
 
29
 
30
     @Override
30
     @Override
31
     public Void visitCapturedDirect(CapturedDirectExpression expression) {
31
     public Void visitCapturedDirect(CapturedDirectExpression expression) {
32
-        return null;
32
+        return expression.value.accept(expressionVisitor);
33
     }
33
     }
34
 
34
 
35
     @Override
35
     @Override
36
     public Void visitRecaptured(CapturedClosureExpression expression) {
36
     public Void visitRecaptured(CapturedClosureExpression expression) {
37
-        expression.value.accept(this);
38
-        return null;
37
+        return expression.value.accept(this);
39
     }
38
     }
40
 }
39
 }

+ 24
- 13
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

6
 import org.openzen.zenscript.codemodel.CompareType;
6
 import org.openzen.zenscript.codemodel.CompareType;
7
 import org.openzen.zenscript.codemodel.expression.*;
7
 import org.openzen.zenscript.codemodel.expression.*;
8
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
8
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
9
+import org.openzen.zenscript.codemodel.member.GetterMember;
9
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
10
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
10
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
11
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
11
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
16
 import org.openzen.zenscript.shared.CompileExceptionCode;
17
 import org.openzen.zenscript.shared.CompileExceptionCode;
17
 
18
 
18
 import java.util.Arrays;
19
 import java.util.Arrays;
20
+import java.util.Comparator;
19
 import java.util.Map;
21
 import java.util.Map;
20
 import java.util.StringJoiner;
22
 import java.util.StringJoiner;
21
 
23
 
23
     private static final JavaMethodInfo MAP_PUT = JavaMethodInfo.get(Opcodes.ACC_PUBLIC, Map.class, "put", Object.class, Object.class, Object.class);
25
     private static final JavaMethodInfo MAP_PUT = JavaMethodInfo.get(Opcodes.ACC_PUBLIC, Map.class, "put", Object.class, Object.class, Object.class);
24
 
26
 
25
     private final JavaWriter javaWriter;
27
     private final JavaWriter javaWriter;
28
+    private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
26
 
29
 
27
     public JavaExpressionVisitor(JavaWriter javaWriter) {
30
     public JavaExpressionVisitor(JavaWriter javaWriter) {
28
         this.javaWriter = javaWriter;
31
         this.javaWriter = javaWriter;
119
 
122
 
120
     @Override
123
     @Override
121
     public Void visitCapturedClosure(CapturedClosureExpression expression) {
124
     public Void visitCapturedClosure(CapturedClosureExpression expression) {
122
-        expression.value.accept(this);
123
-        return null;
125
+        return expression.accept(capturedExpressionVisitor);
124
     }
126
     }
125
 
127
 
126
     @Override
128
     @Override
127
     public Void visitCapturedDirect(CapturedDirectExpression expression) {
129
     public Void visitCapturedDirect(CapturedDirectExpression expression) {
128
-        return null;
130
+        return expression.accept(capturedExpressionVisitor);
129
     }
131
     }
130
 
132
 
131
     @Override
133
     @Override
132
     public Void visitCapturedLocalVariable(CapturedLocalVariableExpression expression) {
134
     public Void visitCapturedLocalVariable(CapturedLocalVariableExpression expression) {
133
-        new GetLocalVariableExpression(expression.position, expression.variable).accept(this);
134
-        return null;
135
+        return expression.accept(capturedExpressionVisitor);
135
     }
136
     }
136
 
137
 
137
     @Override
138
     @Override
138
     public Void visitCapturedParameter(CapturedParameterExpression expression) {
139
     public Void visitCapturedParameter(CapturedParameterExpression expression) {
139
-
140
-        return null;
140
+        return expression.accept(capturedExpressionVisitor);
141
     }
141
     }
142
 
142
 
143
     @Override
143
     @Override
144
     public Void visitCapturedThis(CapturedThisExpression expression) {
144
     public Void visitCapturedThis(CapturedThisExpression expression) {
145
-        return null;
145
+        return expression.accept(capturedExpressionVisitor);
146
     }
146
     }
147
 
147
 
148
     @Override
148
     @Override
282
     public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
282
     public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
283
         Type type = expression.objectType.accept(JavaTypeVisitor.INSTANCE);
283
         Type type = expression.objectType.accept(JavaTypeVisitor.INSTANCE);
284
 
284
 
285
+        javaWriter.loadObject(0);
285
         if (javaWriter.method.javaClass.isEnum) {
286
         if (javaWriter.method.javaClass.isEnum) {
286
-            javaWriter.loadObject(0);
287
             javaWriter.loadObject(1);
287
             javaWriter.loadObject(1);
288
             javaWriter.loadInt(2);
288
             javaWriter.loadInt(2);
289
-        } else {
290
-            javaWriter.loadObject(0);
291
         }
289
         }
292
 
290
 
293
         for (Expression argument : expression.arguments.arguments) {
291
         for (Expression argument : expression.arguments.arguments) {
417
 
415
 
418
     @Override
416
     @Override
419
     public Void visitGetter(GetterExpression expression) {
417
     public Void visitGetter(GetterExpression expression) {
418
+        expression.target.accept(this);
419
+        final GetterMember getter = expression.getter;
420
+        //TODO check, since I don't know how to declare getters...
421
+        javaWriter.invokeVirtual(
422
+                new JavaMethodInfo(
423
+                        new JavaClassInfo(
424
+                                expression.target.type.accept(JavaTypeVisitor.INSTANCE).getInternalName(),
425
+                                false),
426
+                        getter.name,
427
+                        CompilerUtils.calcDesc(getter.header, false),
428
+                        CompilerUtils.calcAccess(getter.modifiers)
429
+                )
430
+        );
420
         return null;
431
         return null;
421
     }
432
     }
422
 
433
 
491
         }
502
         }
492
 
503
 
493
         JavaSwitchLabel[] sortedSwitchLabels = Arrays.copyOf(switchLabels, switchLabels.length);
504
         JavaSwitchLabel[] sortedSwitchLabels = Arrays.copyOf(switchLabels, switchLabels.length);
494
-        Arrays.sort(sortedSwitchLabels, (a, b) -> a.key - b.key);
505
+        Arrays.sort(sortedSwitchLabels, Comparator.comparingInt(a -> a.key));
495
 
506
 
496
         javaWriter.lookupSwitch(defaultLabel, sortedSwitchLabels);
507
         javaWriter.lookupSwitch(defaultLabel, sortedSwitchLabels);
497
 
508
 
518
         return null;
529
         return null;
519
     }
530
     }
520
 
531
 
521
-    private boolean hasNoDefault(MatchExpression switchStatement) {
532
+    private static boolean hasNoDefault(MatchExpression switchStatement) {
522
         for (MatchExpression.Case switchCase : switchStatement.cases)
533
         for (MatchExpression.Case switchCase : switchStatement.cases)
523
             if (switchCase.key == null) return false;
534
             if (switchCase.key == null) return false;
524
         return true;
535
         return true;

+ 3
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java View File

9
 import org.openzen.zenscript.codemodel.type.ITypeID;
9
 import org.openzen.zenscript.codemodel.type.ITypeID;
10
 import org.openzen.zenscript.javabytecode.JavaClassInfo;
10
 import org.openzen.zenscript.javabytecode.JavaClassInfo;
11
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
11
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
12
+import org.openzen.zenscript.javabytecode.JavaModule;
12
 import org.openzen.zenscript.javabytecode.compiler.*;
13
 import org.openzen.zenscript.javabytecode.compiler.*;
13
 
14
 
14
 
15
 
172
 
173
 
173
     @Override
174
     @Override
174
     public byte[] visitAlias(AliasDefinition definition) {
175
     public byte[] visitAlias(AliasDefinition definition) {
175
-        return null;
176
+        //TODO would that work?
177
+        return JavaModule.classes.get(definition.name);
176
     }
178
     }
177
 
179
 
178
 	@Override
180
 	@Override

Loading…
Cancel
Save