"not" instruction

This commit is contained in:
2025-08-21 11:05:32 +10:00
parent 14758df1ab
commit 50d83aa228
2 changed files with 43 additions and 2 deletions

View File

@@ -53,7 +53,7 @@ enum class Instructions {
Jump, If,
Stdout, Stdin, Stdlnout,
Add, Subtract, Multiply, Divide,
Equal, Inequal, Greater, Lesser,
Equal, Inequal, Greater, Lesser, Not,
End, Set, Empty,
Setlist, Getlistat, Setlistat, Getlistsize, Listappend, Listprepend,
Getstrcharat, Getstrsize,
@@ -1264,6 +1264,35 @@ Literal exec(vector<Instruction> in) {
variables[varName] = final;
}
break;
/*
not instruction
Negates a boolean.
*/
case Instructions::Not:
if (l.args.size() < 2) {
error("Could not find all arguments required for Not inbuilt");
}
{
Literal boolean;
if (holds_alternative<Literal>(l.args[0])) {
if (holds_alternative<bool>(get<Literal>(l.args[0]).val)) {
boolean.val = !(get<bool>(get<Literal>(l.args[0]).val));
} else {
error("First argument of not must be a boolean literal");
}
} else {
error("First argument of not must be a boolean literal");
}
if (holds_alternative<Direct>(l.args[1])) {
variables[get<Direct>(l.args[1]).varName] = boolean;
} else {
error("Second argument of not must be a direct reference");
}
}
break;
/*
greater instruction
This instruction checks if the left value is greater than the right value