Skip to content

Commit d9f3218

Browse files
committed
Fixed null comparison.
1 parent 6f2b593 commit d9f3218

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,22 @@ public Void visitCall(CallExpression expression) {
519519
javaWriter.iSub();
520520
}, PushOption.AFTER);
521521
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;
522538
default:
523539
expression.target.accept(this);
524540
for (Expression argument : expression.arguments.arguments) {
@@ -1035,21 +1051,6 @@ public Void visitCall(CallExpression expression) {
10351051
break;
10361052
case AUTOOP_NOTEQUALS:
10371053
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;
10531054

10541055
default:
10551056
throw new UnsupportedOperationException("Unknown builtin: " + builtin);

JavaScripting/configuration.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
group='org.openzen.zencode'
2-
version='0.1.0'
2+
version='0.2.0'

ScriptingExample/scripts/helloworld.zs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ println(1 - 2);
55
println(1 + 3 as long);
66

77
println(<hello world in bracket parser>);
8+
9+
10+
var a = null as string?;
11+
if (a == null)
12+
println("A is null!");

common.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ apply plugin: 'java'
66
apply plugin: 'maven'
77

88
String mavenGroupId = 'org.openzen.zencode'
9-
String mavenVersion = '0.1.2'
9+
String mavenVersion = '0.2.0'
1010

1111
sourceCompatibility = '1.8'
1212
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

0 commit comments

Comments
 (0)