forked from ground/ground
"not" instruction
This commit is contained in:
@@ -50,6 +50,12 @@ Reference a list (a list reference) with an asterisk:
|
||||
setlist *myList $value1 $value2 # and so on
|
||||
```
|
||||
|
||||
Add comments with a `#`:
|
||||
|
||||
```
|
||||
# This is a comment
|
||||
```
|
||||
|
||||
## Keywords
|
||||
|
||||
Note: &var can be replaced with any direct reference. $value can be replaced with a literal value or a value reference. %1 can be replaced with a line reference.
|
||||
@@ -188,6 +194,12 @@ Checks if two values are not equal. Outputs a boolean to a direct reference.
|
||||
|
||||
Usage: `inequal $value $value &var`
|
||||
|
||||
#### not
|
||||
|
||||
Negates a boolean.
|
||||
|
||||
Usage: `not $value &var`
|
||||
|
||||
#### greater
|
||||
|
||||
Checks if the left value is greater than the right value. Outputs a boolean to a direct reference.
|
||||
|
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