From 2bfdc82f9e73c8393d2853968db5b0b82e7537d5 Mon Sep 17 00:00:00 2001 From: Alexey Vyskubov Date: Sat, 31 Jan 2015 00:33:09 +0200 Subject: [PATCH 1/3] allow Read32FromFile to return signed value --- csrc/pf_save.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csrc/pf_save.c b/csrc/pf_save.c index d46958a..80b4c1e 100644 --- a/csrc/pf_save.c +++ b/csrc/pf_save.c @@ -513,7 +513,7 @@ cell_t ffSaveForth( const char *FileName, ExecToken EntryPoint, cell_t NameSize, #ifndef PF_NO_FILEIO /***************************************************************/ -static uint32_t Read32FromFile( FileStream *fid, uint32_t *ValPtr ) +static int32_t Read32FromFile( FileStream *fid, uint32_t *ValPtr ) { int32_t numr; uint8_t pad[4]; From 5e1c6644bbd1a696fb02ee26a2ad8c359e81e57f Mon Sep 17 00:00:00 2001 From: Hannu Vuolasaho Date: Sat, 21 Feb 2015 02:37:25 +0200 Subject: [PATCH 2/3] Makefile fix for Linux compilation Simple fix to compile with GCC 4.9.2 on Arch Linux --- build/unix/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/unix/Makefile b/build/unix/Makefile index c3e2156..c1df0d0 100644 --- a/build/unix/Makefile +++ b/build/unix/Makefile @@ -24,7 +24,7 @@ PFORTHAPP = pforth_standalone WIDTHOPT= FULL_WARNINGS = \ - -c89 \ + --std=c89 \ -fsigned-char \ -fno-builtin \ -fno-unroll-loops \ @@ -59,7 +59,7 @@ PFSOURCE = $(PFBASESOURCE) $(IO_SOURCE) VPATH = .:$(CSRCDIR):$(CSRCDIR)/posix:$(CSRCDIR)/stdio:$(CSRCDIR)/win32_console:$(CSRCDIR)/win32 XCFLAGS = $(CCOPTS) -XCPPFLAGS = -DPF_SUPPORT_FP +XCPPFLAGS = -DPF_SUPPORT_FP -D_DEFAULT_SOURCE XLDFLAGS = $(WIDTHOPT) CPPFLAGS = -I. $(XCPPFLAGS) From 259625078859cb06e6cf02ddb5567c8a130d3821 Mon Sep 17 00:00:00 2001 From: Hannu Vuolasaho Date: Sat, 21 Feb 2015 03:44:05 +0200 Subject: [PATCH 3/3] Sample crossbuild makefile Crossbuild Makefile for building win32 without floating point support --- build/mingw-crossbuild-linux/Makefile | 149 +++++++++++++++++++++++ csrc/win32_console/pf_io_win32_console.c | 12 +- 2 files changed, 155 insertions(+), 6 deletions(-) create mode 100644 build/mingw-crossbuild-linux/Makefile diff --git a/build/mingw-crossbuild-linux/Makefile b/build/mingw-crossbuild-linux/Makefile new file mode 100644 index 0000000..f6f8d68 --- /dev/null +++ b/build/mingw-crossbuild-linux/Makefile @@ -0,0 +1,149 @@ +# makefile for pForth +# Portable Forth written in 'C' +# by Phil Burk +# For more info visit http://www.softsynth.com/pforth/ +# +# See "help" target below. + +.POSIX: + +# Options include: PF_SUPPORT_FP PF_NO_MALLOC PF_NO_INIT PF_DEBUG +# See "docs/pf_ref.htm" file for more info. + +CC = x86_64-w64-mingw32-gcc +WINE = wineconsole +SRCDIR = ../.. +PFORTHDIR = $(SRCDIR) +CSRCDIR = $(PFORTHDIR)/csrc +FTHDIR = $(PFORTHDIR)/fth + +PFDICAPP = pforth.exe +PFORTHDIC = pforth.dic +PFDICDAT = pfdicdat.h +PFORTHAPP = pforth_standalone.exe + +# This is needed to get pForth to build on Snow Leopard and other 64 bit platforms. +WIDTHOPT= + +FULL_WARNINGS = \ + --std=c89 \ + -fsigned-char \ + -fno-builtin \ + -fno-unroll-loops \ + -fpeephole \ + -fno-keep-inline-functions \ + -pedantic \ + -Wcast-qual \ + -Wall \ + -Wwrite-strings \ + -Winline \ + -Wmissing-prototypes \ + -Wmissing-declarations + +DEBUGOPTS = -g +CCOPTS = $(WIDTHOPT) -x c -O2 $(FULL_WARNINGS) $(EXTRA_CCOPTS) $(DEBUGOPTS) + +#IO_SOURCE = pf_io_posix.c +#IO_SOURCE = pf_io_stdio.c +IO_SOURCE = pf_io_win32_console.c + +EMBCCOPTS = -DPF_STATIC_DIC + +####################################### +PFINCLUDES = pf_all.h pf_cglue.h pf_clib.h pf_core.h pf_float.h \ + pf_guts.h pf_host.h pf_inc1.h pf_io.h pf_mem.h pf_save.h \ + pf_text.h pf_types.h pf_win32.h pf_words.h pfcompfp.h \ + pfcompil.h pfdicdat_arm.h pfinnrfp.h pforth.h +PFBASESOURCE = pf_cglue.c pf_clib.c pf_core.c pf_inner.c \ + pf_io.c pf_io_none.c pf_main.c pf_mem.c pf_save.c \ + pf_text.c pf_words.c pfcompil.c pfcustom.c +PFSOURCE = $(PFBASESOURCE) $(IO_SOURCE) + +VPATH = .:$(CSRCDIR):$(CSRCDIR)/posix:$(CSRCDIR)/stdio:$(CSRCDIR)/win32_console:$(CSRCDIR)/win32 + +XCFLAGS = $(CCOPTS) +#XCPPFLAGS = -DPF_SUPPORT_FP -DWIN32 +XCPPFLAGS = -DWIN32 +XLDFLAGS = $(WIDTHOPT) + +CPPFLAGS = -I. $(XCPPFLAGS) +CFLAGS = $(XCFLAGS) +LDFLAGS = $(XLDFLAGS) + +COMPILE = $(CC) $(CFLAGS) $(CPPFLAGS) +LINK = $(CC) $(LDFLAGS) + +.SUFFIXES: .c .o .eo + +PFOBJS = $(PFSOURCE:.c=.o) +PFEMBOBJS = $(PFSOURCE:.c=.eo) + +.c.o: $(PFINCLUDES) + $(COMPILE) -c -o $@ $< + +.c.eo: $(PFINCLUDES) pfdicdat.h + $(COMPILE) $(EMBCCOPTS) -c -o $@ $< + +.PHONY: all clean test +.PHONY: help pffiles pfdicapp pfdicdat pforthapp + +all: $(PFORTHAPP) + +pffiles: + @echo "INCLUDE FILES -----------------" + @echo ${PFINCLUDES} + @echo "'C' FILES ---------------------" + @echo ${PFSOURCE} + @echo "OBJECT FILES ------------------" + @echo ${PFOBJS} + @echo "EMBEDDED OBJECT FILES ------------------" + @echo ${PFEMBOBJS} + +# Build pforth by compiling 'C' source. +$(PFDICAPP): $(PFINCLUDES) $(PFOBJS) + $(LINK) -o $@ $(PFOBJS) $(LDADD) -lm + +# Build basic dictionary image by running newly built pforth and including "system.fth". +$(PFORTHDIC): $(PFDICAPP) + wd=$$(pwd); (cd $(FTHDIR); $(WINE) $${wd}/$(PFDICAPP) -i system.fth) + (cd $(FTHDIR); cat pforth.dic; rm -f pforth.dic) > $@ + +$(PFDICDAT): $(PFORTHDIC) $(PFDICAPP) + echo 'include $(FTHDIR)/savedicd.fth SDAD BYE'>load-dict-tmp.fth&& $(WINE) ./$(PFDICAPP) -d $(PFORTHDIC) load-dict-tmp.fth; rm -f load-dict-tmp.fth + +$(PFORTHAPP): $(PFDICDAT) $(PFEMBOBJS) + $(LINK) -o $@ $(PFEMBOBJS) $(LDADD) -lm + @echo "" + @echo "Standalone pForth executable written to $(PFORTHAPP)" + + +# target aliases +pfdicapp: $(PFDICAPP) + +pfdicdat: $(PFDICDAT) + +pforthapp: $(PFORTHAPP) + +help: + @echo "Use 'make all' to build standalone pForth executable." + @echo "PForth can be built in several stages using these targets:" + @echo " pfdicapp = executable pForth with minimal dictionary. All from 'C'." + @echo " pfdicdat = image of full dictionary build by compiling Forth code." + @echo " pforthapp = executable with embedded dictionary image. DEFAULT 'all' target." + @echo "" + @echo " The file 'fth/pfdicdat.h' is generated by pForth. It contains a binary image of the Forth dictionary." + @echo " It allows pForth to work as a standalone image that does not need to load a dictionary file." + +test: $(PFORTHAPP) + wd=$$(pwd); (cd $(FTHDIR); $(WINE) $${wd}/$(PFORTHAPP) -q t_corex.fth) + wd=$$(pwd); (cd $(FTHDIR); $(WINE) $${wd}/$(PFORTHAPP) -q t_strings.fth) + wd=$$(pwd); (cd $(FTHDIR); $(WINE) $${wd}/$(PFORTHAPP) -q t_locals.fth) + wd=$$(pwd); (cd $(FTHDIR); $(WINE) $${wd}/$(PFORTHAPP) -q t_alloc.fth) + wd=$$(pwd); (cd $(FTHDIR); $(WINE) $${wd}/$(PFORTHAPP) -q t_floats.fth) + +clean: + rm -f $(PFOBJS) $(PFEMBOBJS) + rm -f $(PFORTHAPP) + rm -f $(PFDICDAT) $(FTHDIR)/$(PFDICDAT) + rm -f $(PFORTHDIC) $(FTHDIR)/$(PFORTHDIC) + rm -f $(PFDICAPP) diff --git a/csrc/win32_console/pf_io_win32_console.c b/csrc/win32_console/pf_io_win32_console.c index d36a04c..a081812 100644 --- a/csrc/win32_console/pf_io_win32_console.c +++ b/csrc/win32_console/pf_io_win32_console.c @@ -33,7 +33,7 @@ typedef enum ConsoleState_e { SDCONSOLE_STATE_IDLE = 0, SDCONSOLE_STATE_GOT_ESCAPE, - SDCONSOLE_STATE_GOT_BRACKET, + SDCONSOLE_STATE_GOT_BRACKET } ConsoleState; @@ -44,8 +44,8 @@ static CONSOLE_SCREEN_BUFFER_INFO sScreenInfo; /******************************************************************/ static void sdConsoleEmit( char c ) { - // Write a WCHAR in case we have compiled with Unicode support. - // Otherwise we will see '?' printed. + /* Write a WCHAR in case we have compiled with Unicode support. + * Otherwise we will see '?' printed.*/ WCHAR wc = (WCHAR) c; DWORD count; if( sIsConsoleValid ) @@ -54,7 +54,7 @@ static void sdConsoleEmit( char c ) } else { - // This will get called if we are redirecting to a file. + /* This will get called if we are redirecting to a file.*/ WriteFile(sConsoleHandle, &c, 1, &count, NULL ); } } @@ -215,12 +215,12 @@ void sdTerminalInit( void ) sConsoleHandle = GetStdHandle( STD_OUTPUT_HANDLE ); if( GetConsoleMode( sConsoleHandle, &mode ) ) { - //printf("GetConsoleMode() mode is 0x%08X\n", mode ); + /*printf("GetConsoleMode() mode is 0x%08X\n", mode );*/ sIsConsoleValid = TRUE; } else { - //printf("GetConsoleMode() failed\n", mode ); + /*printf("GetConsoleMode() failed\n", mode );*/ sIsConsoleValid = FALSE; } }