Fixes for windows again.

This commit is contained in:
Curle 2023-12-08 03:01:56 +00:00
parent cdd8e017e2
commit 5f014fed8b
6 changed files with 30 additions and 12 deletions

View File

@ -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)

View File

@ -16,6 +16,10 @@
#include <errno.h>
#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);

View File

@ -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:

View File

@ -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;

11
tests/localinit.er Normal file
View File

@ -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);
}

View File

@ -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;