From a8322e39b6db5cfee2195a6603ccf813e5194205 Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:40:24 +0100 Subject: [PATCH 01/15] docs: fix docs in compiler --- src/compiler/compiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 73cb241..7081887 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -135,7 +135,7 @@ IR_CTX* makeContext(AST_NODE* tree) { /** * Compiles the Context tree to an executable named the provided file name. * @param ctx the IR context. - * @param char the output file name. + * @param out the output file. */ void compile(IR_CTX* ctx, FILE* out) { From 838b32cfa4e6cf8acc4c577a07ac114070c2e7fd Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:40:51 +0100 Subject: [PATCH 02/15] clean: removed old code used for testing --- src/cli/main.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/cli/main.c b/src/cli/main.c index 358187b..570d474 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -25,10 +25,6 @@ // Version #define VERSION "0.1.0" -uint8_t code_section[6] = { - 0xB8, 0x4C, 0x00, 0x00, 0x00, 0xC3 -}; - void showCommandEntry(char* commandName, char* description, int argumentCount, char* argumentNames[], char* argumentDescriptions[]) { printf("\n > %s\n\n %s%sDescription%s: %s\n", commandName, STYLE_BOLD, STYLE_UNDERLINE, RESET, description); From a7f16011792e77b49e5691e6c2afce0c70580b9f Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:41:41 +0100 Subject: [PATCH 03/15] clean: removed commented code used for testing --- src/cli/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cli/main.c b/src/cli/main.c index 570d474..698208d 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -125,9 +125,7 @@ int main(int argc, char* argv[]) { fptr = fopen(outputFile, "w"); compile(ctx, fptr); - - //compilePE(fptr, code_section, sizeof(code_section)); - + break; case 'v': if(strlen(argv[1]) > 1 && strcmp(argv[1], "version") != 0) { From 4a0be4f43a2e607a50fe87544fdffaf0c84a4212 Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:42:50 +0100 Subject: [PATCH 04/15] docs: added docs for parseFunctionInvoke in header --- src/parser/asts/functions.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parser/asts/functions.h b/src/parser/asts/functions.h index 5cc03da..17216aa 100644 --- a/src/parser/asts/functions.h +++ b/src/parser/asts/functions.h @@ -37,6 +37,11 @@ AST_NODE* parseFunctionDeclaration(struct LexerResult result, int index); */ AST_NODE* parseASMFunctionDeclaration(struct LexerResult result, int index); +/** + * Parses an function invocation. + * @param result the lexer result. + * @param index the starting index of the parsing. + */ AST_NODE* parseFunctionInvoke(struct LexerResult result, int index); #endif From c341cbe90d291f5ceb5b83ffdc1f0ba4676ccbe5 Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:43:54 +0100 Subject: [PATCH 05/15] refactor: changed IR_2_H to IR_H --- src/parser/ast.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser/ast.h b/src/parser/ast.h index d666f0b..e0a77a5 100644 --- a/src/parser/ast.h +++ b/src/parser/ast.h @@ -2,8 +2,8 @@ * The header file of AST nodes in Quickfall. */ -#ifndef AST_2_H -#define AST_2_H +#ifndef AST_H +#define AST_H /** * The type of AST Node(s). From fe7991fafacf5e992bc4e7928a1b446fc355f83c Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:45:28 +0100 Subject: [PATCH 06/15] clean: cleaned up struct definition of AST_NODE --- src/parser/ast.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/parser/ast.h b/src/parser/ast.h index e0a77a5..e1c6473 100644 --- a/src/parser/ast.h +++ b/src/parser/ast.h @@ -38,11 +38,11 @@ enum ASTNodeType { /** * An AST Node. Has a tree-ish structure. */ -struct ASTNode { +typedef struct { - struct ASTNode* left; - struct ASTNode* right; - struct ASTNode* next; + AST_NODE* left; + AST_NODE* right; + AST_NODE* next; enum ASTNodeType type; @@ -50,9 +50,7 @@ struct ASTNode { char* value; int endingIndex; // The index which the parsing ended -}; - -typedef struct ASTNode AST_NODE; +} AST_NODE; /** * Creates a new AST Node. From 98f74dc3b8d159b6123ee59c4914e2e6b227e52e Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:46:21 +0100 Subject: [PATCH 07/15] feat: added #ifndef for math ast --- src/parser/asts/math.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/parser/asts/math.h b/src/parser/asts/math.h index 13aaac6..a093bb1 100644 --- a/src/parser/asts/math.h +++ b/src/parser/asts/math.h @@ -4,6 +4,9 @@ #include "../ast.h" +#ifndef AST_MATH_H +#define AST_MATH_H + /** * Parses the mathematical operation. * @param result the lexer result. @@ -11,3 +14,4 @@ */ AST_NODE* parseMathematicalOpNode(struct LexerResult result, int index); +#endif \ No newline at end of file From 3ee2fde1aa946ae99ccfcae97ba76b668979ebce Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:47:56 +0100 Subject: [PATCH 08/15] clean: cleaned up struct and enum declarations for IR --- src/compiler/ir.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/compiler/ir.h b/src/compiler/ir.h index 9271653..315c080 100644 --- a/src/compiler/ir.h +++ b/src/compiler/ir.h @@ -9,7 +9,7 @@ #ifndef IR_H #define IR_H -enum IRNodeType { +typedef enum { IR_FUNCTION, IR_ASM_FUNCTION, @@ -17,11 +17,9 @@ enum IRNodeType { IR_VARIABLE, IR_FUNCTION_ARGUMENT, IR_FUNCTION_BODY_VARIABLE -}; +} IR_TYPE; -typedef enum IRNodeType IR_TYPE; - -struct IRNode { +typedef struct { IR_TYPE nodeType; @@ -41,11 +39,9 @@ struct IRNode { struct Hashmap* variableMap; AST_NODE* tree; -}; - -typedef struct IRNode IR_NODE; +} IR_NODE; -struct IRContext { +typedef struct { IR_NODE** nodes; int nodeIndex; @@ -53,9 +49,7 @@ struct IRContext { IR_NODE* mainFunc; -}; - -typedef struct IRContext IR_CTX; +} IR_CTX; /** * Creates an IR node based on the type and the name given. From 4b2f6f911321aa73553515288eb3df9bba4ddba4 Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:48:47 +0100 Subject: [PATCH 09/15] docs: added docs for IR_NODE and IR_CTX --- src/compiler/ir.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/ir.h b/src/compiler/ir.h index 315c080..a60b184 100644 --- a/src/compiler/ir.h +++ b/src/compiler/ir.h @@ -19,6 +19,9 @@ typedef enum { IR_FUNCTION_BODY_VARIABLE } IR_TYPE; +/** + * An IR Node. + */ typedef struct { IR_TYPE nodeType; @@ -41,6 +44,9 @@ typedef struct { AST_NODE* tree; } IR_NODE; +/** + * The overall IR context. + */ typedef struct { IR_NODE** nodes; int nodeIndex; From 10a5aabe0151b60f0a5b9b79571150eff1128c06 Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:49:33 +0100 Subject: [PATCH 10/15] clean: removed units as they were not used --- src/compiler/pe/format.h | 2 - src/compiler/units.h | 11 ----- src/compiler/utils.c | 93 ---------------------------------------- 3 files changed, 106 deletions(-) delete mode 100644 src/compiler/units.h delete mode 100644 src/compiler/utils.c diff --git a/src/compiler/pe/format.h b/src/compiler/pe/format.h index 58d9257..1267082 100644 --- a/src/compiler/pe/format.h +++ b/src/compiler/pe/format.h @@ -2,8 +2,6 @@ * Quickfall PE Format Defintion. */ -#include "../units.h" - #ifndef PE_FORMAT #define PE_FORMAT diff --git a/src/compiler/units.h b/src/compiler/units.h deleted file mode 100644 index b6dafcf..0000000 --- a/src/compiler/units.h +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Quickfall Compiler common data-types. - */ - -#ifndef COMPILER_UNITS -#define COMPILER_UNITS - -typedef unsigned long DWORD; // 32 bits -typedef unsigned short WORD; // 16 bits - -#endif diff --git a/src/compiler/utils.c b/src/compiler/utils.c deleted file mode 100644 index 2fa9b41..0000000 --- a/src/compiler/utils.c +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Utilities for the Quickfall compiler. - */ - -#include -#include -#include -#include -#include - -/** - * Writes an 8 bit number into the file. - */ -void write8(FILE *file, uint8_t value) { - - printf("Input %d for: %02x\n", value, (value >> 0) & 0xff); - - if (fputc(value, file) == EOF) { - perror("fputc"); - exit(1); - } -} - -/** - * Writes an 16 bit number into the file. - */ -void write16(FILE *file, uint16_t value) { - write8(file, (value >> 0) & 0xff); - write8(file, (value >> 8) & 0xff); -} - -/** - * Writes an 32 bit number into the file. - */ -void write32(FILE *file, uint32_t value) { - write8(file, (value >> 0) & 0xff); - write8(file, (value >> 8) & 0xff); - write8(file, (value >> 16) & 0xff); - write8(file, (value >> 24) & 0xff); - - printf("32 Input for %d: %02x %02x %02x %02x\n", (value >> 0) & 0xff, (value >> 8) & 0xff, (value >> 16) && 0xff, (value >> 24) & 0xff); -} - -/** - * Writes a string with a 8 bit padding. - */ -void writestr8(FILE *file, char *str) { - size_t len, i; - - len = strlen(str); - assert(len <= 8 && "The string must fit in 8 bytes."); - - for (i = 0; i < 8; i++) { - write8(file, i < len ? str[i] : 0); - } -} - -/** - * Writes a string with a 16 bit padding. - */ -void writestr16(FILE *file, char *str) { - size_t len, i; - - len = strlen(str); - assert(len <= 15 && "The string and terminator must fit in 16 bytes."); - - for (i = 0; i < 16; i++) { - write8(file, i < len ? str[i] : 0); - } -} - -/** - * Seeks to offset in a file. - */ -void seek(FILE *file, long offset) { - if (fseek(file, offset, SEEK_SET) == -1) { - perror("fseek"); - exit(1); - } -} - -/** - * Rounds the number to the provided alignment. - */ -uint32_t align_to(uint32_t value, uint32_t alignment) { - uint32_t remainder = value % alignment; - - if (remainder == 0) { - return value; - } - - return value + (alignment - remainder); -} From 0400eb7a07a50500b4ceaf37fd5e4e637ff893ef Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:52:18 +0100 Subject: [PATCH 11/15] docs: cleaned lexer structs --- src/lexer/lexer.c | 8 ++++---- src/lexer/lexer.h | 10 +++++----- src/lexer/tokens.h | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index c61f19a..ca4c82d 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -15,16 +15,16 @@ /** * Sets the token type of the currently selected token in the LexerResult with the provided token type. */ -void pushToken(struct LexerResult* result, enum TokenType type) { +void pushToken(LEXER_RESULT* result, TOKEN_TYPE type) { result->tokens[result->size].type = type; result->size++; } -struct LexerResult runLexer(char* string, int size) { - struct LexerResult result; +LEXER_RESULT runLexer(char* string, int size) { + LEXER_RESULT result; result.size = 0; - result.tokens = malloc(sizeof(struct Token) * 1024); + result.tokens = malloc(sizeof(TOKEN) * 1024); char c; diff --git a/src/lexer/lexer.h b/src/lexer/lexer.h index 68ac9ea..61bb123 100644 --- a/src/lexer/lexer.h +++ b/src/lexer/lexer.h @@ -7,22 +7,22 @@ /** * Contains the results of lexical analysis */ -struct LexerResult { +typedef struct { int size; - struct Token* tokens; -}; + TOKEN* tokens; +} LEXER_RESULT; /** * Performs lexical analysis on an input string * Returns a LexerResult containing the tokens */ -struct LexerResult runLexer(char* input, int size); +LEXER_RESULT runLexer(char* input, int size); /** * Adds a token to the LexerResult * @param result The LexerResult to add the token to * @param type The type of the token to add */ -void pushToken(struct LexerResult* result, enum TokenType type); +void pushToken(LEXER_RESULT* result, TOKEN_TYPE type); #endif diff --git a/src/lexer/tokens.h b/src/lexer/tokens.h index 2e99cee..3917555 100644 --- a/src/lexer/tokens.h +++ b/src/lexer/tokens.h @@ -1,7 +1,7 @@ #ifndef TOKENS_H #define TOKENS_H -enum TokenType { +typedef enum { ASM_FUNCTION, FUNCTION, RETURN, @@ -23,15 +23,15 @@ enum TokenType { USE, NONE, MATH_OP -}; +} TOKEN_TYPE; /** * An lexer token generated by the Lexer. */ -struct Token { - enum TokenType type; +typedef struct { + TOKEN_TYPE type; char* value; -}; +} TOKEN; #endif From fdbe60b8bf2a89bd220369865048846eb998b804 Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 12:56:40 +0100 Subject: [PATCH 12/15] fix: further fixes --- src/parser/ast.c | 2 +- src/parser/ast.h | 6 +++--- src/parser/asts/functions.c | 19 +++++++++---------- src/parser/asts/functions.h | 10 +++++----- src/parser/asts/math.c | 2 +- src/parser/asts/math.h | 2 +- src/parser/asts/variables.c | 6 +++--- src/parser/asts/variables.h | 4 ++-- src/parser/parser.c | 4 ++-- src/parser/parser.h | 2 +- 10 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/parser/ast.c b/src/parser/ast.c index 4400d84..4ccbfeb 100644 --- a/src/parser/ast.c +++ b/src/parser/ast.c @@ -10,7 +10,7 @@ * Creates a new AST Node. * @param type the AST type of the node. */ -AST_NODE* createASTNode(enum ASTNodeType type) { +AST_NODE* createASTNode(AST_NODE_TYPE type) { AST_NODE* node = malloc(sizeof(AST_NODE)); node->valueSize = 0; diff --git a/src/parser/ast.h b/src/parser/ast.h index e1c6473..6e66c91 100644 --- a/src/parser/ast.h +++ b/src/parser/ast.h @@ -8,7 +8,7 @@ /** * The type of AST Node(s). */ -enum ASTNodeType { +typedef enum { AST_ROOT, // A root of an AST tree, can either represent the first node of the tree or a function body. @@ -33,7 +33,7 @@ enum ASTNodeType { AST_MATH_OP_HEADER, AST_PARAMETER // A function parameter AST Node, used in function declaration. -}; +} AST_NODE_TYPE; /** * An AST Node. Has a tree-ish structure. @@ -56,6 +56,6 @@ typedef struct { * Creates a new AST Node. * @param type the AST type of the node. */ -AST_NODE* createASTNode(enum ASTNodeType type); +AST_NODE* createASTNode(AST_NODE_TYPE type); #endif diff --git a/src/parser/asts/functions.c b/src/parser/asts/functions.c index 330b3f6..d70a500 100644 --- a/src/parser/asts/functions.c +++ b/src/parser/asts/functions.c @@ -20,7 +20,7 @@ * @param result the lexer result. * @param index the starting index of the parsing. */ -AST_NODE* parseParameters(struct LexerResult result, int index) { +AST_NODE* parseParameters(LEXER_RESULT result, int index) { AST_NODE* root = createASTNode(AST_PARAMETER); AST_NODE* current = root; @@ -28,7 +28,7 @@ AST_NODE* parseParameters(struct LexerResult result, int index) { int stack = 0; for(; index < result.size + 1; ++index) { - struct Token t = result.tokens[index]; + TOKEN t = result.tokens[index]; switch(t.type) { case COMMA: @@ -46,7 +46,7 @@ AST_NODE* parseParameters(struct LexerResult result, int index) { return NULL; } - struct Token next = result.tokens[index + 1]; + TOKEN next = result.tokens[index + 1]; if(next.type == NONE || next.type == KEYWORD) { current->left = createASTNode(AST_TYPE); @@ -77,12 +77,12 @@ AST_NODE* parseParameters(struct LexerResult result, int index) { * @param result the result of the lexer. * @param index the starting index of the parsing. */ -AST_NODE* parseArguments(struct LexerResult result, int index) { +AST_NODE* parseArguments(LEXER_RESULT result, int index) { AST_NODE* root = NULL; AST_NODE* current = root; for(; index < result.size + 1; ++index) { - struct Token t = result.tokens[index]; + TOKEN t = result.tokens[index]; if(t.type == PAREN_CLOSE) { return root; @@ -106,13 +106,12 @@ AST_NODE* parseArguments(struct LexerResult result, int index) { return NULL; } -AST_NODE* parseFunctionDeclaration(struct LexerResult result, int index) { +AST_NODE* parseFunctionDeclaration(LEXER_RESULT result, int index) { AST_NODE* node = createASTNode(AST_FUNCTION_DECLARATION); node->left = createASTNode(AST_FUNCTION_HEADER); if(result.tokens[index].type != KEYWORD) { - printf("jd"); return NULL; } @@ -147,7 +146,7 @@ AST_NODE* parseFunctionDeclaration(struct LexerResult result, int index) { return node; } -AST_NODE* parseASMFunctionDeclaration(struct LexerResult result, int index) { +AST_NODE* parseASMFunctionDeclaration(LEXER_RESULT result, int index) { AST_NODE* node = createASTNode(AST_ASM_FUNCTION_DECLARATION); node->left = createASTNode(AST_FUNCTION_HEADER); @@ -174,7 +173,7 @@ AST_NODE* parseASMFunctionDeclaration(struct LexerResult result, int index) { uint8_t* buff = malloc(sizeof(uint8_t) * buffSize); for(; index <= result.size; ++index) { - struct Token t = result.tokens[index]; + TOKEN t = result.tokens[index]; if(t.type == BRACKETS_CLOSE) { break; @@ -198,7 +197,7 @@ AST_NODE* parseASMFunctionDeclaration(struct LexerResult result, int index) { return node; } -AST_NODE* parseFunctionInvoke(struct LexerResult result, int index) { +AST_NODE* parseFunctionInvoke(LEXER_RESULT result, int index) { AST_NODE* node = createASTNode(AST_FUNCTION_INVOKE); node->value = result.tokens[index].value; diff --git a/src/parser/asts/functions.h b/src/parser/asts/functions.h index 17216aa..e30cf77 100644 --- a/src/parser/asts/functions.h +++ b/src/parser/asts/functions.h @@ -14,34 +14,34 @@ * @param result the lexer result. * @param index the starting index of the parsing. */ -AST_NODE* parseParameters(struct LexerResult result, int index); +AST_NODE* parseParameters(LEXER_RESULT result, int index); /** * Parses the arguments from a function call (for example). * @param result the lexer result. * @param index the starting index of the parsing. */ -AST_NODE* parseArguments(struct LexerResult result, int index); +AST_NODE* parseArguments(LEXER_RESULT result, int index); /** * Parses a function declaration. * @param result the lexer result. * @param index the starting index of the parsing. */ -AST_NODE* parseFunctionDeclaration(struct LexerResult result, int index); +AST_NODE* parseFunctionDeclaration(LEXER_RESULT result, int index); /** * Parses an ASM function declaration. * @param result the lexer result. * @param index the starting index of the parsing. */ -AST_NODE* parseASMFunctionDeclaration(struct LexerResult result, int index); +AST_NODE* parseASMFunctionDeclaration(LEXER_RESULT result, int index); /** * Parses an function invocation. * @param result the lexer result. * @param index the starting index of the parsing. */ -AST_NODE* parseFunctionInvoke(struct LexerResult result, int index); +AST_NODE* parseFunctionInvoke(LEXER_RESULT result, int index); #endif diff --git a/src/parser/asts/math.c b/src/parser/asts/math.c index ca72818..b68ac3b 100644 --- a/src/parser/asts/math.c +++ b/src/parser/asts/math.c @@ -14,7 +14,7 @@ * @param result the lexer result. * @param index the starting index. */ -AST_NODE* parseMathematicalOpNode(struct LexerResult result, int index) { +AST_NODE* parseMathematicalOpNode(LEXER_RESULT result, int index) { AST_NODE* node = createASTNode(AST_MATH_OPERATION); node->left = createASTNode(AST_MATH_OP_HEADER); diff --git a/src/parser/asts/math.h b/src/parser/asts/math.h index a093bb1..f69c66b 100644 --- a/src/parser/asts/math.h +++ b/src/parser/asts/math.h @@ -12,6 +12,6 @@ * @param result the lexer result. * @param index the starting index. */ -AST_NODE* parseMathematicalOpNode(struct LexerResult result, int index); +AST_NODE* parseMathematicalOpNode(LEXER_RESULT, int index); #endif \ No newline at end of file diff --git a/src/parser/asts/variables.c b/src/parser/asts/variables.c index 71cb9c3..5241d31 100644 --- a/src/parser/asts/variables.c +++ b/src/parser/asts/variables.c @@ -9,8 +9,8 @@ #include "../ast.h" -AST_NODE* parseVariableValue(struct LexerResult result, int index) { - struct Token t = result.tokens[index]; +AST_NODE* parseVariableValue(LEXER_RESULT result, int index) { + TOKEN t = result.tokens[index]; if(t.type == NUMBER || t.type == STRING || t.type == BOOLEAN_VALUE) { AST_NODE* node = createASTNode(AST_VARIABLE_VALUE); @@ -50,7 +50,7 @@ AST_NODE* parseVariableValue(struct LexerResult result, int index) { * @param result the lexer result. * @param index the starting index. */ -AST_NODE* parseVariableDeclaration(struct LexerResult result, int index) { +AST_NODE* parseVariableDeclaration(LEXER_RESULT result, int index) { AST_NODE* node = createASTNode(AST_VARIABLE_DECLARATION); if(result.tokens[index].type == VAR) { diff --git a/src/parser/asts/variables.h b/src/parser/asts/variables.h index daf4681..e05205b 100644 --- a/src/parser/asts/variables.h +++ b/src/parser/asts/variables.h @@ -14,13 +14,13 @@ * @param result the lexer result. * @param index the starting index. */ -AST_NODE* parseVariableValue(struct LexerResult result, int index); +AST_NODE* parseVariableValue(LEXER_RESULT result, int index); /** * Parses a variable declaration. * @param result the lexer result. * @param index the starting index. */ -AST_NODE* parseVariableDeclaration(struct LexerResult result, int index); +AST_NODE* parseVariableDeclaration(LEXER_RESULT result, int index); #endif diff --git a/src/parser/parser.c b/src/parser/parser.c index 169e1d8..5c3f26d 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -17,12 +17,12 @@ * @param result the LexerResult provided by the lexer. * @param index the starting index. */ -AST_NODE* parseNodes(struct LexerResult result, int index, enum ASTNodeType type) { +AST_NODE* parseNodes(LEXER_RESULT result, int index, AST_NODE_TYPE type) { AST_NODE* root = createASTNode(type); AST_NODE* current = root; for(; index <= result.size; ++index) { - struct Token t = result.tokens[index]; + TOKEN t = result.tokens[index]; AST_NODE* node = NULL; diff --git a/src/parser/parser.h b/src/parser/parser.h index 6a3cc5e..1759e02 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -14,6 +14,6 @@ * @param index the starting index. * @param type the AST node type to return. */ -AST_NODE* parseNodes(struct LexerResult result, int index, enum ASTNodeType type); +AST_NODE* parseNodes(LEXER_RESULT result, int index, AST_NODE_TYPE type); #endif From 0bffa183a28b8269e68064432976c54bb1f8776b Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 13:01:07 +0100 Subject: [PATCH 13/15] fix: further fixes --- benchmarks/main.c | 2 +- src/cli/main.c | 4 ++-- src/parser/ast.h | 10 +++++----- tests/ir.c | 3 ++- tests/lexer.c | 4 +++- tests/parser.c | 5 +++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/benchmarks/main.c b/benchmarks/main.c index 3985c50..0de2352 100644 --- a/benchmarks/main.c +++ b/benchmarks/main.c @@ -123,7 +123,7 @@ void main(int argc, char* argv[]) { endTimer(i, 0); startTimer(); - struct LexerResult result = runLexer(buff, size); + LEXER_RESULT result = runLexer(buff, size); free(buff); diff --git a/src/cli/main.c b/src/cli/main.c index 698208d..3943aa1 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -113,8 +113,8 @@ int main(int argc, char* argv[]) { buff[size] = '\0'; fclose(fptr); - struct LexerResult result = runLexer(buff, size); - struct ASTNode* root = parseNodes(result, 0, AST_ROOT); + LEXER_RESULT result = runLexer(buff, size); + AST_NODE* root = parseNodes(result, 0, AST_ROOT); IR_CTX* ctx = makeContext(root); diff --git a/src/parser/ast.h b/src/parser/ast.h index 6e66c91..7d4c7b1 100644 --- a/src/parser/ast.h +++ b/src/parser/ast.h @@ -38,13 +38,13 @@ typedef enum { /** * An AST Node. Has a tree-ish structure. */ -typedef struct { +typedef struct AST_NODE { - AST_NODE* left; - AST_NODE* right; - AST_NODE* next; + struct AST_NODE* left; + struct AST_NODE* right; + struct AST_NODE* next; - enum ASTNodeType type; + AST_NODE_TYPE type; int valueSize; char* value; diff --git a/tests/ir.c b/tests/ir.c index e50b919..1e2d6c7 100644 --- a/tests/ir.c +++ b/tests/ir.c @@ -2,6 +2,7 @@ * Test to check if the IR is working correctly. */ +#include #include #include @@ -15,7 +16,7 @@ #include "../src/compiler/ir.h" int runIRTest(char* buff) { - struct LexerResult result = runLexer(buff); + LEXER_RESULT result = runLexer(buff, strlen(buff)); AST_NODE* node = parseNodes(result, 0, AST_ROOT); IR_CTX* ctx = makeContext(node); diff --git a/tests/lexer.c b/tests/lexer.c index 556b993..85c1cec 100644 --- a/tests/lexer.c +++ b/tests/lexer.c @@ -2,6 +2,8 @@ * Lexer test for Quickfall. */ +#include + #include "../src/lexer/lexer.h" #include "../src/lexer/tokens.h" @@ -9,7 +11,7 @@ * Runs the lexer test. */ int runLexerTest(char* buff) { - struct LexerResult result = runLexer(buff); + LEXER_RESULT result = runLexer(buff, strlen(buff)); for(int i = 0; i < result.size; ++i) { printf("Token type: %d\n", result.tokens[i].type); diff --git a/tests/parser.c b/tests/parser.c index ba5986f..9317bd5 100644 --- a/tests/parser.c +++ b/tests/parser.c @@ -2,6 +2,7 @@ * A simple parser AST test. */ +#include #include #include @@ -13,7 +14,7 @@ void dumpASTTree(AST_NODE* node, int depth); int runParserTest(char* buff) { - struct LexerResult result = runLexer(buff); + LEXER_RESULT result = runLexer(buff, strlen(buff)); AST_NODE* root = parseNodes(result, 0, AST_ROOT); @@ -22,7 +23,7 @@ int runParserTest(char* buff) { char* debug[12] = {"Root", "Type Node", "Variable Name", "Variable Value", "Variable Declaration", "Variable Reference", "Function Declaration", "Function Header", "Math Operator", "Math Operation", "Math Operation Header", "Parameter"}; -void dumpASTTree(struct ASTNode* node, int depth) { +void dumpASTTree(AST_NODE* node, int depth) { for(int i = 0; i < depth; ++i) { printf(" "); } From 08eaef6f40f7111659e6b9f43349240e73517ddd Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 13:02:46 +0100 Subject: [PATCH 14/15] fix: fixes --- src/compiler/ir.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/ir.h b/src/compiler/ir.h index a60b184..43c6e59 100644 --- a/src/compiler/ir.h +++ b/src/compiler/ir.h @@ -22,7 +22,7 @@ typedef enum { /** * An IR Node. */ -typedef struct { +typedef struct IR_NODE { IR_TYPE nodeType; @@ -36,7 +36,7 @@ typedef struct { int valueSize; // Function Properties - struct IRNode** variables; + struct IR_NODE** variables; int variableIndex; struct Hashmap* variableMap; From f39393b9530d1c7c977735186fbc2fdf04498a60 Mon Sep 17 00:00:00 2001 From: Zffu Date: Tue, 24 Dec 2024 13:05:18 +0100 Subject: [PATCH 15/15] examples: added assembly example --- examples/assembly.qf | 7 +++++++ examples/helloWorld.qf | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 examples/assembly.qf delete mode 100644 examples/helloWorld.qf diff --git a/examples/assembly.qf b/examples/assembly.qf new file mode 100644 index 0000000..df2f2b1 --- /dev/null +++ b/examples/assembly.qf @@ -0,0 +1,7 @@ +func main() { + myAssemblyFunction() +} + +asmf myAssemblyFunction() { + 0xB8 0x4C 0x00 0x00 0x00 0xC3 +} \ No newline at end of file diff --git a/examples/helloWorld.qf b/examples/helloWorld.qf deleted file mode 100644 index 123cd65..0000000 --- a/examples/helloWorld.qf +++ /dev/null @@ -1,6 +0,0 @@ -stackPut(ascii, "Hello World\0"); - -salloc(40); -mov(LC0, rip, rcx); -call(printf); -sfree(40); \ No newline at end of file