mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-17 15:54:07 +10:00
Arrays and dictionaries have been implemented, read more
The arrays and dictionaries are currently being printed out correctly, afaik. This means I should be able to go back and work on the type system, assuming nothing happens.
This commit is contained in:
@@ -37,14 +37,26 @@ void freeNode(Node* node) {
|
||||
for (int i = 0; i < node->block.count; i++) {
|
||||
freeNode(node->block.nodes + i);
|
||||
}
|
||||
//each sub-node gets freed individually
|
||||
FREE_ARRAY(Node, node->block.nodes, node->block.capacity);
|
||||
break;
|
||||
|
||||
case NODE_COMPOUND:
|
||||
for (int i = 0; i < node->compound.count; i++) {
|
||||
freeNode(node->compound.nodes + i);
|
||||
}
|
||||
FREE_ARRAY(Node, node->compound.nodes, node->compound.capacity);
|
||||
break;
|
||||
|
||||
case NODE_PAIR:
|
||||
freeNode(node->pair.left);
|
||||
freeNode(node->pair.right);
|
||||
break;
|
||||
|
||||
case NODE_VAR_TYPES:
|
||||
for (int i = 0; i < node->varTypes.count; i++) {
|
||||
freeNode(node->varTypes.nodes + 1);
|
||||
}
|
||||
//each sub-node gets freed individually
|
||||
FREE_ARRAY(Node, node->varTypes.nodes, node->varTypes.capacity);
|
||||
break;
|
||||
|
||||
case NODE_VAR_DECL:
|
||||
@@ -53,8 +65,6 @@ void freeNode(Node* node) {
|
||||
freeNode(node->varDecl.expression);
|
||||
break;
|
||||
}
|
||||
|
||||
FREE(Node, node);
|
||||
}
|
||||
|
||||
void emitNodeLiteral(Node** nodeHandle, Literal literal) {
|
||||
@@ -105,6 +115,27 @@ void emitNodeBlock(Node** nodeHandle) {
|
||||
*nodeHandle = tmp;
|
||||
}
|
||||
|
||||
void emitNodeCompound(Node** nodeHandle) {
|
||||
Node* tmp = ALLOCATE(Node, 1);
|
||||
|
||||
tmp->type = NODE_COMPOUND;
|
||||
tmp->compound.nodes = NULL;
|
||||
tmp->compound.capacity = 0;
|
||||
tmp->compound.count = 0;
|
||||
|
||||
*nodeHandle = tmp;
|
||||
}
|
||||
|
||||
void emitNodePair(Node** nodeHandle, Node* left, Node* right) {
|
||||
Node* tmp = ALLOCATE(Node, 1);
|
||||
|
||||
tmp->type = NODE_PAIR;
|
||||
tmp->pair.left = left;
|
||||
tmp->pair.right = right;
|
||||
|
||||
*nodeHandle = tmp;
|
||||
}
|
||||
|
||||
void emitNodeVarTypes(Node** nodeHandle, unsigned char mask) {
|
||||
Node* tmp = ALLOCATE(Node, 1);
|
||||
|
||||
@@ -172,8 +203,26 @@ void printNode(Node* node) {
|
||||
printf("}\n");
|
||||
break;
|
||||
|
||||
case NODE_COMPOUND:
|
||||
printf("compound[\n");
|
||||
|
||||
for (int i = 0; i < node->compound.count; i++) {
|
||||
printNode(&(node->compound.nodes[i]));
|
||||
}
|
||||
|
||||
printf("]\n");
|
||||
break;
|
||||
|
||||
case NODE_PAIR:
|
||||
printf("pair-left:");
|
||||
printNode(node->pair.left);
|
||||
printf(";pair-right:");
|
||||
printNode(node->pair.right);
|
||||
printf(";");
|
||||
break;
|
||||
|
||||
case NODE_VAR_TYPES:
|
||||
printf("[\n");
|
||||
printf("type[\n");
|
||||
|
||||
for (int i = 0; i < node->varTypes.count; i++) {
|
||||
printNode(&(node->varTypes.nodes[i]));
|
||||
|
||||
Reference in New Issue
Block a user