diff --git a/Bobfile b/Bobfile index c50ee3c..62187c9 100644 --- a/Bobfile +++ b/Bobfile @@ -1,5 +1,5 @@ compiler "g++"; binary "ground"; source "src/main.cpp"; -flag "O3"; +flag "Ofast"; compile; diff --git a/docs/syntax.md b/docs/syntax.md index 4fa9220..3330641 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -35,7 +35,7 @@ Reference a line (a line reference) with a percent symbol before a line number: Alternatively, set a label: ``` - @myLabel + @myLabel # The '@' symbol denotes setting a label ``` and jump to that (setting labels will be discussed below): diff --git a/src/main.cpp b/src/main.cpp index 51665c8..9159375 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -531,6 +531,52 @@ void exec(vector 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(l.args[0])) { + listref = get(l.args[0]); + } else { + error("First argument of setlistat must be a list reference"); + } + + if (holds_alternative(l.args[1])) { + if (holds_alternative(get(l.args[1]).val)) { + ref = get(get(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(l.args[2])) { + value = get(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"); diff --git a/tests/lists.grnd b/tests/lists.grnd index ffa89c6..8b56097 100644 --- a/tests/lists.grnd +++ b/tests/lists.grnd @@ -1,9 +1,13 @@ -setlist *favNums "hello" "there" "general" "kenobi" +# A cool list +setlist *favWords "hello" "there" "general" "kenobi" + set &count 0 -getlistat *favNums $count &tmp +set &passedThrough true + +@jmpbck +getlistat *favWords $count &tmp stdlnout $tmp add $count 1 &count -getlistsize *favNums &tmp2 +getlistsize *favWords &tmp2 inequal $count $tmp2 &tmp3 -if $tmp3 %3 -stdlnout "finished!" +if $tmp3 %jmpbck