Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Automatic wrapper generator
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-18 (08:38)
From: skaller <skaller@u...>
Subject: [Caml-list] Automatic wrapper generator
This is a brief status report concerning the Felix
automatic wrapper generator (reason for posting to Caml list
explained below).

With some platform specific hackery, I am now able to 
wrap 90% of all headers in '/usr/include' and execute
a single Felix test case:

include "stdio_h";
C_hack::ignore(stdio_h::printf(c"%s\n", c"Hello World"));

Line 1 includes the wrapper generated for stdio.h.
Line 2 invokes the wrapper for a popular function 'printf()'.
This program compiles and executes correctly.

C_hack::ignore is the same as Ocaml's ignore function,
it throws away the result of calling printf. 
The lexical elements c".." generate C char arrays
(instead of Felix strings which are C++ STL strings).
The include directive pulls in a precompiled header
containing a module named stdio_h, which is used
as a qualifier to the function name printf().

It isn't clear I have got everything right yet,
there is still a long way to go. However I do consider
this a reasonable "proof-of-principle" demonstration
that automatic wrapping of the complete C development
environment is possible. The wrapper generator uses the
frontc/Cil parser, and generates the wrappers for 
of /usr/include in a couple of seconds.


There isn't much that I'm doing for Felix wrappers
that can't be applied to Ocaml: perhaps with some
extra work it seems possible to make an Ocaml back end
to generate Foreign Function Interfaces for the whole
C environment in a few seconds.

Felix does have a few advantages over Ocaml that may
need to be considered in adapting the code, for example,
in Felix everything is automatically mutually recursive,
and so the order of definitions of types and functions
is irrelevant. Ocaml sometimes needs sequential definitions,
and has some problems with intermodule recursion.

However, I do not see any major obstacles.
[EG: intermodule recursion is a mess to handle by hand...
but it's no problem for a mechanical wrapper generator]

Note of course the generated wrappers are,
at least currently, LOW LEVEL and thus not safe.

for some time, people have been crying for 'MORE LIBRARIES'
for Ocaml.

Here's your chance to get THE LOT in one go.

I'm willing to work on adapting the wrapper generator
so it can be used to generate Ocaml wrappers, 
provided it continues to be useful generating
Felix ones. However, I can't tackle this on my own.

The generator needs to understand a heap
of highly  platform specific details, and a thus a lot
of people need to try it on many platforms to provide
the feedback needed to make it configurable enough to
actually work on many platforms.

Any comments appreciated.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: