X-Git-Url: http://git.subgeniuskitty.com/pforth/.git/blobdiff_plain/ccd2b2a1dc0b1d207fb738593845e9be8b6e1d80..49295627b371a3479ded25c6bf32ad139652ecfd:/csrc/pf_inner.c diff --git a/csrc/pf_inner.c b/csrc/pf_inner.c index 606dc5c..57559bd 100644 --- a/csrc/pf_inner.c +++ b/csrc/pf_inner.c @@ -197,8 +197,8 @@ static void TraceNames( ExecToken Token, cell_t Level ) static uint64_t UdToUint64( ucell_t Lo, ucell_t Hi ) { return (( 2 * sizeof(ucell_t) == sizeof(uint64_t) ) - ? (((uint64_t)Lo) | (((uint64_t)Hi) >> (sizeof(ucell_t) * 8))) - : Lo ); + ? (((uint64_t)Lo) | (((uint64_t)Hi) >> (sizeof(ucell_t) * 8))) + : Lo); } /* Return TRUE if the unsigned double cell integer LO/HI is not greater @@ -207,15 +207,15 @@ static uint64_t UdToUint64( ucell_t Lo, ucell_t Hi ) static int UdIsUint64( ucell_t Lo, ucell_t Hi ) { return (( 2 * sizeof(ucell_t) == sizeof(uint64_t) ) - ? TRUE - : Hi == 0 ); + ? TRUE + : Hi == 0); } -static const char *pfSelectFileModeCreate( int fam ); -static const char *pfSelectFileModeOpen( int fam ); +static const char *pfSelectFileModeCreate(cell_t fam ); +static const char *pfSelectFileModeOpen(cell_t fam ); /**************************************************************/ -static const char *pfSelectFileModeCreate( int fam ) +static const char *pfSelectFileModeCreate( cell_t fam ) { const char *famText = NULL; switch( fam ) @@ -240,7 +240,7 @@ static const char *pfSelectFileModeCreate( int fam ) } /**************************************************************/ -static const char *pfSelectFileModeOpen( int fam ) +static const char *pfSelectFileModeOpen( cell_t fam ) { const char *famText = NULL; switch( fam ) @@ -269,7 +269,7 @@ static const char *pfSelectFileModeOpen( int fam ) } /**************************************************************/ -int pfCatch( ExecToken XT ) +ThrowCode pfCatch( ExecToken XT ) { register cell_t TopOfStack; /* Cache for faster execution. */ register cell_t *DataStackPtr; @@ -502,6 +502,7 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); endcase; case ID_BYE: + EMIT_CR; M_THROW( THROW_BYE ); endcase; @@ -744,8 +745,8 @@ DBUGX(("After Branch: IP = 0x%x\n", InsPtr )); /* Calculate product sign: */ sg = ((cell_t)(ahi ^ bhi) < 0); /* Take absolute values and reduce to um* */ - if ((cell_t)ahi < 0) ahi = (ucell_t)(-ahi); - if ((cell_t)bhi < 0) bhi = (ucell_t)(-bhi); + if ((cell_t)ahi < 0) ahi = (ucell_t)(-(cell_t)ahi); + if ((cell_t)bhi < 0) bhi = (ucell_t)(-(cell_t)bhi); /* Break into hi and lo 16 bit parts. */ alo = LOWER_HALF(ahi); @@ -1029,25 +1030,38 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); Scratch = M_POP; CharPtr = (char *) M_POP; Temp = sdReadFile( CharPtr, 1, Scratch, FileID ); + /* TODO check feof() or ferror() */ M_PUSH(Temp); TOS = 0; endcase; + /* TODO Why does this crash when passed an illegal FID? */ case ID_FILE_SIZE: /* ( fid -- ud ior ) */ /* Determine file size by seeking to end and returning position. */ FileID = (FileStream *) TOS; { - file_offset_t endposition, offsetHi; + file_offset_t endposition = -1; file_offset_t original = sdTellFile( FileID ); - sdSeekFile( FileID, 0, PF_SEEK_END ); - endposition = sdTellFile( FileID ); - M_PUSH(endposition); - /* Just use a 0 if they are the same size. */ - offsetHi = (sizeof(file_offset_t) > sizeof(cell_t)) - ? (endposition >> (8*sizeof(cell_t))) : 0 ; - M_PUSH(offsetHi); - sdSeekFile( FileID, original, PF_SEEK_SET ); - TOS = (original < 0) ? -4 : 0 ; /* !!! err num */ + if (original >= 0) + { + sdSeekFile( FileID, 0, PF_SEEK_END ); + endposition = sdTellFile( FileID ); + /* Restore original position. */ + sdSeekFile( FileID, original, PF_SEEK_SET ); + } + if (endposition < 0) + { + M_PUSH(0); /* low */ + M_PUSH(0); /* high */ + TOS = -4; /* TODO proper error number */ + } + else + { + M_PUSH(endposition); /* low */ + /* We do not support double precision file offsets.*/ + M_PUSH(0); /* high */ + TOS = 0; /* OK */ + } } endcase; @@ -1075,7 +1089,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); TOS = -3; /* TODO err num? */ break; } - offset = offsetLow; + offset = (file_offset_t)offsetLow; TOS = sdSeekFile( FileID, offset, PF_SEEK_SET ); } endcase; @@ -1096,7 +1110,7 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); M_PUSH(position); /* low */ /* We do not support double precision file offsets.*/ M_PUSH(0); /* high */ - TOS = 0; + TOS = 0; /* OK */ } } endcase;