FROM THE U.S.A. call 901-313-4312
UK time is now:

VFX Forth – Common Features

 

  

VFX Forth logo

Last update: 9 April 2020
licence
downloads
shop and support

Features


Visit our papers page to download  our VFX Flier and benchmark code and results.

Click here for the VFX Forth v5 change history; or here for change notes for earlier versions.

Not all features presented on this page are available for VFX Forth for DOS.

VFX Forth v5


Most of the changes from v4 to v5 will make only small individual improvements, but overall increase reliability and standards conformance. As usual, the code was tested on an application of 1.2 million lines of Forth source, which required only minor changes, nearly all to its myriad string defining words.

The first major change improves standards compliance for parsing words such as string definers. The new arrangement allows these to be defined more clearly and the results are completely compliant with the ANS and Forth-2012 standards.

The second change allows the text interpreter to be changed more easily. In particular, new numeric literals are easy to install into the system. The new technique is called “recognisers” because each section in a chain “recognises” a particular data type.

The chassis is looking good.

VFX Code Generator


MPE’s VFX Forth for Windows has consistently proven itself to be the fastest Windows Forth available by a considerable margin. The benchmarks to prove it are on our web site. The v4 release includes many detailed changes to the code generator making v4 even faster than before with no increase in code size.

The VFX code generator generates native code with optimisation and inlining. Using mainstream compiler techniques the VFX optimiser can merge many Forth words and reduce memory access to a minimum. At its most elementary level the effect of the optimisation is impressive:

: n>char \ n -- char
  dup 9 >
  if 7 + endif
  [char] 0 +
; ok
dis n>char
N>CHAR
( 00463D44 83FB09 )       CMP EBX, 09
( 00463D47 0F8E03000000 ) JLE/NG 00463D50
( 00463D4D 83C307 )       ADD EBX, 07
( 00463D50 83C330 )       ADD EBX, 30
( 00463D53 )              RET
16 bytes ok

However, unlike other Forth code generators, VFX can optimise all data stack traffic to a mimum sequence. VFX Forth includes many standard techniques from compiler theory. The result is code generation that is within 25% of hand-written assembler sequences. A set of benchmarks and further papers on the VFX optimiser are available from our downloads page.

The user has control of the inlining level, so that trade-offs between speed and space can be investigated. The default levels are:

  NO INLINING
  NORMAL INLINING
  AGGRESSIVE INLINING
  ABSURD INLINING

The VFX code generator also tokenises many small definitions that are expanded during compilation, so removing not only the call/return overhead but also permitting the optimiser to operate across the call/return boundaries.

Even with all optimisation options enabled, VFX Forth compiles extremely quickly. Fast compilation speed and ease of testing provide a rapid, interactive, and productive compile-debug-fix cycle. Incremental compilation means that only new code needs to be compiled, leading to even shorter compilation times.

 

A set of application benchmarks follow.

 

******************************************
Core i7 3.4GHz, 8Gb RAM, Windows 7-64, SP1
******************************************

12 May 2012
===========
VFX        VFX Forth for Windows v4.60 [build 3332]
SF3        SwiftForth i386-Win32 3.4.2 11-Feb-2012
iForth	   version 4.0.400, generated December 31, 2010.
SP-Forth   Version 4.20 Build 001 at 21.Jan.2009
W32FS      Win32Forth-STC version: 0.05.01 build: 273
gff        gforth-fast 0.7.0

All with no specifics and no hackery

Test time including overhead (ms)         VFX  iForth     SF3    SPF4   W32FS     gff
DO LOOP                                     4       0       4       0      16       0
+                                           5       0       4       0       0       0
M+                                          4       0       5      15      16       0
*                                           5       0       5       0       0      16
/                                           7       0       3       0      15       0
M*                                          4       0       2       0       0       0
M/                                          4       0       3      16       0      15
/MOD                                        3       0       4       0       0       0
*/                                          4      16       4       0      16      16
ARRAY fill                                  2       0       9       0       0       0
=====================================================================================
Total:                                     42      16      43      31      63      47

Win32 API: SendMessage                      5       0       2       0       0       0
Win32 API: COUNTER                         36       0      20       0       0     218
System I/O: KEY?                            7       0     112     359     359     765
=====================================================================================
Total:                                     48       0     134     359     359     983

Eratosthenes sieve 1899 Primes             43      47      64      47     109     171
Fibonacci recursion ( 35 -> 9227465 )      44     109      43      62      47     234
Hoare's quick sort (reverse order)         38      47      80      47      93     203
Generate random numbers (1024 kb array)    55      62      78      63      78     172
LZ77 Comp. (400 kb Random Data Mem>Mem)    65      78     306      93     109     249
Dhrystone (integer)                        38      32      96      47      78     156
=====================================================================================
Total:                                    283     375     667     359     514    1105
Time (ratio to VFX):                     1.00    1.32    2.36    1.27    1.82    3.90

 

Users of threaded code systems should note that applications can be expected to run ten or more times faster, and that writing CODE definitions is unnecessary in VFX Forth.



GTK+ Cross Platform GUI


We have settled on GTK+ as a suitable cross-platform GUI library. Now that we have VFX Forth for Windows, Mac OS X and Linux, it was time to take the prototype Linux interface more seriously. At the
same time, we were being strongly urged by a client to give him back a graphics interface similar to his dearly beloved Borland BGI system from the old days of DOS. With a bit of effort, we found that it is possible to have portable graphics with a cross platform GUI.

GTK + Cross Platform GUI

The four pictures are from Windows, Mac OS X, x86 Linux and ARM Linux. All four were produced by compiling the same source code with no changes. The library interface file contains a small amount of conditional compilation for library file names, but that’s all that changes between operating systems.

The GUI is designed using the Glade GUI designer, which produces an XML description of the GUI. The XML description is loaded into the program by the Builder. The example code below shows a callback (an action needed when an event happens) and the code that produces the display.

2 0 CCBproc: on_about1_activate	\ *widget *user -- ; -- entry
\ *G Callback to run the About dialog.
  2drop  MainAbout runDlg drop
;

The code above produces a callback in the form needed by applications such as GTK that use a C calling convention. The name of the callback was also defined to Glade. A callback in the Builder associates the Glade name with a Forth callback name. In  this case, when the “Help -> About” button is clicked, the About  dialog is run.

: showGraphics3	\ --
\ *G Test word to read a Glade Builder XML file and run the
\ ** GUI it describes.
  initGTK  +gtimer			\ start GTK and timer

  z" gdemo3bld.ui" loadBuilderXML	\ load GTK builder design
  0= abort" Can't load builder file"
  z" window1" builderObject to window1	\ get handles
  z" drawingarea1" builderObject to DrawingArea1
  z" aboutdialog1" builderObject to MainAbout
  freeBuilder

  window1 gtk_widget_show_all		\ show design
  DrawingArea1 win2 initGWin		\ initialise graphics area
  win2 enable-graphics  win2 onto  dirty
  black cleardevice			\ drawing commands
  white  50 circle
  green  200 100 line
  red 30 30 at  70 30 filled rectangle
  80 70 at  100 40 blue filled ellipse
;

 

Operating system API and shared libraries


VFX Forth can make operating system API calls, as well as functions in DLLs and shared libraries. The function interface allows API calls to be defined by cut and paste from other language reference manuals.

Windows

EXTERN: int PASCAL CreateDialogIndirectParam( HINSTANCE, void *,HWND, WNDPROC, LPARAM );
EXTERN: int PASCAL SetWindowText( HANDLE, LPSTR );
EXTERN: HANDLE PASCAL GetDlgItem( HANDLE, int );

Mac OS X

Extern: char * ttyname( int fd );
Extern: int fstat( int fildes, void * buf );
Extern: int copyfile(
  const char * from, const char * to, void * state, int flags
);

Linux

Extern: int ioperm( unsigned long from, unsigned long num, int turn_on );
Extern: int iopl( int level );
Extern: void * mmap(
  void * start, size_t length, int prot, int flags, int fd, off_t offset
);

 

Operating System Constants


VFX Forth incorporates a support library that provides development-time access to thousands of operating system constants. Because the library is only used at development time, there is no impact on the size
of the application. At compile time these constants are treated  as literals and are fully optimised. The Windows version has over 28,000 named Windows constants. Source is provided to rebuild
the library

 

Local Variables


Interfacing to the operating system regularly requires the use of temporary buffers and variables. VFX Forth incorporates MPE’s extended local variable syntax as well as the default ANS syntax. Of course these are fully optimised by the VFX code generator. The following example is taken from a RichEdit
handler:

: DoContextMenu { hwnd posx posy | hmenu pt[ POINT ] -- }
  ...
;

This declares three named inputs (hwndposx and posy), a local variable (hmenu) and a local array
(pt[) of size POINT.

The following example is taken from and environment string handler. Var$ and Dest$ are named inputs and temp$[ is a local buffer.

: GetEnvVar	\ var$ dest$ --
\ *G Extract the environment variable *\i{var$} and place its
\ ** string value at *\i{dest$}. Both strings are counted strings, e.g.
\ *E  c" COMSPEC=" root-buff GetEnvVar
\ **  root-buff count type
  { var$ dest$ | temp$[ #256 ] -- }
  ...
;

 

Help systems


The help system allows you to type HELP name from the console to access the correct page of the PDF manual.  You can select which PDF viewer to use.

Just type LOCATE <name> and the source code for <name> is there on the screen for viewing or editing.

Source Management


The cross reference tool allows you to find out and display where words are used, and also to find out which words are unused for final code reduction. XREF <name> will tell you where the word is used, and XREF-UNUSED will tell you which words in your application have not been used.

Robust Exception Handling


VFX Forth uses the ANS Forth CATCH and  THROW mechanism for nested exception handling, but also integrates this with the operating system’s exception mechanism so that all exceptions can be handled by VFX Forth applications, and all information is available to the user for post-mortem analysis or error recovery.

INI file system


IniParser is a configuration file system that is source compatible between Linux, Mac OS X and Windows. The generated files are compatible with Window INI files. INI files can be generated and used by your applications. IniParser is the basis of the VFX Forth configuration system.

Examples and Libraries


VFX Forth comes with a wide range of application examples. Common to all versions are:

  • Floating point (3 types)
  • Serial communications
  • Socket-based communications
  • JACK Audio interface
  • Multi-tasking
  • State machines
  • Web server
  • Email sender
  • Internationalisation
  • File system interface
  • Binary overlays
  • benchmarks
  • … and much more

 

PowerNet


The PowerNet Echo, Telnet and Web servers have been ported to VFX Forth. These are multi-threaded servers. The Web server supports CGI and ASP, with Forth being used as the scripting language. SOAP, XML and Web Services are provided for direct interchange of information between VFX Forth and and any web service enabled product such as Excel and Project. The PowerNet shipped with VFX Forth is an enhancement of the code in the embedded verion, so see the PowerNet page for more details of PowerNet

PowerNet can be embedded inside your applications to provide fully Web enabled systems.

DocGen Documentation and Help Generator


Built into VFX Forth, the DocGen system can produce documentation for code while it is being compiled. DocGen processes formal comments in your source code, extracts them, and formats them into word processor files in HTML, PDF, TEX, Markdown or user definable formats. Now your source code can include an up-to-date manual for your project! The VFX Forth manual is itself built this way. The following example is part of the source code for selector chains.

: exec-chain? \ i*x n addr -- j*x true | n FALSE
\ *G Run through a given chain using TOS as a selector. If a match is
\ ** made execute the relevant code block and return TRUE otherwise
\ ** the initial selector and a FALSE flag is returned.
  ...
;

The result is the automatic generation of the glossary entry for this word in the manual. DocGen allows multiple files and sections, table of contents, titlepage generation, several levels of headings, special
facilities for examples, and a choice of public or internal release documentation.

Note that DocGen can work with any Forth source code files, not just those for VFX Forth for Windows, making it ideal for use with MPE’s Forth cross compilers.

A special version of DocGen has been developed for safety critical applications. DocGen/SC generates documentation to the US Food and Drug Administration requirements. For a client’s application, DocGen/SC generates over 1500 pages of documentation in PDF format from the project source code in under two minutes!

Internationalisation


The file Lib/International.fth permits full internationalisation of applications according to the ANS
draft standard for internationalisation.

You can define text messages to be internationalised. A simple set of hooks allow you to export text for translation and later reloading at run time.

The supplied code is based on techniques used in a major Forth application running all over the world.

Rapid Development


Conventional programming requires you to use an editor, language compiler, resource compiler, and finally a linker before even a small change can be tested. With VFX Forth, you just make your change using your favourite editor and recompile directly into executable form in seconds. You can drop code from your
editor directly into the VFX Forth console for immediate testing of any definition, or you can just type it at the keyboard.

VFX Forth includes all the tools you need to create bound turnkey applications.

System Resources Give You Full Control


VFX Forth for Windows provides a complete set of system resources and development tools to give you maximum control over your application. These include:

  • Turnkey application generator
  • Dynamic heap management
  • x86 assembler
  • x86 disassembler
  • Binary overlays

VFX Forth includes all tools required to compile, test and create bound versions of your applications for distribution.

Compatible with other MPE Products


The VFX Forth kernel is source-code compatible with MPE’s Forth 7 cross compilers, and compatibility for earlier versions of VFX Forth for Windows and other MPE Forths has been made simple.

Ordering


Go

  • Basic: Non-commercial use only. Free of charge.
  • Standard: Commercial use for one seat. Forum support.
  • Professional: Commercial use for up to three seats. Professional support with guaranteed response time.
  • Ultimate: Commercial use for up to ten seats. Ultimate support with guaranteed response time.
  • licence
    downloads
    support

    Support Services


    MPE has been supporting professional Forth users since 1981. We offer the following services:

    Advanced Technical Support

    • Ad-hoc on-site support
    • Forth Programming Courses
    • Custom Application Design
    • Programming Services

     

    Courses, Consultancy


    MPE can provide start up courses or consultancy using VFX Forth for Windows. The MPE course “Programming Windows with VFX Forth” is for VFX Forth, “Embedded Software for Hardware Engineers” covers cross compiling, and “Architectural Introduction to Forth” is a Forth conversion course. Contact MPE to find out more.

    Go to the pricelist page.

    Ordering


    Go here