«previous next»

SWIFTFORTH DETAILS

Overview

Windows Interface (a)

Windows Interface (b)

Windows Interface (c)

Programming Aids & Features (a)

Programming Aids & Features (b)

Programming Aids & Features (c)

Object-Oriented Programming (SWOOP)

Forth Implementation Features (a)

Forth Implementation Features (b)

Multitasking

Demo Programs

SwiftForth Programming References

Release History

Download Free Evaluation Version


Windows Interface

Because SwiftForth was designed from the outset as a Windows system, great care has been given to make the interface to Windows as clean and easy-to-use as possible, given the inherent complexity of the Windows environment.

Easy access to Win32 functions via DLLs

System functions in Windows are provided to an application program via the DLL mechanism. SwiftForth supports a simple DLL function import mechanism that resembles the C function prototype. All of the Windows functions are made available in this manner. As an example of this facility, the file Sendmail.f provides an ability to e-mail a file via the Internet using direct calls to WINSOCK functions; the whole file is only 205 lines, including comments.

To link to a previously unattached DLL, all you have to do is:

    LIBRARY: <name.dll>

Any functions in any linked DLL may be made available as Forth words using:

    <n> IMPORT: <name>

…where n is the number of parameters it takes and name is the (case-sensitive) published function name. Parameters are provided on the stack in the order described in function documentation (not reverse order, as required by some Windows Forths). Many commonly used functions are already defined.

Both C-prototype and Pascal-prototype DLLs may be called. Importing SwiftForth-based DLLs bypasses the overhead associated with the creation and destruction of the stack frame required for C-based DLLs. Functions with identical names from separate DLLs may be invoked without name collision via an internal-alias mechanism. In addition, a "lazy" loading option postpones the instantiation of the DLL files until they are needed. Lists of currently attached DLLs and their imports may be displayed at any time.

Windows programmers have toolbar access to common functions.

Making DLLs and exporting functions

In SwiftForth, it is a simple matter to create 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.

(In order to comply with FORTH, Inc. licensing policies, you may not export any access to SwiftForth development tools, including the compiler and assembler, without making appropriate arrangements with FORTH, Inc.)

For example, suppose you have defined:

    : SQRT ( n1 -- n2 ) ... ;   \ n2 is the square root of n1

To could export this function, simply execute the following:

    1 EXPORT: SQRT

…where 1 indicates that the exported function will require one parameter when it is used. To expand the functionality of the new DLL, you could export other related functions:

    AS Add           2 EXPORT: +
    AS Subtract      2 EXPORT: -
    AS Multiply      2 EXPORT: *
    AS Divide        2 EXPORT: /

The above lines provide exports and assign aliases (or "pseudonyms") to be used by the calling program when invoking each of the functions. This can be useful both to improve readability and to avoid duplicating function names. When all the desired exports have been defined, create the DLL:
PROGRAM CALCULATOR.DLL

Then, to import the new DLL's functions into SwiftForth, for example,
LIBRARY CALCULATOR.DLL

    1 IMPORT: SQRT
    2 IMPORT: Add
    2 IMPORT: Subtract
    2 IMPORT: Multiply
    2 IMPORT: Divide

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

«previous next»