Next: , Previous: Model, Up: Top

11 Integrating Gforth into C programs

This is not yet implemented.

Several people like to use Forth as scripting language for applications that are otherwise written in C, C++, or some other language.

The Forth system ATLAST provides facilities for embedding it into applications; unfortunately it has several disadvantages: most importantly, it is not based on ANS Forth, and it is apparently dead (i.e., not developed further and not supported). The facilities provided by Gforth in this area are inspired by ATLAST's facilities, so making the switch should not be hard.

We also tried to design the interface such that it can easily be implemented by other Forth systems, so that we may one day arrive at a standardized interface. Such a standard interface would allow you to replace the Forth system without having to rewrite C code.

You embed the Gforth interpreter by linking with the library libgforth.a (give the compiler the option -lgforth). All global symbols in this library that belong to the interface, have the prefix forth_. (Global symbols that are used internally have the prefix gforth_).

You can include the declarations of Forth types and the functions and variables of the interface with #include <forth.h>.



Data and FP Stack pointer. Area sizes.


forth_init(imagefile) forth_evaluate(string) exceptions? forth_goto(address) (or forth_execute(xt)?) forth_continue() (a corountining mechanism)

Adding primitives.

No checking.


Accessing the Stacks