diff --git a/heap.c b/heap.c index 026fc45..c66cb42 100644 --- a/heap.c +++ b/heap.c @@ -16,7 +16,6 @@ static unsigned char HeapMemory[HEAP_SIZE]; /* all memory - stack and he static void *HeapBottom = &HeapMemory[HEAP_SIZE]; /* the bottom of the (downward-growing) heap */ static void *StackFrame = &HeapMemory[0]; /* the current stack frame */ void *HeapStackTop = &HeapMemory[0]; /* the top of the stack */ -void *HeapMemStart = &HeapMemory[0]; #endif static struct AllocNode *FreeListBucket[FREELIST_BUCKETS]; /* we keep a pool of freelist buckets to reduce fragmentation */ @@ -39,11 +38,15 @@ void ShowBigList() void HeapInit() { int Count; + int AlignOffset = 0; - StackFrame = &HeapMemory[0]; - HeapStackTop = &HeapMemory[0]; + while (((unsigned int)&HeapMemory[AlignOffset] & (sizeof(ALIGN_TYPE)-1)) != 0) + AlignOffset++; + + StackFrame = &HeapMemory[AlignOffset]; + HeapStackTop = &HeapMemory[AlignOffset]; *(void **)StackFrame = NULL; - HeapBottom = &HeapMemory[HEAP_SIZE]; + HeapBottom = &HeapMemory[HEAP_SIZE-sizeof(ALIGN_TYPE)+AlignOffset]; FreeListBig = NULL; for (Count = 0; Count < FREELIST_BUCKETS; Count++) FreeListBucket[Count] = NULL; diff --git a/picoc.h b/picoc.h index aa6b564..f8f0ef6 100644 --- a/picoc.h +++ b/picoc.h @@ -17,7 +17,7 @@ #define min(x,y) (((x)<(y))?(x):(y)) #endif -#define MEM_ALIGN(x) (((x) + ARCH_ALIGN_WORDSIZE - 1) & ~(ARCH_ALIGN_WORDSIZE-1)) +#define MEM_ALIGN(x) (((x) + sizeof(ALIGN_TYPE) - 1) & ~(sizeof(ALIGN_TYPE)-1)) #define GETS_BUF_MAX 256 @@ -260,7 +260,6 @@ enum ParseResult { ParseResultEOF, ParseResultError, ParseResultOk }; /* globals */ extern void *HeapStackTop; -extern void *HeapMemStart; extern struct Table GlobalTable; extern struct StackFrame *TopStackFrame; extern struct ValueType UberType; diff --git a/platform.h b/platform.h index c34f91e..216b9cd 100644 --- a/platform.h +++ b/platform.h @@ -11,8 +11,11 @@ */ #define LARGE_INT_POWER_OF_TEN 1000000000 /* the largest power of ten which fits in an int on this architecture */ +#ifdef __hppa__ +#define ALIGN_TYPE double /* the data type to use for alignment */ +#else #define ALIGN_TYPE void * /* the data type to use for alignment */ -#define ARCH_ALIGN_WORDSIZE sizeof(ALIGN_TYPE) /* memory alignment boundary on this architecture */ +#endif #define GLOBAL_TABLE_SIZE 97 /* global variable table */ #define STRING_TABLE_SIZE 97 /* shared string table size */ @@ -50,7 +53,6 @@ # include # define PICOC_MATH_LIBRARY # define NEED_MATH_LIBRARY -# undef BIG_ENDIAN #endif extern jmp_buf ExitBuf;