fix lots more issues, add endian conversions to ObjGenMachO, add 64-bit kludge to Switch.c

This commit is contained in:
Ash Wolf
2023-01-13 01:36:56 +00:00
parent 3a6db389b2
commit 9d985413ce
25 changed files with 362 additions and 249 deletions

View File

@@ -4137,7 +4137,6 @@ static void prependif(void) {
}
static void prepifskip(void) {
// this function does something very weird with its code generation that i can't match
TStreamElement ts;
short t;
@@ -4146,78 +4145,75 @@ static void prepifskip(void) {
case IfState_1:
case IfState_3:
case IfState_4:
while (1) {
t = prepskipnextchar();
pos = nextcharpos;
switch (t) {
case 0:
if (tokenstacklevel > 0) {
poptokenseq();
} else if (tokenstacklevel > 0 || pos >= prep_file_end) {
if (filesp > 0) {
popfile();
} else {
was_prep_error = 0;
ts.tokenfile = ifstack[iflevel - 1].file;
ts.tokenoffset = ifstack[iflevel - 1].pos;
CError_SetErrorToken(&ts);
CError_ErrorTerm(CErrorStr119);
iflevel = 0;
return;
}
restart:
t = prepskipnextchar();
pos = nextcharpos;
switch (t) {
case 0:
if (tokenstacklevel > 0) {
poptokenseq();
} else if (tokenstacklevel > 0 || pos >= prep_file_end) {
if (filesp > 0) {
popfile();
} else {
CPrep_Error(CErrorStr105);
was_prep_error = 0;
ts.tokenfile = ifstack[iflevel - 1].file;
ts.tokenoffset = ifstack[iflevel - 1].pos;
CError_SetErrorToken(&ts);
CError_ErrorTerm(CErrorStr119);
iflevel = 0;
return;
}
continue;
case '\r':
newline();
continue;
case '"':
skipendoflinematch((StringPtr) pos, '"');
continue;
case '\'':
skipendoflinematch((StringPtr) pos, '"');
continue;
case '#':
t = prepskipnextchar();
pos = nextcharpos;
switch (t) {
case '\r':
continue;
case 0:
CPrep_Error(CErrorStr102);
default:
pos = ReadIdentifier(pos - 1);
if (!strcmp("if", tkidentifier->name)) {
prepif();
} else if (!strcmp("ifdef", tkidentifier->name)) {
prepifdef();
} else if (!strcmp("ifndef", tkidentifier->name)) {
prepifndef();
} else if (!strcmp("elif", tkidentifier->name)) {
prepelif();
} else if (!strcmp("else", tkidentifier->name)) {
prepelse();
} else if (!strcmp("endif", tkidentifier->name)) {
prependif();
} else {
skipendofline();
continue;
}
}
break;
default:
skipendofline();
continue;
}
break;
} else {
CPrep_Error(CErrorStr105);
}
goto restart;
case '\r':
newline();
goto restart;
case '"':
skipendoflinematch((StringPtr) pos, '"');
goto restart;
case '\'':
skipendoflinematch((StringPtr) pos, '"');
goto restart;
case '#':
t = prepskipnextchar();
pos = nextcharpos;
switch (t) {
case '\r':
goto restart;
case 0:
CPrep_Error(CErrorStr102);
default:
pos = ReadIdentifier(pos - 1);
if (!strcmp("if", tkidentifier->name)) {
prepif();
} else if (!strcmp("ifdef", tkidentifier->name)) {
prepifdef();
} else if (!strcmp("ifndef", tkidentifier->name)) {
prepifndef();
} else if (!strcmp("elif", tkidentifier->name)) {
prepelif();
} else if (!strcmp("else", tkidentifier->name)) {
prepelse();
} else if (!strcmp("endif", tkidentifier->name)) {
prependif();
} else {
skipendofline();
goto restart;
}
}
break;
default:
skipendofline();
goto restart;
}
break;
case IfState_2:
default:
return;
}
return;
}
}

View File

@@ -53,6 +53,69 @@ unsigned char *CTool_CtoPstr(char *cstr) {
return (unsigned char *) cstr;
}
#ifdef CW_64_BIT_SUPPORT
enum { PoolCapacity = 64 };
typedef struct ITPPool {
void *pointers[PoolCapacity];
UInt32 baseIndex;
UInt32 size;
struct ITPPool *next;
} ITPPool;
static ITPPool *poolHead;
static ITPPool *poolTail;
void *CTool_ResolveIndexToPointer(UInt32 index) {
ITPPool *pool = poolHead;
if (index == 0)
return NULL;
while (pool && index >= PoolCapacity) {
pool = pool->next;
index -= PoolCapacity;
}
if (pool && index < pool->size)
return pool->pointers[index];
else
return NULL;
}
UInt32 CTool_CreateIndexFromPointer(void *ptr) {
ITPPool *pool = poolTail;
UInt32 index;
if (ptr == NULL)
return 0;
if (!pool || pool->size >= PoolCapacity) {
pool = lalloc(sizeof(ITPPool));
pool->size = 0;
if (poolTail) {
pool->baseIndex = poolTail->baseIndex + PoolCapacity;
poolTail->next = pool;
} else {
pool->baseIndex = 0;
// always reserve index 0 for NULL
pool->pointers[0] = NULL;
pool->size = 1;
poolHead = pool;
}
poolTail = pool;
}
index = pool->baseIndex + pool->size;
pool->pointers[pool->size] = ptr;
pool->size++;
return index;
}
static void CTool_ResetPointerPool(void) {
poolHead = NULL;
poolTail = NULL;
}
#endif
static void GListError(void) {
if (GListErrorProc)
GListErrorProc();
@@ -845,6 +908,10 @@ void freelheap(void) {
blockp->blockfree = blockp->blocksize - sizeof(HeapBlock);
blockp = blockp->next;
}
#ifdef CW_64_BIT_SUPPORT
CTool_ResetPointerPool();
#endif
}
}