forked from ground/ground
"not" instruction
This commit is contained in:
31
src/main.cpp
31
src/main.cpp
@@ -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
|
||||
|
Reference in New Issue
Block a user