diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b1cb92..a423e1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ add_executable(Erythro src/assemble/AssemblerDispatcher.c src/assemble/Win32GASAssembler.c src/assemble/LinuxGASAssembler.c + src/assemble/JVMAssembler.c src/assemble/QBEAssembler.c src/Delegate.c src/Dump.c @@ -22,5 +23,4 @@ add_executable(Erythro src/Symbols.c src/Types.c src/Importer.c - src/assemble/JVMAssembler.c src/Errors.c) diff --git a/src/Importer.c b/src/Importer.c index 13f4636..322787f 100644 --- a/src/Importer.c +++ b/src/Importer.c @@ -16,6 +16,10 @@ #include #endif +#ifdef WIN32 + #define realpath(N,R) _fullpath((R),(N),PATH_MAX) +#endif + /** * The function of the importer is to read in definitions from a file, and store * them into the symbol tables. @@ -65,9 +69,10 @@ DieMessage("Unable to find cwd when importing module", Module); // Append the module name to the current working directory - char* ModulePath = malloc(sizeof(CWD) + sizeof(Module) + 1); + char* ModulePath = malloc(strlen(CWD) + strlen(Module) + 1); strcpy(ModulePath, CWD); - strcpy(ModulePath, Module); + strcpy(ModulePath + strlen(CWD), "/"); + strcpy(ModulePath + strlen(CWD) + 1, Module); printf("Scanning %s for module definitions.\n", ModulePath); @@ -77,7 +82,12 @@ free(ModulePath); char SourcePath[PATH_MAX + 1]; realpath(CurrentFile->SourceName, SourcePath); + // Deal with windows being windows char* SourceFolderLength = strrchr(SourcePath, '/'); + if (SourceFolderLength == NULL) { + SourceFolderLength = strrchr(SourcePath, '\\'); + } + *(SourceFolderLength + 1) = '\0'; size_t SourcePathLength = strlen(SourcePath); diff --git a/src/Parser.c b/src/Parser.c index 67bad81..9593761 100644 --- a/src/Parser.c +++ b/src/Parser.c @@ -430,19 +430,19 @@ struct ASTNode* ParseStatement(void) { struct ASTNode* Node; struct SymbolTableEntry* Composite; - printf("\t\tBranch leads to here, type %s/%d\r\n", TokenNames[CurrentFile->CurrentSymbol.type], CurrentFile->CurrentSymbol.type); + printf("\t\tBranch leads to type %s/%d\r\n", TokenNames[CurrentFile->CurrentSymbol.type], CurrentFile->CurrentSymbol.type); switch (CurrentFile->CurrentSymbol.type) { case LI_LBRAC: Tokenise(); Node = ParseCompound(); VerifyToken(LI_RBRAC, "}"); return Node; -/* case TY_IDENTIFIER: + case TY_IDENTIFIER: if (FindAlias(CurrentIdentifier) != NULL) { Node = ParsePrecedenceASTNode(0); VerifyToken(LI_SEMIC, ";"); return Node; - }*/ + } case TY_CHAR: case TY_LONG: case TY_INT: diff --git a/src/Statements.c b/src/Statements.c index a446a13..bfe33a4 100644 --- a/src/Statements.c +++ b/src/Statements.c @@ -148,7 +148,7 @@ static int ParseType(struct SymbolTableEntry** CompositeType, int* Scope) { Type = -1; break; default: - ErrorReport("Illegal type on token %s\n", CurrentFile->CurrentSymbol.type); + ErrorReport("Illegal type on token %s\n", TokenNames[CurrentFile->CurrentSymbol.type]); } return Type; @@ -577,7 +577,6 @@ static char* copyString(char* str) { */ static struct SymbolTableEntry* ParseDeclarationSymbol(int Type, struct SymbolTableEntry* CompositeType, int Storage, struct ASTNode** Tree) { struct SymbolTableEntry* symbol = NULL; - malloc(2); char* variableName = copyString(CurrentIdentifier); int structureType = ST_VAR; diff --git a/tests/localinit.er b/tests/localinit.er new file mode 100644 index 0000000..3b72d62 --- /dev/null +++ b/tests/localinit.er @@ -0,0 +1,11 @@ +import "import/defs.eh" + +int :: main() { + int x = 3, y = 14; + int z = 2 * x + y; + char* str = "Hello world"; + + printf("%s %d %d\n", str, x + y, z); + + return (0); +} \ No newline at end of file diff --git a/tests/sieve.er b/tests/sieve.er index 792cd70..15947ad 100644 --- a/tests/sieve.er +++ b/tests/sieve.er @@ -2,10 +2,8 @@ import "import/defs.eh" long num[100]; int :: main() { - long i; - i = 0; - long j; - j = 0; + long i = 0; + long j = 0; for (i = 0; i < 100; i++) { num[i] = i + 1;