On Tue, 2007-07-17 at 11:39 -0700, Raoul Duke wrote: > hi, > > Many thanks for the tutorial! I will give it a shot. > > Reading over the info, it seems like there is quite a bit of work that > a developer has to do to get hooked up with C++ code.
Not really. The glue logic I gave was complete: it covered everything including *linking*. Roughly you have: type int = "int"; fun add: int * int -> int = "$1+$2"; and now you can add integers. You need a binding for every method. This is really simple, because you don't need to #include the C definition of 'int' (its a builtin type), and you don't need to link any library (other than libc) to use it. For user defined types, you need to do both these things. You have to #include the definition, and you have to link to the C library providing the required functionality. There is also a cclass construction for C++ classes I didn't tell you about: cclass Foo { ctor: int; fun getId: 1 -> int; }; which does everything in one go. Here 'ctor' means 'constructor', and 1 is the type of () the 'unit' tuple. > Would it be > possible to have some meta-generator (dunno if SWIG could work?) that > would alleviate some of the work? It's called 'flxcc', in the bin directory, but it takes quite a bit of work to drive, because it is designed to create bindings for your whole system in one go. That thing is a mess because it parses both GNU system header files correctly, as well as all of Windows.h. The problem is that to wrap a C file you have to parse EVERYTHING, not just that file -- you have to expand it with the system preprocessor first, and then you get all the #included files too. This is because C is an extremely bad language .. and C++ is even worse. You can't parse bits of C, only whole programs. > > A simpler treatment is just to put: > > The simpler treatment looks simpler, but it seems to not entirely > avoid DRY. Can one do something like: > > header > #include<Foo.h> > > rather than use the """ ... """ style? How would you parse it? Felix already has #include <foo.h> but it includes a *Felix* file, not a C one. Realise that header "C code"; can include *anything* not just a #include. > Does one have to do the header > thing in all .flx files, or just once and then that is the single > mapping and then all the other files just use the Felix wrapper (i > figure that has got to be the general idea)? You only need to do it once, because it is a proper construction. Look at this file: /////////////////////////// #import <flx.flxh> header '#include "fred.h"'; type fred = "fred"; println "Hello World"; ////////////////////////// If you run Felix on it and look at the *.hpp file generated, you'll see the #include has been included. But, it isn't used! to fix this problem: type fred = "fred" requires header '#include "fred.h"'; Now try again .. now fred.h isn't included! You can also write this as: type fred = "fred" requires fred_h; header fred_h = '#include "fred.h"'; which requires a name be invented. The main purpose of this mechanism is to *conditionally* include C definitions into your generated code. The conditional nature of the inclusion has two roles: the obvious one is just to make the C++ compile faster. The second one is more subtle.. you can do: type HANDLE = "HANDLE" requires '#include <windows.h>'; #if WIN32 typedef fd = HANDLE; #else typedef fd = int; #endif So now, if you're on Unix, and you read a file, it won't try to yank in windows.h, but on Windows it will. The clause requires package 'foo' together with the config/foo.fpc file is to handle the opposite end of the binding: linking to the required C library .. conditionally of course. The need to do all this is clear if you're writing a library .. Felix is whole program analyser .. you don't want to #include every header file and link to every C library for every program you write, just because it includes the Felix binding library. Instead, these operations are triggered by using a type or function from the library. The system is unique.. it takes some extra work, but the result is SOOOOO much better than bindings in any other language. Remember the goal is to just say: flx myprogram and have it do ALL the work, including calculate linker switches, link to libraries, and run the program. You can't get out of telling it how to do this .. :) -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language