forked from ground/ground
Exists for lists and lines
This commit is contained in:
36
src/main.cpp
36
src/main.cpp
@@ -542,7 +542,7 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
newLine.lineNum = (*currentLabels)[ln.label];
|
||||
l.args[j] = newLine;
|
||||
} else {
|
||||
error("Could not find label " + ln.label);
|
||||
if (l.inst != Instructions::Exists) error("Could not find label " + ln.label);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1661,23 +1661,37 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
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]);
|
||||
} else {
|
||||
error("Second argument of exists must be a direct reference");
|
||||
}
|
||||
|
||||
if (variables.find(ref1.varName) != variables.end()) {
|
||||
variables[ref2.varName].val = true;
|
||||
bool exists = false;
|
||||
if (holds_alternative<Direct>(l.args[0])) {
|
||||
if (variables.find(get<Direct>(l.args[0]).varName) != variables.end()) {
|
||||
exists = true;
|
||||
}
|
||||
} else if (holds_alternative<ListRef>(l.args[0])) {
|
||||
if (lists.find(get<ListRef>(l.args[0]).listName) != lists.end()) {
|
||||
exists = true;
|
||||
}
|
||||
} else if (holds_alternative<Line>(l.args[0])) {
|
||||
Line line = get<Line>(l.args[0]);
|
||||
if (line.isLabel) {
|
||||
if (labels.find(line.label) != labels.end()) {
|
||||
exists = true;
|
||||
}
|
||||
} else {
|
||||
if (line.lineNum > 0 && line.lineNum <= in.size()) {
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
variables[ref2.varName].val = false;
|
||||
error("First argument of exists must be a direct, list, or line reference");
|
||||
}
|
||||
variables[ref2.varName].val = exists;
|
||||
}
|
||||
break;
|
||||
/*
|
||||
|
Reference in New Issue
Block a user