kindlich преди 6 години
родител
ревизия
15e1277aaa
No known key found for this signature in database

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaModule.java Целия файл

@@ -17,7 +17,7 @@ import java.util.logging.Logger;
17 17
  * @author Hoofdgebruiker
18 18
  */
19 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 22
 	public JavaModule() {
23 23
 		

+ 2
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaCapturedExpressionVisitor.java Целия файл

@@ -29,12 +29,11 @@ public class JavaCapturedExpressionVisitor implements CapturedExpressionVisitor<
29 29
 
30 30
     @Override
31 31
     public Void visitCapturedDirect(CapturedDirectExpression expression) {
32
-        return null;
32
+        return expression.value.accept(expressionVisitor);
33 33
     }
34 34
 
35 35
     @Override
36 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 Целия файл

@@ -6,6 +6,7 @@ import org.objectweb.asm.Type;
6 6
 import org.openzen.zenscript.codemodel.CompareType;
7 7
 import org.openzen.zenscript.codemodel.expression.*;
8 8
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
9
+import org.openzen.zenscript.codemodel.member.GetterMember;
9 10
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
10 11
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
11 12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
@@ -16,6 +17,7 @@ import org.openzen.zenscript.shared.CompileException;
16 17
 import org.openzen.zenscript.shared.CompileExceptionCode;
17 18
 
18 19
 import java.util.Arrays;
20
+import java.util.Comparator;
19 21
 import java.util.Map;
20 22
 import java.util.StringJoiner;
21 23
 
@@ -23,6 +25,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
23 25
     private static final JavaMethodInfo MAP_PUT = JavaMethodInfo.get(Opcodes.ACC_PUBLIC, Map.class, "put", Object.class, Object.class, Object.class);
24 26
 
25 27
     private final JavaWriter javaWriter;
28
+    private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
26 29
 
27 30
     public JavaExpressionVisitor(JavaWriter javaWriter) {
28 31
         this.javaWriter = javaWriter;
@@ -119,30 +122,27 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
119 122
 
120 123
     @Override
121 124
     public Void visitCapturedClosure(CapturedClosureExpression expression) {
122
-        expression.value.accept(this);
123
-        return null;
125
+        return expression.accept(capturedExpressionVisitor);
124 126
     }
125 127
 
126 128
     @Override
127 129
     public Void visitCapturedDirect(CapturedDirectExpression expression) {
128
-        return null;
130
+        return expression.accept(capturedExpressionVisitor);
129 131
     }
130 132
 
131 133
     @Override
132 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 138
     @Override
138 139
     public Void visitCapturedParameter(CapturedParameterExpression expression) {
139
-
140
-        return null;
140
+        return expression.accept(capturedExpressionVisitor);
141 141
     }
142 142
 
143 143
     @Override
144 144
     public Void visitCapturedThis(CapturedThisExpression expression) {
145
-        return null;
145
+        return expression.accept(capturedExpressionVisitor);
146 146
     }
147 147
 
148 148
     @Override
@@ -282,12 +282,10 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
282 282
     public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
283 283
         Type type = expression.objectType.accept(JavaTypeVisitor.INSTANCE);
284 284
 
285
+        javaWriter.loadObject(0);
285 286
         if (javaWriter.method.javaClass.isEnum) {
286
-            javaWriter.loadObject(0);
287 287
             javaWriter.loadObject(1);
288 288
             javaWriter.loadInt(2);
289
-        } else {
290
-            javaWriter.loadObject(0);
291 289
         }
292 290
 
293 291
         for (Expression argument : expression.arguments.arguments) {
@@ -417,6 +415,19 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
417 415
 
418 416
     @Override
419 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 431
         return null;
421 432
     }
422 433
 
@@ -491,7 +502,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
491 502
         }
492 503
 
493 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 507
         javaWriter.lookupSwitch(defaultLabel, sortedSwitchLabels);
497 508
 
@@ -518,7 +529,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
518 529
         return null;
519 530
     }
520 531
 
521
-    private boolean hasNoDefault(MatchExpression switchStatement) {
532
+    private static boolean hasNoDefault(MatchExpression switchStatement) {
522 533
         for (MatchExpression.Case switchCase : switchStatement.cases)
523 534
             if (switchCase.key == null) return false;
524 535
         return true;

+ 3
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java Целия файл

@@ -9,6 +9,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
9 9
 import org.openzen.zenscript.codemodel.type.ITypeID;
10 10
 import org.openzen.zenscript.javabytecode.JavaClassInfo;
11 11
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
12
+import org.openzen.zenscript.javabytecode.JavaModule;
12 13
 import org.openzen.zenscript.javabytecode.compiler.*;
13 14
 
14 15
 
@@ -172,7 +173,8 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
172 173
 
173 174
     @Override
174 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 180
 	@Override

Loading…
Отказ
Запис