Browse Source

Fixed null comparison.

Stan Hebben 6 years ago
parent
commit
d9f32182f1

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

@@ -519,6 +519,22 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
519 519
 					javaWriter.iSub();
520 520
 				}, PushOption.AFTER);
521 521
 				return null;
522
+			case OPTIONAL_IS_NULL:
523
+			case OPTIONAL_IS_NOT_NULL:
524
+				expression.target.accept(this);
525
+				final Label isFalse = new Label();
526
+				final Label end = new Label();
527
+
528
+				if(builtin == BuiltinID.OPTIONAL_IS_NULL)
529
+					javaWriter.ifNonNull(isFalse);
530
+				else
531
+					javaWriter.ifNull(isFalse);
532
+				javaWriter.iConst1();
533
+				javaWriter.goTo(end);
534
+				javaWriter.label(isFalse);
535
+				javaWriter.iConst0();
536
+				javaWriter.label(end);
537
+				return null;
522 538
 			default:
523 539
 				expression.target.accept(this);
524 540
 				for (Expression argument : expression.arguments.arguments) {
@@ -1035,21 +1051,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
1035 1051
 				break;
1036 1052
 			case AUTOOP_NOTEQUALS:
1037 1053
 				throw new UnsupportedOperationException("Not yet supported!");
1038
-			case OPTIONAL_IS_NULL:
1039
-			case OPTIONAL_IS_NOT_NULL:
1040
-				final Label isFalse = new Label();
1041
-				final Label end = new Label();
1042
-
1043
-				if(builtin == BuiltinID.OPTIONAL_IS_NULL)
1044
-					javaWriter.ifNonNull(isFalse);
1045
-				else
1046
-					javaWriter.ifNull(isFalse);
1047
-				javaWriter.iConst1();
1048
-				javaWriter.goTo(end);
1049
-				javaWriter.label(isFalse);
1050
-				javaWriter.iConst0();
1051
-				javaWriter.label(end);
1052
-				break;
1053 1054
 
1054 1055
 			default:
1055 1056
 				throw new UnsupportedOperationException("Unknown builtin: " + builtin);

+ 1
- 1
JavaScripting/configuration.gradle View File

@@ -1,2 +1,2 @@
1 1
 group='org.openzen.zencode'
2
-version='0.1.0'
2
+version='0.2.0'

+ 5
- 0
ScriptingExample/scripts/helloworld.zs View File

@@ -5,3 +5,8 @@ println(1 - 2);
5 5
 println(1 + 3 as long);
6 6
 
7 7
 println(<hello world in bracket parser>);
8
+
9
+
10
+var a = null as string?;
11
+if (a == null)
12
+	println("A is null!");

+ 1
- 1
common.gradle View File

@@ -6,7 +6,7 @@ apply plugin: 'java'
6 6
 apply plugin: 'maven'
7 7
 
8 8
 String mavenGroupId = 'org.openzen.zencode'
9
-String mavenVersion = '0.1.2'
9
+String mavenVersion = '0.2.0'
10 10
 
11 11
 sourceCompatibility = '1.8'
12 12
 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

Loading…
Cancel
Save