Skip to content

Commit 8d162b0

Browse files
committed
BinOpAst: Add && and || to the operations. This was supported by the parser but never tested
1 parent eb11a30 commit 8d162b0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/org/piccode/ast/BinOpAst.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ public PiccodeValue execute(Integer frame) {
107107
return new PiccodeBoolean(left.equals(right) ? "true" : "false");
108108
}
109109

110+
111+
if (left instanceof PiccodeBoolean lf && right instanceof PiccodeBoolean rh) {
112+
if (op.equals("&&")){
113+
var left = (boolean) lf.raw();
114+
var right = (boolean) rh.raw();
115+
return new PiccodeBoolean(String.valueof(left && right));
116+
}
117+
118+
if (op.equals("||")) {
119+
var left = (boolean) lf.raw();
120+
var right = (boolean) rh.raw();
121+
return new PiccodeBoolean(String.valueof(left || right));
122+
}
123+
}
124+
110125
var err = new PiccodeException(file, line, column,"Operator `" + Chalk.on(op).blue() + "` cannot be used with types "
111126
+ Chalk.on(left.type()).red()
112127
+ " and " + Chalk.on(right.type()).red());

0 commit comments

Comments
 (0)