1 Commits

Author SHA1 Message Date
945f70d756 Update README.md 2025-09-21 16:13:50 +10:00
5 changed files with 76 additions and 73 deletions

View File

@@ -2,7 +2,7 @@
## What is Ground?
Ground is an interpreter which processes and interprets Ground instructions. It is quite fast, and the syntax is simple.
Ground is a sigma interpreter which processes and interprets Ground instructions. It is quite fast, and the syntax is simple.
## What are the main features of Ground?

View File

@@ -44,6 +44,12 @@ and jump to that (setting labels will be discussed below):
jump %myLabel
```
Reference a list (a list reference) with an asterisk:
```
setlist *myList $value1 $value2 # and so on
```
Add comments with a `#`:
```
@@ -122,31 +128,31 @@ Note: You can also replace &var1 with a list or line reference to check if it al
Allows you to initialize a list.
Usage: `setlist &list $value1 $value2 $value3...`
Usage: `setlist *list $value1 $value2 $value3...`
#### setlistat
Sets a list item at an index. The item at the index must already exist. Lists are index 0.
Usage: `setlistat &list $intvalue $value`
Usage: `setlistat *list $intvalue $value`
#### getlistat
Gets a list item at an index, and puts it in the variable provided. The item at the index must already exist. Lists are index 0.
Usage: `getlistat &list $intvalue &var`
Usage: `getlistat *list $intvalue &var`
#### getlistsize
Gets the size of a list and puts it in the variable provided.
Usage: `getlistsize &list &var`
Usage: `getlistsize *list &var`
#### listappend
Appends an item to a list.
Usage: `listappend &list $var`
Usage: `listappend *list $var`
### String Operations

View File

@@ -735,12 +735,6 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
case Types::Bool:
newVal.val = false;
break;
case Types::List:
{
List newList;
newVal.val = newList;
}
break;
default:
return error("You dingus you werent supposed to get here");
}
@@ -833,8 +827,12 @@ 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 if (holds_alternative<List>(get<Literal>(l.args[0]).val)) {
List list = get<List>(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);
cout << "[";
for (int l = 0; l < list.val.size(); l++) {
if (holds_alternative<string>(list.val[l].val)) {
@@ -863,10 +861,9 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
cout << ", ";
}
}
cout << "]" << endl;
}
else {
return error("Couldn't print that", "printError");
cout << "]";
} else {
return error("Couldn't find list named " + get<ListRef>(l.args[0]).listName);
}
} else {
return error("Argument of stdlnout must be a value (literal or a value reference)");
@@ -901,8 +898,12 @@ 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 if (holds_alternative<List>(get<Literal>(l.args[0]).val)) {
List list = get<List>(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);
cout << "[";
for (int l = 0; l < list.val.size(); l++) {
if (holds_alternative<string>(list.val[l].val)) {
@@ -932,9 +933,8 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
}
}
cout << "]" << endl;
}
else {
return error("Couldn't print that", "printError");
} else {
return error("Couldn't find list named " + get<ListRef>(l.args[0]).listName);
}
} else {
return error("Argument of stdlnout must be a value (literal or a value reference) or a list reference");
@@ -1064,12 +1064,6 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
case Types::Bool:
newVal.val = false;
break;
case Types::List:
{
List newList;
newVal.val = newList;
}
break;
default:
return error("You dingus you werent supposed to get here");
}
@@ -1090,8 +1084,8 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
string listName;
List listContents;
if (holds_alternative<Direct>(l.args[0])) {
listName = get<Direct>(l.args[0]).varName;
if (holds_alternative<ListRef>(l.args[0])) {
listName = get<ListRef>(l.args[0]).listName;
} else {
return error("First argument of setlist must be a list reference");
}
@@ -1120,12 +1114,12 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Could not find all arguments required for Getlistat inbuilt");
}
{
string listref;
ListRef listref;
int ref;
Direct var;
if (holds_alternative<Direct>(l.args[0])) {
listref = get<Direct>(l.args[0]).varName;
if (holds_alternative<ListRef>(l.args[0])) {
listref = get<ListRef>(l.args[0]);
} else {
return error("First argument of getlistat must be a list reference");
}
@@ -1146,19 +1140,19 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Third argument of getlistat must be a direct reference");
}
if (variables.find(listref) != variables.end()) {
if (holds_alternative<List>(variables[listref].val)) {
if (get<List>(variables[listref].val).val.size() > ref) {
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) {
bool existed = variables.count(var.varName) > 0;
setVal(var.varName, get<List>(variables[listref].val).val[ref]);
setVal(var.varName, get<List>(variables[listref.listName].val).val[ref]);
} else {
return error("Index " + to_string(ref) + " out of range of list " + listref, "rangeError");
return error("Index " + to_string(ref) + " out of range of list " + listref.listName, "rangeError");
}
} else {
return error("Variable " + listref + " is not a list");
return error("Found a normal variable in place of a list");
}
} else {
return error("Unknown list: " + listref);
return error("Unknown list: " + listref.listName);
}
}
break;
@@ -1221,12 +1215,12 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Could not find all arguments required for Setlistat inbuilt");
}
{
string listref;
ListRef listref;
int ref;
Literal value;
if (holds_alternative<Direct>(l.args[0])) {
listref = get<Direct>(l.args[0]).varName;
if (holds_alternative<ListRef>(l.args[0])) {
listref = get<ListRef>(l.args[0]);
} else {
return error("First argument of setlistat must be a list reference");
}
@@ -1246,22 +1240,20 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
} else {
return error("Third argument of setlistat must be a direct reference");
}
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);
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);
tmpList.val[ref] = value;
Literal tmpLit;
tmpLit.val = tmpList;
setVal(listref, tmpLit);
setVal(listref.listName, tmpLit);
} else {
return error("Index " + to_string(ref) + " out of range of list " + listref, "rangeError");
return error("Index " + to_string(ref) + " out of range of list " + listref.listName, "rangeError");
}
} else {
return error("Variable " + listref + " is not a list");
}
} else {
return error("Unknown list: " + listref);
return error("Unknown list: " + listref.listName);
}
}
break;
@@ -1274,11 +1266,11 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Could not find all arguments required for Listappend inbuilt");
}
{
string listref;
ListRef listref;
Literal value;
if (holds_alternative<Direct>(l.args[0])) {
listref = get<Direct>(l.args[0]).varName;
if (holds_alternative<ListRef>(l.args[0])) {
listref = get<ListRef>(l.args[0]);
} else {
return error("First argument of listappend must be a list reference");
}
@@ -1289,17 +1281,17 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Second argument of listappend must be a direct reference");
}
if (variables.find(listref) != variables.end()) {
if (!holds_alternative<List>(variables[listref].val)) {
return error("Variable " + listref + "is not a list");
if (variables.find(listref.listName) != variables.end()) {
if (!holds_alternative<List>(variables[listref.listName].val)) {
return error("Variable " + listref.listName + "is not a list");
}
List tmpList = get<List>(variables[listref].val);
List tmpList = get<List>(variables[listref.listName].val);
tmpList.val.push_back(value);
Literal tmpLit;
tmpLit.val = tmpList;
setVal(listref, tmpLit);
setVal(listref.listName, tmpLit);
} else {
return error("Unknown list: " + listref);
return error("Unknown list: " + listref.listName);
}
}
break;
@@ -1312,11 +1304,11 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
return error("Could not find all arguments required for Getlistsize inbuilt");
}
{
string ref;
ListRef ref;
Direct var;
if (holds_alternative<Direct>(l.args[0])) {
ref = get<Direct>(l.args[0]).varName;
if (holds_alternative<ListRef>(l.args[0])) {
ref = get<ListRef>(l.args[0]);
} else {
return error("First argument of getlistsize must be a list reference");
}
@@ -1328,12 +1320,12 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
}
Literal newLit;
if (variables.find(ref) != variables.end()) {
newLit.val = int(get<List>(variables[ref].val).val.size());
if (variables.find(ref.listName) != variables.end()) {
newLit.val = int(get<List>(variables[ref.listName].val).val.size());
bool existed = variables.count(var.varName) > 0;
setVal(var.varName, newLit);
} else {
return error("Couldn't find the list " + ref);
return error("Couldn't find the list " + ref.listName);
}
break;
@@ -2121,6 +2113,10 @@ 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) {
@@ -2228,6 +2224,8 @@ 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");
}
@@ -2851,9 +2849,8 @@ vector<Instruction> parser(vector<vector<string>> in) {
break;
case Types::ListRef:
{
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);
ListRef newLR;
newLR.listName = i.substr(1);
newInst.args.push_back(newLR);
}
break;

View File

@@ -1,6 +1,6 @@
# A cool list
setlist *favWords "hello" "there" "general" "kenobi"
stdlnout $favWords
stdlnout *favWords
set &count 0
set &passedThrough true