Deprecate *list syntax, use &direct refs instead

This commit is contained in:
2025-09-25 08:09:27 +10:00
parent 7066b4300d
commit 81d6e21a00
3 changed files with 59 additions and 74 deletions

View File

@@ -833,12 +833,8 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
else if (holds_alternative<char>(get<Literal>(l.args[0]).val)) {
cout << get<char>(get<Literal>(l.args[0]).val);
}
else {
return error("Couldn't print that", "printError");
}
} else if (holds_alternative<ListRef>(l.args[0])) {
if (variables.find(get<ListRef>(l.args[0]).listName) != variables.end()) {
List list = get<List>(variables[get<ListRef>(l.args[0]).listName].val);
else if (holds_alternative<List>(get<Literal>(l.args[0]).val)) {
List list = get<List>(get<Literal>(l.args[0]).val);
cout << "[";
for (int l = 0; l < list.val.size(); l++) {
if (holds_alternative<string>(list.val[l].val)) {
@@ -867,9 +863,10 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
cout << ", ";
}
}
cout << "]";
} else {
return error("Couldn't find list named " + get<ListRef>(l.args[0]).listName);
cout << "]" << endl;
}
else {
return error("Couldn't print that", "printError");
}
} else {
return error("Argument of stdlnout must be a value (literal or a value reference)");
@@ -904,12 +901,8 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
else if (holds_alternative<char>(get<Literal>(l.args[0]).val)) {
cout << get<char>(get<Literal>(l.args[0]).val) << endl;
}
else {
return error("Couldn't print that", "printError");
}
} else if (holds_alternative<ListRef>(l.args[0])) {
if (variables.find(get<ListRef>(l.args[0]).listName) != variables.end()) {
List list = get<List>(variables[get<ListRef>(l.args[0]).listName].val);
else if (holds_alternative<List>(get<Literal>(l.args[0]).val)) {
List list = get<List>(get<Literal>(l.args[0]).val);
cout << "[";
for (int l = 0; l < list.val.size(); l++) {
if (holds_alternative<string>(list.val[l].val)) {
@@ -939,8 +932,9 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
}
}
cout << "]" << endl;
} else {
return error("Couldn't find list named " + get<ListRef>(l.args[0]).listName);
}
else {
return error("Couldn't print that", "printError");
}
} else {
return error("Argument of stdlnout must be a value (literal or a value reference) or a list reference");
@@ -1096,8 +1090,8 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
string listName;
List listContents;
if (holds_alternative<ListRef>(l.args[0])) {
listName = get<ListRef>(l.args[0]).listName;
if (holds_alternative<Direct>(l.args[0])) {
listName = get<Direct>(l.args[0]).varName;
} else {
return error("First argument of setlist must be a list reference");
}
@@ -1126,12 +1120,12 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Could not find all arguments required for Getlistat inbuilt");
}
{
ListRef listref;
string listref;
int ref;
Direct var;
if (holds_alternative<ListRef>(l.args[0])) {
listref = get<ListRef>(l.args[0]);
if (holds_alternative<Direct>(l.args[0])) {
listref = get<Direct>(l.args[0]).varName;
} else {
return error("First argument of getlistat must be a list reference");
}
@@ -1152,19 +1146,19 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Third argument of getlistat must be a direct reference");
}
if (variables.find(listref.listName) != variables.end()) {
if (holds_alternative<List>(variables[listref.listName].val)) {
if (get<List>(variables[listref.listName].val).val.size() > ref) {
if (variables.find(listref) != variables.end()) {
if (holds_alternative<List>(variables[listref].val)) {
if (get<List>(variables[listref].val).val.size() > ref) {
bool existed = variables.count(var.varName) > 0;
setVal(var.varName, get<List>(variables[listref.listName].val).val[ref]);
setVal(var.varName, get<List>(variables[listref].val).val[ref]);
} else {
return error("Index " + to_string(ref) + " out of range of list " + listref.listName, "rangeError");
return error("Index " + to_string(ref) + " out of range of list " + listref, "rangeError");
}
} else {
return error("Found a normal variable in place of a list");
return error("Variable " + listref + " is not a list");
}
} else {
return error("Unknown list: " + listref.listName);
return error("Unknown list: " + listref);
}
}
break;
@@ -1227,12 +1221,12 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Could not find all arguments required for Setlistat inbuilt");
}
{
ListRef listref;
string listref;
int ref;
Literal value;
if (holds_alternative<ListRef>(l.args[0])) {
listref = get<ListRef>(l.args[0]);
if (holds_alternative<Direct>(l.args[0])) {
listref = get<Direct>(l.args[0]).varName;
} else {
return error("First argument of setlistat must be a list reference");
}
@@ -1252,20 +1246,22 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
} else {
return error("Third argument of setlistat must be a direct reference");
}
if (variables.find(listref.listName) != variables.end()) {
if (holds_alternative<List>(variables[listref.listName].val)) {
if (get<List>(variables[listref.listName].val).val.size() > ref) {
List tmpList = get<List>(variables[listref.listName].val);
if (variables.find(listref) != variables.end()) {
if (holds_alternative<List>(variables[listref].val)) {
if (get<List>(variables[listref].val).val.size() > ref) {
List tmpList = get<List>(variables[listref].val);
tmpList.val[ref] = value;
Literal tmpLit;
tmpLit.val = tmpList;
setVal(listref.listName, tmpLit);
setVal(listref, tmpLit);
} else {
return error("Index " + to_string(ref) + " out of range of list " + listref.listName, "rangeError");
return error("Index " + to_string(ref) + " out of range of list " + listref, "rangeError");
}
} else {
return error("Variable " + listref + " is not a list");
}
} else {
return error("Unknown list: " + listref.listName);
return error("Unknown list: " + listref);
}
}
break;
@@ -1278,11 +1274,11 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Could not find all arguments required for Listappend inbuilt");
}
{
ListRef listref;
string listref;
Literal value;
if (holds_alternative<ListRef>(l.args[0])) {
listref = get<ListRef>(l.args[0]);
if (holds_alternative<Direct>(l.args[0])) {
listref = get<Direct>(l.args[0]).varName;
} else {
return error("First argument of listappend must be a list reference");
}
@@ -1293,17 +1289,17 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Second argument of listappend must be a direct reference");
}
if (variables.find(listref.listName) != variables.end()) {
if (!holds_alternative<List>(variables[listref.listName].val)) {
return error("Variable " + listref.listName + "is not a list");
if (variables.find(listref) != variables.end()) {
if (!holds_alternative<List>(variables[listref].val)) {
return error("Variable " + listref + "is not a list");
}
List tmpList = get<List>(variables[listref.listName].val);
List tmpList = get<List>(variables[listref].val);
tmpList.val.push_back(value);
Literal tmpLit;
tmpLit.val = tmpList;
setVal(listref.listName, tmpLit);
setVal(listref, tmpLit);
} else {
return error("Unknown list: " + listref.listName);
return error("Unknown list: " + listref);
}
}
break;
@@ -1316,11 +1312,11 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Could not find all arguments required for Getlistsize inbuilt");
}
{
ListRef ref;
string ref;
Direct var;
if (holds_alternative<ListRef>(l.args[0])) {
ref = get<ListRef>(l.args[0]);
if (holds_alternative<Direct>(l.args[0])) {
ref = get<Direct>(l.args[0]).varName;
} else {
return error("First argument of getlistsize must be a list reference");
}
@@ -1332,12 +1328,12 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
}
Literal newLit;
if (variables.find(ref.listName) != variables.end()) {
newLit.val = int(get<List>(variables[ref.listName].val).val.size());
if (variables.find(ref) != variables.end()) {
newLit.val = int(get<List>(variables[ref].val).val.size());
bool existed = variables.count(var.varName) > 0;
setVal(var.varName, newLit);
} else {
return error("Couldn't find the list " + ref.listName);
return error("Couldn't find the list " + ref);
}
break;
@@ -2125,10 +2121,6 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
if (variables.find(get<Direct>(l.args[0]).varName) != variables.end()) {
exists = true;
}
} else if (holds_alternative<ListRef>(l.args[0])) {
if (variables.find(get<ListRef>(l.args[0]).listName) != variables.end() && holds_alternative<List>(variables[get<ListRef>(l.args[0]).listName].val)) {
exists = true;
}
} else if (holds_alternative<Line>(l.args[0])) {
Line line = get<Line>(l.args[0]);
if (line.isLabel) {
@@ -2236,8 +2228,6 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
}
if (holds_alternative<Literal>(l.args[0])) {
return get<Literal>(l.args[0]);
} else if (holds_alternative<ListRef>(l.args[0])) {
return variables[get<ListRef>(l.args[0]).listName];
} else {
return error("First argument of return must be a literal value/value reference");
}
@@ -2861,8 +2851,9 @@ vector<Instruction> parser(vector<vector<string>> in) {
break;
case Types::ListRef:
{
ListRef newLR;
newLR.listName = i.substr(1);
cout << "Note: List References are no longer supported and will be removed in future. Please reference lists using a direct reference (&) instead. Converting to a Direct reference." << endl;
Direct newLR;
newLR.varName = i.substr(1);
newInst.args.push_back(newLR);
}
break;