From 50d83aa228c577d683967761c382890900e397f1 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Thu, 21 Aug 2025 11:05:32 +1000 Subject: [PATCH] "not" instruction --- docs/syntax.md | 14 +++++++++++++- src/main.cpp | 31 ++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index ba12a10..34f4d21 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -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. @@ -276,4 +288,4 @@ Attempts to import a shared object library written for Ground. All functions in Note: Ground will check the directory where the program is stored when trying to find external programs. If that fails, it will check the directory set in the $GROUND_PATH environment variable set by your system. The '.so', '.dll', etc extension is appended automatically. -Usage: `extern $stringvalue` \ No newline at end of file +Usage: `extern $stringvalue` diff --git a/src/main.cpp b/src/main.cpp index 46d5a2d..771326a 100644 --- a/src/main.cpp +++ b/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 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(l.args[0])) { + if (holds_alternative(get(l.args[0]).val)) { + boolean.val = !(get(get(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(l.args[1])) { + variables[get(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