mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-19 16:54:08 +10:00
Wrote the interpreter
This commit is contained in:
@@ -12,7 +12,7 @@ void initLiteralArray(LiteralArray* array) {
|
||||
array->literals = NULL;
|
||||
}
|
||||
|
||||
int writeLiteralArray(LiteralArray* array, Literal literal) {
|
||||
int pushLiteralArray(LiteralArray* array, Literal literal) {
|
||||
if (array->capacity < array->count + 1) {
|
||||
int oldCapacity = array->capacity;
|
||||
|
||||
@@ -29,6 +29,17 @@ int writeLiteralArray(LiteralArray* array, Literal literal) {
|
||||
return array->count++;
|
||||
}
|
||||
|
||||
Literal popLiteralArray(LiteralArray* array) {
|
||||
//get the return
|
||||
Literal ret = array->literals[array->count-1];
|
||||
|
||||
//null the existing data
|
||||
array->literals[array->count-1] = TO_NULL_LITERAL;
|
||||
|
||||
array->count--;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void freeLiteralArray(LiteralArray* array) {
|
||||
//clean up memory
|
||||
for(int i = 0; i < array->count; i++) {
|
||||
@@ -84,3 +95,10 @@ int findLiteralIndex(LiteralArray* array, Literal literal) {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void printLiteralArray(LiteralArray* array, const char* delim) {
|
||||
for (int i = 0; i < array->count; i++) {
|
||||
printLiteral(array->literals[i]);
|
||||
printf("%s", delim);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user