forked from ground/ground
updates
This commit is contained in:
41
src/main.cpp
41
src/main.cpp
@@ -20,8 +20,8 @@
|
||||
With the licence out of the way, let's begin!
|
||||
|
||||
Ground is a programming language which takes some inspiration from
|
||||
Assembly in it's design, but has higher level features (more types,
|
||||
simpler IO, easier variables, etc) which make it easy to use.
|
||||
Assembly in its design, but has higher level features (more types,
|
||||
simpler IO, easier variables, etc) which makes it easy to use.
|
||||
|
||||
Ground works even better if you write a programming language that
|
||||
compiles to Ground code. Ground is designed to have a similar
|
||||
@@ -54,7 +54,7 @@ enum class Instructions {
|
||||
Add, Subtract, Multiply, Divide,
|
||||
Equal, Inequal, Greater, Lesser,
|
||||
End, Set, Empty,
|
||||
Setlist, Getlistat, Setlistat, Getlistsize
|
||||
Setlist, Getlistat, Setlistat, Getlistsize, Listappend, Listprepend
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -531,6 +531,10 @@ void exec(vector<Instruction> in) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*
|
||||
setlistat instruction
|
||||
This instruction sets an item in a list to be a certain value.
|
||||
*/
|
||||
case Instructions::Setlistat:
|
||||
if (l.args.size() < 3) {
|
||||
error("Could not find all arguments required for Setlistat inbuilt");
|
||||
@@ -573,6 +577,37 @@ void exec(vector<Instruction> in) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*
|
||||
listappend instruction
|
||||
This instruction appends an item to a list.
|
||||
*/
|
||||
case Instructions::Listappend:
|
||||
if (l.args.size() < 2) {
|
||||
error("Could not find all arguments required for Listappend inbuilt");
|
||||
}
|
||||
{
|
||||
ListRef listref;
|
||||
Literal value;
|
||||
|
||||
if (holds_alternative<ListRef>(l.args[0])) {
|
||||
listref = get<ListRef>(l.args[0]);
|
||||
} else {
|
||||
error("Second argument of listappend must be a list reference");
|
||||
}
|
||||
|
||||
if (holds_alternative<Literal>(l.args[1])) {
|
||||
value = get<Literal>(l.args[1]);
|
||||
} else {
|
||||
error("Second argument of listappend must be a direct reference");
|
||||
}
|
||||
|
||||
if (lists.find(listref.listName) != lists.end()) {
|
||||
lists[listref.listName].val.push_back(value);
|
||||
} else {
|
||||
error("Unknown list: " + listref.listName);
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*
|
||||
getlistsize instruction
|
||||
This instruction saves the size of a list in a variable.
|
||||
|
Reference in New Issue
Block a user