Renamed Node to ASTNode

This commit is contained in:
2022-09-18 19:14:37 +01:00
parent 2458996ee7
commit 6a086395be
13 changed files with 495 additions and 495 deletions

View File

@@ -1,4 +1,4 @@
#include "node.h"
#include "ast_node.h"
#include "memory.h"
#include "console_colors.h"
@@ -12,8 +12,8 @@ int main() {
Literal literal = TO_STRING_LITERAL(copyString(str, strlen(str)), strlen(str));
Node* node;
emitNodeLiteral(&node, literal);
ASTNode* node;
emitASTNodeLiteral(&node, literal);
freeLiteral(literal);
freeNode(node);
}
@@ -23,27 +23,27 @@ int main() {
char* idn = "foobar";
char* str = "hello world";
Node* dictionary;
Node* left;
Node* right;
ASTNode* dictionary;
ASTNode* left;
ASTNode* right;
Literal identifier = TO_IDENTIFIER_LITERAL(copyString(idn, strlen(idn)), strlen(idn));
Literal string = TO_STRING_LITERAL(copyString(str, strlen(str)), strlen(str));
emitNodeCompound(&dictionary, LITERAL_DICTIONARY);
emitNodeLiteral(&left, identifier);
emitNodeLiteral(&right, string);
emitASTNodeCompound(&dictionary, LITERAL_DICTIONARY);
emitASTNodeLiteral(&left, identifier);
emitASTNodeLiteral(&right, string);
//grow the node if needed
if (dictionary->compound.capacity < dictionary->compound.count + 1) {
int oldCapacity = dictionary->compound.capacity;
dictionary->compound.capacity = GROW_CAPACITY(oldCapacity);
dictionary->compound.nodes = GROW_ARRAY(Node, dictionary->compound.nodes, oldCapacity, dictionary->compound.capacity);
dictionary->compound.nodes = GROW_ARRAY(ASTNode, dictionary->compound.nodes, oldCapacity, dictionary->compound.capacity);
}
//store the left and right in the node
setNodePair(&dictionary->compound.nodes[dictionary->compound.count++], left, right);
setASTNodePair(&dictionary->compound.nodes[dictionary->compound.count++], left, right);
//the real test
freeNode(dictionary);

View File

@@ -65,7 +65,7 @@ int main() {
initParser(&parser, &lexer);
initCompiler(&compiler);
Node* node = scanParser(&parser);
ASTNode* node = scanParser(&parser);
//write
writeCompiler(&compiler, node);
@@ -95,9 +95,9 @@ int main() {
initParser(&parser, &lexer);
initCompiler(&compiler);
Node* node = scanParser(&parser);
ASTNode* node = scanParser(&parser);
while (node != NULL) {
if (node->type == NODE_ERROR) {
if (node->type == AST_NODEERROR) {
fprintf(stderr, ERROR "ERROR: Error node found" RESET);
return -1;
}

View File

@@ -60,10 +60,10 @@ unsigned char* compileString(char* source, size_t* size) {
initCompiler(&compiler);
//run the parser until the end of the source
Node* node = scanParser(&parser);
ASTNode* node = scanParser(&parser);
while(node != NULL) {
//pack up and leave
if (node->type == NODE_ERROR) {
if (node->type == AST_NODEERROR) {
printf(ERROR "error node detected\n" RESET);
freeNode(node);
freeCompiler(&compiler);
@@ -138,7 +138,7 @@ int main() {
initCompiler(&compiler);
initInterpreter(&interpreter);
Node* node = scanParser(&parser);
ASTNode* node = scanParser(&parser);
//write
writeCompiler(&compiler, node);

View File

@@ -62,10 +62,10 @@ unsigned char* compileString(char* source, size_t* size) {
initCompiler(&compiler);
//run the parser until the end of the source
Node* node = scanParser(&parser);
ASTNode* node = scanParser(&parser);
while(node != NULL) {
//pack up and leave
if (node->type == NODE_ERROR) {
if (node->type == AST_NODEERROR) {
printf(ERROR "error node detected\n" RESET);
freeNode(node);
freeCompiler(&compiler);

View File

@@ -64,21 +64,21 @@ int main() {
initLexer(&lexer, source);
initParser(&parser, &lexer);
Node* node = scanParser(&parser);
ASTNode* node = scanParser(&parser);
//inspect the node
if (node == NULL) {
fprintf(stderr, ERROR "ERROR: Node is null" RESET);
fprintf(stderr, ERROR "ERROR: ASTNode is null" RESET);
return -1;
}
if (node->type != NODE_UNARY || node->unary.opcode != OP_PRINT) {
fprintf(stderr, ERROR "ERROR: Node is not a print instruction" RESET);
if (node->type != AST_NODEUNARY || node->unary.opcode != OP_PRINT) {
fprintf(stderr, ERROR "ERROR: ASTNode is not a print instruction" RESET);
return -1;
}
if (node->unary.child->type != NODE_LITERAL || !IS_NULL(node->unary.child->atomic.literal)) {
fprintf(stderr, ERROR "ERROR: Node to be printed is not a null value" RESET);
if (node->unary.child->type != AST_NODELITERAL || !IS_NULL(node->unary.child->atomic.literal)) {
fprintf(stderr, ERROR "ERROR: ASTNode to be printed is not a null value" RESET);
return -1;
}
@@ -98,10 +98,10 @@ int main() {
initLexer(&lexer, source);
initParser(&parser, &lexer);
Node* node = scanParser(&parser);
ASTNode* node = scanParser(&parser);
while (node != NULL) {
if (node->type == NODE_ERROR) {
if (node->type == AST_NODEERROR) {
fprintf(stderr, ERROR "ERROR: Error node detected" RESET);
return -1;
}