The MSVC x86_64 compiler defines long as 32-bits.
This means '1L' is 32-bits and a 62 bit shift on a 32-bit
value is UB which resulted in a 0 for the FP_DHI1 value.
letoh [Mon, 12 Mar 2018 14:25:58 +0000 (22:25 +0800)]
Fixes #40: add _DEFAULT_SOURCE back for Linux build
This commit fixes the improper patch in the pull request #7.
When building pforth on the Linux system with glibc version before
2.19, defining _GNU_SOURCE is needed for using ECHOCTL in the
source. However, the later version of glibc uses _DEFAULT_SOURCE
instead of _GNU_SOURCE for the same purpose, we will need both symbols
for both older glibc and newer glibc.
Helmut Eller [Sun, 8 Jan 2017 20:27:28 +0000 (21:27 +0100)]
This introduces a RESIZE-FILE-LIMIT
The intention is to protect the user from a presumably common mistake:
passing the size as single cell number instead of a double cell
number. This would create a very big file that is written in many
small chunks.
I also changed sdResizeFile to use uint64_t instead of Lo/Hi pairs.
* csrc/pfcompil.c (pfBuildDictionary): Rename RESIZE-FILE
to (RESIZE-FILE).
* fth/file.fth (RESIZE-FILE-LIMIT): New variable.
(RESIZE-FILE): Use it.
* fth/system.fth (D<, D>): Implemented. Needed for compare the limit.
* csrc/pf_io.h, csrc/pf_io.c (sdResizeFile): Use uint64_t.
* csrc/stdio/pf_fileio_stdio.c (sdResizeFile): Use uint64_t.
(IsGreaterThanLongMax): Deleted.
* csrc/pf_inner.c (ID_FILE_RESIZE): Convert the Lo/Hi pair to uint64_t.
(UdToUint64, UdIsUint64): New helpers.
Helmut Eller [Wed, 4 Jan 2017 10:11:14 +0000 (11:11 +0100)]
Implement REQUIRE (Forth 2012)
This turned out to be simpler than I had thought, as we can use the
::::<filename> marker to detected already included files.
* fth/require.fth: New file
* fth/loadp4th.fth: Load it. As REQUIRE uses FINDNFA.FROM, the
file filefind.fth is no longer optional.
* fth/system.fth (INCLUDE.MARK.START): Allocate a temporary buffer for
the string. PAD was problematic because the interpreter versions of
S" and C" also write to PAD, so something like C" foo.fth" $INCLUDE
would created the marker "::::::::". Despite that, no standard words
should write to PAD. Of course, neither S" and C" should use PAD.
That's a problem for another day.
* fth/t_file.fth: Restore tests for REQUIRE.
* fth/t_required-helper1.fth, fth/t_required-helper2.fth: Files needed
for tests.
Helmut Eller [Tue, 3 Jan 2017 21:13:53 +0000 (22:13 +0100)]
Implement FILE-STATUS
This implements FILE-STATUS on top of OPEN-FILE: FILE-STATUS succeeds
if we can open the file in read-only mode. This way we avoid adding
yet another primitive.
* fth/file.fth (FILE-STATUS): New
* fth/t_file.fth (FILE-STATUS): Delete stub
Helmut Eller [Tue, 3 Jan 2017 09:31:36 +0000 (10:31 +0100)]
Implement RESIZE-FILE
On Unix, the easiest way to implement RESIZE-FILE would be to call
ftruncate, but in ANSI C alone it's quite difficult. As this takes a
bit more code, I created a new file pf_fileio_stdio.c and moved it
there. The idea is that somebody could replace that with say a
pf_fileio_posix.c and use ftruncate there.
Because there's a new file I had to change the Makefiles. I did not
fix the VisualStudio project file, as I don't know how to do that.
Helmut Eller [Mon, 2 Jan 2017 18:28:25 +0000 (19:28 +0100)]
Implement RENAME-FILE
This introduces a primitive (RENAME-FILE) which takes C-strings as
arguments. The conversion from Forth-strings to C-strings is done in
Forth code as it doesn't seem to be any easier to do it in C.
* csrc/pf_io.h (sdRenameFile): New. It has the same semantics as
rename(2) from <stdio.h>
Helmut Eller [Sun, 1 Jan 2017 22:09:26 +0000 (23:09 +0100)]
Some changes based on feedback.
* fth/file.fth: Clearer license statement.
(\N, \R, SKIP-\N): Upcase properly.
(READ-LINE): Use 0<> instead of 0< for the (unlikely) case that
we have large unsigned numbers with the highest bit set.
Also, skip-\n can overwrite the \r that we just detected.
* fth/t_file.fth: Add tests with buffers that are shorter and exaclty
as long as the line.
Helmut Eller [Sun, 1 Jan 2017 11:12:08 +0000 (12:12 +0100)]
Implement READ-LINE and WRITE-LINE
This is implemented on top of READ-FILE and WRITE-FILE which avoids
new dependencies in the C code.
* fth/file.fth: New file.
* fth/loadp4th.fth: Load it.
* fth/t_file.fth: New tests. Some tests fail and some are commented
out due to missing functionality. There's an actual bug in SAVE-INPUT
which I know how to fix.
* build/unix/Makefile, build/mingw-crossbuild-linux/Makefile (test):
Run test in t_file.fth.
Helmut Eller [Tue, 27 Dec 2016 08:42:45 +0000 (09:42 +0100)]
Implement SAVE-INPUT and RESTORE-INPUT
There used to be primitive tokens ID_SAVE_INPUT and ID_RESTORE_INPUT
but those weren't used. Saving/restoring positions in files is
somewhat involved so I decided to it in Forth. To support this, I
re-purposed the codes of ID_SAVE_INPUT and ID_RESTORE_INPUT to
save/store the current line number (ID_SOURCE_LINE_NUMBER_FETCH, and
ID_SOURCE_LINE_NUMBER_STORE). Those can also be used for something
like C's __LINE__ macro.
* fth/save-input.fth: New file.
* fth/loadp4th.fth: Load it.
* fth/system.fth (D=): New. Needed to compare file positions.
* fth/t_corex.fth: Add simple tests.
* csrc/pf_guts.h (ID_SOURCE_LINE_NUMBER_FETCH,
ID_SOURCE_LINE_NUMBER_STORE): Renamed from ID_SAVE_INPUT and
ID_RESTORE_INPUT.
* csrc/pf_inner.c (ID_SOURCE_LINE_NUMBER_FETCH,
ID_SOURCE_LINE_NUMBER_STORE): Implement.
(ID_SAVE_INPUT): Deleted. It's now in Forth.
* csrc/pfcompil.c (pfBuildDictionary): Define SOURCE-LINE-NUMBER@ and
SOURCE-LINE-NUMBER!.
Helmut Eller [Wed, 21 Dec 2016 19:45:50 +0000 (20:45 +0100)]
Use C version of LWORD in INTERPRET
* csrc/pf_words.c (ffLWord): New.
(Word): Factored out from ffWord.
(ffWord): Call Word.
* csrc/pfcompil.c (ffInterpret): Use ffLWord instead of ffWord to
preserve case for NUMBER?. Can't use ffWord because that would
convert a character written as "'a'" to "'A'".
Helmut Eller [Sun, 18 Dec 2016 10:57:03 +0000 (11:57 +0100)]
Implememnt standard word INCLUDED
* fth/system.fth (INCLUDED): Rewrite existing $INCLUDE to use addr+len strings.
($INCLUDE): Call INCLUDED.
(INCLUDE.MARK.START): Also take addr+len string as argument.
Helmut Eller [Mon, 12 Dec 2016 15:59:25 +0000 (16:59 +0100)]
Add Makefile to cross-compile from Linux to Amiga
This Makefile can be used to cross-compile pForth on a Linux host to
an Amiga target. GCC is used as host-compiler and VBCC as
cross-compiler.
* build/linux-crossbuild-amiga/Makefile: New file.
* csrc/pf_io.c, csrc/pf_inner.c: Add some quirks to satisfy VBCC. In
particular fseek and ftell needed some help.