From 4e62bbdc51f1db71d0a8348f2e9a0209e1dab1a4 Mon Sep 17 00:00:00 2001 From: Curle Date: Sat, 5 Mar 2022 02:05:18 +0000 Subject: [PATCH] Finish the Import mechanism, plus some bug fixes --- src/Importer.c | 21 ++++++++++++++++++++- src/Main.c | 1 + src/Parser.c | 4 ++-- src/Pointers.c | 1 + 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Importer.c b/src/Importer.c index 653a478..99ca587 100644 --- a/src/Importer.c +++ b/src/Importer.c @@ -70,6 +70,25 @@ DieMessage("Unable to access the imported module", ModulePath); // At this point, the file exists and we have the path. - // Pass it to the lexer and have at it. + // Save the current file, so that we can restore it later + struct FileData* SavedFile = CurrentFile; + + // Create a new file with the module name + struct FileData* ModuleData = malloc(sizeof(struct FileData)); + ModuleData->AllowDefinitions = false; + ModuleData->SourceName = ModulePath; + + printf("Swapping to module %s..\n\n", ModulePath); + + // Parse all relevant data from the module file... + Compile(ModuleData); + + printf("\n\nSwapping back to file %s..\n", SavedFile->SourceName); + + // Reinstate the saved file + CurrentFile = SavedFile; + + // Tokenise past the string we just parsed + Tokenise(); } \ No newline at end of file diff --git a/src/Main.c b/src/Main.c index bf7c509..2042f84 100644 --- a/src/Main.c +++ b/src/Main.c @@ -155,6 +155,7 @@ int main(int argc, char* argv[]) { // Prepare the source metadata before we start compiling struct FileData* Source = malloc(sizeof(struct FileData)); Source->SourceName = argv[i]; + Source->AllowDefinitions = true; Files[i] = Source; // Compile the file by invoking the Delegate diff --git a/src/Parser.c b/src/Parser.c index c063286..f8fbd8c 100644 --- a/src/Parser.c +++ b/src/Parser.c @@ -433,7 +433,7 @@ struct ASTNode* CallFunction() { */ struct ASTNode* GetExpressionList() { struct ASTNode* Tree = NULL, * Child = NULL; - int Count; + int Count = 0; while (CurrentFile->CurrentSymbol.type != LI_RPARE) { Child = ParsePrecedenceASTNode(0); @@ -605,7 +605,7 @@ void ParseGlobals() { if (FunctionComing && CurrentFile->CurrentSymbol.type == LI_LPARE) { printf("\tParsing function\n"); Tree = ParseFunction(Type); - if (Tree) { + if (Tree && CurrentFile->AllowDefinitions) { printf("\nBeginning assembler creation of new function %s\n", Tree->Symbol->Name); AssembleTree(Tree, -1, 0); FreeLocals(); diff --git a/src/Pointers.c b/src/Pointers.c index 5b920bc..83a6497 100644 --- a/src/Pointers.c +++ b/src/Pointers.c @@ -77,6 +77,7 @@ int ParseOptionalPointer(struct SymbolTableEntry** Composite) { switch (CurrentFile->CurrentSymbol.type) { case KW_IMPORT: + Type = DAT_NONE; ImportModule(); break; case TY_VOID: