Add exists instruction

This commit is contained in:
2025-08-30 10:40:59 +10:00
parent 8247ba36e4
commit 0eb5670dfd
2 changed files with 32 additions and 1 deletions

View File

@@ -116,6 +116,12 @@ Gets the type of a variable. Outputs a string which can be "int", "double", "boo
Usage: `gettype $value &var` Usage: `gettype $value &var`
#### exists
Checks if a variable exists with a direct reference. If the variable exists, outputs true. Otherwise outputs false.
Usage `exists &var1 &var2`
#### setlist #### setlist
Allows you to initialize a list. Allows you to initialize a list.

View File

@@ -73,7 +73,7 @@ enum class Instructions {
Stdout, Stdin, Stdlnout, Stdout, Stdin, Stdlnout,
Add, Subtract, Multiply, Divide, Add, Subtract, Multiply, Divide,
Equal, Inequal, Greater, Lesser, Not, Equal, Inequal, Greater, Lesser, Not,
End, Set, Empty, Gettype, End, Set, Empty, Gettype, Exists,
Setlist, Getlistat, Setlistat, Getlistsize, Listappend, Listprepend, Setlist, Getlistat, Setlistat, Getlistsize, Listappend, Listprepend,
Getstrcharat, Getstrsize, Getstrcharat, Getstrsize,
Stoi, Stod, Tostring, Stoi, Stod, Tostring,
@@ -1655,6 +1655,30 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
} }
break;
case Instructions::Exists:
if (l.args.size() < 2) {
error("Could not find all arguments required for Exists inbuilt");
}
{
Direct ref1;
if (holds_alternative<Direct>(l.args[0])) {
ref1 = get<Direct>(l.args[0]);
} else {
error("First argument of exists must be a direct reference");
}
Direct ref2;
if (holds_alternative<Direct>(l.args[1])) {
ref2 = get<Direct>(l.args[1]);
}
if (variables.find(ref1.varName) != variables.end()) {
variables[ref2.varName].val = true;
} else {
variables[ref2.varName].val = false;
}
}
break; break;
/* /*
fun instruction fun instruction
@@ -2113,6 +2137,7 @@ vector<Instruction> parser(vector<vector<string>> in) {
else if (i == "end") newInst.inst = Instructions::End; else if (i == "end") newInst.inst = Instructions::End;
else if (i == "set") newInst.inst = Instructions::Set; else if (i == "set") newInst.inst = Instructions::Set;
else if (i == "gettype") newInst.inst = Instructions::Gettype; else if (i == "gettype") newInst.inst = Instructions::Gettype;
else if (i == "exists") newInst.inst = Instructions::Exists;
else if (i == "setlist") newInst.inst = Instructions::Setlist; else if (i == "setlist") newInst.inst = Instructions::Setlist;
else if (i == "setlistat") newInst.inst = Instructions::Setlistat; else if (i == "setlistat") newInst.inst = Instructions::Setlistat;
else if (i == "getlistat") newInst.inst = Instructions::Getlistat; else if (i == "getlistat") newInst.inst = Instructions::Getlistat;