From: phil@softsynth.com Date: Thu, 20 May 2010 00:15:20 +0000 (+0000) Subject: V25 with 64-bit support X-Git-Url: http://git.subgeniuskitty.com/pforth/.git/commitdiff_plain/1cb310e62eaf4422ee298d9d87c35f9dd6b4c71c V25 with 64-bit support --- diff --git a/build/unix/Makefile b/build/unix/Makefile index a7dbb5d..de0b90f 100644 --- a/build/unix/Makefile +++ b/build/unix/Makefile @@ -24,7 +24,7 @@ OBJECTDIR = $(PFORTHDIR)/objects TEMPOBJECTDIR = $(PFORTHDIR)/tempobjects # This is needed to get pForth to build on Snow Leopard and other 64 bit platforms. -WIDTHOPT=-m32 +WIDTHOPT= FULL_WARNINGS = \ -fsigned-char \ @@ -38,7 +38,7 @@ FULL_WARNINGS = \ -Winline \ -Wmissing-prototypes \ -Wmissing-declarations - + DEBUGOPTS = -g CCOPTS = $(WIDTHOPT) -x c -DPF_SUPPORT_FP -O2 $(FULL_WARNINGS) $(EXTRA_CCOPTS) $(DEBUGOPTS) @@ -57,11 +57,11 @@ PFOBJS = ${PFTEMP:${CSRCDIR}/%=${TEMPOBJECTDIR}/%} PFEMBOBJS = ${PFTEMP:${CSRCDIR}/%=${OBJECTDIR}/%} COMPILE = $(COMPILER) $(CCOPTS) $(CDEFS) - + ${TEMPOBJECTDIR}/%.o: ${TEMPOBJECTDIR} $(PFINCLUDES) ${CSRCDIR}/%.c $(COMPILE) -O -o ${TEMPOBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c - -${OBJECTDIR}/%.o: ${OBJECTDIR} $(PFINCLUDES) ${CSRCDIR}/%.c ${CSRCDIR}/pfdicdat.h + +${OBJECTDIR}/%.o: ${OBJECTDIR} $(PFINCLUDES) ${CSRCDIR}/%.c ${CSRCDIR}/pfdicdat.h $(COMPILE) -O -o ${OBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c $(EMBCCOPTS) all: $(PFORTHAPP) @@ -77,12 +77,12 @@ pffiles: @echo ${PFOBJS} @echo "EMBEDDED OBJECT FILES ------------------" @echo ${PFEMBOBJS} - -${TEMPOBJECTDIR}: + +${TEMPOBJECTDIR}: mkdir -p ${TEMPOBJECTDIR}/posix mkdir -p ${TEMPOBJECTDIR}/stdio -${OBJECTDIR}: +${OBJECTDIR}: mkdir -p ${OBJECTDIR}/posix mkdir -p ${OBJECTDIR}/stdio @@ -98,8 +98,8 @@ $(PFORTHAPP): $(PFDICDAT) $(PFEMBOBJS) $(COMPILER) $(PFEMBOBJS) $(WIDTHOPT) -lm -o $(PFORTHAPP) @echo "" @echo "Standalone pForth executable written to $(PFORTHAPP)" - - + + # target aliases pfdicapp: $(PFDICAPP) @@ -119,8 +119,8 @@ help: clean: - -rm -f $(PFOBJS) $(PFEMBOBJS) - -rm $(PFORTHAPP) - -rm $(PFDICDAT) - -rm $(PFORTHDIC) - -rm $(PFDICAPP) + rm -f $(PFOBJS) $(PFEMBOBJS) + rm -f $(PFORTHAPP) + rm -f $(PFDICDAT) + rm -f $(PFORTHDIC) + rm -f $(PFDICAPP) diff --git a/csrc/pf_cglue.c b/csrc/pf_cglue.c index d768ea4..2e6f52d 100644 --- a/csrc/pf_cglue.c +++ b/csrc/pf_cglue.c @@ -21,10 +21,10 @@ extern CFunc0 CustomFunctionTable[]; /***************************************************************/ -int32 CallUserFunction( int32 Index, int32 ReturnMode, int32 NumParams ) +cell_t CallUserFunction( cell_t Index, int32_t ReturnMode, int32_t NumParams ) { - cell P1, P2, P3, P4, P5; - cell Result = 0; + cell_t P1, P2, P3, P4, P5; + cell_t Result = 0; CFunc0 CF; DBUG(("CallUserFunction: Index = %d, ReturnMode = %d, NumParams = %d\n", @@ -80,9 +80,9 @@ DBUG(("CallUserFunction: Index = %d, ReturnMode = %d, NumParams = %d\n", #if (!defined(PF_NO_INIT)) && (!defined(PF_NO_SHELL)) /***************************************************************/ -Err CreateGlueToC( const char *CName, uint32 Index, int32 ReturnMode, int32 NumParams ) +Err CreateGlueToC( const char *CName, ucell_t Index, cell_t ReturnMode, int32_t NumParams ) { - uint32 Packed; + ucell_t Packed; char FName[40]; CStringToForth( FName, CName ); diff --git a/csrc/pf_cglue.h b/csrc/pf_cglue.h index 530c2f4..c3ddc87 100644 --- a/csrc/pf_cglue.h +++ b/csrc/pf_cglue.h @@ -19,21 +19,21 @@ ** ***************************************************************/ -typedef cell (*CFunc0)( void ); -typedef cell (*CFunc1)( cell P1 ); -typedef cell (*CFunc2)( cell P1, cell P2 ); -typedef cell (*CFunc3)( cell P1, cell P2, cell P3 ); -typedef cell (*CFunc4)( cell P1, cell P2, cell P3, cell P4 ); -typedef cell (*CFunc5)( cell P1, cell P2, cell P3, cell P4, cell P5 ); +typedef cell_t (*CFunc0)( void ); +typedef cell_t (*CFunc1)( cell_t P1 ); +typedef cell_t (*CFunc2)( cell_t P1, cell_t P2 ); +typedef cell_t (*CFunc3)( cell_t P1, cell_t P2, cell_t P3 ); +typedef cell_t (*CFunc4)( cell_t P1, cell_t P2, cell_t P3, cell_t P4 ); +typedef cell_t (*CFunc5)( cell_t P1, cell_t P2, cell_t P3, cell_t P4, cell_t P5 ); #ifdef __cplusplus extern "C" { #endif -Err CreateGlueToC( const char *CName, uint32 Index, int32 ReturnMode, int32 NumParams ); +Err CreateGlueToC( const char *CName, ucell_t Index, cell_t ReturnMode, int32_t NumParams ); Err CompileCustomFunctions( void ); Err LoadCustomFunctionTable( void ); -int32 CallUserFunction( int32 Index, int32 ReturnMode, int32 NumParams ); +cell_t CallUserFunction( cell_t Index, int32_t ReturnMode, int32_t NumParams ); #ifdef __cplusplus } diff --git a/csrc/pf_clib.c b/csrc/pf_clib.c index ac0beee..0299c3b 100644 --- a/csrc/pf_clib.c +++ b/csrc/pf_clib.c @@ -27,26 +27,26 @@ #ifdef PF_NO_CLIB /* Count chars until NUL. Replace strlen() */ #define NUL ((char) 0) -cell pfCStringLength( const char *s ) +cell_t pfCStringLength( const char *s ) { - cell len = 0; + cell_t len = 0; while( *s++ != NUL ) len++; return len; } -/* void *memset (void *s, int32 c, size_t n); */ -void *pfSetMemory( void *s, cell c, cell n ) +/* void *memset (void *s, cell_t c, size_t n); */ +void *pfSetMemory( void *s, cell_t c, cell_t n ) { - uint8 *p = s, byt = (uint8) c; + uint8_t *p = s, byt = (uint8_t) c; while( (n--) > 0) *p++ = byt; return s; } -/* void *memccpy (void *s1, const void *s2, int32 c, size_t n); */ -void *pfCopyMemory( void *s1, const void *s2, cell n) +/* void *memccpy (void *s1, const void *s2, cell_t c, size_t n); */ +void *pfCopyMemory( void *s1, const void *s2, cell_t n) { - uint8 *p1 = s1; - const uint8 *p2 = s2; + uint8_t *p1 = s1; + const uint8_t *p2 = s2; while( (n--) > 0) *p1++ = *p2++; return s1; } diff --git a/csrc/pf_clib.h b/csrc/pf_clib.h index 0d8ad18..da3dc5f 100644 --- a/csrc/pf_clib.h +++ b/csrc/pf_clib.h @@ -25,9 +25,9 @@ extern "C" { #endif - cell pfCStringLength( const char *s ); - void *pfSetMemory( void *s, cell c, cell n ); - void *pfCopyMemory( void *s1, const void *s2, cell n); + cell_t pfCStringLength( const char *s ); + void *pfSetMemory( void *s, cell_t c, cell_t n ); + void *pfCopyMemory( void *s1, const void *s2, cell_t n); #define EXIT(n) {while(1);} #ifdef __cplusplus diff --git a/csrc/pf_core.c b/csrc/pf_core.c index 740d942..7abe8c1 100644 --- a/csrc/pf_core.c +++ b/csrc/pf_core.c @@ -42,7 +42,7 @@ char gScratch[TIB_SIZE]; pfTaskData_t *gCurrentTask = NULL; pfDictionary_t *gCurrentDictionary; -int32 gNumPrimitives; +cell_t gNumPrimitives; ExecToken gLocalCompiler_XT; /* custom compiler for local variables */ ExecToken gNumberQ_XT; /* XT of NUMBER? */ @@ -50,22 +50,22 @@ ExecToken gQuitP_XT; /* XT of (QUIT) */ ExecToken gAcceptP_XT; /* XT of ACCEPT */ /* Depth of data stack when colon called. */ -int32 gDepthAtColon; +cell_t gDepthAtColon; /* Global Forth variables. */ char *gVarContext; /* Points to last name field. */ -cell gVarState; /* 1 if compiling. */ -cell gVarBase; /* Numeric Base. */ -cell gVarEcho; /* Echo input. */ -cell gVarTraceLevel; /* Trace Level for Inner Interpreter. */ -cell gVarTraceStack; /* Dump Stack each time if true. */ -cell gVarTraceFlags; /* Enable various internal debug messages. */ -cell gVarQuiet; /* Suppress unnecessary messages, OK, etc. */ -cell gVarReturnCode; /* Returned to caller of Forth, eg. UNIX shell. */ +cell_t gVarState; /* 1 if compiling. */ +cell_t gVarBase; /* Numeric Base. */ +cell_t gVarEcho; /* Echo input. */ +cell_t gVarTraceLevel; /* Trace Level for Inner Interpreter. */ +cell_t gVarTraceStack; /* Dump Stack each time if true. */ +cell_t gVarTraceFlags; /* Enable various internal debug messages. */ +cell_t gVarQuiet; /* Suppress unnecessary messages, OK, etc. */ +cell_t gVarReturnCode; /* Returned to caller of Forth, eg. UNIX shell. */ /* data for INCLUDE that allows multiple nested files. */ IncludeFrame gIncludeStack[MAX_INCLUDE_DEPTH]; -int32 gIncludeIndex; +cell_t gIncludeIndex; static void pfResetForthTask( void ); static void pfInit( void ); @@ -123,7 +123,7 @@ void pfDeleteTask( PForthTask task ) /* Allocate some extra cells to protect against mild stack underflows. */ #define STACK_SAFETY (8) -PForthTask pfCreateTask( int32 UserStackDepth, int32 ReturnStackDepth ) +PForthTask pfCreateTask( cell_t UserStackDepth, cell_t ReturnStackDepth ) { pfTaskData_t *cftd; @@ -132,14 +132,14 @@ PForthTask pfCreateTask( int32 UserStackDepth, int32 ReturnStackDepth ) pfSetMemory( cftd, 0, sizeof( pfTaskData_t )); /* Allocate User Stack */ - cftd->td_StackLimit = (cell *) pfAllocMem((uint32)(sizeof(int32) * + cftd->td_StackLimit = (cell_t *) pfAllocMem((ucell_t)(sizeof(cell_t) * (UserStackDepth + STACK_SAFETY))); if( !cftd->td_StackLimit ) goto nomem; cftd->td_StackBase = cftd->td_StackLimit + UserStackDepth; cftd->td_StackPtr = cftd->td_StackBase; /* Allocate Return Stack */ - cftd->td_ReturnLimit = (cell *) pfAllocMem((uint32)(sizeof(int32) * ReturnStackDepth) ); + cftd->td_ReturnLimit = (cell_t *) pfAllocMem((ucell_t)(sizeof(cell_t) * ReturnStackDepth) ); if( !cftd->td_ReturnLimit ) goto nomem; cftd->td_ReturnBase = cftd->td_ReturnLimit + ReturnStackDepth; cftd->td_ReturnPtr = cftd->td_ReturnBase; @@ -147,7 +147,7 @@ PForthTask pfCreateTask( int32 UserStackDepth, int32 ReturnStackDepth ) /* Allocate Float Stack */ #ifdef PF_SUPPORT_FP /* Allocate room for as many Floats as we do regular data. */ - cftd->td_FloatStackLimit = (PF_FLOAT *) pfAllocMem((uint32)(sizeof(PF_FLOAT) * + cftd->td_FloatStackLimit = (PF_FLOAT *) pfAllocMem((ucell_t)(sizeof(PF_FLOAT) * (UserStackDepth + STACK_SAFETY))); if( !cftd->td_FloatStackLimit ) goto nomem; cftd->td_FloatStackBase = cftd->td_FloatStackLimit + UserStackDepth; @@ -171,7 +171,7 @@ nomem: ** Dictionary Management ***************************************************************/ -int32 pfExecIfDefined( const char *CString ) +cell_t pfExecIfDefined( const char *CString ) { int result = 0; if( NAME_BASE != NULL) @@ -208,7 +208,7 @@ void pfDeleteDictionary( PForthDictionary dictionary ) ** Delete using pfDeleteDictionary(). ** Return pointer to dictionary management structure. */ -PForthDictionary pfCreateDictionary( int32 HeaderSize, int32 CodeSize ) +PForthDictionary pfCreateDictionary( cell_t HeaderSize, cell_t CodeSize ) { /* Allocate memory for initial dictionary. */ pfDictionary_t *dic; @@ -221,19 +221,19 @@ PForthDictionary pfCreateDictionary( int32 HeaderSize, int32 CodeSize ) /* Align dictionary segments to preserve alignment of floats across hosts. * Thank you Helmut Proelss for pointing out that this needs to be cast - * to (uint32) on 16 bit systems. + * to (ucell_t) on 16 bit systems. */ -#define DIC_ALIGNMENT_SIZE ((uint32)(0x10)) -#define DIC_ALIGN(addr) ((uint8 *)((((uint32)(addr)) + DIC_ALIGNMENT_SIZE - 1) & ~(DIC_ALIGNMENT_SIZE - 1))) +#define DIC_ALIGNMENT_SIZE ((ucell_t)(0x10)) +#define DIC_ALIGN(addr) ((uint8_t *)((((ucell_t)(addr)) + DIC_ALIGNMENT_SIZE - 1) & ~(DIC_ALIGNMENT_SIZE - 1))) /* Allocate memory for header. */ if( HeaderSize > 0 ) { - dic->dic_HeaderBaseUnaligned = ( uint8 * ) pfAllocMem( (uint32) HeaderSize + DIC_ALIGNMENT_SIZE ); + dic->dic_HeaderBaseUnaligned = ( uint8_t * ) pfAllocMem( (ucell_t) HeaderSize + DIC_ALIGNMENT_SIZE ); if( !dic->dic_HeaderBaseUnaligned ) goto nomem; /* Align header base. */ dic->dic_HeaderBase = DIC_ALIGN(dic->dic_HeaderBaseUnaligned); - pfSetMemory( dic->dic_HeaderBase, 0xA5, (uint32) HeaderSize); + pfSetMemory( dic->dic_HeaderBase, 0xA5, (ucell_t) HeaderSize); dic->dic_HeaderLimit = dic->dic_HeaderBase + HeaderSize; dic->dic_HeaderPtr.Byte = dic->dic_HeaderBase; } @@ -243,10 +243,10 @@ PForthDictionary pfCreateDictionary( int32 HeaderSize, int32 CodeSize ) } /* Allocate memory for code. */ - dic->dic_CodeBaseUnaligned = ( uint8 * ) pfAllocMem( (uint32) CodeSize + DIC_ALIGNMENT_SIZE ); + dic->dic_CodeBaseUnaligned = ( uint8_t * ) pfAllocMem( (ucell_t) CodeSize + DIC_ALIGNMENT_SIZE ); if( !dic->dic_CodeBaseUnaligned ) goto nomem; dic->dic_CodeBase = DIC_ALIGN(dic->dic_CodeBaseUnaligned); - pfSetMemory( dic->dic_CodeBase, 0x5A, (uint32) CodeSize); + pfSetMemory( dic->dic_CodeBase, 0x5A, (ucell_t) CodeSize); dic->dic_CodeLimit = dic->dic_CodeBase + CodeSize; dic->dic_CodePtr.Byte = dic->dic_CodeBase + QUADUP(NUM_PRIMITIVES); @@ -291,16 +291,16 @@ void pfSetCurrentTask( PForthTask task ) ** Set Quiet Flag. ***************************************************************/ -void pfSetQuiet( int32 IfQuiet ) +void pfSetQuiet( cell_t IfQuiet ) { - gVarQuiet = (cell) IfQuiet; + gVarQuiet = (cell_t) IfQuiet; } /*************************************************************** ** Query message status. ***************************************************************/ -int32 pfQueryQuiet( void ) +cell_t pfQueryQuiet( void ) { return gVarQuiet; } @@ -347,12 +347,12 @@ ThrowCode pfQuit( void ) ** Include file based on 'C' name. ***************************************************************/ -int32 pfIncludeFile( const char *FileName ) +cell_t pfIncludeFile( const char *FileName ) { FileStream *fid; - int32 Result; + cell_t Result; char buffer[32]; - int32 numChars, len; + cell_t numChars, len; /* Open file. */ fid = sdOpenFile( FileName, "r" ); @@ -366,7 +366,7 @@ int32 pfIncludeFile( const char *FileName ) /* Create a dictionary word named ::::FileName for FILE? */ pfCopyMemory( &buffer[0], "::::", 4); - len = (int32) pfCStringLength(FileName); + len = (cell_t) pfCStringLength(FileName); numChars = ( len > (32-4-1) ) ? (32-4-1) : len; pfCopyMemory( &buffer[4], &FileName[len-numChars], numChars+1 ); CreateDicEntryC( ID_NOOP, buffer, 0 ); @@ -423,17 +423,17 @@ void pfDebugPrintDecimalNumber( int n ) ***************************************************************/ void pfMessage( const char *CString ) { - ioType( CString, (int32) pfCStringLength(CString) ); + ioType( CString, (cell_t) pfCStringLength(CString) ); } /************************************************************************** -** Main entry point for pForth. +** Main entry point for pForth. */ -int32 pfDoForth( const char *DicFileName, const char *SourceName, int32 IfInit ) +cell_t pfDoForth( const char *DicFileName, const char *SourceName, cell_t IfInit ) { pfTaskData_t *cftd; pfDictionary_t *dic = NULL; - int32 Result = 0; + cell_t Result = 0; ExecToken EntryPoint = 0; #ifdef PF_USER_INIT @@ -461,6 +461,15 @@ int32 pfDoForth( const char *DicFileName, const char *SourceName, int32 IfInit ) #elif PF_LITTLE_ENDIAN_DIC MSG("/LE"); #endif + if (sizeof(cell_t) == 8) + { + MSG("/64"); + } + else if (sizeof(cell_t) == 4) + { + MSG("/32"); + } + MSG( ", built "__DATE__" "__TIME__ ); } diff --git a/csrc/pf_guts.h b/csrc/pf_guts.h index b3814ad..0e34581 100644 --- a/csrc/pf_guts.h +++ b/csrc/pf_guts.h @@ -23,7 +23,7 @@ ** PFORTH_VERSION changes when PForth is modified and released. ** See README file for version info. */ -#define PFORTH_VERSION "24" +#define PFORTH_VERSION "25" /* ** PFORTH_FILE_VERSION changes when incompatible changes are made @@ -35,9 +35,10 @@ ** FV6 - 961213 - Added ID_LOCAL_PLUSSTORE, ID_COLON_P, etc. ** FV7 - 971203 - Added ID_FILL, (1LOCAL@), etc., ran out of reserved, resorted. ** FV8 - 980818 - Added Endian flag. +** FV9 - 20100503 - Added support for 64-bit CELL. */ -#define PF_FILE_VERSION (8) /* Bump this whenever primitives added. */ -#define PF_EARLIEST_FILE_VERSION (8) /* earliest one still compatible */ +#define PF_FILE_VERSION (9) /* Bump this whenever primitives added. */ +#define PF_EARLIEST_FILE_VERSION (9) /* earliest one still compatible */ /*************************************************************** ** Sizes and other constants @@ -72,7 +73,7 @@ #define NUM_TYPE_DOUBLE (2) #define NUM_TYPE_FLOAT (3) -#define CREATE_BODY_OFFSET (3*sizeof(cell)) +#define CREATE_BODY_OFFSET (3*sizeof(cell_t)) /*************************************************************** ** Primitive Token IDS @@ -275,6 +276,9 @@ enum cforth_primitive_ids ID_INTERPRET, ID_FILE_WO, ID_FILE_BIN, + /* Added to support 64 bit operation. */ + ID_CELL, + ID_CELLS, /* If you add a word here, take away one reserved word below. */ #ifdef PF_SUPPORT_FP /* Only reserve space if we are adding FP so that we can detect @@ -294,8 +298,6 @@ enum cforth_primitive_ids ID_RESERVED12, ID_RESERVED13, ID_RESERVED14, - ID_RESERVED15, - ID_RESERVED16, ID_FP_D_TO_F, ID_FP_FSTORE, ID_FP_FTIMES, @@ -377,26 +379,26 @@ enum cforth_primitive_ids typedef struct pfTaskData_s { - cell *td_StackPtr; /* Primary data stack */ - cell *td_StackBase; - cell *td_StackLimit; - cell *td_ReturnPtr; /* Return stack */ - cell *td_ReturnBase; - cell *td_ReturnLimit; + cell_t *td_StackPtr; /* Primary data stack */ + cell_t *td_StackBase; + cell_t *td_StackLimit; + cell_t *td_ReturnPtr; /* Return stack */ + cell_t *td_ReturnBase; + cell_t *td_ReturnLimit; #ifdef PF_SUPPORT_FP PF_FLOAT *td_FloatStackPtr; PF_FLOAT *td_FloatStackBase; PF_FLOAT *td_FloatStackLimit; #endif - cell *td_InsPtr; /* Instruction pointer, "PC" */ + cell_t *td_InsPtr; /* Instruction pointer, "PC" */ FileStream *td_InputStream; /* Terminal. */ char td_TIB[TIB_SIZE]; /* Buffer for terminal input. */ - cell td_IN; /* Index into Source */ - cell td_SourceNum; /* #TIB after REFILL */ + cell_t td_IN; /* Index into Source */ + cell_t td_SourceNum; /* #TIB after REFILL */ char *td_SourcePtr; /* Pointer to TIB or other source. */ - int32 td_LineNumber; /* Incremented on every refill. */ - cell td_OUT; /* Current output column. */ + cell_t td_LineNumber; /* Incremented on every refill. */ + cell_t td_OUT; /* Current output column. */ } pfTaskData_t; typedef struct pfNode @@ -408,7 +410,7 @@ typedef struct pfNode /* Structure of header entry in dictionary. These will be stored in dictionary specific endian format*/ typedef struct cfNameLinks { - cell cfnl_PreviousName; /* name relative address of previous */ + cell_t cfnl_PreviousName; /* name relative address of previous */ ExecToken cfnl_ExecToken; /* Execution token for word. */ /* Followed by variable length name field. */ } cfNameLinks; @@ -417,38 +419,38 @@ typedef struct cfNameLinks typedef struct pfDictionary_s { pfNode dic_Node; - uint32 dic_Flags; + ucell_t dic_Flags; /* Headers contain pointers to names and dictionary. */ - uint8 *dic_HeaderBaseUnaligned; + uint8_t *dic_HeaderBaseUnaligned; - uint8 *dic_HeaderBase; + uint8_t *dic_HeaderBase; union { - cell *Cell; - uint8 *Byte; + cell_t *Cell; + uint8_t *Byte; } dic_HeaderPtr; - uint8 *dic_HeaderLimit; + uint8_t *dic_HeaderLimit; /* Code segment contains tokenized code and data. */ - uint8 *dic_CodeBaseUnaligned; + uint8_t *dic_CodeBaseUnaligned; - uint8 *dic_CodeBase; + uint8_t *dic_CodeBase; union { - cell *Cell; - uint8 *Byte; + cell_t *Cell; + uint8_t *Byte; } dic_CodePtr; - uint8 *dic_CodeLimit; + uint8_t *dic_CodeLimit; } pfDictionary_t; /* Save state of include when nesting files. */ typedef struct IncludeFrame { FileStream *inf_FileID; - int32 inf_LineNumber; - int32 inf_SourceNum; - int32 inf_IN; + cell_t inf_LineNumber; + cell_t inf_SourceNum; + cell_t inf_IN; char inf_SaveTIB[TIB_SIZE]; } IncludeFrame; @@ -474,7 +476,7 @@ int pfCatch( ExecToken XT ); extern pfTaskData_t *gCurrentTask; extern pfDictionary_t *gCurrentDictionary; extern char gScratch[TIB_SIZE]; -extern int32 gNumPrimitives; +extern cell_t gNumPrimitives; extern ExecToken gLocalCompiler_XT; /* CFA of (LOCAL) compiler. */ extern ExecToken gNumberQ_XT; /* XT of NUMBER? */ @@ -482,22 +484,22 @@ extern ExecToken gQuitP_XT; /* XT of (QUIT) */ extern ExecToken gAcceptP_XT; /* XT of ACCEPT */ #define DEPTH_AT_COLON_INVALID (-100) -extern int32 gDepthAtColon; +extern cell_t gDepthAtColon; /* Global variables. */ extern char *gVarContext; /* Points to last name field. */ -extern cell gVarState; /* 1 if compiling. */ -extern cell gVarBase; /* Numeric Base. */ -extern cell gVarEcho; /* Echo input from file. */ -extern cell gVarEchoAccept; /* Echo input from ACCEPT. */ -extern cell gVarTraceLevel; -extern cell gVarTraceStack; -extern cell gVarTraceFlags; -extern cell gVarQuiet; /* Suppress unnecessary messages, OK, etc. */ -extern cell gVarReturnCode; /* Returned to caller of Forth, eg. UNIX shell. */ +extern cell_t gVarState; /* 1 if compiling. */ +extern cell_t gVarBase; /* Numeric Base. */ +extern cell_t gVarEcho; /* Echo input from file. */ +extern cell_t gVarEchoAccept; /* Echo input from ACCEPT. */ +extern cell_t gVarTraceLevel; +extern cell_t gVarTraceStack; +extern cell_t gVarTraceFlags; +extern cell_t gVarQuiet; /* Suppress unnecessary messages, OK, etc. */ +extern cell_t gVarReturnCode; /* Returned to caller of Forth, eg. UNIX shell. */ extern IncludeFrame gIncludeStack[MAX_INCLUDE_DEPTH]; -extern int32 gIncludeIndex; +extern cell_t gIncludeIndex; /*************************************************************** ** Macros ***************************************************************/ @@ -512,51 +514,51 @@ extern int32 gIncludeIndex; #if defined(PF_BIG_ENDIAN_DIC) #define WRITE_FLOAT_DIC WriteFloatBigEndian -#define WRITE_LONG_DIC(addr,data) WriteLongBigEndian((uint32 *)(addr),(uint32)(data)) -#define WRITE_SHORT_DIC(addr,data) WriteShortBigEndian((uint16 *)(addr),(uint16)(data)) +#define WRITE_CELL_DIC(addr,data) WriteCellBigEndian((uint8_t *)(addr),(ucell_t)(data)) +#define WRITE_SHORT_DIC(addr,data) Write16BigEndian((uint8_t *)(addr),(uint16_t)(data)) #define READ_FLOAT_DIC ReadFloatBigEndian -#define READ_LONG_DIC(addr) ReadLongBigEndian((const uint32 *)(addr)) -#define READ_SHORT_DIC(addr) ReadShortBigEndian((const uint16 *)(addr)) +#define READ_CELL_DIC(addr) ReadCellBigEndian((const uint8_t *)(addr)) +#define READ_SHORT_DIC(addr) Read16BigEndian((const uint8_t *)(addr)) #elif defined(PF_LITTLE_ENDIAN_DIC) #define WRITE_FLOAT_DIC WriteFloatLittleEndian -#define WRITE_LONG_DIC(addr,data) WriteLongLittleEndian((uint32 *)(addr),(uint32)(data)) -#define WRITE_SHORT_DIC(addr,data) WriteShortLittleEndian((uint16 *)(addr),(uint16)(data)) +#define WRITE_CELL_DIC(addr,data) WriteCellLittleEndian((uint8_t *)(addr),(ucell_t)(data)) +#define WRITE_SHORT_DIC(addr,data) Write16LittleEndian((uint8_t *)(addr),(uint16_t)(data)) #define READ_FLOAT_DIC ReadFloatLittleEndian -#define READ_LONG_DIC(addr) ReadLongLittleEndian((const uint32 *)(addr)) -#define READ_SHORT_DIC(addr) ReadShortLittleEndian((const uint16 *)(addr)) +#define READ_CELL_DIC(addr) ReadCellLittleEndian((const uint8_t *)(addr)) +#define READ_SHORT_DIC(addr) Read16LittleEndian((const uint8_t *)(addr)) #else #define WRITE_FLOAT_DIC(addr,data) { *((PF_FLOAT *)(addr)) = (PF_FLOAT)(data); } -#define WRITE_LONG_DIC(addr,data) { *((int32 *)(addr)) = (int32)(data); } -#define WRITE_SHORT_DIC(addr,data) { *((int16 *)(addr)) = (int16)(data); } +#define WRITE_CELL_DIC(addr,data) { *((cell_t *)(addr)) = (cell_t)(data); } +#define WRITE_SHORT_DIC(addr,data) { *((int16_t *)(addr)) = (int16_t)(data); } #define READ_FLOAT_DIC(addr) ( *((PF_FLOAT *)(addr)) ) -#define READ_LONG_DIC(addr) ( *((const uint32 *)(addr)) ) -#define READ_SHORT_DIC(addr) ( *((const uint16 *)(addr)) ) +#define READ_CELL_DIC(addr) ( *((const ucell_t *)(addr)) ) +#define READ_SHORT_DIC(addr) ( *((const uint16_t *)(addr)) ) #endif #define HEADER_HERE (gCurrentDictionary->dic_HeaderPtr.Cell) #define CODE_HERE (gCurrentDictionary->dic_CodePtr.Cell) -#define CODE_COMMA( N ) WRITE_LONG_DIC(CODE_HERE++,(N)) +#define CODE_COMMA( N ) WRITE_CELL_DIC(CODE_HERE++,(N)) #define NAME_BASE (gCurrentDictionary->dic_HeaderBase) #define CODE_BASE (gCurrentDictionary->dic_CodeBase) #define NAME_SIZE (gCurrentDictionary->dic_HeaderLimit - gCurrentDictionary->dic_HeaderBase) #define CODE_SIZE (gCurrentDictionary->dic_CodeLimit - gCurrentDictionary->dic_CodeBase) -#define IN_CODE_DIC(addr) ( ( ((uint8 *)(addr)) >= gCurrentDictionary->dic_CodeBase) && ( ((uint8 *)(addr)) < gCurrentDictionary->dic_CodeLimit) ) +#define IN_CODE_DIC(addr) ( ( ((uint8_t *)(addr)) >= gCurrentDictionary->dic_CodeBase) && ( ((uint8_t *)(addr)) < gCurrentDictionary->dic_CodeLimit) ) -#define IN_NAME_DIC(addr) ( ( ((uint8 *)(addr)) >= gCurrentDictionary->dic_HeaderBase) && ( ((uint8 *)(addr)) < gCurrentDictionary->dic_HeaderLimit) ) +#define IN_NAME_DIC(addr) ( ( ((uint8_t *)(addr)) >= gCurrentDictionary->dic_HeaderBase) && ( ((uint8_t *)(addr)) < gCurrentDictionary->dic_HeaderLimit) ) #define IN_DICS(addr) (IN_CODE_DIC(addr) || IN_NAME_DIC(addr)) /* Address conversion */ -#define ABS_TO_NAMEREL( a ) ((int32) (((uint8 *) a) - NAME_BASE )) -#define ABS_TO_CODEREL( a ) ((int32) (((uint8 *) a) - CODE_BASE )) -#define NAMEREL_TO_ABS( a ) ((char *) (((int32) a) + NAME_BASE)) -#define CODEREL_TO_ABS( a ) ((cell *) (((int32) a) + CODE_BASE)) +#define ABS_TO_NAMEREL( a ) ((cell_t) (((uint8_t *) a) - NAME_BASE )) +#define ABS_TO_CODEREL( a ) ((cell_t) (((uint8_t *) a) - CODE_BASE )) +#define NAMEREL_TO_ABS( a ) ((char *) (((cell_t) a) + NAME_BASE)) +#define CODEREL_TO_ABS( a ) ((cell_t *) (((cell_t) a) + CODE_BASE)) /* The check for >0 is only needed for CLONE testing. !!! */ #define IsTokenPrimitive(xt) ((xt=0)) @@ -566,7 +568,7 @@ extern int32 gIncludeIndex; #define DATA_STACK_DEPTH (gCurrentTask->td_StackBase - gCurrentTask->td_StackPtr) #define DROP_DATA_STACK (gCurrentTask->td_StackPtr++) #define POP_DATA_STACK (*gCurrentTask->td_StackPtr++) -#define PUSH_DATA_STACK(x) {*(--(gCurrentTask->td_StackPtr)) = (cell) x; } +#define PUSH_DATA_STACK(x) {*(--(gCurrentTask->td_StackPtr)) = (cell_t) x; } /* Force Quad alignment. */ #define QUADUP(x) (((x)+3)&~3) @@ -592,9 +594,9 @@ extern int32 gIncludeIndex; #define DBUG(x) /* PRT(x) */ #define DBUGX(x) /* DBUG(x) */ -#define MSG_NUM_D(msg,num) { MSG(msg); ffDot((int32) num); EMIT_CR; } -#define MSG_NUM_H(msg,num) { MSG(msg); ffDotHex((int32) num); EMIT_CR; } +#define MSG_NUM_D(msg,num) { MSG(msg); ffDot((cell_t) num); EMIT_CR; } +#define MSG_NUM_H(msg,num) { MSG(msg); ffDotHex((cell_t) num); EMIT_CR; } -#define DBUG_NUM_D(msg,num) { pfDebugMessage(msg); pfDebugPrintDecimalNumber((int32) num); pfDebugMessage("\n"); } +#define DBUG_NUM_D(msg,num) { pfDebugMessage(msg); pfDebugPrintDecimalNumber((cell_t) num); pfDebugMessage("\n"); } #endif /* _pf_guts_h */ diff --git a/csrc/pf_inner.c b/csrc/pf_inner.c index 15f764f..87c8613 100644 --- a/csrc/pf_inner.c +++ b/csrc/pf_inner.c @@ -41,7 +41,7 @@ #define STKPTR (DataStackPtr) #define M_POP (*(STKPTR++)) -#define M_PUSH(n) {*(--(STKPTR)) = (cell) (n);} +#define M_PUSH(n) {*(--(STKPTR)) = (cell_t) (n);} #define M_STACK(n) (STKPTR[n]) #define TOS (TopOfStack) @@ -74,13 +74,13 @@ #define M_R_DROP {TORPTR++;} #define M_R_POP (*(TORPTR++)) #define M_R_PICK(n) (TORPTR[n]) -#define M_R_PUSH(n) {*(--(TORPTR)) = (cell) (n);} +#define M_R_PUSH(n) {*(--(TORPTR)) = (cell_t) (n);} /*************************************************************** ** Misc Forth macros ***************************************************************/ -#define M_BRANCH { InsPtr = (cell *) (((uint8 *) InsPtr) + READ_LONG_DIC(InsPtr)); } +#define M_BRANCH { InsPtr = (cell_t *) (((uint8_t *) InsPtr) + READ_CELL_DIC(InsPtr)); } /* Cache top of data stack like in JForth. */ #ifdef PF_SUPPORT_FP @@ -124,7 +124,7 @@ ffDotS( ); \ LOAD_REGISTERS; -#define DO_VAR(varname) { PUSH_TOS; TOS = (cell) &varname; } +#define DO_VAR(varname) { PUSH_TOS; TOS = (cell_t) &varname; } #ifdef PF_SUPPORT_FP #define M_THROW(err) \ @@ -154,14 +154,14 @@ #define TRACENAMES /* no names */ #else /* Display name of executing routine. */ -static void TraceNames( ExecToken Token, int32 Level ) +static void TraceNames( ExecToken Token, cell_t Level ) { char *DebugName; - int32 i; + cell_t i; if( ffTokenToName( Token, &DebugName ) ) { - cell NumSpaces; + cell_t NumSpaces; if( gCurrentTask->td_OUT > 0 ) EMIT_CR; EMIT( '>' ); for( i=0; i> 31) & 1, (Scratch >> 24) & 0x7F ); LOAD_REGISTERS; endcase; - - case ID_CFETCH: TOS = *((uint8 *) TOS); endcase; + + /* Support 32/64 bit operation. */ + case ID_CELL: + M_PUSH( TOS ); + TOS = sizeof(cell_t); + endcase; + + case ID_CELLS: + TOS = TOS * sizeof(cell_t); + endcase; + + case ID_CFETCH: TOS = *((uint8_t *) TOS); endcase; case ID_CMOVE: /* ( src dst n -- ) */ { register char *DstPtr = (char *) M_POP; /* dst */ CharPtr = (char *) M_POP; /* src */ - for( Scratch=0; (uint32) Scratch < (uint32) TOS ; Scratch++ ) + for( Scratch=0; (ucell_t) Scratch < (ucell_t) TOS ; Scratch++ ) { *DstPtr++ = *CharPtr++; } @@ -529,7 +539,7 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); { register char *DstPtr = ((char *) M_POP) + TOS; /* dst */ CharPtr = ((char *) M_POP) + TOS;; /* src */ - for( Scratch=0; (uint32) Scratch < (uint32) TOS ; Scratch++ ) + for( Scratch=0; (ucell_t) Scratch < (ucell_t) TOS ; Scratch++ ) { *(--DstPtr) = *(--CharPtr); } @@ -552,7 +562,7 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); case ID_COMPARE: { const char *s1, *s2; - int32 len1; + cell_t len1; s2 = (const char *) M_POP; len1 = M_POP; s1 = (const char *) M_POP; @@ -574,10 +584,10 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); TOS = ( M_POP < TOS ) ? FTRUE : FFALSE ; endcase; case ID_COMP_U_GREATERTHAN: - TOS = ( ((uint32)M_POP) > ((uint32)TOS) ) ? FTRUE : FFALSE ; + TOS = ( ((ucell_t)M_POP) > ((ucell_t)TOS) ) ? FTRUE : FFALSE ; endcase; case ID_COMP_U_LESSTHAN: - TOS = ( ((uint32)M_POP) < ((uint32)TOS) ) ? FTRUE : FFALSE ; + TOS = ( ((ucell_t)M_POP) < ((ucell_t)TOS) ) ? FTRUE : FFALSE ; endcase; case ID_COMP_ZERO_EQUAL: TOS = ( TOS == 0 ) ? FTRUE : FFALSE ; @@ -607,18 +617,18 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); case ID_CREATE_P: PUSH_TOS; /* Put address of body on stack. Insptr points after code start. */ - TOS = (cell) ((char *)InsPtr - sizeof(cell) + CREATE_BODY_OFFSET ); + TOS = (cell_t) ((char *)InsPtr - sizeof(cell_t) + CREATE_BODY_OFFSET ); endcase; case ID_CSTORE: /* ( c caddr -- ) */ - *((uint8 *) TOS) = (uint8) M_POP; + *((uint8_t *) TOS) = (uint8_t) M_POP; M_DROP; endcase; /* Double precision add. */ case ID_D_PLUS: /* D+ ( al ah bl bh -- sl sh ) */ { - register ucell ah,al,bl,sh,sl; + register ucell_t ah,al,bl,sh,sl; #define bh TOS bl = M_POP; ah = M_POP; @@ -636,7 +646,7 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); /* Double precision subtract. */ case ID_D_MINUS: /* D- ( al ah bl bh -- sl sh ) */ { - register ucell ah,al,bl,sh,sl; + register ucell_t ah,al,bl,sh,sl; #define bh TOS bl = M_POP; ah = M_POP; @@ -653,10 +663,10 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); /* Perform 32*32 bit multiply for 64 bit result, by factoring into 16 bit quantities. */ /* Using an improved algorithm suggested by Steve Green. */ - case ID_D_UMTIMES: /* M* ( a b -- pl ph ) */ + case ID_D_UMTIMES: /* UM* ( a b -- pl ph ) */ { - ucell ahi, alo, bhi, blo, temp; - ucell pl, ph; + ucell_t ahi, alo, bhi, blo, temp; + ucell_t pl, ph; /* Get values from stack. */ ahi = M_POP; bhi = TOS; @@ -693,9 +703,9 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); /* Perform 32*32 bit multiply for 64 bit result, using shift and add. */ case ID_D_MTIMES: /* M* ( a b -- pl ph ) */ { - cell a,b; - ucell ap,bp, ahi, alo, bhi, blo, temp; - ucell pl, ph; + cell_t a,b; + ucell_t ap,bp, ahi, alo, bhi, blo, temp; + ucell_t pl, ph; /* Get values from stack. */ a = M_POP; b = TOS; @@ -749,7 +759,7 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); /* Perform 64/32 bit divide for 32 bit result, using shift and subtract. */ case ID_D_UMSMOD: /* UM/MOD ( al ah bdiv -- rem q ) */ { - ucell ah,al, q,di, bl,bh, sl,sh; + ucell_t ah,al, q,di, bl,bh, sl,sh; ah = M_POP; al = M_POP; bh = TOS; @@ -785,23 +795,24 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); /* Perform 64/32 bit divide for 64 bit result, using shift and subtract. */ case ID_D_MUSMOD: /* MU/MOD ( al am bdiv -- rem ql qh ) */ { - register ucell ah,am,al,ql,qh,di; -#define bdiv ((ucell)TOS) + register ucell_t ah,am,al,ql,qh,di; +#define bdiv ((ucell_t)TOS) ah = 0; am = M_POP; al = M_POP; qh = ql = 0; - for( di=0; di<64; di++ ) +#define NBITS (sizeof(cell_t)*8) + for( di=0; di<2*NBITS; di++ ) { if( bdiv <= ah ) { ah = ah - bdiv; ql |= 1; } - qh = (qh << 1) | (ql >> 31); + qh = (qh << 1) | (ql >> (NBITS-1)); ql = ql << 1; - ah = (ah << 1) | (am >> 31); - am = (am << 1) | (al >> 31); + ah = (ah << 1) | (am >> (NBITS-1)); + am = (am << 1) | (al >> (NBITS-1)); al = al << 1; DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); } @@ -860,7 +871,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_EOL: /* ( -- end_of_line_char ) */ PUSH_TOS; - TOS = (cell) '\n'; + TOS = (cell_t) '\n'; endcase; case ID_ERRORQ_P: /* ( flag num -- , quit if flag true ) */ @@ -890,12 +901,12 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); #endif if( IsTokenPrimitive( TOS ) ) { - WRITE_LONG_DIC( (cell *) &FakeSecondary[0], TOS); /* Build a fake secondary and execute it. */ + WRITE_CELL_DIC( (cell_t *) &FakeSecondary[0], TOS); /* Build a fake secondary and execute it. */ InsPtr = &FakeSecondary[0]; } else { - InsPtr = (cell *) LOCAL_CODEREL_TO_ABS(TOS); + InsPtr = (cell_t *) LOCAL_CODEREL_TO_ABS(TOS); } M_DROP; endcase; @@ -904,14 +915,14 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); #if (defined(PF_BIG_ENDIAN_DIC) || defined(PF_LITTLE_ENDIAN_DIC)) if( IN_DICS( TOS ) ) { - TOS = (cell) READ_LONG_DIC((cell *)TOS); + TOS = (cell_t) READ_CELL_DIC((cell_t *)TOS); } else { - TOS = *((cell *)TOS); + TOS = *((cell_t *)TOS); } #else - TOS = *((cell *)TOS); + TOS = *((cell_t *)TOS); #endif endcase; @@ -922,12 +933,12 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); if( Scratch < TIB_SIZE-2 ) { const char *famText = pfSelectFileModeCreate( TOS ); - pfCopyMemory( gScratch, (char *) Temp, (uint32) Scratch ); + pfCopyMemory( gScratch, (char *) Temp, (ucell_t) Scratch ); gScratch[Scratch] = '\0'; DBUG(("Create file = %s with famTxt %s\n", gScratch, famText )); FileID = sdOpenFile( gScratch, famText ); TOS = ( FileID == NULL ) ? -1 : 0 ; - M_PUSH( (cell) FileID ); + M_PUSH( (cell_t) FileID ); } else { @@ -944,13 +955,13 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); if( Scratch < TIB_SIZE-2 ) { const char *famText = pfSelectFileModeOpen( TOS ); - pfCopyMemory( gScratch, (char *) Temp, (uint32) Scratch ); + pfCopyMemory( gScratch, (char *) Temp, (ucell_t) Scratch ); gScratch[Scratch] = '\0'; DBUG(("Open file = %s\n", gScratch )); FileID = sdOpenFile( gScratch, famText ); TOS = ( FileID == NULL ) ? -1 : 0 ; - M_PUSH( (cell) FileID ); + M_PUSH( (cell_t) FileID ); } else { @@ -1026,7 +1037,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); register char *DstPtr; Temp = M_POP; /* num */ DstPtr = (char *) M_POP; /* dst */ - for( Scratch=0; (uint32) Scratch < (uint32) Temp ; Scratch++ ) + for( Scratch=0; (ucell_t) Scratch < (ucell_t) Temp ; Scratch++ ) { *DstPtr++ = (char) TOS; } @@ -1042,7 +1053,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_FINDNFA: TOS = ffFindNFA( (const ForthString *) TOS, (const ForthString **) &Temp ); - M_PUSH( (cell) Temp ); + M_PUSH( (cell_t) Temp ); endcase; #endif /* !PF_NO_SHELL */ @@ -1059,9 +1070,9 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); } else { - CellPtr = (cell *) TOS; + CellPtr = (cell_t *) TOS; CellPtr--; - if( ((uint32)*CellPtr) != ((uint32)CellPtr ^ PF_MEMORY_VALIDATOR)) + if( ((ucell_t)*CellPtr) != ((ucell_t)CellPtr ^ PF_MEMORY_VALIDATOR)) { TOS = -2; /* FIXME error code */ } @@ -1078,14 +1089,14 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_HERE: PUSH_TOS; - TOS = (cell)CODE_HERE; + TOS = (cell_t)CODE_HERE; endcase; case ID_NUMBERQ_P: /* ( addr -- 0 | n 1 ) */ /* Convert using number converter in 'C'. ** Only supports single precision for bootstrap. */ - TOS = (cell) ffNumberQ( (char *) TOS, &Temp ); + TOS = (cell_t) ffNumberQ( (char *) TOS, &Temp ); if( TOS == NUM_TYPE_SINGLE) { M_PUSH( Temp ); /* Push single number */ @@ -1137,7 +1148,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_LITERAL_P: DBUG(("ID_LITERAL_P: InsPtr = 0x%x, *InsPtr = 0x%x\n", InsPtr, *InsPtr )); PUSH_TOS; - TOS = READ_LONG_DIC(InsPtr++); + TOS = READ_CELL_DIC(InsPtr++); endcase; #ifndef PF_NO_SHELL @@ -1191,8 +1202,8 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_LOCAL_ENTRY: /* ( x0 x1 ... xn n -- ) */ /* create local stack frame */ { - int32 i = TOS; - cell *lp; + cell_t i = TOS; + cell_t *lp; DBUG(("LocalEntry: n = %d\n", TOS)); /* End of locals. Create stack frame */ DBUG(("LocalEntry: before RP@ = 0x%x, LP = 0x%x\n", @@ -1215,7 +1226,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); DBUG(("LocalExit: before RP@ = 0x%x, LP = 0x%x\n", TORPTR, LocalsPtr)); TORPTR = LocalsPtr; - LocalsPtr = (cell *) M_R_POP; + LocalsPtr = (cell_t *) M_R_POP; DBUG(("LocalExit: after RP@ = 0x%x, LP = 0x%x\n", TORPTR, LocalsPtr)); endcase; @@ -1278,11 +1289,11 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); #ifndef PF_NO_SHELL case ID_NAME_TO_TOKEN: - TOS = (cell) NameToToken((ForthString *)TOS); + TOS = (cell_t) NameToToken((ForthString *)TOS); endcase; case ID_NAME_TO_PREVIOUS: - TOS = (cell) NameToPrevious((ForthString *)TOS); + TOS = (cell_t) NameToPrevious((ForthString *)TOS); endcase; #endif @@ -1306,23 +1317,23 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); #if (defined(PF_BIG_ENDIAN_DIC) || defined(PF_LITTLE_ENDIAN_DIC)) if( IN_DICS( TOS ) ) { - Scratch = READ_LONG_DIC((cell *)TOS); + Scratch = READ_CELL_DIC((cell_t *)TOS); Scratch += M_POP; - WRITE_LONG_DIC((cell *)TOS,Scratch); + WRITE_CELL_DIC((cell_t *)TOS,Scratch); } else { - *((cell *)TOS) += M_POP; + *((cell_t *)TOS) += M_POP; } #else - *((cell *)TOS) += M_POP; + *((cell_t *)TOS) += M_POP; #endif M_DROP; endcase; case ID_PLUSLOOP_P: /* ( delta -- ) ( R: index limit -- | index limit ) */ { - ucell OldIndex, NewIndex, Limit; + ucell_t OldIndex, NewIndex, Limit; Limit = M_R_POP; OldIndex = M_R_POP; @@ -1397,10 +1408,10 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); /* Resize memory allocated by ALLOCATE. */ case ID_RESIZE: /* ( addr1 u -- addr2 result ) */ { - cell *Addr1 = (cell *) M_POP; + cell_t *Addr1 = (cell_t *) M_POP; // Point to validator below users address. - cell *FreePtr = Addr1 - 1; - if( ((uint32)*FreePtr) != ((uint32)FreePtr ^ PF_MEMORY_VALIDATOR)) + cell_t *FreePtr = Addr1 - 1; + if( ((ucell_t)*FreePtr) != ((ucell_t)FreePtr ^ PF_MEMORY_VALIDATOR)) { // 090218 - Fixed bug, was returning zero. M_PUSH( Addr1 ); @@ -1409,15 +1420,15 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); else { /* Try to allocate. */ - CellPtr = (cell *) pfAllocMem( TOS + sizeof(cell) ); + CellPtr = (cell_t *) pfAllocMem( TOS + sizeof(cell_t) ); if( CellPtr ) { /* Copy memory including validation. */ - pfCopyMemory( (char *) CellPtr, (char *) FreePtr, TOS + sizeof(cell) ); - *CellPtr = (cell)(((uint32)CellPtr) ^ (uint32)PF_MEMORY_VALIDATOR); + pfCopyMemory( (char *) CellPtr, (char *) FreePtr, TOS + sizeof(cell_t) ); + *CellPtr = (cell_t)(((ucell_t)CellPtr) ^ (ucell_t)PF_MEMORY_VALIDATOR); // 090218 - Fixed bug that was incrementing the address twice. Thanks Reinhold Straub. // Increment past validator to user address. - M_PUSH( (cell) (CellPtr + 1) ); + M_PUSH( (cell_t) (CellPtr + 1) ); TOS = 0; // Result code. // Mark old cell as dead so we can't free it twice. FreePtr[0] = 0xDeadBeef; @@ -1439,18 +1450,18 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); */ case ID_RP_FETCH: /* ( -- rp , address of top of return stack ) */ PUSH_TOS; - TOS = (cell)TORPTR; /* value before calling RP@ */ + TOS = (cell_t)TORPTR; /* value before calling RP@ */ endcase; case ID_RP_STORE: /* ( rp -- , address of top of return stack ) */ - TORPTR = (cell *) TOS; + TORPTR = (cell_t *) TOS; M_DROP; endcase; case ID_ROLL: /* ( xu xu-1 xu-1 ... x0 u -- xu-1 xu-1 ... x0 xu ) */ { - int32 ri; - cell *srcPtr, *dstPtr; + cell_t ri; + cell_t *srcPtr, *dstPtr; Scratch = M_STACK(TOS); srcPtr = &M_STACK(TOS-1); dstPtr = &M_STACK(TOS); @@ -1472,12 +1483,12 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); endcase; /* Logical right shift */ - case ID_RSHIFT: { TOS = ((uint32)M_POP) >> TOS; } endcase; + case ID_RSHIFT: { TOS = ((ucell_t)M_POP) >> TOS; } endcase; #ifndef PF_NO_SHELL case ID_SAVE_FORTH_P: /* ( $name Entry NameSize CodeSize -- err ) */ { - int32 NameSize, CodeSize, EntryPoint; + cell_t NameSize, CodeSize, EntryPoint; CodeSize = TOS; NameSize = M_POP; EntryPoint = M_POP; @@ -1499,11 +1510,11 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_SP_FETCH: /* ( -- sp , address of top of stack, sorta ) */ PUSH_TOS; - TOS = (cell)STKPTR; + TOS = (cell_t)STKPTR; endcase; case ID_SP_STORE: /* ( sp -- , address of top of stack, sorta ) */ - STKPTR = (cell *) TOS; + STKPTR = (cell_t *) TOS; M_DROP; endcase; @@ -1511,14 +1522,14 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); #if (defined(PF_BIG_ENDIAN_DIC) || defined(PF_LITTLE_ENDIAN_DIC)) if( IN_DICS( TOS ) ) { - WRITE_LONG_DIC((cell *)TOS,M_POP); + WRITE_CELL_DIC(TOS,M_POP); } else { - *((cell *)TOS) = M_POP; + *((cell_t *)TOS) = M_POP; } #else - *((cell *)TOS) = M_POP; + *((cell_t *)TOS) = M_POP; #endif M_DROP; endcase; @@ -1527,7 +1538,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); Scratch = M_POP; /* cnt */ Temp = M_POP; /* addr */ TOS = ffScan( (char *) Temp, Scratch, (char) TOS, &CharPtr ); - M_PUSH((cell) CharPtr); + M_PUSH((cell_t) CharPtr); endcase; #ifndef PF_NO_SHELL @@ -1543,13 +1554,13 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); Scratch = M_POP; /* cnt */ Temp = M_POP; /* addr */ TOS = ffSkip( (char *) Temp, Scratch, (char) TOS, &CharPtr ); - M_PUSH((cell) CharPtr); + M_PUSH((cell_t) CharPtr); endcase; case ID_SOURCE: /* ( -- c-addr num ) */ PUSH_TOS; - M_PUSH( (cell) gCurrentTask->td_SourcePtr ); - TOS = (cell) gCurrentTask->td_SourceNum; + M_PUSH( (cell_t) gCurrentTask->td_SourcePtr ); + TOS = (cell_t) gCurrentTask->td_SourceNum; endcase; case ID_SOURCE_SET: /* ( c-addr num -- ) */ @@ -1569,7 +1580,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); endcase; case ID_SOURCE_ID_PUSH: /* ( source-id -- ) */ - TOS = (cell)ffConvertSourceIDToStream( TOS ); + TOS = (cell_t)ffConvertSourceIDToStream( TOS ); Scratch = ffPushInputStream((FileStream *) TOS ); if( Scratch ) { @@ -1652,21 +1663,21 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_VAR_RETURN_CODE: DO_VAR(gVarReturnCode); endcase; case ID_WORD: - TOS = (cell) ffWord( (char) TOS ); + TOS = (cell_t) ffWord( (char) TOS ); endcase; case ID_WORD_FETCH: /* ( waddr -- w ) */ #if (defined(PF_BIG_ENDIAN_DIC) || defined(PF_LITTLE_ENDIAN_DIC)) if( IN_DICS( TOS ) ) { - TOS = (uint16) READ_SHORT_DIC((uint16 *)TOS); + TOS = (uint16_t) READ_SHORT_DIC((uint8_t *)TOS); } else { - TOS = *((uint16 *)TOS); + TOS = *((uint16_t *)TOS); } #else - TOS = *((uint16 *)TOS); + TOS = *((uint16_t *)TOS); #endif endcase; @@ -1675,14 +1686,14 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); #if (defined(PF_BIG_ENDIAN_DIC) || defined(PF_LITTLE_ENDIAN_DIC)) if( IN_DICS( TOS ) ) { - WRITE_SHORT_DIC((uint16 *)TOS,(uint16)M_POP); + WRITE_SHORT_DIC(TOS,M_POP); } else { - *((uint16 *)TOS) = (uint16) M_POP; + *((uint16_t *)TOS) = (uint16_t) M_POP; } #else - *((uint16 *)TOS) = (uint16) M_POP; + *((uint16_t *)TOS) = (uint16_t) M_POP; #endif M_DROP; endcase; @@ -1709,13 +1720,13 @@ DBUGX(("After 0Branch: IP = 0x%x\n", InsPtr )); ERR("pfCatch: Unrecognised token = 0x"); ffDotHex(Token); ERR(" at 0x"); - ffDotHex((int32) InsPtr); + ffDotHex((cell_t) InsPtr); EMIT_CR; InsPtr = 0; endcase; } - if(InsPtr) Token = READ_LONG_DIC(InsPtr++); /* Traverse to next token in secondary. */ + if(InsPtr) Token = READ_CELL_DIC(InsPtr++); /* Traverse to next token in secondary. */ #ifdef PF_DEBUG M_DOTS; diff --git a/csrc/pf_io.c b/csrc/pf_io.c index 2cd3d3d..5638874 100644 --- a/csrc/pf_io.c +++ b/csrc/pf_io.c @@ -39,7 +39,7 @@ void ioTerm( void ) */ void ioEmit( char c ) { - int32 Result; + cell_t Result; Result = sdTerminalOut(c); if( Result < 0 ) EXIT(1); @@ -61,9 +61,9 @@ void ioEmit( char c ) /*************************************************************** ** Send an entire string.. */ -void ioType( const char *s, int32 n ) +void ioType( const char *s, cell_t n ) { - int32 i; + cell_t i; for( i=0; idlln_Next->dlln_Previous != NodePtr) || (NodePtr->dlln_Previous->dlln_Next != NodePtr)) @@ -141,7 +141,7 @@ static DoublyLinkedList gMemList; typedef struct MemListNode { DoublyLinkedListNode mln_Node; - int32 mln_Size; + cell_t mln_Size; } MemListNode; #ifdef PF_DEBUG @@ -168,7 +168,7 @@ void maDumpList( void ) /*************************************************************** ** Free mem of any size. */ -static void pfFreeRawMem( char *Mem, int32 NumBytes ) +static void pfFreeRawMem( char *Mem, cell_t NumBytes ) { MemListNode *mln, *FreeNode; MemListNode *AdjacentLower = NULL; @@ -181,9 +181,9 @@ static void pfFreeRawMem( char *Mem, int32 NumBytes ) DBUG(("\npfFreeRawMem: Align NumBytes to 0x%x\n", NumBytes )); /* Check memory alignment. */ - if( ( ((int32)Mem) & (PF_MEM_BLOCK_SIZE - 1)) != 0) + if( ( ((cell_t)Mem) & (PF_MEM_BLOCK_SIZE - 1)) != 0) { - MSG_NUM_H("pfFreeRawMem: misaligned Mem = 0x", (int32) Mem ); + MSG_NUM_H("pfFreeRawMem: misaligned Mem = 0x", (cell_t) Mem ); return; } @@ -245,10 +245,10 @@ DBUG((" Link before 0x%x\n", NextBiggest )); /*************************************************************** ** Setup memory list. Initialize allocator. */ -static void pfInitMemBlock( void *addr, uint32 poolSize ) +static void pfInitMemBlock( void *addr, ucell_t poolSize ) { char *AlignedMemory; - int32 AlignedSize; + cell_t AlignedSize; pfDebugMessage("pfInitMemBlock()\n"); /* Set globals. */ @@ -258,7 +258,7 @@ static void pfInitMemBlock( void *addr, uint32 poolSize ) dllSetupList( &gMemList ); /* Adjust to next highest aligned memory location. */ - AlignedMemory = (char *) ((((int32)gMemPoolPtr) + PF_MEM_BLOCK_SIZE - 1) & + AlignedMemory = (char *) ((((cell_t)gMemPoolPtr) + PF_MEM_BLOCK_SIZE - 1) & ~(PF_MEM_BLOCK_SIZE - 1)); /* Adjust size to reflect aligned memory. */ @@ -275,7 +275,7 @@ static void pfInitMemBlock( void *addr, uint32 poolSize ) /*************************************************************** ** Allocate mem from list of free nodes. */ -static char *pfAllocRawMem( int32 NumBytes ) +static char *pfAllocRawMem( cell_t NumBytes ) { char *Mem = NULL; MemListNode *mln; @@ -295,7 +295,7 @@ static char *pfAllocRawMem( int32 NumBytes ) { if( mln->mln_Size >= NumBytes ) { - int32 RemSize; + cell_t RemSize; Mem = (char *) mln; @@ -320,16 +320,16 @@ static char *pfAllocRawMem( int32 NumBytes ) /*************************************************************** ** Keep mem size at first cell. */ -char *pfAllocMem( int32 NumBytes ) +char *pfAllocMem( cell_t NumBytes ) { - int32 *IntMem; + cell_t *IntMem; if( NumBytes <= 0 ) return NULL; /* Allocate an extra cell for size. */ - NumBytes += sizeof(int32); + NumBytes += sizeof(cell_t); - IntMem = (int32 *)pfAllocRawMem( NumBytes ); + IntMem = (cell_t *)pfAllocRawMem( NumBytes ); if( IntMem != NULL ) *IntMem++ = NumBytes; @@ -341,13 +341,13 @@ char *pfAllocMem( int32 NumBytes ) */ void pfFreeMem( void *Mem ) { - int32 *IntMem; - int32 NumBytes; + cell_t *IntMem; + cell_t NumBytes; if( Mem == NULL ) return; /* Allocate an extra cell for size. */ - IntMem = (int32 *) Mem; + IntMem = (cell_t *) Mem; IntMem--; NumBytes = *IntMem; diff --git a/csrc/pf_mem.h b/csrc/pf_mem.h index 9fdadc2..9f8beda 100644 --- a/csrc/pf_mem.h +++ b/csrc/pf_mem.h @@ -22,7 +22,7 @@ #endif void pfInitMemoryAllocator( void ); - char *pfAllocMem( int32 NumBytes ); + char *pfAllocMem( cell_t NumBytes ); void pfFreeMem( void *Mem ); #ifdef __cplusplus diff --git a/csrc/pf_save.c b/csrc/pf_save.c index 410a2ae..6a9d195 100644 --- a/csrc/pf_save.c +++ b/csrc/pf_save.c @@ -24,9 +24,11 @@ ** of names and code was the same when saved and reloaded. ** 940228 PLB Added PF_NO_FILEIO version ** 961204 PLB Added PF_STATIC_DIC -** 000623 PLB Cast chars as uint32 before shifting for 16 bit systems. +** 000623 PLB Cast chars as ucell_t before shifting for 16 bit systems. ***************************************************************/ +#include + #include "pf_all.h" /* If no File I/O, then force static dictionary. */ @@ -65,41 +67,72 @@ Chunks /***************************************************************/ /* Endian-ness tools. */ -uint32 ReadLongBigEndian( const uint32 *addr ) +ucell_t ReadCellBigEndian( const uint8_t *addr ) { - const unsigned char *bp = (const unsigned char *) addr; -/* We must cast char to uint32 before shifting because -** of systems with 16 bit ints. 000623 */ - uint32 temp = ((uint32)bp[0])<<24; - temp |= ((uint32)bp[1])<<16; - temp |= ((uint32)bp[2])<<8; - temp |= ((uint32)bp[3]); + ucell_t temp = (ucell_t)addr[0]; + temp = (temp << 8) | ((ucell_t)addr[1]); + temp = (temp << 8) | ((ucell_t)addr[2]); + temp = (temp << 8) | ((ucell_t)addr[3]); + if( sizeof(ucell_t) == 8 ) + { + temp = (temp << 8) | ((ucell_t)addr[4]); + temp = (temp << 8) | ((ucell_t)addr[5]); + temp = (temp << 8) | ((ucell_t)addr[6]); + temp = (temp << 8) | ((ucell_t)addr[7]); + } + return temp; } /***************************************************************/ -uint16 ReadShortBigEndian( const uint16 *addr ) +/* Endian-ness tools. */ +uint32_t Read32BigEndian( const uint8_t *addr ) { - const unsigned char *bp = (const unsigned char *) addr; - return (uint16) ((bp[0]<<8) | bp[1]); + uint32_t temp = (uint32_t)addr[0]; + temp = (temp << 8) | ((uint32_t)addr[1]); + temp = (temp << 8) | ((uint32_t)addr[2]); + temp = (temp << 8) | ((uint32_t)addr[3]); + return temp; } /***************************************************************/ -uint32 ReadLongLittleEndian( const uint32 *addr ) +uint16_t Read16BigEndian( const uint8_t *addr ) { - const unsigned char *bp = (const unsigned char *) addr; -/* We must cast char to uint32 before shifting because -** of systems with 16 bit ints. 000623 */ - uint32 temp = ((uint32)bp[3])<<24; - temp |= ((uint32)bp[2])<<16; - temp |= ((uint32)bp[1])<<8; - temp |= ((uint32)bp[0]); + return (uint16_t) ((addr[0]<<8) | addr[1]); +} + +/***************************************************************/ +ucell_t ReadCellLittleEndian( const uint8_t *addr ) +{ + ucell_t temp = 0; + if( sizeof(ucell_t) == 8 ) + { + temp = (temp << 8) | ((uint32_t)addr[7]); + temp = (temp << 8) | ((uint32_t)addr[6]); + temp = (temp << 8) | ((uint32_t)addr[5]); + temp = (temp << 8) | ((uint32_t)addr[4]); + } + temp = (temp << 8) | ((uint32_t)addr[3]); + temp = (temp << 8) | ((uint32_t)addr[2]); + temp = (temp << 8) | ((uint32_t)addr[1]); + temp = (temp << 8) | ((uint32_t)addr[0]); return temp; } + /***************************************************************/ -uint16 ReadShortLittleEndian( const uint16 *addr ) +uint32_t Read32LittleEndian( const uint8_t *addr ) +{ + uint32_t temp = (uint32_t)addr[3]; + temp = (temp << 8) | ((uint32_t)addr[2]); + temp = (temp << 8) | ((uint32_t)addr[1]); + temp = (temp << 8) | ((uint32_t)addr[0]); + return temp; +} + +/***************************************************************/ +uint16_t Read16LittleEndian( const uint8_t *addr ) { const unsigned char *bp = (const unsigned char *) addr; - return (uint16) ((bp[1]<<8) | bp[0]); + return (uint16_t) ((bp[1]<<8) | bp[0]); } #ifdef PF_SUPPORT_FP @@ -178,42 +211,81 @@ PF_FLOAT ReadFloatLittleEndian( const PF_FLOAT *addr ) #endif /* PF_SUPPORT_FP */ /***************************************************************/ -void WriteLongBigEndian( uint32 *addr, uint32 data ) +void WriteCellBigEndian( uint8_t *addr, ucell_t data ) { - unsigned char *bp = (unsigned char *) addr; - - bp[0] = (unsigned char) (data>>24); - bp[1] = (unsigned char) (data>>16); - bp[2] = (unsigned char) (data>>8); - bp[3] = (unsigned char) (data); + // Write should be in order of increasing address + // to optimize for burst writes to DRAM. + if( sizeof(ucell_t) == 8 ) + { + *addr++ = (uint8_t) (data>>56); + *addr++ = (uint8_t) (data>>48); + *addr++ = (uint8_t) (data>>40); + *addr++ = (uint8_t) (data>>32); + } + *addr++ = (uint8_t) (data>>24); + *addr++ = (uint8_t) (data>>16); + *addr++ = (uint8_t) (data>>8); + *addr = (uint8_t) (data); } /***************************************************************/ -void WriteShortBigEndian( uint16 *addr, uint16 data ) +void Write32BigEndian( uint8_t *addr, uint32_t data ) { - unsigned char *bp = (unsigned char *) addr; - - bp[0] = (unsigned char) (data>>8); - bp[1] = (unsigned char) (data); + *addr++ = (uint8_t) (data>>24); + *addr++ = (uint8_t) (data>>16); + *addr++ = (uint8_t) (data>>8); + *addr = (uint8_t) (data); } /***************************************************************/ -void WriteLongLittleEndian( uint32 *addr, uint32 data ) +void Write16BigEndian( uint8_t *addr, uint16_t data ) { - unsigned char *bp = (unsigned char *) addr; + *addr++ = (uint8_t) (data>>8); + *addr = (uint8_t) (data); +} - bp[0] = (unsigned char) (data); - bp[1] = (unsigned char) (data>>8); - bp[2] = (unsigned char) (data>>16); - bp[3] = (unsigned char) (data>>24); +/***************************************************************/ +void WriteCellLittleEndian( uint8_t *addr, ucell_t data ) +{ + // Write should be in order of increasing address + // to optimize for burst writes to DRAM. + if( sizeof(ucell_t) == 8 ) + { + *addr++ = (uint8_t) data; // LSB at near end + data = data >> 8; + *addr++ = (uint8_t) data; + data = data >> 8; + *addr++ = (uint8_t) data; + data = data >> 8; + *addr++ = (uint8_t) data; + data = data >> 8; + } + *addr++ = (uint8_t) data; + data = data >> 8; + *addr++ = (uint8_t) data; + data = data >> 8; + *addr++ = (uint8_t) data; + data = data >> 8; + *addr = (uint8_t) data; } /***************************************************************/ -void WriteShortLittleEndian( uint16 *addr, uint16 data ) +void Write32LittleEndian( uint8_t *addr, uint32_t data ) { - unsigned char *bp = (unsigned char *) addr; + *addr++ = (uint8_t) data; + data = data >> 8; + *addr++ = (uint8_t) data; + data = data >> 8; + *addr++ = (uint8_t) data; + data = data >> 8; + *addr = (uint8_t) data; +} - bp[0] = (unsigned char) (data); - bp[1] = (unsigned char) (data>>8); +/***************************************************************/ +void Write16LittleEndian( uint8_t *addr, uint16_t data ) +{ + *addr++ = (uint8_t) data; + data = data >> 8; + *addr = (uint8_t) data; } /***************************************************************/ @@ -227,7 +299,7 @@ int IsHostLittleEndian( void ) #if defined(PF_NO_FILEIO) || defined(PF_NO_SHELL) -int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, int32 CodeSize) +cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, cell_t CodeSize) { TOUCH(FileName); TOUCH(EntryPoint); @@ -241,33 +313,33 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i #else /* PF_NO_FILEIO or PF_NO_SHELL */ /***************************************************************/ -static int32 WriteLong( FileStream *fid, int32 Val ) +static int Write32ToFile( FileStream *fid, uint32_t Val ) { - int32 numw; - uint32 pad; + int numw; + uint8_t pad[4]; - WriteLongBigEndian(&pad,Val); - numw = sdWriteFile( (char *) &pad, 1, sizeof(int32), fid ); - if( numw != sizeof(int32) ) return -1; + Write32BigEndian(pad,Val); + numw = sdWriteFile( pad, 1, sizeof(pad), fid ); + if( numw != sizeof(pad) ) return -1; return 0; } /***************************************************************/ -static int32 WriteChunk( FileStream *fid, int32 ID, char *Data, int32 NumBytes ) +static cell_t WriteChunkToFile( FileStream *fid, cell_t ID, char *Data, int32_t NumBytes ) { - int32 numw; - int32 EvenNumW; + cell_t numw; + cell_t EvenNumW; EvenNumW = EVENUP(NumBytes); - if( WriteLong( fid, ID ) < 0 ) goto error; - if( WriteLong( fid, EvenNumW ) < 0 ) goto error; + if( Write32ToFile( fid, ID ) < 0 ) goto error; + if( Write32ToFile( fid, EvenNumW ) < 0 ) goto error; numw = sdWriteFile( Data, 1, EvenNumW, fid ); if( numw != EvenNumW ) goto error; return 0; error: - pfReportError("WriteChunk", PF_ERR_WRITE_FILE); + pfReportError("WriteChunkToFile", PF_ERR_WRITE_FILE); return -1; } @@ -276,15 +348,14 @@ error: ** If EntryPoint is NULL, save as development environment. ** If EntryPoint is non-NULL, save as turnKey environment with no names. */ -int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, int32 CodeSize) +cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, cell_t CodeSize) { FileStream *fid; DictionaryInfoChunk SD; - int32 FormSize; - int32 NameChunkSize = 0; - int32 CodeChunkSize; - uint32 rhp, rcp; - uint32 *p; + uint32_t FormSize; + uint32_t NameChunkSize = 0; + uint32_t CodeChunkSize; + uint32_t relativeCodePtr; int i; fid = sdOpenFile( FileName, "wb" ); @@ -298,17 +369,17 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i pfExecIfDefined("AUTO.TERM"); /* Write FORM Header ---------------------------- */ - if( WriteLong( fid, ID_FORM ) < 0 ) goto error; - if( WriteLong( fid, 0 ) < 0 ) goto error; - if( WriteLong( fid, ID_P4TH ) < 0 ) goto error; + if( Write32ToFile( fid, ID_FORM ) < 0 ) goto error; + if( Write32ToFile( fid, 0 ) < 0 ) goto error; + if( Write32ToFile( fid, ID_P4TH ) < 0 ) goto error; /* Write P4DI Dictionary Info ------------------ */ SD.sd_Version = PF_FILE_VERSION; - rcp = ABS_TO_CODEREL(gCurrentDictionary->dic_CodePtr.Byte); /* 940225 */ - SD.sd_RelCodePtr = rcp; - SD.sd_UserStackSize = sizeof(cell) * (gCurrentTask->td_StackBase - gCurrentTask->td_StackLimit); - SD.sd_ReturnStackSize = sizeof(cell) * (gCurrentTask->td_ReturnBase - gCurrentTask->td_ReturnLimit); + relativeCodePtr = ABS_TO_CODEREL(gCurrentDictionary->dic_CodePtr.Byte); /* 940225 */ + SD.sd_RelCodePtr = relativeCodePtr; + SD.sd_UserStackSize = sizeof(cell_t) * (gCurrentTask->td_StackBase - gCurrentTask->td_StackLimit); + SD.sd_ReturnStackSize = sizeof(cell_t) * (gCurrentTask->td_ReturnBase - gCurrentTask->td_ReturnLimit); SD.sd_NumPrimitives = gNumPrimitives; /* Must match compiled dictionary. */ #ifdef PF_SUPPORT_FP @@ -317,9 +388,9 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i SD.sd_FloatSize = 0; #endif - SD.sd_Reserved = 0; + SD.sd_CellSize = sizeof(cell_t); -/* Set bit that specifiec whether dictionary is BIG or LITTLE Endian. */ +/* Set bit that specifies whether dictionary is BIG or LITTLE Endian. */ { #if defined(PF_BIG_ENDIAN_DIC) int eflag = SD_F_BIG_ENDIAN_DIC; @@ -349,13 +420,14 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i } else { + uint32_t relativeHeaderPtr; /* Development mode. */ SD.sd_RelContext = ABS_TO_NAMEREL(gVarContext); - rhp = ABS_TO_NAMEREL(gCurrentDictionary->dic_HeaderPtr.Byte); - SD.sd_RelHeaderPtr = rhp; + relativeHeaderPtr = ABS_TO_NAMEREL(gCurrentDictionary->dic_HeaderPtr.Byte); + SD.sd_RelHeaderPtr = relativeHeaderPtr; /* How much real name space is there? */ - NameChunkSize = QUADUP(rhp); /* Align */ + NameChunkSize = QUADUP(relativeHeaderPtr); /* Align */ /* NameSize must be 0 or greater than NameChunkSize + 1K */ NameSize = QUADUP(NameSize); /* Align */ @@ -367,53 +439,52 @@ int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, i } /* How much real code is there? */ - CodeChunkSize = QUADUP(rcp); + CodeChunkSize = QUADUP(relativeCodePtr); CodeSize = QUADUP(CodeSize); /* Align */ CodeSize = MAX( CodeSize, (CodeChunkSize + 2048) ); SD.sd_CodeSize = CodeSize; -/* Convert all fields in structure from Native to BigEndian. */ - p = (uint32 *) &SD; - for( i=0; i<((int)(sizeof(SD)/sizeof(int32))); i++ ) +/* Convert all fields in DictionaryInfoChunk from Native to BigEndian. + * This assumes they are all 32-bit integers. + */ { - WriteLongBigEndian( &p[i], p[i] ); + uint32_t *p = (uint32_t *) &SD; + for( i=0; i<((int)(sizeof(SD)/sizeof(uint32_t))); i++ ) + { + Write32BigEndian( (uint8_t *)&p[i], p[i] ); + } } - if( WriteChunk( fid, ID_P4DI, (char *) &SD, sizeof(DictionaryInfoChunk) ) < 0 ) goto error; + if( WriteChunkToFile( fid, ID_P4DI, (char *) &SD, sizeof(DictionaryInfoChunk) ) < 0 ) goto error; /* Write Name Fields if NameSize non-zero ------- */ if( NameSize > 0 ) { - if( WriteChunk( fid, ID_P4NM, (char *) NAME_BASE, + if( WriteChunkToFile( fid, ID_P4NM, (char *) NAME_BASE, NameChunkSize ) < 0 ) goto error; } /* Write Code Fields ---------------------------- */ - if( WriteChunk( fid, ID_P4CD, (char *) CODE_BASE, + if( WriteChunkToFile( fid, ID_P4CD, (char *) CODE_BASE, CodeChunkSize ) < 0 ) goto error; FormSize = sdTellFile( fid ) - 8; sdSeekFile( fid, 4, PF_SEEK_SET ); - if( WriteLong( fid, FormSize ) < 0 ) goto error; + if( Write32ToFile( fid, FormSize ) < 0 ) goto error; sdCloseFile( fid ); - - /* Restore initialization. */ - pfExecIfDefined("AUTO.INIT"); - return 0; error: sdSeekFile( fid, 0, PF_SEEK_SET ); - WriteLong( fid, ID_BADF ); /* Mark file as bad. */ + Write32ToFile( fid, ID_BADF ); /* Mark file as bad. */ sdCloseFile( fid ); /* Restore initialization. */ - pfExecIfDefined("AUTO.INIT"); return -1; @@ -425,14 +496,13 @@ error: #ifndef PF_NO_FILEIO /***************************************************************/ -static int32 ReadLong( FileStream *fid, int32 *ValPtr ) +static uint32_t Read32FromFile( FileStream *fid, uint32_t *ValPtr ) { - int32 numr; - uint32 temp; - - numr = sdReadFile( &temp, 1, sizeof(int32), fid ); - if( numr != sizeof(int32) ) return -1; - *ValPtr = ReadLongBigEndian( &temp ); + int32_t numr; + uint8_t pad[4]; + numr = sdReadFile( pad, 1, sizeof(pad), fid ); + if( numr != sizeof(pad) ) return -1; + *ValPtr = Read32BigEndian( pad ); return 0; } @@ -442,12 +512,11 @@ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPt pfDictionary_t *dic = NULL; FileStream *fid; DictionaryInfoChunk *sd; - int32 ChunkID; - int32 ChunkSize; - int32 FormSize; - int32 BytesLeft; - int32 numr; - uint32 *p; + uint32_t ChunkID; + uint32_t ChunkSize; + uint32_t FormSize; + uint32_t BytesLeft; + uint32_t numr; int i; int isDicBigEndian; @@ -462,17 +531,17 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); } /* Read FORM, Size, ID */ - if (ReadLong( fid, &ChunkID ) < 0) goto read_error; + if (Read32FromFile( fid, &ChunkID ) < 0) goto read_error; if( ChunkID != ID_FORM ) { pfReportError("pfLoadDictionary", PF_ERR_WRONG_FILE); goto error; } - if (ReadLong( fid, &FormSize ) < 0) goto read_error; + if (Read32FromFile( fid, &FormSize ) < 0) goto read_error; BytesLeft = FormSize; - if (ReadLong( fid, &ChunkID ) < 0) goto read_error; + if (Read32FromFile( fid, &ChunkID ) < 0) goto read_error; BytesLeft -= 4; if( ChunkID != ID_P4TH ) { @@ -483,11 +552,11 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); /* Scan and parse all chunks in file. */ while( BytesLeft > 0 ) { - if (ReadLong( fid, &ChunkID ) < 0) goto read_error; - if (ReadLong( fid, &ChunkSize ) < 0) goto read_error; + if (Read32FromFile( fid, &ChunkID ) < 0) goto read_error; + if (Read32FromFile( fid, &ChunkSize ) < 0) goto read_error; BytesLeft -= 8; - DBUG(("ChunkID = %4s, Size = %d\n", &ChunkID, ChunkSize )); + DBUG(("ChunkID = %4s, Size = %d\n", (char *)&ChunkID, ChunkSize )); switch( ChunkID ) { @@ -500,12 +569,14 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); BytesLeft -= ChunkSize; /* Convert all fields in structure from BigEndian to Native. */ - p = (uint32 *) sd; - for( i=0; i<((int)(sizeof(*sd)/sizeof(int32))); i++ ) { - p[i] = ReadLongBigEndian( &p[i] ); + uint32_t *p = (uint32_t *) sd; + for( i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++ ) + { + p[i] = Read32BigEndian( (uint8_t *)&p[i] ); + } } - + isDicBigEndian = sd->sd_Flags & SD_F_BIG_ENDIAN_DIC; if( !gVarQuiet ) @@ -516,6 +587,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); MSG_NUM_D(" Name space size = ", sd->sd_NameSize ); MSG_NUM_D(" Code space size = ", sd->sd_CodeSize ); MSG_NUM_D(" Entry Point = ", sd->sd_EntryPoint ); + MSG_NUM_D(" Cell Size = ", sd->sd_CellSize ); MSG( (isDicBigEndian ? " Big Endian Dictionary" : " Little Endian Dictionary") ); if( isDicBigEndian == IsHostLittleEndian() ) MSG(" !!!!"); @@ -532,6 +604,11 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); pfReportError("pfLoadDictionary", PF_ERR_VERSION_PAST ); goto error; } + if( sd->sd_CellSize != sizeof(cell_t) ) + { + pfReportError("pfLoadDictionary", PF_ERR_CELL_SIZE_CONFLICT ); + goto error; + } if( sd->sd_NumPrimitives > NUM_PRIMITIVES ) { pfReportError("pfLoadDictionary", PF_ERR_NOT_SUPPORTED ); @@ -568,7 +645,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); if( sd->sd_NameSize > 0 ) { gVarContext = (char *) NAMEREL_TO_ABS(sd->sd_RelContext); /* Restore context. */ - gCurrentDictionary->dic_HeaderPtr.Byte = (uint8 *) + gCurrentDictionary->dic_HeaderPtr.Byte = (uint8_t *) NAMEREL_TO_ABS(sd->sd_RelHeaderPtr); } else @@ -576,7 +653,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); gVarContext = 0; gCurrentDictionary->dic_HeaderPtr.Byte = NULL; } - gCurrentDictionary->dic_CodePtr.Byte = (uint8 *) CODEREL_TO_ABS(sd->sd_RelCodePtr); + gCurrentDictionary->dic_CodePtr.Byte = (uint8_t *) CODEREL_TO_ABS(sd->sd_RelCodePtr); gNumPrimitives = sd->sd_NumPrimitives; /* Must match compiled dictionary. */ /* Pass EntryPoint back to caller. */ if( EntryPointPtr != NULL ) *EntryPointPtr = sd->sd_EntryPoint; @@ -636,7 +713,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); if( NAME_BASE != NULL) { - int32 Result; + cell_t Result; /* Find special words in dictionary for global XTs. */ if( (Result = FindSpecialXTs()) < 0 ) { @@ -645,7 +722,7 @@ DBUG(("pfLoadDictionary( %s )\n", FileName )); } } -DBUG(("pfLoadDictionary: return 0x%x\n", dic)); +DBUG(("pfLoadDictionary: return %p\n", dic)); return (PForthDictionary) dic; nomem_error: @@ -677,9 +754,9 @@ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPt PForthDictionary pfLoadStaticDictionary( void ) { #ifdef PF_STATIC_DIC - int32 Result; + cell_t Result; pfDictionary_t *dic; - int32 NewNameSize, NewCodeSize; + cell_t NewNameSize, NewCodeSize; if( IF_LITTLE_ENDIAN != IsHostLittleEndian() ) { @@ -725,15 +802,15 @@ PForthDictionary pfLoadStaticDictionary( void ) pfCopyMemory( dic->dic_HeaderBase, MinDicNames, sizeof(MinDicNames) ); pfCopyMemory( dic->dic_CodeBase, MinDicCode, sizeof(MinDicCode) ); - DBUG("Static data copied to newly allocated dictionaries.\n"); + DBUG(("Static data copied to newly allocated dictionaries.\n")); - dic->dic_CodePtr.Byte = (uint8 *) CODEREL_TO_ABS(CODEPTR); + dic->dic_CodePtr.Byte = (uint8_t *) CODEREL_TO_ABS(CODEPTR); gNumPrimitives = NUM_PRIMITIVES; if( NAME_BASE != NULL) { /* Setup name space. */ - dic->dic_HeaderPtr.Byte = (uint8 *) NAMEREL_TO_ABS(HEADERPTR); + dic->dic_HeaderPtr.Byte = (uint8_t *) NAMEREL_TO_ABS(HEADERPTR); gVarContext = (char *) NAMEREL_TO_ABS(RELCONTEXT); /* Restore context. */ /* Find special words in dictionary for global XTs. */ diff --git a/csrc/pf_save.h b/csrc/pf_save.h index f4d1e7a..3bf8c2f 100644 --- a/csrc/pf_save.h +++ b/csrc/pf_save.h @@ -24,28 +24,30 @@ typedef struct DictionaryInfoChunk { -/* All fields are stored in BIG ENDIAN format for consistency in data files. */ -/* All fileds must be the same size as int32 for easy endian conversion. */ - int32 sd_Version; - int32 sd_RelContext; /* relative ptr to Dictionary Context */ - int32 sd_RelHeaderPtr; /* relative ptr to Dictionary Header Ptr */ - int32 sd_RelCodePtr; /* relative ptr to Dictionary Header Ptr */ - ExecToken sd_EntryPoint; /* relative ptr to entry point or NULL */ - int32 sd_UserStackSize; /* in bytes */ - int32 sd_ReturnStackSize; /* in bytes */ - int32 sd_NameSize; /* in bytes */ - int32 sd_CodeSize; /* in bytes */ - int32 sd_NumPrimitives; /* To distinguish between primitive and secondary. */ - uint32 sd_Flags; - int32 sd_FloatSize; /* In bytes. Must match code. 0 means no floats. */ - uint32 sd_Reserved; +/* All fields are stored in BIG ENDIAN format for consistency in data files. + * All fields must be the same size for easy endian conversion. + * All fields must be 32 bit for file compatibility with older versions. + */ + int32_t sd_Version; + int32_t sd_RelContext; /* relative ptr to Dictionary Context */ + int32_t sd_RelHeaderPtr; /* relative ptr to Dictionary Header Ptr */ + int32_t sd_RelCodePtr; /* relative ptr to Dictionary Header Ptr */ + int32_t sd_EntryPoint; /* relative ptr to entry point or NULL */ + int32_t sd_UserStackSize; /* in bytes */ + int32_t sd_ReturnStackSize; /* in bytes */ + int32_t sd_NameSize; /* in bytes */ + int32_t sd_CodeSize; /* in bytes */ + int32_t sd_NumPrimitives; /* To distinguish between primitive and secondary. */ + uint32_t sd_Flags; + int32_t sd_FloatSize; /* In bytes. Must match code. 0 means no floats. */ + int32_t sd_CellSize; /* In bytes. Must match code. */ } DictionaryInfoChunk; /* Bits in sd_Flags */ #define SD_F_BIG_ENDIAN_DIC (1<<0) #ifndef MAKE_ID -#define MAKE_ID(a,b,c,d) ((((uint32)a)<<24)|(((uint32)b)<<16)|(((uint32)c)<<8)|((uint32)d)) +#define MAKE_ID(a,b,c,d) ((((uint32_t)a)<<24)|(((uint32_t)b)<<16)|(((uint32_t)c)<<8)|((uint32_t)d)) #endif #define ID_FORM MAKE_ID('F','O','R','M') @@ -63,19 +65,26 @@ typedef struct DictionaryInfoChunk extern "C" { #endif -int32 ffSaveForth( const char *FileName, ExecToken EntryPoint, int32 NameSize, int32 CodeSize ); +cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, cell_t CodeSize ); /* Endian-ness tools. */ - int IsHostLittleEndian( void ); -uint32 ReadLongBigEndian( const uint32 *addr ); -uint16 ReadShortBigEndian( const uint16 *addr ); -uint32 ReadLongLittleEndian( const uint32 *addr ); -uint16 ReadShortLittleEndian( const uint16 *addr ); -void WriteLongBigEndian( uint32 *addr, uint32 data ); -void WriteShortBigEndian( uint16 *addr, uint16 data ); -void WriteLongLittleEndian( uint32 *addr, uint32 data ); -void WriteShortLittleEndian( uint16 *addr, uint16 data ); + +ucell_t ReadCellBigEndian( const uint8_t *addr ); +uint32_t Read32BigEndian( const uint8_t *addr ); +uint16_t Read16BigEndian( const uint8_t *addr ); + +ucell_t ReadCellLittleEndian( const uint8_t *addr ); +uint32_t Read32LittleEndian( const uint8_t *addr ); +uint16_t Read16LittleEndian( const uint8_t *addr ); + +void WriteCellBigEndian( uint8_t *addr, ucell_t data ); +void Write32BigEndian( uint8_t *addr, uint32_t data ); +void Write16BigEndian( uint8_t *addr, uint16_t data ); + +void WriteCellLittleEndian( uint8_t *addr, ucell_t data ); +void Write32LittleEndian( uint8_t *addr, uint32_t data ); +void Write16LittleEndian( uint8_t *addr, uint16_t data ); #ifdef PF_SUPPORT_FP void WriteFloatBigEndian( PF_FLOAT *addr, PF_FLOAT data ); diff --git a/csrc/pf_text.c b/csrc/pf_text.c index ebf5c48..9530546 100644 --- a/csrc/pf_text.c +++ b/csrc/pf_text.c @@ -82,6 +82,8 @@ void pfReportError( const char *FunctionName, Err ErrCode ) s = "endian-ness of dictionary does not match code"; break; case PF_ERR_FLOAT_CONFLICT & 0xFF: s = "float support mismatch between .dic file and code"; break; + case PF_ERR_CELL_SIZE_CONFLICT & 0xFF: + s = "cell size mismatch between .dic file and code"; break; default: s = "unrecognized error code!"; break; } @@ -135,9 +137,9 @@ void pfReportThrow( ThrowCode code ) char *ForthStringToC( char *dst, const char *FString ) { - int32 Len; + cell_t Len; - Len = (int32) *FString; + Len = (cell_t) *FString; pfCopyMemory( dst, FString+1, Len ); dst[Len] = '\0'; @@ -150,7 +152,7 @@ char *ForthStringToC( char *dst, const char *FString ) char *CStringToForth( char *dst, const char *CString ) { char *s; - int32 i; + cell_t i; s = dst+1; for( i=0; *CString; i++ ) @@ -165,9 +167,9 @@ char *CStringToForth( char *dst, const char *CString ) ** Compare two test strings, case sensitive. ** Return TRUE if they match. */ -int32 ffCompareText( const char *s1, const char *s2, int32 len ) +cell_t ffCompareText( const char *s1, const char *s2, cell_t len ) { - int32 i, Result; + cell_t i, Result; Result = TRUE; for( i=0; is2; */ -int32 ffCompare( const char *s1, int32 len1, const char *s2, int32 len2 ) +cell_t ffCompare( const char *s1, cell_t len1, const char *s2, int32_t len2 ) { - int32 i, result, n, diff; + cell_t i, result, n, diff; result = 0; n = MIN(len1,len2); @@ -243,15 +245,15 @@ int32 ffCompare( const char *s1, int32 len1, const char *s2, int32 len2 ) /*************************************************************** ** Convert number to text. */ -#define CNTT_PAD_SIZE ((sizeof(int32)*8)+2) /* PLB 19980522 - Expand PAD so "-1 binary .s" doesn't crash. */ +#define CNTT_PAD_SIZE ((sizeof(cell_t)*8)+2) /* PLB 19980522 - Expand PAD so "-1 binary .s" doesn't crash. */ static char cnttPad[CNTT_PAD_SIZE]; -char *ConvertNumberToText( int32 Num, int32 Base, int32 IfSigned, int32 MinChars ) +char *ConvertNumberToText( cell_t Num, cell_t Base, int32_t IfSigned, int32_t MinChars ) { - int32 IfNegative = 0; + cell_t IfNegative = 0; char *p,c; - uint32 NewNum, Rem, uNum; - int32 i = 0; + ucell_t NewNum, Rem, uNum; + cell_t i = 0; uNum = Num; if( IfSigned ) @@ -287,9 +289,9 @@ char *ConvertNumberToText( int32 Num, int32 Base, int32 IfSigned, int32 MinChars /*************************************************************** ** Diagnostic routine that prints memory in table format. */ -void DumpMemory( void *addr, int32 cnt) +void DumpMemory( void *addr, cell_t cnt) { - int32 ln, cn, nlines; + cell_t ln, cn, nlines; unsigned char *ptr, *cptr, c; nlines = (cnt + 15) / 16; @@ -300,12 +302,12 @@ void DumpMemory( void *addr, int32 cnt) for (ln=0; ln= '0') && (c <= '9') ) { @@ -156,9 +156,9 @@ static cell HexDigitToNumber( char c ) } /* Convert a string to the corresponding number using BASE. */ -cell ffNumberQ( const char *FWord, cell *Num ) +cell_t ffNumberQ( const char *FWord, cell_t *Num ) { - int32 Len, i, Accum=0, n, Sign=1; + cell_t Len, i, Accum=0, n, Sign=1; const char *s; /* get count */ @@ -195,8 +195,8 @@ cell ffNumberQ( const char *FWord, cell *Num ) char * ffWord( char c ) { char *s1,*s2,*s3; - int32 n1, n2, n3; - int32 i, nc; + cell_t n1, n2, n3; + cell_t i, nc; s1 = gCurrentTask->td_SourcePtr + gCurrentTask->td_IN; n1 = gCurrentTask->td_SourceNum - gCurrentTask->td_IN; diff --git a/csrc/pf_words.h b/csrc/pf_words.h index 2dc2e92..edf81a1 100644 --- a/csrc/pf_words.h +++ b/csrc/pf_words.h @@ -23,11 +23,11 @@ extern "C" { #endif -void ffDot( int32 n ); -void ffDotHex( int32 n ); +void ffDot( cell_t n ); +void ffDotHex( cell_t n ); void ffDotS( void ); -cell ffSkip( char *AddrIn, cell Cnt, char c, char **AddrOut ); -cell ffScan( char *AddrIn, cell Cnt, char c, char **AddrOut ); +cell_t ffSkip( char *AddrIn, cell_t Cnt, char c, char **AddrOut ); +cell_t ffScan( char *AddrIn, cell_t Cnt, char c, char **AddrOut ); #ifdef __cplusplus } diff --git a/csrc/pfcompil.c b/csrc/pfcompil.c index 0d3e33e..3613b33 100644 --- a/csrc/pfcompil.c +++ b/csrc/pfcompil.c @@ -25,23 +25,23 @@ #include "pfcompil.h" #define ABORT_RETURN_CODE (10) -#define UINT32_MASK ((sizeof(uint32)-1)) +#define UINT32_MASK ((sizeof(ucell_t)-1)) /***************************************************************/ /************** Static Prototypes ******************************/ /***************************************************************/ static void ffStringColon( const ForthStringPtr FName ); -static int32 CheckRedefinition( const ForthStringPtr FName ); +static cell_t CheckRedefinition( const ForthStringPtr FName ); static void ffUnSmudge( void ); -static int32 FindAndCompile( const char *theWord ); -static int32 ffCheckDicRoom( void ); +static cell_t FindAndCompile( const char *theWord ); +static cell_t ffCheckDicRoom( void ); #ifndef PF_NO_INIT static void CreateDeferredC( ExecToken DefaultXT, const char *CName ); #endif -int32 NotCompiled( const char *FunctionName ) +cell_t NotCompiled( const char *FunctionName ) { MSG("Function "); MSG(FunctionName); @@ -54,7 +54,7 @@ int32 NotCompiled( const char *FunctionName ) ** Create an entry in the Dictionary for the given ExecutionToken. ** FName is name in Forth format. */ -void CreateDicEntry( ExecToken XT, const ForthStringPtr FName, uint32 Flags ) +void CreateDicEntry( ExecToken XT, const ForthStringPtr FName, ucell_t Flags ) { cfNameLinks *cfnl; @@ -63,7 +63,7 @@ void CreateDicEntry( ExecToken XT, const ForthStringPtr FName, uint32 Flags ) /* Set link to previous header, if any. */ if( gVarContext ) { - WRITE_LONG_DIC( &cfnl->cfnl_PreviousName, ABS_TO_NAMEREL( gVarContext ) ); + WRITE_CELL_DIC( &cfnl->cfnl_PreviousName, ABS_TO_NAMEREL( gVarContext ) ); } else { @@ -71,7 +71,7 @@ void CreateDicEntry( ExecToken XT, const ForthStringPtr FName, uint32 Flags ) } /* Put Execution token in header. */ - WRITE_LONG_DIC( &cfnl->cfnl_ExecToken, XT ); + WRITE_CELL_DIC( &cfnl->cfnl_ExecToken, XT ); /* Advance Header Dictionary Pointer */ gCurrentDictionary->dic_HeaderPtr.Byte += sizeof(cfNameLinks); @@ -85,7 +85,7 @@ void CreateDicEntry( ExecToken XT, const ForthStringPtr FName, uint32 Flags ) *gVarContext |= (char) Flags; /* Align to quad byte boundaries with zeroes. */ - while( ((uint32) gCurrentDictionary->dic_HeaderPtr.Byte) & UINT32_MASK ) + while( ((ucell_t) gCurrentDictionary->dic_HeaderPtr.Byte) & UINT32_MASK ) { *gCurrentDictionary->dic_HeaderPtr.Byte++ = 0; } @@ -94,7 +94,7 @@ void CreateDicEntry( ExecToken XT, const ForthStringPtr FName, uint32 Flags ) /*************************************************************** ** Convert name then create dictionary entry. */ -void CreateDicEntryC( ExecToken XT, const char *CName, uint32 Flags ) +void CreateDicEntryC( ExecToken XT, const char *CName, ucell_t Flags ) { ForthString FName[40]; CStringToForth( FName, CName ); @@ -107,14 +107,14 @@ void CreateDicEntryC( ExecToken XT, const char *CName, uint32 Flags ) */ const ForthString *NameToPrevious( const ForthString *NFA ) { - cell RelNamePtr; + cell_t RelNamePtr; const cfNameLinks *cfnl; -/* DBUG(("\nNameToPrevious: NFA = 0x%x\n", (int32) NFA)); */ +/* DBUG(("\nNameToPrevious: NFA = 0x%x\n", (cell_t) NFA)); */ cfnl = (const cfNameLinks *) ( ((const char *) NFA) - sizeof(cfNameLinks) ); - RelNamePtr = READ_LONG_DIC((const cell *) (&cfnl->cfnl_PreviousName)); -/* DBUG(("\nNameToPrevious: RelNamePtr = 0x%x\n", (int32) RelNamePtr )); */ + RelNamePtr = READ_CELL_DIC((const cell_t *) (&cfnl->cfnl_PreviousName)); +/* DBUG(("\nNameToPrevious: RelNamePtr = 0x%x\n", (cell_t) RelNamePtr )); */ if( RelNamePtr ) { return ( NAMEREL_TO_ABS( RelNamePtr ) ); @@ -134,18 +134,18 @@ ExecToken NameToToken( const ForthString *NFA ) /* Convert absolute namefield address to absolute link field address. */ cfnl = (const cfNameLinks *) ( ((const char *) NFA) - sizeof(cfNameLinks) ); - return READ_LONG_DIC((const cell *) (&cfnl->cfnl_ExecToken)); + return READ_CELL_DIC((const cell_t *) (&cfnl->cfnl_ExecToken)); } /*************************************************************** ** Find XTs needed by compiler. */ -int32 FindSpecialXTs( void ) +cell_t FindSpecialXTs( void ) { if( ffFindC( "(QUIT)", &gQuitP_XT ) == 0) goto nofind; if( ffFindC( "NUMBER?", &gNumberQ_XT ) == 0) goto nofind; if( ffFindC( "ACCEPT", &gAcceptP_XT ) == 0) goto nofind; -DBUG(("gNumberQ_XT = 0x%x\n", gNumberQ_XT )); +DBUG(("gNumberQ_XT = 0x%x\n", (unsigned int)gNumberQ_XT )); return 0; nofind: @@ -157,7 +157,7 @@ nofind: ** Build a dictionary from scratch. */ #ifndef PF_NO_INIT -PForthDictionary pfBuildDictionary( int32 HeaderSize, int32 CodeSize ) +PForthDictionary pfBuildDictionary( cell_t HeaderSize, cell_t CodeSize ) { pfDictionary_t *dic; @@ -197,6 +197,8 @@ PForthDictionary pfBuildDictionary( int32 HeaderSize, int32 CodeSize ) CreateDicEntryC( ID_BODY_OFFSET, "BODY_OFFSET", 0 ); CreateDicEntryC( ID_BYE, "BYE", 0 ); CreateDicEntryC( ID_CATCH, "CATCH", 0 ); + CreateDicEntryC( ID_CELL, "CELL", 0 ); + CreateDicEntryC( ID_CELLS, "CELLS", 0 ); CreateDicEntryC( ID_CFETCH, "C@", 0 ); CreateDicEntryC( ID_CMOVE, "CMOVE", 0 ); CreateDicEntryC( ID_CMOVE_UP, "CMOVE>", 0 ); @@ -398,11 +400,11 @@ nomem: ** ( xt -- nfa 1 , x 0 , find NFA in dictionary from XT ) ** 1 for IMMEDIATE values */ -cell ffTokenToName( ExecToken XT, const ForthString **NFAPtr ) +cell_t ffTokenToName( ExecToken XT, const ForthString **NFAPtr ) { const ForthString *NameField; - int32 Searching = TRUE; - cell Result = 0; + cell_t Searching = TRUE; + cell_t Result = 0; ExecToken TempXT; NameField = gVarContext; @@ -437,16 +439,16 @@ DBUGX(("ffCodeToName: NFA = 0x%x\n", NameField)); ** ( $name -- $addr 0 | nfa -1 | nfa 1 , find NFA in dictionary ) ** 1 for IMMEDIATE values */ -cell ffFindNFA( const ForthString *WordName, const ForthString **NFAPtr ) +cell_t ffFindNFA( const ForthString *WordName, const ForthString **NFAPtr ) { const ForthString *WordChar; - uint8 WordLen; + uint8_t WordLen; const char *NameField, *NameChar; - int8 NameLen; - int32 Searching = TRUE; - cell Result = 0; + int8_t NameLen; + cell_t Searching = TRUE; + cell_t Result = 0; - WordLen = (uint8) ((uint32)*WordName & 0x1F); + WordLen = (uint8_t) ((ucell_t)*WordName & 0x1F); WordChar = WordName+1; NameField = gVarContext; @@ -454,7 +456,7 @@ DBUG(("\nffFindNFA: WordLen = %d, WordName = %*s\n", WordLen, WordLen, WordChar DBUG(("\nffFindNFA: gVarContext = 0x%x\n", gVarContext)); do { - NameLen = (uint8) ((uint32)(*NameField) & MASK_NAME_SIZE); + NameLen = (uint8_t) ((ucell_t)(*NameField) & MASK_NAME_SIZE); NameChar = NameField+1; /* DBUG((" %c\n", (*NameField & FLAG_SMUDGE) ? 'S' : 'V' )); */ if( ((*NameField & FLAG_SMUDGE) == 0) && @@ -485,10 +487,10 @@ DBUG(("ffFindNFA: returns 0x%x\n", Result)); ** ( $name -- $name 0 | xt -1 | xt 1 ) ** 1 for IMMEDIATE values */ -cell ffFind( const ForthString *WordName, ExecToken *pXT ) +cell_t ffFind( const ForthString *WordName, ExecToken *pXT ) { const ForthString *NFA; - int32 Result; + cell_t Result; Result = ffFindNFA( WordName, &NFA ); DBUG(("ffFind: %8s at 0x%x\n", WordName+1, NFA)); /* WARNING, not NUL terminated. %Q */ @@ -507,7 +509,7 @@ DBUG(("ffFind: %8s at 0x%x\n", WordName+1, NFA)); /* WARNING, not NUL terminated /**************************************************************** ** Find name when passed 'C' string. */ -cell ffFindC( const char *WordName, ExecToken *pXT ) +cell_t ffFindC( const char *WordName, ExecToken *pXT ) { DBUG(("ffFindC: %s\n", WordName )); CStringToForth( gScratch, WordName ); @@ -523,9 +525,9 @@ DBUG(("ffFindC: %s\n", WordName )); /************************************************************* ** Check for dictionary overflow. */ -static int32 ffCheckDicRoom( void ) +static cell_t ffCheckDicRoom( void ) { - int32 RoomLeft; + cell_t RoomLeft; RoomLeft = gCurrentDictionary->dic_HeaderLimit - gCurrentDictionary->dic_HeaderPtr.Byte; if( RoomLeft < DIC_SAFETY_MARGIN ) @@ -556,9 +558,8 @@ void ffCreateSecondaryHeader( const ForthStringPtr FName) pfDebugMessage("ffCreateSecondaryHeader: CheckRedefinition()\n"); CheckRedefinition( FName ); /* Align CODE_HERE */ - CODE_HERE = (cell *)( (((uint32)CODE_HERE) + UINT32_MASK) & ~UINT32_MASK); + CODE_HERE = (cell_t *)( (((ucell_t)CODE_HERE) + UINT32_MASK) & ~UINT32_MASK); CreateDicEntry( (ExecToken) ABS_TO_CODEREL(CODE_HERE), FName, FLAG_SMUDGE ); -DBUG(("ffCreateSecondaryHeader, XT = 0x%x, Name = %8s\n")); } /************************************************************* @@ -589,15 +590,15 @@ void ffColon( void ) /************************************************************* ** Check to see if name is already in dictionary. */ -static int32 CheckRedefinition( const ForthStringPtr FName ) +static cell_t CheckRedefinition( const ForthStringPtr FName ) { - int32 flag; + cell_t flag; ExecToken XT; flag = ffFind( FName, &XT); if ( flag && !gVarQuiet) { - ioType( FName+1, (int32) *FName ); + ioType( FName+1, (cell_t) *FName ); MSG( " redefined.\n" ); // FIXME - allow user to run off this warning. } return flag; @@ -692,18 +693,18 @@ void ffFinishSecondary( void ) /**************************************************************/ /* Used to pull a number from the dictionary to the stack */ -void ff2Literal( cell dHi, cell dLo ) +void ff2Literal( cell_t dHi, cell_t dLo ) { CODE_COMMA( ID_2LITERAL_P ); CODE_COMMA( dHi ); CODE_COMMA( dLo ); } -void ffALiteral( cell Num ) +void ffALiteral( cell_t Num ) { CODE_COMMA( ID_ALITERAL_P ); CODE_COMMA( Num ); } -void ffLiteral( cell Num ) +void ffLiteral( cell_t Num ) { CODE_COMMA( ID_LITERAL_P ); CODE_COMMA( Num ); @@ -716,11 +717,11 @@ void ffFPLiteral( PF_FLOAT fnum ) * original expression. */ PF_FLOAT *temp; - cell *dicPtr; + cell_t *dicPtr; /* Make sure that literal float data is float aligned. */ dicPtr = CODE_HERE + 1; - while( (((uint32) dicPtr++) & (sizeof(PF_FLOAT) - 1)) != 0) + while( (((ucell_t) dicPtr++) & (sizeof(PF_FLOAT) - 1)) != 0) { DBUG((" comma NOOP to align FPLiteral\n")); CODE_COMMA( ID_NOOP ); @@ -730,16 +731,16 @@ void ffFPLiteral( PF_FLOAT fnum ) temp = (PF_FLOAT *)CODE_HERE; WRITE_FLOAT_DIC(temp,fnum); /* Write to dictionary. */ temp++; - CODE_HERE = (cell *) temp; + CODE_HERE = (cell_t *) temp; } #endif /* PF_SUPPORT_FP */ /**************************************************************/ ThrowCode FindAndCompile( const char *theWord ) { - int32 Flag; + cell_t Flag; ExecToken XT; - cell Num; + cell_t Num; ThrowCode exception = 0; Flag = ffFind( theWord, &XT); @@ -765,7 +766,7 @@ DBUG(("FindAndCompile: IMMEDIATE, theWord = 0x%x\n", theWord )); else /* try to interpret it as a number. */ { /* Call deferred NUMBER? */ - int32 NumResult; + cell_t NumResult; DBUG(("FindAndCompile: not found, try number?\n" )); PUSH_DATA_STACK( theWord ); /* Push text of number */ @@ -820,7 +821,7 @@ error: */ ThrowCode ffInterpret( void ) { - int32 flag; + cell_t flag; char *theWord; ThrowCode exception = 0; @@ -852,7 +853,6 @@ ThrowCode ffInterpret( void ) DBUG(("ffInterpret: IN=%d, SourceNum=%d\n", gCurrentTask->td_IN, gCurrentTask->td_SourceNum ) ); } - DBUG(("ffInterpret: CHECK_ABORT = %d\n", CHECK_ABORT)); error: return exception; } @@ -860,7 +860,7 @@ error: /**************************************************************/ ThrowCode ffOK( void ) { - int32 exception = 0; + cell_t exception = 0; /* Check for stack underflow. %Q what about overflows? */ if( (gCurrentTask->td_StackBase - gCurrentTask->td_StackPtr) < 0 ) { @@ -909,7 +909,7 @@ void pfHandleIncludeError( void ) ***************************************************************/ ThrowCode ffOuterInterpreterLoop( void ) { - int32 exception = 0; + cell_t exception = 0; do { exception = ffRefill(); @@ -972,7 +972,7 @@ ThrowCode ffIncludeFile( FileStream *InputFile ) ***************************************************************/ Err ffPushInputStream( FileStream *InputFile ) { - cell Result = 0; + cell_t Result = 0; IncludeFrame *inf; /* Push current input state onto special include stack. */ @@ -1040,9 +1040,9 @@ DBUG(("ffPopInputStream: return = 0x%x\n", Result )); /*************************************************************** ** Convert file pointer to value consistent with SOURCE-ID. ***************************************************************/ -cell ffConvertStreamToSourceID( FileStream *Stream ) +cell_t ffConvertStreamToSourceID( FileStream *Stream ) { - cell Result; + cell_t Result; if(Stream == PF_STDIN) { Result = 0; @@ -1053,7 +1053,7 @@ cell ffConvertStreamToSourceID( FileStream *Stream ) } else { - Result = (cell) Stream; + Result = (cell_t) Stream; } return Result; } @@ -1061,7 +1061,7 @@ cell ffConvertStreamToSourceID( FileStream *Stream ) /*************************************************************** ** Convert file pointer to value consistent with SOURCE-ID. ***************************************************************/ -FileStream * ffConvertSourceIDToStream( cell id ) +FileStream * ffConvertSourceIDToStream( cell_t id ) { FileStream *stream; @@ -1085,7 +1085,7 @@ FileStream * ffConvertSourceIDToStream( cell id ) ** Return length, or -1 for EOF. */ #define BACKSPACE (8) -static cell readLineFromStream( char *buffer, cell maxChars, FileStream *stream ) +static cell_t readLineFromStream( char *buffer, cell_t maxChars, FileStream *stream ) { int c; int len; @@ -1135,10 +1135,10 @@ DBUGX(("readLineFromStream(0x%x, 0x%x, 0x%x)\n", buffer, len, stream )); ** ( -- , fill Source from current stream ) ** Return 1 if successful, 0 for EOF, or a negative error. */ -cell ffRefill( void ) +cell_t ffRefill( void ) { - cell Num; - cell Result = 1; + cell_t Num; + cell_t Result = 1; /* reset >IN for parser */ gCurrentTask->td_IN = 0; diff --git a/csrc/pfcompil.h b/csrc/pfcompil.h index cdb7785..8f27015 100644 --- a/csrc/pfcompil.h +++ b/csrc/pfcompil.h @@ -26,32 +26,32 @@ extern "C" { Err ffPushInputStream( FileStream *InputFile ); ExecToken NameToToken( const ForthString *NFA ); -FileStream * ffConvertSourceIDToStream( cell id ); +FileStream * ffConvertSourceIDToStream( cell_t id ); FileStream *ffPopInputStream( void ); -cell ffConvertStreamToSourceID( FileStream *Stream ); -cell ffFind( const ForthString *WordName, ExecToken *pXT ); -cell ffFindC( const char *WordName, ExecToken *pXT ); -cell ffFindNFA( const ForthString *WordName, const ForthString **NFAPtr ); -cell ffNumberQ( const char *FWord, cell *Num ); -cell ffRefill( void ); -cell ffTokenToName( ExecToken XT, const ForthString **NFAPtr ); -cell *NameToCode( ForthString *NFA ); -PForthDictionary pfBuildDictionary( int32 HeaderSize, int32 CodeSize ); +cell_t ffConvertStreamToSourceID( FileStream *Stream ); +cell_t ffFind( const ForthString *WordName, ExecToken *pXT ); +cell_t ffFindC( const char *WordName, ExecToken *pXT ); +cell_t ffFindNFA( const ForthString *WordName, const ForthString **NFAPtr ); +cell_t ffNumberQ( const char *FWord, cell_t *Num ); +cell_t ffRefill( void ); +cell_t ffTokenToName( ExecToken XT, const ForthString **NFAPtr ); +cell_t *NameToCode( ForthString *NFA ); +PForthDictionary pfBuildDictionary( cell_t HeaderSize, cell_t CodeSize ); char *ffWord( char c ); const ForthString *NameToPrevious( const ForthString *NFA ); -int32 FindSpecialCFAs( void ); -int32 FindSpecialXTs( void ); -int32 NotCompiled( const char *FunctionName ); -void CreateDicEntry( ExecToken XT, const ForthStringPtr FName, uint32 Flags ); -void CreateDicEntryC( ExecToken XT, const char *CName, uint32 Flags ); -void ff2Literal( cell dHi, cell dLo ); -void ffALiteral( cell Num ); +cell_t FindSpecialCFAs( void ); +cell_t FindSpecialXTs( void ); +cell_t NotCompiled( const char *FunctionName ); +void CreateDicEntry( ExecToken XT, const ForthStringPtr FName, ucell_t Flags ); +void CreateDicEntryC( ExecToken XT, const char *CName, ucell_t Flags ); +void ff2Literal( cell_t dHi, cell_t dLo ); +void ffALiteral( cell_t Num ); void ffColon( void ); void ffCreate( void ); void ffCreateSecondaryHeader( const ForthStringPtr FName); void ffDefer( void ); void ffFinishSecondary( void ); -void ffLiteral( cell Num ); +void ffLiteral( cell_t Num ); void ffStringCreate( ForthStringPtr FName); void ffStringDefer( const ForthStringPtr FName, ExecToken DefaultXT ); void pfHandleIncludeError( void ); diff --git a/csrc/pfcustom.c b/csrc/pfcustom.c index 7aa8ff4..ca42f61 100644 --- a/csrc/pfcustom.c +++ b/csrc/pfcustom.c @@ -28,20 +28,20 @@ #include "pf_all.h" -static int32 CTest0( int32 Val ); -static void CTest1( int32 Val1, cell Val2 ); +static cell_t CTest0( cell_t Val ); +static void CTest1( cell_t Val1, cell_t Val2 ); /**************************************************************** ** Step 1: Put your own special glue routines here ** or link them in from another file or library. ****************************************************************/ -static int32 CTest0( int32 Val ) +static cell_t CTest0( cell_t Val ) { MSG_NUM_D("CTest0: Val = ", Val); return Val+1; } -static void CTest1( int32 Val1, cell Val2 ) +static void CTest1( cell_t Val1, cell_t Val2 ) { MSG("CTest1: Val1 = "); ffDot(Val1); diff --git a/csrc/pfdicdat_arm.h b/csrc/pfdicdat_arm.h index 8aebba7..19299ce 100644 --- a/csrc/pfdicdat_arm.h +++ b/csrc/pfdicdat_arm.h @@ -3,7 +3,7 @@ #define RELCONTEXT (0x00003D5C) #define CODEPTR (0x000093E8) #define IF_LITTLE_ENDIAN (0x00000001) -static const uint8 MinDicNames[] = { +static const uint8_t MinDicNames[] = { /* 0x00000000: */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x45,0x58,0x49,0x54,0x00,0x00,0x00, /* 0x00000010: */ 0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,0x31,0x2D,0x00,0x18,0x00,0x00,0x00, /* 0x00000020: */ 0x02,0x00,0x00,0x00,0x02,0x31,0x2B,0x00,0x24,0x00,0x00,0x00,0x0A,0x00,0x00,0x00, @@ -989,7 +989,7 @@ static const uint8 MinDicNames[] = { /* 0x00003D60: */ 0x3B,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, }; -static const uint8 MinDicCode[] = { +static const uint8_t MinDicCode[] = { /* 0x00000000: */ 0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A, /* 0x00000010: */ 0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A, /* 0x00000020: */ 0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A, diff --git a/csrc/pfinnrfp.h b/csrc/pfinnrfp.h index d0bd4ab..0428b25 100644 --- a/csrc/pfinnrfp.h +++ b/csrc/pfinnrfp.h @@ -41,7 +41,7 @@ { fpTemp = ((PF_FLOAT) TOS); /* dhi */ fpTemp *= FP_DHI1; - fpScratch = ( (PF_FLOAT) ((uint32)Scratch) ); /* Convert TOS and push on FP stack. */ + fpScratch = ( (PF_FLOAT) ((ucell_t)Scratch) ); /* Convert TOS and push on FP stack. */ FP_TOS = fpTemp + fpScratch; } M_DROP; @@ -102,8 +102,8 @@ case ID_FP_F_TO_D: /* ( -- dlo dhi) ( F: r -- ) */ /* printf("f2d = %g\n", FP_TOS); */ { - uint32 dlo; - int32 dhi; + ucell_t dlo; + cell_t dhi; int ifNeg; /* Convert absolute value, then negate D if negative. */ PUSH_TOS; /* Save old TOS */ @@ -116,12 +116,12 @@ } fpScratch = fpTemp / FP_DHI1; /* printf("f2d - fpScratch = %g\n", fpScratch); */ - dhi = (int32) fpScratch; /* dhi */ + dhi = (cell_t) fpScratch; /* dhi */ fpScratch = ((PF_FLOAT) dhi) * FP_DHI1; /* printf("f2d - , dhi = 0x%x, fpScratch = %g\n", dhi, fpScratch); */ fpTemp = fpTemp - fpScratch; /* Remainder */ - dlo = (uint32) fpTemp; + dlo = (ucell_t) fpTemp; /* printf("f2d - , dlo = 0x%x, fpTemp = %g\n", dlo, fpTemp); */ if( ifNeg ) { @@ -284,7 +284,7 @@ PF_FLOAT *fptr; fptr = (PF_FLOAT *)InsPtr; FP_TOS = READ_FLOAT_DIC( fptr++ ); - InsPtr = (cell *) fptr; + InsPtr = (cell_t *) fptr; } #endif endcase; diff --git a/csrc/pforth.h b/csrc/pforth.h index 39a1290..70a700a 100644 --- a/csrc/pforth.h +++ b/csrc/pforth.h @@ -26,31 +26,32 @@ typedef void *PForthTask; typedef void *PForthDictionary; -typedef unsigned long ExecToken; /* Execution Token */ -typedef long ThrowCode; +#include +/* Integer types for Forth cells, signed and unsigned: */ +typedef intptr_t cell_t; +typedef uintptr_t ucell_t; -#ifndef int32 - typedef long int32; -#endif +typedef ucell_t ExecToken; /* Execution Token */ +typedef cell_t ThrowCode; #ifdef __cplusplus extern "C" { #endif /* Main entry point to pForth. */ -int32 pfDoForth( const char *DicName, const char *SourceName, int32 IfInit ); +cell_t pfDoForth( const char *DicName, const char *SourceName, cell_t IfInit ); /* Turn off messages. */ -void pfSetQuiet( int32 IfQuiet ); +void pfSetQuiet( cell_t IfQuiet ); /* Query message status. */ -int32 pfQueryQuiet( void ); +cell_t pfQueryQuiet( void ); /* Send a message using low level I/O of pForth */ void pfMessage( const char *CString ); /* Create a task used to maintain context of execution. */ -PForthTask pfCreateTask( int32 UserStackDepth, int32 ReturnStackDepth ); +PForthTask pfCreateTask( cell_t UserStackDepth, cell_t ReturnStackDepth ); /* Establish this task as the current task. */ void pfSetCurrentTask( PForthTask task ); @@ -59,10 +60,10 @@ void pfSetCurrentTask( PForthTask task ); void pfDeleteTask( PForthTask task ); /* Build a dictionary with all the basic kernel words. */ -PForthDictionary pfBuildDictionary( int32 HeaderSize, int32 CodeSize ); +PForthDictionary pfBuildDictionary( cell_t HeaderSize, cell_t CodeSize ); /* Create an empty dictionary. */ -PForthDictionary pfCreateDictionary( int32 HeaderSize, int32 CodeSize ); +PForthDictionary pfCreateDictionary( cell_t HeaderSize, cell_t CodeSize ); /* Load dictionary from a file. */ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPtr ); diff --git a/fth/misc1.fth b/fth/misc1.fth index 29e8ede..1e36e55 100644 --- a/fth/misc1.fth +++ b/fth/misc1.fth @@ -18,7 +18,6 @@ decimal : >> rshift ; : << lshift ; -: CELL* ( n -- n*cell ) 2 lshift ; : (WARNING") ( flag $message -- ) swap diff --git a/fth/savedicd.fth b/fth/savedicd.fth index 8e465b3..290b01d 100644 --- a/fth/savedicd.fth +++ b/fth/savedicd.fth @@ -152,13 +152,13 @@ variable SDAD-BUFFER-FID c" IF_LITTLE_ENDIAN" IS.LITTLE.ENDIAN? IF 1 ELSE 0 THEN sdad.define ." Saving Names" cr - s" static const uint8 MinDicNames[] = {" sdad.type + s" static const uint8_t MinDicNames[] = {" sdad.type namebase headers-ptr @ SDAD_NAMES_EXTRA sdad.dump.data EOL sdad.emit c" };" $sdad.line ." Saving Code" cr - s" static const uint8 MinDicCode[] = {" sdad.type + s" static const uint8_t MinDicCode[] = {" sdad.type codebase here SDAD_CODE_EXTRA sdad.dump.data EOL sdad.emit c" };" $sdad.line diff --git a/fth/strings.fth b/fth/strings.fth index ff0fc91..8bead25 100644 --- a/fth/strings.fth +++ b/fth/strings.fth @@ -24,7 +24,7 @@ ANEW TASK-STRINGS.FTH 2+ * even-up allot DOES> ( index -- $addr ) dup @ ( get #chars ) - rot * + 4 + + rot * + cell+ ; \ Compare two strings diff --git a/fth/system.fth b/fth/system.fth index 01b779d..0223ab0 100644 --- a/fth/system.fth +++ b/fth/system.fth @@ -17,8 +17,8 @@ : \ ( -- , comment out rest of line ) EOL word drop ; immediate - -\ 1 echo ! \ Uncomment this line to echo Forth code while compiling. + +\ 1 echo ! \ Uncomment this line to echo Forth code while compiling. \ ********************************************************************* \ This is another style of comment that is common in Forth. @@ -48,13 +48,9 @@ 0 swap ! ; -\ size of data items -\ FIXME - move these into 'C' code for portability ???? -: CELL ( -- size_of_stack_item ) 4 ; - : CELL+ ( n -- n+cell ) cell + ; : CELL- ( n -- n+cell ) cell - ; -: CELLS ( n -- n*cell ) 2 lshift ; +: CELL* ( n -- n*cell ) cells ; : CHAR+ ( n -- n+size_of_char ) 1+ ; : CHARS ( n -- n*size_of_char , don't do anything) ; immediate @@ -174,7 +170,7 @@ ; : N>LINK ( nfa -- lfa ) - 8 - + 2 CELLS - ; : >BODY ( xt -- pfa ) @@ -358,7 +354,8 @@ ; : D2* ( d -- d*2 ) - 2* over 31 rshift or swap + 2* over + cell 8 * 1- rshift or swap 2* swap ; @@ -825,6 +822,6 @@ FREEZE \ prevent forgetting below this point .( Dictionary compiled, save in "pforth.dic".) cr c" pforth.dic" save-forth - + \ Save the dictionary in "pfdicdat.h" file so pForth can be compiled for standalone mode. SDAD diff --git a/releases.txt b/releases.txt index 59e7752..88fd68c 100644 --- a/releases.txt +++ b/releases.txt @@ -2,9 +2,9 @@ Release History for pForth - a Portable ANS-like Forth written in ANSI 'C' Documentation for pForth at http://www.softsynth.com/pforth/ -V?? - - Added -m32 to Makefile so we get 32 bit longs on Snow Leopard. - - Added "-x c" to Makefile CCOPTS to prevent confusion with C++ +V25 5/19/2010 + - Added 64-bit CELL support contributed by Aleksej Saushev. Thanks Aleksej! + - Added "-x c" to Makefile CCOPTS to prevent confusion with C++ - Allow space after -d command line option. - Restore normal tty mode if pForth dictionary loading fails. @@ -32,7 +32,7 @@ V22 (unreleased) - Fixed float evaluation in EVALUATE in "quit.fth". - Flush register cache for ffColon and ffSemiColon to prevent stack warnings from ; -V21 - 9/16/98 +V21 - 9/16/1998 - Fixed some compiler warnings. V20 @@ -57,7 +57,7 @@ V20 started with "-i" option. It used to always consider numeric input as HEX. Initial BASE is decimal. -V19 4/98 +V19 4/1998 - Warn if local var name matches dictionary, : foo { count -- } ; - TO -> and +-> now parse input stream. No longer use to-flag.