|
@@ -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;
|