made and and or operators short circuits

This commit is contained in:
cozis
2022-08-13 23:37:22 +02:00
parent 8565722bab
commit d24877c5f3
9 changed files with 240 additions and 120 deletions
+8 -2
View File
@@ -4,9 +4,15 @@
1 and 2;
#bytecode
PUSHINT 1;
JUMPIFNOTANDPOP false;
PUSHINT 2;
AND;
JUMPIFNOTANDPOP false;
PUSHTRU;
JUMP end;
false:
PUSHFLS;
end:
POP 1;
RETURN 0;
+7 -1
View File
@@ -6,7 +6,13 @@
#bytecode
PUSHINT 1;
JUMPIFANDPOP true;
PUSHINT 2;
OR;
JUMPIFANDPOP true;
PUSHFLS;
JUMP end;
true:
PUSHTRU;
end:
POP 1;
RETURN 0;
+22 -5
View File
@@ -6,12 +6,29 @@
#bytecode
PUSHVAR "A";
JUMPIFNOTANDPOP false_0;
PUSHVAR "B";
AND;
JUMPIFNOTANDPOP false_0;
PUSHTRU;
JUMP end_0;
false_0:
PUSHFLS;
end_0:
JUMPIFANDPOP true_2;
PUSHVAR "C";
JUMPIFNOTANDPOP false_1;
PUSHVAR "D";
AND;
OR;
JUMPIFNOTANDPOP false_1;
PUSHTRU;
JUMP end_1;
false_1:
PUSHFLS;
end_1:
JUMPIFANDPOP true_2;
PUSHFLS;
JUMP end_2;
true_2:
PUSHTRU;
end_2:
POP 1;
RETURN 0;
RETURN 0;
+27 -10
View File
@@ -4,14 +4,31 @@
X or Y and Z or W;
#bytecode
PUSHVAR "X";
PUSHVAR "Y";
PUSHVAR "Z";
AND;
OR;
PUSHVAR "W";
OR;
POP 1;
RETURN 0;
PUSHVAR "X";
JUMPIFANDPOP true_0;
PUSHVAR "Y";
JUMPIFNOTANDPOP false_1;
PUSHVAR "Z";
JUMPIFNOTANDPOP false_1;
PUSHTRU;
JUMP end_1;
false_1:
PUSHFLS;
end_1:
JUMPIFANDPOP true_0;
PUSHFLS;
JUMP end_0;
true_0:
PUSHTRU;
end_0:
JUMPIFANDPOP true_2;
PUSHVAR "W";
JUMPIFANDPOP true_2;
PUSHFLS;
JUMP end_2;
true_2:
PUSHTRU;
end_2:
POP 1;
RETURN 0;
+7
View File
@@ -69,6 +69,13 @@
assert((false or false) == false);
}
# Test short-circuitness of the logical operators
{
# The assertions shouldn't trigger.
true or assert(false);
false and assert(false);
}
# Test lists.
{
[1]; [1.0]; ['x']; [1, 1]; [1.0, 1.0]; ['x', 'x'];