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/AssemblerDispatcher.c
src/assemble/Win32GASAssembler.c src/assemble/Win32GASAssembler.c
src/assemble/LinuxGASAssembler.c src/assemble/LinuxGASAssembler.c
src/assemble/JVMAssembler.c
src/assemble/QBEAssembler.c src/assemble/QBEAssembler.c
src/Delegate.c src/Delegate.c
src/Dump.c src/Dump.c
@ -22,5 +23,4 @@ add_executable(Erythro
src/Symbols.c src/Symbols.c
src/Types.c src/Types.c
src/Importer.c src/Importer.c
src/assemble/JVMAssembler.c
src/Errors.c) src/Errors.c)

View File

@ -16,6 +16,10 @@
#include <errno.h> #include <errno.h>
#endif #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 * The function of the importer is to read in definitions from a file, and store
* them into the symbol tables. * them into the symbol tables.
@ -65,9 +69,10 @@
DieMessage("Unable to find cwd when importing module", Module); DieMessage("Unable to find cwd when importing module", Module);
// Append the module name to the current working directory // 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, CWD);
strcpy(ModulePath, Module); strcpy(ModulePath + strlen(CWD), "/");
strcpy(ModulePath + strlen(CWD) + 1, Module);
printf("Scanning %s for module definitions.\n", ModulePath); printf("Scanning %s for module definitions.\n", ModulePath);
@ -77,7 +82,12 @@
free(ModulePath); free(ModulePath);
char SourcePath[PATH_MAX + 1]; char SourcePath[PATH_MAX + 1];
realpath(CurrentFile->SourceName, SourcePath); realpath(CurrentFile->SourceName, SourcePath);
// Deal with windows being windows
char* SourceFolderLength = strrchr(SourcePath, '/'); char* SourceFolderLength = strrchr(SourcePath, '/');
if (SourceFolderLength == NULL) {
SourceFolderLength = strrchr(SourcePath, '\\');
}
*(SourceFolderLength + 1) = '\0'; *(SourceFolderLength + 1) = '\0';
size_t SourcePathLength = strlen(SourcePath); size_t SourcePathLength = strlen(SourcePath);

View File

@ -430,19 +430,19 @@ struct ASTNode* ParseStatement(void) {
struct ASTNode* Node; struct ASTNode* Node;
struct SymbolTableEntry* Composite; 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) { switch (CurrentFile->CurrentSymbol.type) {
case LI_LBRAC: case LI_LBRAC:
Tokenise(); Tokenise();
Node = ParseCompound(); Node = ParseCompound();
VerifyToken(LI_RBRAC, "}"); VerifyToken(LI_RBRAC, "}");
return Node; return Node;
/* case TY_IDENTIFIER: case TY_IDENTIFIER:
if (FindAlias(CurrentIdentifier) != NULL) { if (FindAlias(CurrentIdentifier) != NULL) {
Node = ParsePrecedenceASTNode(0); Node = ParsePrecedenceASTNode(0);
VerifyToken(LI_SEMIC, ";"); VerifyToken(LI_SEMIC, ";");
return Node; return Node;
}*/ }
case TY_CHAR: case TY_CHAR:
case TY_LONG: case TY_LONG:
case TY_INT: case TY_INT:

View File

@ -148,7 +148,7 @@ static int ParseType(struct SymbolTableEntry** CompositeType, int* Scope) {
Type = -1; Type = -1;
break; break;
default: default:
ErrorReport("Illegal type on token %s\n", CurrentFile->CurrentSymbol.type); ErrorReport("Illegal type on token %s\n", TokenNames[CurrentFile->CurrentSymbol.type]);
} }
return 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) { static struct SymbolTableEntry* ParseDeclarationSymbol(int Type, struct SymbolTableEntry* CompositeType, int Storage, struct ASTNode** Tree) {
struct SymbolTableEntry* symbol = NULL; struct SymbolTableEntry* symbol = NULL;
malloc(2);
char* variableName = copyString(CurrentIdentifier); char* variableName = copyString(CurrentIdentifier);
int structureType = ST_VAR; 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]; long num[100];
int :: main() { int :: main() {
long i; long i = 0;
i = 0; long j = 0;
long j;
j = 0;
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
num[i] = i + 1; num[i] = i + 1;