This commit is contained in:
2025-08-10 16:08:56 +10:00
parent 3f2482d7ea
commit f8397e85d4
4 changed files with 57 additions and 7 deletions

View File

@@ -531,6 +531,52 @@ void exec(vector<Instruction> in) {
}
}
break;
case Instructions::Setlistat:
if (l.args.size() < 3) {
error("Could not find all arguments required for Setlistat inbuilt");
}
{
ListRef listref;
int ref;
Literal value;
if (holds_alternative<ListRef>(l.args[0])) {
listref = get<ListRef>(l.args[0]);
} else {
error("First argument of setlistat must be a list reference");
}
if (holds_alternative<Literal>(l.args[1])) {
if (holds_alternative<int>(get<Literal>(l.args[1]).val)) {
ref = get<int>(get<Literal>(l.args[1]).val);
} else {
error("Second argument of setlistat must be an integer literal");
}
} else {
error("Second argument of setlistat must be an integer literal");
}
if (holds_alternative<Literal>(l.args[2])) {
value = get<Literal>(l.args[2]);
} else {
error("Third argument of setlistat must be a direct reference");
}
if (lists.find(listref.listName) != lists.end()) {
if (lists[listref.listName].val.size() > ref) {
lists[listref.listName].val[ref] = value;
} else {
error("Index " + to_string(ref) + " out of range of list " + listref.listName);
}
} else {
error("Unknown list: " + listref.listName);
}
}
break;
/*
getlistsize instruction
This instruction saves the size of a list in a variable.
*/
case Instructions::Getlistsize:
if (l.args.size() < 2) {
error("Could not find all arguments required for Getlistsize inbuilt");