Finish the Import mechanism, plus some bug fixes

This commit is contained in:
Curle 2022-03-05 02:05:18 +00:00
parent 2c27f2eb40
commit 4e62bbdc51
4 changed files with 24 additions and 3 deletions

View File

@ -70,6 +70,25 @@
DieMessage("Unable to access the imported module", ModulePath); DieMessage("Unable to access the imported module", ModulePath);
// At this point, the file exists and we have the path. // 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();
} }

View File

@ -155,6 +155,7 @@ int main(int argc, char* argv[]) {
// Prepare the source metadata before we start compiling // Prepare the source metadata before we start compiling
struct FileData* Source = malloc(sizeof(struct FileData)); struct FileData* Source = malloc(sizeof(struct FileData));
Source->SourceName = argv[i]; Source->SourceName = argv[i];
Source->AllowDefinitions = true;
Files[i] = Source; Files[i] = Source;
// Compile the file by invoking the Delegate // Compile the file by invoking the Delegate

View File

@ -433,7 +433,7 @@ struct ASTNode* CallFunction() {
*/ */
struct ASTNode* GetExpressionList() { struct ASTNode* GetExpressionList() {
struct ASTNode* Tree = NULL, * Child = NULL; struct ASTNode* Tree = NULL, * Child = NULL;
int Count; int Count = 0;
while (CurrentFile->CurrentSymbol.type != LI_RPARE) { while (CurrentFile->CurrentSymbol.type != LI_RPARE) {
Child = ParsePrecedenceASTNode(0); Child = ParsePrecedenceASTNode(0);
@ -605,7 +605,7 @@ void ParseGlobals() {
if (FunctionComing && CurrentFile->CurrentSymbol.type == LI_LPARE) { if (FunctionComing && CurrentFile->CurrentSymbol.type == LI_LPARE) {
printf("\tParsing function\n"); printf("\tParsing function\n");
Tree = ParseFunction(Type); Tree = ParseFunction(Type);
if (Tree) { if (Tree && CurrentFile->AllowDefinitions) {
printf("\nBeginning assembler creation of new function %s\n", Tree->Symbol->Name); printf("\nBeginning assembler creation of new function %s\n", Tree->Symbol->Name);
AssembleTree(Tree, -1, 0); AssembleTree(Tree, -1, 0);
FreeLocals(); FreeLocals();

View File

@ -77,6 +77,7 @@ int ParseOptionalPointer(struct SymbolTableEntry** Composite) {
switch (CurrentFile->CurrentSymbol.type) { switch (CurrentFile->CurrentSymbol.type) {
case KW_IMPORT: case KW_IMPORT:
Type = DAT_NONE;
ImportModule(); ImportModule();
break; break;
case TY_VOID: case TY_VOID: