Fix REPOSITION-FILE, HISTORY, locked file handle and other problems.
authorphil@softsynth.com <phil@softsynth.com@b0a0988d-7f52-0410-8c73-4f6cdee1a2cf>
Mon, 23 Aug 2010 21:32:46 +0000 (21:32 +0000)
committerphil@softsynth.com <phil@softsynth.com@b0a0988d-7f52-0410-8c73-4f6cdee1a2cf>
Mon, 23 Aug 2010 21:32:46 +0000 (21:32 +0000)
build/unix/Makefile
csrc/pf_core.c
csrc/pf_guts.h
csrc/pf_inner.c
csrc/pf_save.c
csrc/pfcompil.c
fth/floats.fth
fth/history.fth
fth/system.fth
releases.txt

index de0b90f..8896f7c 100644 (file)
@@ -4,7 +4,7 @@
 # For more info visit http://www.softsynth.com/pforth/
 #
 # See "help" target below.
-\r
+
 .SUFFIXES: .c .o
 
 # Options include: PF_SUPPORT_FP PF_NO_MALLOC PF_NO_INIT PF_DEBUG
@@ -124,3 +124,5 @@ clean:
        rm -f $(PFDICDAT)
        rm -f $(PFORTHDIC)
        rm -f $(PFDICAPP)
+       rm -rf $(OBJECTDIR) $(TEMPOBJECTDIR)
+
index 41fa5f7..0564a65 100644 (file)
@@ -371,12 +371,11 @@ cell_t pfIncludeFile( const char *FileName )
        pfCopyMemory( &buffer[4], &FileName[len-numChars], numChars+1 );\r
        CreateDicEntryC( ID_NOOP, buffer, 0 );\r
        \r
-       Result = ffIncludeFile( fid );\r
+       Result = ffIncludeFile( fid ); /* Also close the file. */\r
        \r
 /* Create a dictionary word named ;;;; for FILE? */\r
        CreateDicEntryC( ID_NOOP, ";;;;", 0 );\r
        \r
-       sdCloseFile(fid);\r
        return Result;\r
 }\r
 \r
index 0666108..acb92a6 100644 (file)
@@ -23,7 +23,7 @@
 ** PFORTH_VERSION changes when PForth is modified and released.\r
 ** See README file for version info.\r
 */\r
-#define PFORTH_VERSION "26"\r
+#define PFORTH_VERSION "27"\r
 \r
 /*\r
 ** PFORTH_FILE_VERSION changes when incompatible changes are made\r
index 59ddfff..0149da0 100644 (file)
@@ -1289,9 +1289,8 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql ));
                        if( FileID )\r
                        {\r
                                SAVE_REGISTERS;\r
-                               Scratch = ffIncludeFile( FileID );\r
+                               Scratch = ffIncludeFile( FileID ); /* Also closes the file. */\r
                                LOAD_REGISTERS;\r
-                               sdCloseFile( FileID );\r
                                if( Scratch ) M_THROW(Scratch);\r
                        }\r
                        else\r
index 128b474..f3f9ac0 100644 (file)
@@ -343,6 +343,33 @@ error:
        return -1;\r
 }\r
 \r
+/* Convert dictionary info chunk between native and on-disk (big-endian). */\r
+static void\r
+convertDictionaryInfoWrite (DictionaryInfoChunk *sd)\r
+{\r
+/* Convert all fields in DictionaryInfoChunk from Native to BigEndian. \r
+ * This assumes they are all 32-bit integers.\r
+ */\r
+       int   i;\r
+       uint32_t *p = (uint32_t *) sd;\r
+       for (i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++)\r
+       {\r
+               Write32BigEndian( (uint8_t *)&p[i], p[i] );\r
+       }\r
+}\r
+\r
+static void\r
+convertDictionaryInfoRead (DictionaryInfoChunk *sd)\r
+{\r
+/* Convert all fields in structure from BigEndian to Native. */\r
+       int   i;\r
+       uint32_t *p = (uint32_t *) sd;\r
+       for (i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++)\r
+       {\r
+               p[i] = Read32BigEndian( (uint8_t *)&p[i] );\r
+       }\r
+}\r
+\r
 /****************************************************************\r
 ** Save Dictionary in File.\r
 ** If EntryPoint is NULL, save as development environment.\r
@@ -356,7 +383,6 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize,
        uint32_t NameChunkSize = 0;\r
        uint32_t CodeChunkSize;\r
        uint32_t relativeCodePtr;\r
-       int   i;\r
 \r
        fid = sdOpenFile( FileName, "wb" );\r
        if( fid == NULL )\r
@@ -445,16 +471,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize,
        SD.sd_CodeSize = CodeSize;\r
 \r
        \r
-/* Convert all fields in DictionaryInfoChunk from Native to BigEndian. \r
- * This assumes they are all 32-bit integers.\r
- */\r
-       {\r
-               uint32_t *p = (uint32_t *) &SD;\r
-               for( i=0; i<((int)(sizeof(SD)/sizeof(uint32_t))); i++ )\r
-               {\r
-                       Write32BigEndian( (uint8_t *)&p[i], p[i] );\r
-               }\r
-       }\r
+       convertDictionaryInfoWrite (&SD);\r
 \r
        if( WriteChunkToFile( fid, ID_P4DI, (char *) &SD, sizeof(DictionaryInfoChunk) ) < 0 ) goto error;\r
 \r
@@ -517,7 +534,6 @@ PForthDictionary pfLoadDictionary( const char *FileName, ExecToken *EntryPointPt
        uint32_t FormSize;\r
        uint32_t BytesLeft;\r
        uint32_t numr;\r
-       int   i;\r
        int   isDicBigEndian;\r
 \r
 DBUG(("pfLoadDictionary( %s )\n", FileName ));\r
@@ -568,15 +584,8 @@ DBUG(("pfLoadDictionary( %s )\n", FileName ));
                        if( numr != ChunkSize ) goto read_error;\r
                        BytesLeft -= ChunkSize;\r
                        \r
-/* Convert all fields in structure from BigEndian to Native. */\r
-                       {\r
-                               uint32_t *p = (uint32_t *) sd;\r
-                               for( i=0; i<((int)(sizeof(*sd)/sizeof(uint32_t))); i++ )\r
-                               {\r
-                                       p[i] = Read32BigEndian( (uint8_t *)&p[i] );\r
-                               }\r
-                       }\r
-                               \r
+                       convertDictionaryInfoRead (sd);\r
+\r
                        isDicBigEndian = sd->sd_Flags & SD_F_BIG_ENDIAN_DIC;\r
 \r
                        if( !gVarQuiet )\r
index dcb386f..84546c4 100644 (file)
@@ -927,7 +927,7 @@ ThrowCode ffOuterInterpreterLoop( void )
 }\r
 \r
 /***************************************************************\r
-** Include a file\r
+** Include then close a file\r
 ***************************************************************/\r
 \r
 ThrowCode ffIncludeFile( FileStream *InputFile )\r
@@ -963,6 +963,9 @@ ThrowCode ffIncludeFile( FileStream *InputFile )
 /* Pop file stream. */\r
        ffPopInputStream();\r
        \r
+/* ANSI spec specifies that this should also close the file. */\r
+       sdCloseFile(InputFile);\r
+\r
        return exception;\r
 }\r
 \r
index cb77770..9196575 100644 (file)
@@ -406,16 +406,21 @@ false fp-require-e !   \ violate ANSI !!
                        c-addr c@ [char] E =\r
                        c-addr c@ [char] e =  OR\r
                        IF\r
-                               1 +-> c-addr   -1 +-> u'   \ skip char\r
-                               c-addr c@ [char] + = \ ignore + on exponent\r
+                               1 +-> c-addr   -1 +-> u'   \ skip E char
+                               u' 0>
                                IF\r
-                                       1 +-> c-addr   -1 +-> u'   \ skip char\r
-                               THEN\r
-                               c-addr u' ((number?))\r
-                               num_type_single =\r
-                               IF\r
-                                       nshift + -> nshift\r
-                                       true -> flag\r
+                               c-addr c@ [char] + = \ ignore + on exponent
+                               IF\r
+                        1 +-> c-addr   -1 +-> u'   \ skip char\r
+                    THEN\r
+                                   c-addr u' ((number?))\r
+                                   num_type_single =\r
+                                   IF\r
+                                          nshift + -> nshift\r
+                                          true -> flag\r
+                                   THEN
+                               ELSE
+                                   true -> flag   \ allow "1E"
                                THEN\r
                        THEN\r
                ELSE\r
index 5e5409e..574d6a6 100644 (file)
@@ -50,6 +50,8 @@ KH-HISTORY kh_history_size erase
 \\r
 \ The most recent entry is put at the beginning,\r
 \ older entries are shifted up.\r
+
+4 constant KH_LINE_EXTRA_SIZE ( 2 count bytes plus 2 size bytes )
 \r
 : KH-END ( -- addr , end of history buffer )\r
        kh-history kh_history_size +\r
@@ -131,8 +133,10 @@ variable KH-INSIDE        ( true if we are scrolling inside the history buffer )
                ELSE\r
                        >r ( save count )\r
 \ Set look pointer to point to first count byte of last string.\r
-                       0 kh-look !\r
-                       r@ cell+ kh.make.room\r
+                       0 kh-look !
+\ Make room for this line of text and line header. 
+\ PLB20100823 Was cell+ which broke on 64-bit code.\r
+                       r@ KH_LINE_EXTRA_SIZE + kh.make.room\r
 \ Set count bytes at beginning and end.\r
                        r@ kh-history c!  ( start count )\r
                        r@ kh.endcount.addr c!\r
index 0223ab0..b9c46f3 100644 (file)
@@ -738,16 +738,14 @@ variable TRACE-INCLUDE
                 drop ." Could not find file " $type cr abort\r
         ELSE ( -- $filename good-fid )\r
                 swap include.mark.start\r
-                dup >r   \ save fid for close-file\r
                 depth >r\r
-                include-file\r
+                include-file    \ will also close the file\r
                 depth 1+ r> -\r
                 IF\r
                         ." Warning: stack depth changed during include!" cr\r
                         .s cr\r
                         0sp\r
                 THEN\r
-                r> close-file drop\r
                 include.mark.end\r
         THEN\r
         trace-include @\r
index 62f3502..4830690 100644 (file)
@@ -2,9 +2,14 @@ Release History for pForth - a Portable ANS-like Forth written in ANSI 'C'
 \r
 Documentation for pForth at http://www.softsynth.com/pforth/\r
 
-V??
+V27
     - Fixed REPOSITION-FILE FILE-SIZE and FILE-POSITION.
       They used to use single precision offset. Now use double as specified.
+    - Delete object directories in Makefile clean.
+    - Fixed "Issue 4: Filehandle remains locked upon INCLUDE error".
+      http://code.google.com/p/pforth/issues/detail?id=4&can=1
+    - Fixed scambled HISTORY on 64-bit systems. Was using CELL+ but really needed 4 +.
+    - Fixed floating point input. Now accepts "1E" as 1.0. Was Issue #2.
 \r
 V26  5/20/2010
     - 64-bit support for M* UM/MOD etc by Aleksej Saushev. Thanks Aleksej!