Chapter 3. Tools

The idea of separating a program into language-specific parts is not new or unexplored. In fact, the problem of interfacing different languages to C is usually addressed, and in our case there are several tools that I'll be using to connect our four languages:

SmallEiffel externals. SmallEiffel, the Eiffel compiler used in this study, incorporates a fairly simple method for calling C functions from within Eiffel code. The external keyword in Eiffel means that a feature has been defined outside the Eiffel language. By postfixing this with a specifier such as "C_WithoutCurrent", the Eiffel program will call the C function cleanly. SmallEiffel's "C_WithCurrent" qualifier allows Eiffel programs to call C functions and pass the address of an Eiffel object, providing some means for C programs to call Eiffel code, a feature covered by Cecil.

Cecil. Cecil, the C-Eiffel Call-In Library, is a tool created for interfacing SmallEiffel with C. Rather than embedding any special code in Eiffel files, the developer writes a special "cecil" file which contains the function name as it will be exported to C, the class exporting the feature, and the feature to export. Using a combination of the external keywords and a well-defined Cecil file, it should be possible to connect Eiffel and C with little difficulty.

SWIG. Dave Beazley's Simplified Wrapper and Interface Generator (SWIG) is a tool used to make foreign-language interfaces to C from other languages, particularly scripting languages. SWIG takes an input C file and an interface description file and produces an output file in the chosen language which allows it to communicate with the given C library. SWIG is very popular indeed, and has modules available for several different languages--including, as it happens, Eiffel and Python.

Python's external features. Through a series of coordinated calls, it's possible for a scrap of Python code to pass a C program the address of a Python object, or in C parlance a static PyObject *. With this Python object in hand, it's possible to shuttle the PyObject and tuples of arguments through a series of parsing functions and reference count increase/decrease functions and call Python code from C. The interface is somewhat cryptic, but it can be done; and so Python can be called from C.

HaskellDirect. A well-defined tool, HaskellDirect is an Interface Definition Language compiler which takes a description of external functions and translates them into Haskell-compatible code. HaskellDirect provides features for calling C code from Haskell (generally its intended purpose) and for calling Haskell code from C. It goes a few steps further, giving the intrepid user the ability to wrap Haskell code as a COM module, but this functionality won't be used in this study.

Using these tools, we can diagram the communications pathways thusly: