More about SwiftForth…

 

Overview

Forth Implementation Features

Optimizing Compiler

Programming Tools

Debugging Tools

SWOOP Object-Oriented Programming

Libraries, Functions, Callbacks, and Threads

Windows Programming

SwiftForth Programming References

Release History

Download Free Evaluation Version


Mac and the Mac logo are trademarks of Apple Inc., registered in the U.S. and other countries.

Windows Programming

System messages

System messages are handled via a compiled switch mechanism, which can be easily extended to include any new messages that need to be handled. For example, this is the code to extend the standard existing Windows message handler SFMESSAGES to include keystroke events:

   [+SWITCH SFMESSAGES
      WM_SYSKEYDOWN     RUNS KDOWN1
      WM_KEYDOWN        RUNS KDOWN0
      WM_CHAR           RUNS CDOWN0
      WM_SYSCHAR        RUNS CDOWN1
    SWITCH]

Windows dialogs

Dialog boxes are supported via a simple dialog compiler, which parallels the Microsoft resource compiler. SwiftForth's console debugging tool can be used to trace the execution of Windows dialog box code.

Making DLLs and exporting functions

In SwiftForth, it is a simple matter to create Windows DLLs with exported functions. A DLL made from SwiftForth contains the entire system. Any program capable of calling DLL-based functions may import the exported functions.

DDE support

SwiftForth includes optional DDE client services, including a simple set of user words for sending or requesting data:

TELL sends a string to an item on the server and ASK gets an item from the server. For example:

   SERVER PROGMAN
   TOPIC PROGMAN
   ASK GROUPS

Menu definition and execution

Windows menus are simple to implement in SwiftForth

SwiftForth provides a simple means of defining menus and relating their items to Forth words. The mechanism provides for context-sensitive item execution by the user, and is easily extensible by simply defining a Forth name that directly corresponds to the menu text. For example, the "Hello World" demo in the figure shown here includes File and About menus, defined by:

    MENU HELLO-MENU
        POPUP "&File"
            MI_EXIT MENUITEM "E&xit"
        END-POPUP
       POPUP "&Help"
            MI_ABOUT MENUITEM "&About"
        END-POPUP
    END-MENU

Behaviors may be attached using extensible switch structures. The menu items MI_EXIT and MI_ABOUT defined in the above popups may be assigned behaviors like this:

    [SWITCH HELLO-COMMANDS ZERO
       MI_EXIT  RUN: ( -- res )   HELLO-CLOSE 0 ;
       MI_ABOUT RUN: ( -- res )   HELLO-ABOUT 0 ;
    SWITCH]

The code following the RUN: is an unnamed definition attached to the respective menu item. Predefined words may also be attached by replacing RUN: with RUNS <name>.

Exception handler

Windows exceptions, which are caught by the standard exception filter, are trapped, logged, and generate a simple Forth THROW which the user can capture and handle. Errors during callbacks are also caught and handled.