Added the ability to select the stack size on UNIX platforms.
Fixes issue 92. git-svn-id: http://picoc.googlecode.com/svn/trunk@477 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
0ffbd21f2e
commit
8e02f32095
28
heap.c
28
heap.c
|
@ -4,18 +4,25 @@
|
|||
#define FREELIST_BUCKETS 8 /* freelists for 4, 8, 12 ... 32 byte allocs */
|
||||
#define SPLIT_MEM_THRESHOLD 16 /* don't split memory which is close in size */
|
||||
|
||||
#ifdef SURVEYOR_HOST
|
||||
#define HEAP_SIZE C_HEAPSIZE
|
||||
#ifdef USE_MALLOC_STACK
|
||||
static unsigned char *HeapMemory = NULL; /* stack memory since our heap is malloc()ed */
|
||||
static void *HeapBottom = NULL; /* the bottom of the (downward-growing) heap */
|
||||
static void *StackFrame = NULL; /* the current stack frame */
|
||||
void *HeapStackTop = NULL; /* the top of the stack */
|
||||
#else
|
||||
# ifdef SURVEYOR_HOST
|
||||
# define HEAP_SIZE C_HEAPSIZE
|
||||
static unsigned char *HeapMemory = (unsigned char *)C_HEAPSTART; /* all memory - stack and heap */
|
||||
static void *HeapBottom = (void *)C_HEAPSTART + HEAP_SIZE; /* the bottom of the (downward-growing) heap */
|
||||
static void *StackFrame = (void *)C_HEAPSTART; /* the current stack frame */
|
||||
void *HeapStackTop = (void *)C_HEAPSTART; /* the top of the stack */
|
||||
void *HeapMemStart = (void *)C_HEAPSTART;
|
||||
#else
|
||||
# else
|
||||
static unsigned char HeapMemory[HEAP_SIZE]; /* all memory - stack and heap */
|
||||
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 */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static struct AllocNode *FreeListBucket[FREELIST_BUCKETS]; /* we keep a pool of freelist buckets to reduce fragmentation */
|
||||
|
@ -35,23 +42,34 @@ void ShowBigList()
|
|||
#endif
|
||||
|
||||
/* initialise the stack and heap storage */
|
||||
void HeapInit()
|
||||
void HeapInit(int StackOrHeapSize)
|
||||
{
|
||||
int Count;
|
||||
int AlignOffset = 0;
|
||||
|
||||
#ifdef USE_MALLOC_STACK
|
||||
HeapMemory = malloc(StackOrHeapSize);
|
||||
#endif
|
||||
|
||||
while (((unsigned long)&HeapMemory[AlignOffset] & (sizeof(ALIGN_TYPE)-1)) != 0)
|
||||
AlignOffset++;
|
||||
|
||||
StackFrame = &HeapMemory[AlignOffset];
|
||||
HeapStackTop = &HeapMemory[AlignOffset];
|
||||
*(void **)StackFrame = NULL;
|
||||
HeapBottom = &HeapMemory[HEAP_SIZE-sizeof(ALIGN_TYPE)+AlignOffset];
|
||||
HeapBottom = &HeapMemory[StackOrHeapSize-sizeof(ALIGN_TYPE)+AlignOffset];
|
||||
FreeListBig = NULL;
|
||||
for (Count = 0; Count < FREELIST_BUCKETS; Count++)
|
||||
FreeListBucket[Count] = NULL;
|
||||
}
|
||||
|
||||
void HeapCleanup()
|
||||
{
|
||||
#ifdef USE_MALLOC_STACK
|
||||
free(HeapMemory);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* allocate some space on the stack, in the current stack frame
|
||||
* clears memory. can return NULL if out of stack space */
|
||||
void *HeapAllocStack(int Size)
|
||||
|
|
37
picoc.c
37
picoc.c
|
@ -5,10 +5,10 @@
|
|||
|
||||
|
||||
/* initialise everything */
|
||||
void Initialise()
|
||||
void Initialise(int StackSize)
|
||||
{
|
||||
BasicIOInit();
|
||||
HeapInit();
|
||||
HeapInit(StackSize);
|
||||
TableInit();
|
||||
VariableInit();
|
||||
LexInit();
|
||||
|
@ -31,6 +31,7 @@ void Cleanup()
|
|||
VariableCleanup();
|
||||
TypeCleanup();
|
||||
TableStrFree();
|
||||
HeapCleanup();
|
||||
}
|
||||
|
||||
/* platform-dependent code for running programs is in this file */
|
||||
|
@ -63,6 +64,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
int ParamCount = 1;
|
||||
int DontRunMain = FALSE;
|
||||
int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : STACK_SIZE;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
|
@ -72,7 +74,7 @@ int main(int argc, char **argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
Initialise();
|
||||
Initialise(StackSize);
|
||||
|
||||
if (strcmp(argv[ParamCount], "-s") == 0 || strcmp(argv[ParamCount], "-m") == 0)
|
||||
{
|
||||
|
@ -110,7 +112,7 @@ int picoc(char *SourceStr)
|
|||
{
|
||||
int ix;
|
||||
|
||||
Initialise();
|
||||
Initialise(HEAP_SIZE);
|
||||
if (SourceStr) {
|
||||
for (ix=0; ix<strlen(SourceStr); ix++) /* clear out ctrl-z from XMODEM transfer */
|
||||
if (SourceStr[ix] == 0x1A)
|
||||
|
@ -132,32 +134,5 @@ int picoc(char *SourceStr)
|
|||
Cleanup();
|
||||
return 0;
|
||||
}
|
||||
# else
|
||||
# ifdef SRV1_UNIX_HOST
|
||||
/*
|
||||
* Howard - this was my guess at what might suit you.
|
||||
* Please feel free to change this to whatever type of main function suits you best
|
||||
*/
|
||||
int picoc(char *SourceFile, int Interactive)
|
||||
{
|
||||
Initialise();
|
||||
|
||||
if (Interactive)
|
||||
ParseInteractive();
|
||||
else
|
||||
{
|
||||
if (PlatformSetExitPoint())
|
||||
{
|
||||
Cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
PlatformScanFile(SourceFile);
|
||||
}
|
||||
|
||||
Cleanup();
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
|
3
picoc.h
3
picoc.h
|
@ -371,7 +371,8 @@ struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *P
|
|||
struct ValueType *TypeCreateOpaqueStruct(struct ParseState *Parser, const char *StructName, int Size);
|
||||
|
||||
/* heap.c */
|
||||
void HeapInit();
|
||||
void HeapInit(int StackSize);
|
||||
void HeapCleanup();
|
||||
void *HeapAllocStack(int Size);
|
||||
int HeapPopStack(void *Addr, int Size);
|
||||
void HeapUnpopStack(int Size);
|
||||
|
|
115
platform.h
115
platform.h
|
@ -37,7 +37,8 @@
|
|||
|
||||
/* host platform includes */
|
||||
#ifdef UNIX_HOST
|
||||
# define HEAP_SIZE (128*1024) /* space for the the stack */
|
||||
# define STACK_SIZE (128*1024) /* space for the the stack */
|
||||
# define USE_MALLOC_STACK /* stack is allocated using malloc() */
|
||||
# define USE_MALLOC_HEAP /* heap is allocated using malloc() */
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
@ -62,87 +63,67 @@
|
|||
extern jmp_buf ExitBuf;
|
||||
|
||||
#else
|
||||
# ifdef SRV1_UNIX_HOST
|
||||
# define HEAP_SIZE (128*1024) /* space for the the stack */
|
||||
# define USE_MALLOC_HEAP /* heap is allocated using malloc() */
|
||||
# include <stdio.h>
|
||||
# ifdef FLYINGFOX_HOST
|
||||
# define HEAP_SIZE (16*1024) /* space for the heap and the stack */
|
||||
# define NO_HASH_INCLUDE
|
||||
# include <stdlib.h>
|
||||
# include <ctype.h>
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <unistd.h>
|
||||
# include <stdarg.h>
|
||||
# include <setjmp.h>
|
||||
# include <math.h>
|
||||
|
||||
extern jmp_buf ExitBuf;
|
||||
# define assert(x)
|
||||
# define BUILTIN_MINI_STDLIB
|
||||
# undef BIG_ENDIAN
|
||||
|
||||
# else
|
||||
# ifdef FLYINGFOX_HOST
|
||||
# define HEAP_SIZE (16*1024) /* space for the heap and the stack */
|
||||
# ifdef SURVEYOR_HOST
|
||||
# define NO_FP
|
||||
# define NO_CTYPE
|
||||
# define NO_HASH_INCLUDE
|
||||
# include <stdlib.h>
|
||||
# include <ctype.h>
|
||||
# include <string.h>
|
||||
# include <sys/types.h>
|
||||
# include <stdarg.h>
|
||||
# include <setjmp.h>
|
||||
# include <math.h>
|
||||
# define NO_MODULUS
|
||||
# include <cdefBF537.h>
|
||||
# include "../string.h"
|
||||
# include "../print.h"
|
||||
# include "../srv.h"
|
||||
# include "../setjmp.h"
|
||||
# include "../stdarg.h"
|
||||
# include "../colors.h"
|
||||
# include "../neural.h"
|
||||
# include "../gps.h"
|
||||
# include "../i2c.h"
|
||||
# include "../jpeg.h"
|
||||
# include "../malloc.h"
|
||||
# define assert(x)
|
||||
# define BUILTIN_MINI_STDLIB
|
||||
# undef INTERACTIVE_PROMPT_STATEMENT
|
||||
# undef INTERACTIVE_PROMPT_LINE
|
||||
# define INTERACTIVE_PROMPT_STATEMENT "> "
|
||||
# define INTERACTIVE_PROMPT_LINE "- "
|
||||
# undef BIG_ENDIAN
|
||||
|
||||
# define NO_CALLOC
|
||||
# define NO_REALLOC
|
||||
# define BROKEN_FLOAT_CASTS
|
||||
# define BUILTIN_MINI_STDLIB
|
||||
# else
|
||||
# ifdef SURVEYOR_HOST
|
||||
# ifdef UMON_HOST
|
||||
# define HEAP_SIZE (128*1024) /* space for the heap and the stack */
|
||||
# define NO_FP
|
||||
# define NO_CTYPE
|
||||
# define NO_HASH_INCLUDE
|
||||
# define NO_MODULUS
|
||||
# include <cdefBF537.h>
|
||||
# include "../string.h"
|
||||
# include "../print.h"
|
||||
# include "../srv.h"
|
||||
# include "../setjmp.h"
|
||||
# include "../stdarg.h"
|
||||
# include "../colors.h"
|
||||
# include "../neural.h"
|
||||
# include "../gps.h"
|
||||
# include "../i2c.h"
|
||||
# include "../jpeg.h"
|
||||
# include "../malloc.h"
|
||||
# define assert(x)
|
||||
# undef INTERACTIVE_PROMPT_STATEMENT
|
||||
# undef INTERACTIVE_PROMPT_LINE
|
||||
# define INTERACTIVE_PROMPT_STATEMENT "> "
|
||||
# define INTERACTIVE_PROMPT_LINE "- "
|
||||
# undef BIG_ENDIAN
|
||||
# define NO_CALLOC
|
||||
# define NO_REALLOC
|
||||
# define BROKEN_FLOAT_CASTS
|
||||
# define BUILTIN_MINI_STDLIB
|
||||
# else
|
||||
# ifdef UMON_HOST
|
||||
# define HEAP_SIZE (128*1024) /* space for the heap and the stack */
|
||||
# define NO_FP
|
||||
# define BUILTIN_MINI_STDLIB
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <ctype.h>
|
||||
# include <sys/types.h>
|
||||
# include <stdarg.h>
|
||||
# include <math.h>
|
||||
# include "monlib.h"
|
||||
# define assert(x)
|
||||
# define malloc mon_malloc
|
||||
# define calloc(a,b) mon_malloc(a*b)
|
||||
# define realloc mon_realloc
|
||||
# define free mon_free
|
||||
# undef PlatformSetExitPoint
|
||||
# define PlatformSetExitPoint()
|
||||
|
||||
# endif
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <ctype.h>
|
||||
# include <sys/types.h>
|
||||
# include <stdarg.h>
|
||||
# include <math.h>
|
||||
# include "monlib.h"
|
||||
# define assert(x)
|
||||
# define malloc mon_malloc
|
||||
# define calloc(a,b) mon_malloc(a*b)
|
||||
# define realloc mon_realloc
|
||||
# define free mon_free
|
||||
# undef PlatformSetExitPoint
|
||||
# define PlatformSetExitPoint()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue