Although the "define interface" form provides a fairly rich sublanguage for specifying interfaces, it is often sufficient to use just the "minimal" form. For example, if "gc.h" contained the following code:
typedef char bool; typedef struct obj obj_t; typedef char *str; extern obj_t alloc(obj_t class, int bytes); extern void scavenge(obj_t *addr); extern obj_t transport(obj_t obj, int bytes); extern void shrink(obj_t obj, int bytes); extern void collect_garbage(void); extern bool TimeToGC; #define ForwardingMarker ((obj_t)(0xDEADBEEF))
then you could import it by creating a file named "class.intr" which includes arbitrary Dylan code and the following:
define interface #include "gc.h"; end interface;
You would then run "melange class.intr" [Or possibly " mindy -f melange.dbc class.intr ", depending upon the installation on your particular machine.] , which would produce a file of Dylan code which contains approriate definitions for the classes <bool>", "<obj>", "<obj_t>", and "<str>"; the variable "TimeToGC"; and the functions "alloc", "scavenge", "transport", "shrink", and "collect_garbage". (The constant "ForwardingMarker" will be excluded because it is not a simple literal.)
if (TimeToGC() ~= 0) collect_garbage(); end if;
This code fragment points out some of the hazards of "simple" imports. Melange has no way of knowing that "bool" should correspond to Mindy's <boolean> class, so you are stuck with a simple integer. Likewise, the system wouldn't be able to guess that "char *" shoudl correspond to the Mindy class "<c-string>". We will explain in later sections how "map:" or "equate:" options may be used to provide this information to Melange.
As mentioned above, the include directive in the previous example will only work for files which have been previously linked into Mindy. There are extra facilities available to handle other situations.
If your machine is one for which we support dynamic loading [Currently support is primarily for HPUX machines, but some work has been done on Macintoshes and ELF systems. Contact us for more details.] , and you wish to load some declared objects from a shared library, you can add one or more "object-file:" options to the "#include" clause, as in the following:
define interface #include "gc.h", object-file: "/usr/lib/mindy/gc.sl"; end interface;
This would cause the code from "gc.sl" to be loaded into Mindy at run-time and make its functions and objects available just as they were in the previous example. If you are running on a non-HPUX machine, you will have to statically link Mindy with the appropriate library and a list of mappings from names to addresses. This can be accomplished most easily by following these steps:
Add a "mindy-include-file:" option to your interface definition. This specifies the name of an "interface description file" which will be written by Melange, and which can later be linked into Mindy along with the appropriate library.
Run Melange on the source file in the normal manner. You may wish to move the newly created interface description file into your Mindy build directory.
Change the Makefile in the Mindy build directory, by adding the imported library to LIBS and the interface description file to EXTERN-INCLUDES.
Run "make" to rebuild Mindy with the new library information.
Compile and run the generated Dylan code as normal.
A typical interface definition for this approach might be:
define interface #include "gc.h", mindy-include-file: "/usr/local/mindy-build/gc.inc" end interface;