From: Camille G. <k10...@wa...> - 2012-07-17 21:07:27
|
Le mardi 17 juillet 2012 00:10:10, William S Fulton a écrit : > On 15/07/12 17:48, k1000 wrote: > > Hello Swig developpers, > > > > I've been using swig for a while, and have started to rewrite the ocaml > > module, following a proposal made in 2009 by Guillaume Yziquel. > > Do you have a link to this proposal? > In the swig-devel archives, here is the first answer to his mail (which is also your answer by the way :-)) : http://sourceforge.net/mailarchive/message.php?msg_id=22889753 His also has a dedicated yziquel-ocaml branch in subversion. > > Based on the D module code, my code supports non-overloaded classes, > > functions and variables - everything statically typed. > > > > In order to get working directors, I need to have a way to 'duplicate' a > > > > class. Consider the following example.i : > >> %module(directors=1) example; > >> > >> %feature("director") foo; > >> > >> %inline %{ > >> class foo { > >> public: > >> virtual int main(); > >> }; > > > > The trick would be to generate 2 ocaml classes : the plain "foo" director > > class, which is meant to be derived in ocaml, and a "foo_cppderived" > > pseudo- class, which wraps C++ derived implementations. > > > > In generated .ml file, this would look like : > >> class foo = object(this) > >> method main = [[ explicit call to c++ "this->foo::main()" ]] > >> end > >> > >> class foo_cppderived = object(this) > >> inherit foo > >> method main = [[ virtual call to c++ "this->main()" ]] > >> end > > > > And used like that : > >> class bar = object(this) > >> inherit foo as super > >> method main = 1 + super#main (* explicit upcall *) > >> end > > > > This trick is not ocaml specific, but would still have two advantages : > > enforce override check at target language level (for pure virtual > > functions), and get rid of having to select upcalls. > > Hi Camille, > > I'm afraid I don't know ocaml, so if you are proposing something for all > other director classes, you'll have to provide a use case in one of the > more mainstream languages. > > I vaguely recall having two classes for one C++ class for either an > early implementation of directors or early implementations of proxy > classes. They have been long since scrapped. Searching through some > commit logs or the CHANGES file might reveal why. > > With regard to the Ocaml module in general, it is in dire need of a > maintainer. I'll be surprised if it works very well atm. I gave up > trying to get it to pass any tests a few years back. Hello William, I've looked at the CHANGES file and part of swig-devel archives, and no trace of duplicate classes. The first note from Mark Rose about directors already looks like actual implementation. I may investigate a bit more about this later. For now, I give priority to basic features, and overloading. By the way, is there a way to create specific typemaps for "SWIGTYPE" being a class, or are we stuck with a global case ? The documentation gives a specific construct for enums, but none for structs/classes. To be precise, I use different wrapping mechanism for class-type objects and non class-type objects, and I'd like to discriminate the cases at typemap level. Camille |