forked from ground/ground
Labels
This commit is contained in:
2
Bobfile
2
Bobfile
@@ -1,5 +1,5 @@
|
|||||||
compiler "g++";
|
compiler "g++";
|
||||||
binary "ground";
|
binary "ground";
|
||||||
source "src/main.cpp";
|
source "src/main.cpp";
|
||||||
flag "O3";
|
flag "Ofast";
|
||||||
compile;
|
compile;
|
||||||
|
@@ -35,7 +35,7 @@ Reference a line (a line reference) with a percent symbol before a line number:
|
|||||||
Alternatively, set a label:
|
Alternatively, set a label:
|
||||||
|
|
||||||
```
|
```
|
||||||
@myLabel
|
@myLabel # The '@' symbol denotes setting a label
|
||||||
```
|
```
|
||||||
|
|
||||||
and jump to that (setting labels will be discussed below):
|
and jump to that (setting labels will be discussed below):
|
||||||
|
46
src/main.cpp
46
src/main.cpp
@@ -531,6 +531,52 @@ void exec(vector<Instruction> in) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case Instructions::Getlistsize:
|
||||||
if (l.args.size() < 2) {
|
if (l.args.size() < 2) {
|
||||||
error("Could not find all arguments required for Getlistsize inbuilt");
|
error("Could not find all arguments required for Getlistsize inbuilt");
|
||||||
|
@@ -1,9 +1,13 @@
|
|||||||
setlist *favNums "hello" "there" "general" "kenobi"
|
# A cool list
|
||||||
|
setlist *favWords "hello" "there" "general" "kenobi"
|
||||||
|
|
||||||
set &count 0
|
set &count 0
|
||||||
getlistat *favNums $count &tmp
|
set &passedThrough true
|
||||||
|
|
||||||
|
@jmpbck
|
||||||
|
getlistat *favWords $count &tmp
|
||||||
stdlnout $tmp
|
stdlnout $tmp
|
||||||
add $count 1 &count
|
add $count 1 &count
|
||||||
getlistsize *favNums &tmp2
|
getlistsize *favWords &tmp2
|
||||||
inequal $count $tmp2 &tmp3
|
inequal $count $tmp2 &tmp3
|
||||||
if $tmp3 %3
|
if $tmp3 %jmpbck
|
||||||
stdlnout "finished!"
|
|
||||||
|
Reference in New Issue
Block a user